From 29722de6acc94e8f2a49e9969a8eaa3f885c2036 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 11 Mar 2019 03:31:33 +0200 Subject: [PATCH] - fixed the Properties Project menu entry to work on the new way - in Properties tool now the Gerber apertures show the number of polygons in 'solid_geometry' instead of listing the objects --- FlatCAMApp.py | 2 +- ObjectCollection.py | 1 + README.md | 3 +- camlib.py | 52 ++++++++++++++++++++++------------ flatcamTools/ToolProperties.py | 8 +++++- 5 files changed, 45 insertions(+), 21 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index a808c2da..465b47a1 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -5266,7 +5266,7 @@ class App(QtCore.QObject): def obj_properties(self): self.report_usage("obj_properties()") - self.properties_tool.run() + self.properties_tool.run(toggle=False) def on_project_context_save(self): obj = self.collection.get_active() diff --git a/ObjectCollection.py b/ObjectCollection.py index 52d3f0d4..aecaf7f1 100644 --- a/ObjectCollection.py +++ b/ObjectCollection.py @@ -26,6 +26,7 @@ import builtins if '_' not in builtins.__dict__: _ = gettext.gettext + class KeySensitiveListView(QtWidgets.QTreeView): """ QtGui.QListView extended to emit a signal on key press. diff --git a/README.md b/README.md index f26ae0f5..95b8de24 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ CAD program, and create G-Code for Isolation routing. 11.03.2019 - changed some icons here and there - +- fixed the Properties Project menu entry to work on the new way +- in Properties tool now the Gerber apertures show the number of polygons in 'solid_geometry' instead of listing the objects 10.03.2019 diff --git a/camlib.py b/camlib.py index c3a88c54..6f1a1e69 100644 --- a/camlib.py +++ b/camlib.py @@ -2553,8 +2553,8 @@ class Gerber (Geometry): else: if '0' not in self.apertures: self.apertures['0'] = {} - self.apertures['0']['solid_geometry'] = [] self.apertures['0']['type'] = 'REG' + self.apertures['0']['solid_geometry'] = [] used_aperture = '0' try: @@ -2590,18 +2590,6 @@ class Gerber (Geometry): # NOTE: Letting it continue allows it to react to the # operation code. - # we do this for the case that a region is done without having defined any aperture - # Allegro does that - if current_aperture: - last_path_aperture = current_aperture - - if last_path_aperture is None: - if '0' not in self.apertures: - self.apertures['0'] = {} - self.apertures['0']['solid_geometry'] = [] - self.apertures['0']['type'] = 'REG' - last_path_aperture = '0' - # Parse coordinates if match.group(2) is not None: linear_x = parse_gerber_number(match.group(2), @@ -2628,7 +2616,7 @@ class Gerber (Geometry): if path[-1] != [linear_x, linear_y]: path.append([linear_x, linear_y]) - if making_region is False: + if making_region is False: # if the aperture is rectangle then add a rectangular shape having as parameters the # coordinates of the start and end point and also the width and height # of the 'R' aperture @@ -2652,6 +2640,14 @@ class Gerber (Geometry): except: pass last_path_aperture = current_aperture + # we do this for the case that a region is done without having defined any aperture + # Allegro does that + if last_path_aperture is None: + if '0' not in self.apertures: + self.apertures['0'] = {} + self.apertures['0']['type'] = 'REG' + self.apertures['0']['solid_geometry'] = [] + last_path_aperture = '0' else: self.app.inform.emit(_("[WARNING] Coordinates missing, line ignored: %s") % str(gline)) self.app.inform.emit(_("[WARNING_NOTCL] GERBER file might be CORRUPT. Check the file !!!")) @@ -2660,21 +2656,40 @@ class Gerber (Geometry): if len(path) > 1: geo = None - ## --- BUFFERED --- + # --- BUFFERED --- # this treats the case when we are storing geometry as paths only if making_region: + # we do this for the case that a region is done without having defined any aperture + # Allegro does that + if last_path_aperture is None: + if '0' not in self.apertures: + self.apertures['0'] = {} + self.apertures['0']['type'] = 'REG' + self.apertures['0']['solid_geometry'] = [] + last_path_aperture = '0' geo = Polygon() else: geo = LineString(path) + try: if self.apertures[last_path_aperture]["type"] != 'R': if not geo.is_empty: follow_buffer.append(geo) - except: - follow_buffer.append(geo) + except Exception as e: + log.debug("camlib.Gerber.parse_lines() --> %s" % str(e)) + if not geo.is_empty: + follow_buffer.append(geo) # this treats the case when we are storing geometry as solids if making_region: + # we do this for the case that a region is done without having defined any aperture + # Allegro does that + if last_path_aperture is None: + if '0' not in self.apertures: + self.apertures['0'] = {} + self.apertures['0']['type'] = 'REG' + self.apertures['0']['solid_geometry'] = [] + last_path_aperture = '0' elem = [linear_x, linear_y] if elem != path[-1]: path.append([linear_x, linear_y]) @@ -2701,7 +2716,8 @@ class Gerber (Geometry): except KeyError: self.apertures[last_path_aperture]['solid_geometry'] = [] self.apertures[last_path_aperture]['solid_geometry'].append(geo) - except: + except Exception as e: + log.debug("camlib.Gerber.parse_lines() --> %s" % str(e)) poly_buffer.append(geo) try: self.apertures[last_path_aperture]['solid_geometry'].append(geo) diff --git a/flatcamTools/ToolProperties.py b/flatcamTools/ToolProperties.py index e0def350..ef03d86f 100644 --- a/flatcamTools/ToolProperties.py +++ b/flatcamTools/ToolProperties.py @@ -156,8 +156,14 @@ class Properties(FlatCAMTool): self.addChild(options, [str(option), str(obj.options[option])], True) if obj.kind.lower() == 'gerber': + temp_ap = {} for ap in obj.apertures: - self.addChild(apertures, [str(ap), str(obj.apertures[ap])], True) + temp_ap.clear() + temp_ap = deepcopy(obj.apertures[ap]) + if obj.apertures[ap]['solid_geometry']: + elems = len(obj.apertures[ap]['solid_geometry']) + temp_ap['solid_geometry'] = '%s Polygons' % str(elems) + self.addChild(apertures, [str(ap), str(temp_ap)], True) elif obj.kind.lower() == 'excellon': for tool, value in obj.tools.items(): self.addChild(tools, [str(tool), str(value['C'])], True)