From b994ee9639fa24c458a697d89e9a6c9092021378 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 28 Oct 2019 15:03:21 +0200 Subject: [PATCH] - in Tools: Paint, NCC and Copper Fill, when using the Area Selection, now the selected aras will stay drawn as markers until the user click RMB - in legacy2D graphic engine, adding an utility geometry no longer draw the older ones, overwriting them --- FlatCAMApp.py | 8 +++++ FlatCAMTool.py | 48 ++++++++++++++++++++++++++++++ README.md | 7 ++++- flatcamGUI/PlotCanvasLegacy.py | 8 +++-- flatcamTools/ToolCopperFill.py | 10 +++++-- flatcamTools/ToolNonCopperClear.py | 12 ++++++-- flatcamTools/ToolPaint.py | 13 ++++++-- 7 files changed, 95 insertions(+), 11 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 5dd8e2a0..22428809 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -2748,6 +2748,14 @@ class App(QtCore.QObject): # this holds a widget that is installed in the Plot Area when View Source option is used self.source_editor_tab = None + # Storage for shapes, storage that can be used by FlatCAm tools for utility geometry + # VisPy visuals + if self.is_legacy is False: + self.tool_shapes = ShapeCollection(parent=self.plotcanvas.view.scene, layers=1) + else: + from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy + self.tool_shapes = ShapeCollectionLegacy(obj=self, app=self, name="tool") + # ############################################################################### # ############# Save defaults to factory_defaults.FlatConfig file ############### # ############# It's done only once after install ############### diff --git a/FlatCAMTool.py b/FlatCAMTool.py index 80795a35..56e17a70 100644 --- a/FlatCAMTool.py +++ b/FlatCAMTool.py @@ -9,6 +9,8 @@ from PyQt5 import QtGui, QtCore, QtWidgets, QtWidgets from PyQt5.QtCore import Qt +from shapely.geometry import Polygon + class FlatCAMTool(QtWidgets.QWidget): @@ -90,3 +92,49 @@ class FlatCAMTool(QtWidgets.QWidget): self.app.ui.tool_scroll_area.widget().setObjectName(self.toolName) self.show() + + def draw_tool_selection_shape(self, old_coords, coords, **kwargs): + """ + + :param old_coords: old coordinates + :param coords: new coordinates + :return: + """ + + if 'color' in kwargs: + color = kwargs['color'] + else: + color = self.app.defaults['global_sel_line'] + + if 'face_color' in kwargs: + face_color = kwargs['face_color'] + else: + face_color = self.app.defaults['global_sel_fill'] + + if 'face_alpha' in kwargs: + face_alpha = kwargs['face_alpha'] + else: + face_alpha = 0.3 + + x0, y0 = old_coords + x1, y1 = coords + + pt1 = (x0, y0) + pt2 = (x1, y0) + pt3 = (x1, y1) + pt4 = (x0, y1) + sel_rect = Polygon([pt1, pt2, pt3, pt4]) + + # color_t = Color(face_color) + # color_t.alpha = face_alpha + + color_t = face_color[:-2] + str(hex(int(face_alpha * 255)))[2:] + + self.app.tool_shapes.add(sel_rect, color=color, face_color=color_t, update=True, + layer=0, tolerance=None) + if self.app.is_legacy is True: + self.app.tool_shapes.redraw() + + def delete_tool_selection_shape(self): + self.app.tool_shapes.clear() + self.app.tool_shapes.redraw() diff --git a/README.md b/README.md index ae043de2..e473dd95 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,11 @@ CAD program, and create G-Code for Isolation routing. ================================================= +28.10.2019 + +- in Tools: Paint, NCC and Copper Fill, when using the Area Selection, now the selected aras will stay drawn as markers until the user click RMB +- in legacy2D graphic engine, adding an utility geometry no longer draw the older ones, overwriting them + 27.10.2019 - Copper Fill Tool: some PEP8 corrections @@ -53,7 +58,7 @@ CAD program, and create G-Code for Isolation routing. - working on the Calibrate Excellon Tool - finished the GUI layout for the Calibrate Excellon Tool - start working on QRCode Tool - not working yet -- start working on QRCode Tool - searching for alternatives +- start working on QRCode Tool - searching for alternativess 21.10.2019 diff --git a/flatcamGUI/PlotCanvasLegacy.py b/flatcamGUI/PlotCanvasLegacy.py index 01780ae6..96ec5f89 100644 --- a/flatcamGUI/PlotCanvasLegacy.py +++ b/flatcamGUI/PlotCanvasLegacy.py @@ -272,8 +272,6 @@ class PlotCanvasLegacy(QtCore.QObject): :return: None """ - # self.double_click.disconnect(cid) - self.canvas.mpl_disconnect(cid) def on_new_screen(self): @@ -936,6 +934,7 @@ class ShapeCollectionLegacy: :return: None """ + path_num = 0 local_shapes = deepcopy(self._shapes) @@ -945,6 +944,10 @@ class ShapeCollectionLegacy: obj_type = 'utility' if self._visible: + # if we don't use this then when adding each new shape, the old ones will be added again, too + if obj_type == 'utility': + self.axes.patches.clear() + for element in local_shapes: if obj_type == 'excellon': # Plot excellon (All polygons?) @@ -1040,6 +1043,7 @@ class ShapeCollectionLegacy: edgecolor=local_shapes[element]['color'], alpha=local_shapes[element]['alpha'], zorder=2) + self.axes.add_patch(patch) except Exception as e: log.debug("ShapeCollectionLegacy.redraw() --> %s" % str(e)) diff --git a/flatcamTools/ToolCopperFill.py b/flatcamTools/ToolCopperFill.py index 327db040..64844875 100644 --- a/flatcamTools/ToolCopperFill.py +++ b/flatcamTools/ToolCopperFill.py @@ -373,6 +373,7 @@ class ToolCopperFill(FlatCAMTool): self.cursor_pos = self.app.geo_editor.snap(event_pos[0], event_pos[1]) else: self.app.inform.emit(_("Zone added. Click to start adding next zone or right click to finish.")) + self.app.delete_selection_shape() if self.app.grid_status() is True: curr_pos = self.app.geo_editor.snap(event_pos[0], event_pos[1]) @@ -386,15 +387,20 @@ class ToolCopperFill(FlatCAMTool): pt3 = (x1, y1) pt4 = (x0, y1) - self.sel_rect.append(Polygon([pt1, pt2, pt3, pt4])) + new_rectangle = Polygon([pt1, pt2, pt3, pt4]) + self.sel_rect.append(new_rectangle) + + # add a temporary shape on canvas + self.draw_tool_selection_shape(old_coords=(x0, y0), coords=(x1, y1)) self.first_click = False return elif event.button == right_button and self.mouse_is_dragging is False: - self.app.delete_selection_shape() self.area_method = False self.first_click = False + self.delete_tool_selection_shape() + if self.app.is_legacy is False: self.app.plotcanvas.graph_event_disconnect('mouse_release', self.on_mouse_release) self.app.plotcanvas.graph_event_disconnect('mouse_move', self.on_mouse_move) diff --git a/flatcamTools/ToolNonCopperClear.py b/flatcamTools/ToolNonCopperClear.py index 6d471875..b29203e3 100644 --- a/flatcamTools/ToolNonCopperClear.py +++ b/flatcamTools/ToolNonCopperClear.py @@ -1241,6 +1241,7 @@ class NonCopperClear(FlatCAMTool, Gerber): self.cursor_pos = self.app.geo_editor.snap(event_pos[0], event_pos[1]) else: self.app.inform.emit(_("Zone added. Click to start adding next zone or right click to finish.")) + self.app.delete_selection_shape() if self.app.grid_status() == True: curr_pos = self.app.geo_editor.snap(event_pos[0], event_pos[1]) @@ -1254,15 +1255,20 @@ class NonCopperClear(FlatCAMTool, Gerber): pt3 = (x1, y1) pt4 = (x0, y1) - self.sel_rect.append(Polygon([pt1, pt2, pt3, pt4])) + new_rectangle = Polygon([pt1, pt2, pt3, pt4]) + self.sel_rect.append(new_rectangle) + + # add a temporary shape on canvas + self.draw_tool_selection_shape(old_coords=(x0, y0), coords=(x1, y1)) + self.first_click = False return elif event.button == right_button and self.mouse_is_dragging == False: - self.app.delete_selection_shape() - self.first_click = False + self.delete_tool_selection_shape() + if self.app.is_legacy is False: self.app.plotcanvas.graph_event_disconnect('mouse_release', self.on_mouse_release) self.app.plotcanvas.graph_event_disconnect('mouse_move', self.on_mouse_move) diff --git a/flatcamTools/ToolPaint.py b/flatcamTools/ToolPaint.py index 46ea4d4e..a1781966 100644 --- a/flatcamTools/ToolPaint.py +++ b/flatcamTools/ToolPaint.py @@ -1122,6 +1122,7 @@ class ToolPaint(FlatCAMTool, Gerber): self.cursor_pos = self.app.geo_editor.snap(self.cursor_pos[0], self.cursor_pos[1]) else: self.app.inform.emit(_("Zone added. Click to start adding next zone or right click to finish.")) + self.app.delete_selection_shape() curr_pos = self.app.plotcanvas.translate_coords(event_pos) if self.app.grid_status() == True: @@ -1133,15 +1134,21 @@ class ToolPaint(FlatCAMTool, Gerber): pt2 = (x1, y0) pt3 = (x1, y1) pt4 = (x0, y1) - self.sel_rect.append(Polygon([pt1, pt2, pt3, pt4])) + + new_rectangle = Polygon([pt1, pt2, pt3, pt4]) + self.sel_rect.append(new_rectangle) + + # add a temporary shape on canvas + self.draw_tool_selection_shape(old_coords=(x0, y0), coords=(x1, y1)) + self.first_click = False return elif event.button == right_button and self.mouse_is_dragging is False: - self.app.delete_selection_shape() - self.first_click = False + self.delete_tool_selection_shape() + if self.app.is_legacy is False: self.app.plotcanvas.graph_event_disconnect('mouse_release', self.on_mouse_release) self.app.plotcanvas.graph_event_disconnect('mouse_move', self.on_mouse_move)