From 8851bc17b94a921453b0afd9c2421cb30f8d4425 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 9 Oct 2014 18:09:17 -0400 Subject: Doc update --- gerber/gerber_statements.py | 28 +++++++++++++ gerber/render/render.py | 86 ++++++++++++++++++++++++++++++++++++++- gerber/render/svgwrite_backend.py | 8 +++- 3 files changed, 119 insertions(+), 3 deletions(-) (limited to 'gerber') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index 76a6f0c..4c5133a 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -16,6 +16,20 @@ __all__ = ['FSParamStmt', 'MOParamStmt', 'IPParamStmt', 'OFParamStmt', class Statement(object): + """ Gerber statement Base class + + The statement class provides a type attribute. + + Parameters + ---------- + type : string + String identifying the statement type. + + Attributes + ---------- + type : string + String identifying the statement type. + """ def __init__(self, stype): self.type = stype @@ -30,6 +44,20 @@ class Statement(object): class ParamStmt(Statement): + """ Gerber parameter statement Base class + + The parameter statement class provides a parameter type attribute. + + Parameters + ---------- + param : string + two-character code identifying the parameter statement type. + + Attributes + ---------- + param : string + Parameter type code + """ def __init__(self, param): Statement.__init__(self, "PARAM") self.param = param diff --git a/gerber/render/render.py b/gerber/render/render.py index e91c71e..8cfc5de 100644 --- a/gerber/render/render.py +++ b/gerber/render/render.py @@ -23,7 +23,60 @@ from ..gerber_statements import (CommentStmt, UnknownStmt, EofStmt, ParamStmt, class GerberContext(object): - + """ Gerber rendering context base class + + Provides basic functionality and API for rendering gerber files. Medium- + specific renderers should subclass GerberContext and implement the drawing + functions. Colors are stored internally as 32-bit RGB and may need to be + converted to a native format in the rendering subclass. + + Attributes + ---------- + settings : FileSettings (dict-like) + Gerber file settings + + x : float + X-coordinate of the "photoplotter" head. + + y : float + Y-coordinate of the "photoplotter" head + + aperture : int + The aperture that is currently in use + + interpolation : str + Current interpolation mode. may be 'linear' or 'arc' + + direction : string + Current arc direction. May be either 'clockwise' or 'counterclockwise' + + image_polarity : string + Current image polarity setting. May be 'positive' or 'negative' + + level_polarity : string + Level polarity. May be 'dark' or 'clear'. Dark polarity indicates the + existance of copper/silkscreen/etc. in the exposed area, whereas clear + polarity indicates material should be removed from the exposed area. + + region_mode : string + Region mode. May be 'on' or 'off'. When region mode is set to 'on' the + following "contours" define the outline of a region. When region mode + is subsequently turned 'off', the defined area is filled. + + quadrant_mode : string + Quadrant mode. May be 'single-quadrant' or 'multi-quadrant'. Defines + how arcs are specified. + + color : tuple (, , ) + Color used for rendering as a tuple of normalized (red, green, blue) values. + + drill_color : tuple (, , ) + Color used for rendering drill hits. Format is the same as for `color`. + + background_color : tuple (, , ) + Color of the background. Used when exposing areas in 'clear' level + polarity mode. Format is the same as for `color`. + """ def __init__(self): self.settings = {} self.x = 0 @@ -35,13 +88,36 @@ class GerberContext(object): self.image_polarity = 'positive' self.level_polarity = 'dark' self.region_mode = 'off' + self.quadrant_mode = 'multi-quadrant' + self.color = (0.7215, 0.451, 0.200) self.drill_color = (0.25, 0.25, 0.25) + self.background_color = (0.0, 0.0, 0.0) def set_format(self, settings): + """ Set source file format. + + Parameters + ---------- + settings : FileSettings instance or dict-like + Gerber file settings used in source file. + """ self.settings = settings def set_coord_format(self, zero_suppression, format, notation): + """ Set coordinate format used in source gerber file + + Parameters + ---------- + zero_suppression : string + Zero suppression mode. may be 'leading' or 'trailling' + + format : tuple (, ) + decimal precision format + + notation : string + notation mode. 'absolute' or 'incremental' + """ self.settings['zero_suppression'] = zero_suppression self.settings['format'] = format self.settings['notation'] = notation @@ -69,6 +145,9 @@ class GerberContext(object): def set_drill_color(self, color): self.drill_color = color + + def set_background_color(self, color): + self.background_color = color def resolve(self, x, y): x = x if x is not None else self.x @@ -120,6 +199,8 @@ class GerberContext(object): def _evaluate_mode(self, stmt): if stmt.type == 'RegionMode': + if self.region_mode == 'on' and stmt.mode == 'off': + self._fill_region() self.region_mode = stmt.mode elif stmt.type == 'QuadrantMode': self.quadrant_mode = stmt.mode @@ -153,3 +234,6 @@ class GerberContext(object): def _evaluate_aperture(self, stmt): self.set_aperture(stmt.d) + + def _fill_region(self): + pass diff --git a/gerber/render/svgwrite_backend.py b/gerber/render/svgwrite_backend.py index 3b2f3c1..7570c84 100644 --- a/gerber/render/svgwrite_backend.py +++ b/gerber/render/svgwrite_backend.py @@ -152,7 +152,9 @@ class GerberSvgContext(GerberContext): ap = self.apertures.get(self.aperture, None) if ap is None: return - self.dwg.add(ap.line(self, x, y, convert_color(self.color))) + color = (convert_color(self.color) if self.level_polarity == 'dark' + else convert_color(self.background_color)) + self.dwg.add(ap.line(self, x, y, color)) self.move(x, y, resolve=False) def arc(self, x, y, i, j): @@ -171,7 +173,9 @@ class GerberSvgContext(GerberContext): ap = self.apertures.get(self.aperture, None) if ap is None: return - for shape in ap.flash(self, x, y, convert_color(self.color)): + color = (convert_color(self.color) if self.level_polarity == 'dark' + else convert_color(self.background_color)) + for shape in ap.flash(self, x, y, color): self.dwg.add(shape) self.move(x, y, resolve=False) -- cgit