Kaynağa Gözat

- fixed Geometry Editor to work in legacy graphic engine
- fixed Excellon Editor to work in legacy graphic engine

Marius Stanciu 6 yıl önce
ebeveyn
işleme
63b261685d

+ 20 - 0
FlatCAMApp.py

@@ -3143,12 +3143,32 @@ class App(QtCore.QObject):
                             self.collection.set_active(old_name)
                             self.collection.delete_active()
 
+                        # restore GUI to the Selected TAB
+                        # Remove anything else in the GUI
+                        self.ui.selected_scroll_area.takeWidget()
+                        # Switch notebook to Selected page
+                        self.ui.notebook.setCurrentWidget(self.ui.selected_tab)
+
                     elif isinstance(edited_obj, FlatCAMExcellon):
                         obj_type = "Excellon"
                         if cleanup is None:
                             self.exc_editor.update_fcexcellon(edited_obj)
                             self.exc_editor.update_options(edited_obj)
+
                         self.exc_editor.deactivate()
+
+                        # delete the old object (the source object) if it was an empty one
+                        if len(edited_obj.drills) == 0 and len(edited_obj.slots) == 0:
+                            old_name = edited_obj.options['name']
+                            self.collection.set_active(old_name)
+                            self.collection.delete_active()
+
+                        # restore GUI to the Selected TAB
+                        # Remove anything else in the GUI
+                        self.ui.tool_scroll_area.takeWidget()
+                        # Switch notebook to Selected page
+                        self.ui.notebook.setCurrentWidget(self.ui.selected_tab)
+
                     else:
                         self.inform.emit('[WARNING_NOTCL] %s' %
                                          _("Select a Gerber, Geometry or Excellon Object to update."))

+ 3 - 0
README.md

@@ -21,6 +21,9 @@ CAD program, and create G-Code for Isolation routing.
 - fixed drawing of selection box when dragging mouse on screen and the selection shape drawing on the selected objects
 - fixed the moving drawing shape in Tool Move in legacy graphic engine
 - fixed moving geometry in Tool Measurement in legacy graphic engine
+- fixed Geometry Editor to work in legacy graphic engine
+- fixed Excellon Editor to work in legacy graphic engine
+
 
 20.09.2019
 

+ 75 - 43
flatcamEditors/FlatCAMExcEditor.py

@@ -2456,8 +2456,10 @@ class FlatCAMExcEditor(QtCore.QObject):
                 row_to_be_selected = int(key) - 1
                 self.last_tool_selected = int(key)
                 break
-
-        self.tools_table_exc.selectRow(row_to_be_selected)
+        try:
+            self.tools_table_exc.selectRow(row_to_be_selected)
+        except TypeError as e:
+            log.debug("FlatCAMExcEditor.on_tool_add() --> %s" % str(e))
 
     def on_tool_delete(self, dia=None):
         self.is_modified = True
@@ -2928,6 +2930,11 @@ class FlatCAMExcEditor(QtCore.QObject):
 
         self.select_tool("drill_select")
 
+        # reset the tool table
+        self.tools_table_exc.clear()
+        self.tools_table_exc.setHorizontalHeaderLabels(['#', _('Diameter'), 'D', 'S'])
+        self.last_tool_selected = None
+
         self.set_ui()
 
         # now that we hava data, create the GUI interface and add it to the Tool Tab
@@ -3078,6 +3085,7 @@ class FlatCAMExcEditor(QtCore.QObject):
         # element[1] of the tuple is a list of coordinates (a tuple themselves)
         ordered_edited_points = sorted(zip(edited_points.keys(), edited_points.values()))
 
+
         current_tool = 0
         for tool_dia in ordered_edited_points:
             current_tool += 1
@@ -3146,26 +3154,13 @@ class FlatCAMExcEditor(QtCore.QObject):
                     self.edited_obj_name += "_1"
             else:
                 self.edited_obj_name += "_edit"
-
-        self.app.worker_task.emit({'fcn': self.new_edited_excellon,
-                                   'params': [self.edited_obj_name]})
-
         self.new_tool_offset = self.exc_obj.tool_offset
 
