- for Tools: Calculators, Calibration, Copper Thieving, Corners, Fiducials - moved the Tool UI in its own class
This commit is contained in:
@@ -28,8 +28,6 @@ log = logging.getLogger('base')
|
||||
|
||||
class ToolCorners(AppTool):
|
||||
|
||||
toolName = _("Corner Markers Tool")
|
||||
|
||||
def __init__(self, app):
|
||||
AppTool.__init__(self, app)
|
||||
|
||||
@@ -39,158 +37,11 @@ class ToolCorners(AppTool):
|
||||
self.decimals = self.app.decimals
|
||||
self.units = ''
|
||||
|
||||
# ## 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(''))
|
||||
|
||||
# Gerber object #
|
||||
self.object_label = QtWidgets.QLabel('<b>%s:</b>' % _("GERBER"))
|
||||
self.object_label.setToolTip(
|
||||
_("The Gerber object to which will be added corner markers.")
|
||||
)
|
||||
self.object_combo = FCComboBox()
|
||||
self.object_combo.setModel(self.app.collection)
|
||||
self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.object_combo.is_last = True
|
||||
self.object_combo.obj_type = "Gerber"
|
||||
|
||||
self.layout.addWidget(self.object_label)
|
||||
self.layout.addWidget(self.object_combo)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
self.layout.addWidget(separator_line)
|
||||
|
||||
self.points_label = QtWidgets.QLabel('<b>%s:</b>' % _('Locations'))
|
||||
self.points_label.setToolTip(
|
||||
_("Locations where to place corner markers.")
|
||||
)
|
||||
self.layout.addWidget(self.points_label)
|
||||
|
||||
# BOTTOM LEFT
|
||||
self.bl_cb = FCCheckBox(_("Bottom Left"))
|
||||
self.layout.addWidget(self.bl_cb)
|
||||
|
||||
# BOTTOM RIGHT
|
||||
self.br_cb = FCCheckBox(_("Bottom Right"))
|
||||
self.layout.addWidget(self.br_cb)
|
||||
|
||||
# TOP LEFT
|
||||
self.tl_cb = FCCheckBox(_("Top Left"))
|
||||
self.layout.addWidget(self.tl_cb)
|
||||
|
||||
# TOP RIGHT
|
||||
self.tr_cb = FCCheckBox(_("Top Right"))
|
||||
self.layout.addWidget(self.tr_cb)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
self.layout.addWidget(separator_line)
|
||||
|
||||
# Toggle ALL
|
||||
self.toggle_all_cb = FCCheckBox(_("Toggle ALL"))
|
||||
self.layout.addWidget(self.toggle_all_cb)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
self.layout.addWidget(separator_line)
|
||||
|
||||
# ## Grid Layout
|
||||
grid_lay = QtWidgets.QGridLayout()
|
||||
self.layout.addLayout(grid_lay)
|
||||
grid_lay.setColumnStretch(0, 0)
|
||||
grid_lay.setColumnStretch(1, 1)
|
||||
|
||||
self.param_label = QtWidgets.QLabel('<b>%s:</b>' % _('Parameters'))
|
||||
self.param_label.setToolTip(
|
||||
_("Parameters used for this tool.")
|
||||
)
|
||||
grid_lay.addWidget(self.param_label, 0, 0, 1, 2)
|
||||
|
||||
# Thickness #
|
||||
self.thick_label = QtWidgets.QLabel('%s:' % _("Thickness"))
|
||||
self.thick_label.setToolTip(
|
||||
_("The thickness of the line that makes the corner marker.")
|
||||
)
|
||||
self.thick_entry = FCDoubleSpinner(callback=self.confirmation_message)
|
||||
self.thick_entry.set_range(0.0000, 9.9999)
|
||||
self.thick_entry.set_precision(self.decimals)
|
||||
self.thick_entry.setWrapping(True)
|
||||
self.thick_entry.setSingleStep(10 ** -self.decimals)
|
||||
|
||||
grid_lay.addWidget(self.thick_label, 1, 0)
|
||||
grid_lay.addWidget(self.thick_entry, 1, 1)
|
||||
|
||||
# Length #
|
||||
self.l_label = QtWidgets.QLabel('%s:' % _("Length"))
|
||||
self.l_label.setToolTip(
|
||||
_("The length of the line that makes the corner marker.")
|
||||
)
|
||||
self.l_entry = FCDoubleSpinner(callback=self.confirmation_message)
|
||||
self.l_entry.set_range(-9999.9999, 9999.9999)
|
||||
self.l_entry.set_precision(self.decimals)
|
||||
self.l_entry.setSingleStep(10 ** -self.decimals)
|
||||
|
||||
grid_lay.addWidget(self.l_label, 2, 0)
|
||||
grid_lay.addWidget(self.l_entry, 2, 1)
|
||||
|
||||
# Margin #
|
||||
self.margin_label = QtWidgets.QLabel('%s:' % _("Margin"))
|
||||
self.margin_label.setToolTip(
|
||||
_("Bounding box margin.")
|
||||
)
|
||||
self.margin_entry = FCDoubleSpinner(callback=self.confirmation_message)
|
||||
self.margin_entry.set_range(-9999.9999, 9999.9999)
|
||||
self.margin_entry.set_precision(self.decimals)
|
||||
self.margin_entry.setSingleStep(0.1)
|
||||
|
||||
grid_lay.addWidget(self.margin_label, 3, 0)
|
||||
grid_lay.addWidget(self.margin_entry, 3, 1)
|
||||
|
||||
separator_line_2 = QtWidgets.QFrame()
|
||||
separator_line_2.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
grid_lay.addWidget(separator_line_2, 4, 0, 1, 2)
|
||||
|
||||
# ## Insert Corner Marker
|
||||
self.add_marker_button = FCButton(_("Add Marker"))
|
||||
self.add_marker_button.setToolTip(
|
||||
_("Will add corner markers to the selected Gerber file.")
|
||||
)
|
||||
self.add_marker_button.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
grid_lay.addWidget(self.add_marker_button, 11, 0, 1, 2)
|
||||
|
||||
self.layout.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.layout.addWidget(self.reset_button)
|
||||
# #############################################################################
|
||||
# ######################### Tool GUI ##########################################
|
||||
# #############################################################################
|
||||
self.ui = CornersUI(layout=self.layout, app=self.app)
|
||||
self.toolName = self.ui.toolName
|
||||
|
||||
# Objects involved in Copper thieving
|
||||
self.grb_object = None
|
||||
@@ -204,8 +55,8 @@ class ToolCorners(AppTool):
|
||||
self.grb_steps_per_circle = self.app.defaults["gerber_circle_steps"]
|
||||
|
||||
# SIGNALS
|
||||
self.add_marker_button.clicked.connect(self.add_markers)
|
||||
self.toggle_all_cb.toggled.connect(self.on_toggle_all)
|
||||
self.ui.add_marker_button.clicked.connect(self.add_markers)
|
||||
self.ui.toggle_all_cb.toggled.connect(self.on_toggle_all)
|
||||
|
||||
def run(self, toggle=True):
|
||||
self.app.defaults.report_usage("ToolCorners()")
|
||||
@@ -240,27 +91,27 @@ class ToolCorners(AppTool):
|
||||
|
||||
def set_tool_ui(self):
|
||||
self.units = self.app.defaults['units']
|
||||
self.thick_entry.set_value(self.app.defaults["tools_corners_thickness"])
|
||||
self.l_entry.set_value(float(self.app.defaults["tools_corners_length"]))
|
||||
self.margin_entry.set_value(float(self.app.defaults["tools_corners_margin"]))
|
||||
self.toggle_all_cb.set_value(False)
|
||||
self.ui.thick_entry.set_value(self.app.defaults["tools_corners_thickness"])
|
||||
self.ui.l_entry.set_value(float(self.app.defaults["tools_corners_length"]))
|
||||
self.ui.margin_entry.set_value(float(self.app.defaults["tools_corners_margin"]))
|
||||
self.ui.toggle_all_cb.set_value(False)
|
||||
|
||||
def on_toggle_all(self, val):
|
||||
self.bl_cb.set_value(val)
|
||||
self.br_cb.set_value(val)
|
||||
self.tl_cb.set_value(val)
|
||||
self.tr_cb.set_value(val)
|
||||
self.ui.bl_cb.set_value(val)
|
||||
self.ui.br_cb.set_value(val)
|
||||
self.ui.tl_cb.set_value(val)
|
||||
self.ui.tr_cb.set_value(val)
|
||||
|
||||
def add_markers(self):
|
||||
self.app.call_source = "corners_tool"
|
||||
tl_state = self.tl_cb.get_value()
|
||||
tr_state = self.tr_cb.get_value()
|
||||
bl_state = self.bl_cb.get_value()
|
||||
br_state = self.br_cb.get_value()
|
||||
tl_state = self.ui.tl_cb.get_value()
|
||||
tr_state = self.ui.tr_cb.get_value()
|
||||
bl_state = self.ui.bl_cb.get_value()
|
||||
br_state = self.ui.br_cb.get_value()
|
||||
|
||||
# get the Gerber object on which the corner marker will be inserted
|
||||
selection_index = self.object_combo.currentIndex()
|
||||
model_index = self.app.collection.index(selection_index, 0, self.object_combo.rootModelIndex())
|
||||
selection_index = self.ui.object_combo.currentIndex()
|
||||
model_index = self.app.collection.index(selection_index, 0, self.ui.object_combo.rootModelIndex())
|
||||
|
||||
try:
|
||||
self.grb_object = model_index.internalPointer().obj
|
||||
@@ -296,9 +147,9 @@ class ToolCorners(AppTool):
|
||||
:return: None
|
||||
"""
|
||||
|
||||
line_thickness = self.thick_entry.get_value()
|
||||
line_length = self.l_entry.get_value()
|
||||
margin = self.margin_entry.get_value()
|
||||
line_thickness = self.ui.thick_entry.get_value()
|
||||
line_length = self.ui.l_entry.get_value()
|
||||
margin = self.ui.margin_entry.get_value()
|
||||
|
||||
geo_list = []
|
||||
|
||||
@@ -439,3 +290,186 @@ class ToolCorners(AppTool):
|
||||
|
||||
self.app.call_source = "app"
|
||||
self.app.inform.emit('[success] %s' % _("Corners Tool exit."))
|
||||
|
||||
|
||||
class CornersUI:
|
||||
|
||||
toolName = _("Corner Markers 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(""))
|
||||
|
||||
# Gerber object #
|
||||
self.object_label = QtWidgets.QLabel('<b>%s:</b>' % _("GERBER"))
|
||||
self.object_label.setToolTip(
|
||||
_("The Gerber object to which will be added corner markers.")
|
||||
)
|
||||
self.object_combo = FCComboBox()
|
||||
self.object_combo.setModel(self.app.collection)
|
||||
self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.object_combo.is_last = True
|
||||
self.object_combo.obj_type = "Gerber"
|
||||
|
||||
self.layout.addWidget(self.object_label)
|
||||
self.layout.addWidget(self.object_combo)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
self.layout.addWidget(separator_line)
|
||||
|
||||
self.points_label = QtWidgets.QLabel('<b>%s:</b>' % _('Locations'))
|
||||
self.points_label.setToolTip(
|
||||
_("Locations where to place corner markers.")
|
||||
)
|
||||
self.layout.addWidget(self.points_label)
|
||||
|
||||
# BOTTOM LEFT
|
||||
self.bl_cb = FCCheckBox(_("Bottom Left"))
|
||||
self.layout.addWidget(self.bl_cb)
|
||||
|
||||
# BOTTOM RIGHT
|
||||
self.br_cb = FCCheckBox(_("Bottom Right"))
|
||||
self.layout.addWidget(self.br_cb)
|
||||
|
||||
# TOP LEFT
|
||||
self.tl_cb = FCCheckBox(_("Top Left"))
|
||||
self.layout.addWidget(self.tl_cb)
|
||||
|
||||
# TOP RIGHT
|
||||
self.tr_cb = FCCheckBox(_("Top Right"))
|
||||
self.layout.addWidget(self.tr_cb)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
self.layout.addWidget(separator_line)
|
||||
|
||||
# Toggle ALL
|
||||
self.toggle_all_cb = FCCheckBox(_("Toggle ALL"))
|
||||
self.layout.addWidget(self.toggle_all_cb)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
self.layout.addWidget(separator_line)
|
||||
|
||||
# ## Grid Layout
|
||||
grid_lay = QtWidgets.QGridLayout()
|
||||
self.layout.addLayout(grid_lay)
|
||||
grid_lay.setColumnStretch(0, 0)
|
||||
grid_lay.setColumnStretch(1, 1)
|
||||
|
||||
self.param_label = QtWidgets.QLabel('<b>%s:</b>' % _('Parameters'))
|
||||
self.param_label.setToolTip(
|
||||
_("Parameters used for this tool.")
|
||||
)
|
||||
grid_lay.addWidget(self.param_label, 0, 0, 1, 2)
|
||||
|
||||
# Thickness #
|
||||
self.thick_label = QtWidgets.QLabel('%s:' % _("Thickness"))
|
||||
self.thick_label.setToolTip(
|
||||
_("The thickness of the line that makes the corner marker.")
|
||||
)
|
||||
self.thick_entry = FCDoubleSpinner(callback=self.confirmation_message)
|
||||
self.thick_entry.set_range(0.0000, 9.9999)
|
||||
self.thick_entry.set_precision(self.decimals)
|
||||
self.thick_entry.setWrapping(True)
|
||||
self.thick_entry.setSingleStep(10 ** -self.decimals)
|
||||
|
||||
grid_lay.addWidget(self.thick_label, 1, 0)
|
||||
grid_lay.addWidget(self.thick_entry, 1, 1)
|
||||
|
||||
# Length #
|
||||
self.l_label = QtWidgets.QLabel('%s:' % _("Length"))
|
||||
self.l_label.setToolTip(
|
||||
_("The length of the line that makes the corner marker.")
|
||||
)
|
||||
self.l_entry = FCDoubleSpinner(callback=self.confirmation_message)
|
||||
self.l_entry.set_range(-9999.9999, 9999.9999)
|
||||
self.l_entry.set_precision(self.decimals)
|
||||
self.l_entry.setSingleStep(10 ** -self.decimals)
|
||||
|
||||
grid_lay.addWidget(self.l_label, 2, 0)
|
||||
grid_lay.addWidget(self.l_entry, 2, 1)
|
||||
|
||||
# Margin #
|
||||
self.margin_label = QtWidgets.QLabel('%s:' % _("Margin"))
|
||||
self.margin_label.setToolTip(
|
||||
_("Bounding box margin.")
|
||||
)
|
||||
self.margin_entry = FCDoubleSpinner(callback=self.confirmation_message)
|
||||
self.margin_entry.set_range(-9999.9999, 9999.9999)
|
||||
self.margin_entry.set_precision(self.decimals)
|
||||
self.margin_entry.setSingleStep(0.1)
|
||||
|
||||
grid_lay.addWidget(self.margin_label, 3, 0)
|
||||
grid_lay.addWidget(self.margin_entry, 3, 1)
|
||||
|
||||
separator_line_2 = QtWidgets.QFrame()
|
||||
separator_line_2.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
grid_lay.addWidget(separator_line_2, 4, 0, 1, 2)
|
||||
|
||||
# ## Insert Corner Marker
|
||||
self.add_marker_button = FCButton(_("Add Marker"))
|
||||
self.add_marker_button.setToolTip(
|
||||
_("Will add corner markers to the selected Gerber file.")
|
||||
)
|
||||
self.add_marker_button.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
grid_lay.addWidget(self.add_marker_button, 11, 0, 1, 2)
|
||||
|
||||
self.layout.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.layout.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)
|
||||
Reference in New Issue
Block a user