- 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

@@ -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]