diff options
Diffstat (limited to 'gerber')
-rw-r--r-- | gerber/excellon_statements.py | 20 | ||||
-rw-r--r-- | gerber/render/excellon_backend.py | 76 | ||||
-rw-r--r-- | gerber/render/rs274x_backend.py | 32 |
3 files changed, 100 insertions, 28 deletions
diff --git a/gerber/excellon_statements.py b/gerber/excellon_statements.py index d2ba233..66641a1 100644 --- a/gerber/excellon_statements.py +++ b/gerber/excellon_statements.py @@ -220,6 +220,22 @@ class ExcellonTool(ExcellonStatement): def _hit(self): self.hit_count += 1 + + def equivalent(self, other): + """ + Is the other tool equal to this, ignoring the tool number, and other file specified properties + """ + + if type(self) != type(other): + return False + + return (self.diameter == other.diameter + and self.feed_rate == other.feed_rate + and self.retract_rate == other.retract_rate + and self.rpm == other.rpm + and self.depth_offset == other.depth_offset + and self.max_hit_count == other.max_hit_count + and self.settings.units == other.settings.units) def __repr__(self): unit = 'in.' if self.settings.units == 'inch' else 'mm' @@ -322,6 +338,10 @@ class ZAxisInfeedRateStmt(ExcellonStatement): class CoordinateStmt(ExcellonStatement): @classmethod + def from_point(cls, point): + return cls(point[0], point[1]) + + @classmethod def from_excellon(cls, line, settings, **kwargs): x_coord = None y_coord = None diff --git a/gerber/render/excellon_backend.py b/gerber/render/excellon_backend.py new file mode 100644 index 0000000..bec8367 --- /dev/null +++ b/gerber/render/excellon_backend.py @@ -0,0 +1,76 @@ + +from .render import GerberContext +from ..excellon_statements import * + +class ExcellonContext(GerberContext): + + def __init__(self, settings): + GerberContext.__init__(self) + self.comments = [] + self.header = [] + self.tool_def = [] + self.body = [] + self.end = [EndOfProgramStmt()] + + self.handled_tools = set() + self.cur_tool = None + self.pos = (None, None) + + self.settings = settings + + self._start_header(settings) + + def _start_header(self, settings): + pass + + @property + def statements(self): + return self.comments + self.header + self.body + self.end + + def set_bounds(self, bounds): + pass + + def _paint_background(self): + pass + + def _render_line(self, line, color): + raise ValueError('Invalid Excellon object') + def _render_arc(self, arc, color): + raise ValueError('Invalid Excellon object') + + def _render_region(self, region, color): + raise ValueError('Invalid Excellon object') + + def _render_level_polarity(self, region): + raise ValueError('Invalid Excellon object') + + def _render_circle(self, circle, color): + raise ValueError('Invalid Excellon object') + + def _render_rectangle(self, rectangle, color): + raise ValueError('Invalid Excellon object') + + def _render_obround(self, obround, color): + raise ValueError('Invalid Excellon object') + + def _render_polygon(self, polygon, color): + raise ValueError('Invalid Excellon object') + + def _simplify_point(self, point): + return (point[0] if point[0] != self._pos[0] else None, point[1] if point[1] != self._pos[1] else None) + + def _render_drill(self, drill, color): + + if not drill in self.handled_tools: + self.tool_def.append(drill.tool) + + if drill.tool != self.cur_tool: + self.body.append(ToolSelectionStmt(drill.tool.number)) + + point = self._simplify_point(drill.position) + self._pos = drill.position + self.body.append(CoordinateStmt.from_point()) + + def _render_inverted_layer(self): + pass +
\ No newline at end of file diff --git a/gerber/render/rs274x_backend.py b/gerber/render/rs274x_backend.py index 5a15fe5..81e86f2 100644 --- a/gerber/render/rs274x_backend.py +++ b/gerber/render/rs274x_backend.py @@ -93,30 +93,11 @@ class Rs274xContext(GerberContext): self.settings = settings self._start_header(settings) - #self._define_dcodes() def _start_header(self, settings): self.header.append(FSParamStmt.from_settings(settings)) self.header.append(MOParamStmt.from_units(settings.units)) - def _define_dcodes(self): - - self._get_circle(.1575, 10) - self._get_circle(.035, 17) - self._get_rectangle(0.1575, 0.1181, 15) - self._get_rectangle(0.0492, 0.0118, 16) - self._get_circle(.0197, 11) - self._get_rectangle(0.0236, 0.0591, 12) - self._get_circle(.005, 18) - self._get_circle(.008, 19) - self._get_circle(.009, 20) - self._get_circle(.01, 21) - self._get_circle(.02, 22) - self._get_circle(.006, 23) - self._get_circle(.015, 24) - self._get_rectangle(0.1678, 0.1284, 26) - self._get_rectangle(0.0338, 0.0694, 25) - def _simplify_point(self, point): return (point[0] if point[0] != self._pos[0] else None, point[1] if point[1] != self._pos[1] else None) @@ -330,11 +311,10 @@ class Rs274xContext(GerberContext): pass def _render_polygon(self, polygon, color): - raise NotImplementedError('Not implemented yet') - pass + raise ValueError('Polygons can only exist in the context of aperture macro') - def _render_drill(self, circle, color): - pass + def _render_drill(self, drill, color): + raise ValueError('Drills are not valid in RS274X files') def _hash_amacro(self, amgroup): '''Calculate a very quick hash code for deciding if we should even check AM groups for comparision''' @@ -420,8 +400,4 @@ class Rs274xContext(GerberContext): def _render_inverted_layer(self): pass - - def post_render_primitives(self): - '''No more primitives, so set the end marker''' - - self.body.append()
\ No newline at end of file +
\ No newline at end of file |