- added detection of Gerber files in Gerber X2 format

- added a new feature: if a Gerber file in format Gerber X2 having Drill information's is detected then after loading, it will be converted to an Excellon object
This commit is contained in:
Marius Stanciu
2021-03-05 05:36:40 +02:00
committed by Marius
parent 9c03efa31e
commit f103cc0a70
4 changed files with 84 additions and 18 deletions

View File

@@ -140,7 +140,13 @@ class Gerber(Geometry):
self.source_file = ''
# ### Parser patterns ## ##
# #############################################################################################################
# ################################# Parser patterns ###########################################################
# #############################################################################################################
# Detect Gerber x2 format
self.gx2_re = re.compile(r'%TF\.FileFunction.*')
# FS - Format Specification
# The format of X and Y must be the same!
# L-omit leading zeros, T-omit trailing zeros, D-no zero supression
@@ -355,7 +361,14 @@ class Gerber(Geometry):
break
processed_lines = list(line_generator())
self.parse_lines(processed_lines)
ret_val = self.parse_lines(processed_lines)
if ret_val == 'fail':
return 'fail'
elif ret_val == 'drill':
return 'drill_gx2'
else:
return
# @profile
def parse_lines(self, glines):
@@ -366,10 +379,12 @@ class Gerber(Geometry):
:param glines: Gerber code as list of strings, each element being
one line of the source file.
:type glines: list
:return: None
:rtype: None
:return: only errors/warnings
:rtype: str
"""
is_excellon_gx2 = False
# Coordinates of the current path, each is [x, y]
path = []
@@ -451,6 +466,22 @@ class Gerber(Geometry):
if match:
continue
# ######################################################################################################
# ######## Detect GERBER X2 format #####################################################################
# ######################################################################################################
match = self.gx2_re.search(gline)
if match:
self.app.log.warning('Gerber X2 format detected !!!')
self.app.inform.emit(
'[WARNING] %s' % _('Gerber X2 format detected. Parsing may not be done correctly.'))
if 'Drill' in gline:
self.app.log.warning('Drill file in Gerber X2 format detected !!!')
self.app.inform.emit(
'[WARNING] %s' % _('Drill file Gerber X2 format detected. '
'Parsing may not be done correctly.'))
is_excellon_gx2 = True
continue
# ###############################################################
# ################ Polarity change #############################
# ######## Example: %LPD*% or %LPC*% ###################
@@ -1703,6 +1734,10 @@ class Gerber(Geometry):
loc = '%s #%d %s: %s\n' % (_("Gerber Line"), line_num, _("Gerber Line Content"), gline) + repr(err)
self.app.inform.emit('[ERROR] %s\n%s:' % (_("Gerber Parser ERROR"), loc))
return 'fail'
if is_excellon_gx2 is True:
return 'drill'
@staticmethod
def create_flash_geometry(location, aperture, steps_per_circle=None):