Fixes to gerber parser related to aperture macros and aperture definitions allowed characters in names.
This commit is contained in:
33
camlib.py
33
camlib.py
@@ -6,6 +6,8 @@
|
|||||||
# MIT Licence #
|
# MIT Licence #
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
|
import traceback
|
||||||
|
|
||||||
from numpy import arctan2, Inf, array, sqrt, pi, ceil, sin, cos
|
from numpy import arctan2, Inf, array, sqrt, pi, ceil, sin, cos
|
||||||
from matplotlib.figure import Figure
|
from matplotlib.figure import Figure
|
||||||
import re
|
import re
|
||||||
@@ -31,7 +33,8 @@ import logging
|
|||||||
|
|
||||||
log = logging.getLogger('base2')
|
log = logging.getLogger('base2')
|
||||||
#log.setLevel(logging.DEBUG)
|
#log.setLevel(logging.DEBUG)
|
||||||
log.setLevel(logging.WARNING)
|
#log.setLevel(logging.WARNING)
|
||||||
|
log.setLevel(logging.INFO)
|
||||||
formatter = logging.Formatter('[%(levelname)s] %(message)s')
|
formatter = logging.Formatter('[%(levelname)s] %(message)s')
|
||||||
handler = logging.StreamHandler()
|
handler = logging.StreamHandler()
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
@@ -191,6 +194,16 @@ class Geometry(object):
|
|||||||
|
|
||||||
|
|
||||||
class ApertureMacro:
|
class ApertureMacro:
|
||||||
|
"""
|
||||||
|
Syntax of aperture macros.
|
||||||
|
|
||||||
|
<AM command>: AM<Aperture macro name>*<Macro content>
|
||||||
|
<Macro content>: {{<Variable definition>*}{<Primitive>*}}
|
||||||
|
<Variable definition>: $K=<Arithmetic expression>
|
||||||
|
<Primitive>: <Primitive code>,<Modifier>{,<Modifier>}|<Comment>
|
||||||
|
<Modifier>: $M|< Arithmetic expression>
|
||||||
|
<Comment>: 0 <Text>
|
||||||
|
"""
|
||||||
|
|
||||||
## Regular expressions
|
## Regular expressions
|
||||||
am1_re = re.compile(r'^%AM([^\*]+)\*(.+)?(%)?$')
|
am1_re = re.compile(r'^%AM([^\*]+)\*(.+)?(%)?$')
|
||||||
@@ -635,11 +648,11 @@ class Gerber (Geometry):
|
|||||||
self.comm_re = re.compile(r'^G0?4(.*)$')
|
self.comm_re = re.compile(r'^G0?4(.*)$')
|
||||||
|
|
||||||
# AD - Aperture definition
|
# AD - Aperture definition
|
||||||
self.ad_re = re.compile(r'^%ADD(\d\d+)([a-zA-Z0-9]*)(?:,(.*))?\*%$')
|
self.ad_re = re.compile(r'^%ADD(\d\d+)([a-zA-Z_$\.][a-zA-Z0-9_$\.]*)(?:,(.*))?\*%$')
|
||||||
|
|
||||||
# AM - Aperture Macro
|
# AM - Aperture Macro
|
||||||
# Beginning of macro (Ends with *%):
|
# Beginning of macro (Ends with *%):
|
||||||
self.am_re = re.compile(r'^%AM([a-zA-Z0-9]*)\*')
|
#self.am_re = re.compile(r'^%AM([a-zA-Z0-9]*)\*')
|
||||||
|
|
||||||
# Tool change
|
# Tool change
|
||||||
# May begin with G54 but that is deprecated
|
# May begin with G54 but that is deprecated
|
||||||
@@ -694,7 +707,7 @@ class Gerber (Geometry):
|
|||||||
self.absrel_re = re.compile(r'^G9([01])\*$')
|
self.absrel_re = re.compile(r'^G9([01])\*$')
|
||||||
|
|
||||||
# Aperture macros
|
# Aperture macros
|
||||||
self.am1_re = re.compile(r'^%AM([^\*]+)\*(.+)?(%)?$')
|
self.am1_re = re.compile(r'^%AM([^\*]+)\*([^%]+)?(%)?$')
|
||||||
self.am2_re = re.compile(r'(.*)%$')
|
self.am2_re = re.compile(r'(.*)%$')
|
||||||
|
|
||||||
# TODO: This is bad.
|
# TODO: This is bad.
|
||||||
@@ -915,6 +928,8 @@ class Gerber (Geometry):
|
|||||||
|
|
||||||
#### Parsing starts here ####
|
#### Parsing starts here ####
|
||||||
line_num = 0
|
line_num = 0
|
||||||
|
gline = ""
|
||||||
|
try:
|
||||||
for gline in glines:
|
for gline in glines:
|
||||||
line_num += 1
|
line_num += 1
|
||||||
|
|
||||||
@@ -929,6 +944,7 @@ class Gerber (Geometry):
|
|||||||
match = self.am1_re.search(gline)
|
match = self.am1_re.search(gline)
|
||||||
# Start macro if match, else not an AM, carry on.
|
# Start macro if match, else not an AM, carry on.
|
||||||
if match:
|
if match:
|
||||||
|
log.info("Starting macro. Line %d: %s" % (line_num, gline))
|
||||||
current_macro = match.group(1)
|
current_macro = match.group(1)
|
||||||
self.aperture_macros[current_macro] = ApertureMacro(name=current_macro)
|
self.aperture_macros[current_macro] = ApertureMacro(name=current_macro)
|
||||||
if match.group(2): # Append
|
if match.group(2): # Append
|
||||||
@@ -936,10 +952,13 @@ class Gerber (Geometry):
|
|||||||
if match.group(3): # Finish macro
|
if match.group(3): # Finish macro
|
||||||
#self.aperture_macros[current_macro].parse_content()
|
#self.aperture_macros[current_macro].parse_content()
|
||||||
current_macro = None
|
current_macro = None
|
||||||
|
log.info("Macro complete in 1 line.")
|
||||||
continue
|
continue
|
||||||
else: # Continue macro
|
else: # Continue macro
|
||||||
|
log.info("Continuing macro. Line %d." % line_num)
|
||||||
match = self.am2_re.search(gline)
|
match = self.am2_re.search(gline)
|
||||||
if match: # Finish macro
|
if match: # Finish macro
|
||||||
|
log.info("End of macro. Line %d." % line_num)
|
||||||
self.aperture_macros[current_macro].append(match.group(1))
|
self.aperture_macros[current_macro].append(match.group(1))
|
||||||
#self.aperture_macros[current_macro].parse_content()
|
#self.aperture_macros[current_macro].parse_content()
|
||||||
current_macro = None
|
current_macro = None
|
||||||
@@ -1155,6 +1174,7 @@ class Gerber (Geometry):
|
|||||||
### Aperture definitions %ADD...
|
### Aperture definitions %ADD...
|
||||||
match = self.ad_re.search(gline)
|
match = self.ad_re.search(gline)
|
||||||
if match:
|
if match:
|
||||||
|
log.info("Found aperture definition. Line %d: %s" % (line_num, gline))
|
||||||
self.aperture_parse(match.group(1), match.group(2), match.group(3))
|
self.aperture_parse(match.group(1), match.group(2), match.group(3))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -1254,6 +1274,11 @@ class Gerber (Geometry):
|
|||||||
else:
|
else:
|
||||||
self.solid_geometry = self.solid_geometry.difference(cascaded_union(poly_buffer))
|
self.solid_geometry = self.solid_geometry.difference(cascaded_union(poly_buffer))
|
||||||
|
|
||||||
|
except Exception, err:
|
||||||
|
#print traceback.format_exc()
|
||||||
|
log.error("PARSING FAILED. Line %d: %s" % (line_num, gline))
|
||||||
|
raise
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_flash_geometry(location, aperture):
|
def create_flash_geometry(location, aperture):
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
[{"kind": "excellon", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/FlatCam_Drilling_Test/FlatCam_Drilling_Test.drl"}, {"kind": "excellon", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/Excellon_Planck/X-Y CONTROLLER - Drill Data - Through Hole.drl"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/7V-PSU/7V PSU.GTL"}, {"kind": "cncjob", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/output.gcode"}, {"kind": "project", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/project_copy.fcproj"}, {"kind": "project", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/a_project.fcproj"}, {"kind": "project", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/cirkuix/tests/FlatCAM_TestProject.fcproj"}, {"kind": "cncjob", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/cirkuix/tests/FlatCAM_TestGCode.gcode"}, {"kind": "cncjob", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/cirkuix/tests/CBS-B_Cu_ISOLATION_GCODE.ngc"}, {"kind": "excellon", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/cirkuix/tests/FlatCAM_TestDrill.drl"}]
|
[{"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/WindMills - Bottom Copper 2.gbr"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/Example1_copper_bottom.gbr"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/7V-PSU.zip"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/Gerbers/AVR_Transistor_Tester_copper_top.GTL"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/XGerber/do-kotle.Bot"}, {"kind": "excellon", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/FlatCam_Drilling_Test/FlatCam_Drilling_Test.drl"}, {"kind": "excellon", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/Excellon_Planck/X-Y CONTROLLER - Drill Data - Through Hole.drl"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/7V-PSU/7V PSU.GTL"}, {"kind": "cncjob", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/output.gcode"}, {"kind": "project", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/project_copy.fcproj"}]
|
||||||
Reference in New Issue
Block a user