summaryrefslogtreecommitdiff
path: root/gerber/ipc356.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2016-01-28 12:19:03 -0500
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2016-01-28 12:19:03 -0500
commit5df38c014fd09792995b2b12b1982c535c962c9a (patch)
tree3dd1f118a752b7b6e75511e1f3b3af3ac1b67bdc /gerber/ipc356.py
parentb9f1b106c3006f1dddb1279ae9622630a29d18c7 (diff)
downloadgerbonara-5df38c014fd09792995b2b12b1982c535c962c9a.tar.gz
gerbonara-5df38c014fd09792995b2b12b1982c535c962c9a.tar.bz2
gerbonara-5df38c014fd09792995b2b12b1982c535c962c9a.zip
Cleanup, rendering fixes.
fixed rendering of tented vias fixed rendering of semi-transparent layers fixed file type detection issues added some examples
Diffstat (limited to 'gerber/ipc356.py')
-rw-r--r--gerber/ipc356.py45
1 files changed, 34 insertions, 11 deletions
diff --git a/gerber/ipc356.py b/gerber/ipc356.py
index 7dadd22..a831c0f 100644
--- a/gerber/ipc356.py
+++ b/gerber/ipc356.py
@@ -35,7 +35,7 @@ _SM_FIELD = {
def read(filename):
- """ Read data from filename and return an IPC_D_356
+ """ Read data from filename and return an IPCNetlist
Parameters
----------
filename : string
@@ -43,19 +43,38 @@ def read(filename):
Returns
-------
- file : :class:`gerber.ipc356.IPC_D_356`
- An IPC_D_356 object created from the specified file.
+ file : :class:`gerber.ipc356.IPCNetlist`
+ An IPCNetlist object created from the specified file.
"""
# File object should use settings from source file by default.
- return IPC_D_356.from_file(filename)
+ return IPCNetlist.from_file(filename)
-class IPC_D_356(CamFile):
+def loads(data, filename=None):
+ """ Generate an IPCNetlist object from IPC-D-356 data in memory
+
+ Parameters
+ ----------
+ data : string
+ string containing netlist file contents
+
+ filename : string, optional
+ string containing the filename of the data source
+
+ Returns
+ -------
+ file : :class:`gerber.ipc356.IPCNetlist`
+ An IPCNetlist created from the specified file.
+ """
+ return IPCNetlistParser().parse_raw(data, filename)
+
+
+class IPCNetlist(CamFile):
@classmethod
def from_file(cls, filename):
- parser = IPC_D_356_Parser()
+ parser = IPCNetlistParser()
return parser.parse(filename)
def __init__(self, statements, settings, primitives=None, filename=None):
@@ -130,7 +149,7 @@ class IPC_D_356(CamFile):
ctx.dump(filename)
-class IPC_D_356_Parser(object):
+class IPCNetlistParser(object):
# TODO: Allow multi-line statements (e.g. Altium board edge)
def __init__(self):
@@ -145,9 +164,13 @@ class IPC_D_356_Parser(object):
def parse(self, filename):
with open(filename, 'rU') as f:
- oldline = ''
- for line in f:
- # Check for existing multiline data...
+ data = f.read()
+ return self.parse_raw(data, filename)
+
+ def parse_raw(self, data, filename=None):
+ oldline = ''
+ for line in data.splitlines():
+ # Check for existing multiline data...
if oldline != '':
if len(line) and line[0] == '0':
oldline = oldline.rstrip('\r\n') + line[3:].rstrip()
@@ -158,7 +181,7 @@ class IPC_D_356_Parser(object):
oldline = line
self._parse_line(oldline)
- return IPC_D_356(self.statements, self.settings, filename=filename)
+ return IPCNetlist(self.statements, self.settings, filename=filename)
def _parse_line(self, line):
if not len(line):