-        # reset the tool table
-        self.tools_table_exc.clear()
-        self.tools_table_exc.setHorizontalHeaderLabels(['#', _('Diameter'), 'D', 'S'])
-        self.last_tool_selected = None
-
-        # delete the edited Excellon object which will be replaced by a new one having the edited content of the first
-        # self.app.collection.set_active(self.exc_obj.options['name'])
-        # self.app.collection.delete_active()
-
-        # restore GUI to the Selected TAB
-        # Remove anything else in the GUI
-        self.app.ui.tool_scroll_area.takeWidget()
-        # Switch notebook to Selected page
-        self.app.ui.notebook.setCurrentWidget(self.app.ui.selected_tab)
+        self.app.worker_task.emit({'fcn': self.new_edited_excellon,
+                                   'params': [self.edited_obj_name,
+                                              self.new_drills,
+                                              self.new_slots,
+                                              self.new_tools]})
 
     def update_options(self, obj):
         try:
@@ -3182,7 +3177,7 @@ class FlatCAMExcEditor(QtCore.QObject):
             obj.options = {}
             return True
 
-    def new_edited_excellon(self, outname):
+    def new_edited_excellon(self, outname, n_drills, n_slots, n_tools):
         """
         Creates a new Excellon object for the edited Excellon. Thread-safe.
 
@@ -3195,12 +3190,17 @@ class FlatCAMExcEditor(QtCore.QObject):
         self.app.log.debug("Update the Excellon object with edited content. Source is %s" %
                            self.exc_obj.options['name'])
 
+        new_drills = n_drills
+        new_slots = n_slots
+        new_tools = n_tools
+
         # How the object should be initialized
         def obj_init(excellon_obj, app_obj):
+
             # self.progress.emit(20)
-            excellon_obj.drills = self.new_drills
-            excellon_obj.tools = self.new_tools
-            excellon_obj.slots = self.new_slots
+            excellon_obj.drills = deepcopy(new_drills)
+            excellon_obj.tools = deepcopy(new_tools)
+            excellon_obj.slots = deepcopy(new_slots)
             excellon_obj.tool_offset = self.new_tool_offset
             excellon_obj.options['name'] = outname
 
@@ -3217,15 +3217,17 @@ class FlatCAMExcEditor(QtCore.QObject):
                 app_obj.inform.emit(msg)
                 raise
                 # raise
-            excellon_obj.source_file = self.app.export_excellon(obj_name=outname, filename=None,
-                                                                local_use=excellon_obj, use_thread=False)
 
         with self.app.proc_container.new(_("Creating Excellon.")):
 
             try:
-                self.app.new_object("excellon", outname, obj_init)
+                edited_obj = self.app.new_object("excellon", outname, obj_init)
+                edited_obj.source_file = self.app.export_excellon(obj_name=edited_obj.options['name'],
+                                                                  local_use=edited_obj,
+                                                                  filename=None,
+                                                                  use_thread=False)
             except Exception as e:
-                log.error("Error on object creation: %s" % str(e))
+                log.error("Error on Edited object creation: %s" % str(e))
                 self.app.progress.emit(100)
                 return
 
@@ -3307,20 +3309,28 @@ class FlatCAMExcEditor(QtCore.QObject):
         :param event: Event object dispatched by VisPy
         :return: None
         """
+        if self.app.is_legacy is False:
+            event_pos = event.pos
+            event_is_dragging = event.is_dragging
+            right_button = 2
+        else:
+            event_pos = (event.xdata, event.ydata)
+            event_is_dragging = self.app.plotcanvas.is_dragging
+            right_button = 3
 
-        self.pos = self.canvas.translate_coords(event.pos)
+        self.pos = self.canvas.translate_coords(event_pos)
 
         if self.app.grid_status() == True:
             self.pos  = self.app.geo_editor.snap(self.pos[0], self.pos[1])
         else:
             self.pos = (self.pos[0], self.pos[1])
 
-        if event.button is 1:
+        if event.button == 1:
             self.app.ui.rel_position_label.setText("<b>Dx</b>: %.4f&nbsp;&nbsp;  <b>Dy</b>: "
                                                    "%.4f&nbsp;&nbsp;&nbsp;&nbsp;" % (0, 0))
 
             # Selection with left mouse button
-            if self.active_tool is not None and event.button is 1:
+            if self.active_tool is not None and event.button == 1:
                 # Dispatch event to active_tool
                 # msg = self.active_tool.click(self.app.geo_editor.snap(event.xdata, event.ydata))
                 self.active_tool.click(self.app.geo_editor.snap(self.pos[0], self.pos[1]))
