diff options
author | Paulo Henrique Silva <ph.silva@gmail.com> | 2015-03-03 03:41:55 -0300 |
---|---|---|
committer | Paulo Henrique Silva <ph.silva@gmail.com> | 2015-03-03 03:41:55 -0300 |
commit | 670d3fbbd7ebfb69bd223ac30b73ec47b195b380 (patch) | |
tree | 5373fdec50462a210f84d25caa93f1bc1204c4cb /gerber/rs274x.py | |
parent | b8dcc86cb4560d033761db0ad41924f6d9669333 (diff) | |
download | gerbonara-670d3fbbd7ebfb69bd223ac30b73ec47b195b380.tar.gz gerbonara-670d3fbbd7ebfb69bd223ac30b73ec47b195b380.tar.bz2 gerbonara-670d3fbbd7ebfb69bd223ac30b73ec47b195b380.zip |
Add aperture macro parsing and evaluation.
Aperture macros can get complex with arithmetical operations,
variables and variables substitution.
Current pcb-tools code just read each macro block as an independent
unit, this cannot deal with variables that get changed after used.
This patch splits the task in two: first we parse all macro content
and creates a bytecode representation of all operations. This bytecode
representation will be executed when an AD command is issues passing
the required parameters.
Parsing is heavily based on gerbv using a Shunting Yard approach to
math parsing.
Integration with rs274x.py code is not finished as I need to figure out
how to integrate the final macro primitives with the graphical primitives
already in use.
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..69485a8 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].evaluate(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): |