From 73a44901c0ef0e94e9465c2f35750ca6f85a4473 Mon Sep 17 00:00:00 2001 From: jaseg Date: Mon, 17 Jan 2022 23:14:52 +0100 Subject: Excellon, unit conversion WIP --- gerbonara/gerber/aperture_macros/expression.py | 7 +++---- gerbonara/gerber/aperture_macros/parse.py | 3 ++- gerbonara/gerber/aperture_macros/primitive.py | 8 -------- 3 files changed, 5 insertions(+), 13 deletions(-) (limited to 'gerbonara/gerber/aperture_macros') diff --git a/gerbonara/gerber/aperture_macros/expression.py b/gerbonara/gerber/aperture_macros/expression.py index fb399d3..2375c56 100644 --- a/gerbonara/gerber/aperture_macros/expression.py +++ b/gerbonara/gerber/aperture_macros/expression.py @@ -7,8 +7,7 @@ import operator import re import ast - -MILLIMETERS_PER_INCH = 25.4 +from ..utils import MM, Inch, MILLIMETERS_PER_INCH def expr(obj): @@ -81,10 +80,10 @@ class UnitExpression(Expression): if self.unit is None or unit is None or self.unit == unit: return self._expr - elif unit == 'mm': + elif unit == MM: return self._expr * MILLIMETERS_PER_INCH - elif unit == 'inch': + elif unit == Inch: return self._expr / MILLIMETERS_PER_INCH else: diff --git a/gerbonara/gerber/aperture_macros/parse.py b/gerbonara/gerber/aperture_macros/parse.py index 375bb5b..43af309 100644 --- a/gerbonara/gerber/aperture_macros/parse.py +++ b/gerbonara/gerber/aperture_macros/parse.py @@ -11,6 +11,7 @@ import math from . import primitive as ap from .expression import * +from ..utils import MM def rad_to_deg(x): return (x / math.pi) * 180 @@ -98,7 +99,7 @@ class ApertureMacro: def __hash__(self): return hash(self.to_gerber()) - def dilated(self, offset, unit='mm'): + def dilated(self, offset, unit=MM): dup = copy.deepcopy(self) new_primitives = [] for primitive in dup.primitives: diff --git a/gerbonara/gerber/aperture_macros/primitive.py b/gerbonara/gerber/aperture_macros/primitive.py index b569637..4de19c4 100644 --- a/gerbonara/gerber/aperture_macros/primitive.py +++ b/gerbonara/gerber/aperture_macros/primitive.py @@ -21,14 +21,6 @@ def point_distance(a, b): def deg_to_rad(a): return (a / 180) * math.pi -def convert(value, src, dst): - if src == dst or src is None or dst is None or value is None: - return value - elif dst == 'mm': - return value * 25.4 - else: - return value / 25.4 - class Primitive: def __init__(self, unit, args): self.unit = unit -- cgit