@@ -3338,6 +3348,7 @@ class FlatCAMExcEditor(QtCore.QObject):
                         modifier_to_use = Qt.ControlModifier
                     else:
                         modifier_to_use = Qt.ShiftModifier
+
                     # if modifier key is pressed then we add to the selected list the current shape but if it's already
                     # in the selected list, we removed it. Therefore first click selects, second deselects.
                     if key_modifier == modifier_to_use:
@@ -3442,7 +3453,17 @@ class FlatCAMExcEditor(QtCore.QObject):
         :param event: Event object dispatched by VisPy SceneCavas
         :return: None
         """
-        pos_canvas = self.canvas.translate_coords(event.pos)
+
+        if self.app.is_legacy is False:
+            event_pos = event.pos
+            event_is_dragging = event.is_dragging
+            right_button = 2
+        else:
+            event_pos = (event.xdata, event.ydata)
+            event_is_dragging = self.app.plotcanvas.is_dragging
+            right_button = 3
+
+        pos_canvas = self.canvas.translate_coords(event_pos)
 
         if self.app.grid_status() == True:
             pos = self.app.geo_editor.snap(pos_canvas[0], pos_canvas[1])
@@ -3452,7 +3473,7 @@ class FlatCAMExcEditor(QtCore.QObject):
         # if the released mouse button was RMB then test if it was a panning motion or not, if not it was a context
         # canvas menu
         try:
-            if event.button == 2:  # right click
+            if event.button == right_button:  # right click
                 if self.app.ui.popMenu.mouse_is_panning is False:
                     try:
                         QtGui.QGuiApplication.restoreOverrideCursor()
@@ -3600,7 +3621,16 @@ class FlatCAMExcEditor(QtCore.QObject):
         :return: None
         """
 
-        pos = self.canvas.translate_coords(event.pos)
+        if self.app.is_legacy is False:
+            event_pos = event.pos
+            event_is_dragging = event.is_dragging
+            right_button = 2
+        else:
+            event_pos = (event.xdata, event.ydata)
+            event_is_dragging = self.app.plotcanvas.is_dragging
+            right_button = 3
+
+        pos = self.canvas.translate_coords(event_pos)
         event.xdata, event.ydata = pos[0], pos[1]
 
         self.x = event.xdata
@@ -3609,7 +3639,7 @@ class FlatCAMExcEditor(QtCore.QObject):
         self.app.ui.popMenu.mouse_is_panning = False
 
         # if the RMB is clicked and mouse is moving over plot then 'panning_action' is True
-        if event.button == 2 and event.is_dragging == 1:
+        if event.button == right_button and event_is_dragging == 1:
             self.app.ui.popMenu.mouse_is_panning = True
             return
 
@@ -3625,8 +3655,9 @@ class FlatCAMExcEditor(QtCore.QObject):
         # ## Snap coordinates
         if self.app.grid_status() == True:
             x, y = self.app.geo_editor.snap(x, y)
-            # Update cursor
-            self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
+            if self.app.is_legacy is False:
+                # Update cursor
+                self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
 
         self.snap_x = x
         self.snap_y = y
@@ -3653,7 +3684,7 @@ class FlatCAMExcEditor(QtCore.QObject):
             self.draw_utility_geometry(geo=geo)
 
         # ## Selection area on canvas section # ##
-        if event.is_dragging == 1 and event.button == 1:
+        if event_is_dragging == 1 and event.button == 1:
             # I make an exception for FCDrillAdd and FCDrillArray because clicking and dragging while making regions
             # can create strange issues. Also for FCSlot and FCSlotArray
             if isinstance(self.active_tool, FCDrillAdd) or isinstance(self.active_tool, FCDrillArray) or \
@@ -3673,8 +3704,9 @@ class FlatCAMExcEditor(QtCore.QObject):
         else:
             self.app.selection_type = None
 
-        # Update cursor
-        self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
+        if self.app.is_legacy is False:
+            # Update cursor
+            self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
 
     def on_canvas_key_release(self, event):
         self.key = None
@@ -3735,10 +3767,10 @@ class FlatCAMExcEditor(QtCore.QObject):
                     continue
 
                 if shape_plus in self.selected:
