diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 06ffbc72..3574dcfa 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -1002,6 +1002,10 @@ class App(QtCore.QObject): # Align Objects Tool "tools_align_objects_align_type": 'sp', + # Invert Gerber Tool + "tools_invert_margin": 0.1, + "tools_invert_join_style": 's', + # Utilities # file associations "fa_excellon": 'drd, drl, exc, ncd, tap, xln', @@ -1666,6 +1670,10 @@ class App(QtCore.QObject): "tools_punch_rectangular": self.ui.tools2_defaults_form.tools2_punch_group.rectangular_cb, "tools_punch_others": self.ui.tools2_defaults_form.tools2_punch_group.other_cb, + # Invert Gerber Tool + "tools_invert_margin": self.ui.tools2_defaults_form.tools2_invert_group.margin_entry, + "tools_invert_join_style": self.ui.tools2_defaults_form.tools2_invert_group.join_radio, + # Utilities # File associations "fa_excellon": self.ui.util_defaults_form.fa_excellon_group.exc_list_text, diff --git a/README.md b/README.md index 6ef6dff6..374c683c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ CAD program, and create G-Code for Isolation routing. - adjusted the UI for Excellon and Geometry objects - added a new FlatCAM Tool: Gerber Invert Tool. It will invert the copper features in a Gerber file: where is copper there will be empty and where is empty it will be copper +- added the Preferences entries for the Gerber Invert Tool 13.02.2020 diff --git a/flatcamGUI/PreferencesUI.py b/flatcamGUI/PreferencesUI.py index eeeb413a..df1c0021 100644 --- a/flatcamGUI/PreferencesUI.py +++ b/flatcamGUI/PreferencesUI.py @@ -252,6 +252,9 @@ class Tools2PreferencesUI(QtWidgets.QWidget): self.tools2_punch_group = Tools2PunchGerberPrefGroupUI(decimals=self.decimals) self.tools2_punch_group.setMinimumWidth(220) + self.tools2_invert_group = Tools2InvertPrefGroupUI(decimals=self.decimals) + self.tools2_invert_group.setMinimumWidth(220) + self.vlay = QtWidgets.QVBoxLayout() self.vlay.addWidget(self.tools2_checkrules_group) self.vlay.addWidget(self.tools2_optimal_group) @@ -269,6 +272,7 @@ class Tools2PreferencesUI(QtWidgets.QWidget): self.vlay4 = QtWidgets.QVBoxLayout() self.vlay4.addWidget(self.tools2_punch_group) + self.vlay4.addWidget(self.tools2_invert_group) self.layout.addLayout(self.vlay) self.layout.addLayout(self.vlay1) @@ -8239,6 +8243,62 @@ class Tools2PunchGerberPrefGroupUI(OptionsGroupUI): self.layout.addStretch() +class Tools2InvertPrefGroupUI(OptionsGroupUI): + def __init__(self, decimals=4, parent=None): + + super(Tools2InvertPrefGroupUI, self).__init__(self) + + self.setTitle(str(_("Invert Gerber Tool Options"))) + self.decimals = decimals + + # ## Subtractor Tool Parameters + self.sublabel = QtWidgets.QLabel("%s:" % _("Parameters")) + self.sublabel.setToolTip( + _("A tool to invert Gerber geometry from positive to negative\n" + "and in revers.") + ) + self.layout.addWidget(self.sublabel) + + # Grid Layout + grid0 = QtWidgets.QGridLayout() + grid0.setColumnStretch(0, 0) + grid0.setColumnStretch(1, 1) + self.layout.addLayout(grid0) + + # Margin + self.margin_label = QtWidgets.QLabel('%s:' % _('Margin')) + self.margin_label.setToolTip( + _("Distance by which to avoid\n" + "the edges of the Gerber object.") + ) + self.margin_entry = FCDoubleSpinner() + self.margin_entry.set_precision(self.decimals) + self.margin_entry.set_range(0.0000, 9999.9999) + self.margin_entry.setObjectName(_("Margin")) + + grid0.addWidget(self.margin_label, 2, 0, 1, 2) + grid0.addWidget(self.margin_entry, 3, 0, 1, 2) + + self.join_label = QtWidgets.QLabel('%s:' % _("Lines Join Style")) + self.join_label.setToolTip( + _("The way that the lines in the object outline will be joined.\n" + "Can be:\n" + "- rounded -> an arc is added between two joining lines\n" + "- square -> the lines meet in 90 degrees angle\n" + "- bevel -> the lines are joined by a third line") + ) + self.join_radio = RadioSet([ + {'label': 'Rounded', 'value': 'r'}, + {'label': 'Square', 'value': 's'}, + {'label': 'Bevel', 'value': 'b'} + ], orientation='vertical', stretch=False) + + grid0.addWidget(self.join_label, 5, 0, 1, 2) + grid0.addWidget(self.join_radio, 7, 0, 1, 2) + + self.layout.addStretch() + + class FAExcPrefGroupUI(OptionsGroupUI): def __init__(self, decimals=4, parent=None): # OptionsGroupUI.__init__(self, "Excellon File associations Preferences", parent=None) diff --git a/flatcamTools/ToolInvertGerber.py b/flatcamTools/ToolInvertGerber.py index 8d96419e..df1af676 100644 --- a/flatcamTools/ToolInvertGerber.py +++ b/flatcamTools/ToolInvertGerber.py @@ -8,14 +8,12 @@ from PyQt5 import QtWidgets, QtCore from FlatCAMTool import FlatCAMTool -from flatcamGUI.GUIElements import FCButton, FCDoubleSpinner +from flatcamGUI.GUIElements import FCButton, FCDoubleSpinner, RadioSet -from shapely.geometry import Polygon, MultiPolygon, MultiLineString, LineString, box -from shapely.ops import cascaded_union +from shapely.geometry import box -import traceback from copy import deepcopy -import time + import logging import gettext import FlatCAMTranslation as fcTranslate @@ -30,7 +28,7 @@ log = logging.getLogger('base') class ToolInvertGerber(FlatCAMTool): - toolName = _("Invert Tool") + toolName = _("Invert Gerber Tool") def __init__(self, app): self.app = app @@ -56,7 +54,7 @@ class ToolInvertGerber(FlatCAMTool): """) self.tools_box.addWidget(title_label) - # Form Layout + # Grid Layout grid0 = QtWidgets.QGridLayout() grid0.setColumnStretch(0, 0) grid0.setColumnStretch(1, 1) @@ -70,7 +68,7 @@ class ToolInvertGerber(FlatCAMTool): self.gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex())) self.gerber_combo.setCurrentIndex(1) - self.gerber_label = QtWidgets.QLabel('%s:' % _("Gerber Object")) + self.gerber_label = QtWidgets.QLabel('%s:' % _("GERBER")) self.gerber_label.setToolTip( _("Gerber object that will be inverted.") ) @@ -78,6 +76,13 @@ class ToolInvertGerber(FlatCAMTool): grid0.addWidget(self.gerber_label, 1, 0, 1, 2) grid0.addWidget(self.gerber_combo, 2, 0, 1, 2) + grid0.addWidget(QtWidgets.QLabel(""), 3, 0, 1, 2) + + self.param_label = QtWidgets.QLabel("%s:" % _("Parameters")) + self.param_label.setToolTip('%s.' % _("Parameters for this tool")) + + grid0.addWidget(self.param_label, 4, 0, 1, 2) + # Margin self.margin_label = QtWidgets.QLabel('%s:' % _('Margin')) self.margin_label.setToolTip( @@ -89,18 +94,35 @@ class ToolInvertGerber(FlatCAMTool): self.margin_entry.set_range(0.0000, 9999.9999) self.margin_entry.setObjectName(_("Margin")) - grid0.addWidget(self.margin_label, 3, 0) - grid0.addWidget(self.margin_entry, 3, 1) + grid0.addWidget(self.margin_label, 5, 0, 1, 2) + grid0.addWidget(self.margin_entry, 6, 0, 1, 2) + + self.join_label = QtWidgets.QLabel('%s:' % _("Lines Join Style")) + self.join_label.setToolTip( + _("The way that the lines in the object outline will be joined.\n" + "Can be:\n" + "- rounded -> an arc is added between two joining lines\n" + "- square -> the lines meet in 90 degrees angle\n" + "- bevel -> the lines are joined by a third line") + ) + self.join_radio = RadioSet([ + {'label': 'Rounded', 'value': 'r'}, + {'label': 'Square', 'value': 's'}, + {'label': 'Bevel', 'value': 'b'} + ], orientation='vertical', stretch=False) + + grid0.addWidget(self.join_label, 7, 0, 1, 2) + grid0.addWidget(self.join_radio, 8, 0, 1, 2) separator_line = QtWidgets.QFrame() separator_line.setFrameShape(QtWidgets.QFrame.HLine) separator_line.setFrameShadow(QtWidgets.QFrame.Sunken) - grid0.addWidget(separator_line, 4, 0, 1, 2) + grid0.addWidget(separator_line, 9, 0, 1, 2) self.invert_btn = FCButton(_('Invert Gerber')) self.invert_btn.setToolTip( _("Will invert the Gerber object: areas that have copper\n" - "will be emty of copper and previous empty area will be\n" + "will be empty of copper and previous empty area will be\n" "filled with copper.") ) self.invert_btn.setStyleSheet(""" @@ -109,7 +131,7 @@ class ToolInvertGerber(FlatCAMTool): font-weight: bold; } """) - grid0.addWidget(self.invert_btn, 5, 0, 1, 2) + grid0.addWidget(self.invert_btn, 10, 0, 1, 2) self.tools_box.addStretch() @@ -161,13 +183,18 @@ class ToolInvertGerber(FlatCAMTool): self.app.ui.notebook.setTabText(2, _("Invert Tool")) def set_tool_ui(self): - self.margin_entry.set_value(0.0) + self.margin_entry.set_value(float(self.app.defaults["tools_invert_margin"])) + self.join_radio.set_value(self.app.defaults["tools_invert_join_style"]) def on_grb_invert(self): margin = self.margin_entry.get_value() if round(margin, self.decimals) == 0.0: margin = 1E-10 + join_style = {'r': 1, 'b': 3, 's': 2}[self.join_radio.get_value()] + if join_style is None: + join_style = 'r' + grb_circle_steps = int(self.app.defaults["gerber_circle_steps"]) obj_name = self.gerber_combo.currentText() @@ -181,12 +208,14 @@ class ToolInvertGerber(FlatCAMTool): return "Could not retrieve object: %s with error: %s" % (obj_name, str(e)) if grb_obj is None: + if obj_name == '': + obj_name = 'None' self.app.inform.emit('[ERROR_NOTCL] %s: %s' % (_("Object not found"), str(obj_name))) return xmin, ymin, xmax, ymax = grb_obj.bounds() - grb_box = box(xmin, ymin, xmax, ymax).buffer(margin, resolution=grb_circle_steps, join_style=2) + grb_box = box(xmin, ymin, xmax, ymax).buffer(margin, resolution=grb_circle_steps, join_style=join_style) try: __ = iter(grb_obj.solid_geometry) diff --git a/flatcamTools/ToolPunchGerber.py b/flatcamTools/ToolPunchGerber.py index 2a5d8ef4..282c20d4 100644 --- a/flatcamTools/ToolPunchGerber.py +++ b/flatcamTools/ToolPunchGerber.py @@ -515,7 +515,9 @@ class ToolPunchGerber(FlatCAMTool): punch_method = self.method_punch.get_value() - new_options = deepcopy(grb_obj.options) + new_options = dict() + for opt in grb_obj.options: + new_options[opt] = deepcopy(grb_obj.options[opt]) if punch_method == 'exc':