From ce666e2dbf626f2833f90f15300a7d735170280e Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Tue, 1 Oct 2019 15:08:49 +0300 Subject: [PATCH] - added a fix in the Gerber parser to work even when there is no information about zero suppression in the Gerber file - added new settings in Edit -> Preferences -> Gerber for Gerber Units and Gerber Zeros to be used as defaults in case that those informations are missing from the Gerber file --- FlatCAMApp.py | 4 +++ README.md | 4 ++- camlib.py | 23 ++++++++-------- flatcamGUI/PreferencesUI.py | 52 ++++++++++++++++++++++++++++++++++++- 4 files changed, 70 insertions(+), 13 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 440f3909..dfa46455 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -500,6 +500,8 @@ class App(QtCore.QObject): "gerber_solid": self.ui.gerber_defaults_form.gerber_gen_group.solid_cb, "gerber_multicolored": self.ui.gerber_defaults_form.gerber_gen_group.multicolored_cb, "gerber_circle_steps": self.ui.gerber_defaults_form.gerber_gen_group.circle_steps_entry, + "gerber_def_units": self.ui.gerber_defaults_form.gerber_gen_group.gerber_units_radio, + "gerber_def_zeros": self.ui.gerber_defaults_form.gerber_gen_group.gerber_zeros_radio, # Gerber Options "gerber_isotooldia": self.ui.gerber_defaults_form.gerber_opt_group.iso_tool_dia_entry, @@ -922,6 +924,8 @@ class App(QtCore.QObject): "gerber_multicolored": False, "gerber_circle_steps": 128, "gerber_use_buffer_for_union": True, + "gerber_def_units": 'IN', + "gerber_def_zeros": 'L', # Gerber Options "gerber_isotooldia": 0.00787402, diff --git a/README.md b/README.md index 422ccc56..eb4da546 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ CAD program, and create G-Code for Isolation routing. - fixed the FCSpinner and FCDoubleSpinner GUI elements to select all on first click and deselect on second click in the Spinbox LineEdit - for Gerber object in Selected Tab added ability to chose a V-Shape tool and therefore control the isolation better by adjusting the cut width of the isolation in function of the cut depth, tip width of the tool and the tip angle of the tool -- when in Gerber UI is selectd the V-Shape tool, all those parameters (tip dia, dip angle, tool_type = 'V' and cut Z) are transferred to the generated Geometry and prefilled in the Geoemtry UI +- when in Gerber UI is selected the V-Shape tool, all those parameters (tip dia, dip angle, tool_type = 'V' and cut Z) are transferred to the generated Geometry and prefilled in the Geoemtry UI +- added a fix in the Gerber parser to work even when there is no information about zero suppression in the Gerber file +- added new settings in Edit -> Preferences -> Gerber for Gerber Units and Gerber Zeros to be used as defaults in case that those informations are missing from the Gerber file 30.09.2019 diff --git a/camlib.py b/camlib.py index c229a6de..78902f29 100644 --- a/camlib.py +++ b/camlib.py @@ -2142,7 +2142,7 @@ class Gerber (Geometry): self.frac_digits = 4 """Number of fraction digits in Gerber numbers. Used during parsing.""" - self.gerber_zeros = 'L' + self.gerber_zeros = self.app.defaults['gerber_def_zeros'] """Zeros in Gerber numbers. If 'L' then remove leading zeros, if 'T' remove trailing zeros. Used during parsing. """ @@ -2166,7 +2166,7 @@ class Gerber (Geometry): ''' # store the file units here: - self.gerber_units = 'IN' + self.gerber_units = self.app.defaults['gerber_def_units'] # aperture storage self.apertures = {} @@ -2197,9 +2197,9 @@ class Gerber (Geometry): # The format of X and Y must be the same! # L-omit leading zeros, T-omit trailing zeros, D-no zero supression # A-absolute notation, I-incremental notation - self.fmt_re = re.compile(r'%?FS([LTD])([AI])X(\d)(\d)Y\d\d\*%?$') - self.fmt_re_alt = re.compile(r'%FS([LT])([AI])X(\d)(\d)Y\d\d\*MO(IN|MM)\*%$') - self.fmt_re_orcad = re.compile(r'(G\d+)*\**%FS([LT])([AI]).*X(\d)(\d)Y\d\d\*%$') + self.fmt_re = re.compile(r'%?FS([LTD])?([AI])X(\d)(\d)Y\d\d\*%?$') + self.fmt_re_alt = re.compile(r'%FS([LTD])?([AI])X(\d)(\d)Y\d\d\*MO(IN|MM)\*%$') + self.fmt_re_orcad = re.compile(r'(G\d+)*\**%FS([LTD])?([AI]).*X(\d)(\d)Y\d\d\*%$') # Mode (IN/MM) self.mode_re = re.compile(r'^%?MO(IN|MM)\*%?$') @@ -2408,9 +2408,6 @@ class Gerber (Geometry): # Coordinates of the current path, each is [x, y] path = [] - # store the file units here: - self.gerber_units = 'IN' - # this is for temporary storage of solid geometry until it is added to poly_buffer geo_s = None @@ -2555,7 +2552,8 @@ class Gerber (Geometry): match = self.fmt_re.search(gline) if match: absolute = {'A': 'Absolute', 'I': 'Relative'}[match.group(2)] - self.gerber_zeros = match.group(1) + if match.group(1) is not None: + self.gerber_zeros = match.group(1) self.int_digits = int(match.group(3)) self.frac_digits = int(match.group(4)) log.debug("Gerber format found. (%s) " % str(gline)) @@ -2582,7 +2580,8 @@ class Gerber (Geometry): match = self.fmt_re_alt.search(gline) if match: absolute = {'A': 'Absolute', 'I': 'Relative'}[match.group(2)] - self.gerber_zeros = match.group(1) + if match.group(1) is not None: + self.gerber_zeros = match.group(1) self.int_digits = int(match.group(3)) self.frac_digits = int(match.group(4)) log.debug("Gerber format found. (%s) " % str(gline)) @@ -2608,7 +2607,9 @@ class Gerber (Geometry): elif match.group(1) == 'G75': quadrant_mode = 'MULTI' absolute = {'A': 'Absolute', 'I': 'Relative'}[match.group(3)] - self.gerber_zeros = match.group(2) + if match.group(2) is not None: + self.gerber_zeros = match.group(2) + self.int_digits = int(match.group(4)) self.frac_digits = int(match.group(5)) log.debug("Gerber format found. (%s) " % str(gline)) diff --git a/flatcamGUI/PreferencesUI.py b/flatcamGUI/PreferencesUI.py index baa46091..93ede36d 100644 --- a/flatcamGUI/PreferencesUI.py +++ b/flatcamGUI/PreferencesUI.py @@ -1115,7 +1115,57 @@ class GerberGenPrefGroupUI(OptionsGroupUI): ) self.circle_steps_entry = IntEntry() grid0.addWidget(self.circle_steps_label, 1, 0) - grid0.addWidget(self.circle_steps_entry, 1, 1) + grid0.addWidget(self.circle_steps_entry, 1, 1, 1, 2) + + grid0.addWidget(QtWidgets.QLabel(''), 2, 0, 1, 3) + + # Default format for Gerber + self.gerber_default_label = QtWidgets.QLabel('%s:' % _('Default Values')) + self.gerber_default_label.setToolTip( + _("Those values will be used as fallback values\n" + "in case that they are not found in the Gerber file.") + ) + + grid0.addWidget(self.gerber_default_label, 3, 0, 1, 3) + + # Gerber Units + self.gerber_units_label = QtWidgets.QLabel('%s:' % _('Units')) + self.gerber_units_label.setToolTip( + _("The units used in the Gerber file.") + ) + + self.gerber_units_radio = RadioSet([{'label': _('INCH'), 'value': 'IN'}, + {'label': _('MM'), 'value': 'MM'}]) + self.gerber_units_radio.setToolTip( + _("The units used in the Gerber file.") + ) + + grid0.addWidget(self.gerber_units_label, 4, 0) + grid0.addWidget(self.gerber_units_radio, 4, 1, 1, 2) + + # Gerber Zeros + self.gerber_zeros_label = QtWidgets.QLabel('%s:' % _('Zeros')) + self.gerber_zeros_label.setAlignment(QtCore.Qt.AlignLeft) + self.gerber_zeros_label.setToolTip( + _("This sets the type of Gerber zeros.\n" + "If LZ then Leading Zeros are removed and\n" + "Trailing Zeros are kept.\n" + "If TZ is checked then Trailing Zeros are removed\n" + "and Leading Zeros are kept.") + ) + + self.gerber_zeros_radio = RadioSet([{'label': _('LZ'), 'value': 'L'}, + {'label': _('TZ'), 'value': 'T'}]) + self.gerber_zeros_radio.setToolTip( + _("This sets the type of Gerber zeros.\n" + "If LZ then Leading Zeros are removed and\n" + "Trailing Zeros are kept.\n" + "If TZ is checked then Trailing Zeros are removed\n" + "and Leading Zeros are kept.") + ) + + grid0.addWidget(self.gerber_zeros_label, 5, 0) + grid0.addWidget(self.gerber_zeros_radio, 5, 1, 1, 2) self.layout.addStretch()