summaryrefslogtreecommitdiff
path: root/gerbonara/aperture_macros/parse.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-11-09 20:08:26 +0100
committerjaseg <git@jaseg.de>2023-11-14 21:52:12 +0100
commit11325b213b6ef7cebcdcf0c79f966cda3ce61a89 (patch)
tree90922e50e32b30fb1d7431de9e48d8b5aa5e51ad /gerbonara/aperture_macros/parse.py
parent74fb384c4c0899f4d6f153da8db748a7a49e78ee (diff)
downloadgerbonara-11325b213b6ef7cebcdcf0c79f966cda3ce61a89.tar.gz
gerbonara-11325b213b6ef7cebcdcf0c79f966cda3ce61a89.tar.bz2
gerbonara-11325b213b6ef7cebcdcf0c79f966cda3ce61a89.zip
Calculate out all aperture macros by default.
There are just too many severely buggy implementations around. Today I ran into problems with both gerbv and with whatever JLC uses. You can still export macros with raw expressions by setting a flag in the export FileSettings.
Diffstat (limited to 'gerbonara/aperture_macros/parse.py')
-rw-r--r--gerbonara/aperture_macros/parse.py33
1 files changed, 12 insertions, 21 deletions
diff --git a/gerbonara/aperture_macros/parse.py b/gerbonara/aperture_macros/parse.py
index fb4f0fe..51c1f27 100644
--- a/gerbonara/aperture_macros/parse.py
+++ b/gerbonara/aperture_macros/parse.py
@@ -118,41 +118,32 @@ class ApertureMacro:
pass
return replace(self, primitives=tuple(new_primitives))
+ def substitute_params(self, params, unit=None, macro_name=None):
+ params = dict(enumerate(params, start=1))
+ return replace(self,
+ num_parameters=0,
+ name=macro_name,
+ primitives=tuple(p.substitute_params(params, unit) for p in self.primitives),
+ comments=(f'Fully substituted instance of {self.name} macro',
+ f'Original parameters {"X".join(map(str, params.values()))}'))
+
def to_gerber(self, settings):
""" Serialize this macro's content (without the name) into Gerber using the given file unit """
comments = [ f'0 {c.replace("*", "_").replace("%", "_")}' for c in self.comments ]
subexpression_variables = {}
def register_variable(expr):
- if not settings.allow_mixed_operators_in_aperture_macros:
- expr = expr.replace_mixed_subexpressions(unit=settings.unit)
-
expr_str = expr.to_gerber(register_variable, settings.unit)
if expr_str not in subexpression_variables:
subexpression_variables[expr_str] = self.num_parameters + 1 + len(subexpression_variables)
-
return subexpression_variables[expr_str]
- primitive_defs = []
- for prim in self.primitives:
- if not settings.allow_mixed_operators_in_aperture_macros:
- prim = prim.replace_mixed_subexpressions(unit=settings.unit)
-
- primitive_defs.append(prim.to_gerber(register_variable, settings))
-
- variable_defs = []
- for expr_str, num in subexpression_variables.items():
- variable_defs.append(f'${num}={expr_str}')
-
+ primitive_defs = [prim.to_gerber(register_variable, settings) for prim in self.primitives]
+ variable_defs = [f'${num}={expr_str}' for expr_str, num in subexpression_variables.items()]
return '*\n'.join(comments + variable_defs + primitive_defs)
def to_graphic_primitives(self, offset, rotation, parameters : [float], unit=None, polarity_dark=True):
- variables = {i: v for i, v in enumerate(self.variables, start=1) if v is not None}
- for number, value in enumerate(parameters, start=1):
- if number in variables:
- raise SyntaxError(f'Re-definition of aperture macro variable {number} through parameter {value}')
- variables[number] = value
-
+ parameters = dict(enumerate(parameters, start=1))
for primitive in self.primitives:
yield from primitive.to_graphic_primitives(offset, rotation, variables, unit, polarity_dark)