- in Geometry Editor for the Path tool but only when using the 3D engine graphic mode, the mouse cursor is followed by position data

This commit is contained in:
Marius Stanciu
2022-04-14 02:42:07 +03:00
committed by Marius
parent b049a64684
commit dd4a0dac99
4 changed files with 87 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ CHANGELOG for FlatCAM Evo beta
14.04.2022 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 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 13.04.2022

View File

@@ -949,6 +949,7 @@ class FCPath(FCPolygon):
self.cursor = QtGui.QCursor(QtGui.QPixmap(self.draw_app.app.resource_location + '/aero_path5.png')) self.cursor = QtGui.QCursor(QtGui.QPixmap(self.draw_app.app.resource_location + '/aero_path5.png'))
QtGui.QGuiApplication.setOverrideCursor(self.cursor) 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)) self.draw_app.app.jump_signal.connect(lambda x: self.draw_app.update_utility_geometry(data=x))
def make(self): def make(self):
@@ -966,6 +967,7 @@ class FCPath(FCPolygon):
self.draw_app.app.jump_signal.disconnect() self.draw_app.app.jump_signal.disconnect()
self.geometry.data['type'] = _('Path') self.geometry.data['type'] = _('Path')
self.draw_cursor_data(delete=True)
self.draw_app.app.inform.emit('[success] %s' % _("Done.")) self.draw_app.app.inform.emit('[success] %s' % _("Done."))
def utility_geometry(self, data=None): def utility_geometry(self, data=None):
@@ -976,6 +978,53 @@ class FCPath(FCPolygon):
return None 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): def on_key(self, key):
# Jump to coords # Jump to coords
if key == QtCore.Qt.Key.Key_J or key == 'J': if key == QtCore.Qt.Key.Key_J or key == 'J':
@@ -1024,7 +1073,7 @@ class FCPath(FCPolygon):
return '%s %s' % (_("Failed."), str(err)) return '%s %s' % (_("Failed."), str(err))
self.points.append((new_x, new_y)) 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: if len(self.points) > 0:
msg = '%s: %s. %s' % ( msg = '%s: %s. %s' % (
_("Projected"), str(self.interpolate_length), _("Projected"), str(self.interpolate_length),
@@ -1038,6 +1087,10 @@ class FCPath(FCPolygon):
self.interpolate_length = '' self.interpolate_length = ''
self.draw_app.plot_all() 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: try:
self.draw_app.app.jump_signal.disconnect() self.draw_app.app.jump_signal.disconnect()
except (TypeError, AttributeError): except (TypeError, AttributeError):
@@ -1059,6 +1112,10 @@ class FCSelect(DrawTool):
# self.shape_buffer = self.draw_app.shape_buffer # self.shape_buffer = self.draw_app.shape_buffer
# self.selected = self.draw_app.selected # 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): def click_release(self, point):
""" """
@@ -1633,22 +1690,22 @@ class FCBuffer(FCShapeTool):
self.draw_app.app.inform.emit('[success] %s' % _("Done.")) self.draw_app.app.inform.emit('[success] %s' % _("Done."))
def activate(self): def activate(self):
self.buff_tool.buffer_button.clicked.disconnect() self.buff_tool.ui.buffer_button.clicked.disconnect()
self.buff_tool.buffer_int_button.clicked.disconnect() self.buff_tool.ui.buffer_int_button.clicked.disconnect()
self.buff_tool.buffer_ext_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.ui.buffer_button.clicked.connect(self.on_buffer)
self.buff_tool.buffer_int_button.clicked.connect(self.on_buffer_int) self.buff_tool.ui.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_ext_button.clicked.connect(self.on_buffer_ext)
def deactivate(self): def deactivate(self):
self.buff_tool.buffer_button.clicked.disconnect() self.buff_tool.ui.buffer_button.clicked.disconnect()
self.buff_tool.buffer_int_button.clicked.disconnect() self.buff_tool.ui.buffer_int_button.clicked.disconnect()
self.buff_tool.buffer_ext_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.ui.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.ui.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_ext_button.clicked.connect(self.buff_tool.on_buffer_ext)
self.complete = True self.complete = True
self.draw_app.select_tool("select") self.draw_app.select_tool("select")
# self.buff_tool.hide_tool() # self.buff_tool.hide_tool()
@@ -2735,6 +2792,11 @@ class AppGeoEditor(QtCore.QObject):
self.shapes.enabled = False self.shapes.enabled = False
self.tool_shape.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.setDisabled(True)
self.app.ui.geo_editor_menu.menuAction().setVisible(False) self.app.ui.geo_editor_menu.menuAction().setVisible(False)
@@ -3214,6 +3276,7 @@ class AppGeoEditor(QtCore.QObject):
self.active_tool.complete = True self.active_tool.complete = True
self.in_action = False self.in_action = False
self.delete_utility_geometry() self.delete_utility_geometry()
self.active_tool.clean_up()
self.app.inform.emit('[success] %s' % _("Done.")) self.app.inform.emit('[success] %s' % _("Done."))
self.select_tool('select') self.select_tool('select')
else: else:
@@ -3313,6 +3376,8 @@ class AppGeoEditor(QtCore.QObject):
pass pass
else: else:
self.update_utility_geometry(data=(x, y)) 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 ### # ### Selection area on canvas section ###
dx = pos[0] - self.pos[0] dx = pos[0] - self.pos[0]

View File

@@ -166,6 +166,9 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
self.on_update_text_hud() 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 # 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 # all CNC have a limited workspace
if self.fcapp.options['global_workspace'] is True: if self.fcapp.options['global_workspace'] is True:

View File

@@ -141,6 +141,8 @@ class Camera(scene.PanZoomCamera):
# Default mouse button for panning is RMB # Default mouse button for panning is RMB
self.pan_button_setting = "2" self.pan_button_setting = "2"
self.zoom_callback = lambda *args: None
def zoom(self, factor, center=None): def zoom(self, factor, center=None):
center = center if (center is not None) else self.center center = center if (center is not None) else self.center
super(Camera, self).zoom(factor, center) super(Camera, self).zoom(factor, center)
@@ -183,6 +185,9 @@ class Camera(scene.PanZoomCamera):
center = self._scene_transform.imap(event.pos) center = self._scene_transform.imap(event.pos)
scale = (1 + self.zoom_factor) ** (-event.delta[1] * 30) scale = (1 + self.zoom_factor) ** (-event.delta[1] * 30)
self.limited_zoom(scale, center) self.limited_zoom(scale, center)
if self.zoom_callback:
self.zoom_callback()
event.handled = True event.handled = True
elif event.type == 'mouse_move': elif event.type == 'mouse_move':