- in Tools: Transform, SUb, RulesCheck, DistanceMin, Distance - moved the Tool UI in its own class
This commit is contained in:
parent
71ae6fe5e6
commit
cebffe34b1
|
@ -16,9 +16,10 @@ CHANGELOG for FlatCAM beta
|
|||
- in Tool Cutout: modified the UI in preparation for adding the Mouse Bites feature
|
||||
- Turkish translation strings were updated by the translator, Mehmet Kaya
|
||||
- Film Tool - moved the Tool UI in its own class
|
||||
- in Tools: Film, Image, InvertGerber, Optimal, PcbWizard - moved the Tool UI in its own class
|
||||
- in Tools: Image, InvertGerber, Optimal, PcbWizard - moved the Tool UI in its own class
|
||||
- Tool Isolation - made sure that the app can load from Tools Database only tools marked for Isolation tool
|
||||
- Tool Isolation - on Tool start it will attempt to load the Preferences set tools by diameter from Tools Database. If it can't find one there it will add a default tool.
|
||||
- in Tools: Transform, SUb, RulesCheck, DistanceMin, Distance - moved the Tool UI in its own class
|
||||
|
||||
26.08.2020
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ from PyQt5 import QtWidgets, QtCore
|
|||
|
||||
from appTool import AppTool
|
||||
from appGUI.VisPyVisuals import *
|
||||
from appGUI.GUIElements import FCEntry, FCButton, FCCheckBox
|
||||
from appGUI.GUIElements import FCEntry, FCButton, FCCheckBox, FCLabel
|
||||
|
||||
from shapely.geometry import Point, MultiLineString, Polygon
|
||||
|
||||
|
@ -32,8 +32,6 @@ log = logging.getLogger('base')
|
|||
|
||||
class Distance(AppTool):
|
||||
|
||||
toolName = _("Distance Tool")
|
||||
|
||||
def __init__(self, app):
|
||||
AppTool.__init__(self, app)
|
||||
|
||||
|
@ -43,107 +41,11 @@ class Distance(AppTool):
|
|||
self.canvas = self.app.plotcanvas
|
||||
self.units = self.app.defaults['units'].lower()
|
||||
|
||||
# ## Title
|
||||
title_label = QtWidgets.QLabel("<font size=4><b>%s</b></font><br>" % self.toolName)
|
||||
self.layout.addWidget(title_label)
|
||||
|
||||
# ## Form Layout
|
||||
grid0 = QtWidgets.QGridLayout()
|
||||
grid0.setColumnStretch(0, 0)
|
||||
grid0.setColumnStretch(1, 1)
|
||||
self.layout.addLayout(grid0)
|
||||
|
||||
self.units_label = QtWidgets.QLabel('%s:' % _("Units"))
|
||||
self.units_label.setToolTip(_("Those are the units in which the distance is measured."))
|
||||
self.units_value = QtWidgets.QLabel("%s" % str({'mm': _("METRIC (mm)"), 'in': _("INCH (in)")}[self.units]))
|
||||
self.units_value.setDisabled(True)
|
||||
|
||||
grid0.addWidget(self.units_label, 0, 0)
|
||||
grid0.addWidget(self.units_value, 0, 1)
|
||||
|
||||
self.snap_center_cb = FCCheckBox(_("Snap to center"))
|
||||
self.snap_center_cb.setToolTip(
|
||||
_("Mouse cursor will snap to the center of the pad/drill\n"
|
||||
"when it is hovering over the geometry of the pad/drill.")
|
||||
)
|
||||
grid0.addWidget(self.snap_center_cb, 1, 0, 1, 2)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
grid0.addWidget(separator_line, 2, 0, 1, 2)
|
||||
|
||||
self.start_label = QtWidgets.QLabel("%s:" % _('Start Coords'))
|
||||
self.start_label.setToolTip(_("This is measuring Start point coordinates."))
|
||||
|
||||
self.start_entry = FCEntry()
|
||||
self.start_entry.setReadOnly(True)
|
||||
self.start_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.start_entry.setToolTip(_("This is measuring Start point coordinates."))
|
||||
|
||||
grid0.addWidget(self.start_label, 3, 0)
|
||||
grid0.addWidget(self.start_entry, 3, 1)
|
||||
|
||||
self.stop_label = QtWidgets.QLabel("%s:" % _('Stop Coords'))
|
||||
self.stop_label.setToolTip(_("This is the measuring Stop point coordinates."))
|
||||
|
||||
self.stop_entry = FCEntry()
|
||||
self.stop_entry.setReadOnly(True)
|
||||
self.stop_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.stop_entry.setToolTip(_("This is the measuring Stop point coordinates."))
|
||||
|
||||
grid0.addWidget(self.stop_label, 4, 0)
|
||||
grid0.addWidget(self.stop_entry, 4, 1)
|
||||
|
||||
self.distance_x_label = QtWidgets.QLabel('%s:' % _("Dx"))
|
||||
self.distance_x_label.setToolTip(_("This is the distance measured over the X axis."))
|
||||
|
||||
self.distance_x_entry = FCEntry()
|
||||
self.distance_x_entry.setReadOnly(True)
|
||||
self.distance_x_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.distance_x_entry.setToolTip(_("This is the distance measured over the X axis."))
|
||||
|
||||
grid0.addWidget(self.distance_x_label, 5, 0)
|
||||
grid0.addWidget(self.distance_x_entry, 5, 1)
|
||||
|
||||
self.distance_y_label = QtWidgets.QLabel('%s:' % _("Dy"))
|
||||
self.distance_y_label.setToolTip(_("This is the distance measured over the Y axis."))
|
||||
|
||||
self.distance_y_entry = FCEntry()
|
||||
self.distance_y_entry.setReadOnly(True)
|
||||
self.distance_y_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.distance_y_entry.setToolTip(_("This is the distance measured over the Y axis."))
|
||||
|
||||
grid0.addWidget(self.distance_y_label, 6, 0)
|
||||
grid0.addWidget(self.distance_y_entry, 6, 1)
|
||||
|
||||
self.angle_label = QtWidgets.QLabel('%s:' % _("Angle"))
|
||||
self.angle_label.setToolTip(_("This is orientation angle of the measuring line."))
|
||||
|
||||
self.angle_entry = FCEntry()
|
||||
self.angle_entry.setReadOnly(True)
|
||||
self.angle_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.angle_entry.setToolTip(_("This is orientation angle of the measuring line."))
|
||||
|
||||
grid0.addWidget(self.angle_label, 7, 0)
|
||||
grid0.addWidget(self.angle_entry, 7, 1)
|
||||
|
||||
self.total_distance_label = QtWidgets.QLabel("<b>%s:</b>" % _('DISTANCE'))
|
||||
self.total_distance_label.setToolTip(_("This is the point to point Euclidian distance."))
|
||||
|
||||
self.total_distance_entry = FCEntry()
|
||||
self.total_distance_entry.setReadOnly(True)
|
||||
self.total_distance_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.total_distance_entry.setToolTip(_("This is the point to point Euclidian distance."))
|
||||
|
||||
grid0.addWidget(self.total_distance_label, 8, 0)
|
||||
grid0.addWidget(self.total_distance_entry, 8, 1)
|
||||
|
||||
self.measure_btn = FCButton(_("Measure"))
|
||||
# self.measure_btn.setFixedWidth(70)
|
||||
self.layout.addWidget(self.measure_btn)
|
||||
|
||||
self.layout.addStretch()
|
||||
# #############################################################################
|
||||
# ######################### Tool GUI ##########################################
|
||||
# #############################################################################
|
||||
self.ui = DistUI(layout=self.layout, app=self.app)
|
||||
self.toolName = self.ui.toolName
|
||||
|
||||
# store here the first click and second click of the measurement process
|
||||
self.points = []
|
||||
|
@ -178,8 +80,9 @@ class Distance(AppTool):
|
|||
else:
|
||||
from appGUI.PlotCanvasLegacy import ShapeCollectionLegacy
|
||||
self.sel_shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='measurement')
|
||||
|
||||
self.measure_btn.clicked.connect(self.activate_measure_tool)
|
||||
|
||||
# Signals
|
||||
self.ui.measure_btn.clicked.connect(self.activate_measure_tool)
|
||||
|
||||
def run(self, toggle=False):
|
||||
self.app.defaults.report_usage("ToolDistance()")
|
||||
|
@ -224,27 +127,27 @@ class Distance(AppTool):
|
|||
self.app.command_active = "Distance"
|
||||
|
||||
# initial view of the layout
|
||||
self.start_entry.set_value('(0, 0)')
|
||||
self.stop_entry.set_value('(0, 0)')
|
||||
self.ui.start_entry.set_value('(0, 0)')
|
||||
self.ui.stop_entry.set_value('(0, 0)')
|
||||
|
||||
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')
|
||||
self.ui.distance_x_entry.set_value('0.0')
|
||||
self.ui.distance_y_entry.set_value('0.0')
|
||||
self.ui.angle_entry.set_value('0.0')
|
||||
self.ui.total_distance_entry.set_value('0.0')
|
||||
|
||||
self.snap_center_cb.set_value(self.app.defaults['tools_dist_snap_center'])
|
||||
self.ui.snap_center_cb.set_value(self.app.defaults['tools_dist_snap_center'])
|
||||
|
||||
# snap center works only for Gerber and Execellon Editor's
|
||||
if self.original_call_source == 'exc_editor' or self.original_call_source == 'grb_editor':
|
||||
self.snap_center_cb.show()
|
||||
self.ui.snap_center_cb.show()
|
||||
snap_center = self.app.defaults['tools_dist_snap_center']
|
||||
self.on_snap_toggled(snap_center)
|
||||
|
||||
self.snap_center_cb.toggled.connect(self.on_snap_toggled)
|
||||
self.ui.snap_center_cb.toggled.connect(self.on_snap_toggled)
|
||||
else:
|
||||
self.snap_center_cb.hide()
|
||||
self.ui.snap_center_cb.hide()
|
||||
try:
|
||||
self.snap_center_cb.toggled.disconnect(self.on_snap_toggled)
|
||||
self.ui.snap_center_cb.toggled.disconnect(self.on_snap_toggled)
|
||||
except (TypeError, AttributeError):
|
||||
pass
|
||||
|
||||
|
@ -270,8 +173,8 @@ class Distance(AppTool):
|
|||
self.active = True
|
||||
|
||||
# disable the measuring button
|
||||
self.measure_btn.setDisabled(True)
|
||||
self.measure_btn.setText('%s...' % _("Working"))
|
||||
self.ui.measure_btn.setDisabled(True)
|
||||
self.ui.measure_btn.setText('%s...' % _("Working"))
|
||||
|
||||
self.clicked_meas = 0
|
||||
self.original_call_source = copy(self.app.call_source)
|
||||
|
@ -335,8 +238,8 @@ class Distance(AppTool):
|
|||
self.points = []
|
||||
|
||||
# disable the measuring button
|
||||
self.measure_btn.setDisabled(False)
|
||||
self.measure_btn.setText(_("Measure"))
|
||||
self.ui.measure_btn.setDisabled(False)
|
||||
self.ui.measure_btn.setText(_("Measure"))
|
||||
|
||||
self.app.call_source = copy(self.original_call_source)
|
||||
if self.original_call_source == 'app':
|
||||
|
@ -406,7 +309,7 @@ class Distance(AppTool):
|
|||
if event.button == 1:
|
||||
pos_canvas = self.canvas.translate_coords(event_pos)
|
||||
|
||||
if self.snap_center_cb.get_value() is False:
|
||||
if self.ui.snap_center_cb.get_value() is False:
|
||||
# if GRID is active we need to get the snapped positions
|
||||
if self.app.grid_status():
|
||||
pos = self.app.geo_editor.snap(pos_canvas[0], pos_canvas[1])
|
||||
|
@ -490,14 +393,14 @@ class Distance(AppTool):
|
|||
|
||||
def calculate_distance(self, pos):
|
||||
if len(self.points) == 1:
|
||||
self.start_entry.set_value("(%.*f, %.*f)" % (self.decimals, pos[0], self.decimals, pos[1]))
|
||||
self.ui.start_entry.set_value("(%.*f, %.*f)" % (self.decimals, pos[0], self.decimals, pos[1]))
|
||||
self.app.inform.emit(_("MEASURING: Click on the Destination point ..."))
|
||||
elif len(self.points) == 2:
|
||||
# self.app.app_cursor.enabled = False
|
||||
dx = self.points[1][0] - self.points[0][0]
|
||||
dy = self.points[1][1] - self.points[0][1]
|
||||
d = math.sqrt(dx ** 2 + dy ** 2)
|
||||
self.stop_entry.set_value("(%.*f, %.*f)" % (self.decimals, pos[0], self.decimals, pos[1]))
|
||||
self.ui.stop_entry.set_value("(%.*f, %.*f)" % (self.decimals, pos[0], self.decimals, pos[1]))
|
||||
|
||||
self.app.inform.emit("{tx1}: {tx2} D(x) = {d_x} | D(y) = {d_y} | {tx3} = {d_z}".format(
|
||||
tx1=_("MEASURING"),
|
||||
|
@ -508,18 +411,18 @@ class Distance(AppTool):
|
|||
d_z='%*f' % (self.decimals, abs(d)))
|
||||
)
|
||||
|
||||
self.distance_x_entry.set_value('%.*f' % (self.decimals, abs(dx)))
|
||||
self.distance_y_entry.set_value('%.*f' % (self.decimals, abs(dy)))
|
||||
self.ui.distance_x_entry.set_value('%.*f' % (self.decimals, abs(dx)))
|
||||
self.ui.distance_y_entry.set_value('%.*f' % (self.decimals, abs(dy)))
|
||||
|
||||
try:
|
||||
angle = math.degrees(math.atan2(dy, dx))
|
||||
if angle < 0:
|
||||
angle += 360
|
||||
self.angle_entry.set_value('%.*f' % (self.decimals, angle))
|
||||
self.ui.angle_entry.set_value('%.*f' % (self.decimals, angle))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self.total_distance_entry.set_value('%.*f' % (self.decimals, abs(d)))
|
||||
self.ui.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])
|
||||
|
@ -587,7 +490,7 @@ class Distance(AppTool):
|
|||
angle = math.degrees(math.atan2(dy, dx))
|
||||
if angle < 0:
|
||||
angle += 360
|
||||
self.angle_entry.set_value('%.*f' % (self.decimals, angle))
|
||||
self.ui.angle_entry.set_value('%.*f' % (self.decimals, angle))
|
||||
except Exception as e:
|
||||
log.debug("Distance.on_mouse_move_meas() -> update utility geometry -> %s" % str(e))
|
||||
pass
|
||||
|
@ -635,4 +538,134 @@ class Distance(AppTool):
|
|||
# def set_meas_units(self, units):
|
||||
# self.meas.units_label.setText("[" + self.app.options["units"].lower() + "]")
|
||||
|
||||
# end of file
|
||||
|
||||
class DistUI:
|
||||
|
||||
toolName = _("Distance Tool")
|
||||
|
||||
def __init__(self, layout, app):
|
||||
self.app = app
|
||||
self.decimals = self.app.decimals
|
||||
self.layout = layout
|
||||
|
||||
# ## Title
|
||||
title_label = FCLabel("<font size=4><b>%s</b></font><br>" % self.toolName)
|
||||
self.layout.addWidget(title_label)
|
||||
|
||||
# ## Form Layout
|
||||
grid0 = QtWidgets.QGridLayout()
|
||||
grid0.setColumnStretch(0, 0)
|
||||
grid0.setColumnStretch(1, 1)
|
||||
self.layout.addLayout(grid0)
|
||||
|
||||
self.units_label = FCLabel('%s:' % _("Units"))
|
||||
self.units_label.setToolTip(_("Those are the units in which the distance is measured."))
|
||||
self.units_value = FCLabel("%s" % str({'mm': _("METRIC (mm)"), 'in': _("INCH (in)")}[self.units]))
|
||||
self.units_value.setDisabled(True)
|
||||
|
||||
grid0.addWidget(self.units_label, 0, 0)
|
||||
grid0.addWidget(self.units_value, 0, 1)
|
||||
|
||||
self.snap_center_cb = FCCheckBox(_("Snap to center"))
|
||||
self.snap_center_cb.setToolTip(
|
||||
_("Mouse cursor will snap to the center of the pad/drill\n"
|
||||
"when it is hovering over the geometry of the pad/drill.")
|
||||
)
|
||||
grid0.addWidget(self.snap_center_cb, 1, 0, 1, 2)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
grid0.addWidget(separator_line, 2, 0, 1, 2)
|
||||
|
||||
self.start_label = FCLabel("%s:" % _('Start Coords'))
|
||||
self.start_label.setToolTip(_("This is measuring Start point coordinates."))
|
||||
|
||||
self.start_entry = FCEntry()
|
||||
self.start_entry.setReadOnly(True)
|
||||
self.start_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.start_entry.setToolTip(_("This is measuring Start point coordinates."))
|
||||
|
||||
grid0.addWidget(self.start_label, 3, 0)
|
||||
grid0.addWidget(self.start_entry, 3, 1)
|
||||
|
||||
self.stop_label = FCLabel("%s:" % _('Stop Coords'))
|
||||
self.stop_label.setToolTip(_("This is the measuring Stop point coordinates."))
|
||||
|
||||
self.stop_entry = FCEntry()
|
||||
self.stop_entry.setReadOnly(True)
|
||||
self.stop_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.stop_entry.setToolTip(_("This is the measuring Stop point coordinates."))
|
||||
|
||||
grid0.addWidget(self.stop_label, 4, 0)
|
||||
grid0.addWidget(self.stop_entry, 4, 1)
|
||||
|
||||
self.distance_x_label = FCLabel('%s:' % _("Dx"))
|
||||
self.distance_x_label.setToolTip(_("This is the distance measured over the X axis."))
|
||||
|
||||
self.distance_x_entry = FCEntry()
|
||||
self.distance_x_entry.setReadOnly(True)
|
||||
self.distance_x_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.distance_x_entry.setToolTip(_("This is the distance measured over the X axis."))
|
||||
|
||||
grid0.addWidget(self.distance_x_label, 5, 0)
|
||||
grid0.addWidget(self.distance_x_entry, 5, 1)
|
||||
|
||||
self.distance_y_label = FCLabel('%s:' % _("Dy"))
|
||||
self.distance_y_label.setToolTip(_("This is the distance measured over the Y axis."))
|
||||
|
||||
self.distance_y_entry = FCEntry()
|
||||
self.distance_y_entry.setReadOnly(True)
|
||||
self.distance_y_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.distance_y_entry.setToolTip(_("This is the distance measured over the Y axis."))
|
||||
|
||||
grid0.addWidget(self.distance_y_label, 6, 0)
|
||||
grid0.addWidget(self.distance_y_entry, 6, 1)
|
||||
|
||||
self.angle_label = FCLabel('%s:' % _("Angle"))
|
||||
self.angle_label.setToolTip(_("This is orientation angle of the measuring line."))
|
||||
|
||||
self.angle_entry = FCEntry()
|
||||
self.angle_entry.setReadOnly(True)
|
||||
self.angle_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.angle_entry.setToolTip(_("This is orientation angle of the measuring line."))
|
||||
|
||||
grid0.addWidget(self.angle_label, 7, 0)
|
||||
grid0.addWidget(self.angle_entry, 7, 1)
|
||||
|
||||
self.total_distance_label = FCLabel("<b>%s:</b>" % _('DISTANCE'))
|
||||
self.total_distance_label.setToolTip(_("This is the point to point Euclidian distance."))
|
||||
|
||||
self.total_distance_entry = FCEntry()
|
||||
self.total_distance_entry.setReadOnly(True)
|
||||
self.total_distance_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.total_distance_entry.setToolTip(_("This is the point to point Euclidian distance."))
|
||||
|
||||
grid0.addWidget(self.total_distance_label, 8, 0)
|
||||
grid0.addWidget(self.total_distance_entry, 8, 1)
|
||||
|
||||
self.measure_btn = FCButton(_("Measure"))
|
||||
# self.measure_btn.setFixedWidth(70)
|
||||
self.layout.addWidget(self.measure_btn)
|
||||
|
||||
self.layout.addStretch()
|
||||
|
||||
# #################################### FINSIHED GUI ###########################
|
||||
# #############################################################################
|
||||
|
||||
def confirmation_message(self, accepted, minval, maxval):
|
||||
if accepted is False:
|
||||
self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"),
|
||||
self.decimals,
|
||||
minval,
|
||||
self.decimals,
|
||||
maxval), False)
|
||||
else:
|
||||
self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
|
||||
|
||||
def confirmation_message_int(self, accepted, minval, maxval):
|
||||
if accepted is False:
|
||||
self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' %
|
||||
(_("Edited value is out of range"), minval, maxval), False)
|
||||
else:
|
||||
self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
|
||||
|
|
|
@ -28,8 +28,6 @@ log = logging.getLogger('base')
|
|||
|
||||
class DistanceMin(AppTool):
|
||||
|
||||
toolName = _("Minimum Distance Tool")
|
||||
|
||||
def __init__(self, app):
|
||||
AppTool.__init__(self, app)
|
||||
|
||||
|
@ -38,7 +36,196 @@ class DistanceMin(AppTool):
|
|||
self.units = self.app.defaults['units'].lower()
|
||||
self.decimals = self.app.decimals
|
||||
|
||||
# ## Title
|
||||
# #############################################################################
|
||||
# ######################### Tool GUI ##########################################
|
||||
# #############################################################################
|
||||
self.ui = DistMinUI(layout=self.layout, app=self.app)
|
||||
self.toolName = self.ui.toolName
|
||||
|
||||
self.h_point = (0, 0)
|
||||
|
||||
self.ui.measure_btn.clicked.connect(self.activate_measure_tool)
|
||||
self.ui.jump_hp_btn.clicked.connect(self.on_jump_to_half_point)
|
||||
|
||||
def run(self, toggle=False):
|
||||
self.app.defaults.report_usage("ToolDistanceMin()")
|
||||
|
||||
if self.app.tool_tab_locked is True:
|
||||
return
|
||||
|
||||
self.app.ui.notebook.setTabText(2, _("Minimum Distance Tool"))
|
||||
|
||||
# if the splitter is hidden, display it
|
||||
if self.app.ui.splitter.sizes()[0] == 0:
|
||||
self.app.ui.splitter.setSizes([1, 1])
|
||||
|
||||
if toggle:
|
||||
pass
|
||||
|
||||
self.set_tool_ui()
|
||||
self.app.inform.emit('MEASURING: %s' %
|
||||
_("Select two objects and no more, to measure the distance between them ..."))
|
||||
|
||||
def install(self, icon=None, separator=None, **kwargs):
|
||||
AppTool.install(self, icon, separator, shortcut='Shift+M', **kwargs)
|
||||
|
||||
def set_tool_ui(self):
|
||||
# Remove anything else in the appGUI
|
||||
self.app.ui.tool_scroll_area.takeWidget()
|
||||
|
||||
# Put oneself in the appGUI
|
||||
self.app.ui.tool_scroll_area.setWidget(self)
|
||||
|
||||
# Switch notebook to tool page
|
||||
self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
|
||||
|
||||
self.units = self.app.defaults['units'].lower()
|
||||
|
||||
# initial view of the layout
|
||||
self.ui.start_entry.set_value('(0, 0)')
|
||||
self.ui.stop_entry.set_value('(0, 0)')
|
||||
|
||||
self.ui.distance_x_entry.set_value('0.0')
|
||||
self.ui.distance_y_entry.set_value('0.0')
|
||||
self.ui.angle_entry.set_value('0.0')
|
||||
self.ui.total_distance_entry.set_value('0.0')
|
||||
self.ui.half_point_entry.set_value('(0, 0)')
|
||||
|
||||
self.ui.jump_hp_btn.setDisabled(True)
|
||||
|
||||
log.debug("Minimum Distance Tool --> tool initialized")
|
||||
|
||||
def activate_measure_tool(self):
|
||||
# ENABLE the Measuring TOOL
|
||||
self.ui.jump_hp_btn.setDisabled(False)
|
||||
|
||||
self.units = self.app.defaults['units'].lower()
|
||||
|
||||
if self.app.call_source == 'app':
|
||||
selected_objs = self.app.collection.get_selected()
|
||||
if len(selected_objs) != 2:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s %s' %
|
||||
(_("Select two objects and no more. Currently the selection has objects: "),
|
||||
str(len(selected_objs))))
|
||||
return
|
||||
else:
|
||||
if isinstance(selected_objs[0].solid_geometry, list):
|
||||
try:
|
||||
selected_objs[0].solid_geometry = MultiPolygon(selected_objs[0].solid_geometry)
|
||||
except Exception:
|
||||
selected_objs[0].solid_geometry = cascaded_union(selected_objs[0].solid_geometry)
|
||||
|
||||
try:
|
||||
selected_objs[1].solid_geometry = MultiPolygon(selected_objs[1].solid_geometry)
|
||||
except Exception:
|
||||
selected_objs[1].solid_geometry = cascaded_union(selected_objs[1].solid_geometry)
|
||||
|
||||
first_pos, last_pos = nearest_points(selected_objs[0].solid_geometry, selected_objs[1].solid_geometry)
|
||||
|
||||
elif self.app.call_source == 'geo_editor':
|
||||
selected_objs = self.app.geo_editor.selected
|
||||
if len(selected_objs) != 2:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s %s' %
|
||||
(_("Select two objects and no more. Currently the selection has objects: "),
|
||||
str(len(selected_objs))))
|
||||
return
|
||||
else:
|
||||
first_pos, last_pos = nearest_points(selected_objs[0].geo, selected_objs[1].geo)
|
||||
elif self.app.call_source == 'exc_editor':
|
||||
selected_objs = self.app.exc_editor.selected
|
||||
if len(selected_objs) != 2:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s %s' %
|
||||
(_("Select two objects and no more. Currently the selection has objects: "),
|
||||
str(len(selected_objs))))
|
||||
return
|
||||
else:
|
||||
# the objects are really MultiLinesStrings made out of 2 lines in cross shape
|
||||
xmin, ymin, xmax, ymax = selected_objs[0].geo.bounds
|
||||
first_geo_radius = (xmax - xmin) / 2
|
||||
first_geo_center = Point(xmin + first_geo_radius, ymin + first_geo_radius)
|
||||
first_geo = first_geo_center.buffer(first_geo_radius)
|
||||
|
||||
# the objects are really MultiLinesStrings made out of 2 lines in cross shape
|
||||
xmin, ymin, xmax, ymax = selected_objs[1].geo.bounds
|
||||
last_geo_radius = (xmax - xmin) / 2
|
||||
last_geo_center = Point(xmin + last_geo_radius, ymin + last_geo_radius)
|
||||
last_geo = last_geo_center.buffer(last_geo_radius)
|
||||
|
||||
first_pos, last_pos = nearest_points(first_geo, last_geo)
|
||||
elif self.app.call_source == 'grb_editor':
|
||||
selected_objs = self.app.grb_editor.selected
|
||||
if len(selected_objs) != 2:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s %s' %
|
||||
(_("Select two objects and no more. Currently the selection has objects: "),
|
||||
str(len(selected_objs))))
|
||||
return
|
||||
else:
|
||||
first_pos, last_pos = nearest_points(selected_objs[0].geo['solid'], selected_objs[1].geo['solid'])
|
||||
else:
|
||||
first_pos, last_pos = 0, 0
|
||||
|
||||
self.ui.start_entry.set_value("(%.*f, %.*f)" % (self.decimals, first_pos.x, self.decimals, first_pos.y))
|
||||
self.ui.stop_entry.set_value("(%.*f, %.*f)" % (self.decimals, last_pos.x, self.decimals, last_pos.y))
|
||||
|
||||
dx = first_pos.x - last_pos.x
|
||||
dy = first_pos.y - last_pos.y
|
||||
|
||||
self.ui.distance_x_entry.set_value('%.*f' % (self.decimals, abs(dx)))
|
||||
self.ui.distance_y_entry.set_value('%.*f' % (self.decimals, abs(dy)))
|
||||
|
||||
try:
|
||||
angle = math.degrees(math.atan(dy / dx))
|
||||
self.ui.angle_entry.set_value('%.*f' % (self.decimals, angle))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
d = math.sqrt(dx ** 2 + dy ** 2)
|
||||
self.ui.total_distance_entry.set_value('%.*f' % (self.decimals, abs(d)))
|
||||
|
||||
self.h_point = (min(first_pos.x, last_pos.x) + (abs(dx) / 2), min(first_pos.y, last_pos.y) + (abs(dy) / 2))
|
||||
if d != 0:
|
||||
self.ui.half_point_entry.set_value(
|
||||
"(%.*f, %.*f)" % (self.decimals, self.h_point[0], self.decimals, self.h_point[1])
|
||||
)
|
||||
else:
|
||||
self.ui.half_point_entry.set_value(
|
||||
"(%.*f, %.*f)" % (self.decimals, 0.0, self.decimals, 0.0)
|
||||
)
|
||||
|
||||
if d != 0:
|
||||
self.app.inform.emit("{tx1}: {tx2} D(x) = {d_x} | D(y) = {d_y} | {tx3} = {d_z}".format(
|
||||
tx1=_("MEASURING"),
|
||||
tx2=_("Result"),
|
||||
tx3=_("Distance"),
|
||||
d_x='%*f' % (self.decimals, abs(dx)),
|
||||
d_y='%*f' % (self.decimals, abs(dy)),
|
||||
d_z='%*f' % (self.decimals, abs(d)))
|
||||
)
|
||||
else:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s: %s' %
|
||||
(_("Objects intersects or touch at"),
|
||||
"(%.*f, %.*f)" % (self.decimals, self.h_point[0], self.decimals, self.h_point[1])))
|
||||
|
||||
def on_jump_to_half_point(self):
|
||||
self.app.on_jump_to(custom_location=self.h_point)
|
||||
self.app.inform.emit('[success] %s: %s' %
|
||||
(_("Jumped to the half point between the two selected objects"),
|
||||
"(%.*f, %.*f)" % (self.decimals, self.h_point[0], self.decimals, self.h_point[1])))
|
||||
|
||||
# def set_meas_units(self, units):
|
||||
# self.meas.units_label.setText("[" + self.app.options["units"].lower() + "]")
|
||||
|
||||
|
||||
class DistMinUI:
|
||||
|
||||
toolName = _("Minimum Distance Tool")
|
||||
|
||||
def __init__(self, layout, app):
|
||||
self.app = app
|
||||
self.decimals = self.app.decimals
|
||||
self.layout = layout
|
||||
|
||||
# ## Title
|
||||
title_label = QtWidgets.QLabel("<font size=4><b>%s</b></font><br>" % self.toolName)
|
||||
self.layout.addWidget(title_label)
|
||||
|
||||
|
@ -57,7 +244,7 @@ class DistanceMin(AppTool):
|
|||
|
||||
self.stop_label = QtWidgets.QLabel("%s:" % _('Second object point'))
|
||||
self.stop_label.setToolTip(_("This is second object point coordinates.\n"
|
||||
"This is the end point for measuring distance."))
|
||||
"This is the end point for measuring distance."))
|
||||
|
||||
self.distance_x_label = QtWidgets.QLabel('%s:' % _("Dx"))
|
||||
self.distance_x_label.setToolTip(_("This is the distance measured over the X axis."))
|
||||
|
@ -84,7 +271,7 @@ class DistanceMin(AppTool):
|
|||
self.stop_entry.setReadOnly(True)
|
||||
self.stop_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
self.stop_entry.setToolTip(_("This is second object point coordinates.\n"
|
||||
"This is the end point for measuring distance."))
|
||||
"This is the end point for measuring distance."))
|
||||
|
||||
self.distance_x_entry = FCEntry()
|
||||
self.distance_x_entry.setReadOnly(True)
|
||||
|
@ -128,178 +315,22 @@ class DistanceMin(AppTool):
|
|||
form_layout.addRow(self.half_point_label, self.half_point_entry)
|
||||
|
||||
self.layout.addStretch()
|
||||
# #################################### FINSIHED GUI ###########################
|
||||
# #############################################################################
|
||||
|
||||
self.h_point = (0, 0)
|
||||
|
||||
self.measure_btn.clicked.connect(self.activate_measure_tool)
|
||||
self.jump_hp_btn.clicked.connect(self.on_jump_to_half_point)
|
||||
|
||||
def run(self, toggle=False):
|
||||
self.app.defaults.report_usage("ToolDistanceMin()")
|
||||
|
||||
if self.app.tool_tab_locked is True:
|
||||
return
|
||||
|
||||
self.app.ui.notebook.setTabText(2, _("Minimum Distance Tool"))
|
||||
|
||||
# if the splitter is hidden, display it
|
||||
if self.app.ui.splitter.sizes()[0] == 0:
|
||||
self.app.ui.splitter.setSizes([1, 1])
|
||||
|
||||
if toggle:
|
||||
pass
|
||||
|
||||
self.set_tool_ui()
|
||||
self.app.inform.emit('MEASURING: %s' %
|
||||
_("Select two objects and no more, to measure the distance between them ..."))
|
||||
|
||||
def install(self, icon=None, separator=None, **kwargs):
|
||||
AppTool.install(self, icon, separator, shortcut='Shift+M', **kwargs)
|
||||
|
||||
def set_tool_ui(self):
|
||||
# Remove anything else in the appGUI
|
||||
self.app.ui.tool_scroll_area.takeWidget()
|
||||
|
||||
# Put oneself in the appGUI
|
||||
self.app.ui.tool_scroll_area.setWidget(self)
|
||||
|
||||
# Switch notebook to tool page
|
||||
self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
|
||||
|
||||
self.units = self.app.defaults['units'].lower()
|
||||
|
||||
# initial view of the layout
|
||||
self.start_entry.set_value('(0, 0)')
|
||||
self.stop_entry.set_value('(0, 0)')
|
||||
|
||||
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')
|
||||
self.half_point_entry.set_value('(0, 0)')
|
||||
|
||||
self.jump_hp_btn.setDisabled(True)
|
||||
|
||||
log.debug("Minimum Distance Tool --> tool initialized")
|
||||
|
||||
def activate_measure_tool(self):
|
||||
# ENABLE the Measuring TOOL
|
||||
self.jump_hp_btn.setDisabled(False)
|
||||
|
||||
self.units = self.app.defaults['units'].lower()
|
||||
|
||||
if self.app.call_source == 'app':
|
||||
selected_objs = self.app.collection.get_selected()
|
||||
if len(selected_objs) != 2:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s %s' %
|
||||
(_("Select two objects and no more. Currently the selection has objects: "),
|
||||
str(len(selected_objs))))
|
||||
return
|
||||
else:
|
||||
if isinstance(selected_objs[0].solid_geometry, list):
|
||||
try:
|
||||
selected_objs[0].solid_geometry = MultiPolygon(selected_objs[0].solid_geometry)
|
||||
except Exception:
|
||||
selected_objs[0].solid_geometry = cascaded_union(selected_objs[0].solid_geometry)
|
||||
|
||||
try:
|
||||
selected_objs[1].solid_geometry = MultiPolygon(selected_objs[1].solid_geometry)
|
||||
except Exception:
|
||||
selected_objs[1].solid_geometry = cascaded_union(selected_objs[1].solid_geometry)
|
||||
|
||||
first_pos, last_pos = nearest_points(selected_objs[0].solid_geometry, selected_objs[1].solid_geometry)
|
||||
|
||||
elif self.app.call_source == 'geo_editor':
|
||||
selected_objs = self.app.geo_editor.selected
|
||||
if len(selected_objs) != 2:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s %s' %
|
||||
(_("Select two objects and no more. Currently the selection has objects: "),
|
||||
str(len(selected_objs))))
|
||||
return
|
||||
else:
|
||||
first_pos, last_pos = nearest_points(selected_objs[0].geo, selected_objs[1].geo)
|
||||
elif self.app.call_source == 'exc_editor':
|
||||
selected_objs = self.app.exc_editor.selected
|
||||
if len(selected_objs) != 2:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s %s' %
|
||||
(_("Select two objects and no more. Currently the selection has objects: "),
|
||||
str(len(selected_objs))))
|
||||
return
|
||||
else:
|
||||
# the objects are really MultiLinesStrings made out of 2 lines in cross shape
|
||||
xmin, ymin, xmax, ymax = selected_objs[0].geo.bounds
|
||||
first_geo_radius = (xmax - xmin) / 2
|
||||
first_geo_center = Point(xmin + first_geo_radius, ymin + first_geo_radius)
|
||||
first_geo = first_geo_center.buffer(first_geo_radius)
|
||||
|
||||
# the objects are really MultiLinesStrings made out of 2 lines in cross shape
|
||||
xmin, ymin, xmax, ymax = selected_objs[1].geo.bounds
|
||||
last_geo_radius = (xmax - xmin) / 2
|
||||
last_geo_center = Point(xmin + last_geo_radius, ymin + last_geo_radius)
|
||||
last_geo = last_geo_center.buffer(last_geo_radius)
|
||||
|
||||
first_pos, last_pos = nearest_points(first_geo, last_geo)
|
||||
elif self.app.call_source == 'grb_editor':
|
||||
selected_objs = self.app.grb_editor.selected
|
||||
if len(selected_objs) != 2:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s %s' %
|
||||
(_("Select two objects and no more. Currently the selection has objects: "),
|
||||
str(len(selected_objs))))
|
||||
return
|
||||
else:
|
||||
first_pos, last_pos = nearest_points(selected_objs[0].geo['solid'], selected_objs[1].geo['solid'])
|
||||
def confirmation_message(self, accepted, minval, maxval):
|
||||
if accepted is False:
|
||||
self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"),
|
||||
self.decimals,
|
||||
minval,
|
||||
self.decimals,
|
||||
maxval), False)
|
||||
else:
|
||||
first_pos, last_pos = 0, 0
|
||||
self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
|
||||
|
||||
self.start_entry.set_value("(%.*f, %.*f)" % (self.decimals, first_pos.x, self.decimals, first_pos.y))
|
||||
self.stop_entry.set_value("(%.*f, %.*f)" % (self.decimals, last_pos.x, self.decimals, last_pos.y))
|
||||
|
||||
dx = first_pos.x - last_pos.x
|
||||
dy = first_pos.y - last_pos.y
|
||||
|
||||
self.distance_x_entry.set_value('%.*f' % (self.decimals, abs(dx)))
|
||||
self.distance_y_entry.set_value('%.*f' % (self.decimals, abs(dy)))
|
||||
|
||||
try:
|
||||
angle = math.degrees(math.atan(dy / dx))
|
||||
self.angle_entry.set_value('%.*f' % (self.decimals, angle))
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
d = math.sqrt(dx ** 2 + dy ** 2)
|
||||
self.total_distance_entry.set_value('%.*f' % (self.decimals, abs(d)))
|
||||
|
||||
self.h_point = (min(first_pos.x, last_pos.x) + (abs(dx) / 2), min(first_pos.y, last_pos.y) + (abs(dy) / 2))
|
||||
if d != 0:
|
||||
self.half_point_entry.set_value(
|
||||
"(%.*f, %.*f)" % (self.decimals, self.h_point[0], self.decimals, self.h_point[1])
|
||||
)
|
||||
def confirmation_message_int(self, accepted, minval, maxval):
|
||||
if accepted is False:
|
||||
self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' %
|
||||
(_("Edited value is out of range"), minval, maxval), False)
|
||||
else:
|
||||
self.half_point_entry.set_value(
|
||||
"(%.*f, %.*f)" % (self.decimals, 0.0, self.decimals, 0.0)
|
||||
)
|
||||
|
||||
if d != 0:
|
||||
self.app.inform.emit("{tx1}: {tx2} D(x) = {d_x} | D(y) = {d_y} | {tx3} = {d_z}".format(
|
||||
tx1=_("MEASURING"),
|
||||
tx2=_("Result"),
|
||||
tx3=_("Distance"),
|
||||
d_x='%*f' % (self.decimals, abs(dx)),
|
||||
d_y='%*f' % (self.decimals, abs(dy)),
|
||||
d_z='%*f' % (self.decimals, abs(d)))
|
||||
)
|
||||
else:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s: %s' %
|
||||
(_("Objects intersects or touch at"),
|
||||
"(%.*f, %.*f)" % (self.decimals, self.h_point[0], self.decimals, self.h_point[1])))
|
||||
|
||||
def on_jump_to_half_point(self):
|
||||
self.app.on_jump_to(custom_location=self.h_point)
|
||||
self.app.inform.emit('[success] %s: %s' %
|
||||
(_("Jumped to the half point between the two selected objects"),
|
||||
"(%.*f, %.*f)" % (self.decimals, self.h_point[0], self.decimals, self.h_point[1])))
|
||||
|
||||
def set_meas_units(self, units):
|
||||
self.meas.units_label.setText("[" + self.app.options["units"].lower() + "]")
|
||||
|
||||
# end of file
|
||||
self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -37,159 +37,17 @@ class ToolSub(AppTool):
|
|||
# meaning geometry that was deformed
|
||||
aperture_processing_finished = QtCore.pyqtSignal(str, list)
|
||||
|
||||
toolName = _("Subtract Tool")
|
||||
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.decimals = self.app.decimals
|
||||
|
||||
AppTool.__init__(self, app)
|
||||
|
||||
self.tools_frame = QtWidgets.QFrame()
|
||||
self.tools_frame.setContentsMargins(0, 0, 0, 0)
|
||||
self.layout.addWidget(self.tools_frame)
|
||||
self.tools_box = QtWidgets.QVBoxLayout()
|
||||
self.tools_box.setContentsMargins(0, 0, 0, 0)
|
||||
self.tools_frame.setLayout(self.tools_box)
|
||||
|
||||
# Title
|
||||
title_label = QtWidgets.QLabel("%s" % self.toolName)
|
||||
title_label.setStyleSheet("""
|
||||
QLabel
|
||||
{
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.tools_box.addWidget(title_label)
|
||||
|
||||
# Form Layout
|
||||
form_layout = QtWidgets.QFormLayout()
|
||||
self.tools_box.addLayout(form_layout)
|
||||
|
||||
self.gerber_title = QtWidgets.QLabel("<b>%s</b>" % _("GERBER"))
|
||||
form_layout.addRow(self.gerber_title)
|
||||
|
||||
# Target Gerber Object
|
||||
self.target_gerber_combo = FCComboBox()
|
||||
self.target_gerber_combo.setModel(self.app.collection)
|
||||
self.target_gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
# self.target_gerber_combo.setCurrentIndex(1)
|
||||
self.target_gerber_combo.is_last = True
|
||||
self.target_gerber_combo.obj_type = "Gerber"
|
||||
|
||||
self.target_gerber_label = QtWidgets.QLabel('%s:' % _("Target"))
|
||||
self.target_gerber_label.setToolTip(
|
||||
_("Gerber object from which to subtract\n"
|
||||
"the subtractor Gerber object.")
|
||||
)
|
||||
|
||||
form_layout.addRow(self.target_gerber_label, self.target_gerber_combo)
|
||||
|
||||
# Substractor Gerber Object
|
||||
self.sub_gerber_combo = FCComboBox()
|
||||
self.sub_gerber_combo.setModel(self.app.collection)
|
||||
self.sub_gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.sub_gerber_combo.is_last = True
|
||||
self.sub_gerber_combo.obj_type = "Gerber"
|
||||
|
||||
self.sub_gerber_label = QtWidgets.QLabel('%s:' % _("Subtractor"))
|
||||
self.sub_gerber_label.setToolTip(
|
||||
_("Gerber object that will be subtracted\n"
|
||||
"from the target Gerber object.")
|
||||
)
|
||||
e_lab_1 = QtWidgets.QLabel('')
|
||||
|
||||
form_layout.addRow(self.sub_gerber_label, self.sub_gerber_combo)
|
||||
|
||||
self.intersect_btn = FCButton(_('Subtract Gerber'))
|
||||
self.intersect_btn.setToolTip(
|
||||
_("Will remove the area occupied by the subtractor\n"
|
||||
"Gerber from the Target Gerber.\n"
|
||||
"Can be used to remove the overlapping silkscreen\n"
|
||||
"over the soldermask.")
|
||||
)
|
||||
self.intersect_btn.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.tools_box.addWidget(self.intersect_btn)
|
||||
self.tools_box.addWidget(e_lab_1)
|
||||
|
||||
# Form Layout
|
||||
form_geo_layout = QtWidgets.QFormLayout()
|
||||
self.tools_box.addLayout(form_geo_layout)
|
||||
|
||||
self.geo_title = QtWidgets.QLabel("<b>%s</b>" % _("GEOMETRY"))
|
||||
form_geo_layout.addRow(self.geo_title)
|
||||
|
||||
# Target Geometry Object
|
||||
self.target_geo_combo = FCComboBox()
|
||||
self.target_geo_combo.setModel(self.app.collection)
|
||||
self.target_geo_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
|
||||
# self.target_geo_combo.setCurrentIndex(1)
|
||||
self.target_geo_combo.is_last = True
|
||||
self.target_geo_combo.obj_type = "Geometry"
|
||||
|
||||
self.target_geo_label = QtWidgets.QLabel('%s:' % _("Target"))
|
||||
self.target_geo_label.setToolTip(
|
||||
_("Geometry object from which to subtract\n"
|
||||
"the subtractor Geometry object.")
|
||||
)
|
||||
|
||||
form_geo_layout.addRow(self.target_geo_label, self.target_geo_combo)
|
||||
|
||||
# Substractor Geometry Object
|
||||
self.sub_geo_combo = FCComboBox()
|
||||
self.sub_geo_combo.setModel(self.app.collection)
|
||||
self.sub_geo_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
|
||||
self.sub_geo_combo.is_last = True
|
||||
self.sub_geo_combo.obj_type = "Geometry"
|
||||
|
||||
self.sub_geo_label = QtWidgets.QLabel('%s:' % _("Subtractor"))
|
||||
self.sub_geo_label.setToolTip(
|
||||
_("Geometry object that will be subtracted\n"
|
||||
"from the target Geometry object.")
|
||||
)
|
||||
e_lab_1 = QtWidgets.QLabel('')
|
||||
|
||||
form_geo_layout.addRow(self.sub_geo_label, self.sub_geo_combo)
|
||||
|
||||
self.close_paths_cb = FCCheckBox(_("Close paths"))
|
||||
self.close_paths_cb.setToolTip(_("Checking this will close the paths cut by the Geometry subtractor object."))
|
||||
self.tools_box.addWidget(self.close_paths_cb)
|
||||
|
||||
self.intersect_geo_btn = FCButton(_('Subtract Geometry'))
|
||||
self.intersect_geo_btn.setToolTip(
|
||||
_("Will remove the area occupied by the subtractor\n"
|
||||
"Geometry from the Target Geometry.")
|
||||
)
|
||||
self.intersect_geo_btn.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.tools_box.addWidget(self.intersect_geo_btn)
|
||||
self.tools_box.addWidget(e_lab_1)
|
||||
|
||||
self.tools_box.addStretch()
|
||||
|
||||
# ## Reset Tool
|
||||
self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
|
||||
self.reset_button.setIcon(QtGui.QIcon(self.app.resource_location + '/reset32.png'))
|
||||
self.reset_button.setToolTip(
|
||||
_("Will reset the tool parameters.")
|
||||
)
|
||||
self.reset_button.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.tools_box.addWidget(self.reset_button)
|
||||
# #############################################################################
|
||||
# ######################### Tool GUI ##########################################
|
||||
# #############################################################################
|
||||
self.ui = SubUI(layout=self.layout, app=self.app)
|
||||
self.toolName = self.ui.toolName
|
||||
|
||||
# QTimer for periodic check
|
||||
self.check_thread = QtCore.QTimer()
|
||||
|
@ -228,11 +86,14 @@ class ToolSub(AppTool):
|
|||
self.pool = self.app.pool
|
||||
self.results = []
|
||||
|
||||
self.intersect_btn.clicked.connect(self.on_grb_intersection_click)
|
||||
self.intersect_geo_btn.clicked.connect(self.on_geo_intersection_click)
|
||||
# Signals
|
||||
self.ui.intersect_btn.clicked.connect(self.on_grb_intersection_click)
|
||||
self.ui.intersect_geo_btn.clicked.connect(self.on_geo_intersection_click)
|
||||
self.ui.reset_button.clicked.connect(self.set_tool_ui)
|
||||
|
||||
# Custom Signals
|
||||
self.job_finished.connect(self.on_job_finished)
|
||||
self.aperture_processing_finished.connect(self.new_gerber_object)
|
||||
self.reset_button.clicked.connect(self.set_tool_ui)
|
||||
|
||||
def install(self, icon=None, separator=None, **kwargs):
|
||||
AppTool.install(self, icon, separator, shortcut='Alt+W', **kwargs)
|
||||
|
@ -270,8 +131,8 @@ class ToolSub(AppTool):
|
|||
self.new_solid_geometry = []
|
||||
self.target_options.clear()
|
||||
|
||||
self.tools_frame.show()
|
||||
self.close_paths_cb.setChecked(self.app.defaults["tools_sub_close_paths"])
|
||||
self.ui.tools_frame.show()
|
||||
self.ui.close_paths_cb.setChecked(self.app.defaults["tools_sub_close_paths"])
|
||||
|
||||
def on_grb_intersection_click(self):
|
||||
# reset previous values
|
||||
|
@ -281,7 +142,7 @@ class ToolSub(AppTool):
|
|||
|
||||
self.sub_type = "gerber"
|
||||
|
||||
self.target_grb_obj_name = self.target_gerber_combo.currentText()
|
||||
self.target_grb_obj_name = self.ui.target_gerber_combo.currentText()
|
||||
if self.target_grb_obj_name == '':
|
||||
self.app.inform.emit('[ERROR_NOTCL] %s' % _("No Target object loaded."))
|
||||
return
|
||||
|
@ -296,7 +157,7 @@ class ToolSub(AppTool):
|
|||
self.app.inform.emit('[ERROR_NOTCL] %s: %s' % (_("Could not retrieve object"), self.obj_name))
|
||||
return "Could not retrieve object: %s" % self.target_grb_obj_name
|
||||
|
||||
self.sub_grb_obj_name = self.sub_gerber_combo.currentText()
|
||||
self.sub_grb_obj_name = self.ui.sub_gerber_combo.currentText()
|
||||
if self.sub_grb_obj_name == '':
|
||||
self.app.inform.emit('[ERROR_NOTCL] %s' % _("No Subtractor object loaded."))
|
||||
return
|
||||
|
@ -485,10 +346,9 @@ class ToolSub(AppTool):
|
|||
|
||||
self.sub_type = "geo"
|
||||
|
||||
self.target_geo_obj_name = self.target_geo_combo.currentText()
|
||||
self.target_geo_obj_name = self.ui.target_geo_combo.currentText()
|
||||
if self.target_geo_obj_name == '':
|
||||
self.app.inform.emit('[ERROR_NOTCL] %s' %
|
||||
_("No Target object loaded."))
|
||||
self.app.inform.emit('[ERROR_NOTCL] %s' % _("No Target object loaded."))
|
||||
return
|
||||
|
||||
# Get target object.
|
||||
|
@ -496,14 +356,12 @@ class ToolSub(AppTool):
|
|||
self.target_geo_obj = self.app.collection.get_by_name(self.target_geo_obj_name)
|
||||
except Exception as e:
|
||||
log.debug("ToolSub.on_geo_intersection_click() --> %s" % str(e))
|
||||
self.app.inform.emit('[ERROR_NOTCL] %s: %s' %
|
||||
(_("Could not retrieve object"), self.target_geo_obj_name))
|
||||
self.app.inform.emit('[ERROR_NOTCL] %s: %s' % (_("Could not retrieve object"), self.target_geo_obj_name))
|
||||
return "Could not retrieve object: %s" % self.target_grb_obj_name
|
||||
|
||||
self.sub_geo_obj_name = self.sub_geo_combo.currentText()
|
||||
self.sub_geo_obj_name = self.ui.sub_geo_combo.currentText()
|
||||
if self.sub_geo_obj_name == '':
|
||||
self.app.inform.emit('[ERROR_NOTCL] %s' %
|
||||
_("No Subtractor object loaded."))
|
||||
self.app.inform.emit('[ERROR_NOTCL] %s' % _("No Subtractor object loaded."))
|
||||
return
|
||||
|
||||
# Get substractor object.
|
||||
|
@ -511,8 +369,7 @@ class ToolSub(AppTool):
|
|||
self.sub_geo_obj = self.app.collection.get_by_name(self.sub_geo_obj_name)
|
||||
except Exception as e:
|
||||
log.debug("ToolSub.on_geo_intersection_click() --> %s" % str(e))
|
||||
self.app.inform.emit('[ERROR_NOTCL] %s: %s' %
|
||||
(_("Could not retrieve object"), self.sub_geo_obj_name))
|
||||
self.app.inform.emit('[ERROR_NOTCL] %s: %s' % (_("Could not retrieve object"), self.sub_geo_obj_name))
|
||||
return "Could not retrieve object: %s" % self.sub_geo_obj_name
|
||||
|
||||
if self.sub_geo_obj.multigeo:
|
||||
|
@ -529,11 +386,8 @@ class ToolSub(AppTool):
|
|||
# crate the new_tools dict structure
|
||||
for tool in self.target_geo_obj.tools:
|
||||
self.new_tools[tool] = {}
|
||||
for key in self.target_geo_obj.tools[tool]:
|
||||
if key == 'solid_geometry':
|
||||
self.new_tools[tool][key] = []
|
||||
else:
|
||||
self.new_tools[tool][key] = deepcopy(self.target_geo_obj.tools[tool][key])
|
||||
for key, v in self.target_geo_obj.tools[tool]:
|
||||
self.new_tools[tool][key] = [] if key == 'solid_geometry' else deepcopy(v)
|
||||
|
||||
# add the promises
|
||||
if self.target_geo_obj.multigeo:
|
||||
|
@ -550,12 +404,10 @@ class ToolSub(AppTool):
|
|||
if self.target_geo_obj.multigeo:
|
||||
for tool in self.target_geo_obj.tools:
|
||||
geo = self.target_geo_obj.tools[tool]['solid_geometry']
|
||||
self.app.worker_task.emit({'fcn': self.toolgeo_intersection,
|
||||
'params': [tool, geo]})
|
||||
self.app.worker_task.emit({'fcn': self.toolgeo_intersection, 'params': [tool, geo]})
|
||||
else:
|
||||
geo = self.target_geo_obj.solid_geometry
|
||||
self.app.worker_task.emit({'fcn': self.toolgeo_intersection,
|
||||
'params': ["single", geo]})
|
||||
self.app.worker_task.emit({'fcn': self.toolgeo_intersection, 'params': ["single", geo]})
|
||||
|
||||
def toolgeo_intersection(self, tool, geo):
|
||||
new_geometry = []
|
||||
|
@ -568,7 +420,7 @@ class ToolSub(AppTool):
|
|||
|
||||
with self.app.proc_container.new(text):
|
||||
# resulting paths are closed resulting into Polygons
|
||||
if self.close_paths_cb.isChecked():
|
||||
if self.ui.close_paths_cb.isChecked():
|
||||
new_geo = (cascaded_union(geo)).difference(self.sub_union)
|
||||
if new_geo:
|
||||
if not new_geo.is_empty:
|
||||
|
@ -663,14 +515,12 @@ class ToolSub(AppTool):
|
|||
with self.app.proc_container.new(_("Generating new object ...")):
|
||||
ret = self.app.app_obj.new_object('geometry', outname, obj_init, autoselected=False)
|
||||
if ret == 'fail':
|
||||
self.app.inform.emit('[ERROR_NOTCL] %s' %
|
||||
_('Generating new object failed.'))
|
||||
self.app.inform.emit('[ERROR_NOTCL] %s' % _('Generating new object failed.'))
|
||||
return
|
||||
# Register recent file
|
||||
self.app.file_opened.emit('geometry', outname)
|
||||
# GUI feedback
|
||||
self.app.inform.emit('[success] %s: %s' %
|
||||
(_("Created"), outname))
|
||||
self.app.inform.emit('[success] %s: %s' % (_("Created"), outname))
|
||||
|
||||
# cleanup
|
||||
self.new_tools.clear()
|
||||
|
@ -732,13 +582,12 @@ class ToolSub(AppTool):
|
|||
"""
|
||||
if succcess is True:
|
||||
if self.sub_type == "gerber":
|
||||
outname = self.target_gerber_combo.currentText() + '_sub'
|
||||
outname = self.ui.target_gerber_combo.currentText() + '_sub'
|
||||
|
||||
# intersection jobs finished, start the creation of solid_geometry
|
||||
self.app.worker_task.emit({'fcn': self.new_gerber_object,
|
||||
'params': [outname]})
|
||||
self.app.worker_task.emit({'fcn': self.new_gerber_object, 'params': [outname]})
|
||||
else:
|
||||
outname = self.target_geo_combo.currentText() + '_sub'
|
||||
outname = self.ui.target_geo_combo.currentText() + '_sub'
|
||||
|
||||
# intersection jobs finished, start the creation of solid_geometry
|
||||
self.app.worker_task.emit({'fcn': self.new_geo_object, 'params': [outname]})
|
||||
|
@ -746,13 +595,189 @@ class ToolSub(AppTool):
|
|||
self.app.inform.emit('[ERROR_NOTCL] %s' % _('Generating new object failed.'))
|
||||
|
||||
def reset_fields(self):
|
||||
self.target_gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.sub_gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.ui.target_gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.ui.sub_gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
|
||||
self.target_geo_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
|
||||
self.sub_geo_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
|
||||
self.ui.target_geo_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
|
||||
self.ui.sub_geo_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
|
||||
|
||||
@staticmethod
|
||||
def poly2rings(poly):
|
||||
return [poly.exterior] + [interior for interior in poly.interiors]
|
||||
# end of file
|
||||
|
||||
|
||||
class SubUI:
|
||||
|
||||
toolName = _("Subtract Tool")
|
||||
|
||||
def __init__(self, layout, app):
|
||||
self.app = app
|
||||
self.decimals = self.app.decimals
|
||||
self.layout = layout
|
||||
|
||||
# ## Title
|
||||
title_label = QtWidgets.QLabel("%s" % self.toolName)
|
||||
title_label.setStyleSheet("""
|
||||
QLabel
|
||||
{
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.layout.addWidget(title_label)
|
||||
self.layout.addWidget(QtWidgets.QLabel(""))
|
||||
|
||||
self.tools_frame = QtWidgets.QFrame()
|
||||
self.tools_frame.setContentsMargins(0, 0, 0, 0)
|
||||
self.layout.addWidget(self.tools_frame)
|
||||
self.tools_box = QtWidgets.QVBoxLayout()
|
||||
self.tools_box.setContentsMargins(0, 0, 0, 0)
|
||||
self.tools_frame.setLayout(self.tools_box)
|
||||
|
||||
# Form Layout
|
||||
form_layout = QtWidgets.QFormLayout()
|
||||
self.tools_box.addLayout(form_layout)
|
||||
|
||||
self.gerber_title = QtWidgets.QLabel("<b>%s</b>" % _("GERBER"))
|
||||
form_layout.addRow(self.gerber_title)
|
||||
|
||||
# Target Gerber Object
|
||||
self.target_gerber_combo = FCComboBox()
|
||||
self.target_gerber_combo.setModel(self.app.collection)
|
||||
self.target_gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
# self.target_gerber_combo.setCurrentIndex(1)
|
||||
self.target_gerber_combo.is_last = True
|
||||
self.target_gerber_combo.obj_type = "Gerber"
|
||||
|
||||
self.target_gerber_label = QtWidgets.QLabel('%s:' % _("Target"))
|
||||
self.target_gerber_label.setToolTip(
|
||||
_("Gerber object from which to subtract\n"
|
||||
"the subtractor Gerber object.")
|
||||
)
|
||||
|
||||
form_layout.addRow(self.target_gerber_label, self.target_gerber_combo)
|
||||
|
||||
# Substractor Gerber Object
|
||||
self.sub_gerber_combo = FCComboBox()
|
||||
self.sub_gerber_combo.setModel(self.app.collection)
|
||||
self.sub_gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.sub_gerber_combo.is_last = True
|
||||
self.sub_gerber_combo.obj_type = "Gerber"
|
||||
|
||||
self.sub_gerber_label = QtWidgets.QLabel('%s:' % _("Subtractor"))
|
||||
self.sub_gerber_label.setToolTip(
|
||||
_("Gerber object that will be subtracted\n"
|
||||
"from the target Gerber object.")
|
||||
)
|
||||
e_lab_1 = QtWidgets.QLabel('')
|
||||
|
||||
form_layout.addRow(self.sub_gerber_label, self.sub_gerber_combo)
|
||||
|
||||
self.intersect_btn = FCButton(_('Subtract Gerber'))
|
||||
self.intersect_btn.setToolTip(
|
||||
_("Will remove the area occupied by the subtractor\n"
|
||||
"Gerber from the Target Gerber.\n"
|
||||
"Can be used to remove the overlapping silkscreen\n"
|
||||
"over the soldermask.")
|
||||
)
|
||||
self.intersect_btn.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.tools_box.addWidget(self.intersect_btn)
|
||||
self.tools_box.addWidget(e_lab_1)
|
||||
|
||||
# Form Layout
|
||||
form_geo_layout = QtWidgets.QFormLayout()
|
||||
self.tools_box.addLayout(form_geo_layout)
|
||||
|
||||
self.geo_title = QtWidgets.QLabel("<b>%s</b>" % _("GEOMETRY"))
|
||||
form_geo_layout.addRow(self.geo_title)
|
||||
|
||||
# Target Geometry Object
|
||||
self.target_geo_combo = FCComboBox()
|
||||
self.target_geo_combo.setModel(self.app.collection)
|
||||
self.target_geo_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
|
||||
# self.target_geo_combo.setCurrentIndex(1)
|
||||
self.target_geo_combo.is_last = True
|
||||
self.target_geo_combo.obj_type = "Geometry"
|
||||
|
||||
self.target_geo_label = QtWidgets.QLabel('%s:' % _("Target"))
|
||||
self.target_geo_label.setToolTip(
|
||||
_("Geometry object from which to subtract\n"
|
||||
"the subtractor Geometry object.")
|
||||
)
|
||||
|
||||
form_geo_layout.addRow(self.target_geo_label, self.target_geo_combo)
|
||||
|
||||
# Substractor Geometry Object
|
||||
self.sub_geo_combo = FCComboBox()
|
||||
self.sub_geo_combo.setModel(self.app.collection)
|
||||
self.sub_geo_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
|
||||
self.sub_geo_combo.is_last = True
|
||||
self.sub_geo_combo.obj_type = "Geometry"
|
||||
|
||||
self.sub_geo_label = QtWidgets.QLabel('%s:' % _("Subtractor"))
|
||||
self.sub_geo_label.setToolTip(
|
||||
_("Geometry object that will be subtracted\n"
|
||||
"from the target Geometry object.")
|
||||
)
|
||||
e_lab_1 = QtWidgets.QLabel('')
|
||||
|
||||
form_geo_layout.addRow(self.sub_geo_label, self.sub_geo_combo)
|
||||
|
||||
self.close_paths_cb = FCCheckBox(_("Close paths"))
|
||||
self.close_paths_cb.setToolTip(_("Checking this will close the paths cut by the Geometry subtractor object."))
|
||||
self.tools_box.addWidget(self.close_paths_cb)
|
||||
|
||||
self.intersect_geo_btn = FCButton(_('Subtract Geometry'))
|
||||
self.intersect_geo_btn.setToolTip(
|
||||
_("Will remove the area occupied by the subtractor\n"
|
||||
"Geometry from the Target Geometry.")
|
||||
)
|
||||
self.intersect_geo_btn.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.tools_box.addWidget(self.intersect_geo_btn)
|
||||
self.tools_box.addWidget(e_lab_1)
|
||||
|
||||
self.tools_box.addStretch()
|
||||
|
||||
# ## Reset Tool
|
||||
self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
|
||||
self.reset_button.setIcon(QtGui.QIcon(self.app.resource_location + '/reset32.png'))
|
||||
self.reset_button.setToolTip(
|
||||
_("Will reset the tool parameters.")
|
||||
)
|
||||
self.reset_button.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.tools_box.addWidget(self.reset_button)
|
||||
|
||||
# #################################### FINSIHED GUI ###########################
|
||||
# #############################################################################
|
||||
|
||||
def confirmation_message(self, accepted, minval, maxval):
|
||||
if accepted is False:
|
||||
self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"),
|
||||
self.decimals,
|
||||
minval,
|
||||
self.decimals,
|
||||
maxval), False)
|
||||
else:
|
||||
self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
|
||||
|
||||
def confirmation_message_int(self, accepted, minval, maxval):
|
||||
if accepted is False:
|
||||
self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' %
|
||||
(_("Edited value is out of range"), minval, maxval), False)
|
||||
else:
|
||||
self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue