From 786423eb578a4dd6378bd929873a793fdc8d427a Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Tue, 21 Jul 2020 15:52:53 +0300 Subject: [PATCH] - fixed some issues in Excellon Editor due of recent changes - moved the Gerber colors fill in the AppObject.on_object_created() slot and fixed some minor issues here --- CHANGELOG.md | 2 ++ appEditors/AppExcEditor.py | 65 +++++++++++++++++------------------ appObjects/AppObject.py | 69 +++++++++++++++++++------------------- app_Main.py | 1 - defaults.py | 4 +-- 5 files changed, 72 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1f577a0..11bb5d38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ CHANGELOG for FlatCAM beta - Excellon UI: made sure that when the Multicolor checkbox is unchecked, the color is updated in the Color column of the tools table - made sure that the Preferences files are deleted on new version install, while the application is in Beta status - fixed issues with detecting older Preferences files +- fixed some issues in Excellon Editor due of recent changes +- moved the Gerber colors fill in the AppObject.on_object_created() slot and fixed some minor issues here 20.07.2020 diff --git a/appEditors/AppExcEditor.py b/appEditors/AppExcEditor.py index 86a3ed47..7640d406 100644 --- a/appEditors/AppExcEditor.py +++ b/appEditors/AppExcEditor.py @@ -44,6 +44,7 @@ class FCDrillAdd(FCShapeTool): def __init__(self, draw_app): DrawTool.__init__(self, draw_app) self.name = 'drill_add' + self.draw_app = draw_app self.selected_dia = None try: @@ -52,8 +53,8 @@ class FCDrillAdd(FCShapeTool): # as a visual marker, select again in tooltable the actual tool that we are using # remember that it was deselected when clicking on canvas - item = self.draw_app.tools_table_exc.item((self.draw_app.last_tool_selected - 1), 1) - self.draw_app.tools_table_exc.setCurrentItem(item) + item = self.draw_app.e_ui.tools_table_exc.item((self.draw_app.last_tool_selected - 1), 1) + self.draw_app.e_ui.tools_table_exc.setCurrentItem(item) except KeyError: self.draw_app.app.inform.emit('[WARNING_NOTCL] %s' % _("To add a drill first select a tool")) self.draw_app.select_tool("drill_select") @@ -124,7 +125,7 @@ class FCDrillAdd(FCShapeTool): def clean_up(self): self.draw_app.selected = [] - self.draw_app.tools_table_exc.clearSelection() + self.draw_app.e_ui.tools_table_exc.clearSelection() self.draw_app.plot_all() try: @@ -169,8 +170,8 @@ class FCDrillArray(FCShapeTool): self.selected_dia = self.draw_app.tool2tooldia[self.draw_app.last_tool_selected] # as a visual marker, select again in tooltable the actual tool that we are using # remember that it was deselected when clicking on canvas - item = self.draw_app.tools_table_exc.item((self.draw_app.last_tool_selected - 1), 1) - self.draw_app.tools_table_exc.setCurrentItem(item) + item = self.draw_app.e_ui.tools_table_exc.item((self.draw_app.last_tool_selected - 1), 1) + self.draw_app.e_ui.tools_table_exc.setCurrentItem(item) except KeyError: self.draw_app.app.inform.emit('[WARNING_NOTCL] %s' % _("To add an Drill Array first select a tool in Tool Table")) @@ -359,7 +360,7 @@ class FCDrillArray(FCShapeTool): def clean_up(self): self.draw_app.selected = [] - self.draw_app.tools_table_exc.clearSelection() + self.draw_app.e_ui.tools_table_exc.clearSelection() self.draw_app.plot_all() try: @@ -387,8 +388,8 @@ class FCSlot(FCShapeTool): # as a visual marker, select again in tooltable the actual tool that we are using # remember that it was deselected when clicking on canvas - item = self.draw_app.tools_table_exc.item((self.draw_app.last_tool_selected - 1), 1) - self.draw_app.tools_table_exc.setCurrentItem(item) + item = self.draw_app.e_ui.tools_table_exc.item((self.draw_app.last_tool_selected - 1), 1) + self.draw_app.e_ui.tools_table_exc.setCurrentItem(item) except KeyError: self.draw_app.app.inform.emit('[WARNING_NOTCL] %s' % _("To add a slot first select a tool")) self.draw_app.select_tool("drill_select") @@ -561,7 +562,7 @@ class FCSlot(FCShapeTool): def clean_up(self): self.draw_app.selected = [] - self.draw_app.tools_table_exc.clearSelection() + self.draw_app.e_ui.tools_table_exc.clearSelection() self.draw_app.plot_all() try: @@ -589,8 +590,8 @@ class FCSlotArray(FCShapeTool): self.selected_dia = self.draw_app.tool2tooldia[self.draw_app.last_tool_selected] # as a visual marker, select again in tooltable the actual tool that we are using # remember that it was deselected when clicking on canvas - item = self.draw_app.tools_table_exc.item((self.draw_app.last_tool_selected - 1), 1) - self.draw_app.tools_table_exc.setCurrentItem(item) + item = self.draw_app.e_ui.tools_table_exc.item((self.draw_app.last_tool_selected - 1), 1) + self.draw_app.e_ui.tools_table_exc.setCurrentItem(item) except KeyError: self.draw_app.app.inform.emit('[WARNING_NOTCL] %s' % _("To add an Slot Array first select a tool in Tool Table")) @@ -886,7 +887,7 @@ class FCSlotArray(FCShapeTool): def clean_up(self): self.draw_app.selected = [] - self.draw_app.tools_table_exc.clearSelection() + self.draw_app.e_ui.tools_table_exc.clearSelection() self.draw_app.plot_all() try: @@ -922,7 +923,7 @@ class FCDrillResize(FCShapeTool): self.draw_app.is_modified = True try: - self.draw_app.tools_table_exc.itemChanged.disconnect() + self.draw_app.e_ui.tools_table_exc.itemChanged.disconnect() except TypeError: pass @@ -943,11 +944,11 @@ class FCDrillResize(FCShapeTool): else: self.destination_storage = self.draw_app.storage_dict[new_dia] - for index in self.draw_app.tools_table_exc.selectedIndexes(): + for index in self.draw_app.e_ui.tools_table_exc.selectedIndexes(): row = index.row() # on column 1 in tool tables we hold the diameters, and we retrieve them as strings # therefore below we convert to float - dia_on_row = self.draw_app.tools_table_exc.item(row, 1).text() + dia_on_row = self.draw_app.e_ui.tools_table_exc.item(row, 1).text() self.selected_dia_set.add(float(dia_on_row)) # since we add a new tool, we update also the intial state of the tool_table through it's dictionary @@ -1105,7 +1106,7 @@ class FCDrillResize(FCShapeTool): self.geometry = [] # we reactivate the signals after the after the tool editing - self.draw_app.tools_table_exc.itemChanged.connect(self.draw_app.on_tool_edit) + self.draw_app.e_ui.tools_table_exc.itemChanged.connect(self.draw_app.on_tool_edit) self.draw_app.app.inform.emit('[success] %s' % _("Done. Drill/Slot Resize completed.")) @@ -1124,7 +1125,7 @@ class FCDrillResize(FCShapeTool): def clean_up(self): self.draw_app.selected = [] - self.draw_app.tools_table_exc.clearSelection() + self.draw_app.e_ui.tools_table_exc.clearSelection() self.draw_app.plot_all() try: @@ -1153,11 +1154,11 @@ class FCDrillMove(FCShapeTool): self.current_storage = None self.geometry = [] - for index in self.draw_app.tools_table_exc.selectedIndexes(): + for index in self.draw_app.e_ui.tools_table_exc.selectedIndexes(): row = index.row() # on column 1 in tool tables we hold the diameters, and we retrieve them as strings # therefore below we convert to float - dia_on_row = self.draw_app.tools_table_exc.item(row, 1).text() + dia_on_row = self.draw_app.e_ui.tools_table_exc.item(row, 1).text() self.selected_dia_list.append(float(dia_on_row)) self.draw_app.app.jump_signal.connect(lambda x: self.draw_app.update_utility_geometry(data=x)) @@ -1264,7 +1265,7 @@ class FCDrillMove(FCShapeTool): def clean_up(self): self.draw_app.selected = [] - self.draw_app.tools_table_exc.clearSelection() + self.draw_app.e_ui.tools_table_exc.clearSelection() self.draw_app.plot_all() try: @@ -1319,7 +1320,7 @@ class FCDrillCopy(FCDrillMove): def clean_up(self): self.draw_app.selected = [] - self.draw_app.tools_table_exc.clearSelection() + self.draw_app.e_ui.tools_table_exc.clearSelection() self.draw_app.plot_all() try: @@ -1369,7 +1370,7 @@ class FCDrillSelect(DrawTool): self.exc_editor_app.selected = [] def click_release(self, pos): - self.exc_editor_app.tools_table_exc.clearSelection() + self.exc_editor_app.e_ui.tools_table_exc.clearSelection() xmin, ymin, xmax, ymax = 0, 0, 0, 0 try: @@ -1425,12 +1426,12 @@ class FCDrillSelect(DrawTool): # select the diameter of the selected shape in the tool table try: - self.exc_editor_app.tools_table_exc.cellPressed.disconnect() + self.exc_editor_app.e_ui.tools_table_exc.cellPressed.disconnect() except (TypeError, AttributeError): pass # if mod_key == self.exc_editor_app.app.defaults["global_mselect_key"]: - # self.exc_editor_app.tools_table_exc.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection) + # self.exc_editor_app.e_ui.tools_table_exc.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection) self.sel_tools.clear() for shape_s in self.exc_editor_app.selected: @@ -1438,17 +1439,17 @@ class FCDrillSelect(DrawTool): if shape_s in self.exc_editor_app.storage_dict[storage].get_objects(): self.sel_tools.add(storage) - self.exc_editor_app.tools_table_exc.clearSelection() + self.exc_editor_app.e_ui.tools_table_exc.clearSelection() for storage in self.sel_tools: for k, v in self.exc_editor_app.tool2tooldia.items(): if v == storage: - self.exc_editor_app.tools_table_exc.selectRow(int(k) - 1) + self.exc_editor_app.e_ui.tools_table_exc.selectRow(int(k) - 1) self.exc_editor_app.last_tool_selected = int(k) break - # self.exc_editor_app.tools_table_exc.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) + # self.exc_editor_app.e_ui.tools_table_exc.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) - self.exc_editor_app.tools_table_exc.cellPressed.connect(self.exc_editor_app.on_row_selected) + self.exc_editor_app.e_ui.tools_table_exc.cellPressed.connect(self.exc_editor_app.on_row_selected) # delete whatever is in selection storage, there is no longer need for those shapes self.sel_storage = AppExcEditor.make_storage() @@ -1467,7 +1468,7 @@ class FCDrillSelect(DrawTool): # if not over_shape_list: # self.exc_editor_app.selected = [] # AppExcEditor.draw_shape_idx = -1 - # self.exc_editor_app.tools_table_exc.clearSelection() + # self.exc_editor_app.e_ui.tools_table_exc.clearSelection() # else: # # if there are shapes under our click then advance through the list of them, one at the time in a # # circular way @@ -1500,9 +1501,9 @@ class FCDrillSelect(DrawTool): # if shape in self.exc_editor_app.storage_dict[storage].get_objects(): # for key in self.exc_editor_app.tool2tooldia: # if self.exc_editor_app.tool2tooldia[key] == storage: - # item = self.exc_editor_app.tools_table_exc.item((key - 1), 1) + # item = self.exc_editor_app.e_ui.tools_table_exc.item((key - 1), 1) # item.setSelected(True) - # # self.exc_editor_app.tools_table_exc.selectItem(key - 1) + # # self.exc_editor_app.e_ui.tools_table_exc.selectItem(key - 1) # # except Exception as e: # log.error("[ERROR] Something went bad. %s" % str(e)) @@ -1536,7 +1537,7 @@ class AppExcEditor(QtCore.QObject): self.e_ui.addtool_btn.clicked.connect(self.on_tool_add) self.e_ui.addtool_entry.editingFinished.connect(self.on_tool_add) self.e_ui.deltool_btn.clicked.connect(self.on_tool_delete) - # self.tools_table_exc.selectionModel().currentChanged.connect(self.on_row_selected) + # self.e_ui.tools_table_exc.selectionModel().currentChanged.connect(self.on_row_selected) self.e_ui.tools_table_exc.cellPressed.connect(self.on_row_selected) self.e_ui.array_type_combo.currentIndexChanged.connect(self.on_array_type_combo) diff --git a/appObjects/AppObject.py b/appObjects/AppObject.py index 0ab1cc71..9387384b 100644 --- a/appObjects/AppObject.py +++ b/appObjects/AppObject.py @@ -193,40 +193,6 @@ class AppObject(QtCore.QObject): log.warning("AppObject.new_object() -> The object has no bounds properties. %s" % str(e)) return "fail" - # ############################################################################################################ - # Set the colors for the objects that have geometry - # ############################################################################################################ - if kind != 'document' and kind != 'script': - try: - if kind == 'excellon': - obj.fill_color = self.app.defaults["excellon_plot_fill"] - obj.outline_color = self.app.defaults["excellon_plot_line"] - - if kind == 'gerber': - if self.app.defaults["gerber_store_color_list"] is True: - group = self.app.collection.group_items["gerber"] - index = group.child_count() - - # when loading a Gerber object always create a color tuple (line color, fill_color) - # and add it to the self.app.defaults["gerber_color_list"] from where it will be picked and used - try: - colors = self.app.defaults["gerber_color_list"][index] - except IndexError: - obj.outline_color = self.app.defaults["gerber_plot_line"] - obj.fill_color = self.app.defaults["gerber_plot_fill"] - self.app.defaults["gerber_color_list"].insert(index, (obj.outline_color, obj.fill_color)) - colors = self.app.defaults["gerber_color_list"][index] - - new_line_color = colors[0] - new_fill = colors[1] - obj.outline_color = new_line_color - obj.fill_color = new_fill - else: - obj.outline_color = self.app.defaults["gerber_plot_line"] - obj.fill_color = self.app.defaults["gerber_plot_fill"] - except Exception as e: - log.warning("AppObject.new_object() -> setting colors error. %s" % str(e)) - # ############################################################################################################ # update the KeyWords list with the name of the file # ############################################################################################################ @@ -395,6 +361,41 @@ class AppObject(QtCore.QObject): name=str(obj.options['name']), tx=_("created/selected")) ) + + # ############################################################################################################ + # Set the colors for the objects that have geometry + # ############################################################################################################ + if obj.kind != 'document' and obj.kind != 'script': + try: + if obj.kind == 'excellon': + obj.fill_color = self.app.defaults["excellon_plot_fill"] + obj.outline_color = self.app.defaults["excellon_plot_line"] + + if obj.kind == 'gerber': + if self.app.defaults["gerber_store_color_list"] is True: + group = self.app.collection.group_items["gerber"] + index = group.child_count() - 1 + + # when loading a Gerber object always create a color tuple (line color, fill_color) + # and add it to the self.app.defaults["gerber_color_list"] from where it will be picked and used + try: + colors = self.app.defaults["gerber_color_list"][index] + except IndexError: + obj.outline_color = self.app.defaults["gerber_plot_line"] + obj.fill_color = self.app.defaults["gerber_plot_fill"] + colors = (obj.outline_color, obj.fill_color) + self.app.defaults["gerber_color_list"].append(colors) + + new_line_color = colors[0] + new_fill = colors[1] + obj.outline_color = new_line_color + obj.fill_color = new_fill + else: + obj.outline_color = self.app.defaults["gerber_plot_line"] + obj.fill_color = self.app.defaults["gerber_plot_fill"] + except Exception as e: + log.warning("AppObject.new_object() -> setting colors error. %s" % str(e)) + # ############################################################################################################# # update the SHELL auto-completer model with the name of the new object # ############################################################################################################# diff --git a/app_Main.py b/app_Main.py index 8c64ae1e..e69dadd4 100644 --- a/app_Main.py +++ b/app_Main.py @@ -10137,7 +10137,6 @@ class App(QtCore.QObject): group_index = self.collection.index(group.row(), 0, QtCore.QModelIndex()) new_c = (new_line_color, new_color) - for sel_obj in sel_obj_list: if sel_obj.kind == 'gerber': item = sel_obj.item diff --git a/defaults.py b/defaults.py index bbac7954..a731e191 100644 --- a/defaults.py +++ b/defaults.py @@ -2,7 +2,7 @@ import os import stat import sys from copy import deepcopy -from Common import LoudDict, LoudUniqueList +from Common import LoudDict from camlib import to_dict, CNCjob, Geometry import simplejson import logging @@ -156,7 +156,7 @@ class FlatCAMDefaults: "gerber_plot": True, "gerber_solid": True, "gerber_multicolored": False, - "gerber_color_list": LoudUniqueList(), + "gerber_color_list": [], "gerber_store_color_list": True, "gerber_circle_steps": 64,