From 07fb663e7b75748a4fd5a6977553fc8b2f665faa Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 25 Nov 2019 21:03:12 +0200 Subject: [PATCH] - in Gerber isolation added the option to selectively isolate only certain polygons - made it to work for Legacy(2D) graphic mode --- FlatCAMApp.py | 22 +++++++++++----------- FlatCAMObj.py | 20 ++++++++++++-------- README.md | 1 + flatcamGUI/PlotCanvasLegacy.py | 8 ++++++++ flatcamTools/ToolCopperThieving.py | 6 +++--- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 438dd48f..db593ebe 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -1602,6 +1602,13 @@ class App(QtCore.QObject): else: self.is_legacy = True + # Event signals disconnect id holders + self.mp = None + self.mm = None + self.mr = None + self.mdc = None + self.mp_zc = None + # Matplotlib axis self.axes = None @@ -2511,12 +2518,6 @@ class App(QtCore.QObject): self.width = None self.height = None - # Event signals disconnect id holders - self.mp = None - self.mm = None - self.mr = None - self.mp_zc = None - # when True, the app has to return from any thread self.abort_flag = False @@ -8462,11 +8463,10 @@ class App(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 - if event.button == right_button: # right click - if self.ui.popMenu.mouse_is_panning is False: - self.cursor = QtGui.QCursor() - self.populate_cmenu_grids() - self.ui.popMenu.popup(self.cursor.pos()) + if event.button == right_button and self.ui.popMenu.mouse_is_panning is False: # right click + self.cursor = QtGui.QCursor() + self.populate_cmenu_grids() + self.ui.popMenu.popup(self.cursor.pos()) # if the released mouse button was LMB then test if we had a right-to-left selection or a left-to-right # selection and then select a type of selection ("enclosing" or "touching") diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 0847bd8d..fe75d9ce 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -621,11 +621,14 @@ class FlatCAMGerber(FlatCAMObj, Gerber): self.decimals = 4 # Mouse events - self.mr = self.app.mr + self.mr = None # dict to store the polygons selected for isolation; key is the shape added to be ploted and value is the poly self.poly_dict = dict() + # store the status of grid snapping + self.grid_status_memory = None + # Attributes to be included in serialization # Always append to it because it carries contents # from predecessors. @@ -1061,12 +1064,12 @@ class FlatCAMGerber(FlatCAMObj, Gerber): def on_mouse_click_release(self, event): if self.app.is_legacy is False: event_pos = event.pos - event_is_dragging = event.is_dragging right_button = 2 + event_is_dragging = self.app.event_is_dragging else: event_pos = (event.xdata, event.ydata) - event_is_dragging = self.app.plotcanvas.is_dragging right_button = 3 + event_is_dragging = self.app.ui.popMenu.mouse_is_panning try: x = float(event_pos[0]) @@ -1083,9 +1086,9 @@ class FlatCAMGerber(FlatCAMObj, Gerber): if clicked_poly: if clicked_poly not in self.poly_dict.values(): shape_id = self.app.tool_shapes.add(tolerance=self.drawing_tolerance, layer=0, shape=clicked_poly, - color=self.app.defaults['global_sel_draw_color'] + 'AF', - face_color=self.app.defaults['global_sel_draw_color'] + 'AF', - visible=True) + color=self.app.defaults['global_sel_draw_color'] + 'AF', + face_color=self.app.defaults['global_sel_draw_color'] + 'AF', + visible=True) self.poly_dict[shape_id] = clicked_poly self.app.inform.emit( '%s: %d. %s' % (_("Added polygon"), @@ -1110,7 +1113,7 @@ class FlatCAMGerber(FlatCAMObj, Gerber): else: self.app.inform.emit(_("No polygon detected under click position.")) - elif event.button == right_button and self.app.event_is_dragging is False: + elif event.button == right_button and event_is_dragging is False: # restore the Grid snapping if it was active before if self.grid_status_memory is True: self.app.ui.grid_snap_btn.trigger() @@ -1126,8 +1129,9 @@ class FlatCAMGerber(FlatCAMObj, Gerber): self.app.tool_shapes.clear(update=True) if self.poly_dict: - poly_list = self.poly_dict.values() + poly_list = deepcopy(list(self.poly_dict.values())) self.isolate(iso_type=self.iso_type, geometry=poly_list) + self.poly_dict.clear() else: self.app.inform.emit('[ERROR_NOTCL] %s' % _("List of single polygons is empty. Aborting.")) diff --git a/README.md b/README.md index 3734e6fc..f6658b54 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ CAD program, and create G-Code for Isolation routing. - updated the 'single' isolation of Gerber polygons to remove the polygon if clicked on it and it is already in the list of single polygons to be isolated - clicking to add a polygon when doing Single type isolation will add a blue shape marking the selected polygon, second click will remove that shape - fixed bugs in Paint Tool when painting single polygon +- in Gerber isolation added the option to selectively isolate only certain polygons - made it to work for Legacy(2D) graphic mode 23.11.2019 diff --git a/flatcamGUI/PlotCanvasLegacy.py b/flatcamGUI/PlotCanvasLegacy.py index 96ec5f89..609e2f02 100644 --- a/flatcamGUI/PlotCanvasLegacy.py +++ b/flatcamGUI/PlotCanvasLegacy.py @@ -909,6 +909,14 @@ class ShapeCollectionLegacy: return self.shape_id + def remove(self, shape_id, update=None): + for k in list(self._shapes.keys()): + if shape_id == k: + self._shapes.pop(k, None) + + if update is True: + self.redraw() + def clear(self, update=None): """ Clear the canvas of the shapes. diff --git a/flatcamTools/ToolCopperThieving.py b/flatcamTools/ToolCopperThieving.py index 62276f42..87d0b9fb 100644 --- a/flatcamTools/ToolCopperThieving.py +++ b/flatcamTools/ToolCopperThieving.py @@ -1,7 +1,7 @@ # ########################################################## # FlatCAM: 2D Post-processing for Manufacturing # # File Author: Marius Adrian Stanciu (c) # -# Date: 10/25/2019 # +# Date: 10/25/2019 # # MIT Licence # # ########################################################## @@ -876,7 +876,7 @@ class ToolCopperThieving(FlatCAMTool): if old_disp_number < disp_number <= 100: app_obj.app.proc_container.update_view_text(' %s ... %d%%' % - (_("Thieving"), int(disp_number))) + (_("Thieving"), int(disp_number))) old_disp_number = disp_number except TypeError: # taking care of the case when the self.solid_geometry is just a single Polygon, not a list or a @@ -1074,7 +1074,7 @@ class ToolCopperThieving(FlatCAMTool): if old_disp_number < disp_number <= 100: app_obj.app.proc_container.update_view_text(' %s ... %d%%' % - (_("Buffering"), int(disp_number))) + (_("Buffering"), int(disp_number))) old_disp_number = disp_number except TypeError: # taking care of the case when the self.solid_geometry is just a single Polygon, not a list or a