From 3fe31dec59a843b0f8ef049034dc268acd88da90 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sat, 24 Aug 2019 04:30:27 +0300 Subject: [PATCH] - modified CutOut Tool so now the manual gaps adding will continue until the user is clicking the RMB - added ability to turn on/of the grid snapping and to jump to a location while in CutOut Tool manual gap adding action --- FlatCAMApp.py | 5 +- README.md | 5 ++ flatcamTools/ToolCutOut.py | 111 ++++++++++++++++++++++--------------- 3 files changed, 74 insertions(+), 47 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 04fd7913..79428366 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -98,8 +98,8 @@ class App(QtCore.QObject): # #################################### # Version and VERSION DATE ########### # #################################### - version = 8.96 - version_date = "2019/08/23" + version = 8.97 + version_date = "2019/08/31" beta = True # current date now @@ -5261,6 +5261,7 @@ class App(QtCore.QObject): cursor.setPos(canvas_origin.x() + jump_loc[0], (canvas_origin.y() + jump_loc[1])) self.inform.emit(_("[success] Done.")) + return location def on_copy_object(self): self.report_usage("on_copy_object()") diff --git a/README.md b/README.md index 70c87779..85d9a712 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,11 @@ CAD program, and create G-Code for Isolation routing. ================================================= +24.08.2019 + +- modified CutOut Tool so now the manual gaps adding will continue until the user is clicking the RMB +- added ability to turn on/of the grid snapping and to jump to a location while in CutOut Tool manual gap adding action + 23.08.2019 - in Tool Cutout for the manual gaps, right mouse button click will exit from the action of adding gaps diff --git a/flatcamTools/ToolCutOut.py b/flatcamTools/ToolCutOut.py index 29aab7fd..c2955949 100644 --- a/flatcamTools/ToolCutOut.py +++ b/flatcamTools/ToolCutOut.py @@ -16,7 +16,6 @@ if '_' not in builtins.__dict__: class CutOut(FlatCAMTool): toolName = _("Cutout PCB") - gapFinished = pyqtSignal() def __init__(self, app): FlatCAMTool.__init__(self, app) @@ -296,6 +295,13 @@ class CutOut(FlatCAMTool): # this is the Geometry object generated in this class to be used for adding manual gaps self.man_cutout_obj = None + # if mouse is dragging set the object True + self.mouse_is_dragging = False + + # hold the mouse position here + self.x_pos = None + self.y_pos = None + # Signals self.ff_cutout_object_btn.clicked.connect(self.on_freeform_cutout) self.rect_cutout_object_btn.clicked.connect(self.on_rectangular_cutout) @@ -349,8 +355,6 @@ class CutOut(FlatCAMTool): self.gaps.set_value(self.app.defaults["tools_gaps_ff"]) self.convex_box.set_value(self.app.defaults['tools_cutout_convexshape']) - self.gapFinished.connect(self.on_gap_finished) - def on_freeform_cutout(self): # def subtract_rectangle(obj_, x0, y0, x1, y1): @@ -774,40 +778,7 @@ class CutOut(FlatCAMTool): self.app.plotcanvas.vis_disconnect('mouse_move', self.app.on_mouse_move_over_plot) self.app.plotcanvas.vis_connect('key_press', self.on_key_press) self.app.plotcanvas.vis_connect('mouse_move', self.on_mouse_move) - self.app.plotcanvas.vis_connect('mouse_release', self.doit) - - # To be called after clicking on the plot. - def doit(self, event): - # do paint single only for left mouse clicks - if event.button == 1: - self.app.inform.emit(_("Making manual bridge gap...")) - pos = self.app.plotcanvas.vispy_canvas.translate_coords(event.pos) - self.on_manual_cutout(click_pos=pos) - - self.app.plotcanvas.vis_disconnect('key_press', self.on_key_press) - self.app.plotcanvas.vis_disconnect('mouse_move', self.on_mouse_move) - self.app.plotcanvas.vis_disconnect('mouse_release', self.doit) - self.app.plotcanvas.vis_connect('key_press', self.app.ui.keyPressEvent) - self.app.plotcanvas.vis_connect('mouse_press', self.app.on_mouse_click_over_plot) - self.app.plotcanvas.vis_connect('mouse_release', self.app.on_mouse_click_release_over_plot) - self.app.plotcanvas.vis_connect('mouse_move', self.app.on_mouse_move_over_plot) - - self.app.geo_editor.tool_shape.clear(update=True) - self.app.geo_editor.tool_shape.enabled = False - self.gapFinished.emit() - # if RMB then we exit - elif event.button == 2: - self.app.plotcanvas.vis_disconnect('key_press', self.on_key_press) - self.app.plotcanvas.vis_disconnect('mouse_move', self.on_mouse_move) - self.app.plotcanvas.vis_disconnect('mouse_release', self.doit) - self.app.plotcanvas.vis_connect('key_press', self.app.ui.keyPressEvent) - self.app.plotcanvas.vis_connect('mouse_press', self.app.on_mouse_click_over_plot) - self.app.plotcanvas.vis_connect('mouse_release', self.app.on_mouse_click_release_over_plot) - self.app.plotcanvas.vis_connect('mouse_move', self.app.on_mouse_move_over_plot) - - # Remove any previous utility shape - self.app.geo_editor.tool_shape.clear(update=True) - self.app.geo_editor.tool_shape.enabled = False + self.app.plotcanvas.vis_connect('mouse_release', self.on_mouse_click_release) def on_manual_cutout(self, click_pos): name = self.man_object_combo.currentText() @@ -836,12 +807,6 @@ class CutOut(FlatCAMTool): self.app.should_we_save = True - def on_gap_finished(self): - # if CTRL key modifier is pressed then repeat the bridge gap cut - key_modifier = QtWidgets.QApplication.keyboardModifiers() - if key_modifier == Qt.ControlModifier: - self.on_manual_gap_click() - def on_manual_geo(self): name = self.obj_combo.currentText() @@ -943,6 +908,41 @@ class CutOut(FlatCAMTool): cut_poly = box(xmin, ymin, xmax, ymax) return cut_poly + # To be called after clicking on the plot. + def on_mouse_click_release(self, event): + + # do paint single only for left mouse clicks + if event.button == 1: + self.app.inform.emit(_("Making manual bridge gap...")) + pos = self.app.plotcanvas.vispy_canvas.translate_coords(event.pos) + self.on_manual_cutout(click_pos=pos) + + # self.app.plotcanvas.vis_disconnect('key_press', self.on_key_press) + # self.app.plotcanvas.vis_disconnect('mouse_move', self.on_mouse_move) + # self.app.plotcanvas.vis_disconnect('mouse_release', self.on_mouse_click_release) + # self.app.plotcanvas.vis_connect('key_press', self.app.ui.keyPressEvent) + # self.app.plotcanvas.vis_connect('mouse_press', self.app.on_mouse_click_over_plot) + # self.app.plotcanvas.vis_connect('mouse_release', self.app.on_mouse_click_release_over_plot) + # self.app.plotcanvas.vis_connect('mouse_move', self.app.on_mouse_move_over_plot) + + # self.app.geo_editor.tool_shape.clear(update=True) + # self.app.geo_editor.tool_shape.enabled = False + # self.gapFinished.emit() + + # if RMB then we exit + elif event.button == 2 and self.mouse_is_dragging is False: + self.app.plotcanvas.vis_disconnect('key_press', self.on_key_press) + self.app.plotcanvas.vis_disconnect('mouse_move', self.on_mouse_move) + self.app.plotcanvas.vis_disconnect('mouse_release', self.on_mouse_click_release) + self.app.plotcanvas.vis_connect('key_press', self.app.ui.keyPressEvent) + self.app.plotcanvas.vis_connect('mouse_press', self.app.on_mouse_click_over_plot) + self.app.plotcanvas.vis_connect('mouse_release', self.app.on_mouse_click_release_over_plot) + self.app.plotcanvas.vis_connect('mouse_move', self.app.on_mouse_move_over_plot) + + # Remove any previous utility shape + self.app.geo_editor.tool_shape.clear(update=True) + self.app.geo_editor.tool_shape.enabled = False + def on_mouse_move(self, event): self.app.on_mouse_move_over_plot(event=event) @@ -950,13 +950,23 @@ class CutOut(FlatCAMTool): pos = self.canvas.vispy_canvas.translate_coords(event.pos) event.xdata, event.ydata = pos[0], pos[1] + if event.is_dragging is True: + self.mouse_is_dragging = True + else: + self.mouse_is_dragging = False + try: x = float(event.xdata) y = float(event.ydata) except TypeError: return - snap_x, snap_y = self.app.geo_editor.snap(x, y) + if self.app.grid_status() == True: + snap_x, snap_y = self.app.geo_editor.snap(x, y) + else: + snap_x, snap_y = x, y + + self.x_pos, self.y_pos = snap_x, snap_y # ################################################# # ### This section makes the cutting geo to ####### @@ -1044,7 +1054,7 @@ class CutOut(FlatCAMTool): if key == QtCore.Qt.Key_Escape or key == 'Escape': self.app.plotcanvas.vis_disconnect('key_press', self.on_key_press) self.app.plotcanvas.vis_disconnect('mouse_move', self.on_mouse_move) - self.app.plotcanvas.vis_disconnect('mouse_release', self.doit) + self.app.plotcanvas.vis_disconnect('mouse_release', self.on_mouse_click_release) self.app.plotcanvas.vis_connect('key_press', self.app.ui.keyPressEvent) self.app.plotcanvas.vis_connect('mouse_press', self.app.on_mouse_click_over_plot) self.app.plotcanvas.vis_connect('mouse_release', self.app.on_mouse_click_release_over_plot) @@ -1054,6 +1064,17 @@ class CutOut(FlatCAMTool): self.app.geo_editor.tool_shape.clear(update=True) self.app.geo_editor.tool_shape.enabled = False + # Grid toggle + if key == QtCore.Qt.Key_G or key == 'G': + self.app.ui.grid_snap_btn.trigger() + + # Jump to coords + if key == QtCore.Qt.Key_J or key == 'J': + l_x, l_y = self.app.on_jump_to() + self.app.geo_editor.tool_shape.clear(update=True) + geo = self.cutting_geo(pos=(l_x, l_y)) + self.draw_utility_geometry(geo=geo) + def subtract_poly_from_geo(self, solid_geo, x0, y0, x1, y1): """ Subtract polygon made from points from the given object.