summaryrefslogtreecommitdiff
path: root/gerber/excellon.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2014-10-18 01:44:51 -0400
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2014-10-18 01:44:51 -0400
commit6d2db67e6d0973ce26ce3a6700ca44295f73fea7 (patch)
treee329712e0278883bacc9a5f8501c8e48e1a05d54 /gerber/excellon.py
parentd90da4000f3fd542da1896e705d3db43fd48ea4b (diff)
downloadgerbonara-6d2db67e6d0973ce26ce3a6700ca44295f73fea7.tar.gz
gerbonara-6d2db67e6d0973ce26ce3a6700ca44295f73fea7.tar.bz2
gerbonara-6d2db67e6d0973ce26ce3a6700ca44295f73fea7.zip
Refactor rendering
Diffstat (limited to 'gerber/excellon.py')
-rwxr-xr-xgerber/excellon.py38
1 files changed, 21 insertions, 17 deletions
diff --git a/gerber/excellon.py b/gerber/excellon.py
index 13aacc6..ca2f7c8 100755
--- a/gerber/excellon.py
+++ b/gerber/excellon.py
@@ -25,7 +25,7 @@ This module provides Excellon file classes and parsing utilities
from .excellon_statements import *
from .cam import CamFile, FileSettings
-
+from .primitives import Drill
import math
def read(filename):
@@ -74,30 +74,33 @@ class ExcellonFile(CamFile):
"""
def __init__(self, statements, tools, hits, settings, filename=None):
- super(ExcellonFile, self).__init__(statements, settings, filename)
+ super(ExcellonFile, self).__init__(statements=statements,
+ settings=settings,
+ filename=filename)
self.tools = tools
self.hits = hits
+ self.primitives = [Drill(position, tool.diameter)
+ for tool, position in self.hits]
+
+ @property
+ def bounds(self):
+ xmin = ymin = 100000000000
+ xmax = ymax = -100000000000
+ for tool, position in self.hits:
+ radius = tool.diameter / 2.
+ x = position[0]
+ y = position[1]
+ xmin = min(x - radius, xmin)
+ xmax = max(x + radius, xmax)
+ ymin = min(y - radius, ymin)
+ ymax = max(y + radius, ymax)
+ return ((xmin, xmax), (ymin, ymax))
def report(self):
""" Print drill report
"""
pass
- def render(self, ctx, filename=None):
- """ Generate image of file
-
- Parameters
- ----------
- ctx : :class:`gerber.render.GerberContext`
- GerberContext subclass used for rendering the image
-
- filename : string <optional>
- If provided, the rendered image will be saved to `filename`
- """
- for tool, pos in self.hits:
- ctx.drill(pos[0], pos[1], tool.diameter)
- if filename is not None:
- ctx.dump(filename)
def write(self, filename):
with open(filename, 'w') as f:
@@ -105,6 +108,7 @@ class ExcellonFile(CamFile):
f.write(statement.to_excellon() + '\n')
+
class ExcellonParser(object):
""" Excellon File Parser