-                    self.plot_shape(geometry=shape_plus.geo, color=self.app.defaults['global_sel_draw_color'],
+                    self.plot_shape(geometry=shape_plus.geo, color=self.app.defaults['global_sel_draw_color'] + 'FF',
                                     linewidth=2)
                     continue
-                self.plot_shape(geometry=shape_plus.geo, color=self.app.defaults['global_draw_color'])
+                self.plot_shape(geometry=shape_plus.geo, color=self.app.defaults['global_draw_color'] + 'FF')
 
         # for shape in self.storage.get_objects():
         #     if shape.geo is None:  # TODO: This shouldn't have happened
@@ -3756,7 +3788,7 @@ class FlatCAMExcEditor(QtCore.QObject):
 
         self.shapes.redraw()
 
-    def plot_shape(self, geometry=None, color='black', linewidth=1):
+    def plot_shape(self, geometry=None, color='0x000000FF', linewidth=1):
         """
         Plots a geometric object or list of objects without rendering. Plotted objects
         are returned as a list. This allows for efficient/animated rendering.

+ 11 - 7
flatcamEditors/FlatCAMGeoEditor.py

@@ -3672,8 +3672,9 @@ class FlatCAMGeoEditor(QtCore.QObject):
                     self.app.defaults["global_point_clipboard_format"] % (self.pos[0], self.pos[1]))
                 return
 
+
             # Selection with left mouse button
-            if self.active_tool is not None and event.button is 1:
+            if self.active_tool is not None and event.button == 1:
 
                 # Dispatch event to active_tool
                 self.active_tool.click(self.snap(self.pos[0], self.pos[1]))
@@ -3704,9 +3705,11 @@ class FlatCAMGeoEditor(QtCore.QObject):
         if self.app.is_legacy is False:
             event_pos = event.pos
             event_is_dragging = event.is_dragging
+            right_button = 2
         else:
             event_pos = (event.xdata, event.ydata)
             event_is_dragging = self.app.plotcanvas.is_dragging
+            right_button = 3
 
         pos = self.canvas.translate_coords(event_pos)
         event.xdata, event.ydata = pos[0], pos[1]
@@ -3717,7 +3720,7 @@ class FlatCAMGeoEditor(QtCore.QObject):
         self.app.ui.popMenu.mouse_is_panning = False
 
         # if the RMB is clicked and mouse is moving over plot then 'panning_action' is True
-        if event.button == 2:
+        if event.button == right_button:
             if event_is_dragging:
                 self.app.ui.popMenu.mouse_is_panning = True
                 # return
@@ -3785,9 +3788,11 @@ class FlatCAMGeoEditor(QtCore.QObject):
         if self.app.is_legacy is False:
             event_pos = event.pos
             event_is_dragging = event.is_dragging
+            right_button = 2
         else:
             event_pos = (event.xdata, event.ydata)
             event_is_dragging = self.app.plotcanvas.is_dragging
+            right_button = 3
 
         pos_canvas = self.canvas.translate_coords(event_pos)
 
@@ -3811,7 +3816,7 @@ class FlatCAMGeoEditor(QtCore.QObject):
                     self.active_tool.click_release((self.pos[0], self.pos[1]))
                     # self.app.inform.emit(msg)
                     self.replot()
-            elif event.button == 2:  # right click
+            elif event.button == right_button:  # right click
                 if self.app.ui.popMenu.mouse_is_panning == False:
                     if self.in_action is False:
                         try:
@@ -3978,7 +3983,7 @@ class FlatCAMGeoEditor(QtCore.QObject):
         # return [shape for shape in self.shape_buffer if shape["selected"]]
         return self.selected
 
-    def plot_shape(self, geometry=None, color='black', linewidth=1):
+    def plot_shape(self, geometry=None, color='#000000FF', linewidth=1):
         """
         Plots a geometric object or list of objects without rendering. Plotted objects
         are returned as a list. This allows for efficient/animated rendering.
@@ -3996,7 +4001,6 @@ class FlatCAMGeoEditor(QtCore.QObject):
         try:
             for geo in geometry:
                 plot_elements += self.plot_shape(geometry=geo, color=color, linewidth=linewidth)
-
         # Non-iterable
         except TypeError:
 
@@ -4034,10 +4038,10 @@ class FlatCAMGeoEditor(QtCore.QObject):
                 continue
 
             if shape in self.selected:
-                self.plot_shape(geometry=shape.geo, color=self.app.defaults['global_sel_draw_color'], linewidth=2)
+                self.plot_shape(geometry=shape.geo, color=self.app.defaults['global_sel_draw_color'] + 'FF', linewidth=2)
                 continue
 
-            self.plot_shape(geometry=shape.geo, color=self.app.defaults['global_draw_color'])
+            self.plot_shape(geometry=shape.geo, color=self.app.defaults['global_draw_color'] + "FF")
 
         for shape in self.utility:
             self.plot_shape(geometry=shape.geo, linewidth=1)

+ 15 - 19
flatcamEditors/FlatCAMGrbEditor.py

@@ -3677,6 +3677,12 @@ class FlatCAMGrbEditor(QtCore.QObject):
         self.deactivate_grb_editor()
         self.activate_grb_editor()
 
+        # reset the tool table
+        self.apertures_table.clear()
+
+        self.apertures_table.setHorizontalHeaderLabels(['#', _('Code'), _('Type'), _('Size'), _('Dim')])
+        self.last_aperture_selected = None
+
         # create a reference to the source object
         self.gerber_obj = orig_grb_obj
         self.gerber_obj_options = orig_grb_obj.options
@@ -3869,19 +3875,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
             new_grb_name = self.edited_obj_name + "_edit"
 
         self.app.worker_task.emit({'fcn': self.new_edited_gerber,
-                                   'params': [new_grb_name]})
-
-        # reset the tool table
-        self.apertures_table.clear()
-
-        self.apertures_table.setHorizontalHeaderLabels(['#', _('Code'), _('Type'), _('Size'), _('Dim')])
-        self.last_aperture_selected = None
-
-        # restore GUI to the Selected TAB
-        # Remove anything else in the GUI
-        self.app.ui.selected_scroll_area.takeWidget()
-        # Switch notebook to Selected page
-        self.app.ui.notebook.setCurrentWidget(self.app.ui.selected_tab)
+                                   'params': [new_grb_name, self.storage_dict]})
 
     @staticmethod
     def update_options(obj):
