- all Gerber regions (G36 G37) are stored in the '0' aperture

- fixed a bug that added geometry with clear polarity in the apertures where was not supposed to be
This commit is contained in:
Marius Stanciu
2019-04-27 03:03:00 +03:00
parent 6775c3f3da
commit 43c539702e
3 changed files with 45 additions and 32 deletions

View File

@@ -359,6 +359,12 @@ class FlatCAMObj(QtCore.QObject):
except AttributeError: except AttributeError:
pass pass
# Not all object types have mark_shapes
# try:
# self.mark_shapes.clear(update)
# except AttributeError:
# pass
def delete(self): def delete(self):
# Free resources # Free resources
del self.ui del self.ui

View File

@@ -16,6 +16,8 @@ CAD program, and create G-Code for Isolation routing.
- fixed some bugs recently introduced in Editors due of the changes done to the way mouse panning is detected - fixed some bugs recently introduced in Editors due of the changes done to the way mouse panning is detected
- cleaned up the context menu's when in Editors; made some structural changes - cleaned up the context menu's when in Editors; made some structural changes
- updated the code in camlib.CNCJob.generate_from_excellon_by_tools() to work with the new API from Google OR-Tools - updated the code in camlib.CNCJob.generate_from_excellon_by_tools() to work with the new API from Google OR-Tools
- all Gerber regions (G36 G37) are stored in the '0' aperture
- fixed a bug that added geometry with clear polarity in the apertures where was not supposed to be
25.04.2019 25.04.2019

View File

