From 5b63dee50d90c55b1a8de91b211e332dfdaedf7d Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sun, 19 Jan 2020 19:47:42 +0200 Subject: [PATCH] - made possible to set the colors for Excellon objects too - added to the possible colors the fundamentals: black and white - in the project context menu for setting colors added the option to set the transparency and also a default option which revert the color to the default value set in the Preferences --- FlatCAMApp.py | 84 +++++++++++++++++++++++++++++++++------- FlatCAMObj.py | 13 ++++++- ObjectCollection.py | 2 +- README.md | 3 ++ flatcamGUI/FlatCAMGUI.py | 16 ++++++++ 5 files changed, 101 insertions(+), 17 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 3f3731ff..9d73c0c8 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -12465,24 +12465,39 @@ class App(QtCore.QObject): if not sel_obj_list: return + # a default value, I just chose this one + alpha_level = 'BF' + for sel_obj in sel_obj_list: + if sel_obj.kind == 'excellon': + alpha_level = str(hex( + self.ui.excellon_defaults_form.excellon_gen_group.color_alpha_slider.value())[2:]) + elif sel_obj.kind == 'gerber': + alpha_level = str(hex(self.ui.gerber_defaults_form.gerber_gen_group.pf_color_alpha_slider.value())[2:]) + elif sel_obj.kind == 'geometry': + alpha_level = 'FF' + else: + log.debug( + "App.on_set_color_action_triggered() --> Default alpfa for this object type not supported yet") + continue + sel_obj.alpha_level = alpha_level + if act_name == _('Red'): - new_color = '#FF0000' + \ - str(hex(self.ui.gerber_defaults_form.gerber_gen_group.pf_color_alpha_slider.value())[2:]) + new_color = '#FF0000' + alpha_level if act_name == _('Blue'): - new_color = '#0000FF' + \ - str(hex(self.ui.gerber_defaults_form.gerber_gen_group.pf_color_alpha_slider.value())[2:]) + new_color = '#0000FF' + alpha_level + if act_name == _('Yellow'): - new_color = '#FFDF00' + \ - str(hex(self.ui.gerber_defaults_form.gerber_gen_group.pf_color_alpha_slider.value())[2:]) + new_color = '#FFDF00' + alpha_level if act_name == _('Green'): - new_color = '#00FF00' + \ - str(hex(self.ui.gerber_defaults_form.gerber_gen_group.pf_color_alpha_slider.value())[2:]) + new_color = '#00FF00' + alpha_level if act_name == _('Purple'): - new_color = '#FF00FF' + \ - str(hex(self.ui.gerber_defaults_form.gerber_gen_group.pf_color_alpha_slider.value())[2:]) + new_color = '#FF00FF' + alpha_level if act_name == _('Brown'): - new_color = '#A52A2A' + \ - str(hex(self.ui.gerber_defaults_form.gerber_gen_group.pf_color_alpha_slider.value())[2:]) + new_color = '#A52A2A' + alpha_level + if act_name == _('White'): + new_color = '#FFFFFF' + alpha_level + if act_name == _('Black'): + new_color = '#000000' + alpha_level if act_name == _('Custom'): new_color = QtGui.QColor(self.defaults['gerber_plot_fill'][:7]) @@ -12492,10 +12507,51 @@ class App(QtCore.QObject): if plot_fill_color.isValid() is False: return - new_color = str(plot_fill_color.name()) + \ - str(hex(self.ui.gerber_defaults_form.gerber_gen_group.pf_color_alpha_slider.value())[2:]) + new_color = str(plot_fill_color.name()) + alpha_level + + if act_name == _("Default"): + for sel_obj in sel_obj_list: + if sel_obj.kind == 'excellon': + new_color = self.defaults['excellon_plot_fill'] + new_line_color = self.defaults['excellon_plot_line'] + elif sel_obj.kind == 'gerber': + new_color = self.defaults['gerber_plot_fill'] + new_line_color = self.defaults['gerber_plot_line'] + elif sel_obj.kind == 'geometry': + new_color = self.defaults['geometry_plot_line'] + new_line_color = self.defaults['geometry_plot_line'] + else: + log.debug( + "App.on_set_color_action_triggered() --> Default color for this object type not supported yet") + continue + + sel_obj.fill_color = new_color + sel_obj.outline_color = new_line_color + + sel_obj.shapes.redraw( + update_colors=(new_color, new_line_color) + ) + return + + if act_name == _("Transparency"): + alpha_level, ok_button = QtWidgets.QInputDialog.getInt( + self.ui, _("Set alpha level ..."), '%s:' % _("Value"), min=0, max=255, step=1, value=191) + + if ok_button: + + alpha_str = str(hex(alpha_level)[2:]) if alpha_level != 0 else '00' + for sel_obj in sel_obj_list: + sel_obj.fill_color = sel_obj.fill_color[:-2] + alpha_str + + sel_obj.shapes.redraw( + update_colors=(sel_obj.fill_color, sel_obj.outline_color) + ) + + return new_line_color = color_variant(new_color[:7], 0.7) + if act_name == _("White"): + new_line_color = color_variant("#dedede", 0.7) for sel_obj in sel_obj_list: sel_obj.fill_color = new_color diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 447090a5..37a2d4bc 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -661,6 +661,7 @@ class FlatCAMGerber(FlatCAMObj, Gerber): self.fill_color = self.app.defaults['gerber_plot_fill'] self.outline_color = self.app.defaults['gerber_plot_line'] + self.alpha_level = 'bf' # keep track if the UI is built so we don't have to build it every time self.ui_build = False @@ -671,7 +672,7 @@ class FlatCAMGerber(FlatCAMObj, Gerber): # Attributes to be included in serialization # Always append to it because it carries contents # from predecessors. - self.ser_attrs += ['options', 'kind', 'fill_color', 'outline_color'] + self.ser_attrs += ['options', 'kind', 'fill_color', 'outline_color', 'alpha_level'] def set_ui(self, ui): """ @@ -2297,10 +2298,14 @@ class FlatCAMExcellon(FlatCAMObj, Excellon): self.multigeo = False self.units_found = self.app.defaults['units'] + self.fill_color = self.app.defaults['excellon_plot_fill'] + self.outline_color = self.app.defaults['excellon_plot_line'] + self.alpha_level = 'bf' + # Attributes to be included in serialization # Always append to it because it carries contents # from predecessors. - self.ser_attrs += ['options', 'kind'] + self.ser_attrs += ['options', 'kind',] def merge(self, exc_list, exc_final): """ @@ -3753,6 +3758,10 @@ class FlatCAMGeometry(FlatCAMObj, Geometry): # save here the old value for the Cut Z before it is changed by selecting a V-shape type tool in the tool table self.old_cutz = self.app.defaults["geometry_cutz"] + self.fill_color = self.app.defaults['geometry_plot_line'] + self.outline_color = self.app.defaults['geometry_plot_line'] + self.alpha_level = 'FF' + # Attributes to be included in serialization # Always append to it because it carries contents # from predecessors. diff --git a/ObjectCollection.py b/ObjectCollection.py index f134fc32..bf7c07dd 100644 --- a/ObjectCollection.py +++ b/ObjectCollection.py @@ -338,7 +338,7 @@ class ObjectCollection(QtCore.QAbstractItemModel): self.app.ui.menuprojectcolor.setEnabled(False) for obj in self.get_selected(): - if type(obj) == FlatCAMGerber: + if type(obj) == FlatCAMGerber or type(obj) == FlatCAMExcellon: self.app.ui.menuprojectcolor.setEnabled(True) if type(obj) != FlatCAMGeometry: diff --git a/README.md b/README.md index f8f3643c..da4e6eb1 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,9 @@ CAD program, and create G-Code for Isolation routing. - fixed some bugs that are visible in Linux regarding the ArgsThread class: on app close we need to quit the QThread running the ArgsThread class and also close the opened Socket - make sure that the fixes above apply when rebooting app for theme change or for language change - fixed and issue that made setting colors for the Gerber file not possible if using a translation +- made possible to set the colors for Excellon objects too +- added to the possible colors the fundamentals: black and white +- in the project context menu for setting colors added the option to set the transparency and also a default option which revert the color to the default value set in the Preferences 17.01.2020 diff --git a/flatcamGUI/FlatCAMGUI.py b/flatcamGUI/FlatCAMGUI.py index 86974e3f..9f7700d3 100644 --- a/flatcamGUI/FlatCAMGUI.py +++ b/flatcamGUI/FlatCAMGUI.py @@ -686,9 +686,25 @@ class FlatCAMGUI(QtWidgets.QMainWindow): self.menuproject_brown = self.menuprojectcolor.addAction( QtGui.QIcon(self.app.resource_location + '/brown32.png'), _('Brown')) + self.menuproject_brown = self.menuprojectcolor.addAction( + QtGui.QIcon(self.app.resource_location + '/white32.png'), _('White')) + + self.menuproject_brown = self.menuprojectcolor.addAction( + QtGui.QIcon(self.app.resource_location + '/black32.png'), _('Black')) + + self.menuprojectcolor.addSeparator() + self.menuproject_custom = self.menuprojectcolor.addAction( QtGui.QIcon(self.app.resource_location + '/set_color32.png'), _('Custom')) + self.menuprojectcolor.addSeparator() + + self.menuproject_custom = self.menuprojectcolor.addAction( + QtGui.QIcon(self.app.resource_location + '/set_color32.png'), _('Transparency')) + + self.menuproject_custom = self.menuprojectcolor.addAction( + QtGui.QIcon(self.app.resource_location + '/set_color32.png'), _('Default')) + self.menuproject.addSeparator() self.menuprojectgeneratecnc = self.menuproject.addAction(