diff options
author | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2014-09-25 00:01:10 -0400 |
---|---|---|
committer | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2014-09-25 00:01:10 -0400 |
commit | 10d09512382df7ad512b5a528b6fe390373cd59d (patch) | |
tree | 6244b2baf018370e2e913c9865c4aa0fea9609a4 /gerber/render.py | |
parent | bd38028b01fdb6701195f023adfc72820a6f5ce5 (diff) | |
download | gerbonara-10d09512382df7ad512b5a528b6fe390373cd59d.tar.gz gerbonara-10d09512382df7ad512b5a528b6fe390373cd59d.tar.bz2 gerbonara-10d09512382df7ad512b5a528b6fe390373cd59d.zip |
Move evaluate methods to GerberContext class
Diffstat (limited to 'gerber/render.py')
-rw-r--r-- | gerber/render.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/gerber/render.py b/gerber/render.py index dd30ae0..201f793 100644 --- a/gerber/render.py +++ b/gerber/render.py @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from .parser import CommentStmt, UnknownStmt, EofStmt, ParamStmt, CoordStmt, ApertureStmt IMAGE_POLARITY_POSITIVE = 1 IMAGE_POLARITY_NEGATIVE = 2 @@ -138,3 +139,47 @@ class GerberContext(object): def flash(self, x, y): pass + + def evaluate(self, stmt): + if isinstance(stmt, (CommentStmt, UnknownStmt, EofStmt)): + return + + elif isinstance(stmt, ParamStmt): + self._evaluate_param(stmt) + + elif isinstance(stmt, CoordStmt): + self._evaluate_coord(stmt) + + elif isinstance(stmt, ApertureStmt): + self._evaluate_aperture(stmt) + + else: + raise Exception("Invalid statement to evaluate") + + def _evaluate_param(self, stmt): + if stmt.param == "FS": + self.set_coord_format(stmt.zero, stmt.x, stmt.y) + self.set_coord_notation(stmt.notation) + elif stmt.param == "MO:": + self.set_coord_unit(stmt.mo) + elif stmt.param == "IP:": + self.set_image_polarity(stmt.ip) + elif stmt.param == "LP:": + self.set_level_polarity(stmt.lp) + elif stmt.param == "AD": + self.define_aperture(stmt.d, stmt.shape, stmt.modifiers) + + def _evaluate_coord(self, stmt): + + if stmt.function in ("G01", "G1", "G02", "G2", "G03", "G3"): + self.set_interpolation(stmt.function) + + if stmt.op == "D01": + self.stroke(stmt.x, stmt.y) + elif stmt.op == "D02": + self.move(stmt.x, stmt.y) + elif stmt.op == "D03": + self.flash(stmt.x, stmt.y) + + def _evaluate_aperture(self, stmt): + self.set_aperture(stmt.d) |