diff --git a/AppGUI/ObjectUI.py b/AppGUI/ObjectUI.py index aaa56675..4c1f7abd 100644 --- a/AppGUI/ObjectUI.py +++ b/AppGUI/ObjectUI.py @@ -480,22 +480,38 @@ class ExcellonObjectUI(ObjectUI): parent=parent, app=self.app) - # ### Plot options #### - hlay_plot = QtWidgets.QHBoxLayout() - self.custom_box.addLayout(hlay_plot) + # Plot options + grid_h = QtWidgets.QGridLayout() + grid_h.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) + self.custom_box.addLayout(grid_h) + grid_h.setColumnStretch(0, 0) + grid_h.setColumnStretch(1, 1) self.plot_options_label = QtWidgets.QLabel("%s:" % _("Plot Options")) + self.plot_options_label.setMinimumWidth(90) + + grid_h.addWidget(self.plot_options_label, 0, 0) + + # Solid CB self.solid_cb = FCCheckBox(label=_('Solid')) self.solid_cb.setToolTip( _("Solid circles.") ) - hlay_plot.addWidget(self.plot_options_label) - hlay_plot.addStretch() - hlay_plot.addWidget(self.solid_cb) + self.solid_cb.setMinimumWidth(50) + grid_h.addWidget(self.solid_cb, 0, 1) + + # Multicolored CB + self.multicolored_cb = FCCheckBox(label=_('Multi-Color')) + self.multicolored_cb.setToolTip( + _("Draw polygons in different colors.") + ) + self.multicolored_cb.setMinimumWidth(55) + grid_h.addWidget(self.multicolored_cb, 0, 2) # ## Object name self.name_hlay = QtWidgets.QHBoxLayout() - self.custom_box.addLayout(self.name_hlay) + grid_h.addLayout(self.name_hlay, 1, 0, 1, 3) + name_label = QtWidgets.QLabel("%s:" % _("Name")) self.name_entry = FCEntry() self.name_entry.setFocusPolicy(QtCore.Qt.StrongFocus) diff --git a/AppGUI/preferences/PreferencesUIManager.py b/AppGUI/preferences/PreferencesUIManager.py index f848f5f0..a712c127 100644 --- a/AppGUI/preferences/PreferencesUIManager.py +++ b/AppGUI/preferences/PreferencesUIManager.py @@ -168,6 +168,7 @@ class PreferencesUIManager: # Excellon General "excellon_plot": self.ui.excellon_defaults_form.excellon_gen_group.plot_cb, "excellon_solid": self.ui.excellon_defaults_form.excellon_gen_group.solid_cb, + "excellon_multicolored": self.ui.excellon_defaults_form.excellon_gen_group.multicolored_cb, "excellon_format_upper_in": self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_upper_in_entry, "excellon_format_lower_in": diff --git a/AppGUI/preferences/excellon/ExcellonGenPrefGroupUI.py b/AppGUI/preferences/excellon/ExcellonGenPrefGroupUI.py index 5de50b82..174568a2 100644 --- a/AppGUI/preferences/excellon/ExcellonGenPrefGroupUI.py +++ b/AppGUI/preferences/excellon/ExcellonGenPrefGroupUI.py @@ -36,22 +36,31 @@ class ExcellonGenPrefGroupUI(OptionsGroupUI): grid1 = QtWidgets.QGridLayout() self.layout.addLayout(grid1) + # Plot CB self.plot_cb = FCCheckBox(label=_('Plot')) self.plot_cb.setToolTip( "Plot (show) this object." ) grid1.addWidget(self.plot_cb, 0, 0) + # Solid CB self.solid_cb = FCCheckBox(label=_('Solid')) self.solid_cb.setToolTip( "Plot as solid circles." ) grid1.addWidget(self.solid_cb, 0, 1) + # Multicolored CB + self.multicolored_cb = FCCheckBox(label='%s' % _('M-Color')) + self.multicolored_cb.setToolTip( + _("Draw polygons in different colors.") + ) + grid1.addWidget(self.multicolored_cb, 0, 2) + separator_line = QtWidgets.QFrame() separator_line.setFrameShape(QtWidgets.QFrame.HLine) separator_line.setFrameShadow(QtWidgets.QFrame.Sunken) - grid1.addWidget(separator_line, 1, 0, 1, 2) + grid1.addWidget(separator_line, 1, 0, 1, 3) grid2 = QtWidgets.QGridLayout() self.layout.addLayout(grid2) diff --git a/AppGUI/preferences/excellon/ExcellonPreferencesUI.py b/AppGUI/preferences/excellon/ExcellonPreferencesUI.py index b62fb197..dd1305d9 100644 --- a/AppGUI/preferences/excellon/ExcellonPreferencesUI.py +++ b/AppGUI/preferences/excellon/ExcellonPreferencesUI.py @@ -31,7 +31,7 @@ class ExcellonPreferencesUI(QtWidgets.QWidget): self.decimals = decimals self.excellon_gen_group = ExcellonGenPrefGroupUI(decimals=self.decimals) - self.excellon_gen_group.setMinimumWidth(220) + self.excellon_gen_group.setMinimumWidth(240) self.excellon_opt_group = ExcellonOptPrefGroupUI(decimals=self.decimals) self.excellon_opt_group.setMinimumWidth(290) self.excellon_exp_group = ExcellonExpPrefGroupUI(decimals=self.decimals) diff --git a/AppObjects/FlatCAMExcellon.py b/AppObjects/FlatCAMExcellon.py index 2dfd4c60..71ce705c 100644 --- a/AppObjects/FlatCAMExcellon.py +++ b/AppObjects/FlatCAMExcellon.py @@ -19,6 +19,7 @@ from AppParsers.ParseExcellon import Excellon from AppObjects.FlatCAMObj import * import itertools +import numpy as np import gettext import AppTranslation as fcTranslate @@ -50,6 +51,7 @@ class ExcellonObject(FlatCAMObj, Excellon): self.options.update({ "plot": True, "solid": False, + "multicolored": False, "operation": "drill", "milling_type": "drills", @@ -607,6 +609,7 @@ class ExcellonObject(FlatCAMObj, Excellon): self.form_fields.update({ "plot": self.ui.plot_cb, "solid": self.ui.solid_cb, + "multicolored": self.ui.multicolored_cb, "operation": self.ui.operation_radio, "milling_type": self.ui.milling_type_radio, @@ -708,6 +711,8 @@ class ExcellonObject(FlatCAMObj, Excellon): self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click) self.ui.solid_cb.stateChanged.connect(self.on_solid_cb_click) + self.ui.multicolored_cb.stateChanged.connect(self.on_multicolored_cb_click) + self.ui.generate_cnc_button.clicked.connect(self.on_create_cncjob_button_click) self.ui.generate_milling_button.clicked.connect(self.on_generate_milling_button_click) self.ui.generate_milling_slots_button.clicked.connect(self.on_generate_milling_slots_button_click) @@ -1751,6 +1756,12 @@ class ExcellonObject(FlatCAMObj, Excellon): self.read_form_item('solid') self.plot() + def on_multicolored_cb_click(self, *args): + if self.muted_ui: + return + self.read_form_item('multicolored') + self.plot() + def on_plot_cb_click(self, *args): if self.muted_ui: return @@ -1824,6 +1835,27 @@ class ExcellonObject(FlatCAMObj, Excellon): if not FlatCAMObj.plot(self): return + if self.app.is_legacy is False: + def random_color(): + r_color = np.random.rand(4) + r_color[3] = 1 + return r_color + else: + def random_color(): + while True: + r_color = np.random.rand(4) + r_color[3] = 1 + + new_color = '#' + for idx in range(len(r_color)): + new_color += '%x' % int(r_color[idx] * 255) + # do it until a valid color is generated + # a valid color has the # symbol, another 6 chars for the color and the last 2 chars for alpha + # for a total of 9 chars + if len(new_color) == 9: + break + return new_color + # try: # # Plot Excellon (All polygons?) # if self.options["solid"]: @@ -1855,12 +1887,26 @@ class ExcellonObject(FlatCAMObj, Excellon): try: # Plot Excellon (All polygons?) if self.options["solid"]: - for geo in self.solid_geometry: - self.add_shape(shape=geo, - color=self.outline_color, - face_color=self.fill_color, - visible=visible, - layer=2) + # for geo in self.solid_geometry: + # self.add_shape(shape=geo, + # color=self.outline_color, + # face_color=random_color() if self.options['multicolored'] else self.fill_color, + # visible=visible, + # layer=2) + + # plot polygons for each tool separately + for tool in self.tools: + # set the color here so we have one color for each tool + geo_color = random_color() + + # tool is a dict also + for geo in self.tools[tool]["solid_geometry"]: + self.add_shape(shape=geo, + color=geo_color if self.options['multicolored'] else self.outline_color, + face_color=geo_color if self.options['multicolored'] else self.fill_color, + visible=visible, + layer=2) + else: for geo in self.solid_geometry: self.add_shape(shape=geo.exterior, color='red', visible=visible) diff --git a/AppObjects/FlatCAMObj.py b/AppObjects/FlatCAMObj.py index 330f4d98..7c292aec 100644 --- a/AppObjects/FlatCAMObj.py +++ b/AppObjects/FlatCAMObj.py @@ -459,8 +459,13 @@ class FlatCAMObj(QtCore.QObject): def visible(self, value, threaded=True): log.debug("FlatCAMObj.visible()") - # self.shapes.visible = value # maybe this is slower in VisPy - self.shapes.enabled = value + # self.shapes.visible = value # maybe this is slower in VisPy? use enabled property? + if self.shapes.visible is True: + if value is False: + self.shapes.visible = False + else: + if value is True: + self.shapes.visible = True if self.app.is_legacy is False: # Not all object types has annotations diff --git a/CHANGELOG.md b/CHANGELOG.md index ceefe67b..a4d558a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ CHANGELOG for FlatCAM beta - In Tool Isolation made sure that the use of ESC key while some processes are active will disconnect the mouse events that may be connected, correctly - optimized the Gerber UI - added a Multi-color checkbox for the Geometry UI (will color differently tool geometry when the geometry is multitool) +- added a Multi-color checkbox for the Excellon UI (this way colors for each tool are easier to differentiate especially when the diameter is close) 29.05.2020 diff --git a/defaults.py b/defaults.py index c72ad391..833563cb 100644 --- a/defaults.py +++ b/defaults.py @@ -212,6 +212,7 @@ class FlatCAMDefaults: # Excellon General "excellon_plot": True, "excellon_solid": True, + "excellon_multicolored": False, "excellon_format_upper_in": 2, "excellon_format_lower_in": 4, "excellon_format_upper_mm": 3,