summaryrefslogtreecommitdiff
path: root/gerber/rs274x.py
diff options
context:
space:
mode:
authorGarret Fick <garret@ficksworkshop.com>2016-07-17 10:42:03 +0800
committerGarret Fick <garret@ficksworkshop.com>2016-07-17 10:42:03 +0800
commit0dded38353e1d650458f6401aea37a4aadaf28ff (patch)
treea297c26c7cbb6b1c7d7a9cbe4eb4639b203fba53 /gerber/rs274x.py
parentd0e9018da0d7c51c2195f641c9189f85378df3e8 (diff)
parentd1598b46c91ee36719460d49d7ba2ed5ecd0ef45 (diff)
downloadgerbonara-0dded38353e1d650458f6401aea37a4aadaf28ff.tar.gz
gerbonara-0dded38353e1d650458f6401aea37a4aadaf28ff.tar.bz2
gerbonara-0dded38353e1d650458f6401aea37a4aadaf28ff.zip
Merge in negative soldermask. Still required further changes to support negatives for shapes that dont exist in the merge source
Diffstat (limited to 'gerber/rs274x.py')
-rw-r--r--gerber/rs274x.py68
1 files changed, 40 insertions, 28 deletions
diff --git a/gerber/rs274x.py b/gerber/rs274x.py
index 384d498..f8b3222 100644
--- a/gerber/rs274x.py
+++ b/gerber/rs274x.py
@@ -27,7 +27,7 @@ try:
from cStringIO import StringIO
except(ImportError):
from io import StringIO
-
+
from .gerber_statements import *
from .primitives import *
from .cam import CamFile, FileSettings
@@ -51,8 +51,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
@@ -234,7 +247,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):
for stmt in self._parse(self._split_commands(data)):
@@ -303,7 +316,6 @@ 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
@@ -321,23 +333,7 @@ class GerberParser(object):
line = r
did_something = True
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
-
+
# aperture selection
(aperture, r) = _match_one(self.APERTURE_STMT, line)
if aperture:
@@ -346,14 +342,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)
@@ -406,6 +394,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: