From 2e7d9f953f306f40e0c8d8ee32583b6a55ae5866 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sun, 14 Apr 2019 22:46:08 +0300 Subject: [PATCH] - solved bug in Gerber apertures size and dimensions values conversion when file units are different than app units --- README.md | 1 + camlib.py | 14 +++++++++++++- flatcamEditors/FlatCAMGrbEditor.py | 11 +++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index adf9c96a..80f9c49d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ CAD program, and create G-Code for Isolation routing. - moved the key handler out of the Measurement tool to flatcamGUI.FlatCAMGui.keyPressEvent() - Gerber Editor: started to add new function of poligonize which should make a filled polygon out of a shape - cleaned up Measuring Tool +- solved bug in Gerber apertures size and dimensions values conversion when file units are different than app units 13.04.2019 diff --git a/camlib.py b/camlib.py index ec598154..6f46b161 100644 --- a/camlib.py +++ b/camlib.py @@ -2162,6 +2162,9 @@ class Gerber (Geometry): # Coordinates of the current path, each is [x, y] path = [] + # store the file units here: + gerber_units = 'IN' + # this is for temporary storage of geometry until it is added to poly_buffer geo = None @@ -3180,6 +3183,13 @@ class Gerber (Geometry): self.apertures[last_path_aperture]['solid_geometry'] = [] self.apertures[last_path_aperture]['solid_geometry'].append(geo) + # TODO: make sure to keep track of units changes because right now it seems to happen in a weird way + # find out the conversion factor used to convert inside the self.apertures keys: size, width, height + file_units = gerber_units if gerber_units else 'IN' + app_units = self.app.defaults['units'] + + conversion_factor = 25.4 if file_units == 'IN' else (1/25.4) if file_units != app_units else 1 + # first check if we have any clear_geometry (LPC) and if yes then we need to substract it # from the apertures solid_geometry temp_geo = [] @@ -3195,7 +3205,9 @@ class Gerber (Geometry): self.apertures[apid]['solid_geometry'] = deepcopy(temp_geo) self.apertures[apid].pop('clear_geometry', None) - + for k, v in self.apertures[apid].items(): + if k == 'size' or k == 'width' or k == 'height': + self.apertures[apid][k] = v * conversion_factor # --- Apply buffer --- # this treats the case when we are storing geometry as paths diff --git a/flatcamEditors/FlatCAMGrbEditor.py b/flatcamEditors/FlatCAMGrbEditor.py index 16d7b5e2..9770f25b 100644 --- a/flatcamEditors/FlatCAMGrbEditor.py +++ b/flatcamEditors/FlatCAMGrbEditor.py @@ -1570,15 +1570,15 @@ class FlatCAMGrbEditor(QtCore.QObject): if str(self.storage_dict[ap_code]['type']) == 'R' or str(self.storage_dict[ap_code]['type']) == 'O': ap_dim_item = QtWidgets.QTableWidgetItem( - '%.4f, %.4f' % (self.storage_dict[ap_code]['width'] * self.gerber_obj.file_units_factor, - self.storage_dict[ap_code]['height'] * self.gerber_obj.file_units_factor + '%.4f, %.4f' % (self.storage_dict[ap_code]['width'], + self.storage_dict[ap_code]['height'] ) ) ap_dim_item.setFlags(QtCore.Qt.ItemIsEnabled) elif str(self.storage_dict[ap_code]['type']) == 'P': ap_dim_item = QtWidgets.QTableWidgetItem( - '%.4f, %.4f' % (self.storage_dict[ap_code]['diam'] * self.gerber_obj.file_units_factor, - self.storage_dict[ap_code]['nVertices'] * self.gerber_obj.file_units_factor) + '%.4f, %.4f' % (self.storage_dict[ap_code]['diam'], + self.storage_dict[ap_code]['nVertices']) ) ap_dim_item.setFlags(QtCore.Qt.ItemIsEnabled) else: @@ -1588,8 +1588,7 @@ class FlatCAMGrbEditor(QtCore.QObject): try: if self.storage_dict[ap_code]['size'] is not None: ap_size_item = QtWidgets.QTableWidgetItem('%.4f' % - float(self.storage_dict[ap_code]['size'] * - self.gerber_obj.file_units_factor)) + float(self.storage_dict[ap_code]['size'])) else: ap_size_item = QtWidgets.QTableWidgetItem('') except KeyError: