From 7fa40fd940e6b3395f82f21d6ac887af54a195c3 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sat, 23 Sep 2023 20:25:34 +0300 Subject: [PATCH] - fixed aperture macros parse for Gerber files generated from KiCAD 7.0.7 --- CHANGELOG.md | 4 ++ appGUI/preferences/PreferencesUIManager.py | 2 +- appMain.py | 2 +- camlib.py | 43 ++++++++++++++++------ defaults.py | 4 +- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a57ac11..4ea95f85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ CHANGELOG for FlatCAM Evo beta ================================================= +23.09.2023 + +- fixed aperture macros parse for Gerber files generated from KiCAD 7.0.7 + 6.07.2023 - Isolation Plugin: reversed the milling direction between the conventional and climbing milling types diff --git a/appGUI/preferences/PreferencesUIManager.py b/appGUI/preferences/PreferencesUIManager.py index 4b3a307c..30de316f 100644 --- a/appGUI/preferences/PreferencesUIManager.py +++ b/appGUI/preferences/PreferencesUIManager.py @@ -55,7 +55,7 @@ class PreferencesUIManager(QtCore.QObject): # def app_obj.new_object(self, kind, name, initialize, active=True, fit=True, plot=True) self.defaults_form_fields = { # General App - "decimals_metric": self.ui.general_pref_form.general_app_group.precision_metric_entry, + "units_precision": self.ui.general_pref_form.general_app_group.precision_metric_entry, "global_graphic_engine": self.ui.general_pref_form.general_app_group.ge_radio, "global_graphic_engine_3d_no_mp": self.ui.general_pref_form.general_app_group.ge_comp_cb, "global_app_level": self.ui.general_pref_form.general_app_group.app_level_radio, diff --git a/appMain.py b/appMain.py index 3aa43021..09a66e85 100644 --- a/appMain.py +++ b/appMain.py @@ -621,7 +621,7 @@ class App(QtCore.QObject): self.app_units = self.options["units"] self.default_units = self.defaults["units"] - self.decimals = int(self.options['decimals_metric']) + self.decimals = int(self.options['units_precision']) if self.options["global_theme"] == 'default': self.resource_location = 'assets/resources' diff --git a/camlib.py b/camlib.py index f68fd7e5..fbfdd649 100644 --- a/camlib.py +++ b/camlib.py @@ -40,6 +40,7 @@ from shapely.affinity import scale, translate from shapely.wkt import loads as sloads from shapely.wkt import dumps as sdumps from shapely.geometry.base import BaseGeometry +from shapely import union, difference # --------------------------------------- # NEEDED for Legacy mode @@ -193,19 +194,28 @@ class ApertureMacro: if match: # ## Replace all variables for v in self.locvars: - # replaced the following line with the next to fix Mentor custom apertures not parsed OK - # part = re.sub(r'\$' + str(v) + r'(?![0-9a-zA-Z])', str(self.locvars[v]), part) - part = part.replace('$' + str(v), str(self.locvars[v])) + part = re.sub(r'\$' + str(v) + r'(?![0-9a-zA-Z])', str(self.locvars[v]), part) + # Sometimes the 'X' char is used instead of * for multiplication + part = re.sub(r'[Xx]', "*", part) # Make all others 0 part = re.sub(r'\$[0-9a-zA-Z](?![0-9a-zA-Z])', "0", part) + self.primitives.append([eval(x) for x in part.split(",")]) - # Change x with * - part = re.sub(r'[xX]', "*", part) + # for v in self.locvars: + # # replaced the following line with the next to fix Mentor custom apertures not parsed OK + # # part = re.sub(r'\$' + str(v) + r'(?![0-9a-zA-Z])', str(self.locvars[v]), part) + # part = part.replace('$' + str(v), str(self.locvars[v])) - # ## Store - elements = part.split(",") - self.primitives.append([eval(x) for x in elements]) + # # Make all others 0 + # part = re.sub(r'\$[0-9a-zA-Z](?![0-9a-zA-Z])', "0", part) + # + # # Change x with * + # part = re.sub(r'[xX]', "*", part) + # + # # ## Store + # elements = part.split(",") + # self.primitives.append([eval(x) for x in elements]) continue log.warning("Unknown syntax of aperture macro part: %s" % str(part)) @@ -348,6 +358,8 @@ class ApertureMacro: vertex_list = mods[2:-1] # rotation is the last value angle = mods[-1] + # vertex points number is second value + vtx_nr = mods[1] n = int(len(vertex_list) / 2) points = [(0, 0)] * n @@ -355,6 +367,11 @@ class ApertureMacro: start = 2 * i stop = (2 * i) + 2 points[i] = vertex_list[start:stop] + + # Fix for KiCAD 7.0.7 who is too lazy to respect the Gerber specification which says + # that the last point should always be the first + if len(points) < vtx_nr: + points.append(points[0]) # --------------------------- poly = Polygon(points) @@ -467,7 +484,7 @@ class ApertureMacro: return {"pol": 1, "geometry": thermal} - def make_geometry(self, modifiers): + def make_geometry(self, modifiers: list): """ Runs the macro for the given modifiers and generates the corresponding geometry. @@ -513,12 +530,14 @@ class ApertureMacro: # self.geometry = prim_geo['geometry'] # continue if prim_geo['pol'] == 1: - self.geometry = self.geometry.union(prim_geo['geometry']) + if self.geometry.is_empty: + self.geometry = prim_geo['geometry'] + continue + self.geometry = union(self.geometry, prim_geo['geometry']) continue if prim_geo['pol'] == 0: - self.geometry = self.geometry.difference(prim_geo['geometry']) + self.geometry = difference(self.geometry, prim_geo['geometry']) continue - return self.geometry diff --git a/defaults.py b/defaults.py index f0779d7e..4043184e 100644 --- a/defaults.py +++ b/defaults.py @@ -24,7 +24,6 @@ class AppDefaults: factory_defaults = { # Global - "units": "MM", "version": 8.992, # defaults format version, not necessarily equal to app version "first_run": True, "root_folder_path": '', @@ -74,7 +73,8 @@ class AppDefaults: "global_tcl_path": '', # General APP Preferences - "decimals_metric": 4, + "units": "MM", + "units_precision": 4, "global_graphic_engine": '3D', "global_graphic_engine_3d_no_mp": False, "global_app_level": 'b',