From cb7bcf257fa00a02ea5662a21c3e281e7f4b87a7 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sat, 23 Apr 2022 18:12:43 +0300 Subject: [PATCH] - fixed some leftovers due of recent changes in the theme management - added a new feature (new modules are required) in the Image Plugin (Menu -> File -> Import -> Import Image) that allow tracing images. This may allow engraving pictures. - started to add UI's for the Excellon Editor Tools (really early work) --- CHANGELOG.md | 6 + appEditors/exc_plugins/ExcCopyPlugin.py | 545 +++++++++++++++ appEditors/exc_plugins/ExcDrillArrayPlugin.py | 545 +++++++++++++++ appEditors/exc_plugins/ExcGenPlugin.py | 156 +++++ appEditors/exc_plugins/ExcScalePlugin.py | 0 appEditors/exc_plugins/ExcSlotArrayPlugin.py | 545 +++++++++++++++ appEditors/geo_plugins/GeoStitchPlugin.py | 0 appGUI/MainGUI.py | 4 +- appGUI/PlotCanvasLegacy.py | 6 +- appMain.py | 3 +- appObjects/AppObjectTemplate.py | 2 +- appObjects/GerberObject.py | 2 +- appPlugins/ToolImage.py | 656 ++++++++++++++++-- appPlugins/ToolReport.py | 2 +- camlib.py | 2 +- requirements.txt | 1 + setup_ubuntu.sh | 4 +- 17 files changed, 2399 insertions(+), 80 deletions(-) create mode 100644 appEditors/exc_plugins/ExcCopyPlugin.py create mode 100644 appEditors/exc_plugins/ExcDrillArrayPlugin.py create mode 100644 appEditors/exc_plugins/ExcGenPlugin.py create mode 100644 appEditors/exc_plugins/ExcScalePlugin.py create mode 100644 appEditors/exc_plugins/ExcSlotArrayPlugin.py create mode 100644 appEditors/geo_plugins/GeoStitchPlugin.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e53c371..d71ad62c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ CHANGELOG for FlatCAM Evo beta ================================================= +23.04.2022 + +- fixed some leftovers due of recent changes in the theme management +- added a new feature (new modules are required) in the Image Plugin (Menu -> File -> Import -> Import Image) that allow tracing images. This may allow engraving pictures. +- started to add UI's for the Excellon Editor Tools (really early work) + 20.04.2022 - in Solderpaste Plugin fixed the GCode generation; make sure that if no object is selected then the first Gerber object is autoselected diff --git a/appEditors/exc_plugins/ExcCopyPlugin.py b/appEditors/exc_plugins/ExcCopyPlugin.py new file mode 100644 index 00000000..e7a36c37 --- /dev/null +++ b/appEditors/exc_plugins/ExcCopyPlugin.py @@ -0,0 +1,545 @@ + +from appTool import * + +fcTranslate.apply_language('strings') +if '_' not in builtins.__dict__: + _ = gettext.gettext + + +class ExcCopyEditorTool(AppTool): + """ + Copy Plugin + """ + + def __init__(self, app, draw_app, plugin_name): + AppTool.__init__(self, app) + + self.draw_app = draw_app + self.decimals = app.decimals + self.plugin_name = plugin_name + + self.ui = ExcCopyEditorUI(layout=self.layout, copy_class=self, plugin_name=plugin_name) + + self.connect_signals_at_init() + self.set_tool_ui() + + def connect_signals_at_init(self): + # Signals + self.ui.clear_btn.clicked.connect(self.on_clear) + + def disconnect_signals(self): + # Signals + try: + self.ui.clear_btn.clicked.disconnect() + except (TypeError, AttributeError): + pass + + def run(self): + self.app.defaults.report_usage("Geo Editor CopyTool()") + AppTool.run(self) + + # if the splitter us hidden, display it + if self.app.ui.splitter.sizes()[0] == 0: + self.app.ui.splitter.setSizes([1, 1]) + + # if the Tool Tab is hidden display it, else hide it but only if the objectName is the same + found_idx = None + for idx in range(self.app.ui.notebook.count()): + if self.app.ui.notebook.widget(idx).objectName() == "plugin_tab": + found_idx = idx + break + # show the Tab + if not found_idx: + try: + self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin")) + except RuntimeError: + self.app.ui.plugin_tab = QtWidgets.QWidget() + self.app.ui.plugin_tab.setObjectName("plugin_tab") + self.app.ui.plugin_tab_layout = QtWidgets.QVBoxLayout(self.app.ui.plugin_tab) + self.app.ui.plugin_tab_layout.setContentsMargins(2, 2, 2, 2) + + self.app.ui.plugin_scroll_area = VerticalScrollArea() + self.app.ui.plugin_tab_layout.addWidget(self.app.ui.plugin_scroll_area) + self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin")) + + # focus on Tool Tab + self.app.ui.notebook.setCurrentWidget(self.app.ui.plugin_tab) + + # self.app.ui.notebook.callback_on_close = self.on_tab_close + + self.app.ui.notebook.setTabText(2, self.plugin_name) + + def set_tool_ui(self): + # Init appGUI + self.length = 0.0 + self.ui.mode_radio.set_value('n') + self.ui.on_copy_mode(self.ui.mode_radio.get_value()) + self.ui.array_type_radio.set_value('linear') + self.ui.on_array_type_radio(self.ui.array_type_radio.get_value()) + self.ui.axis_radio.set_value('X') + self.ui.on_linear_angle_radio(self.ui.axis_radio.get_value()) + + self.ui.array_dir_radio.set_value('CW') + + self.ui.placement_radio.set_value('s') + self.ui.on_placement_radio(self.ui.placement_radio.get_value()) + + self.ui.spacing_rows.set_value(0) + self.ui.spacing_columns.set_value(0) + self.ui.rows.set_value(1) + self.ui.columns.set_value(1) + self.ui.offsetx_entry.set_value(0) + self.ui.offsety_entry.set_value(0) + + def on_tab_close(self): + self.disconnect_signals() + self.hide_tool() + # self.app.ui.notebook.callback_on_close = lambda: None + + def on_clear(self): + self.set_tool_ui() + + @property + def length(self): + return self.ui.project_line_entry.get_value() + + @length.setter + def length(self, val): + self.ui.project_line_entry.set_value(val) + + def hide_tool(self): + self.ui.copy_frame.hide() + self.app.ui.notebook.setCurrentWidget(self.app.ui.properties_tab) + if self.draw_app.active_tool.name != 'select': + self.draw_app.select_tool("select") + + +class ExcCopyEditorUI: + + def __init__(self, layout, copy_class, plugin_name): + self.pluginName = plugin_name + self.copy_class = copy_class + self.decimals = self.copy_class.app.decimals + self.layout = layout + self.app = self.copy_class.app + + # Title + title_label = FCLabel("%s" % ('Editor ' + self.pluginName)) + title_label.setStyleSheet(""" + QLabel + { + font-size: 16px; + font-weight: bold; + } + """) + self.layout.addWidget(title_label) + + # this way I can hide/show the frame + self.copy_frame = QtWidgets.QFrame() + self.copy_frame.setContentsMargins(0, 0, 0, 0) + self.layout.addWidget(self.copy_frame) + self.copy_tool_box = QtWidgets.QVBoxLayout() + self.copy_tool_box.setContentsMargins(0, 0, 0, 0) + self.copy_frame.setLayout(self.copy_tool_box) + + # Grid Layout + grid0 = GLay(v_spacing=5, h_spacing=3) + self.copy_tool_box.addLayout(grid0) + + # Project distance + self.project_line_lbl = FCLabel('%s:' % _("Length")) + self.project_line_lbl.setToolTip( + _("Length of the current segment/move.") + ) + self.project_line_entry = NumericalEvalEntry(border_color='#0069A9') + grid0.addWidget(self.project_line_lbl, 0, 0) + grid0.addWidget(self.project_line_entry, 0, 1) + + self.clear_btn = FCButton(_("Clear")) + grid0.addWidget(self.clear_btn, 2, 0, 1, 2) + + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) + grid0.addWidget(separator_line, 4, 0, 1, 2) + + # Type of Array + self.mode_label = FCLabel('%s:' % _("Mode"), bold=True) + self.mode_label.setToolTip( + _("Single copy or special (array of copies)") + ) + self.mode_radio = RadioSet([ + {'label': _('Single'), 'value': 'n'}, + {'label': _('Array'), 'value': 'a'} + ]) + + grid0.addWidget(self.mode_label, 6, 0) + grid0.addWidget(self.mode_radio, 6, 1) + + # ############################################################################################################# + # ######################################## Add Array ########################################################## + # ############################################################################################################# + # add a frame and inside add a grid box layout. + self.array_frame = FCFrame() + # self.array_frame.setContentsMargins(0, 0, 0, 0) + self.layout.addWidget(self.array_frame) + + self.array_grid = GLay(v_spacing=5, h_spacing=3) + # self.array_grid.setContentsMargins(0, 0, 0, 0) + self.array_frame.setLayout(self.array_grid) + + # Set the number of items in the array + self.array_size_label = FCLabel('%s:' % _('Size')) + self.array_size_label.setToolTip(_("Specify how many items to be in the array.")) + + self.array_size_entry = FCSpinner(policy=False) + self.array_size_entry.set_range(1, 100000) + + self.array_grid.addWidget(self.array_size_label, 2, 0) + self.array_grid.addWidget(self.array_size_entry, 2, 1) + + # Array Type + array_type_lbl = FCLabel('%s:' % _("Type")) + array_type_lbl.setToolTip( + _("Select the type of array to create.\n" + "It can be Linear X(Y) or Circular") + ) + + self.array_type_radio = RadioSet([ + {'label': _('Linear'), 'value': 'linear'}, + {'label': _('2D'), 'value': '2D'}, + {'label': _('Circular'), 'value': 'circular'} + ]) + + self.array_grid.addWidget(array_type_lbl, 4, 0) + self.array_grid.addWidget(self.array_type_radio, 4, 1) + + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) + self.array_grid.addWidget(separator_line, 6, 0, 1, 2) + + # ############################################################################################################# + # ############################ LINEAR Array ################################################################### + # ############################################################################################################# + self.array_linear_frame = QtWidgets.QFrame() + self.array_linear_frame.setContentsMargins(0, 0, 0, 0) + self.array_grid.addWidget(self.array_linear_frame, 8, 0, 1, 2) + + self.lin_grid = GLay(v_spacing=5, h_spacing=3) + self.lin_grid.setContentsMargins(0, 0, 0, 0) + self.array_linear_frame.setLayout(self.lin_grid) + + # Linear Drill Array direction + self.axis_label = FCLabel('%s:' % _('Direction')) + self.axis_label.setToolTip( + _("Direction on which the linear array is oriented:\n" + "- 'X' - horizontal axis \n" + "- 'Y' - vertical axis or \n" + "- 'Angle' - a custom angle for the array inclination") + ) + + self.axis_radio = RadioSet([ + {'label': _('X'), 'value': 'X'}, + {'label': _('Y'), 'value': 'Y'}, + {'label': _('Angle'), 'value': 'A'} + ]) + + self.lin_grid.addWidget(self.axis_label, 0, 0) + self.lin_grid.addWidget(self.axis_radio, 0, 1) + + # Linear Array pitch distance + self.pitch_label = FCLabel('%s:' % _('Pitch')) + self.pitch_label.setToolTip( + _("Pitch = Distance between elements of the array.") + ) + + self.pitch_entry = FCDoubleSpinner(policy=False) + self.pitch_entry.set_precision(self.decimals) + self.pitch_entry.set_range(0.0000, 10000.0000) + + self.lin_grid.addWidget(self.pitch_label, 2, 0) + self.lin_grid.addWidget(self.pitch_entry, 2, 1) + + # Linear Array angle + self.linear_angle_label = FCLabel('%s:' % _('Angle')) + self.linear_angle_label.setToolTip( + _("Angle at which the linear array is placed.\n" + "The precision is of max 2 decimals.\n" + "Min value is: -360.00 degrees.\n" + "Max value is: 360.00 degrees.") + ) + + self.linear_angle_spinner = FCDoubleSpinner(policy=False) + self.linear_angle_spinner.set_precision(self.decimals) + self.linear_angle_spinner.setSingleStep(1.0) + self.linear_angle_spinner.setRange(-360.00, 360.00) + + self.lin_grid.addWidget(self.linear_angle_label, 4, 0) + self.lin_grid.addWidget(self.linear_angle_spinner, 4, 1) + + # ############################################################################################################# + # ################################ 2D Array ################################################################### + # ############################################################################################################# + self.two_dim_array_frame = QtWidgets.QFrame() + self.two_dim_array_frame.setContentsMargins(0, 0, 0, 0) + self.array_grid.addWidget(self.two_dim_array_frame, 10, 0, 1, 2) + + self.dd_grid = GLay(v_spacing=5, h_spacing=3) + self.dd_grid.setContentsMargins(0, 0, 0, 0) + self.two_dim_array_frame.setLayout(self.dd_grid) + + # 2D placement + self.place_label = FCLabel('%s:' % _('Placement')) + self.place_label.setToolTip( + _("Placement of array items:\n" + "'Spacing' - define space between rows and columns \n" + "'Offset' - each row (and column) will be placed at a multiple of a value, from origin") + ) + + self.placement_radio = RadioSet([ + {'label': _('Spacing'), 'value': 's'}, + {'label': _('Offset'), 'value': 'o'} + ]) + + self.dd_grid.addWidget(self.place_label, 0, 0) + self.dd_grid.addWidget(self.placement_radio, 0, 1) + + # Rows + self.rows = FCSpinner(callback=self.confirmation_message_int) + self.rows.set_range(0, 10000) + + self.rows_label = FCLabel('%s:' % _("Rows")) + self.rows_label.setToolTip( + _("Number of rows") + ) + self.dd_grid.addWidget(self.rows_label, 2, 0) + self.dd_grid.addWidget(self.rows, 2, 1) + + # Columns + self.columns = FCSpinner(callback=self.confirmation_message_int) + self.columns.set_range(0, 10000) + + self.columns_label = FCLabel('%s:' % _("Columns")) + self.columns_label.setToolTip( + _("Number of columns") + ) + self.dd_grid.addWidget(self.columns_label, 4, 0) + self.dd_grid.addWidget(self.columns, 4, 1) + + # ------------------------------------------------ + # ############## Spacing Frame ################# + # ------------------------------------------------ + self.spacing_frame = QtWidgets.QFrame() + self.spacing_frame.setContentsMargins(0, 0, 0, 0) + self.dd_grid.addWidget(self.spacing_frame, 6, 0, 1, 2) + + self.s_grid = GLay(v_spacing=5, h_spacing=3) + self.s_grid.setContentsMargins(0, 0, 0, 0) + self.spacing_frame.setLayout(self.s_grid) + + # Spacing Rows + self.spacing_rows = FCDoubleSpinner(callback=self.confirmation_message) + self.spacing_rows.set_range(0, 9999) + self.spacing_rows.set_precision(4) + + self.spacing_rows_label = FCLabel('%s:' % _("Spacing rows")) + self.spacing_rows_label.setToolTip( + _("Spacing between rows.\n" + "In current units.") + ) + self.s_grid.addWidget(self.spacing_rows_label, 0, 0) + self.s_grid.addWidget(self.spacing_rows, 0, 1) + + # Spacing Columns + self.spacing_columns = FCDoubleSpinner(callback=self.confirmation_message) + self.spacing_columns.set_range(0, 9999) + self.spacing_columns.set_precision(4) + + self.spacing_columns_label = FCLabel('%s:' % _("Spacing cols")) + self.spacing_columns_label.setToolTip( + _("Spacing between columns.\n" + "In current units.") + ) + self.s_grid.addWidget(self.spacing_columns_label, 2, 0) + self.s_grid.addWidget(self.spacing_columns, 2, 1) + + # ------------------------------------------------ + # ############## Offset Frame ################## + # ------------------------------------------------ + self.offset_frame = QtWidgets.QFrame() + self.offset_frame.setContentsMargins(0, 0, 0, 0) + self.dd_grid.addWidget(self.offset_frame, 8, 0, 1, 2) + + self.o_grid = GLay(v_spacing=5, h_spacing=3) + self.o_grid.setContentsMargins(0, 0, 0, 0) + self.offset_frame.setLayout(self.o_grid) + + # Offset X Value + self.offsetx_label = FCLabel('%s X:' % _("Offset")) + self.offsetx_label.setToolTip( + _("'Offset' - each row (and column) will be placed at a multiple of a value, from origin") + ) + + self.offsetx_entry = FCDoubleSpinner(policy=False) + self.offsetx_entry.set_precision(self.decimals) + self.offsetx_entry.set_range(0.0000, 10000.0000) + + self.o_grid.addWidget(self.offsetx_label, 0, 0) + self.o_grid.addWidget(self.offsetx_entry, 0, 1) + + # Offset Y Value + self.offsety_label = FCLabel('%s Y:' % _("Offset")) + self.offsety_label.setToolTip( + _("'Offset' - each row (and column) will be placed at a multiple of a value, from origin") + ) + + self.offsety_entry = FCDoubleSpinner(policy=False) + self.offsety_entry.set_precision(self.decimals) + self.offsety_entry.set_range(0.0000, 10000.0000) + + self.o_grid.addWidget(self.offsety_label, 2, 0) + self.o_grid.addWidget(self.offsety_entry, 2, 1) + + # ############################################################################################################# + # ############################ CIRCULAR Array ################################################################# + # ############################################################################################################# + self.array_circular_frame = QtWidgets.QFrame() + self.array_circular_frame.setContentsMargins(0, 0, 0, 0) + self.array_grid.addWidget(self.array_circular_frame, 12, 0, 1, 2) + + self.circ_grid = GLay(v_spacing=5, h_spacing=3) + self.circ_grid.setContentsMargins(0, 0, 0, 0) + self.array_circular_frame.setLayout(self.circ_grid) + + # Array Direction + self.array_dir_lbl = FCLabel('%s:' % _('Direction')) + self.array_dir_lbl.setToolTip( + _("Direction for circular array.\n" + "Can be CW = clockwise or CCW = counter clockwise.")) + + self.array_dir_radio = RadioSet([ + {'label': _('CW'), 'value': 'CW'}, + {'label': _('CCW'), 'value': 'CCW'}]) + + self.circ_grid.addWidget(self.array_dir_lbl, 0, 0) + self.circ_grid.addWidget(self.array_dir_radio, 0, 1) + + # Array Angle + self.array_angle_lbl = FCLabel('%s:' % _('Angle')) + self.array_angle_lbl.setToolTip(_("Angle at which each element in circular array is placed.")) + + self.angle_entry = FCDoubleSpinner(policy=False) + self.angle_entry.set_precision(self.decimals) + self.angle_entry.setSingleStep(1.0) + self.angle_entry.setRange(-360.00, 360.00) + + self.circ_grid.addWidget(self.array_angle_lbl, 2, 0) + self.circ_grid.addWidget(self.angle_entry, 2, 1) + + # Buttons + self.add_button = FCButton(_("Add")) + self.add_button.setIcon(QtGui.QIcon(self.app.resource_location + '/plus16.png')) + self.layout.addWidget(self.add_button) + + GLay.set_common_column_size([ + grid0, self.array_grid, self.lin_grid, self.dd_grid, self.circ_grid, self.s_grid, self.o_grid + ], 0) + + self.layout.addStretch(1) + + # Signals + self.mode_radio.activated_custom.connect(self.on_copy_mode) + self.array_type_radio.activated_custom.connect(self.on_array_type_radio) + self.axis_radio.activated_custom.connect(self.on_linear_angle_radio) + self.placement_radio.activated_custom.connect(self.on_placement_radio) + + def confirmation_message(self, accepted, minval, maxval): + if accepted is False: + self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"), + self.decimals, + minval, + self.decimals, + maxval), False) + + def confirmation_message_int(self, accepted, minval, maxval): + if accepted is False: + self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' % + (_("Edited value is out of range"), minval, maxval), False) + + def on_copy_mode(self, val): + if val == 'n': + self.array_frame.hide() + self.app.inform.emit(_("Click on reference location ...")) + else: + self.array_frame.show() + + def on_array_type_radio(self, val): + if val == '2D': + self.array_circular_frame.hide() + self.array_linear_frame.hide() + self.two_dim_array_frame.show() + if self.placement_radio.get_value() == 's': + self.spacing_frame.show() + self.offset_frame.hide() + else: + self.spacing_frame.hide() + self.offset_frame.show() + + self.array_size_entry.setDisabled(True) + self.on_rows_cols_value_changed() + + self.rows.valueChanged.connect(self.on_rows_cols_value_changed) + self.columns.valueChanged.connect(self.on_rows_cols_value_changed) + + self.app.inform.emit(_("Click on reference location ...")) + else: + if val == 'linear': + self.array_circular_frame.hide() + self.array_linear_frame.show() + self.two_dim_array_frame.hide() + self.spacing_frame.hide() + self.offset_frame.hide() + + self.app.inform.emit(_("Click on reference location ...")) + else: # 'circular' + self.array_circular_frame.show() + self.array_linear_frame.hide() + self.two_dim_array_frame.hide() + self.spacing_frame.hide() + self.offset_frame.hide() + + self.app.inform.emit(_("Click on the circular array Center position")) + + self.array_size_entry.setDisabled(False) + try: + self.rows.valueChanged.disconnect() + except (TypeError, AttributeError): + pass + + try: + self.columns.valueChanged.disconnect() + except (TypeError, AttributeError): + pass + + def on_rows_cols_value_changed(self): + new_size = self.rows.get_value() * self.columns.get_value() + if new_size == 0: + new_size = 1 + self.array_size_entry.set_value(new_size) + + def on_linear_angle_radio(self, val): + if val == 'A': + self.linear_angle_spinner.show() + self.linear_angle_label.show() + else: + self.linear_angle_spinner.hide() + self.linear_angle_label.hide() + + def on_placement_radio(self, val): + if val == 's': + self.spacing_frame.show() + self.offset_frame.hide() + else: + self.spacing_frame.hide() + self.offset_frame.show() diff --git a/appEditors/exc_plugins/ExcDrillArrayPlugin.py b/appEditors/exc_plugins/ExcDrillArrayPlugin.py new file mode 100644 index 00000000..d4eb9449 --- /dev/null +++ b/appEditors/exc_plugins/ExcDrillArrayPlugin.py @@ -0,0 +1,545 @@ + +from appTool import * + +fcTranslate.apply_language('strings') +if '_' not in builtins.__dict__: + _ = gettext.gettext + + +class ExcDrillArrayEditorTool(AppTool): + """ + Create an array of drill holes + """ + + def __init__(self, app, draw_app, plugin_name): + AppTool.__init__(self, app) + + self.draw_app = draw_app + self.decimals = app.decimals + self.plugin_name = plugin_name + + self.ui = ExcDrillArrayEditorUI(layout=self.layout, copy_class=self, plugin_name=plugin_name) + + self.connect_signals_at_init() + self.set_tool_ui() + + def connect_signals_at_init(self): + # Signals + self.ui.clear_btn.clicked.connect(self.on_clear) + + def disconnect_signals(self): + # Signals + try: + self.ui.clear_btn.clicked.disconnect() + except (TypeError, AttributeError): + pass + + def run(self): + self.app.defaults.report_usage("Exc Editor ArrayTool()") + AppTool.run(self) + + # if the splitter us hidden, display it + if self.app.ui.splitter.sizes()[0] == 0: + self.app.ui.splitter.setSizes([1, 1]) + + # if the Tool Tab is hidden display it, else hide it but only if the objectName is the same + found_idx = None + for idx in range(self.app.ui.notebook.count()): + if self.app.ui.notebook.widget(idx).objectName() == "plugin_tab": + found_idx = idx + break + # show the Tab + if not found_idx: + try: + self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin")) + except RuntimeError: + self.app.ui.plugin_tab = QtWidgets.QWidget() + self.app.ui.plugin_tab.setObjectName("plugin_tab") + self.app.ui.plugin_tab_layout = QtWidgets.QVBoxLayout(self.app.ui.plugin_tab) + self.app.ui.plugin_tab_layout.setContentsMargins(2, 2, 2, 2) + + self.app.ui.plugin_scroll_area = VerticalScrollArea() + self.app.ui.plugin_tab_layout.addWidget(self.app.ui.plugin_scroll_area) + self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin")) + + # focus on Tool Tab + self.app.ui.notebook.setCurrentWidget(self.app.ui.plugin_tab) + + # self.app.ui.notebook.callback_on_close = self.on_tab_close + + self.app.ui.notebook.setTabText(2, self.plugin_name) + + def set_tool_ui(self): + # Init appGUI + self.length = 0.0 + self.ui.mode_radio.set_value('n') + self.ui.on_copy_mode(self.ui.mode_radio.get_value()) + self.ui.array_type_radio.set_value('linear') + self.ui.on_array_type_radio(self.ui.array_type_radio.get_value()) + self.ui.axis_radio.set_value('X') + self.ui.on_linear_angle_radio(self.ui.axis_radio.get_value()) + + self.ui.array_dir_radio.set_value('CW') + + self.ui.placement_radio.set_value('s') + self.ui.on_placement_radio(self.ui.placement_radio.get_value()) + + self.ui.spacing_rows.set_value(0) + self.ui.spacing_columns.set_value(0) + self.ui.rows.set_value(1) + self.ui.columns.set_value(1) + self.ui.offsetx_entry.set_value(0) + self.ui.offsety_entry.set_value(0) + + def on_tab_close(self): + self.disconnect_signals() + self.hide_tool() + # self.app.ui.notebook.callback_on_close = lambda: None + + def on_clear(self): + self.set_tool_ui() + + @property + def length(self): + return self.ui.project_line_entry.get_value() + + @length.setter + def length(self, val): + self.ui.project_line_entry.set_value(val) + + def hide_tool(self): + self.ui.copy_frame.hide() + self.app.ui.notebook.setCurrentWidget(self.app.ui.properties_tab) + if self.draw_app.active_tool.name != 'select': + self.draw_app.select_tool("select") + + +class ExcDrillArrayEditorUI: + + def __init__(self, layout, copy_class, plugin_name): + self.pluginName = plugin_name + self.copy_class = copy_class + self.decimals = self.copy_class.app.decimals + self.layout = layout + self.app = self.copy_class.app + + # Title + title_label = FCLabel("%s" % ('Editor ' + self.pluginName)) + title_label.setStyleSheet(""" + QLabel + { + font-size: 16px; + font-weight: bold; + } + """) + self.layout.addWidget(title_label) + + # this way I can hide/show the frame + self.copy_frame = QtWidgets.QFrame() + self.copy_frame.setContentsMargins(0, 0, 0, 0) + self.layout.addWidget(self.copy_frame) + self.copy_tool_box = QtWidgets.QVBoxLayout() + self.copy_tool_box.setContentsMargins(0, 0, 0, 0) + self.copy_frame.setLayout(self.copy_tool_box) + + # Grid Layout + grid0 = GLay(v_spacing=5, h_spacing=3) + self.copy_tool_box.addLayout(grid0) + + # Project distance + self.project_line_lbl = FCLabel('%s:' % _("Length")) + self.project_line_lbl.setToolTip( + _("Length of the current segment/move.") + ) + self.project_line_entry = NumericalEvalEntry(border_color='#0069A9') + grid0.addWidget(self.project_line_lbl, 0, 0) + grid0.addWidget(self.project_line_entry, 0, 1) + + self.clear_btn = FCButton(_("Clear")) + grid0.addWidget(self.clear_btn, 2, 0, 1, 2) + + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) + grid0.addWidget(separator_line, 4, 0, 1, 2) + + # Type of Array + self.mode_label = FCLabel('%s:' % _("Mode"), bold=True) + self.mode_label.setToolTip( + _("Single copy or special (array of copies)") + ) + self.mode_radio = RadioSet([ + {'label': _('Single'), 'value': 'n'}, + {'label': _('Array'), 'value': 'a'} + ]) + + grid0.addWidget(self.mode_label, 6, 0) + grid0.addWidget(self.mode_radio, 6, 1) + + # ############################################################################################################# + # ######################################## Add Array ########################################################## + # ############################################################################################################# + # add a frame and inside add a grid box layout. + self.array_frame = FCFrame() + # self.array_frame.setContentsMargins(0, 0, 0, 0) + self.layout.addWidget(self.array_frame) + + self.array_grid = GLay(v_spacing=5, h_spacing=3) + # self.array_grid.setContentsMargins(0, 0, 0, 0) + self.array_frame.setLayout(self.array_grid) + + # Set the number of items in the array + self.array_size_label = FCLabel('%s:' % _('Size')) + self.array_size_label.setToolTip(_("Specify how many items to be in the array.")) + + self.array_size_entry = FCSpinner(policy=False) + self.array_size_entry.set_range(1, 100000) + + self.array_grid.addWidget(self.array_size_label, 2, 0) + self.array_grid.addWidget(self.array_size_entry, 2, 1) + + # Array Type + array_type_lbl = FCLabel('%s:' % _("Type")) + array_type_lbl.setToolTip( + _("Select the type of array to create.\n" + "It can be Linear X(Y) or Circular") + ) + + self.array_type_radio = RadioSet([ + {'label': _('Linear'), 'value': 'linear'}, + {'label': _('2D'), 'value': '2D'}, + {'label': _('Circular'), 'value': 'circular'} + ]) + + self.array_grid.addWidget(array_type_lbl, 4, 0) + self.array_grid.addWidget(self.array_type_radio, 4, 1) + + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) + self.array_grid.addWidget(separator_line, 6, 0, 1, 2) + + # ############################################################################################################# + # ############################ LINEAR Array ################################################################### + # ############################################################################################################# + self.array_linear_frame = QtWidgets.QFrame() + self.array_linear_frame.setContentsMargins(0, 0, 0, 0) + self.array_grid.addWidget(self.array_linear_frame, 8, 0, 1, 2) + + self.lin_grid = GLay(v_spacing=5, h_spacing=3) + self.lin_grid.setContentsMargins(0, 0, 0, 0) + self.array_linear_frame.setLayout(self.lin_grid) + + # Linear Drill Array direction + self.axis_label = FCLabel('%s:' % _('Direction')) + self.axis_label.setToolTip( + _("Direction on which the linear array is oriented:\n" + "- 'X' - horizontal axis \n" + "- 'Y' - vertical axis or \n" + "- 'Angle' - a custom angle for the array inclination") + ) + + self.axis_radio = RadioSet([ + {'label': _('X'), 'value': 'X'}, + {'label': _('Y'), 'value': 'Y'}, + {'label': _('Angle'), 'value': 'A'} + ]) + + self.lin_grid.addWidget(self.axis_label, 0, 0) + self.lin_grid.addWidget(self.axis_radio, 0, 1) + + # Linear Array pitch distance + self.pitch_label = FCLabel('%s:' % _('Pitch')) + self.pitch_label.setToolTip( + _("Pitch = Distance between elements of the array.") + ) + + self.pitch_entry = FCDoubleSpinner(policy=False) + self.pitch_entry.set_precision(self.decimals) + self.pitch_entry.set_range(0.0000, 10000.0000) + + self.lin_grid.addWidget(self.pitch_label, 2, 0) + self.lin_grid.addWidget(self.pitch_entry, 2, 1) + + # Linear Array angle + self.linear_angle_label = FCLabel('%s:' % _('Angle')) + self.linear_angle_label.setToolTip( + _("Angle at which the linear array is placed.\n" + "The precision is of max 2 decimals.\n" + "Min value is: -360.00 degrees.\n" + "Max value is: 360.00 degrees.") + ) + + self.linear_angle_spinner = FCDoubleSpinner(policy=False) + self.linear_angle_spinner.set_precision(self.decimals) + self.linear_angle_spinner.setSingleStep(1.0) + self.linear_angle_spinner.setRange(-360.00, 360.00) + + self.lin_grid.addWidget(self.linear_angle_label, 4, 0) + self.lin_grid.addWidget(self.linear_angle_spinner, 4, 1) + + # ############################################################################################################# + # ################################ 2D Array ################################################################### + # ############################################################################################################# + self.two_dim_array_frame = QtWidgets.QFrame() + self.two_dim_array_frame.setContentsMargins(0, 0, 0, 0) + self.array_grid.addWidget(self.two_dim_array_frame, 10, 0, 1, 2) + + self.dd_grid = GLay(v_spacing=5, h_spacing=3) + self.dd_grid.setContentsMargins(0, 0, 0, 0) + self.two_dim_array_frame.setLayout(self.dd_grid) + + # 2D placement + self.place_label = FCLabel('%s:' % _('Placement')) + self.place_label.setToolTip( + _("Placement of array items:\n" + "'Spacing' - define space between rows and columns \n" + "'Offset' - each row (and column) will be placed at a multiple of a value, from origin") + ) + + self.placement_radio = RadioSet([ + {'label': _('Spacing'), 'value': 's'}, + {'label': _('Offset'), 'value': 'o'} + ]) + + self.dd_grid.addWidget(self.place_label, 0, 0) + self.dd_grid.addWidget(self.placement_radio, 0, 1) + + # Rows + self.rows = FCSpinner(callback=self.confirmation_message_int) + self.rows.set_range(0, 10000) + + self.rows_label = FCLabel('%s:' % _("Rows")) + self.rows_label.setToolTip( + _("Number of rows") + ) + self.dd_grid.addWidget(self.rows_label, 2, 0) + self.dd_grid.addWidget(self.rows, 2, 1) + + # Columns + self.columns = FCSpinner(callback=self.confirmation_message_int) + self.columns.set_range(0, 10000) + + self.columns_label = FCLabel('%s:' % _("Columns")) + self.columns_label.setToolTip( + _("Number of columns") + ) + self.dd_grid.addWidget(self.columns_label, 4, 0) + self.dd_grid.addWidget(self.columns, 4, 1) + + # ------------------------------------------------ + # ############## Spacing Frame ################# + # ------------------------------------------------ + self.spacing_frame = QtWidgets.QFrame() + self.spacing_frame.setContentsMargins(0, 0, 0, 0) + self.dd_grid.addWidget(self.spacing_frame, 6, 0, 1, 2) + + self.s_grid = GLay(v_spacing=5, h_spacing=3) + self.s_grid.setContentsMargins(0, 0, 0, 0) + self.spacing_frame.setLayout(self.s_grid) + + # Spacing Rows + self.spacing_rows = FCDoubleSpinner(callback=self.confirmation_message) + self.spacing_rows.set_range(0, 9999) + self.spacing_rows.set_precision(4) + + self.spacing_rows_label = FCLabel('%s:' % _("Spacing rows")) + self.spacing_rows_label.setToolTip( + _("Spacing between rows.\n" + "In current units.") + ) + self.s_grid.addWidget(self.spacing_rows_label, 0, 0) + self.s_grid.addWidget(self.spacing_rows, 0, 1) + + # Spacing Columns + self.spacing_columns = FCDoubleSpinner(callback=self.confirmation_message) + self.spacing_columns.set_range(0, 9999) + self.spacing_columns.set_precision(4) + + self.spacing_columns_label = FCLabel('%s:' % _("Spacing cols")) + self.spacing_columns_label.setToolTip( + _("Spacing between columns.\n" + "In current units.") + ) + self.s_grid.addWidget(self.spacing_columns_label, 2, 0) + self.s_grid.addWidget(self.spacing_columns, 2, 1) + + # ------------------------------------------------ + # ############## Offset Frame ################## + # ------------------------------------------------ + self.offset_frame = QtWidgets.QFrame() + self.offset_frame.setContentsMargins(0, 0, 0, 0) + self.dd_grid.addWidget(self.offset_frame, 8, 0, 1, 2) + + self.o_grid = GLay(v_spacing=5, h_spacing=3) + self.o_grid.setContentsMargins(0, 0, 0, 0) + self.offset_frame.setLayout(self.o_grid) + + # Offset X Value + self.offsetx_label = FCLabel('%s X:' % _("Offset")) + self.offsetx_label.setToolTip( + _("'Offset' - each row (and column) will be placed at a multiple of a value, from origin") + ) + + self.offsetx_entry = FCDoubleSpinner(policy=False) + self.offsetx_entry.set_precision(self.decimals) + self.offsetx_entry.set_range(0.0000, 10000.0000) + + self.o_grid.addWidget(self.offsetx_label, 0, 0) + self.o_grid.addWidget(self.offsetx_entry, 0, 1) + + # Offset Y Value + self.offsety_label = FCLabel('%s Y:' % _("Offset")) + self.offsety_label.setToolTip( + _("'Offset' - each row (and column) will be placed at a multiple of a value, from origin") + ) + + self.offsety_entry = FCDoubleSpinner(policy=False) + self.offsety_entry.set_precision(self.decimals) + self.offsety_entry.set_range(0.0000, 10000.0000) + + self.o_grid.addWidget(self.offsety_label, 2, 0) + self.o_grid.addWidget(self.offsety_entry, 2, 1) + + # ############################################################################################################# + # ############################ CIRCULAR Array ################################################################# + # ############################################################################################################# + self.array_circular_frame = QtWidgets.QFrame() + self.array_circular_frame.setContentsMargins(0, 0, 0, 0) + self.array_grid.addWidget(self.array_circular_frame, 12, 0, 1, 2) + + self.circ_grid = GLay(v_spacing=5, h_spacing=3) + self.circ_grid.setContentsMargins(0, 0, 0, 0) + self.array_circular_frame.setLayout(self.circ_grid) + + # Array Direction + self.array_dir_lbl = FCLabel('%s:' % _('Direction')) + self.array_dir_lbl.setToolTip( + _("Direction for circular array.\n" + "Can be CW = clockwise or CCW = counter clockwise.")) + + self.array_dir_radio = RadioSet([ + {'label': _('CW'), 'value': 'CW'}, + {'label': _('CCW'), 'value': 'CCW'}]) + + self.circ_grid.addWidget(self.array_dir_lbl, 0, 0) + self.circ_grid.addWidget(self.array_dir_radio, 0, 1) + + # Array Angle + self.array_angle_lbl = FCLabel('%s:' % _('Angle')) + self.array_angle_lbl.setToolTip(_("Angle at which each element in circular array is placed.")) + + self.angle_entry = FCDoubleSpinner(policy=False) + self.angle_entry.set_precision(self.decimals) + self.angle_entry.setSingleStep(1.0) + self.angle_entry.setRange(-360.00, 360.00) + + self.circ_grid.addWidget(self.array_angle_lbl, 2, 0) + self.circ_grid.addWidget(self.angle_entry, 2, 1) + + # Buttons + self.add_button = FCButton(_("Add")) + self.add_button.setIcon(QtGui.QIcon(self.app.resource_location + '/plus16.png')) + self.layout.addWidget(self.add_button) + + GLay.set_common_column_size([ + grid0, self.array_grid, self.lin_grid, self.dd_grid, self.circ_grid, self.s_grid, self.o_grid + ], 0) + + self.layout.addStretch(1) + + # Signals + self.mode_radio.activated_custom.connect(self.on_copy_mode) + self.array_type_radio.activated_custom.connect(self.on_array_type_radio) + self.axis_radio.activated_custom.connect(self.on_linear_angle_radio) + self.placement_radio.activated_custom.connect(self.on_placement_radio) + + def confirmation_message(self, accepted, minval, maxval): + if accepted is False: + self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"), + self.decimals, + minval, + self.decimals, + maxval), False) + + def confirmation_message_int(self, accepted, minval, maxval): + if accepted is False: + self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' % + (_("Edited value is out of range"), minval, maxval), False) + + def on_copy_mode(self, val): + if val == 'n': + self.array_frame.hide() + self.app.inform.emit(_("Click on reference location ...")) + else: + self.array_frame.show() + + def on_array_type_radio(self, val): + if val == '2D': + self.array_circular_frame.hide() + self.array_linear_frame.hide() + self.two_dim_array_frame.show() + if self.placement_radio.get_value() == 's': + self.spacing_frame.show() + self.offset_frame.hide() + else: + self.spacing_frame.hide() + self.offset_frame.show() + + self.array_size_entry.setDisabled(True) + self.on_rows_cols_value_changed() + + self.rows.valueChanged.connect(self.on_rows_cols_value_changed) + self.columns.valueChanged.connect(self.on_rows_cols_value_changed) + + self.app.inform.emit(_("Click on reference location ...")) + else: + if val == 'linear': + self.array_circular_frame.hide() + self.array_linear_frame.show() + self.two_dim_array_frame.hide() + self.spacing_frame.hide() + self.offset_frame.hide() + + self.app.inform.emit(_("Click on reference location ...")) + else: # 'circular' + self.array_circular_frame.show() + self.array_linear_frame.hide() + self.two_dim_array_frame.hide() + self.spacing_frame.hide() + self.offset_frame.hide() + + self.app.inform.emit(_("Click on the circular array Center position")) + + self.array_size_entry.setDisabled(False) + try: + self.rows.valueChanged.disconnect() + except (TypeError, AttributeError): + pass + + try: + self.columns.valueChanged.disconnect() + except (TypeError, AttributeError): + pass + + def on_rows_cols_value_changed(self): + new_size = self.rows.get_value() * self.columns.get_value() + if new_size == 0: + new_size = 1 + self.array_size_entry.set_value(new_size) + + def on_linear_angle_radio(self, val): + if val == 'A': + self.linear_angle_spinner.show() + self.linear_angle_label.show() + else: + self.linear_angle_spinner.hide() + self.linear_angle_label.hide() + + def on_placement_radio(self, val): + if val == 's': + self.spacing_frame.show() + self.offset_frame.hide() + else: + self.spacing_frame.hide() + self.offset_frame.show() diff --git a/appEditors/exc_plugins/ExcGenPlugin.py b/appEditors/exc_plugins/ExcGenPlugin.py new file mode 100644 index 00000000..076b9763 --- /dev/null +++ b/appEditors/exc_plugins/ExcGenPlugin.py @@ -0,0 +1,156 @@ + +from appTool import * + +fcTranslate.apply_language('strings') +if '_' not in builtins.__dict__: + _ = gettext.gettext + + +class ExcGenEditorTool(AppTool): + """ + Simple input for buffer distance. + """ + + def __init__(self, app, draw_app, plugin_name): + AppTool.__init__(self, app) + + self.draw_app = draw_app + self.decimals = app.decimals + self.plugin_name = plugin_name + + self.ui = ExcGenEditorUI(layout=self.layout, path_class=self, plugin_name=plugin_name) + + self.connect_signals_at_init() + self.set_tool_ui() + + def connect_signals_at_init(self): + # Signals + self.ui.clear_btn.clicked.connect(self.on_clear) + + def disconnect_signals(self): + # Signals + try: + self.ui.clear_btn.clicked.disconnect() + except (TypeError, AttributeError): + pass + + def run(self): + self.app.defaults.report_usage("Geo Editor ToolPath()") + AppTool.run(self) + + # if the splitter us hidden, display it + if self.app.ui.splitter.sizes()[0] == 0: + self.app.ui.splitter.setSizes([1, 1]) + + # if the Tool Tab is hidden display it, else hide it but only if the objectName is the same + found_idx = None + for idx in range(self.app.ui.notebook.count()): + if self.app.ui.notebook.widget(idx).objectName() == "plugin_tab": + found_idx = idx + break + # show the Tab + if not found_idx: + try: + self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin")) + except RuntimeError: + self.app.ui.plugin_tab = QtWidgets.QWidget() + self.app.ui.plugin_tab.setObjectName("plugin_tab") + self.app.ui.plugin_tab_layout = QtWidgets.QVBoxLayout(self.app.ui.plugin_tab) + self.app.ui.plugin_tab_layout.setContentsMargins(2, 2, 2, 2) + + self.app.ui.plugin_scroll_area = VerticalScrollArea() + self.app.ui.plugin_tab_layout.addWidget(self.app.ui.plugin_scroll_area) + self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin")) + + # focus on Tool Tab + self.app.ui.notebook.setCurrentWidget(self.app.ui.plugin_tab) + + # self.app.ui.notebook.callback_on_close = self.on_tab_close + + self.app.ui.notebook.setTabText(2, self.plugin_name) + + def set_tool_ui(self): + # Init appGUI + self.length = 0.0 + + def on_tab_close(self): + self.disconnect_signals() + self.hide_tool() + # self.app.ui.notebook.callback_on_close = lambda: None + + def on_clear(self): + self.set_tool_ui() + + @property + def length(self): + return self.ui.project_line_entry.get_value() + + @length.setter + def length(self, val): + self.ui.project_line_entry.set_value(val) + + def hide_tool(self): + self.ui.path_tool_frame.hide() + self.app.ui.notebook.setCurrentWidget(self.app.ui.properties_tab) + if self.draw_app.active_tool.name != 'select': + self.draw_app.select_tool("select") + + +class ExcGenEditorUI: + + def __init__(self, layout, path_class, plugin_name): + self.pluginName = plugin_name + self.path_class = path_class + self.decimals = self.path_class.app.decimals + self.layout = layout + + # Title + title_label = FCLabel("%s" % ('Editor ' + self.pluginName)) + title_label.setStyleSheet(""" + QLabel + { + font-size: 16px; + font-weight: bold; + } + """) + self.layout.addWidget(title_label) + + # this way I can hide/show the frame + self.path_tool_frame = QtWidgets.QFrame() + self.path_tool_frame.setContentsMargins(0, 0, 0, 0) + self.layout.addWidget(self.path_tool_frame) + self.path_tool_box = QtWidgets.QVBoxLayout() + self.path_tool_box.setContentsMargins(0, 0, 0, 0) + self.path_tool_frame.setLayout(self.path_tool_box) + + # Grid Layout + grid_path = GLay(v_spacing=5, h_spacing=3) + self.path_tool_box.addLayout(grid_path) + + # Project distance + self.project_line_lbl = FCLabel('%s:' % _("Length")) + self.project_line_lbl.setToolTip( + _("Length of the current segment/move.") + ) + self.project_line_entry = NumericalEvalEntry(border_color='#0069A9') + grid_path.addWidget(self.project_line_lbl, 0, 0) + grid_path.addWidget(self.project_line_entry, 0, 1) + + # self.buffer_corner_lbl = FCLabel('%s:' % _("Buffer corner")) + # self.buffer_corner_lbl.setToolTip( + # _("There are 3 types of corners:\n" + # " - 'Round': the corner is rounded for exterior buffer.\n" + # " - 'Square': the corner is met in a sharp angle for exterior buffer.\n" + # " - 'Beveled': the corner is a line that directly connects the features meeting in the corner") + # ) + # self.buffer_corner_cb = FCComboBox() + # self.buffer_corner_cb.addItem(_("Round")) + # self.buffer_corner_cb.addItem(_("Square")) + # self.buffer_corner_cb.addItem(_("Beveled")) + # grid_path.addWidget(self.buffer_corner_lbl, 2, 0) + # grid_path.addWidget(self.buffer_corner_cb, 2, 1) + + self.clear_btn = FCButton(_("Clear")) + grid_path.addWidget(self.clear_btn, 4, 0, 1, 2) + + self.layout.addStretch(1) diff --git a/appEditors/exc_plugins/ExcScalePlugin.py b/appEditors/exc_plugins/ExcScalePlugin.py new file mode 100644 index 00000000..e69de29b diff --git a/appEditors/exc_plugins/ExcSlotArrayPlugin.py b/appEditors/exc_plugins/ExcSlotArrayPlugin.py new file mode 100644 index 00000000..08250567 --- /dev/null +++ b/appEditors/exc_plugins/ExcSlotArrayPlugin.py @@ -0,0 +1,545 @@ + +from appTool import * + +fcTranslate.apply_language('strings') +if '_' not in builtins.__dict__: + _ = gettext.gettext + + +class ExcSlotArrayEditorTool(AppTool): + """ + Create an array of drill holes + """ + + def __init__(self, app, draw_app, plugin_name): + AppTool.__init__(self, app) + + self.draw_app = draw_app + self.decimals = app.decimals + self.plugin_name = plugin_name + + self.ui = ExcSlotArrayEditorUI(layout=self.layout, copy_class=self, plugin_name=plugin_name) + + self.connect_signals_at_init() + self.set_tool_ui() + + def connect_signals_at_init(self): + # Signals + self.ui.clear_btn.clicked.connect(self.on_clear) + + def disconnect_signals(self): + # Signals + try: + self.ui.clear_btn.clicked.disconnect() + except (TypeError, AttributeError): + pass + + def run(self): + self.app.defaults.report_usage("Exc Editor ArrayTool()") + AppTool.run(self) + + # if the splitter us hidden, display it + if self.app.ui.splitter.sizes()[0] == 0: + self.app.ui.splitter.setSizes([1, 1]) + + # if the Tool Tab is hidden display it, else hide it but only if the objectName is the same + found_idx = None + for idx in range(self.app.ui.notebook.count()): + if self.app.ui.notebook.widget(idx).objectName() == "plugin_tab": + found_idx = idx + break + # show the Tab + if not found_idx: + try: + self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin")) + except RuntimeError: + self.app.ui.plugin_tab = QtWidgets.QWidget() + self.app.ui.plugin_tab.setObjectName("plugin_tab") + self.app.ui.plugin_tab_layout = QtWidgets.QVBoxLayout(self.app.ui.plugin_tab) + self.app.ui.plugin_tab_layout.setContentsMargins(2, 2, 2, 2) + + self.app.ui.plugin_scroll_area = VerticalScrollArea() + self.app.ui.plugin_tab_layout.addWidget(self.app.ui.plugin_scroll_area) + self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin")) + + # focus on Tool Tab + self.app.ui.notebook.setCurrentWidget(self.app.ui.plugin_tab) + + # self.app.ui.notebook.callback_on_close = self.on_tab_close + + self.app.ui.notebook.setTabText(2, self.plugin_name) + + def set_tool_ui(self): + # Init appGUI + self.length = 0.0 + self.ui.mode_radio.set_value('n') + self.ui.on_copy_mode(self.ui.mode_radio.get_value()) + self.ui.array_type_radio.set_value('linear') + self.ui.on_array_type_radio(self.ui.array_type_radio.get_value()) + self.ui.axis_radio.set_value('X') + self.ui.on_linear_angle_radio(self.ui.axis_radio.get_value()) + + self.ui.array_dir_radio.set_value('CW') + + self.ui.placement_radio.set_value('s') + self.ui.on_placement_radio(self.ui.placement_radio.get_value()) + + self.ui.spacing_rows.set_value(0) + self.ui.spacing_columns.set_value(0) + self.ui.rows.set_value(1) + self.ui.columns.set_value(1) + self.ui.offsetx_entry.set_value(0) + self.ui.offsety_entry.set_value(0) + + def on_tab_close(self): + self.disconnect_signals() + self.hide_tool() + # self.app.ui.notebook.callback_on_close = lambda: None + + def on_clear(self): + self.set_tool_ui() + + @property + def length(self): + return self.ui.project_line_entry.get_value() + + @length.setter + def length(self, val): + self.ui.project_line_entry.set_value(val) + + def hide_tool(self): + self.ui.copy_frame.hide() + self.app.ui.notebook.setCurrentWidget(self.app.ui.properties_tab) + if self.draw_app.active_tool.name != 'select': + self.draw_app.select_tool("select") + + +class ExcSlotArrayEditorUI: + + def __init__(self, layout, copy_class, plugin_name): + self.pluginName = plugin_name + self.copy_class = copy_class + self.decimals = self.copy_class.app.decimals + self.layout = layout + self.app = self.copy_class.app + + # Title + title_label = FCLabel("%s" % ('Editor ' + self.pluginName)) + title_label.setStyleSheet(""" + QLabel + { + font-size: 16px; + font-weight: bold; + } + """) + self.layout.addWidget(title_label) + + # this way I can hide/show the frame + self.copy_frame = QtWidgets.QFrame() + self.copy_frame.setContentsMargins(0, 0, 0, 0) + self.layout.addWidget(self.copy_frame) + self.copy_tool_box = QtWidgets.QVBoxLayout() + self.copy_tool_box.setContentsMargins(0, 0, 0, 0) + self.copy_frame.setLayout(self.copy_tool_box) + + # Grid Layout + grid0 = GLay(v_spacing=5, h_spacing=3) + self.copy_tool_box.addLayout(grid0) + + # Project distance + self.project_line_lbl = FCLabel('%s:' % _("Length")) + self.project_line_lbl.setToolTip( + _("Length of the current segment/move.") + ) + self.project_line_entry = NumericalEvalEntry(border_color='#0069A9') + grid0.addWidget(self.project_line_lbl, 0, 0) + grid0.addWidget(self.project_line_entry, 0, 1) + + self.clear_btn = FCButton(_("Clear")) + grid0.addWidget(self.clear_btn, 2, 0, 1, 2) + + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) + grid0.addWidget(separator_line, 4, 0, 1, 2) + + # Type of Array + self.mode_label = FCLabel('%s:' % _("Mode"), bold=True) + self.mode_label.setToolTip( + _("Single copy or special (array of copies)") + ) + self.mode_radio = RadioSet([ + {'label': _('Single'), 'value': 'n'}, + {'label': _('Array'), 'value': 'a'} + ]) + + grid0.addWidget(self.mode_label, 6, 0) + grid0.addWidget(self.mode_radio, 6, 1) + + # ############################################################################################################# + # ######################################## Add Array ########################################################## + # ############################################################################################################# + # add a frame and inside add a grid box layout. + self.array_frame = FCFrame() + # self.array_frame.setContentsMargins(0, 0, 0, 0) + self.layout.addWidget(self.array_frame) + + self.array_grid = GLay(v_spacing=5, h_spacing=3) + # self.array_grid.setContentsMargins(0, 0, 0, 0) + self.array_frame.setLayout(self.array_grid) + + # Set the number of items in the array + self.array_size_label = FCLabel('%s:' % _('Size')) + self.array_size_label.setToolTip(_("Specify how many items to be in the array.")) + + self.array_size_entry = FCSpinner(policy=False) + self.array_size_entry.set_range(1, 100000) + + self.array_grid.addWidget(self.array_size_label, 2, 0) + self.array_grid.addWidget(self.array_size_entry, 2, 1) + + # Array Type + array_type_lbl = FCLabel('%s:' % _("Type")) + array_type_lbl.setToolTip( + _("Select the type of array to create.\n" + "It can be Linear X(Y) or Circular") + ) + + self.array_type_radio = RadioSet([ + {'label': _('Linear'), 'value': 'linear'}, + {'label': _('2D'), 'value': '2D'}, + {'label': _('Circular'), 'value': 'circular'} + ]) + + self.array_grid.addWidget(array_type_lbl, 4, 0) + self.array_grid.addWidget(self.array_type_radio, 4, 1) + + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) + self.array_grid.addWidget(separator_line, 6, 0, 1, 2) + + # ############################################################################################################# + # ############################ LINEAR Array ################################################################### + # ############################################################################################################# + self.array_linear_frame = QtWidgets.QFrame() + self.array_linear_frame.setContentsMargins(0, 0, 0, 0) + self.array_grid.addWidget(self.array_linear_frame, 8, 0, 1, 2) + + self.lin_grid = GLay(v_spacing=5, h_spacing=3) + self.lin_grid.setContentsMargins(0, 0, 0, 0) + self.array_linear_frame.setLayout(self.lin_grid) + + # Linear Drill Array direction + self.axis_label = FCLabel('%s:' % _('Direction')) + self.axis_label.setToolTip( + _("Direction on which the linear array is oriented:\n" + "- 'X' - horizontal axis \n" + "- 'Y' - vertical axis or \n" + "- 'Angle' - a custom angle for the array inclination") + ) + + self.axis_radio = RadioSet([ + {'label': _('X'), 'value': 'X'}, + {'label': _('Y'), 'value': 'Y'}, + {'label': _('Angle'), 'value': 'A'} + ]) + + self.lin_grid.addWidget(self.axis_label, 0, 0) + self.lin_grid.addWidget(self.axis_radio, 0, 1) + + # Linear Array pitch distance + self.pitch_label = FCLabel('%s:' % _('Pitch')) + self.pitch_label.setToolTip( + _("Pitch = Distance between elements of the array.") + ) + + self.pitch_entry = FCDoubleSpinner(policy=False) + self.pitch_entry.set_precision(self.decimals) + self.pitch_entry.set_range(0.0000, 10000.0000) + + self.lin_grid.addWidget(self.pitch_label, 2, 0) + self.lin_grid.addWidget(self.pitch_entry, 2, 1) + + # Linear Array angle + self.linear_angle_label = FCLabel('%s:' % _('Angle')) + self.linear_angle_label.setToolTip( + _("Angle at which the linear array is placed.\n" + "The precision is of max 2 decimals.\n" + "Min value is: -360.00 degrees.\n" + "Max value is: 360.00 degrees.") + ) + + self.linear_angle_spinner = FCDoubleSpinner(policy=False) + self.linear_angle_spinner.set_precision(self.decimals) + self.linear_angle_spinner.setSingleStep(1.0) + self.linear_angle_spinner.setRange(-360.00, 360.00) + + self.lin_grid.addWidget(self.linear_angle_label, 4, 0) + self.lin_grid.addWidget(self.linear_angle_spinner, 4, 1) + + # ############################################################################################################# + # ################################ 2D Array ################################################################### + # ############################################################################################################# + self.two_dim_array_frame = QtWidgets.QFrame() + self.two_dim_array_frame.setContentsMargins(0, 0, 0, 0) + self.array_grid.addWidget(self.two_dim_array_frame, 10, 0, 1, 2) + + self.dd_grid = GLay(v_spacing=5, h_spacing=3) + self.dd_grid.setContentsMargins(0, 0, 0, 0) + self.two_dim_array_frame.setLayout(self.dd_grid) + + # 2D placement + self.place_label = FCLabel('%s:' % _('Placement')) + self.place_label.setToolTip( + _("Placement of array items:\n" + "'Spacing' - define space between rows and columns \n" + "'Offset' - each row (and column) will be placed at a multiple of a value, from origin") + ) + + self.placement_radio = RadioSet([ + {'label': _('Spacing'), 'value': 's'}, + {'label': _('Offset'), 'value': 'o'} + ]) + + self.dd_grid.addWidget(self.place_label, 0, 0) + self.dd_grid.addWidget(self.placement_radio, 0, 1) + + # Rows + self.rows = FCSpinner(callback=self.confirmation_message_int) + self.rows.set_range(0, 10000) + + self.rows_label = FCLabel('%s:' % _("Rows")) + self.rows_label.setToolTip( + _("Number of rows") + ) + self.dd_grid.addWidget(self.rows_label, 2, 0) + self.dd_grid.addWidget(self.rows, 2, 1) + + # Columns + self.columns = FCSpinner(callback=self.confirmation_message_int) + self.columns.set_range(0, 10000) + + self.columns_label = FCLabel('%s:' % _("Columns")) + self.columns_label.setToolTip( + _("Number of columns") + ) + self.dd_grid.addWidget(self.columns_label, 4, 0) + self.dd_grid.addWidget(self.columns, 4, 1) + + # ------------------------------------------------ + # ############## Spacing Frame ################# + # ------------------------------------------------ + self.spacing_frame = QtWidgets.QFrame() + self.spacing_frame.setContentsMargins(0, 0, 0, 0) + self.dd_grid.addWidget(self.spacing_frame, 6, 0, 1, 2) + + self.s_grid = GLay(v_spacing=5, h_spacing=3) + self.s_grid.setContentsMargins(0, 0, 0, 0) + self.spacing_frame.setLayout(self.s_grid) + + # Spacing Rows + self.spacing_rows = FCDoubleSpinner(callback=self.confirmation_message) + self.spacing_rows.set_range(0, 9999) + self.spacing_rows.set_precision(4) + + self.spacing_rows_label = FCLabel('%s:' % _("Spacing rows")) + self.spacing_rows_label.setToolTip( + _("Spacing between rows.\n" + "In current units.") + ) + self.s_grid.addWidget(self.spacing_rows_label, 0, 0) + self.s_grid.addWidget(self.spacing_rows, 0, 1) + + # Spacing Columns + self.spacing_columns = FCDoubleSpinner(callback=self.confirmation_message) + self.spacing_columns.set_range(0, 9999) + self.spacing_columns.set_precision(4) + + self.spacing_columns_label = FCLabel('%s:' % _("Spacing cols")) + self.spacing_columns_label.setToolTip( + _("Spacing between columns.\n" + "In current units.") + ) + self.s_grid.addWidget(self.spacing_columns_label, 2, 0) + self.s_grid.addWidget(self.spacing_columns, 2, 1) + + # ------------------------------------------------ + # ############## Offset Frame ################## + # ------------------------------------------------ + self.offset_frame = QtWidgets.QFrame() + self.offset_frame.setContentsMargins(0, 0, 0, 0) + self.dd_grid.addWidget(self.offset_frame, 8, 0, 1, 2) + + self.o_grid = GLay(v_spacing=5, h_spacing=3) + self.o_grid.setContentsMargins(0, 0, 0, 0) + self.offset_frame.setLayout(self.o_grid) + + # Offset X Value + self.offsetx_label = FCLabel('%s X:' % _("Offset")) + self.offsetx_label.setToolTip( + _("'Offset' - each row (and column) will be placed at a multiple of a value, from origin") + ) + + self.offsetx_entry = FCDoubleSpinner(policy=False) + self.offsetx_entry.set_precision(self.decimals) + self.offsetx_entry.set_range(0.0000, 10000.0000) + + self.o_grid.addWidget(self.offsetx_label, 0, 0) + self.o_grid.addWidget(self.offsetx_entry, 0, 1) + + # Offset Y Value + self.offsety_label = FCLabel('%s Y:' % _("Offset")) + self.offsety_label.setToolTip( + _("'Offset' - each row (and column) will be placed at a multiple of a value, from origin") + ) + + self.offsety_entry = FCDoubleSpinner(policy=False) + self.offsety_entry.set_precision(self.decimals) + self.offsety_entry.set_range(0.0000, 10000.0000) + + self.o_grid.addWidget(self.offsety_label, 2, 0) + self.o_grid.addWidget(self.offsety_entry, 2, 1) + + # ############################################################################################################# + # ############################ CIRCULAR Array ################################################################# + # ############################################################################################################# + self.array_circular_frame = QtWidgets.QFrame() + self.array_circular_frame.setContentsMargins(0, 0, 0, 0) + self.array_grid.addWidget(self.array_circular_frame, 12, 0, 1, 2) + + self.circ_grid = GLay(v_spacing=5, h_spacing=3) + self.circ_grid.setContentsMargins(0, 0, 0, 0) + self.array_circular_frame.setLayout(self.circ_grid) + + # Array Direction + self.array_dir_lbl = FCLabel('%s:' % _('Direction')) + self.array_dir_lbl.setToolTip( + _("Direction for circular array.\n" + "Can be CW = clockwise or CCW = counter clockwise.")) + + self.array_dir_radio = RadioSet([ + {'label': _('CW'), 'value': 'CW'}, + {'label': _('CCW'), 'value': 'CCW'}]) + + self.circ_grid.addWidget(self.array_dir_lbl, 0, 0) + self.circ_grid.addWidget(self.array_dir_radio, 0, 1) + + # Array Angle + self.array_angle_lbl = FCLabel('%s:' % _('Angle')) + self.array_angle_lbl.setToolTip(_("Angle at which each element in circular array is placed.")) + + self.angle_entry = FCDoubleSpinner(policy=False) + self.angle_entry.set_precision(self.decimals) + self.angle_entry.setSingleStep(1.0) + self.angle_entry.setRange(-360.00, 360.00) + + self.circ_grid.addWidget(self.array_angle_lbl, 2, 0) + self.circ_grid.addWidget(self.angle_entry, 2, 1) + + # Buttons + self.add_button = FCButton(_("Add")) + self.add_button.setIcon(QtGui.QIcon(self.app.resource_location + '/plus16.png')) + self.layout.addWidget(self.add_button) + + GLay.set_common_column_size([ + grid0, self.array_grid, self.lin_grid, self.dd_grid, self.circ_grid, self.s_grid, self.o_grid + ], 0) + + self.layout.addStretch(1) + + # Signals + self.mode_radio.activated_custom.connect(self.on_copy_mode) + self.array_type_radio.activated_custom.connect(self.on_array_type_radio) + self.axis_radio.activated_custom.connect(self.on_linear_angle_radio) + self.placement_radio.activated_custom.connect(self.on_placement_radio) + + def confirmation_message(self, accepted, minval, maxval): + if accepted is False: + self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"), + self.decimals, + minval, + self.decimals, + maxval), False) + + def confirmation_message_int(self, accepted, minval, maxval): + if accepted is False: + self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' % + (_("Edited value is out of range"), minval, maxval), False) + + def on_copy_mode(self, val): + if val == 'n': + self.array_frame.hide() + self.app.inform.emit(_("Click on reference location ...")) + else: + self.array_frame.show() + + def on_array_type_radio(self, val): + if val == '2D': + self.array_circular_frame.hide() + self.array_linear_frame.hide() + self.two_dim_array_frame.show() + if self.placement_radio.get_value() == 's': + self.spacing_frame.show() + self.offset_frame.hide() + else: + self.spacing_frame.hide() + self.offset_frame.show() + + self.array_size_entry.setDisabled(True) + self.on_rows_cols_value_changed() + + self.rows.valueChanged.connect(self.on_rows_cols_value_changed) + self.columns.valueChanged.connect(self.on_rows_cols_value_changed) + + self.app.inform.emit(_("Click on reference location ...")) + else: + if val == 'linear': + self.array_circular_frame.hide() + self.array_linear_frame.show() + self.two_dim_array_frame.hide() + self.spacing_frame.hide() + self.offset_frame.hide() + + self.app.inform.emit(_("Click on reference location ...")) + else: # 'circular' + self.array_circular_frame.show() + self.array_linear_frame.hide() + self.two_dim_array_frame.hide() + self.spacing_frame.hide() + self.offset_frame.hide() + + self.app.inform.emit(_("Click on the circular array Center position")) + + self.array_size_entry.setDisabled(False) + try: + self.rows.valueChanged.disconnect() + except (TypeError, AttributeError): + pass + + try: + self.columns.valueChanged.disconnect() + except (TypeError, AttributeError): + pass + + def on_rows_cols_value_changed(self): + new_size = self.rows.get_value() * self.columns.get_value() + if new_size == 0: + new_size = 1 + self.array_size_entry.set_value(new_size) + + def on_linear_angle_radio(self, val): + if val == 'A': + self.linear_angle_spinner.show() + self.linear_angle_label.show() + else: + self.linear_angle_spinner.hide() + self.linear_angle_label.hide() + + def on_placement_radio(self, val): + if val == 's': + self.spacing_frame.show() + self.offset_frame.hide() + else: + self.spacing_frame.hide() + self.offset_frame.show() diff --git a/appEditors/geo_plugins/GeoStitchPlugin.py b/appEditors/geo_plugins/GeoStitchPlugin.py new file mode 100644 index 00000000..e69de29b diff --git a/appGUI/MainGUI.py b/appGUI/MainGUI.py index 8aa2d52f..298bcc24 100644 --- a/appGUI/MainGUI.py +++ b/appGUI/MainGUI.py @@ -3457,8 +3457,8 @@ class MainGUI(QtWidgets.QMainWindow): if self.app.geo_editor.get_selected() is not None: self.app.geo_editor.cutpath() else: - msg = _('Please first select a geometry item to be cutted\n' - 'then select the geometry item that will be cutted\n' + msg = _('Please first select a geometry item to be cut\n' + 'then select the geometry item that will be cut\n' 'out of the first item. In the end press ~X~ key or\n' 'the toolbar button.') diff --git a/appGUI/PlotCanvasLegacy.py b/appGUI/PlotCanvasLegacy.py index 17590476..0df96ebb 100644 --- a/appGUI/PlotCanvasLegacy.py +++ b/appGUI/PlotCanvasLegacy.py @@ -650,7 +650,7 @@ class PlotCanvasLegacy(QtCore.QObject): if self.app.options["global_cursor_color_enabled"]: color = self.app.options["global_cursor_color"] else: - if self.app.options['global_theme'] == 'light': + if self.app.options['global_theme'] in ['default', 'light']: color = '#000000' else: color = '#FFFFFF' @@ -705,7 +705,7 @@ class PlotCanvasLegacy(QtCore.QObject): if color: color = color else: - if self.app.options['global_theme'] == 'light': + if self.app.options['global_theme'] in ['default', 'light']: color = '#000000' else: color = '#FFFFFF' @@ -748,7 +748,7 @@ class PlotCanvasLegacy(QtCore.QObject): self.canvas.blit(self.axes.bbox) def clear_cursor(self, state): - if self.app.options['global_theme'] == 'light': + if self.app.options['global_theme'] in ['default', 'light']: color = '#000000' else: color = '#FFFFFF' diff --git a/appMain.py b/appMain.py index 61ff699c..c7a3f800 100644 --- a/appMain.py +++ b/appMain.py @@ -8641,7 +8641,8 @@ class App(QtCore.QObject): root = d_properties_tw.invisibleRootItem() font = QtGui.QFont() font.setBold(True) - p_color = QtGui.QColor("#000000") if self.options['global_theme'] == 'light' else QtGui.QColor("#FFFFFF") + p_color = QtGui.QColor("#000000") if self.options['global_theme'] in ['default', 'light'] else \ + QtGui.QColor("#FFFFFF") # main Items categories general_cat = d_properties_tw.addParent(root, _('General'), expanded=True, color=p_color, font=font) diff --git a/appObjects/AppObjectTemplate.py b/appObjects/AppObjectTemplate.py index 1e22e465..cecf2fdd 100644 --- a/appObjects/AppObjectTemplate.py +++ b/appObjects/AppObjectTemplate.py @@ -536,7 +536,7 @@ class FlatCAMObj(QtCore.QObject): font = QtGui.QFont() font.setBold(True) - p_color = QtGui.QColor("#000000") if self.app.options['global_theme'] == 'light' \ + p_color = QtGui.QColor("#000000") if self.app.options['global_theme'] in ['default', 'light'] \ else QtGui.QColor("#FFFFFF") # main Items categories diff --git a/appObjects/GerberObject.py b/appObjects/GerberObject.py index cac0eaeb..43a1dad9 100644 --- a/appObjects/GerberObject.py +++ b/appObjects/GerberObject.py @@ -988,7 +988,7 @@ class GerberObject(FlatCAMObj, Gerber): used_color = random_color() if self.obj_options['multicolored'] else 'black' used_face_color = None - if self.app.options["gerber_plot_line_disable"] is True: + if self.app.options["gerber_plot_line_enable"] is False: used_color = None if isinstance(plot_geometry, (Polygon, LineString)): self.add_shape(shape=plot_geometry, color=used_color, face_color=used_face_color, visible=visible) diff --git a/appPlugins/ToolImage.py b/appPlugins/ToolImage.py index 18791c24..8d3e963d 100644 --- a/appPlugins/ToolImage.py +++ b/appPlugins/ToolImage.py @@ -9,6 +9,12 @@ from appTool import * from rasterio import open as rasterio_open from rasterio.features import shapes +from svgtrace import trace +from pyppeteer.chromium_downloader import check_chromium +from lxml import etree as ET + +from appParsers.ParseSVG import svgparselength, svgparse_viewbox, getsvggeo, getsvgtext + fcTranslate.apply_language('strings') if '_' not in builtins.__dict__: _ = gettext.gettext @@ -89,7 +95,7 @@ class ToolImage(AppTool): def connect_signals_at_init(self): # ## Signals - self.ui.import_button.clicked.connect(self.on_file_importimage) + self.ui.import_button.clicked.connect(lambda: self.on_file_importimage()) self.ui.image_type.activated_custom.connect(self.ui.on_image_type) def set_tool_ui(self): @@ -101,12 +107,36 @@ class ToolImage(AppTool): # ## Initialize form self.ui.dpi_entry.set_value(96) self.ui.image_type.set_value('black') + self.ui.on_image_type(val=self.ui.image_type.get_value()) + + self.ui.min_area_entry.set_value(0.3) + + self.ui.import_mode_radio.set_value('raster') + self.ui.on_import_image_mode(val=self.ui.import_mode_radio.get_value()) + + self.ui.control_radio.set_value('presets') + self.ui.on_tracing_control_radio(val=self.ui.control_radio.get_value()) + self.ui.mask_bw_entry.set_value(250) self.ui.mask_r_entry.set_value(250) self.ui.mask_g_entry.set_value(250) self.ui.mask_b_entry.set_value(250) - def on_file_importimage(self): + self.ui.error_lines_entry.set_value(1) + self.ui.error_splines_entry.set_value(0) + self.ui.path_omit_entry.set_value(8) + self.ui.enhance_rangle_cb.set_value(True) + self.ui.sampling_combo.set_value(0) + self.ui.nr_colors_entry.set_value(16) + self.ui.ratio_entry.set_value(0) + self.ui.cycles_entry.set_value(3) + self.ui.stroke_width_entry.set_value(1.0) + self.ui.line_filter_cb.set_value(False) + self.ui.rounding_entry.set_value(1) + self.ui.blur_radius_entry.set_value(1) + self.ui.blur_delta_entry.set_value(20) + + def on_file_importimage(self, threaded=True): """ Callback for menu item File->Import IMAGE. @@ -115,6 +145,41 @@ class ToolImage(AppTool): self.app.log.debug("on_file_importimage()") + import_mode = self.ui.import_mode_radio.get_value() + trace_options = self.ui.presets_combo.get_value() if self.ui.control_radio.get_value() == 'presets' else \ + self.get_tracing_options() + type_obj = self.ui.tf_type_obj_combo.get_value() + dpi = self.ui.dpi_entry.get_value() + mode = self.ui.image_type.get_value() + min_area = self.ui.min_area_entry.get_value() + + if import_mode == 'trace': + # check if Chromium is present, if not issue a warning + res = check_chromium() + if res is False: + msgbox = FCMessageBox(parent=self.app.ui) + title = _("Import warning") + txt = _("The tracing require Chromium,\n" + "but it was not detected.\n" + "\n" + "Do you want to download (about 300MB)?") + msgbox.setWindowTitle(title) # taskbar still shows it + msgbox.setWindowIcon(QtGui.QIcon(self.app.resource_location + '/app128.png')) + msgbox.setText('%s' % title) + msgbox.setInformativeText(txt) + msgbox.setIcon(QtWidgets.QMessageBox.Icon.Warning) + + bt_yes = msgbox.addButton(_('Yes'), QtWidgets.QMessageBox.ButtonRole.YesRole) + bt_no = msgbox.addButton(_('No'), QtWidgets.QMessageBox.ButtonRole.NoRole) + + msgbox.setDefaultButton(bt_yes) + msgbox.exec() + response = msgbox.clickedButton() + + if response == bt_no: + self.app.inform.emit('[WARNING_NOTCL] %s' % _("Cancelled.")) + return + _filter = "Image Files(*.BMP *.PNG *.JPG *.JPEG);;" \ "Bitmap File (*.BMP);;" \ "PNG File (*.PNG);;" \ @@ -127,9 +192,7 @@ class ToolImage(AppTool): filename, _f = QtWidgets.QFileDialog.getOpenFileName(caption=_("Import IMAGE"), filter=_filter) filename = str(filename) - type_obj = self.ui.tf_type_obj_combo.get_value() - dpi = self.ui.dpi_entry.get_value() - mode = self.ui.image_type.get_value() + mask = [ self.ui.mask_bw_entry.get_value(), self.ui.mask_r_entry.get_value(), @@ -140,26 +203,44 @@ class ToolImage(AppTool): if filename == "": self.app.inform.emit(_("Cancelled.")) else: - self.app.worker_task.emit({'fcn': self.import_image, - 'params': [filename, type_obj, dpi, mode, mask]}) + if import_mode == 'trace': + # there are thread issues so I process this outside + svg_text = trace(filename, blackAndWhite=True if mode == 'black' else False, mode=trace_options) + else: + svg_text = None + if threaded is True: + self.app.worker_task.emit({'fcn': self.import_image, + 'params': [ + filename, import_mode, type_obj, dpi, mode, mask, svg_text, min_area] + }) + else: + self.import_image(filename, import_mode, type_obj, dpi, mode, mask, svg_text, min_area) - def import_image(self, filename, o_type=_("Gerber"), dpi=96, mode='black', mask=None, outname=None): + def import_image(self, filename, import_mode, o_type=_("Gerber"), dpi=96, mode='black', + mask=None, svg_text=None, min_area=0.0, outname=None, silent=False): """ Adds a new Geometry Object to the projects and populates it with shapes extracted from the SVG file. - :param filename: Path to the SVG file. - :param o_type: type of FlatCAM objeect - :param dpi: dot per inch - :param mode: black or color - :param mask: dictate the level of detail - :param outname: name for the resulting file + :param filename: Path to the SVG file. + :param import_mode: The kind of image import to be done: 'raster' or 'trace' + :param o_type: type of FlatCAM object + :param dpi: dot per inch + :param mode: black or color + :param mask: dictate the level of detail + :param svg_text: a SVG string only for when tracing + :param outname: name for the resulting file + :param min_area: the minimum area for the imported polygons for them to be kept + :param silent: bool: if False then there are no messages issued to GUI :return: """ self.app.defaults.report_usage("import_image()") if not os.path.exists(filename): - self.app.inform.emit('[ERROR_NOTCL] %s' % _("File no longer available.")) + if silent: + self.app.log.debug("File no longer available.") + else: + self.app.inform.emit('[ERROR_NOTCL] %s' % _("File no longer available.")) return if mask is None: @@ -170,35 +251,71 @@ class ToolImage(AppTool): elif o_type == _("Gerber"): obj_type = "gerber" else: - self.app.inform.emit('[ERROR_NOTCL] %s' % - _("Not supported type is picked as parameter. " - "Only Geometry and Gerber are supported")) + if silent is False: + self.app.inform.emit('[ERROR_NOTCL] %s' % _("Only Geometry and Gerber objects are supported")) return def obj_init(geo_obj, app_obj): - app_obj.log.debug("ToolIamge.import_image() -> importing image as geometry") - image_geo = self.import_image_handler(filename, units=units, dpi=dpi, mode=mode, mask=mask) + app_obj.log.debug("ToolImage.import_image() -> importing image as: %s" % obj_type.capitalize()) + if import_mode == 'raster': + image_geo = self.import_image_handler(filename, units=units, dpi=dpi, mode=mode, mask=mask) + else: # 'trace' + image_geo = self.import_image_as_trace_handler(svg_text=svg_text, obj_type=obj_type, units=units, + dpi=dpi) - # # Add to object - # if self.solid_geometry is None: - # self.solid_geometry = [] - # - # if type(self.solid_geometry) is list: - # # self.solid_geometry.append(unary_union(geos)) - # if type(geos) is list: - # self.solid_geometry += geos - # else: - # self.solid_geometry.append(geos) - # else: # It's shapely geometry - # self.solid_geometry = [self.solid_geometry, geos] + if not image_geo: + app_obj.log.debug("ToolImage.import_image() -> empty geometry.") + return 'fail' - # flatten the geo_obj.solid_geometry list - geo_obj.solid_geometry = list(self.flatten_list(image_geo)) - geo_obj.solid_geometry = unary_union(geo_obj.solid_geometry) + if image_geo == 'fail': + if silent is False: + app_obj.inform.emit("[ERROR_NOTCL] %s" % _("Failed.")) + return "fail" geo_obj.multigeo = False geo_obj.multitool = False + # flatten the geo_obj.solid_geometry list + geo_obj.solid_geometry = list(self.flatten_list(image_geo)) + geo_obj.solid_geometry = [p for p in geo_obj.solid_geometry if p and p.is_valid and p.area >= min_area] + + if obj_type == 'geometry': + tooldia = float(self.app.options["tools_mill_tooldia"]) + tooldia = float('%.*f' % (self.decimals, tooldia)) + + new_data = {k: v for k, v in self.app.options.items()} + + geo_obj.tools.update({ + 1: { + 'tooldia': tooldia, + 'data': deepcopy(new_data), + 'solid_geometry': geo_obj.solid_geometry + } + }) + + geo_obj.tools[1]['data']['name'] = name + else: # 'gerber' + if 0 not in geo_obj.tools: + geo_obj.tools[0] = { + 'type': 'REG', + 'size': 0.0, + 'geometry': [] + } + + try: + w_geo = geo_obj.solid_geometry.geoms if \ + isinstance(geo_obj.solid_geometry, (MultiLineString, MultiPolygon)) else geo_obj.solid_geometry + for pol in w_geo: + new_el = {'solid': pol, 'follow': LineString(pol.exterior.coords)} + geo_obj.tools[0]['geometry'].append(new_el) + except TypeError: + new_el = { + 'solid': geo_obj.solid_geometry, + 'follow': LineString(geo_obj.solid_geometry.exterior.coords) if + isinstance(geo_obj.solid_geometry, Polygon) else geo_obj.solid_geometry + } + geo_obj.tools[0]['geometry'].append(new_el) + with self.app.proc_container.new('%s ...' % _("Importing")): # Object name @@ -211,7 +328,8 @@ class ToolImage(AppTool): self.app.file_opened.emit("image", filename) # GUI feedback - self.app.inform.emit('[success] %s: %s' % (_("Opened"), filename)) + if silent is False: + self.app.inform.emit('[success] %s: %s' % (_("Opened"), filename)) def import_image_handler(self, filename, flip=True, units='MM', dpi=96, mode='black', mask=None): """ @@ -221,7 +339,7 @@ class ToolImage(AppTool): :type filename: str :param flip: Flip the object vertically. :type flip: bool - :param units: FlatCAM units + :param units: App units :type units: str :param dpi: dots per inch on the imported image :param mode: how to import the image: as 'black' or 'color' @@ -282,6 +400,93 @@ class ToolImage(AppTool): return geos + def import_image_as_trace_handler(self, svg_text, obj_type, flip=True, units='MM', dpi=96): + """ + Imports shapes from an IMAGE file into the object's geometry. + + :param svg_text: A SVG text object + :type svg_text: str + :param obj_type: the way the image is imported. As: 'gerber' or 'geometry' objects + :type obj_type: str + :param flip: Flip the object vertically. + :type flip: bool + :param units: App units + :type units: str + :param dpi: dots per inch on the imported image + :return: None + """ + + # Parse into list of shapely objects + # svg_tree = ET.parse(filename) + # svg_root = svg_tree.getroot() + svg_root = ET.fromstring(svg_text) + + # Change origin to bottom left + # h = float(svg_root.get('height')) + # w = float(svg_root.get('width')) + svg_parsed_dims = svgparselength(svg_root.get('height')) + h = svg_parsed_dims[0] + svg_units = svg_parsed_dims[1] + if svg_units in ['em', 'ex', 'pt', 'px']: + self.app.log.error("ToolImage.import_image_as_trace_handler(). SVG units not supported: %s" % svg_units) + return "fail" + + res = self.app.options['geometry_circle_steps'] + factor = svgparse_viewbox(svg_root) + + if svg_units == 'cm': + factor *= 10 + + geos = getsvggeo(svg_root, obj_type, units=units, res=res, factor=factor, app=self.app) + if geos is None: + return 'fail' + self.app.log.debug("ToolImage.import_image_as_trace_handler(). Finished parsing the SVG geometry.") + + geos_text = getsvgtext(svg_root, obj_type, app=self.app, units=units) + if geos_text is not None: + self.app.log.debug("ToolImage.import_image_as_trace_handler(). Processing SVG text.") + geos_text_f = [] + if flip: + # Change origin to bottom left + for i in geos_text: + __, minimy, __, maximy = i.bounds + h2 = (maximy - minimy) * 0.5 + geos_text_f.append(translate(scale(i, 1.0, -1.0, origin=(0, 0)), yoff=(h + h2))) + if geos_text_f: + geos += geos_text_f + + if flip: + geos = [translate(scale(g, 1.0, -1.0, origin=(0, 0))) for g in geos] + self.app.log.debug("ToolImage.import_image_as_trace_handler(). SVG geometry was flipped.") + + scale_factor = 25.4 / dpi if units.lower() == 'mm' else 1 / dpi + geos = [translate(scale(g, scale_factor, scale_factor, origin=(0, 0))) for g in geos] + + return geos + + def get_tracing_options(self): + opt_dict = { + 'ltres': self.ui.error_lines_entry.get_value(), + 'qtres': self.ui.error_splines_entry.get_value(), + 'pathomit': self.ui.path_omit_entry.get_value(), + 'rightangleenhance': self.ui.enhance_rangle_cb.get_value(), + 'colorsampling': self.ui.sampling_combo.get_value(), + 'numberofcolors': self.ui.nr_colors_entry.get_value(), + 'mincolorratio': self.ui.ratio_entry.get_value(), + 'colorquantcycles': self.ui.cycles_entry.get_value(), + 'strokewidth': self.ui.stroke_width_entry.get_value(), + 'linefilter': self.ui.line_filter_cb.get_value(), + 'roundcoords': self.ui.rounding_entry.get_value(), + 'blurradius': self.ui.blur_radius_entry.get_value(), + 'blurdelta': self.ui.blur_delta_entry.get_value() + } + dict_as_string = '{ ' + for k, v in opt_dict.items(): + dict_as_string += "%s:%s, " % (str(k), str(v)) + # remove last comma and space and add the terminator + dict_as_string = dict_as_string[:-2] + ' }' + return dict_as_string + def flatten_list(self, obj_list): for item in obj_list: if hasattr(item, '__iter__') and not isinstance(item, (str, bytes)): @@ -310,49 +515,101 @@ class ImageUI: """) self.layout.addWidget(title_label) - # Grid Layout - grid0 = GLay(v_spacing=5, h_spacing=3) - self.layout.addLayout(grid0) + self.param_lbl = FCLabel('%s' % _("Parameters"), color='blue', bold=True) + self.layout.addWidget(self.param_lbl) + # ############################################################################################################# + # ######################################## Parameters ######################################################### + # ############################################################################################################# + # add a frame and inside add a grid box layout. + par_frame = FCFrame() + self.layout.addWidget(par_frame) + + par_grid = GLay(v_spacing=5, h_spacing=3) + par_frame.setLayout(par_grid) # Type of object to create for the image - self.tf_type_obj_combo = FCComboBox() - self.tf_type_obj_combo.addItems([_("Gerber"), _("Geometry")]) - - self.tf_type_obj_combo.setItemIcon(0, QtGui.QIcon(self.app.resource_location + "/flatcam_icon16.png")) - self.tf_type_obj_combo.setItemIcon(1, QtGui.QIcon(self.app.resource_location + "/geometry16.png")) - self.tf_type_obj_combo_label = FCLabel('%s:' % _("Object Type")) self.tf_type_obj_combo_label.setToolTip( _("Specify the type of object to create from the image.\n" "It can be of type: Gerber or Geometry.") ) - grid0.addWidget(self.tf_type_obj_combo_label, 0, 0) - grid0.addWidget(self.tf_type_obj_combo, 0, 1) + + self.tf_type_obj_combo = FCComboBox() + self.tf_type_obj_combo.addItems([_("Gerber"), _("Geometry")]) + self.tf_type_obj_combo.setItemIcon(0, QtGui.QIcon(self.app.resource_location + "/flatcam_icon16.png")) + self.tf_type_obj_combo.setItemIcon(1, QtGui.QIcon(self.app.resource_location + "/geometry16.png")) + + par_grid.addWidget(self.tf_type_obj_combo_label, 0, 0) + par_grid.addWidget(self.tf_type_obj_combo, 0, 1, 1, 2) # DPI value of the imported image self.dpi_entry = FCSpinner(callback=self.confirmation_message_int) self.dpi_entry.set_range(0, 99999) self.dpi_label = FCLabel('%s:' % _("DPI value")) self.dpi_label.setToolTip(_("Specify a DPI value for the image.")) - grid0.addWidget(self.dpi_label, 2, 0) - grid0.addWidget(self.dpi_entry, 2, 1) + par_grid.addWidget(self.dpi_label, 2, 0) + par_grid.addWidget(self.dpi_entry, 2, 1, 1, 2) - grid0.addWidget(FCLabel(''), 4, 0, 1, 2) + # Area + area_lbl = FCLabel('%s' % _("Area"), bold=True) + area_lbl.setToolTip( + _("Polygons inside the image with less area are discarded.") + ) + self.min_area_entry = FCDoubleSpinner() + self.min_area_entry.set_range(0.0000, 10000.0000) + self.min_area_entry.setSingleStep(0.1) + self.min_area_entry.set_value(0.0) + a_units = _("mm") if self.app.app_units == 'MM' else _("in") + area_units_lbl = FCLabel('%s2' % a_units) - self.detail_label = FCLabel("%s:" % _('Level of detail')) - grid0.addWidget(self.detail_label, 6, 0, 1, 2) + par_grid.addWidget(area_lbl, 4, 0) + par_grid.addWidget(self.min_area_entry, 4, 1) + par_grid.addWidget(area_units_lbl, 4, 2) # Type of image interpretation - self.image_type = RadioSet([{'label': 'B/W', 'value': 'black'}, - {'label': 'Color', 'value': 'color'}]) self.image_type_label = FCLabel('%s:' % _('Image type'), bold=True) self.image_type_label.setToolTip( _("Choose a method for the image interpretation.\n" "B/W means a black & white image. Color means a colored image.") ) - grid0.addWidget(self.image_type_label, 8, 0) - grid0.addWidget(self.image_type, 8, 1) + + self.image_type = RadioSet([{'label': 'B/W', 'value': 'black'}, + {'label': 'Color', 'value': 'color'}]) + + par_grid.addWidget(self.image_type_label, 6, 0) + par_grid.addWidget(self.image_type, 6, 1, 1, 2) + + # The import Mode + self.import_mode_lbl = FCLabel('%s:' % _('Mode'), color='red', bold=True) + self.import_mode_lbl.setToolTip( + _("Choose a method for the image interpretation.\n" + "B/W means a black & white image. Color means a colored image.") + ) + + self.import_mode_radio = RadioSet([ + {'label': 'Raster', 'value': 'raster'}, + {'label': 'Tracing', 'value': 'trace'} + ]) + + mod_grid = GLay(v_spacing=5, h_spacing=3) + self.layout.addLayout(mod_grid) + + mod_grid.addWidget(self.import_mode_lbl, 0, 0) + mod_grid.addWidget(self.import_mode_radio, 0, 1) + + # ############################################################################################################# + # ######################################## Raster Mode ######################################################## + # ############################################################################################################# + # add a frame and inside add a grid box layout. + self.raster_frame = FCFrame() + self.layout.addWidget(self.raster_frame) + + raster_grid = GLay(v_spacing=5, h_spacing=3) + self.raster_frame.setLayout(raster_grid) + + self.detail_label = FCLabel("%s:" % _('Level of detail')) + raster_grid.addWidget(self.detail_label, 0, 0, 1, 2) # Mask value of the imported image when image monochrome self.mask_bw_entry = FCSpinner(callback=self.confirmation_message_int) @@ -367,8 +624,8 @@ class ImageUI: "0 means no detail and 255 means everything \n" "(which is totally black).") ) - grid0.addWidget(self.mask_bw_label, 10, 0) - grid0.addWidget(self.mask_bw_entry, 10, 1) + raster_grid.addWidget(self.mask_bw_label, 2, 0) + raster_grid.addWidget(self.mask_bw_entry, 2, 1) # Mask value of the imported image for RED color when image color self.mask_r_entry = FCSpinner(callback=self.confirmation_message_int) @@ -381,8 +638,8 @@ class ImageUI: "Decides the level of details to include\n" "in the resulting geometry.") ) - grid0.addWidget(self.mask_r_label, 12, 0) - grid0.addWidget(self.mask_r_entry, 12, 1) + raster_grid.addWidget(self.mask_r_label, 4, 0) + raster_grid.addWidget(self.mask_r_entry, 4, 1) # Mask value of the imported image for GREEN color when image color self.mask_g_entry = FCSpinner(callback=self.confirmation_message_int) @@ -395,8 +652,8 @@ class ImageUI: "Decides the level of details to include\n" "in the resulting geometry.") ) - grid0.addWidget(self.mask_g_label, 14, 0) - grid0.addWidget(self.mask_g_entry, 14, 1) + raster_grid.addWidget(self.mask_g_label, 6, 0) + raster_grid.addWidget(self.mask_g_entry, 6, 1) # Mask value of the imported image for BLUE color when image color self.mask_b_entry = FCSpinner(callback=self.confirmation_message_int) @@ -409,23 +666,268 @@ class ImageUI: "Decides the level of details to include\n" "in the resulting geometry.") ) - grid0.addWidget(self.mask_b_label, 16, 0) - grid0.addWidget(self.mask_b_entry, 16, 1) + raster_grid.addWidget(self.mask_b_label, 8, 0) + raster_grid.addWidget(self.mask_b_entry, 8, 1) + + # ############################################################################################################# + # ######################################## Raster Mode ######################################################## + # ############################################################################################################# + # add a frame and inside add a grid box layout. + self.trace_frame = FCFrame() + self.layout.addWidget(self.trace_frame) + + trace_grid = GLay(v_spacing=5, h_spacing=3) + self.trace_frame.setLayout(trace_grid) + + # Options Control Mode + self.control_lbl = FCLabel('%s:' % _('Control'), color='indigo', bold=True) + self.control_lbl.setToolTip( + _("Tracing control.") + ) + + self.control_radio = RadioSet([ + {'label': _("Presets"), 'value': 'presets'}, + {'label': _("Options"), 'value': 'options'} + ]) + + trace_grid.addWidget(self.control_lbl, 0, 0) + trace_grid.addWidget(self.control_radio, 0, 1) + + # -------------------------------------------------- + # Presets Frame + # -------------------------------------------------- + self.preset_frame = QtWidgets.QFrame() + self.preset_frame.setContentsMargins(0, 0, 0, 0) + trace_grid.addWidget(self.preset_frame, 2, 0, 1, 2) + + preset_grid = GLay(v_spacing=5, h_spacing=3) + preset_grid.setContentsMargins(0, 0, 0, 0) + self.preset_frame.setLayout(preset_grid) + + # Presets + self.presets_lbl = FCLabel('%s:' % _('Presets')) + self.presets_lbl.setToolTip( + _("Options presets to control the tracing.") + ) + + self.presets_combo = FCComboBox() + self.presets_combo.addItems([ + 'default', 'posterized1', 'posterized2', 'posterized3', 'curvy', 'sharp', 'detailed', 'smoothed', + 'grayscale', 'fixedpalette', 'randomsampling1', 'randomsampling2', 'artistic1', 'artistic2', 'artistic3', + 'artistic4' + ]) + preset_grid.addWidget(self.presets_lbl, 0, 0) + preset_grid.addWidget(self.presets_combo, 0, 1) + + # -------------------------------------------------- + # Options Frame + # -------------------------------------------------- + self.options_frame = QtWidgets.QFrame() + self.options_frame.setContentsMargins(0, 0, 0, 0) + trace_grid.addWidget(self.options_frame, 4, 0, 1, 2) + + options_grid = GLay(v_spacing=5, h_spacing=3) + options_grid.setContentsMargins(0, 0, 0, 0) + self.options_frame.setLayout(options_grid) + + # Error Threshold + self.error_lbl = FCLabel('%s' % _("Error Threshold"), bold=True) + self.error_lbl.setToolTip( + _("Error threshold for straight lines and quadratic splines.") + ) + options_grid.addWidget(self.error_lbl, 0, 0, 1, 2) + + # Error Threshold for Lines + self.error_lines_lbl = FCLabel('%s:' % _("Lines")) + self.error_lines_entry = FCDoubleSpinner() + self.error_lines_entry.set_precision(self.decimals) + self.error_lines_entry.set_range(0, 10) + self.error_lines_entry.setSingleStep(0.1) + + options_grid.addWidget(self.error_lines_lbl, 2, 0) + options_grid.addWidget(self.error_lines_entry, 2, 1) + + # Error Threshold for Splines + self.error_splines_lbl = FCLabel('%s:' % _("Splines")) + self.error_splines_entry = FCDoubleSpinner() + self.error_splines_entry.set_precision(self.decimals) + self.error_splines_entry.set_range(0, 10) + self.error_splines_entry.setSingleStep(0.1) + + options_grid.addWidget(self.error_splines_lbl, 4, 0) + options_grid.addWidget(self.error_splines_entry, 4, 1) + + # Enhance Right Angle + self.enhance_rangle_cb = FCCheckBox(_("Enhance R Angle")) + self.enhance_rangle_cb.setToolTip( + _("Enhance right angle corners.") + ) + options_grid.addWidget(self.enhance_rangle_cb, 6, 0, 1, 2) + + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) + options_grid.addWidget(separator_line, 8, 0, 1, 2) + + # Noise Reduction + self.noise_lbl = FCLabel('%s' % _("Noise Reduction"), bold=True) + options_grid.addWidget(self.noise_lbl, 10, 0, 1, 2) + + # Path Omit + self.path_omit_lbl = FCLabel('%s' % _("Path Omit")) + self.path_omit_lbl.setToolTip( + _("Edge node paths shorter than this will be discarded for noise reduction.") + ) + self.path_omit_entry = FCSpinner() + self.path_omit_entry.set_range(0, 9999) + self.path_omit_entry.setSingleStep(1) + + options_grid.addWidget(self.path_omit_lbl, 12, 0) + options_grid.addWidget(self.path_omit_entry, 12, 1) + + # Line Filter + self.line_filter_cb = FCCheckBox(_("Line Filter")) + options_grid.addWidget(self.line_filter_cb, 14, 0, 1, 2) + + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) + options_grid.addWidget(separator_line, 16, 0, 1, 2) + + # Colors Section + self.colors_lbl = FCLabel('%s' % _("Colors"), bold=True) + options_grid.addWidget(self.colors_lbl, 18, 0, 1, 2) + + # Sampling + self.samp_lbl = FCLabel('%s:' % _('Sampling')) + self.sampling_combo = FCComboBox2() + self.sampling_combo.addItems([_("Palette"), _("Random"), _("Deterministic")]) + options_grid.addWidget(self.samp_lbl, 20, 0) + options_grid.addWidget(self.sampling_combo, 20, 1) + + # Number of colors + self.nr_colors_lbl = FCLabel('%s' % _("Colors")) + self.nr_colors_lbl.setToolTip( + _("Number of colors to use on palette.") + ) + self.nr_colors_entry = FCSpinner() + self.nr_colors_entry.set_range(0, 9999) + self.nr_colors_entry.setSingleStep(1) + + options_grid.addWidget(self.nr_colors_lbl, 22, 0) + options_grid.addWidget(self.nr_colors_entry, 22, 1) + + # Randomization Ratio + self.ratio_lbl = FCLabel('%s' % _("Ratio")) + self.ratio_lbl.setToolTip( + _("Color quantization will randomize a color if fewer pixels than (total pixels * ratio) has it.") + ) + self.ratio_entry = FCSpinner() + self.ratio_entry.set_range(0, 10) + self.ratio_entry.setSingleStep(1) + + options_grid.addWidget(self.ratio_lbl, 24, 0) + options_grid.addWidget(self.ratio_entry, 24, 1) + + # Cycles of quantization + self.cycles_lbl = FCLabel('%s' % _("Cycles")) + self.cycles_lbl.setToolTip( + _("Color quantization will be repeated this many times.") + ) + self.cycles_entry = FCSpinner() + self.cycles_entry.set_range(0, 20) + self.cycles_entry.setSingleStep(1) + + options_grid.addWidget(self.cycles_lbl, 26, 0) + options_grid.addWidget(self.cycles_entry, 26, 1) + + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) + options_grid.addWidget(separator_line, 28, 0, 1, 2) + + # Parameters + self.par_lbl = FCLabel('%s' % _("Parameters"), bold=True) + options_grid.addWidget(self.par_lbl, 30, 0, 1, 2) + + # Stroke width + self.stroke_width_lbl = FCLabel('%s' % _("Stroke")) + self.stroke_width_lbl.setToolTip( + _("Width of the stroke to be applied to the shape.") + ) + self.stroke_width_entry = FCDoubleSpinner() + self.stroke_width_entry.set_precision(self.decimals) + self.stroke_width_entry.set_range(0.0000, 9999.0000) + self.stroke_width_entry.setSingleStep(0.1) + + options_grid.addWidget(self.stroke_width_lbl, 32, 0) + options_grid.addWidget(self.stroke_width_entry, 32, 1) + + # Rounding + self.rounding_lbl = FCLabel('%s' % _("Rounding")) + self.rounding_lbl.setToolTip( + _("Rounding coordinates to a given decimal place.") + ) + self.rounding_entry = FCSpinner() + self.rounding_entry.set_range(0, 10) + self.rounding_entry.setSingleStep(1) + + options_grid.addWidget(self.rounding_lbl, 34, 0) + options_grid.addWidget(self.rounding_entry, 34, 1) + + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) + options_grid.addWidget(separator_line, 36, 0, 1, 2) + + # Blur + self.blur_lbl = FCLabel('%s' % _("Blur"), bold=True) + options_grid.addWidget(self.blur_lbl, 38, 0, 1, 2) + + # Radius + self.blur_radius_lbl = FCLabel('%s' % _("Rounding")) + self.blur_radius_lbl.setToolTip( + _("Selective Gaussian blur preprocessing.") + ) + self.blur_radius_entry = FCSpinner() + self.blur_radius_entry.set_range(0, 5) + self.blur_radius_entry.setSingleStep(1) + + options_grid.addWidget(self.blur_radius_lbl, 40, 0) + options_grid.addWidget(self.blur_radius_entry, 40, 1) + + # Delta + self.blur_delta_lbl = FCLabel('%s' % _("Delta")) + self.blur_delta_lbl.setToolTip( + _("RGBA delta threshold for selective Gaussian blur preprocessing.") + ) + self.blur_delta_entry = FCDoubleSpinner() + self.blur_delta_entry.set_precision(self.decimals) + self.blur_delta_entry.set_range(0.0000, 9999.0000) + self.blur_delta_entry.setSingleStep(0.1) + + options_grid.addWidget(self.blur_delta_lbl, 42, 0) + options_grid.addWidget(self.blur_delta_entry, 42, 1) + + GLay.set_common_column_size([par_grid, mod_grid, raster_grid, trace_grid, preset_grid, options_grid], 0) # Buttons - self.import_button = QtWidgets.QPushButton(_("Import image")) + self.import_button = FCButton(_("Import image")) + self.import_button.setIcon(QtGui.QIcon(self.app.resource_location + '/image32.png')) self.import_button.setToolTip( _("Open a image of raster type and then import it in FlatCAM.") ) - grid0.addWidget(self.import_button, 18, 0, 1, 2) + self.layout.addWidget(self.import_button) self.layout.addStretch(1) - self.on_image_type(val=False) - # #################################### FINSIHED GUI ########################### # ############################################################################# + # Signals + self.import_mode_radio.activated_custom.connect(self.on_import_image_mode) + self.control_radio.activated_custom.connect(self.on_tracing_control_radio) + def on_image_type(self, val): if val == 'color': self.mask_r_label.setDisabled(False) @@ -448,6 +950,22 @@ class ImageUI: self.mask_bw_label.setDisabled(False) self.mask_bw_entry.setDisabled(False) + def on_import_image_mode(self, val): + if val == 'raster': + self.raster_frame.show() + self.trace_frame.hide() + else: + self.raster_frame.hide() + self.trace_frame.show() + + def on_tracing_control_radio(self, val): + if val == 'presets': + self.preset_frame.show() + self.options_frame.hide() + else: + self.preset_frame.hide() + self.options_frame.show() + def confirmation_message(self, accepted, minval, maxval): if accepted is False: self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"), diff --git a/appPlugins/ToolReport.py b/appPlugins/ToolReport.py index 1e93783e..7ec9ee2a 100644 --- a/appPlugins/ToolReport.py +++ b/appPlugins/ToolReport.py @@ -158,7 +158,7 @@ class ObjectReport(AppTool): font = QtGui.QFont() font.setBold(True) - p_color = QtGui.QColor("#000000") if self.app.options['global_theme'] == 'light' \ + p_color = QtGui.QColor("#000000") if self.app.options['global_theme'] in ['default', 'light'] \ else QtGui.QColor("#FFFFFF") # main Items categories diff --git a/camlib.py b/camlib.py index ba507532..a0507d3d 100644 --- a/camlib.py +++ b/camlib.py @@ -7192,7 +7192,7 @@ class CNCjob(Geometry): return try: - if self.app.options['global_theme'] == 'light': + if self.app.options['global_theme'] in ['default', 'light']: obj.annotation.set(text=text, pos=pos, visible=obj.obj_options['plot'], font_size=self.app.options["cncjob_annotation_fontsize"], color=self.app.options["cncjob_annotation_fontcolor"]) diff --git a/requirements.txt b/requirements.txt index be98b3e6..c06ac446 100644 --- a/requirements.txt +++ b/requirements.txt @@ -44,6 +44,7 @@ pyqtdarktheme gdal rasterio +svgtrace # To detect OS dark mode darkdetect diff --git a/setup_ubuntu.sh b/setup_ubuntu.sh index 941186b4..b5b6f69a 100644 --- a/setup_ubuntu.sh +++ b/setup_ubuntu.sh @@ -49,6 +49,8 @@ sudo -H python3 -m pip install --upgrade \ pikepdf \ foronoi \ ortools \ - pyqtdarktheme + pyqtdarktheme \ + darkdetect \ + svgtrace # OR-TOOLS package is now optional # ################################