@@ -1942,6 +1942,10 @@ class Gerber (Geometry):
# will store the Gerber geometry's as paths # will store the Gerber geometry's as paths
self.follow_geometry = [] self.follow_geometry = []
# made True when the LPC command is encountered in Gerber parsing
# it allows adding data into the clear_geometry key of the self.apertures[aperture] dict
self.is_lpc = False
self.source_file = '' self.source_file = ''
# Attributes to be included in serialization # Attributes to be included in serialization
@@ -2174,10 +2178,6 @@ class Gerber (Geometry):
# applying a union for every new polygon. # applying a union for every new polygon.
poly_buffer = [] poly_buffer = []
# made True when the LPC command is encountered in Gerber parsing
# it allows adding data into the clear_geometry key of the self.apertures[aperture] dict
self.is_lpc = False
# store here the follow geometry # store here the follow geometry
follow_buffer = [] follow_buffer = []
@@ -2242,6 +2242,8 @@ class Gerber (Geometry):
match = self.lpol_re.search(gline) match = self.lpol_re.search(gline)
if match: if match:
new_polarity = match.group(1) new_polarity = match.group(1)
# log.info("Polarity CHANGE, LPC = %s, poly_buff = %s" % (self.is_lpc, poly_buffer))
self.is_lpc = True if new_polarity == 'C' else False
if len(path) > 1 and current_polarity != new_polarity: if len(path) > 1 and current_polarity != new_polarity:
# finish the current path and add it to the storage # finish the current path and add it to the storage
@@ -2258,6 +2260,7 @@ class Gerber (Geometry):
self.apertures[last_path_aperture]['follow_geometry'].append(geo) self.apertures[last_path_aperture]['follow_geometry'].append(geo)
geo = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4)) geo = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4))
if not geo.is_empty: if not geo.is_empty:
poly_buffer.append(geo) poly_buffer.append(geo)
if self.is_lpc is True: if self.is_lpc is True:
@@ -2280,12 +2283,10 @@ class Gerber (Geometry):
# TODO: Remove when bug fixed # TODO: Remove when bug fixed
if len(poly_buffer) > 0: if len(poly_buffer) > 0:
if current_polarity == 'D': if current_polarity == 'D':
self.is_lpc = True
# self.follow_geometry = self.follow_geometry.union(cascaded_union(follow_buffer)) # self.follow_geometry = self.follow_geometry.union(cascaded_union(follow_buffer))
self.solid_geometry = self.solid_geometry.union(cascaded_union(poly_buffer)) self.solid_geometry = self.solid_geometry.union(cascaded_union(poly_buffer))
else: else:
self.is_lpc = False
# self.follow_geometry = self.follow_geometry.difference(cascaded_union(follow_buffer)) # self.follow_geometry = self.follow_geometry.difference(cascaded_union(follow_buffer))
self.solid_geometry = self.solid_geometry.difference(cascaded_union(poly_buffer)) self.solid_geometry = self.solid_geometry.difference(cascaded_union(poly_buffer))
@@ -2414,7 +2415,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)) # 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
@@ -2460,7 +2461,7 @@ class Gerber (Geometry):
match = self.tool_re.search(gline) match = self.tool_re.search(gline)
if match: if match:
current_aperture = match.group(1) current_aperture = match.group(1)
log.debug("Line %d: Aperture change to (%s)" % (line_num, match.group(1))) log.debug("Line %d: Aperture change to (%s)" % (line_num, current_aperture))
# If the aperture value is zero then make it something quite small but with a non-zero value # If the aperture value is zero then make it something quite small but with a non-zero value
# so it can be processed by FlatCAM. # so it can be processed by FlatCAM.
@@ -2479,7 +2480,6 @@ class Gerber (Geometry):
else: else:
# --- Buffered ---- # --- Buffered ----
width = self.apertures[last_path_aperture]["size"] width = self.apertures[last_path_aperture]["size"]
geo = LineString(path) geo = LineString(path)
if not geo.is_empty: if not geo.is_empty:
follow_buffer.append(geo) follow_buffer.append(geo)
@@ -2551,6 +2551,11 @@ class Gerber (Geometry):
if self.regionoff_re.search(gline): if self.regionoff_re.search(gline):
making_region = False making_region = False
if '0' not in self.apertures:
self.apertures['0'] = {}
self.apertures['0']['type'] = 'REG'
self.apertures['0']['solid_geometry'] = []
# if D02 happened before G37 we now have a path with 1 element only so we have to add the current # if D02 happened before G37 we now have a path with 1 element only so we have to add the current
# geo to the poly_buffer otherwise we loose it # geo to the poly_buffer otherwise we loose it
if current_operation_code == 2: if current_operation_code == 2:
@@ -2558,24 +2563,24 @@ class Gerber (Geometry):
if not geo.is_empty: if not geo.is_empty:
follow_buffer.append(geo) follow_buffer.append(geo)
try: try:
self.apertures[current_aperture]['follow_geometry'].append(geo) self.apertures['0']['follow_geometry'].append(geo)
except KeyError: except KeyError:
self.apertures[current_aperture]['follow_geometry'] = [] self.apertures['0']['follow_geometry'] = []
self.apertures[current_aperture]['follow_geometry'].append(geo) self.apertures['0']['follow_geometry'].append(geo)
poly_buffer.append(geo) poly_buffer.append(geo)
if self.is_lpc is True: if self.is_lpc is True:
try: try:
self.apertures[current_aperture]['clear_geometry'].append(geo) self.apertures['0']['clear_geometry'].append(geo)
except KeyError: except KeyError:
self.apertures[current_aperture]['clear_geometry'] = [] self.apertures['0']['clear_geometry'] = []
self.apertures[current_aperture]['clear_geometry'].append(geo) self.apertures['0']['clear_geometry'].append(geo)
else: else:
try: try:
self.apertures[current_aperture]['solid_geometry'].append(geo) self.apertures['0']['solid_geometry'].append(geo)
except KeyError: except KeyError:
self.apertures[current_aperture]['solid_geometry'] = [] self.apertures['0']['solid_geometry'] = []
self.apertures[current_aperture]['solid_geometry'].append(geo) self.apertures['0']['solid_geometry'].append(geo)
continue continue
# Only one path defines region? # Only one path defines region?
@@ -2599,10 +2604,10 @@ class Gerber (Geometry):
if not region.is_empty: if not region.is_empty:
follow_buffer.append(region) follow_buffer.append(region)
try: try:
self.apertures[current_aperture]['follow_geometry'].append(region) self.apertures['0']['follow_geometry'].append(region)
except KeyError: except KeyError:
self.apertures[current_aperture]['follow_geometry'] = [] self.apertures['0']['follow_geometry'] = []
self.apertures[current_aperture]['follow_geometry'].append(region) self.apertures['0']['follow_geometry'].append(region)
region = Polygon(path) region = Polygon(path)
if not region.is_valid: if not region.is_valid:
@@ -2613,17 +2618,17 @@ class Gerber (Geometry):
# we do this for the case that a region is done without having defined any aperture # we do this for the case that a region is done without having defined any aperture
# Allegro does that # Allegro does that
if current_aperture: # if current_aperture:
used_aperture = current_aperture # used_aperture = current_aperture
elif last_path_aperture: # elif last_path_aperture:
used_aperture = last_path_aperture # used_aperture = last_path_aperture
else: # else:
if '0' not in self.apertures: # if '0' not in self.apertures:
self.apertures['0'] = {} # self.apertures['0'] = {}
self.apertures['0']['type'] = 'REG' # self.apertures['0']['type'] = 'REG'
self.apertures['0']['solid_geometry'] = [] # self.apertures['0']['solid_geometry'] = []
used_aperture = '0' # used_aperture = '0'
used_aperture = '0'
if self.is_lpc is True: if self.is_lpc is True:
try: try:
self.apertures[used_aperture]['clear_geometry'].append(region) self.apertures[used_aperture]['clear_geometry'].append(region)