summaryrefslogtreecommitdiff
path: root/gerber/render.py
diff options
context:
space:
mode:
Diffstat (limited to 'gerber/render.py')
-rw-r--r--gerber/render.py45
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)