@@ -3899,12 +3893,13 @@ class FlatCAMGrbEditor(QtCore.QObject):
             obj.options = dict()
             return True
 
-    def new_edited_gerber(self, outname):
+    def new_edited_gerber(self, outname, aperture_storage):
         """
         Creates a new Gerber object for the edited Gerber. Thread-safe.
 
         :param outname: Name of the resulting object. None causes the name to be that of the file.
         :type outname: str
+        :param aperture_storage: a dictionary that holds all the objects geometry
         :return: None
         """
 
@@ -3912,13 +3907,14 @@ class FlatCAMGrbEditor(QtCore.QObject):
                            self.gerber_obj.options['name'].upper())
 
         out_name = outname
+        storage_dict = aperture_storage
 
         local_storage_dict = dict()
-        for aperture in self.storage_dict:
-            if 'geometry' in self.storage_dict[aperture]:
+        for aperture in storage_dict:
+            if 'geometry' in storage_dict[aperture]:
                 # add aperture only if it has geometry
-                if len(self.storage_dict[aperture]['geometry']) > 0:
-                    local_storage_dict[aperture] = deepcopy(self.storage_dict[aperture])
+                if len(storage_dict[aperture]['geometry']) > 0:
+                    local_storage_dict[aperture] = deepcopy(storage_dict[aperture])
 
         # How the object should be initialized
         def obj_init(grb_obj, app_obj):
@@ -4007,7 +4003,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
             try:
                 self.app.new_object("gerber", outname, obj_init)
             except Exception as e:
-                log.error("Error on object creation: %s" % str(e))
+                log.error("Error on Edited object creation: %s" % str(e))
                 self.app.progress.emit(100)
                 return
 

+ 2 - 1
flatcamGUI/PlotCanvasLegacy.py

@@ -774,6 +774,7 @@ class ShapeCollectionLegacy():
 
     def redraw(self):
         path_num = 0
+
         try:
             obj_type = self.obj.kind
         except AttributeError:
@@ -782,7 +783,7 @@ class ShapeCollectionLegacy():
             for element in self._shapes:
                 if obj_type == 'excellon':
                     # Plot excellon (All polygons?)
-                    if self.obj.options["solid"]:
+                    if self.obj.options["solid"] and isinstance(self._shapes[element]['shape'], Polygon):
                         patch = PolygonPatch(self._shapes[element]['shape'],
                                              facecolor="#C40000",
                                              edgecolor="#750000",