summaryrefslogtreecommitdiff
path: root/gerber
diff options
context:
space:
mode:
Diffstat (limited to 'gerber')
-rw-r--r--gerber/gerber_statements.py10
-rw-r--r--gerber/render/render.py21
-rw-r--r--gerber/render/rs274x_backend.py27
3 files changed, 53 insertions, 5 deletions
diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py
index 881e5bc..52e7ac3 100644
--- a/gerber/gerber_statements.py
+++ b/gerber/gerber_statements.py
@@ -886,7 +886,10 @@ class CoordStmt(Statement):
@classmethod
def move(cls, func, point):
- return cls(func, point[0], point[1], None, None, CoordStmt.OP_MOVE, None)
+ if point:
+ return cls(func, point[0], point[1], None, None, CoordStmt.OP_MOVE, None)
+ # No point specified, so just write the function. This is normally for ending a region (D02*)
+ return cls(func, None, None, None, None, CoordStmt.OP_MOVE, None)
@classmethod
def line(cls, func, point):
@@ -902,7 +905,10 @@ class CoordStmt(Statement):
@classmethod
def flash(cls, point):
- return cls(None, point[0], point[1], None, None, CoordStmt.OP_FLASH, None)
+ if point:
+ return cls(None, point[0], point[1], None, None, CoordStmt.OP_FLASH, None)
+ else:
+ return cls(None, None, None, None, None, CoordStmt.OP_FLASH, None)
def __init__(self, function, x, y, i, j, op, settings):
""" Initialize CoordStmt class
diff --git a/gerber/render/render.py b/gerber/render/render.py
index 41b632c..128496f 100644
--- a/gerber/render/render.py
+++ b/gerber/render/render.py
@@ -136,6 +136,9 @@ class GerberContext(object):
return
color = (self.color if primitive.level_polarity == 'dark'
else self.background_color)
+
+ self._pre_render_primitive(primitive)
+
if isinstance(primitive, Line):
self._render_line(primitive, color)
elif isinstance(primitive, Arc):
@@ -160,8 +163,22 @@ class GerberContext(object):
self._render_region(primitive, color)
elif isinstance(primitive, TestRecord):
self._render_test_record(primitive, color)
- else:
- return
+
+ self._post_render_primitive(primitive)
+
+ def _pre_render_primitive(self, primitive):
+ """
+ Called before rendering a primitive. Use the callback to perform some action before rendering
+ a primitive, for example adding a comment.
+ """
+ return
+
+ def _post_render_primitive(self, primitive):
+ """
+ Called after rendering a primitive. Use the callback to perform some action after rendering
+ a primitive
+ """
+ return
def _render_line(self, primitive, color):
pass
diff --git a/gerber/render/rs274x_backend.py b/gerber/render/rs274x_backend.py
index c37529e..972edcb 100644
--- a/gerber/render/rs274x_backend.py
+++ b/gerber/render/rs274x_backend.py
@@ -90,6 +90,17 @@ class Rs274xContext(GerberContext):
self._quadrant_mode = None
self._dcode = None
+ # Primarily for testing and comarison to files, should we write
+ # flashes as a single statement or a move plus flash? Set to true
+ # to do in a single statement. Normally this can be false
+ self.condensed_flash = True
+
+ # When closing a region, force a D02 staement to close a region.
+ # This is normally not necessary because regions are closed with a G37
+ # staement, but this will add an extra statement for doubly close
+ # the region
+ self.explicit_region_move_end = False
+
self._next_dcode = 10
self._rects = {}
self._circles = {}
@@ -153,6 +164,11 @@ class Rs274xContext(GerberContext):
if aper.d != self._dcode:
self.body.append(ApertureStmt(aper.d))
self._dcode = aper.d
+
+ def _pre_render_primitive(self, primitive):
+
+ if hasattr(primitive, 'comment'):
+ self.body.append(CommentStmt(primitive.comment))
def _render_line(self, line, color):
@@ -233,6 +249,8 @@ class Rs274xContext(GerberContext):
else:
self._render_arc(p, color)
+ if self.explicit_region_move_end:
+ self.body.append(CoordStmt.move(None, None))
self.body.append(RegionModeStmt.off())
@@ -243,11 +261,18 @@ class Rs274xContext(GerberContext):
def _render_flash(self, primitive, aperture):
+ self._render_level_polarity(primitive)
+
if aperture.d != self._dcode:
self.body.append(ApertureStmt(aperture.d))
self._dcode = aperture.d
- self.body.append(CoordStmt.flash( self._simplify_point(primitive.position)))
+ if self.condensed_flash:
+ self.body.append(CoordStmt.flash(self._simplify_point(primitive.position)))
+ else:
+ self.body.append(CoordStmt.move(None, self._simplify_point(primitive.position)))
+ self.body.append(CoordStmt.flash(None))
+
self._pos = primitive.position
def _get_circle(self, diameter, dcode = None):