2019-10-13 15:13:39 +00:00
|
|
|
# ##########################################################
|
2019-03-10 13:22:16 +00:00
|
|
|
# FlatCAM: 2D Post-processing for Manufacturing #
|
|
|
|
# File Author: Marius Adrian Stanciu (c) #
|
|
|
|
# Date: 3/10/2019 #
|
|
|
|
# MIT Licence #
|
2019-10-13 15:13:39 +00:00
|
|
|
# ##########################################################
|
2019-03-10 13:22:16 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
from FlatCAMTool import FlatCAMTool
|
|
|
|
from FlatCAMObj import *
|
2019-03-11 10:23:26 +00:00
|
|
|
from flatcamGUI.VisPyVisuals import *
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
from math import sqrt
|
2019-03-07 23:32:18 +00:00
|
|
|
|
2019-03-07 16:04:11 +00:00
|
|
|
import gettext
|
2019-03-07 23:32:18 +00:00
|
|
|
import FlatCAMTranslation as fcTranslate
|
2019-07-14 22:16:02 +00:00
|
|
|
import builtins
|
2019-03-10 15:12:58 +00:00
|
|
|
|
2019-03-13 23:09:06 +00:00
|
|
|
fcTranslate.apply_language('strings')
|
2019-03-10 15:12:58 +00:00
|
|
|
if '_' not in builtins.__dict__:
|
|
|
|
_ = gettext.gettext
|
2019-03-07 16:04:11 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-09-29 02:13:36 +00:00
|
|
|
class Distance(FlatCAMTool):
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-09-29 02:13:36 +00:00
|
|
|
toolName = _("Distance Tool")
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def __init__(self, app):
|
|
|
|
FlatCAMTool.__init__(self, app)
|
|
|
|
|
2019-04-10 00:56:56 +00:00
|
|
|
self.app = app
|
2019-04-10 01:37:03 +00:00
|
|
|
self.canvas = self.app.plotcanvas
|
2019-03-04 01:47:19 +00:00
|
|
|
self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower()
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-05-30 18:05:12 +00:00
|
|
|
# ## Title
|
2019-01-03 19:25:08 +00:00
|
|
|
title_label = QtWidgets.QLabel("<font size=4><b>%s</b></font><br>" % self.toolName)
|
|
|
|
self.layout.addWidget(title_label)
|
|
|
|
|
2019-05-30 18:05:12 +00:00
|
|
|
# ## Form Layout
|
2019-01-03 19:25:08 +00:00
|
|
|
form_layout = QtWidgets.QFormLayout()
|
|
|
|
self.layout.addLayout(form_layout)
|
|
|
|
|
2019-08-19 14:24:56 +00:00
|
|
|
self.units_label = QtWidgets.QLabel('%s:' % _("Units"))
|
2019-04-10 00:56:56 +00:00
|
|
|
self.units_label.setToolTip(_("Those are the units in which the distance is measured."))
|
2019-07-17 11:11:10 +00:00
|
|
|
self.units_value = QtWidgets.QLabel("%s" % str({'mm': _("METRIC (mm)"), 'in': _("INCH (in)")}[self.units]))
|
2019-04-10 00:56:56 +00:00
|
|
|
self.units_value.setDisabled(True)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-09-22 14:06:22 +00:00
|
|
|
self.start_label = QtWidgets.QLabel("%s:" % _('Start Coords'))
|
2019-03-10 12:34:13 +00:00
|
|
|
self.start_label.setToolTip(_("This is measuring Start point coordinates."))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-09-22 14:06:22 +00:00
|
|
|
self.stop_label = QtWidgets.QLabel("%s:" % _('Stop Coords'))
|
2019-03-10 12:34:13 +00:00
|
|
|
self.stop_label.setToolTip(_("This is the measuring Stop point coordinates."))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-08-19 14:24:56 +00:00
|
|
|
self.distance_x_label = QtWidgets.QLabel('%s:' % _("Dx"))
|
2019-03-10 12:34:13 +00:00
|
|
|
self.distance_x_label.setToolTip(_("This is the distance measured over the X axis."))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-08-19 14:24:56 +00:00
|
|
|
self.distance_y_label = QtWidgets.QLabel('%s:' % _("Dy"))
|
2019-03-10 12:34:13 +00:00
|
|
|
self.distance_y_label.setToolTip(_("This is the distance measured over the Y axis."))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-09-29 02:13:36 +00:00
|
|
|
self.angle_label = QtWidgets.QLabel('%s:' % _("Angle"))
|
|
|
|
self.angle_label.setToolTip(_("This is orientation angle of the measuring line."))
|
|
|
|
|
2019-03-10 12:34:13 +00:00
|
|
|
self.total_distance_label = QtWidgets.QLabel("<b>%s:</b>" % _('DISTANCE'))
|
|
|
|
self.total_distance_label.setToolTip(_("This is the point to point Euclidian distance."))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
self.start_entry = FCEntry()
|
2019-09-30 01:58:26 +00:00
|
|
|
self.start_entry.setReadOnly(True)
|
2019-01-03 19:25:08 +00:00
|
|
|
self.start_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
2019-03-10 12:34:13 +00:00
|
|
|
self.start_entry.setToolTip(_("This is measuring Start point coordinates."))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
self.stop_entry = FCEntry()
|
2019-09-30 01:58:26 +00:00
|
|
|
self.stop_entry.setReadOnly(True)
|
2019-01-03 19:25:08 +00:00
|
|
|
self.stop_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
2019-03-10 12:34:13 +00:00
|
|
|
self.stop_entry.setToolTip(_("This is the measuring Stop point coordinates."))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
self.distance_x_entry = FCEntry()
|
2019-09-30 01:58:26 +00:00
|
|
|
self.distance_x_entry.setReadOnly(True)
|
2019-01-03 19:25:08 +00:00
|
|
|
self.distance_x_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
2019-03-10 12:34:13 +00:00
|
|
|
self.distance_x_entry.setToolTip(_("This is the distance measured over the X axis."))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
self.distance_y_entry = FCEntry()
|
2019-09-30 01:58:26 +00:00
|
|
|
self.distance_y_entry.setReadOnly(True)
|
2019-01-03 19:25:08 +00:00
|
|
|
self.distance_y_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
2019-03-10 12:34:13 +00:00
|
|
|
self.distance_y_entry.setToolTip(_("This is the distance measured over the Y axis."))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-09-29 02:13:36 +00:00
|
|
|
self.angle_entry = FCEntry()
|
2019-09-30 01:58:26 +00:00
|
|
|
self.angle_entry.setReadOnly(True)
|
2019-09-29 02:13:36 +00:00
|
|
|
self.angle_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
|
|
|
self.angle_entry.setToolTip(_("This is orientation angle of the measuring line."))
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
self.total_distance_entry = FCEntry()
|
2019-09-30 01:58:26 +00:00
|
|
|
self.total_distance_entry.setReadOnly(True)
|
2019-01-03 19:25:08 +00:00
|
|
|
self.total_distance_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
2019-03-10 12:34:13 +00:00
|
|
|
self.total_distance_entry.setToolTip(_("This is the point to point Euclidian distance."))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-03-10 12:34:13 +00:00
|
|
|
self.measure_btn = QtWidgets.QPushButton(_("Measure"))
|
2019-04-10 00:56:56 +00:00
|
|
|
# self.measure_btn.setFixedWidth(70)
|
2019-01-03 19:25:08 +00:00
|
|
|
self.layout.addWidget(self.measure_btn)
|
|
|
|
|
2019-04-10 00:56:56 +00:00
|
|
|
form_layout.addRow(self.units_label, self.units_value)
|
|
|
|
form_layout.addRow(self.start_label, self.start_entry)
|
|
|
|
form_layout.addRow(self.stop_label, self.stop_entry)
|
|
|
|
form_layout.addRow(self.distance_x_label, self.distance_x_entry)
|
|
|
|
form_layout.addRow(self.distance_y_label, self.distance_y_entry)
|
2019-09-29 02:13:36 +00:00
|
|
|
form_layout.addRow(self.angle_label, self.angle_entry)
|
2019-04-10 00:56:56 +00:00
|
|
|
form_layout.addRow(self.total_distance_label, self.total_distance_entry)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
# initial view of the layout
|
|
|
|
self.start_entry.set_value('(0, 0)')
|
|
|
|
self.stop_entry.set_value('(0, 0)')
|
2019-09-29 02:13:36 +00:00
|
|
|
self.distance_x_entry.set_value('0.0')
|
|
|
|
self.distance_y_entry.set_value('0.0')
|
|
|
|
self.angle_entry.set_value('0.0')
|
|
|
|
self.total_distance_entry.set_value('0.0')
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
self.layout.addStretch()
|
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
# store here the first click and second click of the measurement process
|
|
|
|
self.points = []
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-04-23 13:10:34 +00:00
|
|
|
self.rel_point1 = None
|
|
|
|
self.rel_point2 = None
|
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
self.active = False
|
2019-07-14 22:16:02 +00:00
|
|
|
self.clicked_meas = None
|
|
|
|
self.meas_line = None
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-04-14 12:16:37 +00:00
|
|
|
self.original_call_source = 'app'
|
|
|
|
|
2019-09-30 00:02:04 +00:00
|
|
|
# store here the event connection ID's
|
|
|
|
self.mm = None
|
|
|
|
self.mr = None
|
|
|
|
|
|
|
|
self.decimals = 4
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
# VisPy visuals
|
2019-09-20 14:25:32 +00:00
|
|
|
if self.app.is_legacy is False:
|
|
|
|
self.sel_shapes = ShapeCollection(parent=self.app.plotcanvas.view.scene, layers=1)
|
|
|
|
else:
|
|
|
|
from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
|
2019-09-21 15:26:03 +00:00
|
|
|
self.sel_shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='measurement')
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
self.measure_btn.clicked.connect(self.activate_measure_tool)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-03-10 15:21:45 +00:00
|
|
|
def run(self, toggle=False):
|
2019-09-29 02:13:36 +00:00
|
|
|
self.app.report_usage("ToolDistance()")
|
2019-02-03 21:08:09 +00:00
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
self.points[:] = []
|
|
|
|
|
2019-04-23 13:10:34 +00:00
|
|
|
self.rel_point1 = None
|
|
|
|
self.rel_point2 = None
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
if self.app.tool_tab_locked is True:
|
|
|
|
return
|
2019-03-07 23:32:18 +00:00
|
|
|
|
2019-09-29 02:13:36 +00:00
|
|
|
self.app.ui.notebook.setTabText(2, _("Distance Tool"))
|
2019-04-10 00:56:56 +00:00
|
|
|
|
2019-04-14 12:16:37 +00:00
|
|
|
# if the splitter is hidden, display it
|
2019-03-07 23:32:18 +00:00
|
|
|
if self.app.ui.splitter.sizes()[0] == 0:
|
|
|
|
self.app.ui.splitter.setSizes([1, 1])
|
2019-04-14 13:59:20 +00:00
|
|
|
if toggle:
|
|
|
|
pass
|
2019-03-07 23:32:18 +00:00
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
if self.active is False:
|
|
|
|
self.activate_measure_tool()
|
|
|
|
else:
|
|
|
|
self.deactivate_measure_tool()
|
2019-02-02 16:26:01 +00:00
|
|
|
|
|
|
|
def install(self, icon=None, separator=None, **kwargs):
|
|
|
|
FlatCAMTool.install(self, icon, separator, shortcut='CTRL+M', **kwargs)
|
|
|
|
|
|
|
|
def set_tool_ui(self):
|
2019-01-03 19:25:08 +00:00
|
|
|
# Remove anything else in the GUI
|
|
|
|
self.app.ui.tool_scroll_area.takeWidget()
|
|
|
|
|
|
|
|
# Put ourself in the GUI
|
|
|
|
self.app.ui.tool_scroll_area.setWidget(self)
|
|
|
|
|
|
|
|
# Switch notebook to tool page
|
|
|
|
self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
|
2019-03-04 01:47:19 +00:00
|
|
|
self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower()
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-09-29 02:13:36 +00:00
|
|
|
self.app.command_active = "Distance"
|
2019-04-10 00:56:56 +00:00
|
|
|
|
|
|
|
# initial view of the layout
|
|
|
|
self.start_entry.set_value('(0, 0)')
|
|
|
|
self.stop_entry.set_value('(0, 0)')
|
|
|
|
|
2019-09-29 02:13:36 +00:00
|
|
|
self.distance_x_entry.set_value('0.0')
|
|
|
|
self.distance_y_entry.set_value('0.0')
|
|
|
|
self.angle_entry.set_value('0.0')
|
|
|
|
self.total_distance_entry.set_value('0.0')
|
|
|
|
log.debug("Distance Tool --> tool initialized")
|
2019-04-10 00:56:56 +00:00
|
|
|
|
2019-04-14 12:16:37 +00:00
|
|
|
def activate_measure_tool(self):
|
2019-04-14 13:59:20 +00:00
|
|
|
# ENABLE the Measuring TOOL
|
|
|
|
self.active = True
|
|
|
|
|
|
|
|
self.clicked_meas = 0
|
|
|
|
self.original_call_source = copy(self.app.call_source)
|
|
|
|
|
|
|
|
self.app.inform.emit(_("MEASURING: Click on the Start point ..."))
|
|
|
|
self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower()
|
2019-04-10 00:56:56 +00:00
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
# we can connect the app mouse events to the measurement tool
|
|
|
|
# NEVER DISCONNECT THOSE before connecting some other handlers; it breaks something in VisPy
|
2019-09-20 22:10:32 +00:00
|
|
|
self.mm = self.canvas.graph_event_connect('mouse_move', self.on_mouse_move_meas)
|
|
|
|
self.mr = self.canvas.graph_event_connect('mouse_release', self.on_mouse_click_release)
|
2019-04-10 00:56:56 +00:00
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
# we disconnect the mouse/key handlers from wherever the measurement tool was called
|
|
|
|
if self.app.call_source == 'app':
|
2019-09-20 22:10:32 +00:00
|
|
|
if self.app.is_legacy is False:
|
|
|
|
self.canvas.graph_event_disconnect('mouse_move', self.app.on_mouse_move_over_plot)
|
|
|
|
self.canvas.graph_event_disconnect('mouse_press', self.app.on_mouse_click_over_plot)
|
|
|
|
self.canvas.graph_event_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot)
|
|
|
|
else:
|
|
|
|
self.canvas.graph_event_disconnect(self.app.mm)
|
|
|
|
self.canvas.graph_event_disconnect(self.app.mp)
|
|
|
|
self.canvas.graph_event_disconnect(self.app.mr)
|
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
elif self.app.call_source == 'geo_editor':
|
2019-09-20 22:10:32 +00:00
|
|
|
if self.app.is_legacy is False:
|
|
|
|
self.canvas.graph_event_disconnect('mouse_move', self.app.geo_editor.on_canvas_move)
|
|
|
|
self.canvas.graph_event_disconnect('mouse_press', self.app.geo_editor.on_canvas_click)
|
|
|
|
self.canvas.graph_event_disconnect('mouse_release', self.app.geo_editor.on_geo_click_release)
|
|
|
|
else:
|
|
|
|
self.canvas.graph_event_disconnect(self.app.geo_editor.mm)
|
|
|
|
self.canvas.graph_event_disconnect(self.app.geo_editor.mp)
|
|
|
|
self.canvas.graph_event_disconnect(self.app.geo_editor.mr)
|
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
elif self.app.call_source == 'exc_editor':
|
2019-09-20 22:10:32 +00:00
|
|
|
if self.app.is_legacy is False:
|
|
|
|
self.canvas.graph_event_disconnect('mouse_move', self.app.exc_editor.on_canvas_move)
|
|
|
|
self.canvas.graph_event_disconnect('mouse_press', self.app.exc_editor.on_canvas_click)
|
|
|
|
self.canvas.graph_event_disconnect('mouse_release', self.app.exc_editor.on_exc_click_release)
|
|
|
|
else:
|
|
|
|
self.canvas.graph_event_disconnect(self.app.exc_editor.mm)
|
|
|
|
self.canvas.graph_event_disconnect(self.app.exc_editor.mp)
|
|
|
|
self.canvas.graph_event_disconnect(self.app.exc_editor.mr)
|
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
elif self.app.call_source == 'grb_editor':
|
2019-09-20 22:10:32 +00:00
|
|
|
if self.app.is_legacy is False:
|
|
|
|
self.canvas.graph_event_disconnect('mouse_move', self.app.grb_editor.on_canvas_move)
|
|
|
|
self.canvas.graph_event_disconnect('mouse_press', self.app.grb_editor.on_canvas_click)
|
|
|
|
self.canvas.graph_event_disconnect('mouse_release', self.app.grb_editor.on_grb_click_release)
|
|
|
|
else:
|
|
|
|
self.canvas.graph_event_disconnect(self.app.grb_editor.mm)
|
|
|
|
self.canvas.graph_event_disconnect(self.app.grb_editor.mp)
|
|
|
|
self.canvas.graph_event_disconnect(self.app.grb_editor.mr)
|
2019-04-14 13:59:20 +00:00
|
|
|
|
|
|
|
self.app.call_source = 'measurement'
|
|
|
|
|
2019-04-10 00:56:56 +00:00
|
|
|
self.set_tool_ui()
|
|
|
|
|
2019-04-14 12:16:37 +00:00
|
|
|
def deactivate_measure_tool(self):
|
2019-04-14 13:59:20 +00:00
|
|
|
# DISABLE the Measuring TOOL
|
|
|
|
self.active = False
|
|
|
|
self.points = []
|
2019-04-10 00:56:56 +00:00
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
self.app.call_source = copy(self.original_call_source)
|
|
|
|
if self.original_call_source == 'app':
|
2019-09-20 22:10:32 +00:00
|
|
|
self.app.mm = self.canvas.graph_event_connect('mouse_move', self.app.on_mouse_move_over_plot)
|
|
|
|
self.app.mp = self.canvas.graph_event_connect('mouse_press', self.app.on_mouse_click_over_plot)
|
|
|
|
self.app.mr = self.canvas.graph_event_connect('mouse_release', self.app.on_mouse_click_release_over_plot)
|
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
elif self.original_call_source == 'geo_editor':
|
2019-09-20 22:10:32 +00:00
|
|
|
self.app.geo_editor.mm = self.canvas.graph_event_connect('mouse_move', self.app.geo_editor.on_canvas_move)
|
|
|
|
self.app.geo_editor.mp = self.canvas.graph_event_connect('mouse_press', self.app.geo_editor.on_canvas_click)
|
|
|
|
self.app.geo_editor.mr = self.canvas.graph_event_connect('mouse_release',
|
|
|
|
self.app.geo_editor.on_geo_click_release)
|
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
elif self.original_call_source == 'exc_editor':
|
2019-09-20 22:10:32 +00:00
|
|
|
self.app.exc_editor.mm = self.canvas.graph_event_connect('mouse_move', self.app.exc_editor.on_canvas_move)
|
|
|
|
self.app.exc_editor.mp = self.canvas.graph_event_connect('mouse_press', self.app.exc_editor.on_canvas_click)
|
|
|
|
self.app.exc_editor.mr = self.canvas.graph_event_connect('mouse_release',
|
|
|
|
self.app.exc_editor.on_exc_click_release)
|
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
elif self.original_call_source == 'grb_editor':
|
2019-09-20 22:10:32 +00:00
|
|
|
self.app.grb_editor.mm = self.canvas.graph_event_connect('mouse_move', self.app.grb_editor.on_canvas_move)
|
|
|
|
self.app.grb_editor.mp = self.canvas.graph_event_connect('mouse_press', self.app.grb_editor.on_canvas_click)
|
|
|
|
self.app.grb_editor.mr = self.canvas.graph_event_connect('mouse_release',
|
|
|
|
self.app.grb_editor.on_grb_click_release)
|
2019-04-10 00:56:56 +00:00
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
# disconnect the mouse/key events from functions of measurement tool
|
2019-09-20 22:10:32 +00:00
|
|
|
if self.app.is_legacy is False:
|
|
|
|
self.canvas.graph_event_disconnect('mouse_move', self.on_mouse_move_meas)
|
|
|
|
self.canvas.graph_event_disconnect('mouse_release', self.on_mouse_click_release)
|
|
|
|
else:
|
|
|
|
self.canvas.graph_event_disconnect(self.mm)
|
|
|
|
self.canvas.graph_event_disconnect(self.mr)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
# self.app.ui.notebook.setTabText(2, _("Tools"))
|
|
|
|
# self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab)
|
2019-04-10 00:56:56 +00:00
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
self.app.command_active = None
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
# delete the measuring line
|
|
|
|
self.delete_shape()
|
2019-02-02 16:26:01 +00:00
|
|
|
|
2019-09-29 02:13:36 +00:00
|
|
|
log.debug("Distance Tool --> exit tool")
|
2019-02-02 16:26:01 +00:00
|
|
|
|
2019-04-14 12:16:37 +00:00
|
|
|
def on_mouse_click_release(self, event):
|
2019-03-31 21:07:26 +00:00
|
|
|
# mouse click releases will be accepted only if the left button is clicked
|
|
|
|
# this is necessary because right mouse click or middle mouse click
|
2019-01-03 19:25:08 +00:00
|
|
|
# are used for panning on the canvas
|
2019-09-29 02:13:36 +00:00
|
|
|
log.debug("Distance Tool --> mouse click release")
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
if event.button == 1:
|
2019-09-21 10:07:30 +00:00
|
|
|
if self.app.is_legacy is False:
|
|
|
|
event_pos = event.pos
|
|
|
|
else:
|
|
|
|
event_pos = (event.xdata, event.ydata)
|
|
|
|
|
|
|
|
pos_canvas = self.canvas.translate_coords(event_pos)
|
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
# if GRID is active we need to get the snapped positions
|
2019-08-10 23:18:32 +00:00
|
|
|
if self.app.grid_status() == True:
|
2019-04-14 13:59:20 +00:00
|
|
|
pos = self.app.geo_editor.snap(pos_canvas[0], pos_canvas[1])
|
|
|
|
else:
|
|
|
|
pos = pos_canvas[0], pos_canvas[1]
|
|
|
|
self.points.append(pos)
|
2019-04-10 00:56:56 +00:00
|
|
|
|
2019-04-23 13:10:34 +00:00
|
|
|
# Reset here the relative coordinates so there is a new reference on the click position
|
|
|
|
if self.rel_point1 is None:
|
2019-09-30 00:02:04 +00:00
|
|
|
self.app.ui.rel_position_label.setText("<b>Dx</b>: %.*f <b>Dy</b>: "
|
|
|
|
"%.*f " %
|
|
|
|
(self.decimals, 0.0, self.decimals, 0.0))
|
2019-04-23 13:10:34 +00:00
|
|
|
self.rel_point1 = pos
|
|
|
|
else:
|
|
|
|
self.rel_point2 = copy(self.rel_point1)
|
|
|
|
self.rel_point1 = pos
|
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
if len(self.points) == 1:
|
2019-09-30 00:02:04 +00:00
|
|
|
self.start_entry.set_value("(%.*f, %.*f)" % (self.decimals, pos[0], self.decimals, pos[1]))
|
2019-03-10 12:34:13 +00:00
|
|
|
self.app.inform.emit(_("MEASURING: Click on the Destination point ..."))
|
2019-09-21 19:00:02 +00:00
|
|
|
elif len(self.points) == 2:
|
2019-04-14 13:59:20 +00:00
|
|
|
dx = self.points[1][0] - self.points[0][0]
|
|
|
|
dy = self.points[1][1] - self.points[0][1]
|
2019-04-10 01:37:03 +00:00
|
|
|
d = sqrt(dx ** 2 + dy ** 2)
|
2019-09-30 00:02:04 +00:00
|
|
|
self.stop_entry.set_value("(%.*f, %.*f)" % (self.decimals, pos[0], self.decimals, pos[1]))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-04-10 01:37:03 +00:00
|
|
|
self.app.inform.emit(_("MEASURING: Result D(x) = {d_x} | D(y) = {d_y} | Distance = {d_z}").format(
|
2019-09-30 00:02:04 +00:00
|
|
|
d_x='%*f' % (self.decimals, abs(dx)),
|
|
|
|
d_y='%*f' % (self.decimals, abs(dy)),
|
|
|
|
d_z='%*f' % (self.decimals, abs(d)))
|
|
|
|
)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-09-30 00:02:04 +00:00
|
|
|
self.distance_x_entry.set_value('%.*f' % (self.decimals, abs(dx)))
|
|
|
|
self.distance_y_entry.set_value('%.*f' % (self.decimals, abs(dy)))
|
2019-09-29 02:13:36 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
angle = math.degrees(math.atan(dy / dx))
|
2019-09-30 00:02:04 +00:00
|
|
|
self.angle_entry.set_value('%.*f' % (self.decimals, angle))
|
2019-09-29 02:13:36 +00:00
|
|
|
except Exception as e:
|
|
|
|
pass
|
|
|
|
|
2019-09-30 00:02:04 +00:00
|
|
|
self.total_distance_entry.set_value('%.*f' % (self.decimals, abs(d)))
|
|
|
|
self.app.ui.rel_position_label.setText(
|
|
|
|
"<b>Dx</b>: {} <b>Dy</b>: {} ".format(
|
|
|
|
'%.*f' % (self.decimals, pos[0]), '%.*f' % (self.decimals, pos[1])
|
|
|
|
)
|
|
|
|
)
|
2019-04-14 13:59:20 +00:00
|
|
|
self.deactivate_measure_tool()
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def on_mouse_move_meas(self, event):
|
2019-04-23 13:10:34 +00:00
|
|
|
try: # May fail in case mouse not within axes
|
2019-09-21 10:07:30 +00:00
|
|
|
if self.app.is_legacy is False:
|
|
|
|
event_pos = event.pos
|
|
|
|
else:
|
|
|
|
event_pos = (event.xdata, event.ydata)
|
|
|
|
|
2019-09-21 19:00:02 +00:00
|
|
|
try:
|
|
|
|
x = float(event_pos[0])
|
|
|
|
y = float(event_pos[1])
|
|
|
|
except TypeError:
|
|
|
|
return
|
|
|
|
|
|
|
|
pos_canvas = self.app.plotcanvas.translate_coords((x, y))
|
|
|
|
|
2019-08-10 23:18:32 +00:00
|
|
|
if self.app.grid_status() == True:
|
2019-04-23 13:10:34 +00:00
|
|
|
pos = self.app.geo_editor.snap(pos_canvas[0], pos_canvas[1])
|
2019-09-22 10:12:21 +00:00
|
|
|
|
|
|
|
# Update cursor
|
|
|
|
self.app.app_cursor.set_data(np.asarray([(pos[0], pos[1])]),
|
2019-10-07 01:06:00 +00:00
|
|
|
symbol='++', edge_color=self.app.cursor_color_3D,
|
2019-09-27 01:42:28 +00:00
|
|
|
size=self.app.defaults["global_cursor_size"])
|
2019-04-23 13:10:34 +00:00
|
|
|
else:
|
|
|
|
pos = (pos_canvas[0], pos_canvas[1])
|
|
|
|
|
2019-09-30 00:02:04 +00:00
|
|
|
self.app.ui.position_label.setText(
|
|
|
|
" <b>X</b>: {} <b>Y</b>: {}".format(
|
|
|
|
'%.*f' % (self.decimals, pos[0]), '%.*f' % (self.decimals, pos[1])
|
|
|
|
)
|
|
|
|
)
|
2019-09-21 19:00:02 +00:00
|
|
|
|
2019-04-23 13:10:34 +00:00
|
|
|
if self.rel_point1 is not None:
|
2019-09-21 19:00:02 +00:00
|
|
|
dx = pos[0] - float(self.rel_point1[0])
|
|
|
|
dy = pos[1] - float(self.rel_point1[1])
|
2019-04-23 13:10:34 +00:00
|
|
|
else:
|
|
|
|
dx = pos[0]
|
|
|
|
dy = pos[1]
|
|
|
|
|
2019-09-30 00:02:04 +00:00
|
|
|
self.app.ui.rel_position_label.setText(
|
|
|
|
"<b>Dx</b>: {} <b>Dy</b>: {} ".format(
|
|
|
|
'%.*f' % (self.decimals, dx), '%.*f' % (self.decimals, dy)
|
|
|
|
)
|
|
|
|
)
|
2019-09-21 19:00:02 +00:00
|
|
|
|
2019-04-23 13:10:34 +00:00
|
|
|
# update utility geometry
|
|
|
|
if len(self.points) == 1:
|
|
|
|
self.utility_geometry(pos=pos)
|
2019-09-29 02:13:36 +00:00
|
|
|
# and display the temporary angle
|
|
|
|
try:
|
|
|
|
angle = math.degrees(math.atan(dy / dx))
|
2019-09-30 00:02:04 +00:00
|
|
|
self.angle_entry.set_value('%.*f' % (self.decimals, angle))
|
2019-09-29 02:13:36 +00:00
|
|
|
except Exception as e:
|
|
|
|
pass
|
|
|
|
|
2019-07-14 22:16:02 +00:00
|
|
|
except Exception as e:
|
2019-09-29 02:13:36 +00:00
|
|
|
log.debug("Distance.on_mouse_move_meas() --> %s" % str(e))
|
2019-04-23 13:10:34 +00:00
|
|
|
self.app.ui.position_label.setText("")
|
|
|
|
self.app.ui.rel_position_label.setText("")
|
2019-04-14 13:59:20 +00:00
|
|
|
|
|
|
|
def utility_geometry(self, pos):
|
|
|
|
# first delete old shape
|
|
|
|
self.delete_shape()
|
2019-09-21 19:00:02 +00:00
|
|
|
|
2019-04-14 13:59:20 +00:00
|
|
|
# second draw the new shape of the utility geometry
|
2019-09-21 19:00:02 +00:00
|
|
|
meas_line = LineString([pos, self.points[0]])
|
|
|
|
|
2019-10-08 01:17:08 +00:00
|
|
|
settings = QtCore.QSettings("Open Source", "FlatCAM")
|
|
|
|
if settings.contains("theme"):
|
|
|
|
theme = settings.value('theme', type=str)
|
|
|
|
else:
|
|
|
|
theme = 'white'
|
|
|
|
|
|
|
|
if theme == 'white':
|
|
|
|
color = '#000000FF'
|
|
|
|
else:
|
|
|
|
color = '#FFFFFFFF'
|
|
|
|
|
2019-09-21 19:00:02 +00:00
|
|
|
self.sel_shapes.add(meas_line, color=color, update=True, layer=0, tolerance=None)
|
|
|
|
|
|
|
|
if self.app.is_legacy is True:
|
|
|
|
self.sel_shapes.redraw()
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def delete_shape(self):
|
|
|
|
self.sel_shapes.clear()
|
|
|
|
self.sel_shapes.redraw()
|
|
|
|
|
|
|
|
def set_meas_units(self, units):
|
|
|
|
self.meas.units_label.setText("[" + self.app.options["units"].lower() + "]")
|
|
|
|
|
|
|
|
# end of file
|