diff options
author | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-03-05 13:33:49 -0500 |
---|---|---|
committer | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-03-05 13:33:49 -0500 |
commit | c40683b6a216f29fe473c31680ade7ab294002cd (patch) | |
tree | 2e02290c8b5e295c3e3cb933e1b60df5bc43ddbb /gerber/rs274x.py | |
parent | c542493b9b84a6af204c011bb9fc02eb43e48b2b (diff) | |
parent | 21fdb9cb57f5da938084fbf2b8133d903d0b0d77 (diff) | |
download | gerbonara-c40683b6a216f29fe473c31680ade7ab294002cd.tar.gz gerbonara-c40683b6a216f29fe473c31680ade7ab294002cd.tar.bz2 gerbonara-c40683b6a216f29fe473c31680ade7ab294002cd.zip |
Merge pull request #23 from curtacircuitos/macro-parse-eval
Add aperture macro parsing and evaluation.
Diffstat (limited to 'gerber/rs274x.py')
-rw-r--r-- | gerber/rs274x.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/gerber/rs274x.py b/gerber/rs274x.py index c5c89fb..a3a27e9 100644 --- a/gerber/rs274x.py +++ b/gerber/rs274x.py @@ -189,6 +189,7 @@ class GerberParser(object): self.statements = [] self.primitives = [] self.apertures = {} + self.macros = {} self.current_region = None self.x = 0 self.y = 0 @@ -392,6 +393,12 @@ class GerberParser(object): width = modifiers[0][0] height = modifiers[0][1] aperture = Obround(position=None, width=width, height=height) + elif shape == 'P': + # FIXME: not supported yet? + pass + else: + aperture = self.macros[shape].build(modifiers) + self.apertures[d] = aperture def _evaluate_mode(self, stmt): @@ -414,6 +421,8 @@ class GerberParser(object): self.image_polarity = stmt.ip elif stmt.param == "LP": self.level_polarity = stmt.lp + elif stmt.param == "AM": + self.macros[stmt.name] = stmt elif stmt.param == "AD": self._define_aperture(stmt.d, stmt.shape, stmt.modifiers) @@ -449,9 +458,14 @@ class GerberParser(object): primitive = copy.deepcopy(self.apertures[self.aperture]) # XXX: temporary fix because there are no primitives for Macros and Polygon if primitive is not None: - primitive.position = (x, y) - primitive.level_polarity = self.level_polarity - self.primitives.append(primitive) + # XXX: just to make it easy to spot + if isinstance(primitive, type([])): + print(primitive[0].to_gerber()) + else: + primitive.position = (x, y) + primitive.level_polarity = self.level_polarity + self.primitives.append(primitive) + self.x, self.y = x, y def _evaluate_aperture(self, stmt): |