diff --git a/CHANGELOG.md b/CHANGELOG.md index feacf0d9..9e0a5679 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG for FlatCAM Evo beta 14.04.2022 - in Geometry Editor added a new feature. While drawing a 'Path' now the user can project a direction by moving the mouse cursor in a certain direction and after that by typing a number or an arithmetic simple expression, a line segment will be drawn in that direction with the specified length from the last point +- in Geometry Editor for the Path tool but only when using the 3D engine graphic mode, the mouse cursor is followed by position data 13.04.2022 diff --git a/appEditors/AppGeoEditor.py b/appEditors/AppGeoEditor.py index 4d3205ed..90ef6949 100644 --- a/appEditors/AppGeoEditor.py +++ b/appEditors/AppGeoEditor.py @@ -949,6 +949,7 @@ class FCPath(FCPolygon): self.cursor = QtGui.QCursor(QtGui.QPixmap(self.draw_app.app.resource_location + '/aero_path5.png')) QtGui.QGuiApplication.setOverrideCursor(self.cursor) + self.draw_app.app.plotcanvas.view.camera.zoom_callback = self.draw_cursor_data self.draw_app.app.jump_signal.connect(lambda x: self.draw_app.update_utility_geometry(data=x)) def make(self): @@ -966,6 +967,7 @@ class FCPath(FCPolygon): self.draw_app.app.jump_signal.disconnect() self.geometry.data['type'] = _('Path') + self.draw_cursor_data(delete=True) self.draw_app.app.inform.emit('[success] %s' % _("Done.")) def utility_geometry(self, data=None): @@ -976,6 +978,53 @@ class FCPath(FCPolygon): return None + def draw_cursor_data(self, pos=None, delete=False): + if pos is None: + pos = self.draw_app.snap_x, self.draw_app.snap_y + + if delete: + if self.draw_app.app.use_3d_engine: + self.draw_app.app.plotcanvas.text_cursor.parent = None + self.draw_app.app.plotcanvas.view.camera.zoom_callback = lambda *args: None + return + + # font size + qsettings = QtCore.QSettings("Open Source", "FlatCAM") + if qsettings.contains("hud_font_size"): + fsize = qsettings.value('hud_font_size', type=int) + else: + fsize = 8 + + x = pos[0] + y = pos[1] + try: + length = abs(np.sqrt((pos[0] - self.points[-1][0]) ** 2 + (pos[1] - self.points[-1][1]) ** 2)) + except IndexError: + length = self.draw_app.app.dec_format(0.0, self.draw_app.app.decimals) + units = self.draw_app.app.app_units.lower() + + x_dec = str(self.draw_app.app.dec_format(x, self.draw_app.app.decimals)) if x else '0.0' + y_dec = str(self.draw_app.app.dec_format(y, self.draw_app.app.decimals)) if y else '0.0' + length_dec = str(self.draw_app.app.dec_format(length, self.draw_app.app.decimals)) if length else '0.0' + + l1_txt = 'X: %s [%s]' % (x_dec, units) + l2_txt = 'Y: %s [%s]' % (y_dec, units) + l3_txt = 'L: %s [%s]' % (length_dec, units) + cursor_text = '%s\n%s\n\n%s' % (l1_txt, l2_txt, l3_txt) + + if self.draw_app.app.use_3d_engine: + new_pos = self.draw_app.app.plotcanvas.translate_coords_2((x, y)) + x, y, __, ___ = self.draw_app.app.plotcanvas.translate_coords((new_pos[0]+30, new_pos[1])) + + # text + self.draw_app.app.plotcanvas.text_cursor.font_size = fsize + self.draw_app.app.plotcanvas.text_cursor.text = cursor_text + self.draw_app.app.plotcanvas.text_cursor.pos = x, y + self.draw_app.app.plotcanvas.text_cursor.anchors = 'left', 'top' + + if self.draw_app.app.plotcanvas.text_cursor.parent is None: + self.draw_app.app.plotcanvas.text_cursor.parent = self.draw_app.app.plotcanvas.view.scene + def on_key(self, key): # Jump to coords if key == QtCore.Qt.Key.Key_J or key == 'J': @@ -1024,7 +1073,7 @@ class FCPath(FCPolygon): return '%s %s' % (_("Failed."), str(err)) self.points.append((new_x, new_y)) - self.draw_app.app.on_jump_to(custom_location=(new_x, new_y), fit_center=True) + self.draw_app.app.on_jump_to(custom_location=(new_x, new_y), fit_center=False) if len(self.points) > 0: msg = '%s: %s. %s' % ( _("Projected"), str(self.interpolate_length), @@ -1038,6 +1087,10 @@ class FCPath(FCPolygon): self.interpolate_length = '' self.draw_app.plot_all() + if self.draw_app.app.use_3d_engine: + self.draw_app.app.plotcanvas.text_cursor.parent = None + self.draw_app.app.plotcanvas.view.camera.zoom_callback = lambda *args: None + try: self.draw_app.app.jump_signal.disconnect() except (TypeError, AttributeError): @@ -1059,6 +1112,10 @@ class FCSelect(DrawTool): # self.shape_buffer = self.draw_app.shape_buffer # self.selected = self.draw_app.selected + # make sure that the cursor text from the FCPath is deleted + if self.draw_app.app.plotcanvas.text_cursor.parent: + self.draw_app.app.plotcanvas.text_cursor.parent = None + def click_release(self, point): """ @@ -1633,22 +1690,22 @@ class FCBuffer(FCShapeTool): self.draw_app.app.inform.emit('[success] %s' % _("Done.")) def activate(self): - self.buff_tool.buffer_button.clicked.disconnect() - self.buff_tool.buffer_int_button.clicked.disconnect() - self.buff_tool.buffer_ext_button.clicked.disconnect() + self.buff_tool.ui.buffer_button.clicked.disconnect() + self.buff_tool.ui.buffer_int_button.clicked.disconnect() + self.buff_tool.ui.buffer_ext_button.clicked.disconnect() - self.buff_tool.buffer_button.clicked.connect(self.on_buffer) - self.buff_tool.buffer_int_button.clicked.connect(self.on_buffer_int) - self.buff_tool.buffer_ext_button.clicked.connect(self.on_buffer_ext) + self.buff_tool.ui.buffer_button.clicked.connect(self.on_buffer) + self.buff_tool.ui.buffer_int_button.clicked.connect(self.on_buffer_int) + self.buff_tool.ui.buffer_ext_button.clicked.connect(self.on_buffer_ext) def deactivate(self): - self.buff_tool.buffer_button.clicked.disconnect() - self.buff_tool.buffer_int_button.clicked.disconnect() - self.buff_tool.buffer_ext_button.clicked.disconnect() + self.buff_tool.ui.buffer_button.clicked.disconnect() + self.buff_tool.ui.buffer_int_button.clicked.disconnect() + self.buff_tool.ui.buffer_ext_button.clicked.disconnect() - self.buff_tool.buffer_button.clicked.connect(self.buff_tool.on_buffer) - self.buff_tool.buffer_int_button.clicked.connect(self.buff_tool.on_buffer_int) - self.buff_tool.buffer_ext_button.clicked.connect(self.buff_tool.on_buffer_ext) + self.buff_tool.ui.buffer_button.clicked.connect(self.buff_tool.on_buffer) + self.buff_tool.ui.buffer_int_button.clicked.connect(self.buff_tool.on_buffer_int) + self.buff_tool.ui.buffer_ext_button.clicked.connect(self.buff_tool.on_buffer_ext) self.complete = True self.draw_app.select_tool("select") # self.buff_tool.hide_tool() @@ -2735,6 +2792,11 @@ class AppGeoEditor(QtCore.QObject): self.shapes.enabled = False self.tool_shape.enabled = False + # disable text cursor (for FCPath) + if self.app.use_3d_engine: + self.app.plotcanvas.text_cursor.parent = None + self.app.plotcanvas.view.camera.zoom_callback = lambda *args: None + self.app.ui.geo_editor_menu.setDisabled(True) self.app.ui.geo_editor_menu.menuAction().setVisible(False) @@ -3214,6 +3276,7 @@ class AppGeoEditor(QtCore.QObject): self.active_tool.complete = True self.in_action = False self.delete_utility_geometry() + self.active_tool.clean_up() self.app.inform.emit('[success] %s' % _("Done.")) self.select_tool('select') else: @@ -3313,6 +3376,8 @@ class AppGeoEditor(QtCore.QObject): pass else: self.update_utility_geometry(data=(x, y)) + if self.active_tool.name == 'path': + self.active_tool.draw_cursor_data(pos=(x, y)) # ### Selection area on canvas section ### dx = pos[0] - self.pos[0] diff --git a/appGUI/PlotCanvas.py b/appGUI/PlotCanvas.py index 68bf01eb..2253ce71 100644 --- a/appGUI/PlotCanvas.py +++ b/appGUI/PlotCanvas.py @@ -166,6 +166,9 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): self.on_update_text_hud() + # cursor text t obe attached to mouse cursor in Editors + self.text_cursor = Text('', color=self.text_hud_color, method='gpu', anchor_x='left', parent=None) + # draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area # all CNC have a limited workspace if self.fcapp.options['global_workspace'] is True: diff --git a/appGUI/VisPyCanvas.py b/appGUI/VisPyCanvas.py index 9800c65e..597980d3 100644 --- a/appGUI/VisPyCanvas.py +++ b/appGUI/VisPyCanvas.py @@ -141,6 +141,8 @@ class Camera(scene.PanZoomCamera): # Default mouse button for panning is RMB self.pan_button_setting = "2" + self.zoom_callback = lambda *args: None + def zoom(self, factor, center=None): center = center if (center is not None) else self.center super(Camera, self).zoom(factor, center) @@ -183,6 +185,9 @@ class Camera(scene.PanZoomCamera): center = self._scene_transform.imap(event.pos) scale = (1 + self.zoom_factor) ** (-event.delta[1] * 30) self.limited_zoom(scale, center) + + if self.zoom_callback: + self.zoom_callback() event.handled = True elif event.type == 'mouse_move':