summaryrefslogtreecommitdiff
path: root/gerber/rs274x.py
diff options
context:
space:
mode:
authorPaulo Henrique Silva <ph.silva@gmail.com>2015-12-20 22:15:44 -0200
committerPaulo Henrique Silva <ph.silva@gmail.com>2015-12-20 22:15:44 -0200
commitd1598b46c91ee36719460d49d7ba2ed5ecd0ef45 (patch)
tree7e107cc196fade05719f0cc6a659f6f17f6a3b3b /gerber/rs274x.py
parent2e2b4e49c3182cc7385f12d760222ecb57cc1356 (diff)
parent163a0cd531c667ec666108562eb2dbec28ce6125 (diff)
downloadgerbonara-d1598b46c91ee36719460d49d7ba2ed5ecd0ef45.tar.gz
gerbonara-d1598b46c91ee36719460d49d7ba2ed5ecd0ef45.tar.bz2
gerbonara-d1598b46c91ee36719460d49d7ba2ed5ecd0ef45.zip
Merge pull request #52 from curtacircuitos/negative_soldermask
Allow negative solder mask rendering per #50.
Diffstat (limited to 'gerber/rs274x.py')
-rw-r--r--gerber/rs274x.py66
1 files changed, 39 insertions, 27 deletions
diff --git a/gerber/rs274x.py b/gerber/rs274x.py
index 9fd63da..d9fd317 100644
--- a/gerber/rs274x.py
+++ b/gerber/rs274x.py
@@ -26,7 +26,7 @@ try:
from cStringIO import StringIO
except(ImportError):
from io import StringIO
-
+
from .gerber_statements import *
from .primitives import *
from .cam import CamFile, FileSettings
@@ -49,8 +49,21 @@ def read(filename):
def loads(data):
+ """ Generate a GerberFile object from rs274x data in memory
+
+ Parameters
+ ----------
+ data : string
+ string containing gerber file contents
+
+ Returns
+ -------
+ file : :class:`gerber.rs274x.GerberFile`
+ A GerberFile created from the specified file.
+ """
return GerberParser().parse_raw(data)
+
class GerberFile(CamFile):
""" A class representing a single gerber file
@@ -215,7 +228,7 @@ class GerberParser(object):
def parse(self, filename):
with open(filename, "rU") as fp:
data = fp.read()
- return self.parse_raw(data, filename=None)
+ return self.parse_raw(data, filename)
def parse_raw(self, data, filename=None):
lines = [line for line in StringIO(data)]
@@ -254,27 +267,10 @@ class GerberParser(object):
oldline = line
continue
-
did_something = True # make sure we do at least one loop
while did_something and len(line) > 0:
did_something = False
- # Region Mode
- (mode, r) = _match_one(self.REGION_MODE_STMT, line)
- if mode:
- yield RegionModeStmt.from_gerber(line)
- line = r
- did_something = True
- continue
-
- # Quadrant Mode
- (mode, r) = _match_one(self.QUAD_MODE_STMT, line)
- if mode:
- yield QuadrantModeStmt.from_gerber(line)
- line = r
- did_something = True
- continue
-
# coord
(coord, r) = _match_one(self.COORD_STMT, line)
if coord:
@@ -292,14 +288,6 @@ class GerberParser(object):
line = r
continue
- # comment
- (comment, r) = _match_one(self.COMMENT_STMT, line)
- if comment:
- yield CommentStmt(comment["comment"])
- did_something = True
- line = r
- continue
-
# parameter
(param, r) = _match_one_from_many(self.PARAM_STMT, line)
@@ -350,6 +338,30 @@ class GerberParser(object):
line = r
continue
+ # Region Mode
+ (mode, r) = _match_one(self.REGION_MODE_STMT, line)
+ if mode:
+ yield RegionModeStmt.from_gerber(line)
+ line = r
+ did_something = True
+ continue
+
+ # Quadrant Mode
+ (mode, r) = _match_one(self.QUAD_MODE_STMT, line)
+ if mode:
+ yield QuadrantModeStmt.from_gerber(line)
+ line = r
+ did_something = True
+ continue
+
+ # comment
+ (comment, r) = _match_one(self.COMMENT_STMT, line)
+ if comment:
+ yield CommentStmt(comment["comment"])
+ did_something = True
+ line = r
+ continue
+
# deprecated codes
(deprecated_unit, r) = _match_one(self.DEPRECATED_UNIT, line)
if deprecated_unit: