|
|
@@ -6,10 +6,10 @@
|
|
|
# ##########################################################
|
|
|
|
|
|
from PyQt5 import QtGui, QtCore, QtWidgets
|
|
|
-from PyQt5.QtCore import Qt, QSettings
|
|
|
+from PyQt5.QtCore import Qt
|
|
|
|
|
|
from camlib import distance, arc, FlatCAMRTreeStorage
|
|
|
-from appGUI.GUIElements import FCEntry, FCComboBox, FCTable, FCDoubleSpinner, RadioSet, FCSpinner
|
|
|
+from appGUI.GUIElements import FCEntry, FCComboBox, FCTable, FCDoubleSpinner, RadioSet, FCSpinner, FCButton
|
|
|
from appEditors.AppGeoEditor import FCShapeTool, DrawTool, DrawToolShape, DrawToolUtilityShape, AppGeoEditor
|
|
|
from appParsers.ParseExcellon import Excellon
|
|
|
|
|
|
@@ -142,7 +142,7 @@ class FCDrillArray(FCShapeTool):
|
|
|
DrawTool.__init__(self, draw_app)
|
|
|
self.name = 'drill_array'
|
|
|
|
|
|
- self.draw_app.array_frame.show()
|
|
|
+ self.draw_app.e_ui.array_frame.show()
|
|
|
|
|
|
self.selected_dia = None
|
|
|
self.drill_axis = 'X'
|
|
|
@@ -219,15 +219,15 @@ class FCDrillArray(FCShapeTool):
|
|
|
self.origin = origin
|
|
|
|
|
|
def utility_geometry(self, data=None, static=None):
|
|
|
- self.drill_axis = self.draw_app.drill_axis_radio.get_value()
|
|
|
- self.drill_direction = self.draw_app.drill_direction_radio.get_value()
|
|
|
- self.drill_array = self.draw_app.array_type_combo.get_value()
|
|
|
+ self.drill_axis = self.draw_app.e_ui.drill_axis_radio.get_value()
|
|
|
+ self.drill_direction = self.draw_app.e_ui.drill_direction_radio.get_value()
|
|
|
+ self.drill_array = self.draw_app.e_ui.array_type_combo.get_value()
|
|
|
try:
|
|
|
- self.drill_array_size = int(self.draw_app.drill_array_size_entry.get_value())
|
|
|
+ self.drill_array_size = int(self.draw_app.e_ui.drill_array_size_entry.get_value())
|
|
|
try:
|
|
|
- self.drill_pitch = float(self.draw_app.drill_pitch_entry.get_value())
|
|
|
- self.drill_linear_angle = float(self.draw_app.linear_angle_spinner.get_value())
|
|
|
- self.drill_angle = float(self.draw_app.drill_angle_entry.get_value())
|
|
|
+ self.drill_pitch = float(self.draw_app.e_ui.drill_pitch_entry.get_value())
|
|
|
+ self.drill_linear_angle = float(self.draw_app.e_ui.linear_angle_spinner.get_value())
|
|
|
+ self.drill_angle = float(self.draw_app.e_ui.drill_angle_entry.get_value())
|
|
|
except TypeError:
|
|
|
self.draw_app.app.inform.emit('[ERROR_NOTCL] %s' %
|
|
|
_("The value is not Float. Check for comma instead of dot separator."))
|
|
|
@@ -353,7 +353,7 @@ class FCDrillArray(FCShapeTool):
|
|
|
self.complete = True
|
|
|
self.draw_app.app.inform.emit('[success] %s' % _("Done. Drill Array added."))
|
|
|
self.draw_app.in_action = False
|
|
|
- self.draw_app.array_frame.hide()
|
|
|
+ self.draw_app.e_ui.array_frame.hide()
|
|
|
|
|
|
self.draw_app.app.jump_signal.disconnect()
|
|
|
|
|
|
@@ -378,7 +378,7 @@ class FCSlot(FCShapeTool):
|
|
|
self.name = 'slot_add'
|
|
|
self.draw_app = draw_app
|
|
|
|
|
|
- self.draw_app.slot_frame.show()
|
|
|
+ self.draw_app.e_ui.slot_frame.show()
|
|
|
|
|
|
self.selected_dia = None
|
|
|
try:
|
|
|
@@ -442,25 +442,25 @@ class FCSlot(FCShapeTool):
|
|
|
self.steps_per_circ = self.draw_app.app.defaults["geometry_circle_steps"]
|
|
|
|
|
|
try:
|
|
|
- slot_length = float(self.draw_app.slot_length_entry.get_value())
|
|
|
+ slot_length = float(self.draw_app.e_ui.slot_length_entry.get_value())
|
|
|
except ValueError:
|
|
|
# try to convert comma to decimal point. if it's still not working error message and return
|
|
|
try:
|
|
|
- slot_length = float(self.draw_app.slot_length_entry.get_value().replace(',', '.'))
|
|
|
- self.draw_app.slot_length_entry.set_value(slot_length)
|
|
|
+ slot_length = float(self.draw_app.e_ui.slot_length_entry.get_value().replace(',', '.'))
|
|
|
+ self.draw_app.e_ui.slot_length_entry.set_value(slot_length)
|
|
|
except ValueError:
|
|
|
self.draw_app.app.inform.emit('[WARNING_NOTCL] %s' %
|
|
|
_("Value is missing or wrong format. Add it and retry."))
|
|
|
return
|
|
|
|
|
|
try:
|
|
|
- slot_angle = float(self.draw_app.slot_angle_spinner.get_value())
|
|
|
+ slot_angle = float(self.draw_app.e_ui.slot_angle_spinner.get_value())
|
|
|
except ValueError:
|
|
|
self.draw_app.app.inform.emit('[WARNING_NOTCL] %s' %
|
|
|
_("Value is missing or wrong format. Add it and retry."))
|
|
|
return
|
|
|
|
|
|
- if self.draw_app.slot_axis_radio.get_value() == 'X':
|
|
|
+ if self.draw_app.e_ui.slot_axis_radio.get_value() == 'X':
|
|
|
self.half_width = slot_length / 2.0
|
|
|
self.half_height = self.radius
|
|
|
else:
|
|
|
@@ -501,7 +501,7 @@ class FCSlot(FCShapeTool):
|
|
|
geo.append(pt)
|
|
|
geo.append(p4)
|
|
|
|
|
|
- if self.draw_app.slot_axis_radio.get_value() == 'A':
|
|
|
+ if self.draw_app.e_ui.slot_axis_radio.get_value() == 'A':
|
|
|
return affinity.rotate(geom=Polygon(geo), angle=-slot_angle)
|
|
|
else:
|
|
|
return Polygon(geo)
|
|
|
@@ -556,7 +556,7 @@ class FCSlot(FCShapeTool):
|
|
|
self.draw_app.in_action = False
|
|
|
self.complete = True
|
|
|
self.draw_app.app.inform.emit('[success] %s' % _("Done. Adding Slot completed."))
|
|
|
- self.draw_app.slot_frame.hide()
|
|
|
+ self.draw_app.e_ui.slot_frame.hide()
|
|
|
self.draw_app.app.jump_signal.disconnect()
|
|
|
|
|
|
def clean_up(self):
|
|
|
@@ -580,8 +580,8 @@ class FCSlotArray(FCShapeTool):
|
|
|
self.name = 'slot_array'
|
|
|
self.draw_app = draw_app
|
|
|
|
|
|
- self.draw_app.slot_frame.show()
|
|
|
- self.draw_app.slot_array_frame.show()
|
|
|
+ self.draw_app.e_ui.slot_frame.show()
|
|
|
+ self.draw_app.e_ui.slot_array_frame.show()
|
|
|
|
|
|
self.selected_dia = None
|
|
|
try:
|
|
|
@@ -662,15 +662,15 @@ class FCSlotArray(FCShapeTool):
|
|
|
self.origin = origin
|
|
|
|
|
|
def utility_geometry(self, data=None, static=None):
|
|
|
- self.slot_axis = self.draw_app.slot_array_axis_radio.get_value()
|
|
|
- self.slot_direction = self.draw_app.slot_array_direction_radio.get_value()
|
|
|
- self.slot_array = self.draw_app.slot_array_type_combo.get_value()
|
|
|
+ self.slot_axis = self.draw_app.e_ui.slot_array_axis_radio.get_value()
|
|
|
+ self.slot_direction = self.draw_app.e_ui.slot_array_direction_radio.get_value()
|
|
|
+ self.slot_array = self.draw_app.e_ui.slot_array_type_combo.get_value()
|
|
|
try:
|
|
|
- self.slot_array_size = int(self.draw_app.slot_array_size_entry.get_value())
|
|
|
+ self.slot_array_size = int(self.draw_app.e_ui.slot_array_size_entry.get_value())
|
|
|
try:
|
|
|
- self.slot_pitch = float(self.draw_app.slot_array_pitch_entry.get_value())
|
|
|
- self.slot_linear_angle = float(self.draw_app.slot_array_linear_angle_spinner.get_value())
|
|
|
- self.slot_angle = float(self.draw_app.slot_array_angle_entry.get_value())
|
|
|
+ self.slot_pitch = float(self.draw_app.e_ui.slot_array_pitch_entry.get_value())
|
|
|
+ self.slot_linear_angle = float(self.draw_app.e_ui.slot_array_linear_angle_spinner.get_value())
|
|
|
+ self.slot_angle = float(self.draw_app.e_ui.slot_array_angle_entry.get_value())
|
|
|
except TypeError:
|
|
|
self.draw_app.app.inform.emit('[ERROR_NOTCL] %s' %
|
|
|
_("The value is not Float. Check for comma instead of dot separator."))
|
|
|
@@ -730,25 +730,25 @@ class FCSlotArray(FCShapeTool):
|
|
|
self.steps_per_circ = self.draw_app.app.defaults["geometry_circle_steps"]
|
|
|
|
|
|
try:
|
|
|
- slot_length = float(self.draw_app.slot_length_entry.get_value())
|
|
|
+ slot_length = float(self.draw_app.e_ui.slot_length_entry.get_value())
|
|
|
except ValueError:
|
|
|
# try to convert comma to decimal point. if it's still not working error message and return
|
|
|
try:
|
|
|
- slot_length = float(self.draw_app.slot_length_entry.get_value().replace(',', '.'))
|
|
|
- self.draw_app.slot_length_entry.set_value(slot_length)
|
|
|
+ slot_length = float(self.draw_app.e_ui.slot_length_entry.get_value().replace(',', '.'))
|
|
|
+ self.draw_app.e_ui.slot_length_entry.set_value(slot_length)
|
|
|
except ValueError:
|
|
|
self.draw_app.app.inform.emit('[WARNING_NOTCL] %s' %
|
|
|
_("Value is missing or wrong format. Add it and retry."))
|
|
|
return
|
|
|
|
|
|
try:
|
|
|
- slot_angle = float(self.draw_app.slot_angle_spinner.get_value())
|
|
|
+ slot_angle = float(self.draw_app.e_ui.slot_angle_spinner.get_value())
|
|
|
except ValueError:
|
|
|
self.draw_app.app.inform.emit('[WARNING_NOTCL] %s' %
|
|
|
_("Value is missing or wrong format. Add it and retry."))
|
|
|
return
|
|
|
|
|
|
- if self.draw_app.slot_axis_radio.get_value() == 'X':
|
|
|
+ if self.draw_app.e_ui.slot_axis_radio.get_value() == 'X':
|
|
|
self.half_width = slot_length / 2.0
|
|
|
self.half_height = self.radius
|
|
|
else:
|
|
|
@@ -815,7 +815,7 @@ class FCSlotArray(FCShapeTool):
|
|
|
|
|
|
# this function return one slot in the slot array and the following will rotate that one slot around it's
|
|
|
# center if the radio value is "A".
|
|
|
- if self.draw_app.slot_axis_radio.get_value() == 'A':
|
|
|
+ if self.draw_app.e_ui.slot_axis_radio.get_value() == 'A':
|
|
|
return affinity.rotate(Polygon(geo), -slot_angle)
|
|
|
else:
|
|
|
return Polygon(geo)
|
|
|
@@ -880,8 +880,8 @@ class FCSlotArray(FCShapeTool):
|
|
|
self.complete = True
|
|
|
self.draw_app.app.inform.emit('[success] %s' % _("Done. Slot Array added."))
|
|
|
self.draw_app.in_action = False
|
|
|
- self.draw_app.slot_frame.hide()
|
|
|
- self.draw_app.slot_array_frame.hide()
|
|
|
+ self.draw_app.e_ui.slot_frame.hide()
|
|
|
+ self.draw_app.e_ui.slot_array_frame.hide()
|
|
|
self.draw_app.app.jump_signal.disconnect()
|
|
|
|
|
|
def clean_up(self):
|
|
|
@@ -902,7 +902,7 @@ class FCDrillResize(FCShapeTool):
|
|
|
|
|
|
self.draw_app.app.inform.emit(_("Click on the Drill(s) to resize ..."))
|
|
|
self.resize_dia = None
|
|
|
- self.draw_app.resize_frame.show()
|
|
|
+ self.draw_app.e_ui.resize_frame.show()
|
|
|
self.points = None
|
|
|
|
|
|
# made this a set so there are no duplicates
|
|
|
@@ -927,7 +927,7 @@ class FCDrillResize(FCShapeTool):
|
|
|
pass
|
|
|
|
|
|
try:
|
|
|
- new_dia = self.draw_app.resdrill_entry.get_value()
|
|
|
+ new_dia = self.draw_app.e_ui.resdrill_entry.get_value()
|
|
|
except Exception:
|
|
|
self.draw_app.app.inform.emit('[ERROR_NOTCL] %s' %
|
|
|
_("Resize drill(s) failed. Please enter a diameter for resize."))
|
|
|
@@ -1116,7 +1116,7 @@ class FCDrillResize(FCShapeTool):
|
|
|
# init this set() for another use perhaps
|
|
|
self.selected_dia_set = set()
|
|
|
|
|
|
- self.draw_app.resize_frame.hide()
|
|
|
+ self.draw_app.e_ui.resize_frame.hide()
|
|
|
self.complete = True
|
|
|
|
|
|
# MS: always return to the Select Tool
|
|
|
@@ -1348,10 +1348,10 @@ class FCDrillSelect(DrawTool):
|
|
|
# here we store all shapes that were selected so we can search for the nearest to our click location
|
|
|
self.sel_storage = AppExcEditor.make_storage()
|
|
|
|
|
|
- self.exc_editor_app.resize_frame.hide()
|
|
|
- self.exc_editor_app.array_frame.hide()
|
|
|
- self.exc_editor_app.slot_frame.hide()
|
|
|
- self.exc_editor_app.slot_array_frame.hide()
|
|
|
+ self.exc_editor_app.e_ui.resize_frame.hide()
|
|
|
+ self.exc_editor_app.e_ui.array_frame.hide()
|
|
|
+ self.exc_editor_app.e_ui.slot_frame.hide()
|
|
|
+ self.exc_editor_app.e_ui.slot_array_frame.hide()
|
|
|
|
|
|
def click(self, point):
|
|
|
key_modifier = QtWidgets.QApplication.keyboardModifiers()
|
|
|
@@ -1520,2633 +1520,2710 @@ class AppExcEditor(QtCore.QObject):
|
|
|
|
|
|
self.app = app
|
|
|
self.canvas = self.app.plotcanvas
|
|
|
+ self.units = self.app.defaults['units'].upper()
|
|
|
+
|
|
|
+ self.dec_format = self.app.dec_format
|
|
|
|
|
|
# Number of decimals used by tools in this class
|
|
|
self.decimals = self.app.decimals
|
|
|
|
|
|
- # ## Current application units in Upper Case
|
|
|
- self.units = self.app.defaults['units'].upper()
|
|
|
-
|
|
|
- self.exc_edit_widget = QtWidgets.QWidget()
|
|
|
- # ## Box for custom widgets
|
|
|
- # This gets populated in offspring implementations.
|
|
|
- layout = QtWidgets.QVBoxLayout()
|
|
|
- self.exc_edit_widget.setLayout(layout)
|
|
|
+ self.e_ui = AppExcEditorUI(app=self.app)
|
|
|
+
|
|
|
+ # SIGNALS
|
|
|
+ self.e_ui.convert_slots_btn.clicked.connect(self.on_slots_conversion)
|
|
|
+ self.app.ui.delete_drill_btn.triggered.connect(self.on_delete_btn)
|
|
|
+ self.e_ui.name_entry.returnPressed.connect(self.on_name_activate)
|
|
|
+ self.e_ui.addtool_btn.clicked.connect(self.on_tool_add)
|
|
|
+ self.e_ui.addtool_entry.editingFinished.connect(self.on_tool_add)
|
|
|
+ self.e_ui.deltool_btn.clicked.connect(self.on_tool_delete)
|
|
|
+ # self.tools_table_exc.selectionModel().currentChanged.connect(self.on_row_selected)
|
|
|
+ self.e_ui.tools_table_exc.cellPressed.connect(self.on_row_selected)
|
|
|
|
|
|
- # add a frame and inside add a vertical box layout. Inside this vbox layout I add all the Drills widgets
|
|
|
- # this way I can hide/show the frame
|
|
|
- self.drills_frame = QtWidgets.QFrame()
|
|
|
- self.drills_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
- layout.addWidget(self.drills_frame)
|
|
|
- self.tools_box = QtWidgets.QVBoxLayout()
|
|
|
- self.tools_box.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.drills_frame.setLayout(self.tools_box)
|
|
|
+ self.e_ui.array_type_combo.currentIndexChanged.connect(self.on_array_type_combo)
|
|
|
+ self.e_ui.slot_array_type_combo.currentIndexChanged.connect(self.on_slot_array_type_combo)
|
|
|
|
|
|
- # ## Page Title box (spacing between children)
|
|
|
- self.title_box = QtWidgets.QHBoxLayout()
|
|
|
- self.tools_box.addLayout(self.title_box)
|
|
|
+ self.e_ui.drill_axis_radio.activated_custom.connect(self.on_linear_angle_radio)
|
|
|
+ self.e_ui.slot_axis_radio.activated_custom.connect(self.on_slot_angle_radio)
|
|
|
|
|
|
- # ## Page Title icon
|
|
|
- pixmap = QtGui.QPixmap(self.app.resource_location + '/flatcam_icon32.png')
|
|
|
- self.icon = QtWidgets.QLabel()
|
|
|
- self.icon.setPixmap(pixmap)
|
|
|
- self.title_box.addWidget(self.icon, stretch=0)
|
|
|
+ self.e_ui.slot_array_axis_radio.activated_custom.connect(self.on_slot_array_linear_angle_radio)
|
|
|
|
|
|
- # ## Title label
|
|
|
- self.title_label = QtWidgets.QLabel("<font size=5><b>%s</b></font>" % _('Excellon Editor'))
|
|
|
- self.title_label.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
|
|
|
- self.title_box.addWidget(self.title_label, stretch=1)
|
|
|
+ self.app.ui.exc_add_array_drill_menuitem.triggered.connect(self.exc_add_drill_array)
|
|
|
+ self.app.ui.exc_add_drill_menuitem.triggered.connect(self.exc_add_drill)
|
|
|
|
|
|
- # ## Object name
|
|
|
- self.name_box = QtWidgets.QHBoxLayout()
|
|
|
- self.tools_box.addLayout(self.name_box)
|
|
|
- name_label = QtWidgets.QLabel(_("Name:"))
|
|
|
- self.name_box.addWidget(name_label)
|
|
|
- self.name_entry = FCEntry()
|
|
|
- self.name_box.addWidget(self.name_entry)
|
|
|
+ self.app.ui.exc_add_array_slot_menuitem.triggered.connect(self.exc_add_slot_array)
|
|
|
+ self.app.ui.exc_add_slot_menuitem.triggered.connect(self.exc_add_slot)
|
|
|
|
|
|
- # ### Tools Drills ## ##
|
|
|
- self.tools_table_label = QtWidgets.QLabel("<b>%s</b>" % _('Tools Table'))
|
|
|
- self.tools_table_label.setToolTip(
|
|
|
- _("Tools in this Excellon object\n"
|
|
|
- "when are used for drilling.")
|
|
|
- )
|
|
|
- self.tools_box.addWidget(self.tools_table_label)
|
|
|
+ self.app.ui.exc_resize_drill_menuitem.triggered.connect(self.exc_resize_drills)
|
|
|
+ self.app.ui.exc_copy_drill_menuitem.triggered.connect(self.exc_copy_drills)
|
|
|
+ self.app.ui.exc_delete_drill_menuitem.triggered.connect(self.on_delete_btn)
|
|
|
|
|
|
- self.tools_table_exc = FCTable()
|
|
|
- # delegate = SpinBoxDelegate(units=self.units)
|
|
|
- # self.tools_table_exc.setItemDelegateForColumn(1, delegate)
|
|
|
+ self.app.ui.exc_move_drill_menuitem.triggered.connect(self.exc_move_drills)
|
|
|
+ self.e_ui.exit_editor_button.clicked.connect(lambda: self.app.editor2object())
|
|
|
|
|
|
- self.tools_box.addWidget(self.tools_table_exc)
|
|
|
+ self.exc_obj = None
|
|
|
|
|
|
- self.tools_table_exc.setColumnCount(4)
|
|
|
- self.tools_table_exc.setHorizontalHeaderLabels(['#', _('Diameter'), 'D', 'S'])
|
|
|
- self.tools_table_exc.setSortingEnabled(False)
|
|
|
- self.tools_table_exc.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
|
|
|
+ # ## Toolbar events and properties
|
|
|
+ self.tools_exc = {
|
|
|
+ "drill_select": {"button": self.app.ui.select_drill_btn, "constructor": FCDrillSelect},
|
|
|
+ "drill_add": {"button": self.app.ui.add_drill_btn, "constructor": FCDrillAdd},
|
|
|
+ "drill_array": {"button": self.app.ui.add_drill_array_btn, "constructor": FCDrillArray},
|
|
|
+ "slot_add": {"button": self.app.ui.add_slot_btn, "constructor": FCSlot},
|
|
|
+ "slot_array": {"button": self.app.ui.add_slot_array_btn, "constructor": FCSlotArray},
|
|
|
+ "drill_resize": {"button": self.app.ui.resize_drill_btn, "constructor": FCDrillResize},
|
|
|
+ "drill_copy": {"button": self.app.ui.copy_drill_btn, "constructor": FCDrillCopy},
|
|
|
+ "drill_move": {"button": self.app.ui.move_drill_btn, "constructor": FCDrillMove},
|
|
|
+ }
|
|
|
|
|
|
- self.empty_label = QtWidgets.QLabel('')
|
|
|
- self.tools_box.addWidget(self.empty_label)
|
|
|
+ # ## Data
|
|
|
+ self.active_tool = None
|
|
|
+ self.in_action = False
|
|
|
|
|
|
- # ### Add a new Tool ## ##
|
|
|
- self.addtool_label = QtWidgets.QLabel('<b>%s</b>' % _('Add/Delete Tool'))
|
|
|
- self.addtool_label.setToolTip(
|
|
|
- _("Add/Delete a tool to the tool list\n"
|
|
|
- "for this Excellon object.")
|
|
|
- )
|
|
|
- self.tools_box.addWidget(self.addtool_label)
|
|
|
+ self.storage_dict = {}
|
|
|
+ self.current_storage = []
|
|
|
|
|
|
- grid1 = QtWidgets.QGridLayout()
|
|
|
- self.tools_box.addLayout(grid1)
|
|
|
- grid1.setColumnStretch(0, 0)
|
|
|
- grid1.setColumnStretch(1, 1)
|
|
|
+ # build the data from the Excellon point into a dictionary
|
|
|
+ # {tool_dia: [geometry_in_points]}
|
|
|
+ self.points_edit = {}
|
|
|
+ self.slot_points_edit = {}
|
|
|
|
|
|
- addtool_entry_lbl = QtWidgets.QLabel('%s:' % _('Tool Dia'))
|
|
|
- addtool_entry_lbl.setToolTip(
|
|
|
- _("Diameter for the new tool")
|
|
|
- )
|
|
|
+ self.sorted_diameters = []
|
|
|
|
|
|
- hlay = QtWidgets.QHBoxLayout()
|
|
|
- self.addtool_entry = FCDoubleSpinner()
|
|
|
- self.addtool_entry.set_precision(self.decimals)
|
|
|
- self.addtool_entry.set_range(0.0000, 9999.9999)
|
|
|
+ self.new_drills = []
|
|
|
+ self.new_tools = {}
|
|
|
+ self.new_slots = []
|
|
|
|
|
|
- hlay.addWidget(self.addtool_entry)
|
|
|
+ # dictionary to store the tool_row and diameters in Tool_table
|
|
|
+ # it will be updated everytime self.build_ui() is called
|
|
|
+ self.olddia_newdia = {}
|
|
|
|
|
|
- self.addtool_btn = QtWidgets.QPushButton(_('Add Tool'))
|
|
|
- self.addtool_btn.setToolTip(
|
|
|
- _("Add a new tool to the tool list\n"
|
|
|
- "with the diameter specified above.")
|
|
|
- )
|
|
|
- self.addtool_btn.setFixedWidth(80)
|
|
|
- hlay.addWidget(self.addtool_btn)
|
|
|
+ self.tool2tooldia = {}
|
|
|
|
|
|
- grid1.addWidget(addtool_entry_lbl, 0, 0)
|
|
|
- grid1.addLayout(hlay, 0, 1)
|
|
|
+ # this will store the value for the last selected tool, for use after clicking on canvas when the selection
|
|
|
+ # is cleared but as a side effect also the selected tool is cleared
|
|
|
+ self.last_tool_selected = None
|
|
|
+ self.utility = []
|
|
|
|
|
|
- grid2 = QtWidgets.QGridLayout()
|
|
|
- self.tools_box.addLayout(grid2)
|
|
|
+ # this will flag if the Editor "tools" are launched from key shortcuts (True) or from menu toolbar (False)
|
|
|
+ self.launched_from_shortcuts = False
|
|
|
|
|
|
- self.deltool_btn = QtWidgets.QPushButton(_('Delete Tool'))
|
|
|
- self.deltool_btn.setToolTip(
|
|
|
- _("Delete a tool in the tool list\n"
|
|
|
- "by selecting a row in the tool table.")
|
|
|
- )
|
|
|
- grid2.addWidget(self.deltool_btn, 0, 1)
|
|
|
+ # this var will store the state of the toolbar before starting the editor
|
|
|
+ self.toolbar_old_state = False
|
|
|
|
|
|
- # add a frame and inside add a vertical box layout. Inside this vbox layout I add all the Drills widgets
|
|
|
- # this way I can hide/show the frame
|
|
|
- self.resize_frame = QtWidgets.QFrame()
|
|
|
- self.resize_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.tools_box.addWidget(self.resize_frame)
|
|
|
- self.resize_box = QtWidgets.QVBoxLayout()
|
|
|
- self.resize_box.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.resize_frame.setLayout(self.resize_box)
|
|
|
+ if self.units == 'MM':
|
|
|
+ self.tolerance = float(self.app.defaults["global_tolerance"])
|
|
|
+ else:
|
|
|
+ self.tolerance = float(self.app.defaults["global_tolerance"]) / 20
|
|
|
|
|
|
- # ### Resize a drill ## ##
|
|
|
- self.emptyresize_label = QtWidgets.QLabel('')
|
|
|
- self.resize_box.addWidget(self.emptyresize_label)
|
|
|
+ # VisPy Visuals
|
|
|
+ if self.app.is_legacy is False:
|
|
|
+ self.shapes = self.canvas.new_shape_collection(layers=1)
|
|
|
+ if self.canvas.big_cursor is True:
|
|
|
+ self.tool_shape = self.canvas.new_shape_collection(layers=1, line_width=2)
|
|
|
+ else:
|
|
|
+ self.tool_shape = self.canvas.new_shape_collection(layers=1)
|
|
|
+ else:
|
|
|
+ from appGUI.PlotCanvasLegacy import ShapeCollectionLegacy
|
|
|
+ self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='shapes_exc_editor')
|
|
|
+ self.tool_shape = ShapeCollectionLegacy(obj=self, app=self.app, name='tool_shapes_exc_editor')
|
|
|
|
|
|
- self.drillresize_label = QtWidgets.QLabel('<b>%s</b>' % _("Resize Drill(s)"))
|
|
|
- self.drillresize_label.setToolTip(
|
|
|
- _("Resize a drill or a selection of drills.")
|
|
|
- )
|
|
|
- self.resize_box.addWidget(self.drillresize_label)
|
|
|
+ self.app.pool_recreated.connect(self.pool_recreated)
|
|
|
|
|
|
- grid3 = QtWidgets.QGridLayout()
|
|
|
- self.resize_box.addLayout(grid3)
|
|
|
+ # Remove from scene
|
|
|
+ self.shapes.enabled = False
|
|
|
+ self.tool_shape.enabled = False
|
|
|
|
|
|
- res_entry_lbl = QtWidgets.QLabel('%s:' % _('Resize Dia'))
|
|
|
- res_entry_lbl.setToolTip(
|
|
|
- _("Diameter to resize to.")
|
|
|
- )
|
|
|
- grid3.addWidget(res_entry_lbl, 0, 0)
|
|
|
+ # ## List of selected shapes.
|
|
|
+ self.selected = []
|
|
|
|
|
|
- hlay2 = QtWidgets.QHBoxLayout()
|
|
|
- self.resdrill_entry = FCDoubleSpinner()
|
|
|
- self.resdrill_entry.set_precision(self.decimals)
|
|
|
- self.resdrill_entry.set_range(0.0000, 9999.9999)
|
|
|
+ self.move_timer = QtCore.QTimer()
|
|
|
+ self.move_timer.setSingleShot(True)
|
|
|
|
|
|
- hlay2.addWidget(self.resdrill_entry)
|
|
|
+ self.key = None # Currently pressed key
|
|
|
+ self.modifiers = None
|
|
|
+ self.x = None # Current mouse cursor pos
|
|
|
+ self.y = None
|
|
|
+ # Current snapped mouse pos
|
|
|
+ self.snap_x = None
|
|
|
+ self.snap_y = None
|
|
|
+ self.pos = None
|
|
|
|
|
|
- self.resize_btn = QtWidgets.QPushButton(_('Resize'))
|
|
|
- self.resize_btn.setToolTip(
|
|
|
- _("Resize drill(s)")
|
|
|
- )
|
|
|
- self.resize_btn.setFixedWidth(80)
|
|
|
- hlay2.addWidget(self.resize_btn)
|
|
|
- grid3.addLayout(hlay2, 0, 1)
|
|
|
+ self.complete = False
|
|
|
|
|
|
- self.resize_frame.hide()
|
|
|
+ def make_callback(thetool):
|
|
|
+ def f():
|
|
|
+ self.on_tool_select(thetool)
|
|
|
+ return f
|
|
|
|
|
|
- # ####################################
|
|
|
- # ### Add DRILL Array ################
|
|
|
- # ####################################
|
|
|
+ for tool in self.tools_exc:
|
|
|
+ self.tools_exc[tool]["button"].triggered.connect(make_callback(tool)) # Events
|
|
|
+ self.tools_exc[tool]["button"].setCheckable(True) # Checkable
|
|
|
|
|
|
- # add a frame and inside add a vertical box layout. Inside this vbox layout I add
|
|
|
- # all the add drill array widgets
|
|
|
- # this way I can hide/show the frame
|
|
|
- self.array_frame = QtWidgets.QFrame()
|
|
|
- self.array_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.tools_box.addWidget(self.array_frame)
|
|
|
- self.array_box = QtWidgets.QVBoxLayout()
|
|
|
- self.array_box.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.array_frame.setLayout(self.array_box)
|
|
|
+ self.options = {
|
|
|
+ "global_gridx": 0.1,
|
|
|
+ "global_gridy": 0.1,
|
|
|
+ "snap_max": 0.05,
|
|
|
+ "grid_snap": True,
|
|
|
+ "corner_snap": False,
|
|
|
+ "grid_gap_link": True
|
|
|
+ }
|
|
|
+ self.options.update(self.app.options)
|
|
|
|
|
|
- self.emptyarray_label = QtWidgets.QLabel('')
|
|
|
- self.array_box.addWidget(self.emptyarray_label)
|
|
|
+ for option in self.options:
|
|
|
+ if option in self.app.options:
|
|
|
+ self.options[option] = self.app.options[option]
|
|
|
|
|
|
- self.drill_array_label = QtWidgets.QLabel('<b>%s</b>' % _("Add Drill Array"))
|
|
|
- self.drill_array_label.setToolTip(
|
|
|
- _("Add an array of drills (linear or circular array)")
|
|
|
- )
|
|
|
- self.array_box.addWidget(self.drill_array_label)
|
|
|
+ self.data_defaults = {}
|
|
|
|
|
|
- self.array_type_combo = FCComboBox()
|
|
|
- self.array_type_combo.setToolTip(
|
|
|
- _("Select the type of drills array to create.\n"
|
|
|
- "It can be Linear X(Y) or Circular")
|
|
|
- )
|
|
|
- self.array_type_combo.addItem(_("Linear"))
|
|
|
- self.array_type_combo.addItem(_("Circular"))
|
|
|
+ self.rtree_exc_index = rtindex.Index()
|
|
|
+ # flag to show if the object was modified
|
|
|
+ self.is_modified = False
|
|
|
|
|
|
- self.array_box.addWidget(self.array_type_combo)
|
|
|
+ self.edited_obj_name = ""
|
|
|
|
|
|
- self.array_form = QtWidgets.QFormLayout()
|
|
|
- self.array_box.addLayout(self.array_form)
|
|
|
+ # variable to store the total amount of drills per job
|
|
|
+ self.tot_drill_cnt = 0
|
|
|
+ self.tool_row = 0
|
|
|
|
|
|
- # Set the number of drill holes in the drill array
|
|
|
- self.drill_array_size_label = QtWidgets.QLabel('%s:' % _('Nr of drills'))
|
|
|
- self.drill_array_size_label.setToolTip(_("Specify how many drills to be in the array."))
|
|
|
- self.drill_array_size_label.setMinimumWidth(100)
|
|
|
+ # variable to store the total amount of slots per job
|
|
|
+ self.tot_slot_cnt = 0
|
|
|
+ self.tool_row_slots = 0
|
|
|
|
|
|
- self.drill_array_size_entry = FCSpinner()
|
|
|
- self.drill_array_size_entry.set_range(1, 9999)
|
|
|
- self.array_form.addRow(self.drill_array_size_label, self.drill_array_size_entry)
|
|
|
+ self.tool_row = 0
|
|
|
|
|
|
- self.array_linear_frame = QtWidgets.QFrame()
|
|
|
- self.array_linear_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.array_box.addWidget(self.array_linear_frame)
|
|
|
- self.linear_box = QtWidgets.QVBoxLayout()
|
|
|
- self.linear_box.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.array_linear_frame.setLayout(self.linear_box)
|
|
|
+ # store the status of the editor so the Delete at object level will not work until the edit is finished
|
|
|
+ self.editor_active = False
|
|
|
|
|
|
- self.linear_form = QtWidgets.QFormLayout()
|
|
|
- self.linear_box.addLayout(self.linear_form)
|
|
|
+ # def entry2option(option, entry):
|
|
|
+ # self.options[option] = float(entry.text())
|
|
|
|
|
|
- # Linear Drill Array direction
|
|
|
- self.drill_axis_label = QtWidgets.QLabel('%s:' % _('Direction'))
|
|
|
- self.drill_axis_label.setToolTip(
|
|
|
- _("Direction on which the linear array is oriented:\n"
|
|
|
- "- 'X' - horizontal axis \n"
|
|
|
- "- 'Y' - vertical axis or \n"
|
|
|
- "- 'Angle' - a custom angle for the array inclination")
|
|
|
- )
|
|
|
- self.drill_axis_label.setMinimumWidth(100)
|
|
|
+ # Event signals disconnect id holders
|
|
|
+ self.mp = None
|
|
|
+ self.mm = None
|
|
|
+ self.mr = None
|
|
|
|
|
|
- self.drill_axis_radio = RadioSet([{'label': _('X'), 'value': 'X'},
|
|
|
- {'label': _('Y'), 'value': 'Y'},
|
|
|
- {'label': _('Angle'), 'value': 'A'}])
|
|
|
- self.linear_form.addRow(self.drill_axis_label, self.drill_axis_radio)
|
|
|
+ # store the status of the editor so the Delete at object level will not work until the edit is finished
|
|
|
+ self.editor_active = False
|
|
|
+ log.debug("Initialization of the Excellon Editor is finished ...")
|
|
|
|
|
|
- # Linear Drill Array pitch distance
|
|
|
- self.drill_pitch_label = QtWidgets.QLabel('%s:' % _('Pitch'))
|
|
|
- self.drill_pitch_label.setToolTip(
|
|
|
- _("Pitch = Distance between elements of the array.")
|
|
|
- )
|
|
|
- self.drill_pitch_label.setMinimumWidth(100)
|
|
|
+ def pool_recreated(self, pool):
|
|
|
+ self.shapes.pool = pool
|
|
|
+ self.tool_shape.pool = pool
|
|
|
|
|
|
- self.drill_pitch_entry = FCDoubleSpinner()
|
|
|
- self.drill_pitch_entry.set_precision(self.decimals)
|
|
|
- self.drill_pitch_entry.set_range(0.0000, 9999.9999)
|
|
|
+ @staticmethod
|
|
|
+ def make_storage():
|
|
|
+ # ## Shape storage.
|
|
|
+ storage = FlatCAMRTreeStorage()
|
|
|
+ storage.get_points = DrawToolShape.get_pts
|
|
|
|
|
|
- self.linear_form.addRow(self.drill_pitch_label, self.drill_pitch_entry)
|
|
|
+ return storage
|
|
|
|
|
|
- # Linear Drill Array angle
|
|
|
- self.linear_angle_label = QtWidgets.QLabel('%s:' % _('Angle'))
|
|
|
- self.linear_angle_label.setToolTip(
|
|
|
- _("Angle at which the linear array is placed.\n"
|
|
|
- "The precision is of max 2 decimals.\n"
|
|
|
- "Min value is: -360 degrees.\n"
|
|
|
- "Max value is: 360.00 degrees.")
|
|
|
- )
|
|
|
- self.linear_angle_label.setMinimumWidth(100)
|
|
|
+ def set_ui(self):
|
|
|
+ # updated units
|
|
|
+ self.units = self.app.defaults['units'].upper()
|
|
|
|
|
|
- self.linear_angle_spinner = FCDoubleSpinner()
|
|
|
- self.linear_angle_spinner.set_precision(self.decimals)
|
|
|
- self.linear_angle_spinner.setSingleStep(1.0)
|
|
|
- self.linear_angle_spinner.setRange(-360.00, 360.00)
|
|
|
- self.linear_form.addRow(self.linear_angle_label, self.linear_angle_spinner)
|
|
|
+ self.olddia_newdia.clear()
|
|
|
+ self.tool2tooldia.clear()
|
|
|
|
|
|
- self.array_circular_frame = QtWidgets.QFrame()
|
|
|
- self.array_circular_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.array_box.addWidget(self.array_circular_frame)
|
|
|
- self.circular_box = QtWidgets.QVBoxLayout()
|
|
|
- self.circular_box.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.array_circular_frame.setLayout(self.circular_box)
|
|
|
+ # update the olddia_newdia dict to make sure we have an updated state of the tool_table
|
|
|
+ for key in self.points_edit:
|
|
|
+ self.olddia_newdia[key] = key
|
|
|
|
|
|
- self.drill_direction_label = QtWidgets.QLabel('%s:' % _('Direction'))
|
|
|
- self.drill_direction_label.setToolTip(_("Direction for circular array."
|
|
|
- "Can be CW = clockwise or CCW = counter clockwise."))
|
|
|
- self.drill_direction_label.setMinimumWidth(100)
|
|
|
+ for key in self.slot_points_edit:
|
|
|
+ if key not in self.olddia_newdia:
|
|
|
+ self.olddia_newdia[key] = key
|
|
|
|
|
|
- self.circular_form = QtWidgets.QFormLayout()
|
|
|
- self.circular_box.addLayout(self.circular_form)
|
|
|
+ sort_temp = []
|
|
|
+ for diam in self.olddia_newdia:
|
|
|
+ sort_temp.append(float(diam))
|
|
|
+ self.sorted_diameters = sorted(sort_temp)
|
|
|
|
|
|
- self.drill_direction_radio = RadioSet([{'label': _('CW'), 'value': 'CW'},
|
|
|
- {'label': _('CCW'), 'value': 'CCW'}])
|
|
|
- self.circular_form.addRow(self.drill_direction_label, self.drill_direction_radio)
|
|
|
+ # populate self.intial_table_rows dict with the tool number as keys and tool diameters as values
|
|
|
+ if self.exc_obj.diameterless is False:
|
|
|
+ for i in range(len(self.sorted_diameters)):
|
|
|
+ tt_dia = self.sorted_diameters[i]
|
|
|
+ self.tool2tooldia[i + 1] = tt_dia
|
|
|
+ else:
|
|
|
+ # the Excellon object has diameters that are bogus information, added by the application because the
|
|
|
+ # Excellon file has no tool diameter information. In this case do not order the diameter in the table
|
|
|
+ # but use the real order found in the exc_obj.tools
|
|
|
+ for k, v in self.exc_obj.tools.items():
|
|
|
+ tool_dia = float('%.*f' % (self.decimals, v['tooldia']))
|
|
|
+ self.tool2tooldia[int(k)] = tool_dia
|
|
|
|
|
|
- self.drill_angle_label = QtWidgets.QLabel('%s:' % _('Angle'))
|
|
|
- self.drill_angle_label.setToolTip(_("Angle at which each element in circular array is placed."))
|
|
|
- self.drill_angle_label.setMinimumWidth(100)
|
|
|
+ # Init appGUI
|
|
|
+ self.e_ui.addtool_entry.set_value(float(self.app.defaults['excellon_editor_newdia']))
|
|
|
+ self.e_ui.drill_array_size_entry.set_value(int(self.app.defaults['excellon_editor_array_size']))
|
|
|
+ self.e_ui.drill_axis_radio.set_value(self.app.defaults['excellon_editor_lin_dir'])
|
|
|
+ self.e_ui.drill_pitch_entry.set_value(float(self.app.defaults['excellon_editor_lin_pitch']))
|
|
|
+ self.e_ui.linear_angle_spinner.set_value(float(self.app.defaults['excellon_editor_lin_angle']))
|
|
|
+ self.e_ui.drill_direction_radio.set_value(self.app.defaults['excellon_editor_circ_dir'])
|
|
|
+ self.e_ui.drill_angle_entry.set_value(float(self.app.defaults['excellon_editor_circ_angle']))
|
|
|
+
|
|
|
+ self.e_ui.slot_length_entry.set_value(float(self.app.defaults['excellon_editor_slot_length']))
|
|
|
+ self.e_ui.slot_axis_radio.set_value(self.app.defaults['excellon_editor_slot_direction'])
|
|
|
+ self.e_ui.slot_angle_spinner.set_value(float(self.app.defaults['excellon_editor_slot_angle']))
|
|
|
+
|
|
|
+ self.e_ui.slot_array_size_entry.set_value(int(self.app.defaults['excellon_editor_slot_array_size']))
|
|
|
+ self.e_ui.slot_array_axis_radio.set_value(self.app.defaults['excellon_editor_slot_lin_dir'])
|
|
|
+ self.e_ui.slot_array_pitch_entry.set_value(float(self.app.defaults['excellon_editor_slot_lin_pitch']))
|
|
|
+ self.e_ui.slot_array_linear_angle_spinner.set_value(float(self.app.defaults['excellon_editor_slot_lin_angle']))
|
|
|
+ self.e_ui.slot_array_direction_radio.set_value(self.app.defaults['excellon_editor_slot_circ_dir'])
|
|
|
+ self.e_ui.slot_array_angle_entry.set_value(float(self.app.defaults['excellon_editor_slot_circ_angle']))
|
|
|
+
|
|
|
+ self.e_ui.slot_array_circular_frame.hide()
|
|
|
+ self.e_ui.slot_array_linear_frame.show()
|
|
|
|
|
|
- self.drill_angle_entry = FCDoubleSpinner()
|
|
|
- self.drill_angle_entry.set_precision(self.decimals)
|
|
|
- self.drill_angle_entry.setSingleStep(1.0)
|
|
|
- self.drill_angle_entry.setRange(-360.00, 360.00)
|
|
|
+ def build_ui(self, first_run=None):
|
|
|
|
|
|
- self.circular_form.addRow(self.drill_angle_label, self.drill_angle_entry)
|
|
|
+ try:
|
|
|
+ # if connected, disconnect the signal from the slot on item_changed as it creates issues
|
|
|
+ self.e_ui.tools_table_exc.itemChanged.disconnect()
|
|
|
+ except (TypeError, AttributeError):
|
|
|
+ pass
|
|
|
|
|
|
- self.array_circular_frame.hide()
|
|
|
+ try:
|
|
|
+ self.e_ui.tools_table_exc.cellPressed.disconnect()
|
|
|
+ except (TypeError, AttributeError):
|
|
|
+ pass
|
|
|
|
|
|
- self.linear_angle_spinner.hide()
|
|
|
- self.linear_angle_label.hide()
|
|
|
+ # updated units
|
|
|
+ self.units = self.app.defaults['units'].upper()
|
|
|
|
|
|
- self.array_frame.hide()
|
|
|
+ # make a new name for the new Excellon object (the one with edited content)
|
|
|
+ self.edited_obj_name = self.exc_obj.options['name']
|
|
|
+ self.e_ui.name_entry.set_value(self.edited_obj_name)
|
|
|
|
|
|
- # ######################################################
|
|
|
- # ##### ADDING SLOTS ###################################
|
|
|
- # ######################################################
|
|
|
+ sort_temp = []
|
|
|
|
|
|
- # add a frame and inside add a vertical box layout. Inside this vbox layout I add
|
|
|
- # all the add slot widgets
|
|
|
- # this way I can hide/show the frame
|
|
|
- self.slot_frame = QtWidgets.QFrame()
|
|
|
- self.slot_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.tools_box.addWidget(self.slot_frame)
|
|
|
- self.slot_box = QtWidgets.QVBoxLayout()
|
|
|
- self.slot_box.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.slot_frame.setLayout(self.slot_box)
|
|
|
+ for diam in self.olddia_newdia:
|
|
|
+ sort_temp.append(float(diam))
|
|
|
+ self.sorted_diameters = sorted(sort_temp)
|
|
|
|
|
|
- self.emptyarray_label = QtWidgets.QLabel('')
|
|
|
- self.slot_box.addWidget(self.emptyarray_label)
|
|
|
+ # here, self.sorted_diameters will hold in a oblique way, the number of tools
|
|
|
+ n = len(self.sorted_diameters)
|
|
|
+ # we have (n+2) rows because there are 'n' tools, each a row, plus the last 2 rows for totals.
|
|
|
+ self.e_ui.tools_table_exc.setRowCount(n + 2)
|
|
|
|
|
|
- self.slot_label = QtWidgets.QLabel('<b>%s</b>' % _("Slot Parameters"))
|
|
|
- self.slot_label.setToolTip(
|
|
|
- _("Parameters for adding a slot (hole with oval shape)\n"
|
|
|
- "either single or as an part of an array.")
|
|
|
- )
|
|
|
- self.slot_box.addWidget(self.slot_label)
|
|
|
+ self.tot_drill_cnt = 0
|
|
|
+ self.tot_slot_cnt = 0
|
|
|
|
|
|
- self.slot_form = QtWidgets.QFormLayout()
|
|
|
- self.slot_box.addLayout(self.slot_form)
|
|
|
+ self.tool_row = 0
|
|
|
+ # this variable will serve as the real tool_number
|
|
|
+ tool_id = 0
|
|
|
|
|
|
- # Slot length
|
|
|
- self.slot_length_label = QtWidgets.QLabel('%s:' % _('Length'))
|
|
|
- self.slot_length_label.setToolTip(
|
|
|
- _("Length = The length of the slot.")
|
|
|
- )
|
|
|
- self.slot_length_label.setMinimumWidth(100)
|
|
|
+ for tool_no in self.sorted_diameters:
|
|
|
+ tool_id += 1
|
|
|
+ drill_cnt = 0 # variable to store the nr of drills per tool
|
|
|
+ slot_cnt = 0 # variable to store the nr of slots per tool
|
|
|
|
|
|
- self.slot_length_entry = FCDoubleSpinner()
|
|
|
- self.slot_length_entry.set_precision(self.decimals)
|
|
|
- self.slot_length_entry.setSingleStep(0.1)
|
|
|
- self.slot_length_entry.setRange(0.0000, 9999.9999)
|
|
|
+ # Find no of drills for the current tool
|
|
|
+ for tool_dia in self.points_edit:
|
|
|
+ if float(tool_dia) == tool_no:
|
|
|
+ drill_cnt = len(self.points_edit[tool_dia])
|
|
|
|
|
|
- self.slot_form.addRow(self.slot_length_label, self.slot_length_entry)
|
|
|
+ self.tot_drill_cnt += drill_cnt
|
|
|
|
|
|
- # Slot direction
|
|
|
- self.slot_axis_label = QtWidgets.QLabel('%s:' % _('Direction'))
|
|
|
- self.slot_axis_label.setToolTip(
|
|
|
- _("Direction on which the slot is oriented:\n"
|
|
|
- "- 'X' - horizontal axis \n"
|
|
|
- "- 'Y' - vertical axis or \n"
|
|
|
- "- 'Angle' - a custom angle for the slot inclination")
|
|
|
- )
|
|
|
- self.slot_axis_label.setMinimumWidth(100)
|
|
|
+ # try:
|
|
|
+ # # Find no of slots for the current tool
|
|
|
+ # for slot in self.slot_points_edit:
|
|
|
+ # if float(slot) == tool_no:
|
|
|
+ # slot_cnt += 1
|
|
|
+ #
|
|
|
+ # self.tot_slot_cnt += slot_cnt
|
|
|
+ # except AttributeError:
|
|
|
+ # # log.debug("No slots in the Excellon file")
|
|
|
+ # # Find no of slots for the current tool
|
|
|
+ # for tool_dia in self.slot_points_edit:
|
|
|
+ # if float(tool_dia) == tool_no:
|
|
|
+ # slot_cnt = len(self.slot_points_edit[tool_dia])
|
|
|
+ #
|
|
|
+ # self.tot_slot_cnt += slot_cnt
|
|
|
|
|
|
- self.slot_axis_radio = RadioSet([{'label': _('X'), 'value': 'X'},
|
|
|
- {'label': _('Y'), 'value': 'Y'},
|
|
|
- {'label': _('Angle'), 'value': 'A'}])
|
|
|
- self.slot_form.addRow(self.slot_axis_label, self.slot_axis_radio)
|
|
|
+ for tool_dia in self.slot_points_edit:
|
|
|
+ if float(tool_dia) == tool_no:
|
|
|
+ slot_cnt = len(self.slot_points_edit[tool_dia])
|
|
|
|
|
|
- # Slot custom angle
|
|
|
- self.slot_angle_label = QtWidgets.QLabel('%s:' % _('Angle'))
|
|
|
- self.slot_angle_label.setToolTip(
|
|
|
- _("Angle at which the slot is placed.\n"
|
|
|
- "The precision is of max 2 decimals.\n"
|
|
|
- "Min value is: -360 degrees.\n"
|
|
|
- "Max value is: 360.00 degrees.")
|
|
|
- )
|
|
|
- self.slot_angle_label.setMinimumWidth(100)
|
|
|
+ self.tot_slot_cnt += slot_cnt
|
|
|
|
|
|
- self.slot_angle_spinner = FCDoubleSpinner()
|
|
|
- self.slot_angle_spinner.set_precision(self.decimals)
|
|
|
- self.slot_angle_spinner.setWrapping(True)
|
|
|
- self.slot_angle_spinner.setRange(-360.00, 360.00)
|
|
|
- self.slot_angle_spinner.setSingleStep(1.0)
|
|
|
- self.slot_form.addRow(self.slot_angle_label, self.slot_angle_spinner)
|
|
|
+ idd = QtWidgets.QTableWidgetItem('%d' % int(tool_id))
|
|
|
+ idd.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
|
+ self.e_ui.tools_table_exc.setItem(self.tool_row, 0, idd) # Tool name/id
|
|
|
|
|
|
- self.slot_frame.hide()
|
|
|
+ # Make sure that the drill diameter when in MM is with no more than 2 decimals
|
|
|
+ # There are no drill bits in MM with more than 2 decimals diameter
|
|
|
+ # For INCH the decimals should be no more than 4. There are no drills under 10mils
|
|
|
+ dia = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, self.olddia_newdia[tool_no]))
|
|
|
|
|
|
- # ######################################################
|
|
|
- # ##### ADDING SLOT ARRAY #############################
|
|
|
- # ######################################################
|
|
|
+ dia.setFlags(QtCore.Qt.ItemIsEnabled)
|
|
|
|
|
|
- # add a frame and inside add a vertical box layout. Inside this vbox layout I add
|
|
|
- # all the add slot widgets
|
|
|
- # this way I can hide/show the frame
|
|
|
- self.slot_array_frame = QtWidgets.QFrame()
|
|
|
- self.slot_array_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.tools_box.addWidget(self.slot_array_frame)
|
|
|
- self.slot_array_box = QtWidgets.QVBoxLayout()
|
|
|
- self.slot_array_box.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.slot_array_frame.setLayout(self.slot_array_box)
|
|
|
+ drill_count = QtWidgets.QTableWidgetItem('%d' % drill_cnt)
|
|
|
+ drill_count.setFlags(QtCore.Qt.ItemIsEnabled)
|
|
|
|
|
|
- self.emptyarray_label = QtWidgets.QLabel('')
|
|
|
- self.slot_array_box.addWidget(self.emptyarray_label)
|
|
|
+ # if the slot number is zero is better to not clutter the GUI with zero's so we print a space
|
|
|
+ if slot_cnt > 0:
|
|
|
+ slot_count = QtWidgets.QTableWidgetItem('%d' % slot_cnt)
|
|
|
+ else:
|
|
|
+ slot_count = QtWidgets.QTableWidgetItem('')
|
|
|
+ slot_count.setFlags(QtCore.Qt.ItemIsEnabled)
|
|
|
|
|
|
- self.slot_array_label = QtWidgets.QLabel('<b>%s</b>' % _("Slot Array Parameters"))
|
|
|
- self.slot_array_label.setToolTip(
|
|
|
- _("Parameters for the array of slots (linear or circular array)")
|
|
|
- )
|
|
|
- self.slot_array_box.addWidget(self.slot_array_label)
|
|
|
+ self.e_ui.tools_table_exc.setItem(self.tool_row, 1, dia) # Diameter
|
|
|
+ self.e_ui.tools_table_exc.setItem(self.tool_row, 2, drill_count) # Number of drills per tool
|
|
|
+ self.e_ui.tools_table_exc.setItem(self.tool_row, 3, slot_count) # Number of drills per tool
|
|
|
|
|
|
- self.l_form = QtWidgets.QFormLayout()
|
|
|
- self.slot_array_box.addLayout(self.l_form)
|
|
|
+ if first_run is True:
|
|
|
+ # set now the last tool selected
|
|
|
+ self.last_tool_selected = int(tool_id)
|
|
|
|
|
|
- self.slot_array_type_combo = FCComboBox()
|
|
|
- self.slot_array_type_combo.setToolTip(
|
|
|
- _("Select the type of slot array to create.\n"
|
|
|
- "It can be Linear X(Y) or Circular")
|
|
|
- )
|
|
|
- self.slot_array_type_combo.addItem(_("Linear"))
|
|
|
- self.slot_array_type_combo.addItem(_("Circular"))
|
|
|
+ self.tool_row += 1
|
|
|
|
|
|
- self.slot_array_box.addWidget(self.slot_array_type_combo)
|
|
|
+ # make the diameter column editable
|
|
|
+ for row in range(self.tool_row):
|
|
|
+ self.e_ui.tools_table_exc.item(row, 1).setFlags(
|
|
|
+ QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
|
+ self.e_ui.tools_table_exc.item(row, 2).setForeground(QtGui.QColor(0, 0, 0))
|
|
|
+ self.e_ui.tools_table_exc.item(row, 3).setForeground(QtGui.QColor(0, 0, 0))
|
|
|
|
|
|
- self.slot_array_form = QtWidgets.QFormLayout()
|
|
|
- self.slot_array_box.addLayout(self.slot_array_form)
|
|
|
+ # add a last row with the Total number of drills
|
|
|
+ # HACK: made the text on this cell '9999' such it will always be the one before last when sorting
|
|
|
+ # it will have to have the foreground color (font color) white
|
|
|
+ empty = QtWidgets.QTableWidgetItem('9998')
|
|
|
+ empty.setForeground(QtGui.QColor(255, 255, 255))
|
|
|
|
|
|
- # Set the number of slot holes in the slot array
|
|
|
- self.slot_array_size_label = QtWidgets.QLabel('%s:' % _('Nr of slots'))
|
|
|
- self.slot_array_size_label.setToolTip(_("Specify how many slots to be in the array."))
|
|
|
- self.slot_array_size_label.setMinimumWidth(100)
|
|
|
+ empty.setFlags(empty.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
+ empty_b = QtWidgets.QTableWidgetItem('')
|
|
|
+ empty_b.setFlags(empty_b.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
|
|
|
- self.slot_array_size_entry = FCSpinner()
|
|
|
- self.slot_array_size_entry.set_range(0, 9999)
|
|
|
+ label_tot_drill_count = QtWidgets.QTableWidgetItem(_('Total Drills'))
|
|
|
+ tot_drill_count = QtWidgets.QTableWidgetItem('%d' % self.tot_drill_cnt)
|
|
|
|
|
|
- self.slot_array_form.addRow(self.slot_array_size_label, self.slot_array_size_entry)
|
|
|
+ label_tot_drill_count.setFlags(label_tot_drill_count.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
+ tot_drill_count.setFlags(tot_drill_count.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
|
|
|
- self.slot_array_linear_frame = QtWidgets.QFrame()
|
|
|
- self.slot_array_linear_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.slot_array_box.addWidget(self.slot_array_linear_frame)
|
|
|
- self.slot_array_linear_box = QtWidgets.QVBoxLayout()
|
|
|
- self.slot_array_linear_box.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.slot_array_linear_frame.setLayout(self.slot_array_linear_box)
|
|
|
+ self.e_ui.tools_table_exc.setItem(self.tool_row, 0, empty)
|
|
|
+ self.e_ui.tools_table_exc.setItem(self.tool_row, 1, label_tot_drill_count)
|
|
|
+ self.e_ui.tools_table_exc.setItem(self.tool_row, 2, tot_drill_count) # Total number of drills
|
|
|
+ self.e_ui.tools_table_exc.setItem(self.tool_row, 3, empty_b)
|
|
|
|
|
|
- self.slot_array_linear_form = QtWidgets.QFormLayout()
|
|
|
- self.slot_array_linear_box.addLayout(self.slot_array_linear_form)
|
|
|
+ font = QtGui.QFont()
|
|
|
+ font.setBold(True)
|
|
|
+ font.setWeight(75)
|
|
|
|
|
|
- # Linear Slot Array direction
|
|
|
- self.slot_array_axis_label = QtWidgets.QLabel('%s:' % _('Direction'))
|
|
|
- self.slot_array_axis_label.setToolTip(
|
|
|
- _("Direction on which the linear array is oriented:\n"
|
|
|
- "- 'X' - horizontal axis \n"
|
|
|
- "- 'Y' - vertical axis or \n"
|
|
|
- "- 'Angle' - a custom angle for the array inclination")
|
|
|
- )
|
|
|
- self.slot_array_axis_label.setMinimumWidth(100)
|
|
|
+ for k in [1, 2]:
|
|
|
+ self.e_ui.tools_table_exc.item(self.tool_row, k).setForeground(QtGui.QColor(127, 0, 255))
|
|
|
+ self.e_ui.tools_table_exc.item(self.tool_row, k).setFont(font)
|
|
|
|
|
|
- self.slot_array_axis_radio = RadioSet([{'label': _('X'), 'value': 'X'},
|
|
|
- {'label': _('Y'), 'value': 'Y'},
|
|
|
- {'label': _('Angle'), 'value': 'A'}])
|
|
|
- self.slot_array_linear_form.addRow(self.slot_array_axis_label, self.slot_array_axis_radio)
|
|
|
+ self.tool_row += 1
|
|
|
|
|
|
- # Linear Slot Array pitch distance
|
|
|
- self.slot_array_pitch_label = QtWidgets.QLabel('%s:' % _('Pitch'))
|
|
|
- self.slot_array_pitch_label.setToolTip(
|
|
|
- _("Pitch = Distance between elements of the array.")
|
|
|
- )
|
|
|
- self.slot_array_pitch_label.setMinimumWidth(100)
|
|
|
+ # add a last row with the Total number of slots
|
|
|
+ # HACK: made the text on this cell '9999' such it will always be the last when sorting
|
|
|
+ # it will have to have the foreground color (font color) white
|
|
|
+ empty_2 = QtWidgets.QTableWidgetItem('9999')
|
|
|
+ empty_2.setForeground(QtGui.QColor(255, 255, 255))
|
|
|
|
|
|
- self.slot_array_pitch_entry = FCDoubleSpinner()
|
|
|
- self.slot_array_pitch_entry.set_precision(self.decimals)
|
|
|
- self.slot_array_pitch_entry.setSingleStep(0.1)
|
|
|
- self.slot_array_pitch_entry.setRange(0.0000, 9999.9999)
|
|
|
+ empty_2.setFlags(empty_2.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
|
|
|
- self.slot_array_linear_form.addRow(self.slot_array_pitch_label, self.slot_array_pitch_entry)
|
|
|
+ empty_3 = QtWidgets.QTableWidgetItem('')
|
|
|
+ empty_3.setFlags(empty_3.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
|
|
|
- # Linear Slot Array angle
|
|
|
- self.slot_array_linear_angle_label = QtWidgets.QLabel('%s:' % _('Angle'))
|
|
|
- self.slot_array_linear_angle_label.setToolTip(
|
|
|
- _("Angle at which the linear array is placed.\n"
|
|
|
- "The precision is of max 2 decimals.\n"
|
|
|
- "Min value is: -360 degrees.\n"
|
|
|
- "Max value is: 360.00 degrees.")
|
|
|
- )
|
|
|
- self.slot_array_linear_angle_label.setMinimumWidth(100)
|
|
|
+ label_tot_slot_count = QtWidgets.QTableWidgetItem(_('Total Slots'))
|
|
|
+ tot_slot_count = QtWidgets.QTableWidgetItem('%d' % self.tot_slot_cnt)
|
|
|
+ label_tot_slot_count.setFlags(label_tot_slot_count.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
+ tot_slot_count.setFlags(tot_slot_count.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
|
|
|
- self.slot_array_linear_angle_spinner = FCDoubleSpinner()
|
|
|
- self.slot_array_linear_angle_spinner.set_precision(self.decimals)
|
|
|
- self.slot_array_linear_angle_spinner.setSingleStep(1.0)
|
|
|
- self.slot_array_linear_angle_spinner.setRange(-360.00, 360.00)
|
|
|
- self.slot_array_linear_form.addRow(self.slot_array_linear_angle_label, self.slot_array_linear_angle_spinner)
|
|
|
+ self.e_ui.tools_table_exc.setItem(self.tool_row, 0, empty_2)
|
|
|
+ self.e_ui.tools_table_exc.setItem(self.tool_row, 1, label_tot_slot_count)
|
|
|
+ self.e_ui.tools_table_exc.setItem(self.tool_row, 2, empty_3)
|
|
|
+ self.e_ui.tools_table_exc.setItem(self.tool_row, 3, tot_slot_count) # Total number of slots
|
|
|
|
|
|
- self.slot_array_circular_frame = QtWidgets.QFrame()
|
|
|
- self.slot_array_circular_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.slot_array_box.addWidget(self.slot_array_circular_frame)
|
|
|
- self.slot_array_circular_box = QtWidgets.QVBoxLayout()
|
|
|
- self.slot_array_circular_box.setContentsMargins(0, 0, 0, 0)
|
|
|
- self.slot_array_circular_frame.setLayout(self.slot_array_circular_box)
|
|
|
+ for kl in [1, 2, 3]:
|
|
|
+ self.e_ui.tools_table_exc.item(self.tool_row, kl).setFont(font)
|
|
|
+ self.e_ui.tools_table_exc.item(self.tool_row, kl).setForeground(QtGui.QColor(0, 70, 255))
|
|
|
|
|
|
- self.slot_array_direction_label = QtWidgets.QLabel('%s:' % _('Direction'))
|
|
|
- self.slot_array_direction_label.setToolTip(_("Direction for circular array."
|
|
|
- "Can be CW = clockwise or CCW = counter clockwise."))
|
|
|
- self.slot_array_direction_label.setMinimumWidth(100)
|
|
|
+ # all the tools are selected by default
|
|
|
+ self.e_ui.tools_table_exc.selectColumn(0)
|
|
|
+ #
|
|
|
+ self.e_ui.tools_table_exc.resizeColumnsToContents()
|
|
|
+ self.e_ui.tools_table_exc.resizeRowsToContents()
|
|
|
|
|
|
- self.slot_array_circular_form = QtWidgets.QFormLayout()
|
|
|
- self.slot_array_circular_box.addLayout(self.slot_array_circular_form)
|
|
|
+ vertical_header = self.e_ui.tools_table_exc.verticalHeader()
|
|
|
+ # vertical_header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
|
|
|
+ vertical_header.hide()
|
|
|
+ self.e_ui.tools_table_exc.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
|
|
|
|
|
- self.slot_array_direction_radio = RadioSet([{'label': _('CW'), 'value': 'CW'},
|
|
|
- {'label': _('CCW'), 'value': 'CCW'}])
|
|
|
- self.slot_array_circular_form.addRow(self.slot_array_direction_label, self.slot_array_direction_radio)
|
|
|
+ horizontal_header = self.e_ui.tools_table_exc.horizontalHeader()
|
|
|
+ horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
|
|
|
+ horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
|
|
|
+ horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
|
|
|
+ horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
|
|
|
+ # horizontal_header.setStretchLastSection(True)
|
|
|
|
|
|
- self.slot_array_angle_label = QtWidgets.QLabel('%s:' % _('Angle'))
|
|
|
- self.slot_array_angle_label.setToolTip(_("Angle at which each element in circular array is placed."))
|
|
|
- self.slot_array_angle_label.setMinimumWidth(100)
|
|
|
+ # self.e_ui.tools_table_exc.setSortingEnabled(True)
|
|
|
+ # sort by tool diameter
|
|
|
+ self.e_ui.tools_table_exc.sortItems(1)
|
|
|
|
|
|
- self.slot_array_angle_entry = FCDoubleSpinner()
|
|
|
- self.slot_array_angle_entry.set_precision(self.decimals)
|
|
|
- self.slot_array_angle_entry.setSingleStep(1)
|
|
|
- self.slot_array_angle_entry.setRange(-360.00, 360.00)
|
|
|
+ # After sorting, to display also the number of drills in the right row we need to update self.initial_rows dict
|
|
|
+ # with the new order. Of course the last 2 rows in the tool table are just for display therefore we don't
|
|
|
+ # use them
|
|
|
+ self.tool2tooldia.clear()
|
|
|
+ for row in range(self.e_ui.tools_table_exc.rowCount() - 2):
|
|
|
+ tool = int(self.e_ui.tools_table_exc.item(row, 0).text())
|
|
|
+ diameter = float(self.e_ui.tools_table_exc.item(row, 1).text())
|
|
|
+ self.tool2tooldia[tool] = diameter
|
|
|
|
|
|
- self.slot_array_circular_form.addRow(self.slot_array_angle_label, self.slot_array_angle_entry)
|
|
|
+ self.e_ui.tools_table_exc.setMinimumHeight(self.e_ui.tools_table_exc.getHeight())
|
|
|
+ self.e_ui.tools_table_exc.setMaximumHeight(self.e_ui.tools_table_exc.getHeight())
|
|
|
|
|
|
- self.slot_array_linear_angle_spinner.hide()
|
|
|
- self.slot_array_linear_angle_label.hide()
|
|
|
+ # make sure no rows are selected so the user have to click the correct row, meaning selecting the correct tool
|
|
|
+ self.e_ui.tools_table_exc.clearSelection()
|
|
|
|
|
|
- self.slot_array_frame.hide()
|
|
|
+ # Remove anything else in the GUI Selected Tab
|
|
|
+ self.app.ui.selected_scroll_area.takeWidget()
|
|
|
+ # Put ourself in the GUI Selected Tab
|
|
|
+ self.app.ui.selected_scroll_area.setWidget(self.e_ui.exc_edit_widget)
|
|
|
+ # Switch notebook to Selected page
|
|
|
+ self.app.ui.notebook.setCurrentWidget(self.app.ui.selected_tab)
|
|
|
|
|
|
- layout.addStretch()
|
|
|
+ # we reactivate the signals after the after the tool adding as we don't need to see the tool been populated
|
|
|
+ self.e_ui.tools_table_exc.itemChanged.connect(self.on_tool_edit)
|
|
|
+ self.e_ui.tools_table_exc.cellPressed.connect(self.on_row_selected)
|
|
|
|
|
|
- # Editor
|
|
|
- self.exit_editor_button = QtWidgets.QPushButton(_('Exit Editor'))
|
|
|
- self.exit_editor_button.setToolTip(
|
|
|
- _("Exit from Editor.")
|
|
|
- )
|
|
|
- self.exit_editor_button.setStyleSheet("""
|
|
|
- QPushButton
|
|
|
- {
|
|
|
- font-weight: bold;
|
|
|
- }
|
|
|
- """)
|
|
|
- layout.addWidget(self.exit_editor_button)
|
|
|
+ def on_tool_add(self, tooldia=None):
|
|
|
+ self.is_modified = True
|
|
|
+ if tooldia:
|
|
|
+ tool_dia = tooldia
|
|
|
+ else:
|
|
|
+ try:
|
|
|
+ tool_dia = float(self.e_ui.addtool_entry.get_value())
|
|
|
+ except ValueError:
|
|
|
+ # try to convert comma to decimal point. if it's still not working error message and return
|
|
|
+ try:
|
|
|
+ tool_dia = float(self.e_ui.addtool_entry.get_value().replace(',', '.'))
|
|
|
+ except ValueError:
|
|
|
+ self.app.inform.emit('[ERROR_NOTCL] %s' % _("Wrong value format entered, use a number."))
|
|
|
+ return
|
|
|
|
|
|
- self.exit_editor_button.clicked.connect(lambda: self.app.editor2object())
|
|
|
+ if tool_dia not in self.olddia_newdia:
|
|
|
+ storage_elem = AppGeoEditor.make_storage()
|
|
|
+ self.storage_dict[tool_dia] = storage_elem
|
|
|
|
|
|
- # ## Toolbar events and properties
|
|
|
- self.tools_exc = {
|
|
|
- "drill_select": {"button": self.app.ui.select_drill_btn, "constructor": FCDrillSelect},
|
|
|
- "drill_add": {"button": self.app.ui.add_drill_btn, "constructor": FCDrillAdd},
|
|
|
- "drill_array": {"button": self.app.ui.add_drill_array_btn, "constructor": FCDrillArray},
|
|
|
- "slot_add": {"button": self.app.ui.add_slot_btn, "constructor": FCSlot},
|
|
|
- "slot_array": {"button": self.app.ui.add_slot_array_btn, "constructor": FCSlotArray},
|
|
|
- "drill_resize": {"button": self.app.ui.resize_drill_btn, "constructor": FCDrillResize},
|
|
|
- "drill_copy": {"button": self.app.ui.copy_drill_btn, "constructor": FCDrillCopy},
|
|
|
- "drill_move": {"button": self.app.ui.move_drill_btn, "constructor": FCDrillMove},
|
|
|
- }
|
|
|
+ # self.olddia_newdia dict keeps the evidence on current tools diameters as keys and gets updated on values
|
|
|
+ # each time a tool diameter is edited or added
|
|
|
+ self.olddia_newdia[tool_dia] = tool_dia
|
|
|
+ else:
|
|
|
+ self.app.inform.emit('[WARNING_NOTCL] %s' % _("Tool already in the original or actual tool list.\n"
|
|
|
+ "Save and reedit Excellon if you need to add this tool. "))
|
|
|
+ return
|
|
|
|
|
|
- # ## Data
|
|
|
- self.active_tool = None
|
|
|
+ # since we add a new tool, we update also the initial state of the tool_table through it's dictionary
|
|
|
+ # we add a new entry in the tool2tooldia dict
|
|
|
+ self.tool2tooldia[len(self.olddia_newdia)] = tool_dia
|
|
|
|
|
|
- self.in_action = False
|
|
|
+ self.app.inform.emit('[success] %s: %s %s' % (_("Added new tool with dia"), str(tool_dia), str(self.units)))
|
|
|
|
|
|
- self.storage_dict = {}
|
|
|
+ self.build_ui()
|
|
|
|
|
|
- self.current_storage = []
|
|
|
+ # make a quick sort through the tool2tooldia dict so we find which row to select
|
|
|
+ row_to_be_selected = None
|
|
|
+ for key in sorted(self.tool2tooldia):
|
|
|
+ if self.tool2tooldia[key] == tool_dia:
|
|
|
+ row_to_be_selected = int(key) - 1
|
|
|
+ self.last_tool_selected = int(key)
|
|
|
+ break
|
|
|
+ try:
|
|
|
+ self.e_ui.tools_table_exc.selectRow(row_to_be_selected)
|
|
|
+ except TypeError as e:
|
|
|
+ log.debug("AppExcEditor.on_tool_add() --> %s" % str(e))
|
|
|
|
|
|
- # build the data from the Excellon point into a dictionary
|
|
|
- # {tool_dia: [geometry_in_points]}
|
|
|
- self.points_edit = {}
|
|
|
- self.slot_points_edit = {}
|
|
|
+ def on_tool_delete(self, dia=None):
|
|
|
+ self.is_modified = True
|
|
|
+ deleted_tool_dia_list = []
|
|
|
|
|
|
- self.sorted_diameters = []
|
|
|
+ try:
|
|
|
+ if dia is None or dia is False:
|
|
|
+ # deleted_tool_dia = float(self.e_ui.tools_table_exc.item(self.e_ui.tools_table_exc.currentRow(), 1).text())
|
|
|
+ for index in self.e_ui.tools_table_exc.selectionModel().selectedRows():
|
|
|
+ row = index.row()
|
|
|
+ deleted_tool_dia_list.append(float(self.e_ui.tools_table_exc.item(row, 1).text()))
|
|
|
+ else:
|
|
|
+ if isinstance(dia, list):
|
|
|
+ for dd in dia:
|
|
|
+ deleted_tool_dia_list.append(float('%.*f' % (self.decimals, dd)))
|
|
|
+ else:
|
|
|
+ deleted_tool_dia_list.append(float('%.*f' % (self.decimals, dia)))
|
|
|
+ except Exception:
|
|
|
+ self.app.inform.emit('[WARNING_NOTCL] %s' % _("Select a tool in Tool Table"))
|
|
|
+ return
|
|
|
|
|
|
- self.new_tools = {}
|
|
|
+ for deleted_tool_dia in deleted_tool_dia_list:
|
|
|
|
|
|
- # dictionary to store the tool_row and diameters in Tool_table
|
|
|
- # it will be updated everytime self.build_ui() is called
|
|
|
- self.olddia_newdia = {}
|
|
|
+ # delete the storage used for that tool
|
|
|
+ storage_elem = AppGeoEditor.make_storage()
|
|
|
+ self.storage_dict[deleted_tool_dia] = storage_elem
|
|
|
+ self.storage_dict.pop(deleted_tool_dia, None)
|
|
|
|
|
|
- self.tool2tooldia = {}
|
|
|
+ # I've added this flag_del variable because dictionary don't like
|
|
|
+ # having keys deleted while iterating through them
|
|
|
+ flag_del = []
|
|
|
+ # self.points_edit.pop(deleted_tool_dia, None)
|
|
|
+ for deleted_tool in self.tool2tooldia:
|
|
|
+ if self.tool2tooldia[deleted_tool] == deleted_tool_dia:
|
|
|
+ flag_del.append(deleted_tool)
|
|
|
|
|
|
- # this will store the value for the last selected tool, for use after clicking on canvas when the selection
|
|
|
- # is cleared but as a side effect also the selected tool is cleared
|
|
|
- self.last_tool_selected = None
|
|
|
- self.utility = []
|
|
|
+ if flag_del:
|
|
|
+ for tool_to_be_deleted in flag_del:
|
|
|
+ # delete the tool
|
|
|
+ self.tool2tooldia.pop(tool_to_be_deleted, None)
|
|
|
|
|
|
- # this will flag if the Editor "tools" are launched from key shortcuts (True) or from menu toolbar (False)
|
|
|
- self.launched_from_shortcuts = False
|
|
|
+ # delete also the drills from points_edit dict just in case we add the tool again,
|
|
|
+ # we don't want to show the number of drills from before was deleter
|
|
|
+ self.points_edit[deleted_tool_dia] = []
|
|
|
|
|
|
- # this var will store the state of the toolbar before starting the editor
|
|
|
- self.toolbar_old_state = False
|
|
|
+ self.olddia_newdia.pop(deleted_tool_dia, None)
|
|
|
|
|
|
- if self.units == 'MM':
|
|
|
- self.tolerance = float(self.app.defaults["global_tolerance"])
|
|
|
- else:
|
|
|
- self.tolerance = float(self.app.defaults["global_tolerance"]) / 20
|
|
|
+ self.app.inform.emit('[success] %s: %s %s' %
|
|
|
+ (_("Deleted tool with diameter"), str(deleted_tool_dia), str(self.units)))
|
|
|
|
|
|
- self.app.ui.delete_drill_btn.triggered.connect(self.on_delete_btn)
|
|
|
- self.name_entry.returnPressed.connect(self.on_name_activate)
|
|
|
- self.addtool_btn.clicked.connect(self.on_tool_add)
|
|
|
- self.addtool_entry.editingFinished.connect(self.on_tool_add)
|
|
|
- self.deltool_btn.clicked.connect(self.on_tool_delete)
|
|
|
- # self.tools_table_exc.selectionModel().currentChanged.connect(self.on_row_selected)
|
|
|
- self.tools_table_exc.cellPressed.connect(self.on_row_selected)
|
|
|
+ self.replot()
|
|
|
+ # self.app.inform.emit("Could not delete selected tool")
|
|
|
|
|
|
- self.array_type_combo.currentIndexChanged.connect(self.on_array_type_combo)
|
|
|
- self.slot_array_type_combo.currentIndexChanged.connect(self.on_slot_array_type_combo)
|
|
|
+ self.build_ui()
|
|
|
|
|
|
- self.drill_axis_radio.activated_custom.connect(self.on_linear_angle_radio)
|
|
|
- self.slot_axis_radio.activated_custom.connect(self.on_slot_angle_radio)
|
|
|
+ def on_tool_edit(self, item_changed):
|
|
|
+ # if connected, disconnect the signal from the slot on item_changed as it creates issues
|
|
|
+ try:
|
|
|
+ self.e_ui.tools_table_exc.itemChanged.disconnect()
|
|
|
+ except TypeError:
|
|
|
+ pass
|
|
|
|
|
|
- self.slot_array_axis_radio.activated_custom.connect(self.on_slot_array_linear_angle_radio)
|
|
|
+ try:
|
|
|
+ self.e_ui.tools_table_exc.cellPressed.disconnect()
|
|
|
+ except TypeError:
|
|
|
+ pass
|
|
|
+ # self.e_ui.tools_table_exc.selectionModel().currentChanged.disconnect()
|
|
|
|
|
|
- self.app.ui.exc_add_array_drill_menuitem.triggered.connect(self.exc_add_drill_array)
|
|
|
- self.app.ui.exc_add_drill_menuitem.triggered.connect(self.exc_add_drill)
|
|
|
+ self.is_modified = True
|
|
|
+ # new_dia = None
|
|
|
|
|
|
- self.app.ui.exc_add_array_slot_menuitem.triggered.connect(self.exc_add_slot_array)
|
|
|
- self.app.ui.exc_add_slot_menuitem.triggered.connect(self.exc_add_slot)
|
|
|
+ try:
|
|
|
+ new_dia = float(self.e_ui.tools_table_exc.currentItem().text())
|
|
|
+ except ValueError as e:
|
|
|
+ log.debug("AppExcEditor.on_tool_edit() --> %s" % str(e))
|
|
|
+ return
|
|
|
|
|
|
- self.app.ui.exc_resize_drill_menuitem.triggered.connect(self.exc_resize_drills)
|
|
|
- self.app.ui.exc_copy_drill_menuitem.triggered.connect(self.exc_copy_drills)
|
|
|
- self.app.ui.exc_delete_drill_menuitem.triggered.connect(self.on_delete_btn)
|
|
|
+ row_of_item_changed = self.e_ui.tools_table_exc.currentRow()
|
|
|
+ # rows start with 0, tools start with 1 so we adjust the value by 1
|
|
|
+ key_in_tool2tooldia = row_of_item_changed + 1
|
|
|
+ old_dia = self.tool2tooldia[key_in_tool2tooldia]
|
|
|
|
|
|
- self.app.ui.exc_move_drill_menuitem.triggered.connect(self.exc_move_drills)
|
|
|
+ # SOURCE storage
|
|
|
+ source_storage = self.storage_dict[old_dia]
|
|
|
|
|
|
- self.exc_obj = None
|
|
|
+ # DESTINATION storage
|
|
|
+ # tool diameter is not used so we create a new tool with the desired diameter
|
|
|
+ if new_dia not in self.olddia_newdia:
|
|
|
+ destination_storage = AppGeoEditor.make_storage()
|
|
|
+ self.storage_dict[new_dia] = destination_storage
|
|
|
|
|
|
- # VisPy Visuals
|
|
|
- if self.app.is_legacy is False:
|
|
|
- self.shapes = self.app.plotcanvas.new_shape_collection(layers=1)
|
|
|
- if self.app.plotcanvas.big_cursor is True:
|
|
|
- self.tool_shape = self.app.plotcanvas.new_shape_collection(layers=1, line_width=2)
|
|
|
- else:
|
|
|
- self.tool_shape = self.app.plotcanvas.new_shape_collection(layers=1)
|
|
|
+ # self.olddia_newdia dict keeps the evidence on current tools diameters as keys and gets updated on values
|
|
|
+ # each time a tool diameter is edited or added
|
|
|
+ self.olddia_newdia[new_dia] = new_dia
|
|
|
else:
|
|
|
- from appGUI.PlotCanvasLegacy import ShapeCollectionLegacy
|
|
|
- self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='shapes_exc_editor')
|
|
|
- self.tool_shape = ShapeCollectionLegacy(obj=self, app=self.app, name='tool_shapes_exc_editor')
|
|
|
+ # tool diameter is already in use so we move the drills from the prior tool to the new tool
|
|
|
+ destination_storage = self.storage_dict[new_dia]
|
|
|
|
|
|
- self.app.pool_recreated.connect(self.pool_recreated)
|
|
|
+ # since we add a new tool, we update also the intial state of the tool_table through it's dictionary
|
|
|
+ # we add a new entry in the tool2tooldia dict
|
|
|
+ self.tool2tooldia[len(self.olddia_newdia)] = new_dia
|
|
|
|
|
|
- # Remove from scene
|
|
|
- self.shapes.enabled = False
|
|
|
- self.tool_shape.enabled = False
|
|
|
+ # CHANGE the elements geometry according to the new diameter
|
|
|
+ factor = new_dia / old_dia
|
|
|
+ new_geo = Polygon()
|
|
|
+ for shape_exc in source_storage.get_objects():
|
|
|
+ geo_list = []
|
|
|
+ if isinstance(shape_exc.geo, MultiLineString):
|
|
|
+ for subgeo in shape_exc.geo:
|
|
|
+ geo_list.append(affinity.scale(subgeo, xfact=factor, yfact=factor, origin='center'))
|
|
|
+ new_geo = MultiLineString(geo_list)
|
|
|
+ elif isinstance(shape_exc.geo, Polygon):
|
|
|
+ # I don't have any info regarding the angle of the slot geometry, nor how thick it is or
|
|
|
+ # how long it is given the angle. So I will have to make an approximation because
|
|
|
+ # we need to conserve the slot length, we only resize the diameter for the tool
|
|
|
+ # Therefore scaling won't work and buffering will not work either.
|
|
|
|
|
|
- # ## List of selected shapes.
|
|
|
- self.selected = []
|
|
|
+ # First we get the Linestring that is one that the original slot is built around with the
|
|
|
+ # tool having the diameter sel_dia
|
|
|
+ poly = shape_exc.geo
|
|
|
+ xmin, ymin, xmax, ymax = poly.bounds
|
|
|
+ # a line that is certain to be bigger than our slot because it's the diagonal
|
|
|
+ # of it's bounding box
|
|
|
+ poly_diagonal = LineString([(xmin, ymin), (xmax, ymax)])
|
|
|
+ poly_centroid = poly.centroid
|
|
|
+ # center of the slot geometry
|
|
|
+ poly_center = (poly_centroid.x, poly_centroid.y)
|
|
|
|
|
|
- self.move_timer = QtCore.QTimer()
|
|
|
- self.move_timer.setSingleShot(True)
|
|
|
+ # make a list of intersections with the rotated line
|
|
|
+ list_of_cuttings = []
|
|
|
+ for angle in range(0, 359, 1):
|
|
|
+ rot_poly_diagonal = affinity.rotate(poly_diagonal, angle=angle, origin=poly_center)
|
|
|
+ cut_line = rot_poly_diagonal.intersection(poly)
|
|
|
+ cut_line_len = cut_line.length
|
|
|
+ list_of_cuttings.append(
|
|
|
+ (cut_line_len, cut_line)
|
|
|
+ )
|
|
|
+ # find the cut_line with the maximum length which is the LineString for which the start
|
|
|
+ # and stop point are the start and stop point of the slot as in the Gerber file
|
|
|
+ cut_line_with_max_length = max(list_of_cuttings, key=lambda i: i[0])[1]
|
|
|
+ # find the coordinates of this line
|
|
|
+ cut_line_with_max_length_coords = list(cut_line_with_max_length.coords)
|
|
|
+ # extract the first and last point of the line and build some buffered polygon circles
|
|
|
+ # around them
|
|
|
+ start_pt = Point(cut_line_with_max_length_coords[0])
|
|
|
+ stop_pt = Point(cut_line_with_max_length_coords[1])
|
|
|
+ start_cut_geo = start_pt.buffer(new_dia / 2)
|
|
|
+ stop_cut_geo = stop_pt.buffer(new_dia / 2)
|
|
|
|
|
|
- self.key = None # Currently pressed key
|
|
|
- self.modifiers = None
|
|
|
- self.x = None # Current mouse cursor pos
|
|
|
- self.y = None
|
|
|
- # Current snapped mouse pos
|
|
|
- self.snap_x = None
|
|
|
- self.snap_y = None
|
|
|
- self.pos = None
|
|
|
+ # and we cut the above circle polygons from our line and get in this way a line around
|
|
|
+ # which we can build the new slot by buffering with the new tool diameter
|
|
|
+ new_line = cut_line_with_max_length.difference(start_cut_geo)
|
|
|
+ new_line = new_line.difference(stop_cut_geo)
|
|
|
|
|
|
- self.complete = False
|
|
|
+ # create the geometry for the resized slot by buffering with half of the
|
|
|
+ # new diameter value: new_dia
|
|
|
+ new_geo = new_line.buffer(new_dia / 2)
|
|
|
|
|
|
- def make_callback(thetool):
|
|
|
- def f():
|
|
|
- self.on_tool_select(thetool)
|
|
|
- return f
|
|
|
+ try:
|
|
|
+ self.points_edit.pop(old_dia, None)
|
|
|
+ except KeyError:
|
|
|
+ pass
|
|
|
+ try:
|
|
|
+ self.slot_points_edit.pop(old_dia, None)
|
|
|
+ except KeyError:
|
|
|
+ pass
|
|
|
|
|
|
- for tool in self.tools_exc:
|
|
|
- self.tools_exc[tool]["button"].triggered.connect(make_callback(tool)) # Events
|
|
|
- self.tools_exc[tool]["button"].setCheckable(True) # Checkable
|
|
|
+ # add bogus drill/slots points (for total count of drills/slots)
|
|
|
+ # for drills
|
|
|
+ if isinstance(shape_exc.geo, MultiLineString):
|
|
|
+ if new_dia not in self.points_edit:
|
|
|
+ self.points_edit[new_dia] = [(0, 0)]
|
|
|
+ else:
|
|
|
+ self.points_edit[new_dia].append((0, 0))
|
|
|
|
|
|
- self.options = {
|
|
|
- "global_gridx": 0.1,
|
|
|
- "global_gridy": 0.1,
|
|
|
- "snap_max": 0.05,
|
|
|
- "grid_snap": True,
|
|
|
- "corner_snap": False,
|
|
|
- "grid_gap_link": True
|
|
|
- }
|
|
|
- self.options.update(self.app.options)
|
|
|
+ # for slots
|
|
|
+ if isinstance(shape_exc.geo, Polygon):
|
|
|
+ if new_dia not in self.slot_points_edit:
|
|
|
+ self.slot_points_edit[new_dia] = [(0, 0)]
|
|
|
+ else:
|
|
|
+ self.slot_points_edit[new_dia].append((0, 0))
|
|
|
|
|
|
- for option in self.options:
|
|
|
- if option in self.app.options:
|
|
|
- self.options[option] = self.app.options[option]
|
|
|
+ self.add_exc_shape(shape=DrawToolShape(new_geo), storage=destination_storage)
|
|
|
|
|
|
- self.data_defaults = {
|
|
|
- "plot": self.app.defaults["excellon_plot"],
|
|
|
- "solid": self.app.defaults["excellon_solid"],
|
|
|
-
|
|
|
- "operation": self.app.defaults["excellon_operation"],
|
|
|
- "milling_type": self.app.defaults["excellon_milling_type"],
|
|
|
-
|
|
|
- "milling_dia": self.app.defaults["excellon_milling_dia"],
|
|
|
-
|
|
|
- "cutz": self.app.defaults["excellon_cutz"],
|
|
|
- "multidepth": self.app.defaults["excellon_multidepth"],
|
|
|
- "depthperpass": self.app.defaults["excellon_depthperpass"],
|
|
|
- "travelz": self.app.defaults["excellon_travelz"],
|
|
|
- "feedrate": self.app.defaults["geometry_feedrate"],
|
|
|
- "feedrate_z": self.app.defaults["excellon_feedrate_z"],
|
|
|
- "feedrate_rapid": self.app.defaults["excellon_feedrate_rapid"],
|
|
|
- "tooldia": self.app.defaults["excellon_tooldia"],
|
|
|
- "slot_tooldia": self.app.defaults["excellon_slot_tooldia"],
|
|
|
- "toolchange": self.app.defaults["excellon_toolchange"],
|
|
|
- "toolchangez": self.app.defaults["excellon_toolchangez"],
|
|
|
- "toolchangexy": self.app.defaults["excellon_toolchangexy"],
|
|
|
- "extracut": self.app.defaults["geometry_extracut"],
|
|
|
- "extracut_length": self.app.defaults["geometry_extracut_length"],
|
|
|
- "endz": self.app.defaults["excellon_endz"],
|
|
|
- "endxy": self.app.defaults["excellon_endxy"],
|
|
|
- "startz": self.app.defaults["excellon_startz"],
|
|
|
- "offset": self.app.defaults["excellon_offset"],
|
|
|
- "spindlespeed": self.app.defaults["excellon_spindlespeed"],
|
|
|
- "dwell": self.app.defaults["excellon_dwell"],
|
|
|
- "dwelltime": self.app.defaults["excellon_dwelltime"],
|
|
|
- "ppname_e": self.app.defaults["excellon_ppname_e"],
|
|
|
- "ppname_g": self.app.defaults["geometry_ppname_g"],
|
|
|
- "z_pdepth": self.app.defaults["excellon_z_pdepth"],
|
|
|
- "feedrate_probe": self.app.defaults["excellon_feedrate_probe"],
|
|
|
- "optimization_type": self.app.defaults["excellon_optimization_type"]
|
|
|
- }
|
|
|
+ # update the UI and the CANVAS
|
|
|
+ self.build_ui()
|
|
|
+ self.replot()
|
|
|
|
|
|
- self.rtree_exc_index = rtindex.Index()
|
|
|
- # flag to show if the object was modified
|
|
|
- self.is_modified = False
|
|
|
+ # delete the old tool
|
|
|
+ self.on_tool_delete(dia=old_dia)
|
|
|
|
|
|
- self.edited_obj_name = ""
|
|
|
+ # we reactivate the signals after the after the tool editing
|
|
|
+ self.e_ui.tools_table_exc.itemChanged.connect(self.on_tool_edit)
|
|
|
+ self.e_ui.tools_table_exc.cellPressed.connect(self.on_row_selected)
|
|
|
|
|
|
- # variable to store the total amount of drills per job
|
|
|
- self.tot_drill_cnt = 0
|
|
|
- self.tool_row = 0
|
|
|
+ self.app.inform.emit('[success] %s' % _("Done. Tool edit completed."))
|
|
|
|
|
|
- # variable to store the total amount of slots per job
|
|
|
- self.tot_slot_cnt = 0
|
|
|
- self.tool_row_slots = 0
|
|
|
+ # self.e_ui.tools_table_exc.selectionModel().currentChanged.connect(self.on_row_selected)
|
|
|
|
|
|
- self.tool_row = 0
|
|
|
+ def on_name_activate(self):
|
|
|
+ self.edited_obj_name = self.e_ui.name_entry.get_value()
|
|
|
|
|
|
- # store the status of the editor so the Delete at object level will not work until the edit is finished
|
|
|
- self.editor_active = False
|
|
|
+ def activate(self):
|
|
|
+ # adjust the status of the menu entries related to the editor
|
|
|
+ self.app.ui.menueditedit.setDisabled(True)
|
|
|
+ self.app.ui.menueditok.setDisabled(False)
|
|
|
+ # adjust the visibility of some of the canvas context menu
|
|
|
+ self.app.ui.popmenu_edit.setVisible(False)
|
|
|
+ self.app.ui.popmenu_save.setVisible(True)
|
|
|
|
|
|
- # def entry2option(option, entry):
|
|
|
- # self.options[option] = float(entry.text())
|
|
|
+ self.connect_canvas_event_handlers()
|
|
|
|
|
|
- # Event signals disconnect id holders
|
|
|
- self.mp = None
|
|
|
- self.mm = None
|
|
|
- self.mr = None
|
|
|
+ # initialize working objects
|
|
|
+ self.storage_dict = {}
|
|
|
+ self.current_storage = []
|
|
|
+ self.points_edit = {}
|
|
|
+ self.sorted_diameters = []
|
|
|
+ self.new_drills = []
|
|
|
+ self.new_tools = {}
|
|
|
+ self.new_slots = []
|
|
|
|
|
|
- # store the status of the editor so the Delete at object level will not work until the edit is finished
|
|
|
- self.editor_active = False
|
|
|
- log.debug("Initialization of the Excellon Editor is finished ...")
|
|
|
+ self.olddia_newdia = {}
|
|
|
|
|
|
- def pool_recreated(self, pool):
|
|
|
- self.shapes.pool = pool
|
|
|
- self.tool_shape.pool = pool
|
|
|
+ self.shapes.enabled = True
|
|
|
+ self.tool_shape.enabled = True
|
|
|
+ # self.app.app_cursor.enabled = True
|
|
|
|
|
|
- @staticmethod
|
|
|
- def make_storage():
|
|
|
- # ## Shape storage.
|
|
|
- storage = FlatCAMRTreeStorage()
|
|
|
- storage.get_points = DrawToolShape.get_pts
|
|
|
+ self.app.ui.corner_snap_btn.setVisible(True)
|
|
|
+ self.app.ui.snap_magnet.setVisible(True)
|
|
|
|
|
|
- return storage
|
|
|
+ self.app.ui.exc_editor_menu.setDisabled(False)
|
|
|
+ self.app.ui.exc_editor_menu.menuAction().setVisible(True)
|
|
|
|
|
|
- def set_ui(self):
|
|
|
- # updated units
|
|
|
- self.units = self.app.defaults['units'].upper()
|
|
|
+ self.app.ui.update_obj_btn.setEnabled(True)
|
|
|
+ self.app.ui.e_editor_cmenu.setEnabled(True)
|
|
|
|
|
|
- self.olddia_newdia.clear()
|
|
|
- self.tool2tooldia.clear()
|
|
|
+ self.app.ui.exc_edit_toolbar.setDisabled(False)
|
|
|
+ self.app.ui.exc_edit_toolbar.setVisible(True)
|
|
|
+ # self.app.ui.grid_toolbar.setDisabled(False)
|
|
|
|
|
|
- # build the self.points_edit dict {dimaters: [point_list]}
|
|
|
- for tool, tool_dict in self.exc_obj.tools.items():
|
|
|
- tool_dia = float('%.*f' % (self.decimals, self.exc_obj.tools[tool]['tooldia']))
|
|
|
+ # start with GRID toolbar activated
|
|
|
+ if self.app.ui.grid_snap_btn.isChecked() is False:
|
|
|
+ self.app.ui.grid_snap_btn.trigger()
|
|
|
|
|
|
- if 'drills' in tool_dict and tool_dict['drills']:
|
|
|
- for drill in tool_dict['drills']:
|
|
|
- try:
|
|
|
- self.points_edit[tool_dia].append(drill)
|
|
|
- except KeyError:
|
|
|
- self.points_edit[tool_dia] = [drill]
|
|
|
+ self.app.ui.popmenu_disable.setVisible(False)
|
|
|
+ self.app.ui.cmenu_newmenu.menuAction().setVisible(False)
|
|
|
+ self.app.ui.popmenu_properties.setVisible(False)
|
|
|
+ self.app.ui.e_editor_cmenu.menuAction().setVisible(True)
|
|
|
+ self.app.ui.g_editor_cmenu.menuAction().setVisible(False)
|
|
|
+ self.app.ui.grb_editor_cmenu.menuAction().setVisible(False)
|
|
|
|
|
|
- # build the self.slot_points_edit dict {dimaters: {"start": Point, "stop": Point}}
|
|
|
- for tool, tool_dict in self.exc_obj.tools.items():
|
|
|
- tool_dia = float('%.*f' % (self.decimals, self.exc_obj.tools[tool]['tooldia']))
|
|
|
-
|
|
|
- if 'slots' in tool_dict and tool_dict['slots']:
|
|
|
- for slot in tool_dict['slots']:
|
|
|
- try:
|
|
|
- self.slot_points_edit[tool_dia].append({
|
|
|
- "start": slot[0],
|
|
|
- "stop": slot[1]
|
|
|
- })
|
|
|
- except KeyError:
|
|
|
- self.slot_points_edit[tool_dia] = [{
|
|
|
- "start": slot[0],
|
|
|
- "stop": slot[1]
|
|
|
- }]
|
|
|
+ # Tell the App that the editor is active
|
|
|
+ self.editor_active = True
|
|
|
|
|
|
+ # show the UI
|
|
|
+ self.e_ui.drills_frame.show()
|
|
|
|
|
|
- # update the olddia_newdia dict to make sure we have an updated state of the tool_table
|
|
|
- for key in self.points_edit:
|
|
|
- self.olddia_newdia[key] = key
|
|
|
+ def deactivate(self):
|
|
|
+ try:
|
|
|
+ QtGui.QGuiApplication.restoreOverrideCursor()
|
|
|
+ except Exception:
|
|
|
+ pass
|
|
|
|
|
|
- for key in self.slot_points_edit:
|
|
|
- if key not in self.olddia_newdia:
|
|
|
- self.olddia_newdia[key] = key
|
|
|
+ # adjust the status of the menu entries related to the editor
|
|
|
+ self.app.ui.menueditedit.setDisabled(False)
|
|
|
+ self.app.ui.menueditok.setDisabled(True)
|
|
|
+ # adjust the visibility of some of the canvas context menu
|
|
|
+ self.app.ui.popmenu_edit.setVisible(True)
|
|
|
+ self.app.ui.popmenu_save.setVisible(False)
|
|
|
|
|
|
- sort_temp = []
|
|
|
- for diam in self.olddia_newdia:
|
|
|
- sort_temp.append(float(diam))
|
|
|
- self.sorted_diameters = sorted(sort_temp)
|
|
|
+ self.disconnect_canvas_event_handlers()
|
|
|
+ self.clear()
|
|
|
+ self.app.ui.exc_edit_toolbar.setDisabled(True)
|
|
|
|
|
|
- # populate self.intial_table_rows dict with the tool number as keys and tool diameters as values
|
|
|
- if self.exc_obj.diameterless is False:
|
|
|
- for i in range(len(self.sorted_diameters)):
|
|
|
- tt_dia = self.sorted_diameters[i]
|
|
|
- self.tool2tooldia[i + 1] = tt_dia
|
|
|
- else:
|
|
|
- # the Excellon object has diameters that are bogus information, added by the application because the
|
|
|
- # Excellon file has no tool diameter information. In this case do not order the diameter in the table
|
|
|
- # but use the real order found in the exc_obj.tools
|
|
|
- for k, v in self.exc_obj.tools.items():
|
|
|
- tool_dia = float('%.*f' % (self.decimals, v['tooldia']))
|
|
|
- self.tool2tooldia[int(k)] = tool_dia
|
|
|
+ self.app.ui.corner_snap_btn.setVisible(False)
|
|
|
+ self.app.ui.snap_magnet.setVisible(False)
|
|
|
|
|
|
- # Init appGUI
|
|
|
- self.addtool_entry.set_value(float(self.app.defaults['excellon_editor_newdia']))
|
|
|
- self.drill_array_size_entry.set_value(int(self.app.defaults['excellon_editor_array_size']))
|
|
|
- self.drill_axis_radio.set_value(self.app.defaults['excellon_editor_lin_dir'])
|
|
|
- self.drill_pitch_entry.set_value(float(self.app.defaults['excellon_editor_lin_pitch']))
|
|
|
- self.linear_angle_spinner.set_value(float(self.app.defaults['excellon_editor_lin_angle']))
|
|
|
- self.drill_direction_radio.set_value(self.app.defaults['excellon_editor_circ_dir'])
|
|
|
- self.drill_angle_entry.set_value(float(self.app.defaults['excellon_editor_circ_angle']))
|
|
|
-
|
|
|
- self.slot_length_entry.set_value(float(self.app.defaults['excellon_editor_slot_length']))
|
|
|
- self.slot_axis_radio.set_value(self.app.defaults['excellon_editor_slot_direction'])
|
|
|
- self.slot_angle_spinner.set_value(float(self.app.defaults['excellon_editor_slot_angle']))
|
|
|
-
|
|
|
- self.slot_array_size_entry.set_value(int(self.app.defaults['excellon_editor_slot_array_size']))
|
|
|
- self.slot_array_axis_radio.set_value(self.app.defaults['excellon_editor_slot_lin_dir'])
|
|
|
- self.slot_array_pitch_entry.set_value(float(self.app.defaults['excellon_editor_slot_lin_pitch']))
|
|
|
- self.slot_array_linear_angle_spinner.set_value(float(self.app.defaults['excellon_editor_slot_lin_angle']))
|
|
|
- self.slot_array_direction_radio.set_value(self.app.defaults['excellon_editor_slot_circ_dir'])
|
|
|
- self.slot_array_angle_entry.set_value(float(self.app.defaults['excellon_editor_slot_circ_angle']))
|
|
|
-
|
|
|
- self.slot_array_circular_frame.hide()
|
|
|
- self.slot_array_linear_frame.show()
|
|
|
+ # set the Editor Toolbar visibility to what was before entering in the Editor
|
|
|
+ self.app.ui.exc_edit_toolbar.setVisible(False) if self.toolbar_old_state is False \
|
|
|
+ else self.app.ui.exc_edit_toolbar.setVisible(True)
|
|
|
|
|
|
- def build_ui(self, first_run=None):
|
|
|
+ # Disable visuals
|
|
|
+ self.shapes.enabled = False
|
|
|
+ self.tool_shape.enabled = False
|
|
|
+ # self.app.app_cursor.enabled = False
|
|
|
|
|
|
- try:
|
|
|
- # if connected, disconnect the signal from the slot on item_changed as it creates issues
|
|
|
- self.tools_table_exc.itemChanged.disconnect()
|
|
|
- except (TypeError, AttributeError):
|
|
|
- pass
|
|
|
+ # Tell the app that the editor is no longer active
|
|
|
+ self.editor_active = False
|
|
|
|
|
|
- try:
|
|
|
- self.tools_table_exc.cellPressed.disconnect()
|
|
|
- except (TypeError, AttributeError):
|
|
|
- pass
|
|
|
+ self.app.ui.exc_editor_menu.setDisabled(True)
|
|
|
+ self.app.ui.exc_editor_menu.menuAction().setVisible(False)
|
|
|
|
|
|
- # updated units
|
|
|
- self.units = self.app.defaults['units'].upper()
|
|
|
+ self.app.ui.update_obj_btn.setEnabled(False)
|
|
|
|
|
|
- # make a new name for the new Excellon object (the one with edited content)
|
|
|
- self.edited_obj_name = self.exc_obj.options['name']
|
|
|
- self.name_entry.set_value(self.edited_obj_name)
|
|
|
+ self.app.ui.popmenu_disable.setVisible(True)
|
|
|
+ self.app.ui.cmenu_newmenu.menuAction().setVisible(True)
|
|
|
+ self.app.ui.popmenu_properties.setVisible(True)
|
|
|
+ self.app.ui.g_editor_cmenu.menuAction().setVisible(False)
|
|
|
+ self.app.ui.e_editor_cmenu.menuAction().setVisible(False)
|
|
|
+ self.app.ui.grb_editor_cmenu.menuAction().setVisible(False)
|
|
|
|
|
|
- sort_temp = []
|
|
|
+ # Show original geometry
|
|
|
+ if self.exc_obj:
|
|
|
+ self.exc_obj.visible = True
|
|
|
|
|
|
- for diam in self.olddia_newdia:
|
|
|
- sort_temp.append(float(diam))
|
|
|
- self.sorted_diameters = sorted(sort_temp)
|
|
|
+ # hide the UI
|
|
|
+ self.e_ui.drills_frame.hide()
|
|
|
|
|
|
- # here, self.sorted_diameters will hold in a oblique way, the number of tools
|
|
|
- n = len(self.sorted_diameters)
|
|
|
- # we have (n+2) rows because there are 'n' tools, each a row, plus the last 2 rows for totals.
|
|
|
- self.tools_table_exc.setRowCount(n + 2)
|
|
|
+ def connect_canvas_event_handlers(self):
|
|
|
+ # ## Canvas events
|
|
|
|
|
|
- self.tot_drill_cnt = 0
|
|
|
- self.tot_slot_cnt = 0
|
|
|
+ # first connect to new, then disconnect the old handlers
|
|
|
+ # don't ask why but if there is nothing connected I've seen issues
|
|
|
+ self.mp = self.canvas.graph_event_connect('mouse_press', self.on_canvas_click)
|
|
|
+ self.mm = self.canvas.graph_event_connect('mouse_move', self.on_canvas_move)
|
|
|
+ self.mr = self.canvas.graph_event_connect('mouse_release', self.on_exc_click_release)
|
|
|
|
|
|
- self.tool_row = 0
|
|
|
- # this variable will serve as the real tool_number
|
|
|
- tool_id = 0
|
|
|
+ # make sure that the shortcuts key and mouse events will no longer be linked to the methods from FlatCAMApp
|
|
|
+ # but those from AppGeoEditor
|
|
|
+ if self.app.is_legacy is False:
|
|
|
+ self.app.plotcanvas.graph_event_disconnect('mouse_press', self.app.on_mouse_click_over_plot)
|
|
|
+ self.app.plotcanvas.graph_event_disconnect('mouse_move', self.app.on_mouse_move_over_plot)
|
|
|
+ self.app.plotcanvas.graph_event_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot)
|
|
|
+ self.app.plotcanvas.graph_event_disconnect('mouse_double_click', self.app.on_mouse_double_click_over_plot)
|
|
|
+ else:
|
|
|
+ self.app.plotcanvas.graph_event_disconnect(self.app.mp)
|
|
|
+ self.app.plotcanvas.graph_event_disconnect(self.app.mm)
|
|
|
+ self.app.plotcanvas.graph_event_disconnect(self.app.mr)
|
|
|
+ self.app.plotcanvas.graph_event_disconnect(self.app.mdc)
|
|
|
|
|
|
- for tool_no in self.sorted_diameters:
|
|
|
- tool_id += 1
|
|
|
- drill_cnt = 0 # variable to store the nr of drills per tool
|
|
|
- slot_cnt = 0 # variable to store the nr of slots per tool
|
|
|
+ self.app.collection.view.clicked.disconnect()
|
|
|
|
|
|
- # Find no of drills for the current tool
|
|
|
- for tool_dia in self.points_edit:
|
|
|
- if float(tool_dia) == tool_no:
|
|
|
- drill_cnt = len(self.points_edit[tool_dia])
|
|
|
+ self.app.ui.popmenu_copy.triggered.disconnect()
|
|
|
+ self.app.ui.popmenu_delete.triggered.disconnect()
|
|
|
+ self.app.ui.popmenu_move.triggered.disconnect()
|
|
|
|
|
|
- self.tot_drill_cnt += drill_cnt
|
|
|
+ self.app.ui.popmenu_copy.triggered.connect(self.exc_copy_drills)
|
|
|
+ self.app.ui.popmenu_delete.triggered.connect(self.on_delete_btn)
|
|
|
+ self.app.ui.popmenu_move.triggered.connect(self.exc_move_drills)
|
|
|
|
|
|
- # try:
|
|
|
- # # Find no of slots for the current tool
|
|
|
- # for slot in self.slot_points_edit:
|
|
|
- # if float(slot) == tool_no:
|
|
|
- # slot_cnt += 1
|
|
|
- #
|
|
|
- # self.tot_slot_cnt += slot_cnt
|
|
|
- # except AttributeError:
|
|
|
- # # log.debug("No slots in the Excellon file")
|
|
|
- # # Find no of slots for the current tool
|
|
|
- # for tool_dia in self.slot_points_edit:
|
|
|
- # if float(tool_dia) == tool_no:
|
|
|
- # slot_cnt = len(self.slot_points_edit[tool_dia])
|
|
|
- #
|
|
|
- # self.tot_slot_cnt += slot_cnt
|
|
|
+ # Excellon Editor
|
|
|
+ self.app.ui.drill.triggered.connect(self.exc_add_drill)
|
|
|
+ self.app.ui.drill_array.triggered.connect(self.exc_add_drill_array)
|
|
|
|
|
|
- for tool_dia in self.slot_points_edit:
|
|
|
- if float(tool_dia) == tool_no:
|
|
|
- slot_cnt = len(self.slot_points_edit[tool_dia])
|
|
|
+ def disconnect_canvas_event_handlers(self):
|
|
|
+ # we restore the key and mouse control to FlatCAMApp method
|
|
|
+ # first connect to new, then disconnect the old handlers
|
|
|
+ # don't ask why but if there is nothing connected I've seen issues
|
|
|
+ self.app.mp = self.app.plotcanvas.graph_event_connect('mouse_press', self.app.on_mouse_click_over_plot)
|
|
|
+ self.app.mm = self.app.plotcanvas.graph_event_connect('mouse_move', self.app.on_mouse_move_over_plot)
|
|
|
+ self.app.mr = self.app.plotcanvas.graph_event_connect('mouse_release',
|
|
|
+ self.app.on_mouse_click_release_over_plot)
|
|
|
+ self.app.mdc = self.app.plotcanvas.graph_event_connect('mouse_double_click',
|
|
|
+ self.app.on_mouse_double_click_over_plot)
|
|
|
+ self.app.collection.view.clicked.connect(self.app.collection.on_mouse_down)
|
|
|
|
|
|
- self.tot_slot_cnt += slot_cnt
|
|
|
+ if self.app.is_legacy is False:
|
|
|
+ self.canvas.graph_event_disconnect('mouse_press', self.on_canvas_click)
|
|
|
+ self.canvas.graph_event_disconnect('mouse_move', self.on_canvas_move)
|
|
|
+ self.canvas.graph_event_disconnect('mouse_release', self.on_exc_click_release)
|
|
|
+ else:
|
|
|
+ self.canvas.graph_event_disconnect(self.mp)
|
|
|
+ self.canvas.graph_event_disconnect(self.mm)
|
|
|
+ self.canvas.graph_event_disconnect(self.mr)
|
|
|
|
|
|
- idd = QtWidgets.QTableWidgetItem('%d' % int(tool_id))
|
|
|
- idd.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
|
- self.tools_table_exc.setItem(self.tool_row, 0, idd) # Tool name/id
|
|
|
+ try:
|
|
|
+ self.app.ui.popmenu_copy.triggered.disconnect(self.exc_copy_drills)
|
|
|
+ except (TypeError, AttributeError):
|
|
|
+ pass
|
|
|
|
|
|
- # Make sure that the drill diameter when in MM is with no more than 2 decimals
|
|
|
- # There are no drill bits in MM with more than 2 decimals diameter
|
|
|
- # For INCH the decimals should be no more than 4. There are no drills under 10mils
|
|
|
- dia = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, self.olddia_newdia[tool_no]))
|
|
|
+ try:
|
|
|
+ self.app.ui.popmenu_delete.triggered.disconnect(self.on_delete_btn)
|
|
|
+ except (TypeError, AttributeError):
|
|
|
+ pass
|
|
|
|
|
|
- dia.setFlags(QtCore.Qt.ItemIsEnabled)
|
|
|
+ try:
|
|
|
+ self.app.ui.popmenu_move.triggered.disconnect(self.exc_move_drills)
|
|
|
+ except (TypeError, AttributeError):
|
|
|
+ pass
|
|
|
|
|
|
- drill_count = QtWidgets.QTableWidgetItem('%d' % drill_cnt)
|
|
|
- drill_count.setFlags(QtCore.Qt.ItemIsEnabled)
|
|
|
+ self.app.ui.popmenu_copy.triggered.connect(self.app.on_copy_command)
|
|
|
+ self.app.ui.popmenu_delete.triggered.connect(self.app.on_delete)
|
|
|
+ self.app.ui.popmenu_move.triggered.connect(self.app.obj_move)
|
|
|
|
|
|
- # if the slot number is zero is better to not clutter the GUI with zero's so we print a space
|
|
|
- if slot_cnt > 0:
|
|
|
- slot_count = QtWidgets.QTableWidgetItem('%d' % slot_cnt)
|
|
|
- else:
|
|
|
- slot_count = QtWidgets.QTableWidgetItem('')
|
|
|
- slot_count.setFlags(QtCore.Qt.ItemIsEnabled)
|
|
|
+ # Excellon Editor
|
|
|
+ try:
|
|
|
+ self.app.ui.drill.triggered.disconnect(self.exc_add_drill)
|
|
|
+ except (TypeError, AttributeError):
|
|
|
+ pass
|
|
|
|
|
|
- self.tools_table_exc.setItem(self.tool_row, 1, dia) # Diameter
|
|
|
- self.tools_table_exc.setItem(self.tool_row, 2, drill_count) # Number of drills per tool
|
|
|
- self.tools_table_exc.setItem(self.tool_row, 3, slot_count) # Number of drills per tool
|
|
|
+ try:
|
|
|
+ self.app.ui.drill_array.triggered.disconnect(self.exc_add_drill_array)
|
|
|
+ except (TypeError, AttributeError):
|
|
|
+ pass
|
|
|
|
|
|
- if first_run is True:
|
|
|
- # set now the last tool selected
|
|
|
- self.last_tool_selected = int(tool_id)
|
|
|
+ try:
|
|
|
+ self.app.jump_signal.disconnect()
|
|
|
+ except (TypeError, AttributeError):
|
|
|
+ pass
|
|
|
|
|
|
- self.tool_row += 1
|
|
|
+ def clear(self):
|
|
|
+ self.active_tool = None
|
|
|
+ # self.shape_buffer = []
|
|
|
+ self.selected = []
|
|
|
|
|
|
- # make the diameter column editable
|
|
|
- for row in range(self.tool_row):
|
|
|
- self.tools_table_exc.item(row, 1).setFlags(
|
|
|
- QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
|
- self.tools_table_exc.item(row, 2).setForeground(QtGui.QColor(0, 0, 0))
|
|
|
- self.tools_table_exc.item(row, 3).setForeground(QtGui.QColor(0, 0, 0))
|
|
|
+ self.points_edit = {}
|
|
|
+ self.new_tools = {}
|
|
|
+ self.new_drills = []
|
|
|
|
|
|
- # add a last row with the Total number of drills
|
|
|
- # HACK: made the text on this cell '9999' such it will always be the one before last when sorting
|
|
|
- # it will have to have the foreground color (font color) white
|
|
|
- empty = QtWidgets.QTableWidgetItem('9998')
|
|
|
- empty.setForeground(QtGui.QColor(255, 255, 255))
|
|
|
+ # self.storage_dict = {}
|
|
|
|
|
|
- empty.setFlags(empty.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
- empty_b = QtWidgets.QTableWidgetItem('')
|
|
|
- empty_b.setFlags(empty_b.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
+ self.shapes.clear(update=True)
|
|
|
+ self.tool_shape.clear(update=True)
|
|
|
|
|
|
- label_tot_drill_count = QtWidgets.QTableWidgetItem(_('Total Drills'))
|
|
|
- tot_drill_count = QtWidgets.QTableWidgetItem('%d' % self.tot_drill_cnt)
|
|
|
+ # self.storage = AppExcEditor.make_storage()
|
|
|
+ self.replot()
|
|
|
|
|
|
- label_tot_drill_count.setFlags(label_tot_drill_count.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
- tot_drill_count.setFlags(tot_drill_count.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
+ def edit_fcexcellon(self, exc_obj):
|
|
|
+ """
|
|
|
+ Imports the geometry from the given FlatCAM Excellon object
|
|
|
+ into the editor.
|
|
|
|
|
|
- self.tools_table_exc.setItem(self.tool_row, 0, empty)
|
|
|
- self.tools_table_exc.setItem(self.tool_row, 1, label_tot_drill_count)
|
|
|
- self.tools_table_exc.setItem(self.tool_row, 2, tot_drill_count) # Total number of drills
|
|
|
- self.tools_table_exc.setItem(self.tool_row, 3, empty_b)
|
|
|
+ :param exc_obj: ExcellonObject object
|
|
|
+ :return: None
|
|
|
+ """
|
|
|
|
|
|
- font = QtGui.QFont()
|
|
|
- font.setBold(True)
|
|
|
- font.setWeight(75)
|
|
|
+ self.deactivate()
|
|
|
+ self.activate()
|
|
|
|
|
|
- for k in [1, 2]:
|
|
|
- self.tools_table_exc.item(self.tool_row, k).setForeground(QtGui.QColor(127, 0, 255))
|
|
|
- self.tools_table_exc.item(self.tool_row, k).setFont(font)
|
|
|
-
|
|
|
- self.tool_row += 1
|
|
|
-
|
|
|
- # add a last row with the Total number of slots
|
|
|
- # HACK: made the text on this cell '9999' such it will always be the last when sorting
|
|
|
- # it will have to have the foreground color (font color) white
|
|
|
- empty_2 = QtWidgets.QTableWidgetItem('9999')
|
|
|
- empty_2.setForeground(QtGui.QColor(255, 255, 255))
|
|
|
-
|
|
|
- empty_2.setFlags(empty_2.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
-
|
|
|
- empty_3 = QtWidgets.QTableWidgetItem('')
|
|
|
- empty_3.setFlags(empty_3.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
+ # Hide original geometry
|
|
|
+ self.exc_obj = exc_obj
|
|
|
+ exc_obj.visible = False
|
|
|
|
|
|
- label_tot_slot_count = QtWidgets.QTableWidgetItem(_('Total Slots'))
|
|
|
- tot_slot_count = QtWidgets.QTableWidgetItem('%d' % self.tot_slot_cnt)
|
|
|
- label_tot_slot_count.setFlags(label_tot_slot_count.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
- tot_slot_count.setFlags(tot_slot_count.flags() ^ QtCore.Qt.ItemIsEnabled)
|
|
|
+ if self.exc_obj:
|
|
|
+ outname = self.exc_obj.options['name']
|
|
|
+ else:
|
|
|
+ outname = ''
|
|
|
|
|
|
- self.tools_table_exc.setItem(self.tool_row, 0, empty_2)
|
|
|
- self.tools_table_exc.setItem(self.tool_row, 1, label_tot_slot_count)
|
|
|
- self.tools_table_exc.setItem(self.tool_row, 2, empty_3)
|
|
|
- self.tools_table_exc.setItem(self.tool_row, 3, tot_slot_count) # Total number of slots
|
|
|
+ self.data_defaults = {
|
|
|
+ "name": outname + '_drill',
|
|
|
+ "plot": self.app.defaults["excellon_plot"],
|
|
|
+ "solid": self.app.defaults["excellon_solid"],
|
|
|
+ "multicolored": self.app.defaults["excellon_multicolored"],
|
|
|
+ "merge_fuse_tools": self.app.defaults["excellon_merge_fuse_tools"],
|
|
|
+ "format_upper_in": self.app.defaults["excellon_format_upper_in"],
|
|
|
+ "format_lower_in": self.app.defaults["excellon_format_lower_in"],
|
|
|
+ "format_upper_mm": self.app.defaults["excellon_format_upper_mm"],
|
|
|
+ "lower_mm": self.app.defaults["excellon_format_lower_mm"],
|
|
|
+ "zeros": self.app.defaults["excellon_zeros"],
|
|
|
+
|
|
|
+ "tools_drill_tool_order": self.app.defaults["tools_drill_tool_order"],
|
|
|
+ "tools_drill_cutz": self.app.defaults["tools_drill_cutz"],
|
|
|
+ "tools_drill_multidepth": self.app.defaults["tools_drill_multidepth"],
|
|
|
+ "tools_drill_depthperpass": self.app.defaults["tools_drill_depthperpass"],
|
|
|
+ "tools_drill_travelz": self.app.defaults["tools_drill_travelz"],
|
|
|
+
|
|
|
+ "tools_drill_feedrate_z": self.app.defaults["tools_drill_feedrate_z"],
|
|
|
+ "tools_drill_feedrate_rapid": self.app.defaults["tools_drill_feedrate_rapid"],
|
|
|
+
|
|
|
+ "tools_drill_toolchange": self.app.defaults["tools_drill_toolchange"],
|
|
|
+ "tools_drill_toolchangez": self.app.defaults["tools_drill_toolchangez"],
|
|
|
+ "tools_drill_toolchangexy": self.app.defaults["tools_drill_toolchangexy"],
|
|
|
+
|
|
|
+ # Drill Slots
|
|
|
+ "tools_drill_drill_slots": self.app.defaults["tools_drill_drill_slots"],
|
|
|
+ "tools_drill_drill_overlap": self.app.defaults["tools_drill_drill_overlap"],
|
|
|
+ "tools_drill_last_drill": self.app.defaults["tools_drill_last_drill"],
|
|
|
+
|
|
|
+ "tools_drill_endz": self.app.defaults["tools_drill_endz"],
|
|
|
+ "tools_drill_endxy": self.app.defaults["tools_drill_endxy"],
|
|
|
+ "tools_drill_startz": self.app.defaults["tools_drill_startz"],
|
|
|
+ "tools_drill_offset": self.app.defaults["tools_drill_offset"],
|
|
|
+ "tools_drill_spindlespeed": self.app.defaults["tools_drill_spindlespeed"],
|
|
|
+ "tools_drill_dwell": self.app.defaults["tools_drill_dwell"],
|
|
|
+ "tools_drill_dwelltime": self.app.defaults["tools_drill_dwelltime"],
|
|
|
+ "tools_drill_ppname_e": self.app.defaults["tools_drill_ppname_e"],
|
|
|
+ "tools_drill_z_pdepth": self.app.defaults["tools_drill_z_pdepth"],
|
|
|
+ "tools_drill_feedrate_probe": self.app.defaults["tools_drill_feedrate_probe"],
|
|
|
+ "tools_drill_spindledir": self.app.defaults["tools_drill_spindledir"],
|
|
|
+ "tools_drill_f_plunge": self.app.defaults["tools_drill_f_plunge"],
|
|
|
+ "tools_drill_f_retract": self.app.defaults["tools_drill_f_retract"],
|
|
|
+
|
|
|
+ "tools_drill_area_exclusion": self.app.defaults["tools_drill_area_exclusion"],
|
|
|
+ "tools_drill_area_shape": self.app.defaults["tools_drill_area_shape"],
|
|
|
+ "tools_drill_area_strategy": self.app.defaults["tools_drill_area_strategy"],
|
|
|
+ "tools_drill_area_overz": self.app.defaults["tools_drill_area_overz"],
|
|
|
+ }
|
|
|
|
|
|
- for kl in [1, 2, 3]:
|
|
|
- self.tools_table_exc.item(self.tool_row, kl).setFont(font)
|
|
|
- self.tools_table_exc.item(self.tool_row, kl).setForeground(QtGui.QColor(0, 70, 255))
|
|
|
+ # fill in self.default_data values from self.options
|
|
|
+ for opt_key, opt_val in self.app.options.items():
|
|
|
+ if opt_key.find('excellon_') == 0:
|
|
|
+ self.data_defaults[opt_key] = deepcopy(opt_val)
|
|
|
|
|
|
- # all the tools are selected by default
|
|
|
- self.tools_table_exc.selectColumn(0)
|
|
|
- #
|
|
|
- self.tools_table_exc.resizeColumnsToContents()
|
|
|
- self.tools_table_exc.resizeRowsToContents()
|
|
|
+ self.points_edit = {}
|
|
|
+ # build the self.points_edit dict {dimaters: [point_list]}
|
|
|
+ for tool, tool_dict in self.exc_obj.tools.items():
|
|
|
+ tool_dia = self.dec_format(self.exc_obj.tools[tool]['tooldia'])
|
|
|
|
|
|
- vertical_header = self.tools_table_exc.verticalHeader()
|
|
|
- # vertical_header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
|
|
|
- vertical_header.hide()
|
|
|
- self.tools_table_exc.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
|
|
+ if 'drills' in tool_dict and tool_dict['drills']:
|
|
|
+ for drill in tool_dict['drills']:
|
|
|
+ try:
|
|
|
+ self.points_edit[tool_dia].append(drill)
|
|
|
+ except KeyError:
|
|
|
+ self.points_edit[tool_dia] = [drill]
|
|
|
|
|
|
- horizontal_header = self.tools_table_exc.horizontalHeader()
|
|
|
- horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
|
|
|
- horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
|
|
|
- horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
|
|
|
- horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
|
|
|
- # horizontal_header.setStretchLastSection(True)
|
|
|
+ self.slot_points_edit = {}
|
|
|
+ # build the self.slot_points_edit dict {dimaters: {"start": Point, "stop": Point}}
|
|
|
+ for tool, tool_dict in self.exc_obj.tools.items():
|
|
|
+ tool_dia = float('%.*f' % (self.decimals, self.exc_obj.tools[tool]['tooldia']))
|
|
|
|
|
|
- # self.tools_table_exc.setSortingEnabled(True)
|
|
|
- # sort by tool diameter
|
|
|
- self.tools_table_exc.sortItems(1)
|
|
|
+ if 'slots' in tool_dict and tool_dict['slots']:
|
|
|
+ for slot in tool_dict['slots']:
|
|
|
+ try:
|
|
|
+ self.slot_points_edit[tool_dia].append({
|
|
|
+ "start": slot[0],
|
|
|
+ "stop": slot[1]
|
|
|
+ })
|
|
|
+ except KeyError:
|
|
|
+ self.slot_points_edit[tool_dia] = [{
|
|
|
+ "start": slot[0],
|
|
|
+ "stop": slot[1]
|
|
|
+ }]
|
|
|
|
|
|
- # After sorting, to display also the number of drills in the right row we need to update self.initial_rows dict
|
|
|
- # with the new order. Of course the last 2 rows in the tool table are just for display therefore we don't
|
|
|
- # use them
|
|
|
- self.tool2tooldia.clear()
|
|
|
- for row in range(self.tools_table_exc.rowCount() - 2):
|
|
|
- tool = int(self.tools_table_exc.item(row, 0).text())
|
|
|
- diameter = float(self.tools_table_exc.item(row, 1).text())
|
|
|
- self.tool2tooldia[tool] = diameter
|
|
|
+ # Set selection tolerance
|
|
|
+ # DrawToolShape.tolerance = fc_excellon.drawing_tolerance * 10
|
|
|
|
|
|
- self.tools_table_exc.setMinimumHeight(self.tools_table_exc.getHeight())
|
|
|
- self.tools_table_exc.setMaximumHeight(self.tools_table_exc.getHeight())
|
|
|
+ self.select_tool("drill_select")
|
|
|
|
|
|
- # make sure no rows are selected so the user have to click the correct row, meaning selecting the correct tool
|
|
|
- self.tools_table_exc.clearSelection()
|
|
|
+ # reset the tool table
|
|
|
+ self.e_ui.tools_table_exc.clear()
|
|
|
+ self.e_ui.tools_table_exc.setHorizontalHeaderLabels(['#', _('Diameter'), 'D', 'S'])
|
|
|
+ self.last_tool_selected = None
|
|
|
|
|
|
- # Remove anything else in the GUI Selected Tab
|
|
|
- self.app.ui.selected_scroll_area.takeWidget()
|
|
|
- # Put ourself in the GUI Selected Tab
|
|
|
- self.app.ui.selected_scroll_area.setWidget(self.exc_edit_widget)
|
|
|
- # Switch notebook to Selected page
|
|
|
- self.app.ui.notebook.setCurrentWidget(self.app.ui.selected_tab)
|
|
|
+ self.set_ui()
|
|
|
|
|
|
- # we reactivate the signals after the after the tool adding as we don't need to see the tool been populated
|
|
|
- self.tools_table_exc.itemChanged.connect(self.on_tool_edit)
|
|
|
- self.tools_table_exc.cellPressed.connect(self.on_row_selected)
|
|
|
+ # now that we hava data, create the appGUI interface and add it to the Tool Tab
|
|
|
+ self.build_ui(first_run=True)
|
|
|
|
|
|
- def on_tool_add(self, tooldia=None):
|
|
|
- self.is_modified = True
|
|
|
- if tooldia:
|
|
|
- tool_dia = tooldia
|
|
|
- else:
|
|
|
- try:
|
|
|
- tool_dia = float(self.addtool_entry.get_value())
|
|
|
- except ValueError:
|
|
|
- # try to convert comma to decimal point. if it's still not working error message and return
|
|
|
- try:
|
|
|
- tool_dia = float(self.addtool_entry.get_value().replace(',', '.'))
|
|
|
- except ValueError:
|
|
|
- self.app.inform.emit('[ERROR_NOTCL] %s' %
|
|
|
- _("Wrong value format entered, use a number."))
|
|
|
- return
|
|
|
+ # we activate this after the initial build as we don't need to see the tool been populated
|
|
|
+ self.e_ui.tools_table_exc.itemChanged.connect(self.on_tool_edit)
|
|
|
|
|
|
- if tool_dia not in self.olddia_newdia:
|
|
|
+ # build the geometry for each tool-diameter, each drill will be represented by a '+' symbol
|
|
|
+ # and then add it to the storage elements (each storage elements is a member of a list
|
|
|
+ for tool_dia in self.points_edit:
|
|
|
storage_elem = AppGeoEditor.make_storage()
|
|
|
+ for point in self.points_edit[tool_dia]:
|
|
|
+ # make a '+' sign, the line length is the tool diameter
|
|
|
+ start_hor_line = ((point.x - (tool_dia / 2)), point.y)
|
|
|
+ stop_hor_line = ((point.x + (tool_dia / 2)), point.y)
|
|
|
+ start_vert_line = (point.x, (point.y - (tool_dia / 2)))
|
|
|
+ stop_vert_line = (point.x, (point.y + (tool_dia / 2)))
|
|
|
+ shape_geo = MultiLineString([(start_hor_line, stop_hor_line), (start_vert_line, stop_vert_line)])
|
|
|
+ if shape_geo is not None:
|
|
|
+ self.add_exc_shape(DrawToolShape(shape_geo), storage_elem)
|
|
|
self.storage_dict[tool_dia] = storage_elem
|
|
|
|
|
|
- # self.olddia_newdia dict keeps the evidence on current tools diameters as keys and gets updated on values
|
|
|
- # each time a tool diameter is edited or added
|
|
|
- self.olddia_newdia[tool_dia] = tool_dia
|
|
|
- else:
|
|
|
- self.app.inform.emit('[WARNING_NOTCL] %s' % _("Tool already in the original or actual tool list.\n"
|
|
|
- "Save and reedit Excellon if you need to add this tool. "))
|
|
|
- return
|
|
|
+ # slots
|
|
|
+ for tool_dia in self.slot_points_edit:
|
|
|
+ buf_value = float(tool_dia) / 2
|
|
|
+ for elem_dict in self.slot_points_edit[tool_dia]:
|
|
|
|
|
|
- # since we add a new tool, we update also the initial state of the tool_table through it's dictionary
|
|
|
- # we add a new entry in the tool2tooldia dict
|
|
|
- self.tool2tooldia[len(self.olddia_newdia)] = tool_dia
|
|
|
+ line_geo = LineString([elem_dict['start'], elem_dict['stop']])
|
|
|
+ shape_geo = line_geo.buffer(buf_value)
|
|
|
|
|
|
- self.app.inform.emit('[success] %s: %s %s' %
|
|
|
- (_("Added new tool with dia"), str(tool_dia), str(self.units)))
|
|
|
+ if tool_dia not in self.storage_dict:
|
|
|
+ storage_elem = AppGeoEditor.make_storage()
|
|
|
+ self.storage_dict[tool_dia] = storage_elem
|
|
|
|
|
|
- self.build_ui()
|
|
|
+ if shape_geo is not None:
|
|
|
+ self.add_exc_shape(DrawToolShape(shape_geo), self.storage_dict[tool_dia])
|
|
|
|
|
|
- # make a quick sort through the tool2tooldia dict so we find which row to select
|
|
|
- row_to_be_selected = None
|
|
|
- for key in sorted(self.tool2tooldia):
|
|
|
- if self.tool2tooldia[key] == tool_dia:
|
|
|
- row_to_be_selected = int(key) - 1
|
|
|
- self.last_tool_selected = int(key)
|
|
|
- break
|
|
|
- try:
|
|
|
- self.tools_table_exc.selectRow(row_to_be_selected)
|
|
|
- except TypeError as e:
|
|
|
- log.debug("AppExcEditor.on_tool_add() --> %s" % str(e))
|
|
|
+ self.replot()
|
|
|
|
|
|
- def on_tool_delete(self, dia=None):
|
|
|
- self.is_modified = True
|
|
|
- deleted_tool_dia_list = []
|
|
|
+ # add a first tool in the Tool Table but only if the Excellon Object is empty
|
|
|
+ if not self.tool2tooldia:
|
|
|
+ self.on_tool_add(self.dec_format(float(self.app.defaults['excellon_editor_newdia'])))
|
|
|
|
|
|
- try:
|
|
|
- if dia is None or dia is False:
|
|
|
- # deleted_tool_dia = float(self.tools_table_exc.item(self.tools_table_exc.currentRow(), 1).text())
|
|
|
- for index in self.tools_table_exc.selectionModel().selectedRows():
|
|
|
- row = index.row()
|
|
|
- deleted_tool_dia_list.append(float(self.tools_table_exc.item(row, 1).text()))
|
|
|
- else:
|
|
|
- if isinstance(dia, list):
|
|
|
- for dd in dia:
|
|
|
- deleted_tool_dia_list.append(float('%.*f' % (self.decimals, dd)))
|
|
|
- else:
|
|
|
- deleted_tool_dia_list.append(float('%.*f' % (self.decimals, dia)))
|
|
|
- except Exception:
|
|
|
- self.app.inform.emit('[WARNING_NOTCL] %s' % _("Select a tool in Tool Table"))
|
|
|
- return
|
|
|
+ def update_fcexcellon(self, exc_obj):
|
|
|
+ """
|
|
|
+ Create a new Excellon object that contain the edited content of the source Excellon object
|
|
|
|
|
|
- for deleted_tool_dia in deleted_tool_dia_list:
|
|
|
+ :param exc_obj: ExcellonObject
|
|
|
+ :return: None
|
|
|
+ """
|
|
|
|
|
|
- # delete the storage used for that tool
|
|
|
- storage_elem = AppGeoEditor.make_storage()
|
|
|
- self.storage_dict[deleted_tool_dia] = storage_elem
|
|
|
- self.storage_dict.pop(deleted_tool_dia, None)
|
|
|
+ # this dictionary will contain tooldia's as keys and a list of coordinates tuple as values
|
|
|
+ # the values of this dict are coordinates of the holes (drills)
|
|
|
+ edited_points = {}
|
|
|
|
|
|
- # I've added this flag_del variable because dictionary don't like
|
|
|
- # having keys deleted while iterating through them
|
|
|
- flag_del = []
|
|
|
- # self.points_edit.pop(deleted_tool_dia, None)
|
|
|
- for deleted_tool in self.tool2tooldia:
|
|
|
- if self.tool2tooldia[deleted_tool] == deleted_tool_dia:
|
|
|
- flag_del.append(deleted_tool)
|
|
|
+ """
|
|
|
+ - this dictionary will contain tooldia's as keys and a list of another dicts as values
|
|
|
+ - the dict element of the list has the structure
|
|
|
+ ================ ====================================
|
|
|
+ Key Value
|
|
|
+ ================ ====================================
|
|
|
+ start (Shapely.Point) Start point of the slot
|
|
|
+ stop (Shapely.Point) Stop point of the slot
|
|
|
+ ================ ====================================
|
|
|
+ """
|
|
|
+ edited_slot_points = {}
|
|
|
|
|
|
- if flag_del:
|
|
|
- for tool_to_be_deleted in flag_del:
|
|
|
- # delete the tool
|
|
|
- self.tool2tooldia.pop(tool_to_be_deleted, None)
|
|
|
+ for storage_tooldia in self.storage_dict:
|
|
|
+ for x in self.storage_dict[storage_tooldia].get_objects():
|
|
|
+ if isinstance(x.geo, MultiLineString):
|
|
|
+ # all x.geo in self.storage_dict[storage] are MultiLinestring objects for drills
|
|
|
+ # each MultiLineString is made out of Linestrings
|
|
|
+ # select first Linestring object in the current MultiLineString
|
|
|
+ first_linestring = x.geo[0]
|
|
|
+ # get it's coordinates
|
|
|
+ first_linestring_coords = first_linestring.coords
|
|
|
+ x_coord = first_linestring_coords[0][0] + (float(first_linestring.length / 2))
|
|
|
+ y_coord = first_linestring_coords[0][1]
|
|
|
|
|
|
- # delete also the drills from points_edit dict just in case we add the tool again,
|
|
|
- # we don't want to show the number of drills from before was deleter
|
|
|
- self.points_edit[deleted_tool_dia] = []
|
|
|
+ # create a tuple with the coordinates (x, y) and add it to the list that is the value of the
|
|
|
+ # edited_points dictionary
|
|
|
+ point = (x_coord, y_coord)
|
|
|
+ if storage_tooldia not in edited_points:
|
|
|
+ edited_points[storage_tooldia] = [point]
|
|
|
+ else:
|
|
|
+ edited_points[storage_tooldia].append(point)
|
|
|
+ elif isinstance(x.geo, Polygon):
|
|
|
+ # create a tuple with the points (start, stop) and add it to the list that is the value of the
|
|
|
+ # edited_points dictionary
|
|
|
|
|
|
- self.olddia_newdia.pop(deleted_tool_dia, None)
|
|
|
+ # first determine the start and stop coordinates for the slot knowing the geometry and the tool
|
|
|
+ # diameter
|
|
|
+ radius = float(storage_tooldia) / 2
|
|
|
+ radius = radius - 0.0000001
|
|
|
|
|
|
- self.app.inform.emit('[success] %s: %s %s' %
|
|
|
- (_("Deleted tool with diameter"), str(deleted_tool_dia), str(self.units)))
|
|
|
+ poly = x.geo
|
|
|
+ poly = poly.buffer(-radius)
|
|
|
|
|
|
- self.replot()
|
|
|
- # self.app.inform.emit("Could not delete selected tool")
|
|
|
+ if not poly.is_valid or poly.is_empty:
|
|
|
+ # print("Polygon not valid: %s" % str(poly.wkt))
|
|
|
+ continue
|
|
|
|
|
|
- self.build_ui()
|
|
|
+ xmin, ymin, xmax, ymax = poly.bounds
|
|
|
+ line_one = LineString([(xmin, ymin), (xmax, ymax)]).intersection(poly).length
|
|
|
+ line_two = LineString([(xmin, ymax), (xmax, ymin)]).intersection(poly).length
|
|
|
|
|
|
- def on_tool_edit(self, item_changed):
|
|
|
- # if connected, disconnect the signal from the slot on item_changed as it creates issues
|
|
|
- try:
|
|
|
- self.tools_table_exc.itemChanged.disconnect()
|
|
|
- except TypeError:
|
|
|
- pass
|
|
|
+ if line_one < line_two:
|
|
|
+ point_elem = {
|
|
|
+ "start": (xmin, ymax),
|
|
|
+ "stop": (xmax, ymin)
|
|
|
+ }
|
|
|
+ else:
|
|
|
+ point_elem = {
|
|
|
+ "start": (xmin, ymin),
|
|
|
+ "stop": (xmax, ymax)
|
|
|
+ }
|
|
|
|
|
|
- try:
|
|
|
- self.tools_table_exc.cellPressed.disconnect()
|
|
|
- except TypeError:
|
|
|
- pass
|
|
|
- # self.tools_table_exc.selectionModel().currentChanged.disconnect()
|
|
|
+ if storage_tooldia not in edited_slot_points:
|
|
|
+ edited_slot_points[storage_tooldia] = [point_elem]
|
|
|
+ else:
|
|
|
+ edited_slot_points[storage_tooldia].append(point_elem)
|
|
|
|
|
|
- self.is_modified = True
|
|
|
- # new_dia = None
|
|
|
+ # recreate the drills and tools to be added to the new Excellon edited object
|
|
|
+ # first, we look in the tool table if one of the tool diameters was changed then
|
|
|
+ # append that a tuple formed by (old_dia, edited_dia) to a list
|
|
|
+ changed_key = set()
|
|
|
+ for initial_dia in self.olddia_newdia:
|
|
|
+ edited_dia = self.olddia_newdia[initial_dia]
|
|
|
+ if edited_dia != initial_dia:
|
|
|
+ # for drills
|
|
|
+ for old_dia in edited_points:
|
|
|
+ if old_dia == initial_dia:
|
|
|
+ changed_key.add((old_dia, edited_dia))
|
|
|
+ # for slots
|
|
|
+ for old_dia in edited_slot_points:
|
|
|
+ if old_dia == initial_dia:
|
|
|
+ changed_key.add((old_dia, edited_dia))
|
|
|
+ # if the initial_dia is not in edited_points it means it is a new tool with no drill points
|
|
|
+ # (and we have to add it)
|
|
|
+ # because in case we have drill points it will have to be already added in edited_points
|
|
|
+ # if initial_dia not in edited_points.keys():
|
|
|
+ # edited_points[initial_dia] = []
|
|
|
|
|
|
- try:
|
|
|
- new_dia = float(self.tools_table_exc.currentItem().text())
|
|
|
- except ValueError as e:
|
|
|
- log.debug("AppExcEditor.on_tool_edit() --> %s" % str(e))
|
|
|
- return
|
|
|
+ for el in changed_key:
|
|
|
+ edited_points[el[1]] = edited_points.pop(el[0])
|
|
|
+ edited_slot_points[el[1]] = edited_slot_points.pop(el[0])
|
|
|
|
|
|
- row_of_item_changed = self.tools_table_exc.currentRow()
|
|
|
- # rows start with 0, tools start with 1 so we adjust the value by 1
|
|
|
- key_in_tool2tooldia = row_of_item_changed + 1
|
|
|
- old_dia = self.tool2tooldia[key_in_tool2tooldia]
|
|
|
+ # Let's sort the edited_points dictionary by keys (diameters) and store the result in a zipped list
|
|
|
+ # ordered_edited_points is a ordered list of tuples;
|
|
|
+ # element[0] of the tuple is the diameter and
|
|
|
+ # element[1] of the tuple is a list of coordinates (a tuple themselves)
|
|
|
+ ordered_edited_points = sorted(zip(edited_points.keys(), edited_points.values()))
|
|
|
|
|
|
- # SOURCE storage
|
|
|
- source_storage = self.storage_dict[old_dia]
|
|
|
+ current_tool = 0
|
|
|
+ for tool_dia in ordered_edited_points:
|
|
|
+ current_tool += 1
|
|
|
|
|
|
- # DESTINATION storage
|
|
|
- # tool diameter is not used so we create a new tool with the desired diameter
|
|
|
- if new_dia not in self.olddia_newdia:
|
|
|
- destination_storage = AppGeoEditor.make_storage()
|
|
|
- self.storage_dict[new_dia] = destination_storage
|
|
|
+ # create the self.tools for the new Excellon object (the one with edited content)
|
|
|
+ if current_tool not in self.new_tools:
|
|
|
+ self.new_tools[current_tool] = {}
|
|
|
+ self.new_tools[current_tool]['tooldia'] = float(tool_dia[0])
|
|
|
|
|
|
- # self.olddia_newdia dict keeps the evidence on current tools diameters as keys and gets updated on values
|
|
|
- # each time a tool diameter is edited or added
|
|
|
- self.olddia_newdia[new_dia] = new_dia
|
|
|
- else:
|
|
|
- # tool diameter is already in use so we move the drills from the prior tool to the new tool
|
|
|
- destination_storage = self.storage_dict[new_dia]
|
|
|
+ # add in self.tools the 'solid_geometry' key, the value (a list) is populated below
|
|
|
+ self.new_tools[current_tool]['solid_geometry'] = []
|
|
|
|
|
|
- # since we add a new tool, we update also the intial state of the tool_table through it's dictionary
|
|
|
- # we add a new entry in the tool2tooldia dict
|
|
|
- self.tool2tooldia[len(self.olddia_newdia)] = new_dia
|
|
|
+ # create the self.drills for the new Excellon object (the one with edited content)
|
|
|
+ for point in tool_dia[1]:
|
|
|
+ try:
|
|
|
+ self.new_tools[current_tool]['drills'].append(Point(point))
|
|
|
+ except KeyError:
|
|
|
+ self.new_tools[current_tool]['drills'] = [Point(point)]
|
|
|
|
|
|
- # CHANGE the elements geometry according to the new diameter
|
|
|
- factor = new_dia / old_dia
|
|
|
- new_geo = Polygon()
|
|
|
- for shape_exc in source_storage.get_objects():
|
|
|
- geo_list = []
|
|
|
- if isinstance(shape_exc.geo, MultiLineString):
|
|
|
- for subgeo in shape_exc.geo:
|
|
|
- geo_list.append(affinity.scale(subgeo, xfact=factor, yfact=factor, origin='center'))
|
|
|
- new_geo = MultiLineString(geo_list)
|
|
|
- elif isinstance(shape_exc.geo, Polygon):
|
|
|
- # I don't have any info regarding the angle of the slot geometry, nor how thick it is or
|
|
|
- # how long it is given the angle. So I will have to make an approximation because
|
|
|
- # we need to conserve the slot length, we only resize the diameter for the tool
|
|
|
- # Therefore scaling won't work and buffering will not work either.
|
|
|
+ # repopulate the 'solid_geometry' for each tool
|
|
|
+ poly = Point(point).buffer(float(tool_dia[0]) / 2.0, int(int(exc_obj.geo_steps_per_circle) / 4))
|
|
|
+ self.new_tools[current_tool]['solid_geometry'].append(poly)
|
|
|
|
|
|
- # First we get the Linestring that is one that the original slot is built around with the
|
|
|
- # tool having the diameter sel_dia
|
|
|
- poly = shape_exc.geo
|
|
|
- xmin, ymin, xmax, ymax = poly.bounds
|
|
|
- # a line that is certain to be bigger than our slot because it's the diagonal
|
|
|
- # of it's bounding box
|
|
|
- poly_diagonal = LineString([(xmin, ymin), (xmax, ymax)])
|
|
|
- poly_centroid = poly.centroid
|
|
|
- # center of the slot geometry
|
|
|
- poly_center = (poly_centroid.x, poly_centroid.y)
|
|
|
+ ordered_edited_slot_points = sorted(zip(edited_slot_points.keys(), edited_slot_points.values()))
|
|
|
+ for tool_dia in ordered_edited_slot_points:
|
|
|
|
|
|
- # make a list of intersections with the rotated line
|
|
|
- list_of_cuttings = []
|
|
|
- for angle in range(0, 359, 1):
|
|
|
- rot_poly_diagonal = affinity.rotate(poly_diagonal, angle=angle, origin=poly_center)
|
|
|
- cut_line = rot_poly_diagonal.intersection(poly)
|
|
|
- cut_line_len = cut_line.length
|
|
|
- list_of_cuttings.append(
|
|
|
- (cut_line_len, cut_line)
|
|
|
- )
|
|
|
- # find the cut_line with the maximum length which is the LineString for which the start
|
|
|
- # and stop point are the start and stop point of the slot as in the Gerber file
|
|
|
- cut_line_with_max_length = max(list_of_cuttings, key=lambda i: i[0])[1]
|
|
|
- # find the coordinates of this line
|
|
|
- cut_line_with_max_length_coords = list(cut_line_with_max_length.coords)
|
|
|
- # extract the first and last point of the line and build some buffered polygon circles
|
|
|
- # around them
|
|
|
- start_pt = Point(cut_line_with_max_length_coords[0])
|
|
|
- stop_pt = Point(cut_line_with_max_length_coords[1])
|
|
|
- start_cut_geo = start_pt.buffer(new_dia / 2)
|
|
|
- stop_cut_geo = stop_pt.buffer(new_dia / 2)
|
|
|
+ tool_exist_flag = False
|
|
|
+ for tool in self.new_tools:
|
|
|
+ if tool_dia[0] == self.new_tools[tool]["tooldia"]:
|
|
|
+ current_tool = tool
|
|
|
+ tool_exist_flag = True
|
|
|
+ break
|
|
|
|
|
|
- # and we cut the above circle polygons from our line and get in this way a line around
|
|
|
- # which we can build the new slot by buffering with the new tool diameter
|
|
|
- new_line = cut_line_with_max_length.difference(start_cut_geo)
|
|
|
- new_line = new_line.difference(stop_cut_geo)
|
|
|
+ if tool_exist_flag is False:
|
|
|
+ current_tool += 1
|
|
|
|
|
|
- # create the geometry for the resized slot by buffering with half of the
|
|
|
- # new diameter value: new_dia
|
|
|
- new_geo = new_line.buffer(new_dia / 2)
|
|
|
+ # create the self.tools for the new Excellon object (the one with edited content)
|
|
|
+ if current_tool not in self.new_tools:
|
|
|
+ self.new_tools[current_tool] = {}
|
|
|
+ self.new_tools[current_tool]['tooldia'] = float(tool_dia[0])
|
|
|
|
|
|
- try:
|
|
|
- self.points_edit.pop(old_dia, None)
|
|
|
- except KeyError:
|
|
|
- pass
|
|
|
- try:
|
|
|
- self.slot_points_edit.pop(old_dia, None)
|
|
|
- except KeyError:
|
|
|
- pass
|
|
|
+ # add in self.tools the 'solid_geometry' key, the value (a list) is populated below
|
|
|
+ self.new_tools[current_tool]['solid_geometry'] = []
|
|
|
|
|
|
- # add bogus drill/slots points (for total count of drills/slots)
|
|
|
- # for drills
|
|
|
- if isinstance(shape_exc.geo, MultiLineString):
|
|
|
- if new_dia not in self.points_edit:
|
|
|
- self.points_edit[new_dia] = [(0, 0)]
|
|
|
- else:
|
|
|
- self.points_edit[new_dia].append((0, 0))
|
|
|
+ # create the self.slots for the new Excellon object (the one with edited content)
|
|
|
+ for coord_dict in tool_dia[1]:
|
|
|
+ slot = (
|
|
|
+ Point(coord_dict['start']),
|
|
|
+ Point(coord_dict['stop'])
|
|
|
+ )
|
|
|
+ try:
|
|
|
+ self.new_tools[current_tool]['slots'].append(slot)
|
|
|
+ except KeyError:
|
|
|
+ self.new_tools[current_tool]['slots'] = [slot]
|
|
|
|
|
|
- # for slots
|
|
|
- if isinstance(shape_exc.geo, Polygon):
|
|
|
- if new_dia not in self.slot_points_edit:
|
|
|
- self.slot_points_edit[new_dia] = [(0, 0)]
|
|
|
- else:
|
|
|
- self.slot_points_edit[new_dia].append((0, 0))
|
|
|
+ # repopulate the 'solid_geometry' for each tool
|
|
|
+ poly = LineString([coord_dict['start'], coord_dict['stop']]).buffer(
|
|
|
+ float(tool_dia[0]) / 2.0, int(int(exc_obj.geo_steps_per_circle) / 4)
|
|
|
+ )
|
|
|
+ self.new_tools[current_tool]['solid_geometry'].append(poly)
|
|
|
|
|
|
- self.add_exc_shape(shape=DrawToolShape(new_geo), storage=destination_storage)
|
|
|
+ if self.is_modified is True:
|
|
|
+ if "_edit" in self.edited_obj_name:
|
|
|
+ try:
|
|
|
+ idd = int(self.edited_obj_name[-1]) + 1
|
|
|
+ self.edited_obj_name = self.edited_obj_name[:-1] + str(idd)
|
|
|
+ except ValueError:
|
|
|
+ self.edited_obj_name += "_1"
|
|
|
+ else:
|
|
|
+ self.edited_obj_name += "_edit"
|
|
|
|
|
|
- # update the UI and the CANVAS
|
|
|
- self.build_ui()
|
|
|
- self.replot()
|
|
|
+ self.app.worker_task.emit({'fcn': self.new_edited_excellon,
|
|
|
+ 'params': [self.edited_obj_name,
|
|
|
+ self.new_drills,
|
|
|
+ self.new_slots,
|
|
|
+ self.new_tools]})
|
|
|
|
|
|
- # delete the old tool
|
|
|
- self.on_tool_delete(dia=old_dia)
|
|
|
+ return self.edited_obj_name
|
|
|
|
|
|
- # we reactivate the signals after the after the tool editing
|
|
|
- self.tools_table_exc.itemChanged.connect(self.on_tool_edit)
|
|
|
- self.tools_table_exc.cellPressed.connect(self.on_row_selected)
|
|
|
+ @staticmethod
|
|
|
+ def update_options(obj):
|
|
|
+ try:
|
|
|
+ if not obj.options:
|
|
|
+ obj.options = {}
|
|
|
+ obj.options['xmin'] = 0
|
|
|
+ obj.options['ymin'] = 0
|
|
|
+ obj.options['xmax'] = 0
|
|
|
+ obj.options['ymax'] = 0
|
|
|
+ return True
|
|
|
+ else:
|
|
|
+ return False
|
|
|
+ except AttributeError:
|
|
|
+ obj.options = {}
|
|
|
+ return True
|
|
|
|
|
|
- self.app.inform.emit('[success] %s' %
|
|
|
- _("Done. Tool edit completed."))
|
|
|
+ def new_edited_excellon(self, outname, n_drills, n_slots, n_tools):
|
|
|
+ """
|
|
|
+ Creates a new Excellon object for the edited Excellon. Thread-safe.
|
|
|
|
|
|
- # self.tools_table_exc.selectionModel().currentChanged.connect(self.on_row_selected)
|
|
|
+ :param outname: Name of the resulting object. None causes the
|
|
|
+ name to be that of the file.
|
|
|
+ :type outname: str
|
|
|
|
|
|
- def on_name_activate(self):
|
|
|
- self.edited_obj_name = self.name_entry.get_value()
|
|
|
+ :param n_drills: The new Drills storage
|
|
|
+ :param n_slots: The new Slots storage
|
|
|
+ :param n_tools: The new Tools storage
|
|
|
+ :return: None
|
|
|
+ """
|
|
|
|
|
|
- def activate(self):
|
|
|
- # adjust the status of the menu entries related to the editor
|
|
|
- self.app.ui.menueditedit.setDisabled(True)
|
|
|
- self.app.ui.menueditok.setDisabled(False)
|
|
|
- # adjust the visibility of some of the canvas context menu
|
|
|
- self.app.ui.popmenu_edit.setVisible(False)
|
|
|
- self.app.ui.popmenu_save.setVisible(True)
|
|
|
+ self.app.log.debug("Update the Excellon object with edited content. Source is %s" %
|
|
|
+ self.exc_obj.options['name'])
|
|
|
|
|
|
- self.connect_canvas_event_handlers()
|
|
|
+ new_drills = n_drills
|
|
|
+ new_slots = n_slots
|
|
|
+ new_tools = n_tools
|
|
|
|
|
|
- # initialize working objects
|
|
|
- self.storage_dict = {}
|
|
|
- self.current_storage = []
|
|
|
- self.points_edit = {}
|
|
|
- self.sorted_diameters = []
|
|
|
- self.new_drills = []
|
|
|
- self.new_tools = {}
|
|
|
- self.new_slots = []
|
|
|
+ # How the object should be initialized
|
|
|
+ def obj_init(excellon_obj, app_obj):
|
|
|
|
|
|
- self.olddia_newdia = {}
|
|
|
+ excellon_obj.drills = deepcopy(new_drills)
|
|
|
+ excellon_obj.tools = deepcopy(new_tools)
|
|
|
+ excellon_obj.slots = deepcopy(new_slots)
|
|
|
|
|
|
- self.shapes.enabled = True
|
|
|
- self.tool_shape.enabled = True
|
|
|
- # self.app.app_cursor.enabled = True
|
|
|
+ excellon_obj.options['name'] = outname
|
|
|
|
|
|
- self.app.ui.corner_snap_btn.setVisible(True)
|
|
|
- self.app.ui.snap_magnet.setVisible(True)
|
|
|
+ # add a 'data' dict for each tool with the default values
|
|
|
+ for tool in excellon_obj.tools:
|
|
|
+ excellon_obj.tools[tool]['data'] = {}
|
|
|
+ excellon_obj.tools[tool]['data'].update(deepcopy(self.data_defaults))
|
|
|
|
|
|
- self.app.ui.exc_editor_menu.setDisabled(False)
|
|
|
- self.app.ui.exc_editor_menu.menuAction().setVisible(True)
|
|
|
+ try:
|
|
|
+ excellon_obj.create_geometry()
|
|
|
+ except KeyError:
|
|
|
+ self.app.inform.emit('[ERROR_NOTCL] %s' %
|
|
|
+ _("There are no Tools definitions in the file. Aborting Excellon creation.")
|
|
|
+ )
|
|
|
+ except Exception:
|
|
|
+ msg = '[ERROR] %s' % \
|
|
|
+ _("An internal error has ocurred. See Shell.\n")
|
|
|
+ msg += traceback.format_exc()
|
|
|
+ app_obj.inform.emit(msg)
|
|
|
+ return
|
|
|
|
|
|
- self.app.ui.update_obj_btn.setEnabled(True)
|
|
|
- self.app.ui.e_editor_cmenu.setEnabled(True)
|
|
|
+ with self.app.proc_container.new(_("Creating Excellon.")):
|
|
|
|
|
|
- self.app.ui.exc_edit_toolbar.setDisabled(False)
|
|
|
- self.app.ui.exc_edit_toolbar.setVisible(True)
|
|
|
- # self.app.ui.grid_toolbar.setDisabled(False)
|
|
|
+ try:
|
|
|
+ edited_obj = self.app.app_obj.new_object("excellon", outname, obj_init)
|
|
|
+ edited_obj.source_file = self.app.export_excellon(obj_name=edited_obj.options['name'],
|
|
|
+ local_use=edited_obj,
|
|
|
+ filename=None,
|
|
|
+ use_thread=False)
|
|
|
+ except Exception as e:
|
|
|
+ self.deactivate()
|
|
|
+ log.error("Error on Edited object creation: %s" % str(e))
|
|
|
+ return
|
|
|
|
|
|
- # start with GRID toolbar activated
|
|
|
- if self.app.ui.grid_snap_btn.isChecked() is False:
|
|
|
- self.app.ui.grid_snap_btn.trigger()
|
|
|
+ self.deactivate()
|
|
|
+ self.app.inform.emit('[success] %s' % _("Excellon editing finished."))
|
|
|
|
|
|
- self.app.ui.popmenu_disable.setVisible(False)
|
|
|
- self.app.ui.cmenu_newmenu.menuAction().setVisible(False)
|
|
|
- self.app.ui.popmenu_properties.setVisible(False)
|
|
|
- self.app.ui.e_editor_cmenu.menuAction().setVisible(True)
|
|
|
- self.app.ui.g_editor_cmenu.menuAction().setVisible(False)
|
|
|
- self.app.ui.grb_editor_cmenu.menuAction().setVisible(False)
|
|
|
+ def on_tool_select(self, tool):
|
|
|
+ """
|
|
|
+ Behavior of the toolbar. Tool initialization.
|
|
|
|
|
|
- # Tell the App that the editor is active
|
|
|
- self.editor_active = True
|
|
|
+ :rtype : None
|
|
|
+ """
|
|
|
+ current_tool = tool
|
|
|
|
|
|
- # show the UI
|
|
|
- self.drills_frame.show()
|
|
|
+ self.app.log.debug("on_tool_select('%s')" % tool)
|
|
|
|
|
|
- def deactivate(self):
|
|
|
- try:
|
|
|
- QtGui.QGuiApplication.restoreOverrideCursor()
|
|
|
- except Exception:
|
|
|
- pass
|
|
|
+ if self.last_tool_selected is None and current_tool != 'drill_select':
|
|
|
+ # self.draw_app.select_tool('drill_select')
|
|
|
+ self.complete = True
|
|
|
+ current_tool = 'drill_select'
|
|
|
+ self.app.inform.emit('[WARNING_NOTCL] %s' % _("Cancelled. There is no Tool/Drill selected"))
|
|
|
|
|
|
- # adjust the status of the menu entries related to the editor
|
|
|
- self.app.ui.menueditedit.setDisabled(False)
|
|
|
- self.app.ui.menueditok.setDisabled(True)
|
|
|
- # adjust the visibility of some of the canvas context menu
|
|
|
- self.app.ui.popmenu_edit.setVisible(True)
|
|
|
- self.app.ui.popmenu_save.setVisible(False)
|
|
|
+ # This is to make the group behave as radio group
|
|
|
+ if current_tool in self.tools_exc:
|
|
|
+ if self.tools_exc[current_tool]["button"].isChecked():
|
|
|
+ self.app.log.debug("%s is checked." % current_tool)
|
|
|
+ for t in self.tools_exc:
|
|
|
+ if t != current_tool:
|
|
|
+ self.tools_exc[t]["button"].setChecked(False)
|
|
|
|
|
|
- self.disconnect_canvas_event_handlers()
|
|
|
- self.clear()
|
|
|
- self.app.ui.exc_edit_toolbar.setDisabled(True)
|
|
|
+ # this is where the Editor toolbar classes (button's) are instantiated
|
|
|
+ self.active_tool = self.tools_exc[current_tool]["constructor"](self)
|
|
|
+ # self.app.inform.emit(self.active_tool.start_msg)
|
|
|
+ else:
|
|
|
+ self.app.log.debug("%s is NOT checked." % current_tool)
|
|
|
+ for t in self.tools_exc:
|
|
|
+ self.tools_exc[t]["button"].setChecked(False)
|
|
|
|
|
|
- self.app.ui.corner_snap_btn.setVisible(False)
|
|
|
- self.app.ui.snap_magnet.setVisible(False)
|
|
|
+ self.select_tool('drill_select')
|
|
|
+ self.active_tool = FCDrillSelect(self)
|
|
|
|
|
|
- # set the Editor Toolbar visibility to what was before entering in the Editor
|
|
|
- self.app.ui.exc_edit_toolbar.setVisible(False) if self.toolbar_old_state is False \
|
|
|
- else self.app.ui.exc_edit_toolbar.setVisible(True)
|
|
|
+ def on_row_selected(self, row, col):
|
|
|
+ if col == 0:
|
|
|
+ key_modifier = QtWidgets.QApplication.keyboardModifiers()
|
|
|
+ if self.app.defaults["global_mselect_key"] == 'Control':
|
|
|
+ modifier_to_use = Qt.ControlModifier
|
|
|
+ else:
|
|
|
+ modifier_to_use = Qt.ShiftModifier
|
|
|
|
|
|
- # Disable visuals
|
|
|
- self.shapes.enabled = False
|
|
|
- self.tool_shape.enabled = False
|
|
|
- # self.app.app_cursor.enabled = False
|
|
|
+ if key_modifier == modifier_to_use:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ self.selected = []
|
|
|
|
|
|
- # Tell the app that the editor is no longer active
|
|
|
- self.editor_active = False
|
|
|
+ try:
|
|
|
+ selected_dia = self.tool2tooldia[self.e_ui.tools_table_exc.currentRow() + 1]
|
|
|
+ self.last_tool_selected = int(self.e_ui.tools_table_exc.currentRow()) + 1
|
|
|
+ for obj in self.storage_dict[selected_dia].get_objects():
|
|
|
+ self.selected.append(obj)
|
|
|
+ except Exception as e:
|
|
|
+ self.app.log.debug(str(e))
|
|
|
|
|
|
- self.app.ui.exc_editor_menu.setDisabled(True)
|
|
|
- self.app.ui.exc_editor_menu.menuAction().setVisible(False)
|
|
|
+ self.replot()
|
|
|
|
|
|
- self.app.ui.update_obj_btn.setEnabled(False)
|
|
|
+ def on_canvas_click(self, event):
|
|
|
+ """
|
|
|
+ event.x and .y have canvas coordinates
|
|
|
+ event.xdata and .ydata have plot coordinates
|
|
|
|
|
|
- self.app.ui.popmenu_disable.setVisible(True)
|
|
|
- self.app.ui.cmenu_newmenu.menuAction().setVisible(True)
|
|
|
- self.app.ui.popmenu_properties.setVisible(True)
|
|
|
- self.app.ui.g_editor_cmenu.menuAction().setVisible(False)
|
|
|
- self.app.ui.e_editor_cmenu.menuAction().setVisible(False)
|
|
|
- self.app.ui.grb_editor_cmenu.menuAction().setVisible(False)
|
|
|
+ :param event: Event object dispatched by VisPy
|
|
|
+ :return: None
|
|
|
+ """
|
|
|
+ if self.app.is_legacy is False:
|
|
|
+ event_pos = event.pos
|
|
|
+ # event_is_dragging = event.is_dragging
|
|
|
+ # right_button = 2
|
|
|
+ else:
|
|
|
+ event_pos = (event.xdata, event.ydata)
|
|
|
+ # event_is_dragging = self.app.plotcanvas.is_dragging
|
|
|
+ # right_button = 3
|
|
|
+
|
|
|
+ self.pos = self.canvas.translate_coords(event_pos)
|
|
|
+
|
|
|
+ if self.app.grid_status():
|
|
|
+ self.pos = self.app.geo_editor.snap(self.pos[0], self.pos[1])
|
|
|
+ else:
|
|
|
+ self.pos = (self.pos[0], self.pos[1])
|
|
|
+
|
|
|
+ if event.button == 1:
|
|
|
+ self.app.ui.rel_position_label.setText("<b>Dx</b>: %.4f <b>Dy</b>: "
|
|
|
+ "%.4f " % (0, 0))
|
|
|
+
|
|
|
+ # Selection with left mouse button
|
|
|
+ if self.active_tool is not None and event.button == 1:
|
|
|
+ # Dispatch event to active_tool
|
|
|
+ # msg = self.active_tool.click(self.app.geo_editor.snap(event.xdata, event.ydata))
|
|
|
+ self.active_tool.click(self.app.geo_editor.snap(self.pos[0], self.pos[1]))
|
|
|
+
|
|
|
+ # If it is a shape generating tool
|
|
|
+ if isinstance(self.active_tool, FCShapeTool) and self.active_tool.complete:
|
|
|
+ if self.current_storage is not None:
|
|
|
+ self.on_exc_shape_complete(self.current_storage)
|
|
|
+ self.build_ui()
|
|
|
+
|
|
|
+ # MS: always return to the Select Tool if modifier key is not pressed
|
|
|
+ # else return to the current tool
|
|
|
+ key_modifier = QtWidgets.QApplication.keyboardModifiers()
|
|
|
+ if self.app.defaults["global_mselect_key"] == 'Control':
|
|
|
+ modifier_to_use = Qt.ControlModifier
|
|
|
+ else:
|
|
|
+ modifier_to_use = Qt.ShiftModifier
|
|
|
+
|
|
|
+ # if modifier key is pressed then we add to the selected list the current shape but if it's already
|
|
|
+ # in the selected list, we removed it. Therefore first click selects, second deselects.
|
|
|
+ if key_modifier == modifier_to_use:
|
|
|
+ self.select_tool(self.active_tool.name)
|
|
|
+ else:
|
|
|
+ # return to Select tool but not for FCDrillAdd or FCSlot
|
|
|
+ if isinstance(self.active_tool, FCDrillAdd) or isinstance(self.active_tool, FCSlot):
|
|
|
+ self.select_tool(self.active_tool.name)
|
|
|
+ else:
|
|
|
+ self.select_tool("drill_select")
|
|
|
+ return
|
|
|
|
|
|
- # Show original geometry
|
|
|
- if self.exc_obj:
|
|
|
- self.exc_obj.visible = True
|
|
|
+ if isinstance(self.active_tool, FCDrillSelect):
|
|
|
+ # self.app.log.debug("Replotting after click.")
|
|
|
+ self.replot()
|
|
|
+ else:
|
|
|
+ self.app.log.debug("No active tool to respond to click!")
|
|
|
|
|
|
- # hide the UI
|
|
|
- self.drills_frame.hide()
|
|
|
+ def on_exc_shape_complete(self, storage):
|
|
|
+ self.app.log.debug("on_shape_complete()")
|
|
|
|
|
|
- def connect_canvas_event_handlers(self):
|
|
|
- # ## Canvas events
|
|
|
+ # Add shape
|
|
|
+ if type(storage) is list:
|
|
|
+ for item_storage in storage:
|
|
|
+ self.add_exc_shape(self.active_tool.geometry, item_storage)
|
|
|
+ else:
|
|
|
+ self.add_exc_shape(self.active_tool.geometry, storage)
|
|
|
|
|
|
- # first connect to new, then disconnect the old handlers
|
|
|
- # don't ask why but if there is nothing connected I've seen issues
|
|
|
- self.mp = self.canvas.graph_event_connect('mouse_press', self.on_canvas_click)
|
|
|
- self.mm = self.canvas.graph_event_connect('mouse_move', self.on_canvas_move)
|
|
|
- self.mr = self.canvas.graph_event_connect('mouse_release', self.on_exc_click_release)
|
|
|
+ # Remove any utility shapes
|
|
|
+ self.delete_utility_geometry()
|
|
|
+ self.tool_shape.clear(update=True)
|
|
|
|
|
|
- # make sure that the shortcuts key and mouse events will no longer be linked to the methods from FlatCAMApp
|
|
|
- # but those from AppGeoEditor
|
|
|
- if self.app.is_legacy is False:
|
|
|
- self.app.plotcanvas.graph_event_disconnect('mouse_press', self.app.on_mouse_click_over_plot)
|
|
|
- self.app.plotcanvas.graph_event_disconnect('mouse_move', self.app.on_mouse_move_over_plot)
|
|
|
- self.app.plotcanvas.graph_event_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot)
|
|
|
- self.app.plotcanvas.graph_event_disconnect('mouse_double_click', self.app.on_mouse_double_click_over_plot)
|
|
|
- else:
|
|
|
- self.app.plotcanvas.graph_event_disconnect(self.app.mp)
|
|
|
- self.app.plotcanvas.graph_event_disconnect(self.app.mm)
|
|
|
- self.app.plotcanvas.graph_event_disconnect(self.app.mr)
|
|
|
- self.app.plotcanvas.graph_event_disconnect(self.app.mdc)
|
|
|
+ # Replot and reset tool.
|
|
|
+ self.replot()
|
|
|
+ # self.active_tool = type(self.active_tool)(self)
|
|
|
|
|
|
- self.app.collection.view.clicked.disconnect()
|
|
|
+ def add_exc_shape(self, shape, storage):
|
|
|
+ """
|
|
|
+ Adds a shape to a specified shape storage.
|
|
|
|
|
|
- self.app.ui.popmenu_copy.triggered.disconnect()
|
|
|
- self.app.ui.popmenu_delete.triggered.disconnect()
|
|
|
- self.app.ui.popmenu_move.triggered.disconnect()
|
|
|
+ :param shape: Shape to be added.
|
|
|
+ :type shape: DrawToolShape
|
|
|
+ :param storage: object where to store the shapes
|
|
|
+ :return: None
|
|
|
+ """
|
|
|
+ # List of DrawToolShape?
|
|
|
+ if isinstance(shape, list):
|
|
|
+ for subshape in shape:
|
|
|
+ self.add_exc_shape(subshape, storage)
|
|
|
+ return
|
|
|
|
|
|
- self.app.ui.popmenu_copy.triggered.connect(self.exc_copy_drills)
|
|
|
- self.app.ui.popmenu_delete.triggered.connect(self.on_delete_btn)
|
|
|
- self.app.ui.popmenu_move.triggered.connect(self.exc_move_drills)
|
|
|
+ assert isinstance(shape, DrawToolShape), \
|
|
|
+ "Expected a DrawToolShape, got %s" % str(type(shape))
|
|
|
|
|
|
- # Excellon Editor
|
|
|
- self.app.ui.drill.triggered.connect(self.exc_add_drill)
|
|
|
- self.app.ui.drill_array.triggered.connect(self.exc_add_drill_array)
|
|
|
+ assert shape.geo is not None, \
|
|
|
+ "Shape object has empty geometry (None)"
|
|
|
|
|
|
- def disconnect_canvas_event_handlers(self):
|
|
|
- # we restore the key and mouse control to FlatCAMApp method
|
|
|
- # first connect to new, then disconnect the old handlers
|
|
|
- # don't ask why but if there is nothing connected I've seen issues
|
|
|
- self.app.mp = self.app.plotcanvas.graph_event_connect('mouse_press', self.app.on_mouse_click_over_plot)
|
|
|
- self.app.mm = self.app.plotcanvas.graph_event_connect('mouse_move', self.app.on_mouse_move_over_plot)
|
|
|
- self.app.mr = self.app.plotcanvas.graph_event_connect('mouse_release',
|
|
|
- self.app.on_mouse_click_release_over_plot)
|
|
|
- self.app.mdc = self.app.plotcanvas.graph_event_connect('mouse_double_click',
|
|
|
- self.app.on_mouse_double_click_over_plot)
|
|
|
- self.app.collection.view.clicked.connect(self.app.collection.on_mouse_down)
|
|
|
+ assert (isinstance(shape.geo, list) and len(shape.geo) > 0) or not isinstance(shape.geo, list), \
|
|
|
+ "Shape objects has empty geometry ([])"
|
|
|
|
|
|
- if self.app.is_legacy is False:
|
|
|
- self.canvas.graph_event_disconnect('mouse_press', self.on_canvas_click)
|
|
|
- self.canvas.graph_event_disconnect('mouse_move', self.on_canvas_move)
|
|
|
- self.canvas.graph_event_disconnect('mouse_release', self.on_exc_click_release)
|
|
|
+ if isinstance(shape, DrawToolUtilityShape):
|
|
|
+ self.utility.append(shape)
|
|
|
else:
|
|
|
- self.canvas.graph_event_disconnect(self.mp)
|
|
|
- self.canvas.graph_event_disconnect(self.mm)
|
|
|
- self.canvas.graph_event_disconnect(self.mr)
|
|
|
+ storage.insert(shape) # TODO: Check performance
|
|
|
|
|
|
- try:
|
|
|
- self.app.ui.popmenu_copy.triggered.disconnect(self.exc_copy_drills)
|
|
|
- except (TypeError, AttributeError):
|
|
|
- pass
|
|
|
+ def add_shape(self, shape):
|
|
|
+ """
|
|
|
+ Adds a shape to the shape storage.
|
|
|
|
|
|
- try:
|
|
|
- self.app.ui.popmenu_delete.triggered.disconnect(self.on_delete_btn)
|
|
|
- except (TypeError, AttributeError):
|
|
|
- pass
|
|
|
+ :param shape: Shape to be added.
|
|
|
+ :type shape: DrawToolShape
|
|
|
+ :return: None
|
|
|
+ """
|
|
|
|
|
|
- try:
|
|
|
- self.app.ui.popmenu_move.triggered.disconnect(self.exc_move_drills)
|
|
|
- except (TypeError, AttributeError):
|
|
|
- pass
|
|
|
+ # List of DrawToolShape?
|
|
|
+ if isinstance(shape, list):
|
|
|
+ for subshape in shape:
|
|
|
+ self.add_shape(subshape)
|
|
|
+ return
|
|
|
|
|
|
- self.app.ui.popmenu_copy.triggered.connect(self.app.on_copy_command)
|
|
|
- self.app.ui.popmenu_delete.triggered.connect(self.app.on_delete)
|
|
|
- self.app.ui.popmenu_move.triggered.connect(self.app.obj_move)
|
|
|
+ assert isinstance(shape, DrawToolShape), \
|
|
|
+ "Expected a DrawToolShape, got %s" % type(shape)
|
|
|
|
|
|
- # Excellon Editor
|
|
|
- try:
|
|
|
- self.app.ui.drill.triggered.disconnect(self.exc_add_drill)
|
|
|
- except (TypeError, AttributeError):
|
|
|
- pass
|
|
|
+ assert shape.geo is not None, \
|
|
|
+ "Shape object has empty geometry (None)"
|
|
|
|
|
|
- try:
|
|
|
- self.app.ui.drill_array.triggered.disconnect(self.exc_add_drill_array)
|
|
|
- except (TypeError, AttributeError):
|
|
|
- pass
|
|
|
+ assert (isinstance(shape.geo, list) and len(shape.geo) > 0) or not isinstance(shape.geo, list), \
|
|
|
+ "Shape objects has empty geometry ([])"
|
|
|
|
|
|
- try:
|
|
|
- self.app.jump_signal.disconnect()
|
|
|
- except (TypeError, AttributeError):
|
|
|
- pass
|
|
|
+ if isinstance(shape, DrawToolUtilityShape):
|
|
|
+ self.utility.append(shape)
|
|
|
+ # else:
|
|
|
+ # self.storage.insert(shape)
|
|
|
|
|
|
- def clear(self):
|
|
|
- self.active_tool = None
|
|
|
- # self.shape_buffer = []
|
|
|
- self.selected = []
|
|
|
+ def on_exc_click_release(self, event):
|
|
|
+ """
|
|
|
+ Handler of the "mouse_release" event.
|
|
|
+ It will pop-up the context menu on right mouse click unless there was a panning move (decided in the
|
|
|
+ "mouse_move" event handler) and only if the current tool is the Select tool.
|
|
|
+ It will 'close' a Editor tool if it is the case.
|
|
|
|
|
|
- self.points_edit = {}
|
|
|
- self.new_tools = {}
|
|
|
- self.new_drills = []
|
|
|
+ :param event: Event object dispatched by VisPy SceneCavas
|
|
|
+ :return: None
|
|
|
+ """
|
|
|
|
|
|
- # self.storage_dict = {}
|
|
|
+ if self.app.is_legacy is False:
|
|
|
+ event_pos = event.pos
|
|
|
+ # event_is_dragging = event.is_dragging
|
|
|
+ right_button = 2
|
|
|
+ else:
|
|
|
+ event_pos = (event.xdata, event.ydata)
|
|
|
+ # event_is_dragging = self.app.plotcanvas.is_dragging
|
|
|
+ right_button = 3
|
|
|
|
|
|
- self.shapes.clear(update=True)
|
|
|
- self.tool_shape.clear(update=True)
|
|
|
+ pos_canvas = self.canvas.translate_coords(event_pos)
|
|
|
|
|
|
- # self.storage = AppExcEditor.make_storage()
|
|
|
- self.replot()
|
|
|
+ if self.app.grid_status():
|
|
|
+ pos = self.app.geo_editor.snap(pos_canvas[0], pos_canvas[1])
|
|
|
+ else:
|
|
|
+ pos = (pos_canvas[0], pos_canvas[1])
|
|
|
|
|
|
- def edit_fcexcellon(self, exc_obj):
|
|
|
- """
|
|
|
- Imports the geometry from the given FlatCAM Excellon object
|
|
|
- into the editor.
|
|
|
+ # if the released mouse button was RMB then test if it was a panning motion or not, if not it was a context
|
|
|
+ # canvas menu
|
|
|
+ try:
|
|
|
+ if event.button == right_button: # right click
|
|
|
+ if self.app.ui.popMenu.mouse_is_panning is False:
|
|
|
+ try:
|
|
|
+ QtGui.QGuiApplication.restoreOverrideCursor()
|
|
|
+ except Exception:
|
|
|
+ pass
|
|
|
+ if self.active_tool.complete is False and not isinstance(self.active_tool, FCDrillSelect):
|
|
|
+ self.active_tool.complete = True
|
|
|
+ self.in_action = False
|
|
|
+ self.delete_utility_geometry()
|
|
|
+ self.app.inform.emit('[success] %s' % _("Done."))
|
|
|
+ self.select_tool('drill_select')
|
|
|
+ else:
|
|
|
+ if isinstance(self.active_tool, FCDrillAdd):
|
|
|
+ self.active_tool.complete = True
|
|
|
+ self.in_action = False
|
|
|
+ self.delete_utility_geometry()
|
|
|
+ self.app.inform.emit('[success] %s' % _("Done."))
|
|
|
+ self.select_tool('drill_select')
|
|
|
|
|
|
- :param exc_obj: ExcellonObject object
|
|
|
- :return: None
|
|
|
- """
|
|
|
+ self.app.cursor = QtGui.QCursor()
|
|
|
+ self.app.populate_cmenu_grids()
|
|
|
+ self.app.ui.popMenu.popup(self.app.cursor.pos())
|
|
|
|
|
|
- assert isinstance(exc_obj, Excellon), \
|
|
|
- "Expected an Excellon Object, got %s" % type(exc_obj)
|
|
|
+ except Exception as e:
|
|
|
+ log.warning("AppExcEditor.on_exc_click_release() RMB click --> Error: %s" % str(e))
|
|
|
+ raise
|
|
|
|
|
|
- self.deactivate()
|
|
|
- self.activate()
|
|
|
+ # if the released mouse button was LMB then test if we had a right-to-left selection or a left-to-right
|
|
|
+ # selection and then select a type of selection ("enclosing" or "touching")
|
|
|
+ try:
|
|
|
+ if event.button == 1: # left click
|
|
|
+ if self.app.selection_type is not None:
|
|
|
+ self.draw_selection_area_handler(self.pos, pos, self.app.selection_type)
|
|
|
+ self.app.selection_type = None
|
|
|
|
|
|
- # Hide original geometry
|
|
|
- self.exc_obj = exc_obj
|
|
|
- exc_obj.visible = False
|
|
|
+ elif isinstance(self.active_tool, FCDrillSelect):
|
|
|
+ self.active_tool.click_release((self.pos[0], self.pos[1]))
|
|
|
|
|
|
- self.points_edit = {}
|
|
|
- self.slot_points_edit = {}
|
|
|
+ # if there are selected objects then plot them
|
|
|
+ if self.selected:
|
|
|
+ self.replot()
|
|
|
+ except Exception as e:
|
|
|
+ log.warning("AppExcEditor.on_exc_click_release() LMB click --> Error: %s" % str(e))
|
|
|
+ raise
|
|
|
|
|
|
- # Set selection tolerance
|
|
|
- # DrawToolShape.tolerance = fc_excellon.drawing_tolerance * 10
|
|
|
+ def draw_selection_area_handler(self, start, end, sel_type):
|
|
|
+ """
|
|
|
+ This function is called whenever we have a left mouse click release and only we have a left mouse click drag,
|
|
|
+ be it from left to right or from right to left. The direction of the drag is decided in the "mouse_move"
|
|
|
+ event handler.
|
|
|
+ Pressing a modifier key (eg. Ctrl, Shift or Alt) will change the behavior of the selection.
|
|
|
|
|
|
- self.select_tool("drill_select")
|
|
|
+ Depending on which tool belongs the selected shapes, the corresponding rows in the Tools Table are selected or
|
|
|
+ deselected.
|
|
|
|
|
|
- # reset the tool table
|
|
|
- self.tools_table_exc.clear()
|
|
|
- self.tools_table_exc.setHorizontalHeaderLabels(['#', _('Diameter'), 'D', 'S'])
|
|
|
- self.last_tool_selected = None
|
|
|
+ :param start: mouse position when the selection LMB click was done
|
|
|
+ :param end: mouse position when the left mouse button is released
|
|
|
+ :param sel_type: if True it's a left to right selection (enclosure), if False it's a 'touch' selection
|
|
|
+ :return:
|
|
|
+ """
|
|
|
|
|
|
- self.set_ui()
|
|
|
+ start_pos = (start[0], start[1])
|
|
|
+ end_pos = (end[0], end[1])
|
|
|
+ poly_selection = Polygon([start_pos, (end_pos[0], start_pos[1]), end_pos, (start_pos[0], end_pos[1])])
|
|
|
+ modifiers = None
|
|
|
|
|
|
- # now that we hava data, create the appGUI interface and add it to the Tool Tab
|
|
|
- self.build_ui(first_run=True)
|
|
|
+ # delete the selection shape that was just drawn, we no longer need it
|
|
|
+ self.app.delete_selection_shape()
|
|
|
+
|
|
|
+ # detect if a modifier key was pressed while the left mouse button was released
|
|
|
+ self.modifiers = QtWidgets.QApplication.keyboardModifiers()
|
|
|
+ if self.modifiers == QtCore.Qt.ShiftModifier:
|
|
|
+ modifiers = 'Shift'
|
|
|
+ elif self.modifiers == QtCore.Qt.ControlModifier:
|
|
|
+ modifiers = 'Control'
|
|
|
|
|
|
- # we activate this after the initial build as we don't need to see the tool been populated
|
|
|
- self.tools_table_exc.itemChanged.connect(self.on_tool_edit)
|
|
|
+ if modifiers == self.app.defaults["global_mselect_key"]:
|
|
|
+ for storage in self.storage_dict:
|
|
|
+ for obj in self.storage_dict[storage].get_objects():
|
|
|
+ if (sel_type is True and poly_selection.contains(obj.geo)) or \
|
|
|
+ (sel_type is False and poly_selection.intersects(obj.geo)):
|
|
|
|
|
|
- # build the geometry for each tool-diameter, each drill will be represented by a '+' symbol
|
|
|
- # and then add it to the storage elements (each storage elements is a member of a list
|
|
|
- for tool_dia in self.points_edit:
|
|
|
- storage_elem = AppGeoEditor.make_storage()
|
|
|
- for point in self.points_edit[tool_dia]:
|
|
|
- # make a '+' sign, the line length is the tool diameter
|
|
|
- start_hor_line = ((point.x - (tool_dia / 2)), point.y)
|
|
|
- stop_hor_line = ((point.x + (tool_dia / 2)), point.y)
|
|
|
- start_vert_line = (point.x, (point.y - (tool_dia / 2)))
|
|
|
- stop_vert_line = (point.x, (point.y + (tool_dia / 2)))
|
|
|
- shape_geo = MultiLineString([(start_hor_line, stop_hor_line), (start_vert_line, stop_vert_line)])
|
|
|
- if shape_geo is not None:
|
|
|
- self.add_exc_shape(DrawToolShape(shape_geo), storage_elem)
|
|
|
- self.storage_dict[tool_dia] = storage_elem
|
|
|
+ if obj in self.selected:
|
|
|
+ # remove the shape object from the selected shapes storage
|
|
|
+ self.selected.remove(obj)
|
|
|
+ else:
|
|
|
+ # add the shape object to the selected shapes storage
|
|
|
+ self.selected.append(obj)
|
|
|
+ else:
|
|
|
+ # clear the selection shapes storage
|
|
|
+ self.selected = []
|
|
|
+ # then add to the selection shapes storage the shapes that are included (touched) by the selection rectangle
|
|
|
+ for storage in self.storage_dict:
|
|
|
+ for obj in self.storage_dict[storage].get_objects():
|
|
|
+ if (sel_type is True and poly_selection.contains(obj.geo)) or \
|
|
|
+ (sel_type is False and poly_selection.intersects(obj.geo)):
|
|
|
+ self.selected.append(obj)
|
|
|
|
|
|
- # slots
|
|
|
- for tool_dia in self.slot_points_edit:
|
|
|
- buf_value = float(tool_dia) / 2
|
|
|
- for elem_dict in self.slot_points_edit[tool_dia]:
|
|
|
+ try:
|
|
|
+ self.e_ui.tools_table_exc.cellPressed.disconnect()
|
|
|
+ except Exception:
|
|
|
+ pass
|
|
|
|
|
|
- line_geo = LineString([elem_dict['start'], elem_dict['stop']])
|
|
|
- shape_geo = line_geo.buffer(buf_value)
|
|
|
+ # first deselect all rows (tools) in the Tools Table
|
|
|
+ self.e_ui.tools_table_exc.clearSelection()
|
|
|
+ # and select the rows (tools) in the tool table according to the diameter(s) of the selected shape(s)
|
|
|
+ self.e_ui.tools_table_exc.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
|
|
|
+ for storage in self.storage_dict:
|
|
|
+ for shape_s in self.selected:
|
|
|
+ if shape_s in self.storage_dict[storage].get_objects():
|
|
|
+ for key_tool_nr in self.tool2tooldia:
|
|
|
+ if self.tool2tooldia[key_tool_nr] == storage:
|
|
|
+ row_to_sel = key_tool_nr - 1
|
|
|
+ # item = self.e_ui.tools_table_exc.item(row_to_sel, 1)
|
|
|
+ # self.e_ui.tools_table_exc.setCurrentItem(item)
|
|
|
+ # item.setSelected(True)
|
|
|
|
|
|
- if tool_dia not in self.storage_dict:
|
|
|
- storage_elem = AppGeoEditor.make_storage()
|
|
|
- self.storage_dict[tool_dia] = storage_elem
|
|
|
+ # if the row to be selected is not already in the selected rows then select it
|
|
|
+ # otherwise don't do it as it seems that we have a toggle effect
|
|
|
+ if row_to_sel not in set(index.row() for index in self.e_ui.tools_table_exc.selectedIndexes()):
|
|
|
+ self.e_ui.tools_table_exc.selectRow(row_to_sel)
|
|
|
+ self.last_tool_selected = int(key_tool_nr)
|
|
|
|
|
|
- if shape_geo is not None:
|
|
|
- self.add_exc_shape(DrawToolShape(shape_geo), self.storage_dict[tool_dia])
|
|
|
+ self.e_ui.tools_table_exc.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
|
|
|
|
|
|
+ self.e_ui.tools_table_exc.cellPressed.connect(self.on_row_selected)
|
|
|
self.replot()
|
|
|
|
|
|
- # add a first tool in the Tool Table but only if the Excellon Object is empty
|
|
|
- if not self.tool2tooldia:
|
|
|
- self.on_tool_add(tooldia=float('%.*f' % (self.decimals,
|
|
|
- float(self.app.defaults['excellon_editor_newdia']))))
|
|
|
-
|
|
|
- def update_fcexcellon(self, exc_obj):
|
|
|
- """
|
|
|
- Create a new Excellon object that contain the edited content of the source Excellon object
|
|
|
-
|
|
|
- :param exc_obj: ExcellonObject
|
|
|
- :return: None
|
|
|
+ def on_canvas_move(self, event):
|
|
|
"""
|
|
|
+ Called on 'mouse_move' event.
|
|
|
+ It updates the mouse cursor if the grid snapping is ON.
|
|
|
+ It decide if we have a mouse drag and if it is done with the right mouse click. Then it passes this info to a
|
|
|
+ class object which is used in the "mouse_release" handler to decide if to pop-up the context menu or not.
|
|
|
+ It draws utility_geometry for the Editor tools.
|
|
|
+ Update the position labels from status bar.
|
|
|
+ Decide if we have a right to left or a left to right mouse drag with left mouse button and call a function
|
|
|
+ that will draw a selection shape on canvas.
|
|
|
|
|
|
- # this dictionary will contain tooldia's as keys and a list of coordinates tuple as values
|
|
|
- # the values of this dict are coordinates of the holes (drills)
|
|
|
- edited_points = {}
|
|
|
+ event.pos have canvas screen coordinates
|
|
|
|
|
|
+ :param event: Event object dispatched by VisPy SceneCavas
|
|
|
+ :return: None
|
|
|
"""
|
|
|
- - this dictionary will contain tooldia's as keys and a list of another dicts as values
|
|
|
- - the dict element of the list has the structure
|
|
|
- ================ ====================================
|
|
|
- Key Value
|
|
|
- ================ ====================================
|
|
|
- start (Shapely.Point) Start point of the slot
|
|
|
- stop (Shapely.Point) Stop point of the slot
|
|
|
- ================ ====================================
|
|
|
- """
|
|
|
- edited_slot_points = {}
|
|
|
|
|
|
- for storage_tooldia in self.storage_dict:
|
|
|
- for x in self.storage_dict[storage_tooldia].get_objects():
|
|
|
- if isinstance(x.geo, MultiLineString):
|
|
|
- # all x.geo in self.storage_dict[storage] are MultiLinestring objects for drills
|
|
|
- # each MultiLineString is made out of Linestrings
|
|
|
- # select first Linestring object in the current MultiLineString
|
|
|
- first_linestring = x.geo[0]
|
|
|
- # get it's coordinates
|
|
|
- first_linestring_coords = first_linestring.coords
|
|
|
- x_coord = first_linestring_coords[0][0] + (float(first_linestring.length / 2))
|
|
|
- y_coord = first_linestring_coords[0][1]
|
|
|
+ if self.app.is_legacy is False:
|
|
|
+ event_pos = event.pos
|
|
|
+ event_is_dragging = event.is_dragging
|
|
|
+ right_button = 2
|
|
|
+ else:
|
|
|
+ event_pos = (event.xdata, event.ydata)
|
|
|
+ event_is_dragging = self.app.plotcanvas.is_dragging
|
|
|
+ right_button = 3
|
|
|
|
|
|
- # create a tuple with the coordinates (x, y) and add it to the list that is the value of the
|
|
|
- # edited_points dictionary
|
|
|
- point = (x_coord, y_coord)
|
|
|
- if storage_tooldia not in edited_points:
|
|
|
- edited_points[storage_tooldia] = [point]
|
|
|
- else:
|
|
|
- edited_points[storage_tooldia].append(point)
|
|
|
- elif isinstance(x.geo, Polygon):
|
|
|
- # create a tuple with the points (start, stop) and add it to the list that is the value of the
|
|
|
- # edited_points dictionary
|
|
|
+ pos = self.canvas.translate_coords(event_pos)
|
|
|
+ event.xdata, event.ydata = pos[0], pos[1]
|
|
|
|
|
|
- # first determine the start and stop coordinates for the slot knowing the geometry and the tool
|
|
|
- # diameter
|
|
|
- radius = float(storage_tooldia) / 2
|
|
|
- radius = radius - 0.0000001
|
|
|
+ self.x = event.xdata
|
|
|
+ self.y = event.ydata
|
|
|
|
|
|
- poly = x.geo
|
|
|
- poly = poly.buffer(-radius)
|
|
|
+ self.app.ui.popMenu.mouse_is_panning = False
|
|
|
|
|
|
- if not poly.is_valid or poly.is_empty:
|
|
|
- print("Polygon not valid: %s" % str(poly.wkt))
|
|
|
- continue
|
|
|
+ # if the RMB is clicked and mouse is moving over plot then 'panning_action' is True
|
|
|
+ if event.button == right_button and event_is_dragging == 1:
|
|
|
+ self.app.ui.popMenu.mouse_is_panning = True
|
|
|
+ return
|
|
|
|
|
|
- xmin, ymin, xmax, ymax = poly.bounds
|
|
|
- line_one = LineString([(xmin, ymin), (xmax, ymax)]).intersection(poly).length
|
|
|
- line_two = LineString([(xmin, ymax), (xmax, ymin)]).intersection(poly).length
|
|
|
+ try:
|
|
|
+ x = float(event.xdata)
|
|
|
+ y = float(event.ydata)
|
|
|
+ except TypeError:
|
|
|
+ return
|
|
|
|
|
|
- if line_one < line_two:
|
|
|
- point_elem = {
|
|
|
- "start": (xmin, ymax),
|
|
|
- "stop": (xmax, ymin)
|
|
|
- }
|
|
|
- else:
|
|
|
- point_elem = {
|
|
|
- "start": (xmin, ymin),
|
|
|
- "stop": (xmax, ymax)
|
|
|
- }
|
|
|
+ if self.active_tool is None:
|
|
|
+ return
|
|
|
|
|
|
- if storage_tooldia not in edited_slot_points:
|
|
|
- edited_slot_points[storage_tooldia] = [point_elem]
|
|
|
- else:
|
|
|
- edited_slot_points[storage_tooldia].append(point_elem)
|
|
|
+ # ## Snap coordinates
|
|
|
+ if self.app.grid_status():
|
|
|
+ x, y = self.app.geo_editor.snap(x, y)
|
|
|
|
|
|
- # recreate the drills and tools to be added to the new Excellon edited object
|
|
|
- # first, we look in the tool table if one of the tool diameters was changed then
|
|
|
- # append that a tuple formed by (old_dia, edited_dia) to a list
|
|
|
- changed_key = set()
|
|
|
- for initial_dia in self.olddia_newdia:
|
|
|
- edited_dia = self.olddia_newdia[initial_dia]
|
|
|
- if edited_dia != initial_dia:
|
|
|
- # for drills
|
|
|
- for old_dia in edited_points:
|
|
|
- if old_dia == initial_dia:
|
|
|
- changed_key.add((old_dia, edited_dia))
|
|
|
- # for slots
|
|
|
- for old_dia in edited_slot_points:
|
|
|
- if old_dia == initial_dia:
|
|
|
- changed_key.add((old_dia, edited_dia))
|
|
|
- # if the initial_dia is not in edited_points it means it is a new tool with no drill points
|
|
|
- # (and we have to add it)
|
|
|
- # because in case we have drill points it will have to be already added in edited_points
|
|
|
- # if initial_dia not in edited_points.keys():
|
|
|
- # edited_points[initial_dia] = []
|
|
|
+ # Update cursor
|
|
|
+ self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D,
|
|
|
+ edge_width=self.app.defaults["global_cursor_width"],
|
|
|
+ size=self.app.defaults["global_cursor_size"])
|
|
|
|
|
|
- for el in changed_key:
|
|
|
- edited_points[el[1]] = edited_points.pop(el[0])
|
|
|
- edited_slot_points[el[1]] = edited_slot_points.pop(el[0])
|
|
|
+ self.snap_x = x
|
|
|
+ self.snap_y = y
|
|
|
|
|
|
- # Let's sort the edited_points dictionary by keys (diameters) and store the result in a zipped list
|
|
|
- # ordered_edited_points is a ordered list of tuples;
|
|
|
- # element[0] of the tuple is the diameter and
|
|
|
- # element[1] of the tuple is a list of coordinates (a tuple themselves)
|
|
|
- ordered_edited_points = sorted(zip(edited_points.keys(), edited_points.values()))
|
|
|
+ if self.pos is None:
|
|
|
+ self.pos = (0, 0)
|
|
|
+ self.app.dx = x - self.pos[0]
|
|
|
+ self.app.dy = y - self.pos[1]
|
|
|
|
|
|
- current_tool = 0
|
|
|
- for tool_dia in ordered_edited_points:
|
|
|
- current_tool += 1
|
|
|
+ # # update the position label in the infobar since the APP mouse event handlers are disconnected
|
|
|
+ self.app.ui.position_label.setText(" <b>X</b>: %.4f "
|
|
|
+ "<b>Y</b>: %.4f " % (x, y))
|
|
|
+ # # update the reference position label in the infobar since the APP mouse event handlers are disconnected
|
|
|
+ self.app.ui.rel_position_label.setText("<b>Dx</b>: %.4f <b>Dy</b>: "
|
|
|
+ "%.4f " % (self.app.dx, self.app.dy))
|
|
|
|
|
|
- # create the self.tools for the new Excellon object (the one with edited content)
|
|
|
- if current_tool not in self.new_tools:
|
|
|
- self.new_tools[current_tool] = {}
|
|
|
- self.new_tools[current_tool]['tooldia'] = float(tool_dia[0])
|
|
|
+ units = self.app.defaults["units"].lower()
|
|
|
+ self.app.plotcanvas.text_hud.text = \
|
|
|
+ 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format(
|
|
|
+ self.app.dx, units, self.app.dy, units, x, units, y, units)
|
|
|
|
|
|
- # add in self.tools the 'solid_geometry' key, the value (a list) is populated below
|
|
|
- self.new_tools[current_tool]['solid_geometry'] = []
|
|
|
+ # ## Utility geometry (animated)
|
|
|
+ self.update_utility_geometry(data=(x, y))
|
|
|
|
|
|
- # create the self.drills for the new Excellon object (the one with edited content)
|
|
|
- for point in tool_dia[1]:
|
|
|
- try:
|
|
|
- self.new_tools[current_tool]['drills'].append(Point(point))
|
|
|
- except KeyError:
|
|
|
- self.new_tools[current_tool]['drills'] = [Point(point)]
|
|
|
+ # ## Selection area on canvas section # ##
|
|
|
+ if event_is_dragging == 1 and event.button == 1:
|
|
|
+ # I make an exception for FCDrillAdd and FCDrillArray because clicking and dragging while making regions
|
|
|
+ # can create strange issues. Also for FCSlot and FCSlotArray
|
|
|
+ if isinstance(self.active_tool, FCDrillAdd) or isinstance(self.active_tool, FCDrillArray) or \
|
|
|
+ isinstance(self.active_tool, FCSlot) or isinstance(self.active_tool, FCSlotArray):
|
|
|
+ self.app.selection_type = None
|
|
|
+ else:
|
|
|
+ dx = pos[0] - self.pos[0]
|
|
|
+ self.app.delete_selection_shape()
|
|
|
+ if dx < 0:
|
|
|
+ self.app.draw_moving_selection_shape((self.pos[0], self.pos[1]), (x, y),
|
|
|
+ color=self.app.defaults["global_alt_sel_line"],
|
|
|
+ face_color=self.app.defaults['global_alt_sel_fill'])
|
|
|
+ self.app.selection_type = False
|
|
|
+ else:
|
|
|
+ self.app.draw_moving_selection_shape((self.pos[0], self.pos[1]), (x, y))
|
|
|
+ self.app.selection_type = True
|
|
|
+ else:
|
|
|
+ self.app.selection_type = None
|
|
|
|
|
|
- # repopulate the 'solid_geometry' for each tool
|
|
|
- poly = Point(point).buffer(float(tool_dia[0]) / 2.0, int(int(exc_obj.geo_steps_per_circle) / 4))
|
|
|
- self.new_tools[current_tool]['solid_geometry'].append(poly)
|
|
|
+ # Update cursor
|
|
|
+ self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D,
|
|
|
+ edge_width=self.app.defaults["global_cursor_width"],
|
|
|
+ size=self.app.defaults["global_cursor_size"])
|
|
|
|
|
|
- ordered_edited_slot_points = sorted(zip(edited_slot_points.keys(), edited_slot_points.values()))
|
|
|
- for tool_dia in ordered_edited_slot_points:
|
|
|
+ def update_utility_geometry(self, data):
|
|
|
+ # ### Utility geometry (animated) ###
|
|
|
+ geo = self.active_tool.utility_geometry(data=data)
|
|
|
+ if isinstance(geo, DrawToolShape) and geo.geo is not None:
|
|
|
+ # Remove any previous utility shape
|
|
|
+ self.tool_shape.clear(update=True)
|
|
|
+ self.draw_utility_geometry(geo=geo)
|
|
|
|
|
|
- tool_exist_flag = False
|
|
|
- for tool in self.new_tools:
|
|
|
- if tool_dia[0] == self.new_tools[tool]["tooldia"]:
|
|
|
- current_tool = tool
|
|
|
- tool_exist_flag = True
|
|
|
- break
|
|
|
+ def on_canvas_key_release(self, event):
|
|
|
+ self.key = None
|
|
|
|
|
|
- if tool_exist_flag is False:
|
|
|
- current_tool += 1
|
|
|
+ def draw_utility_geometry(self, geo):
|
|
|
+ # Add the new utility shape
|
|
|
+ try:
|
|
|
+ # this case is for the Font Parse
|
|
|
+ for el in list(geo.geo):
|
|
|
+ if type(el) == MultiPolygon:
|
|
|
+ for poly in el:
|
|
|
+ self.tool_shape.add(
|
|
|
+ shape=poly,
|
|
|
+ color=(self.app.defaults["global_draw_color"] + '80'),
|
|
|
+ update=False,
|
|
|
+ layer=0,
|
|
|
+ tolerance=None
|
|
|
+ )
|
|
|
+ elif type(el) == MultiLineString:
|
|
|
+ for linestring in el:
|
|
|
+ self.tool_shape.add(
|
|
|
+ shape=linestring,
|
|
|
+ color=(self.app.defaults["global_draw_color"] + '80'),
|
|
|
+ update=False,
|
|
|
+ layer=0,
|
|
|
+ tolerance=None
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ self.tool_shape.add(
|
|
|
+ shape=el,
|
|
|
+ color=(self.app.defaults["global_draw_color"] + '80'),
|
|
|
+ update=False,
|
|
|
+ layer=0,
|
|
|
+ tolerance=None
|
|
|
+ )
|
|
|
+ except TypeError:
|
|
|
+ self.tool_shape.add(
|
|
|
+ shape=geo.geo, color=(self.app.defaults["global_draw_color"] + '80'),
|
|
|
+ update=False, layer=0, tolerance=None)
|
|
|
+ self.tool_shape.redraw()
|
|
|
|
|
|
- # create the self.tools for the new Excellon object (the one with edited content)
|
|
|
- if current_tool not in self.new_tools:
|
|
|
- self.new_tools[current_tool] = {}
|
|
|
- self.new_tools[current_tool]['tooldia'] = float(tool_dia[0])
|
|
|
+ def replot(self):
|
|
|
+ self.plot_all()
|
|
|
|
|
|
- # add in self.tools the 'solid_geometry' key, the value (a list) is populated below
|
|
|
- self.new_tools[current_tool]['solid_geometry'] = []
|
|
|
+ def plot_all(self):
|
|
|
+ """
|
|
|
+ Plots all shapes in the editor.
|
|
|
|
|
|
- # create the self.slots for the new Excellon object (the one with edited content)
|
|
|
- for coord_dict in tool_dia[1]:
|
|
|
- slot = (
|
|
|
- Point(coord_dict['start']),
|
|
|
- Point(coord_dict['stop'])
|
|
|
- )
|
|
|
- try:
|
|
|
- self.new_tools[current_tool]['slots'].append(slot)
|
|
|
- except KeyError:
|
|
|
- self.new_tools[current_tool]['slots'] = [slot]
|
|
|
+ :return: None
|
|
|
+ :rtype: None
|
|
|
+ """
|
|
|
|
|
|
- # repopulate the 'solid_geometry' for each tool
|
|
|
- poly = LineString([coord_dict['start'], coord_dict['stop']]).buffer(
|
|
|
- float(tool_dia[0]) / 2.0, int(int(exc_obj.geo_steps_per_circle) / 4)
|
|
|
- )
|
|
|
- self.new_tools[current_tool]['solid_geometry'].append(poly)
|
|
|
+ self.shapes.clear(update=True)
|
|
|
|
|
|
- if self.is_modified is True:
|
|
|
- if "_edit" in self.edited_obj_name:
|
|
|
- try:
|
|
|
- idd = int(self.edited_obj_name[-1]) + 1
|
|
|
- self.edited_obj_name = self.edited_obj_name[:-1] + str(idd)
|
|
|
- except ValueError:
|
|
|
- self.edited_obj_name += "_1"
|
|
|
- else:
|
|
|
- self.edited_obj_name += "_edit"
|
|
|
+ for storage in self.storage_dict:
|
|
|
+ for shape_plus in self.storage_dict[storage].get_objects():
|
|
|
+ if shape_plus.geo is None:
|
|
|
+ continue
|
|
|
|
|
|
- self.app.worker_task.emit({'fcn': self.new_edited_excellon,
|
|
|
- 'params': [self.edited_obj_name,
|
|
|
- self.new_drills,
|
|
|
- self.new_slots,
|
|
|
- self.new_tools]})
|
|
|
+ if shape_plus in self.selected:
|
|
|
+ self.plot_shape(geometry=shape_plus.geo, color=self.app.defaults['global_sel_draw_color'] + 'FF',
|
|
|
+ linewidth=2)
|
|
|
+ continue
|
|
|
+ self.plot_shape(geometry=shape_plus.geo, color=self.app.defaults['global_draw_color'] + 'FF')
|
|
|
|
|
|
- return self.edited_obj_name
|
|
|
+ for shape_form in self.utility:
|
|
|
+ self.plot_shape(geometry=shape_form.geo, linewidth=1)
|
|
|
+ continue
|
|
|
|
|
|
- @staticmethod
|
|
|
- def update_options(obj):
|
|
|
- try:
|
|
|
- if not obj.options:
|
|
|
- obj.options = {}
|
|
|
- obj.options['xmin'] = 0
|
|
|
- obj.options['ymin'] = 0
|
|
|
- obj.options['xmax'] = 0
|
|
|
- obj.options['ymax'] = 0
|
|
|
- return True
|
|
|
- else:
|
|
|
- return False
|
|
|
- except AttributeError:
|
|
|
- obj.options = {}
|
|
|
- return True
|
|
|
+ self.shapes.redraw()
|
|
|
|
|
|
- def new_edited_excellon(self, outname, n_drills, n_slots, n_tools):
|
|
|
+ def plot_shape(self, geometry=None, color='0x000000FF', linewidth=1):
|
|
|
"""
|
|
|
- Creates a new Excellon object for the edited Excellon. Thread-safe.
|
|
|
-
|
|
|
- :param outname: Name of the resulting object. None causes the
|
|
|
- name to be that of the file.
|
|
|
- :type outname: str
|
|
|
+ Plots a geometric object or list of objects without rendering. Plotted objects
|
|
|
+ are returned as a list. This allows for efficient/animated rendering.
|
|
|
|
|
|
- :param n_drills: The new Drills storage
|
|
|
- :param n_slots: The new Slots storage
|
|
|
- :param n_tools: The new Tools storage
|
|
|
- :return: None
|
|
|
+ :param geometry: Geometry to be plotted (Any Shapely.geom kind or list of such)
|
|
|
+ :param color: Shape color
|
|
|
+ :param linewidth: Width of lines in # of pixels.
|
|
|
+ :return: List of plotted elements.
|
|
|
"""
|
|
|
+ plot_elements = []
|
|
|
|
|
|
- self.app.log.debug("Update the Excellon object with edited content. Source is %s" %
|
|
|
- self.exc_obj.options['name'])
|
|
|
+ if geometry is None:
|
|
|
+ geometry = self.active_tool.geometry
|
|
|
|
|
|
- new_drills = n_drills
|
|
|
- new_slots = n_slots
|
|
|
- new_tools = n_tools
|
|
|
+ try:
|
|
|
+ for geo in geometry:
|
|
|
+ plot_elements += self.plot_shape(geometry=geo, color=color, linewidth=linewidth)
|
|
|
|
|
|
- # How the object should be initialized
|
|
|
- def obj_init(excellon_obj, app_obj):
|
|
|
+ # ## Non-iterable
|
|
|
+ except TypeError:
|
|
|
+ # ## DrawToolShape
|
|
|
+ if isinstance(geometry, DrawToolShape):
|
|
|
+ plot_elements += self.plot_shape(geometry=geometry.geo, color=color, linewidth=linewidth)
|
|
|
|
|
|
- excellon_obj.drills = deepcopy(new_drills)
|
|
|
- excellon_obj.tools = deepcopy(new_tools)
|
|
|
- excellon_obj.slots = deepcopy(new_slots)
|
|
|
+ # ## Polygon: Descend into exterior and each interior.
|
|
|
+ if type(geometry) == Polygon:
|
|
|
+ plot_elements += self.plot_shape(geometry=geometry.exterior, color=color, linewidth=linewidth)
|
|
|
+ plot_elements += self.plot_shape(geometry=geometry.interiors, color=color, linewidth=linewidth)
|
|
|
|
|
|
- excellon_obj.options['name'] = outname
|
|
|
+ if type(geometry) == LineString or type(geometry) == LinearRing:
|
|
|
+ plot_elements.append(self.shapes.add(shape=geometry, color=color, layer=0, tolerance=self.tolerance))
|
|
|
|
|
|
- # add a 'data' dict for each tool with the default values
|
|
|
- for tool in excellon_obj.tools:
|
|
|
- excellon_obj.tools[tool]['data'] = {}
|
|
|
- excellon_obj.tools[tool]['data'].update(deepcopy(self.data_defaults))
|
|
|
+ if type(geometry) == Point:
|
|
|
+ pass
|
|
|
|
|
|
- try:
|
|
|
- excellon_obj.create_geometry()
|
|
|
- except KeyError:
|
|
|
- self.app.inform.emit('[ERROR_NOTCL] %s' %
|
|
|
- _("There are no Tools definitions in the file. Aborting Excellon creation.")
|
|
|
- )
|
|
|
- except Exception:
|
|
|
- msg = '[ERROR] %s' % \
|
|
|
- _("An internal error has ocurred. See Shell.\n")
|
|
|
- msg += traceback.format_exc()
|
|
|
- app_obj.inform.emit(msg)
|
|
|
- return
|
|
|
+ return plot_elements
|
|
|
|
|
|
- with self.app.proc_container.new(_("Creating Excellon.")):
|
|
|
+ def on_shape_complete(self):
|
|
|
+ # Add shape
|
|
|
+ self.add_shape(self.active_tool.geometry)
|
|
|
|
|
|
- try:
|
|
|
- edited_obj = self.app.app_obj.new_object("excellon", outname, obj_init)
|
|
|
- edited_obj.source_file = self.app.export_excellon(obj_name=edited_obj.options['name'],
|
|
|
- local_use=edited_obj,
|
|
|
- filename=None,
|
|
|
- use_thread=False)
|
|
|
- except Exception as e:
|
|
|
- self.deactivate()
|
|
|
- log.error("Error on Edited object creation: %s" % str(e))
|
|
|
- return
|
|
|
+ # Remove any utility shapes
|
|
|
+ self.delete_utility_geometry()
|
|
|
+ self.tool_shape.clear(update=True)
|
|
|
|
|
|
- self.deactivate()
|
|
|
- self.app.inform.emit('[success] %s' % _("Excellon editing finished."))
|
|
|
+ # Replot and reset tool.
|
|
|
+ self.replot()
|
|
|
+ # self.active_tool = type(self.active_tool)(self)
|
|
|
|
|
|
- def on_tool_select(self, tool):
|
|
|
+ def get_selected(self):
|
|
|
"""
|
|
|
- Behavior of the toolbar. Tool initialization.
|
|
|
+ Returns list of shapes that are selected in the editor.
|
|
|
|
|
|
- :rtype : None
|
|
|
+ :return: List of shapes.
|
|
|
"""
|
|
|
- current_tool = tool
|
|
|
+ return self.selected
|
|
|
|
|
|
- self.app.log.debug("on_tool_select('%s')" % tool)
|
|
|
+ def delete_selected(self):
|
|
|
+ temp_ref = [s for s in self.selected]
|
|
|
+ for shape_sel in temp_ref:
|
|
|
+ self.delete_shape(shape_sel)
|
|
|
|
|
|
- if self.last_tool_selected is None and current_tool != 'drill_select':
|
|
|
- # self.draw_app.select_tool('drill_select')
|
|
|
- self.complete = True
|
|
|
- current_tool = 'drill_select'
|
|
|
- self.app.inform.emit('[WARNING_NOTCL] %s' %
|
|
|
- _("Cancelled. There is no Tool/Drill selected"))
|
|
|
+ self.selected = []
|
|
|
+ self.build_ui()
|
|
|
+ self.app.inform.emit('[success] %s' % _("Done. Drill(s) deleted."))
|
|
|
+
|
|
|
+ def delete_shape(self, del_shape):
|
|
|
+ self.is_modified = True
|
|
|
+
|
|
|
+ if del_shape in self.utility:
|
|
|
+ self.utility.remove(del_shape)
|
|
|
+ return
|
|
|
+
|
|
|
+ for storage in self.storage_dict:
|
|
|
+ # try:
|
|
|
+ # self.storage_dict[storage].remove(shape)
|
|
|
+ # except:
|
|
|
+ # pass
|
|
|
+ if del_shape in self.storage_dict[storage].get_objects():
|
|
|
+ if isinstance(del_shape.geo, MultiLineString):
|
|
|
+ self.storage_dict[storage].remove(del_shape)
|
|
|
+ # a hack to make the tool_table display less drills per diameter
|
|
|
+ # self.points_edit it's only useful first time when we load the data into the storage
|
|
|
+ # but is still used as referecen when building tool_table in self.build_ui()
|
|
|
+ # the number of drills displayed in column 2 is just a len(self.points_edit) therefore
|
|
|
+ # deleting self.points_edit elements (doesn't matter who but just the number)
|
|
|
+ # solved the display issue.
|
|
|
+ del self.points_edit[storage][0]
|
|
|
+ else:
|
|
|
+ self.storage_dict[storage].remove(del_shape)
|
|
|
+ del self.slot_points_edit[storage][0]
|
|
|
|
|
|
- # This is to make the group behave as radio group
|
|
|
- if current_tool in self.tools_exc:
|
|
|
- if self.tools_exc[current_tool]["button"].isChecked():
|
|
|
- self.app.log.debug("%s is checked." % current_tool)
|
|
|
- for t in self.tools_exc:
|
|
|
- if t != current_tool:
|
|
|
- self.tools_exc[t]["button"].setChecked(False)
|
|
|
+ if del_shape in self.selected:
|
|
|
+ self.selected.remove(del_shape)
|
|
|
|
|
|
- # this is where the Editor toolbar classes (button's) are instantiated
|
|
|
- self.active_tool = self.tools_exc[current_tool]["constructor"](self)
|
|
|
- # self.app.inform.emit(self.active_tool.start_msg)
|
|
|
- else:
|
|
|
- self.app.log.debug("%s is NOT checked." % current_tool)
|
|
|
- for t in self.tools_exc:
|
|
|
- self.tools_exc[t]["button"].setChecked(False)
|
|
|
+ def delete_utility_geometry(self):
|
|
|
+ for_deletion = [util_shape for util_shape in self.utility]
|
|
|
+ for util_shape in for_deletion:
|
|
|
+ self.delete_shape(util_shape)
|
|
|
|
|
|
- self.select_tool('drill_select')
|
|
|
- self.active_tool = FCDrillSelect(self)
|
|
|
+ self.tool_shape.clear(update=True)
|
|
|
+ self.tool_shape.redraw()
|
|
|
|
|
|
- def on_row_selected(self, row, col):
|
|
|
- if col == 0:
|
|
|
- key_modifier = QtWidgets.QApplication.keyboardModifiers()
|
|
|
- if self.app.defaults["global_mselect_key"] == 'Control':
|
|
|
- modifier_to_use = Qt.ControlModifier
|
|
|
- else:
|
|
|
- modifier_to_use = Qt.ShiftModifier
|
|
|
+ def on_delete_btn(self):
|
|
|
+ self.delete_selected()
|
|
|
+ self.replot()
|
|
|
|
|
|
- if key_modifier == modifier_to_use:
|
|
|
- pass
|
|
|
- else:
|
|
|
- self.selected = []
|
|
|
+ def select_tool(self, toolname):
|
|
|
+ """
|
|
|
+ Selects a drawing tool. Impacts the object and appGUI.
|
|
|
|
|
|
- try:
|
|
|
- selected_dia = self.tool2tooldia[self.tools_table_exc.currentRow() + 1]
|
|
|
- self.last_tool_selected = int(self.tools_table_exc.currentRow()) + 1
|
|
|
- for obj in self.storage_dict[selected_dia].get_objects():
|
|
|
- self.selected.append(obj)
|
|
|
- except Exception as e:
|
|
|
- self.app.log.debug(str(e))
|
|
|
+ :param toolname: Name of the tool.
|
|
|
+ :return: None
|
|
|
+ """
|
|
|
+ self.tools_exc[toolname]["button"].setChecked(True)
|
|
|
+ self.on_tool_select(toolname)
|
|
|
|
|
|
- self.replot()
|
|
|
+ def set_selected(self, sel_shape):
|
|
|
|
|
|
- # def toolbar_tool_toggle(self, key):
|
|
|
- # self.options[key] = self.sender().isChecked()
|
|
|
- # if self.options[key] is True:
|
|
|
- # return 1
|
|
|
- # else:
|
|
|
- # return 0
|
|
|
+ # Remove and add to the end.
|
|
|
+ if sel_shape in self.selected:
|
|
|
+ self.selected.remove(sel_shape)
|
|
|
|
|
|
- def on_canvas_click(self, event):
|
|
|
- """
|
|
|
- event.x and .y have canvas coordinates
|
|
|
- event.xdata and .ydata have plot coordinates
|
|
|
+ self.selected.append(sel_shape)
|
|
|
|
|
|
- :param event: Event object dispatched by VisPy
|
|
|
- :return: None
|
|
|
- """
|
|
|
- if self.app.is_legacy is False:
|
|
|
- event_pos = event.pos
|
|
|
- # event_is_dragging = event.is_dragging
|
|
|
- # right_button = 2
|
|
|
+ def set_unselected(self, unsel_shape):
|
|
|
+ if unsel_shape in self.selected:
|
|
|
+ self.selected.remove(unsel_shape)
|
|
|
+
|
|
|
+ def on_array_type_combo(self):
|
|
|
+ if self.e_ui.array_type_combo.currentIndex() == 0:
|
|
|
+ self.e_ui.array_circular_frame.hide()
|
|
|
+ self.e_ui.array_linear_frame.show()
|
|
|
else:
|
|
|
- event_pos = (event.xdata, event.ydata)
|
|
|
- # event_is_dragging = self.app.plotcanvas.is_dragging
|
|
|
- # right_button = 3
|
|
|
+ self.delete_utility_geometry()
|
|
|
+ self.e_ui.array_circular_frame.show()
|
|
|
+ self.e_ui.array_linear_frame.hide()
|
|
|
+ self.app.inform.emit(_("Click on the circular array Center position"))
|
|
|
|
|
|
- self.pos = self.canvas.translate_coords(event_pos)
|
|
|
+ def on_slot_array_type_combo(self):
|
|
|
+ if self.e_ui.slot_array_type_combo.currentIndex() == 0:
|
|
|
+ self.e_ui.slot_array_circular_frame.hide()
|
|
|
+ self.e_ui.slot_array_linear_frame.show()
|
|
|
+ else:
|
|
|
+ self.delete_utility_geometry()
|
|
|
+ self.e_ui.slot_array_circular_frame.show()
|
|
|
+ self.e_ui.slot_array_linear_frame.hide()
|
|
|
+ self.app.inform.emit(_("Click on the circular array Center position"))
|
|
|
|
|
|
- if self.app.grid_status():
|
|
|
- self.pos = self.app.geo_editor.snap(self.pos[0], self.pos[1])
|
|
|
+ def on_linear_angle_radio(self):
|
|
|
+ val = self.e_ui.drill_axis_radio.get_value()
|
|
|
+ if val == 'A':
|
|
|
+ self.e_ui.linear_angle_spinner.show()
|
|
|
+ self.e_ui.linear_angle_label.show()
|
|
|
else:
|
|
|
- self.pos = (self.pos[0], self.pos[1])
|
|
|
+ self.e_ui.linear_angle_spinner.hide()
|
|
|
+ self.e_ui.linear_angle_label.hide()
|
|
|
|
|
|
- if event.button == 1:
|
|
|
- self.app.ui.rel_position_label.setText("<b>Dx</b>: %.4f <b>Dy</b>: "
|
|
|
- "%.4f " % (0, 0))
|
|
|
+ def on_slot_array_linear_angle_radio(self):
|
|
|
+ val = self.e_ui.slot_array_axis_radio.get_value()
|
|
|
+ if val == 'A':
|
|
|
+ self.e_ui.slot_array_linear_angle_spinner.show()
|
|
|
+ self.e_ui.slot_array_linear_angle_label.show()
|
|
|
+ else:
|
|
|
+ self.e_ui.slot_array_linear_angle_spinner.hide()
|
|
|
+ self.e_ui.slot_array_linear_angle_label.hide()
|
|
|
|
|
|
- # Selection with left mouse button
|
|
|
- if self.active_tool is not None and event.button == 1:
|
|
|
- # Dispatch event to active_tool
|
|
|
- # msg = self.active_tool.click(self.app.geo_editor.snap(event.xdata, event.ydata))
|
|
|
- self.active_tool.click(self.app.geo_editor.snap(self.pos[0], self.pos[1]))
|
|
|
+ def on_slot_angle_radio(self):
|
|
|
+ val = self.e_ui.slot_axis_radio.get_value()
|
|
|
+ if val == 'A':
|
|
|
+ self.e_ui.slot_angle_spinner.show()
|
|
|
+ self.e_ui.slot_angle_label.show()
|
|
|
+ else:
|
|
|
+ self.e_ui.slot_angle_spinner.hide()
|
|
|
+ self.e_ui.slot_angle_label.hide()
|
|
|
|
|
|
- # If it is a shape generating tool
|
|
|
- if isinstance(self.active_tool, FCShapeTool) and self.active_tool.complete:
|
|
|
- if self.current_storage is not None:
|
|
|
- self.on_exc_shape_complete(self.current_storage)
|
|
|
- self.build_ui()
|
|
|
+ def exc_add_drill(self):
|
|
|
+ self.select_tool('drill_add')
|
|
|
+ return
|
|
|
|
|
|
- # MS: always return to the Select Tool if modifier key is not pressed
|
|
|
- # else return to the current tool
|
|
|
- key_modifier = QtWidgets.QApplication.keyboardModifiers()
|
|
|
- if self.app.defaults["global_mselect_key"] == 'Control':
|
|
|
- modifier_to_use = Qt.ControlModifier
|
|
|
- else:
|
|
|
- modifier_to_use = Qt.ShiftModifier
|
|
|
+ def exc_add_drill_array(self):
|
|
|
+ self.select_tool('drill_array')
|
|
|
+ return
|
|
|
|
|
|
- # if modifier key is pressed then we add to the selected list the current shape but if it's already
|
|
|
- # in the selected list, we removed it. Therefore first click selects, second deselects.
|
|
|
- if key_modifier == modifier_to_use:
|
|
|
- self.select_tool(self.active_tool.name)
|
|
|
- else:
|
|
|
- # return to Select tool but not for FCDrillAdd or FCSlot
|
|
|
- if isinstance(self.active_tool, FCDrillAdd) or isinstance(self.active_tool, FCSlot):
|
|
|
- self.select_tool(self.active_tool.name)
|
|
|
- else:
|
|
|
- self.select_tool("drill_select")
|
|
|
- return
|
|
|
+ def exc_add_slot(self):
|
|
|
+ self.select_tool('slot_add')
|
|
|
+ return
|
|
|
|
|
|
- if isinstance(self.active_tool, FCDrillSelect):
|
|
|
- # self.app.log.debug("Replotting after click.")
|
|
|
- self.replot()
|
|
|
- else:
|
|
|
- self.app.log.debug("No active tool to respond to click!")
|
|
|
+ def exc_add_slot_array(self):
|
|
|
+ self.select_tool('slot_array')
|
|
|
+ return
|
|
|
|
|
|
- def on_exc_shape_complete(self, storage):
|
|
|
- self.app.log.debug("on_shape_complete()")
|
|
|
+ def exc_resize_drills(self):
|
|
|
+ self.select_tool('drill_resize')
|
|
|
+ return
|
|
|
|
|
|
- # Add shape
|
|
|
- if type(storage) is list:
|
|
|
- for item_storage in storage:
|
|
|
- self.add_exc_shape(self.active_tool.geometry, item_storage)
|
|
|
- else:
|
|
|
- self.add_exc_shape(self.active_tool.geometry, storage)
|
|
|
+ def exc_copy_drills(self):
|
|
|
+ self.select_tool('drill_copy')
|
|
|
+ return
|
|
|
|
|
|
- # Remove any utility shapes
|
|
|
- self.delete_utility_geometry()
|
|
|
- self.tool_shape.clear(update=True)
|
|
|
+ def exc_move_drills(self):
|
|
|
+ self.select_tool('drill_move')
|
|
|
+ return
|
|
|
|
|
|
- # Replot and reset tool.
|
|
|
+ def on_slots_conversion(self):
|
|
|
+ # selected rows
|
|
|
+ selected_rows = set()
|
|
|
+ for it in self.e_ui.tools_table_exc.selectedItems():
|
|
|
+ selected_rows.add(it.row())
|
|
|
+
|
|
|
+ # convert a Polygon (slot) to a MultiLineString (drill)
|
|
|
+ def convert_slot2drill(geo_elem, tool_dia):
|
|
|
+ point = geo_elem.centroid
|
|
|
+ start_hor_line = ((point.x - (tool_dia / 2)), point.y)
|
|
|
+ stop_hor_line = ((point.x + (tool_dia / 2)), point.y)
|
|
|
+ start_vert_line = (point.x, (point.y - (tool_dia / 2)))
|
|
|
+ stop_vert_line = (point.x, (point.y + (tool_dia / 2)))
|
|
|
+ return MultiLineString([(start_hor_line, stop_hor_line), (start_vert_line, stop_vert_line)])
|
|
|
+
|
|
|
+ # temporary new storage: a dist with keys the tool diameter and values Rtree storage
|
|
|
+ new_storage_dict = {}
|
|
|
+
|
|
|
+ for row in selected_rows:
|
|
|
+ table_tooldia = self.dec_format(float(self.e_ui.tools_table_exc.item(row, 1).text()))
|
|
|
+ for dict_dia, geo_dict in self.storage_dict.items():
|
|
|
+ if self.dec_format(float(dict_dia)) == table_tooldia:
|
|
|
+ storage_elem = AppGeoEditor.make_storage()
|
|
|
+ for shape in geo_dict.get_objects():
|
|
|
+ if isinstance(shape.geo, MultiLineString):
|
|
|
+ # it's a drill just add it as it is to storage
|
|
|
+ self.add_exc_shape(shape, storage_elem)
|
|
|
+ if isinstance(shape.geo, Polygon):
|
|
|
+ # it's a slot, convert drill to slot and then add it to storage
|
|
|
+ new_shape = convert_slot2drill(shape.geo, table_tooldia)
|
|
|
+ self.add_exc_shape(DrawToolShape(new_shape), storage_elem)
|
|
|
+
|
|
|
+ new_storage_dict[table_tooldia] = storage_elem
|
|
|
+
|
|
|
+ self.storage_dict.update(new_storage_dict)
|
|
|
self.replot()
|
|
|
- # self.active_tool = type(self.active_tool)(self)
|
|
|
|
|
|
- def add_exc_shape(self, shape, storage):
|
|
|
- """
|
|
|
- Adds a shape to a specified shape storage.
|
|
|
|
|
|
- :param shape: Shape to be added.
|
|
|
- :type shape: DrawToolShape
|
|
|
- :param storage: object where to store the shapes
|
|
|
- :return: None
|
|
|
- """
|
|
|
- # List of DrawToolShape?
|
|
|
- if isinstance(shape, list):
|
|
|
- for subshape in shape:
|
|
|
- self.add_exc_shape(subshape, storage)
|
|
|
- return
|
|
|
+class AppExcEditorUI:
|
|
|
+ def __init__(self, app):
|
|
|
+ self.app = app
|
|
|
|
|
|
- assert isinstance(shape, DrawToolShape), \
|
|
|
- "Expected a DrawToolShape, got %s" % str(type(shape))
|
|
|
+ # Number of decimals used by tools in this class
|
|
|
+ self.decimals = self.app.decimals
|
|
|
|
|
|
- assert shape.geo is not None, \
|
|
|
- "Shape object has empty geometry (None)"
|
|
|
+ # ## Current application units in Upper Case
|
|
|
+ self.units = self.app.defaults['units'].upper()
|
|
|
|
|
|
- assert (isinstance(shape.geo, list) and len(shape.geo) > 0) or not isinstance(shape.geo, list), \
|
|
|
- "Shape objects has empty geometry ([])"
|
|
|
+ self.exc_edit_widget = QtWidgets.QWidget()
|
|
|
+ # ## Box for custom widgets
|
|
|
+ # This gets populated in offspring implementations.
|
|
|
+ layout = QtWidgets.QVBoxLayout()
|
|
|
+ self.exc_edit_widget.setLayout(layout)
|
|
|
|
|
|
- if isinstance(shape, DrawToolUtilityShape):
|
|
|
- self.utility.append(shape)
|
|
|
- else:
|
|
|
- storage.insert(shape) # TODO: Check performance
|
|
|
+ # add a frame and inside add a vertical box layout. Inside this vbox layout I add all the Drills widgets
|
|
|
+ # this way I can hide/show the frame
|
|
|
+ self.drills_frame = QtWidgets.QFrame()
|
|
|
+ self.drills_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
+ layout.addWidget(self.drills_frame)
|
|
|
+ self.tools_box = QtWidgets.QVBoxLayout()
|
|
|
+ self.tools_box.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.drills_frame.setLayout(self.tools_box)
|
|
|
|
|
|
- def add_shape(self, shape):
|
|
|
- """
|
|
|
- Adds a shape to the shape storage.
|
|
|
+ # ## Page Title box (spacing between children)
|
|
|
+ self.title_box = QtWidgets.QHBoxLayout()
|
|
|
+ self.tools_box.addLayout(self.title_box)
|
|
|
|
|
|
- :param shape: Shape to be added.
|
|
|
- :type shape: DrawToolShape
|
|
|
- :return: None
|
|
|
- """
|
|
|
+ # ## Page Title icon
|
|
|
+ pixmap = QtGui.QPixmap(self.app.resource_location + '/flatcam_icon32.png')
|
|
|
+ self.icon = QtWidgets.QLabel()
|
|
|
+ self.icon.setPixmap(pixmap)
|
|
|
+ self.title_box.addWidget(self.icon, stretch=0)
|
|
|
|
|
|
- # List of DrawToolShape?
|
|
|
- if isinstance(shape, list):
|
|
|
- for subshape in shape:
|
|
|
- self.add_shape(subshape)
|
|
|
- return
|
|
|
+ # ## Title label
|
|
|
+ self.title_label = QtWidgets.QLabel("<font size=5><b>%s</b></font>" % _('Excellon Editor'))
|
|
|
+ self.title_label.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
|
|
|
+ self.title_box.addWidget(self.title_label, stretch=1)
|
|
|
|
|
|
- assert isinstance(shape, DrawToolShape), \
|
|
|
- "Expected a DrawToolShape, got %s" % type(shape)
|
|
|
+ # ## Object name
|
|
|
+ self.name_box = QtWidgets.QHBoxLayout()
|
|
|
+ self.tools_box.addLayout(self.name_box)
|
|
|
+ name_label = QtWidgets.QLabel(_("Name:"))
|
|
|
+ self.name_box.addWidget(name_label)
|
|
|
+ self.name_entry = FCEntry()
|
|
|
+ self.name_box.addWidget(self.name_entry)
|
|
|
|
|
|
- assert shape.geo is not None, \
|
|
|
- "Shape object has empty geometry (None)"
|
|
|
+ # ### Tools Drills ## ##
|
|
|
+ self.tools_table_label = QtWidgets.QLabel("<b>%s</b>" % _('Tools Table'))
|
|
|
+ self.tools_table_label.setToolTip(
|
|
|
+ _("Tools in this Excellon object\n"
|
|
|
+ "when are used for drilling.")
|
|
|
+ )
|
|
|
+ self.tools_box.addWidget(self.tools_table_label)
|
|
|
|
|
|
- assert (isinstance(shape.geo, list) and len(shape.geo) > 0) or not isinstance(shape.geo, list), \
|
|
|
- "Shape objects has empty geometry ([])"
|
|
|
+ self.tools_table_exc = FCTable()
|
|
|
+ # delegate = SpinBoxDelegate(units=self.units)
|
|
|
+ # self.e_ui.tools_table_exc.setItemDelegateForColumn(1, delegate)
|
|
|
|
|
|
- if isinstance(shape, DrawToolUtilityShape):
|
|
|
- self.utility.append(shape)
|
|
|
- # else:
|
|
|
- # self.storage.insert(shape)
|
|
|
+ self.tools_box.addWidget(self.tools_table_exc)
|
|
|
|
|
|
- def on_exc_click_release(self, event):
|
|
|
- """
|
|
|
- Handler of the "mouse_release" event.
|
|
|
- It will pop-up the context menu on right mouse click unless there was a panning move (decided in the
|
|
|
- "mouse_move" event handler) and only if the current tool is the Select tool.
|
|
|
- It will 'close' a Editor tool if it is the case.
|
|
|
+ self.tools_table_exc.setColumnCount(4)
|
|
|
+ self.tools_table_exc.setHorizontalHeaderLabels(['#', _('Diameter'), 'D', 'S'])
|
|
|
+ self.tools_table_exc.setSortingEnabled(False)
|
|
|
+ self.tools_table_exc.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
|
|
|
|
|
|
- :param event: Event object dispatched by VisPy SceneCavas
|
|
|
- :return: None
|
|
|
- """
|
|
|
+ separator_line = QtWidgets.QFrame()
|
|
|
+ separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
|
|
+ separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
|
|
+ self.tools_box.addWidget(separator_line)
|
|
|
|
|
|
- if self.app.is_legacy is False:
|
|
|
- event_pos = event.pos
|
|
|
- # event_is_dragging = event.is_dragging
|
|
|
- right_button = 2
|
|
|
- else:
|
|
|
- event_pos = (event.xdata, event.ydata)
|
|
|
- # event_is_dragging = self.app.plotcanvas.is_dragging
|
|
|
- right_button = 3
|
|
|
+ self.convert_slots_btn = FCButton('%s' % _("Convert Slots"))
|
|
|
+ self.convert_slots_btn.setToolTip(
|
|
|
+ _("Convert the slots in the selected tools to drills.")
|
|
|
+ )
|
|
|
+ self.tools_box.addWidget(self.convert_slots_btn)
|
|
|
|
|
|
- pos_canvas = self.canvas.translate_coords(event_pos)
|
|
|
+ separator_line = QtWidgets.QFrame()
|
|
|
+ separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
|
|
+ separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
|
|
+ self.tools_box.addWidget(separator_line)
|
|
|
|
|
|
- if self.app.grid_status():
|
|
|
- pos = self.app.geo_editor.snap(pos_canvas[0], pos_canvas[1])
|
|
|
- else:
|
|
|
- pos = (pos_canvas[0], pos_canvas[1])
|
|
|
+ # ### Add a new Tool ## ##
|
|
|
+ self.addtool_label = QtWidgets.QLabel('<b>%s</b>' % _('Add/Delete Tool'))
|
|
|
+ self.addtool_label.setToolTip(
|
|
|
+ _("Add/Delete a tool to the tool list\n"
|
|
|
+ "for this Excellon object.")
|
|
|
+ )
|
|
|
+ self.tools_box.addWidget(self.addtool_label)
|
|
|
|
|
|
- # if the released mouse button was RMB then test if it was a panning motion or not, if not it was a context
|
|
|
- # canvas menu
|
|
|
- try:
|
|
|
- if event.button == right_button: # right click
|
|
|
- if self.app.ui.popMenu.mouse_is_panning is False:
|
|
|
- try:
|
|
|
- QtGui.QGuiApplication.restoreOverrideCursor()
|
|
|
- except Exception:
|
|
|
- pass
|
|
|
- if self.active_tool.complete is False and not isinstance(self.active_tool, FCDrillSelect):
|
|
|
- self.active_tool.complete = True
|
|
|
- self.in_action = False
|
|
|
- self.delete_utility_geometry()
|
|
|
- self.app.inform.emit('[success] %s' %
|
|
|
- _("Done."))
|
|
|
- self.select_tool('drill_select')
|
|
|
- else:
|
|
|
- if isinstance(self.active_tool, FCDrillAdd):
|
|
|
- self.active_tool.complete = True
|
|
|
- self.in_action = False
|
|
|
- self.delete_utility_geometry()
|
|
|
- self.app.inform.emit('[success] %s' %
|
|
|
- _("Done."))
|
|
|
- self.select_tool('drill_select')
|
|
|
+ grid1 = QtWidgets.QGridLayout()
|
|
|
+ self.tools_box.addLayout(grid1)
|
|
|
+ grid1.setColumnStretch(0, 0)
|
|
|
+ grid1.setColumnStretch(1, 1)
|
|
|
|
|
|
- self.app.cursor = QtGui.QCursor()
|
|
|
- self.app.populate_cmenu_grids()
|
|
|
- self.app.ui.popMenu.popup(self.app.cursor.pos())
|
|
|
+ addtool_entry_lbl = QtWidgets.QLabel('%s:' % _('Tool Dia'))
|
|
|
+ addtool_entry_lbl.setToolTip(
|
|
|
+ _("Diameter for the new tool")
|
|
|
+ )
|
|
|
|
|
|
- except Exception as e:
|
|
|
- log.warning("AppExcEditor.on_exc_click_release() RMB click --> Error: %s" % str(e))
|
|
|
- raise
|
|
|
+ hlay = QtWidgets.QHBoxLayout()
|
|
|
+ self.addtool_entry = FCDoubleSpinner()
|
|
|
+ self.addtool_entry.set_precision(self.decimals)
|
|
|
+ self.addtool_entry.set_range(0.0000, 9999.9999)
|
|
|
|
|
|
- # if the released mouse button was LMB then test if we had a right-to-left selection or a left-to-right
|
|
|
- # selection and then select a type of selection ("enclosing" or "touching")
|
|
|
- try:
|
|
|
- if event.button == 1: # left click
|
|
|
- if self.app.selection_type is not None:
|
|
|
- self.draw_selection_area_handler(self.pos, pos, self.app.selection_type)
|
|
|
- self.app.selection_type = None
|
|
|
+ hlay.addWidget(self.addtool_entry)
|
|
|
|
|
|
- elif isinstance(self.active_tool, FCDrillSelect):
|
|
|
- self.active_tool.click_release((self.pos[0], self.pos[1]))
|
|
|
+ self.addtool_btn = QtWidgets.QPushButton(_('Add Tool'))
|
|
|
+ self.addtool_btn.setToolTip(
|
|
|
+ _("Add a new tool to the tool list\n"
|
|
|
+ "with the diameter specified above.")
|
|
|
+ )
|
|
|
+ self.addtool_btn.setFixedWidth(80)
|
|
|
+ hlay.addWidget(self.addtool_btn)
|
|
|
|
|
|
- # if there are selected objects then plot them
|
|
|
- if self.selected:
|
|
|
- self.replot()
|
|
|
- except Exception as e:
|
|
|
- log.warning("AppExcEditor.on_exc_click_release() LMB click --> Error: %s" % str(e))
|
|
|
- raise
|
|
|
+ grid1.addWidget(addtool_entry_lbl, 0, 0)
|
|
|
+ grid1.addLayout(hlay, 0, 1)
|
|
|
|
|
|
- def draw_selection_area_handler(self, start, end, sel_type):
|
|
|
- """
|
|
|
- This function is called whenever we have a left mouse click release and only we have a left mouse click drag,
|
|
|
- be it from left to right or from right to left. The direction of the drag is decided in the "mouse_move"
|
|
|
- event handler.
|
|
|
- Pressing a modifier key (eg. Ctrl, Shift or Alt) will change the behavior of the selection.
|
|
|
+ grid2 = QtWidgets.QGridLayout()
|
|
|
+ self.tools_box.addLayout(grid2)
|
|
|
|
|
|
- Depending on which tool belongs the selected shapes, the corresponding rows in the Tools Table are selected or
|
|
|
- deselected.
|
|
|
+ self.deltool_btn = QtWidgets.QPushButton(_('Delete Tool'))
|
|
|
+ self.deltool_btn.setToolTip(
|
|
|
+ _("Delete a tool in the tool list\n"
|
|
|
+ "by selecting a row in the tool table.")
|
|
|
+ )
|
|
|
+ grid2.addWidget(self.deltool_btn, 0, 1)
|
|
|
|
|
|
- :param start: mouse position when the selection LMB click was done
|
|
|
- :param end: mouse position when the left mouse button is released
|
|
|
- :param sel_type: if True it's a left to right selection (enclosure), if False it's a 'touch' selection
|
|
|
- :return:
|
|
|
- """
|
|
|
+ # add a frame and inside add a vertical box layout. Inside this vbox layout I add all the Drills widgets
|
|
|
+ # this way I can hide/show the frame
|
|
|
+ self.resize_frame = QtWidgets.QFrame()
|
|
|
+ self.resize_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.tools_box.addWidget(self.resize_frame)
|
|
|
+ self.resize_box = QtWidgets.QVBoxLayout()
|
|
|
+ self.resize_box.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.resize_frame.setLayout(self.resize_box)
|
|
|
|
|
|
- start_pos = (start[0], start[1])
|
|
|
- end_pos = (end[0], end[1])
|
|
|
- poly_selection = Polygon([start_pos, (end_pos[0], start_pos[1]), end_pos, (start_pos[0], end_pos[1])])
|
|
|
- modifiers = None
|
|
|
+ # ### Resize a drill ## ##
|
|
|
+ self.emptyresize_label = QtWidgets.QLabel('')
|
|
|
+ self.resize_box.addWidget(self.emptyresize_label)
|
|
|
|
|
|
- # delete the selection shape that was just drawn, we no longer need it
|
|
|
- self.app.delete_selection_shape()
|
|
|
+ self.drillresize_label = QtWidgets.QLabel('<b>%s</b>' % _("Resize Drill(s)"))
|
|
|
+ self.drillresize_label.setToolTip(
|
|
|
+ _("Resize a drill or a selection of drills.")
|
|
|
+ )
|
|
|
+ self.resize_box.addWidget(self.drillresize_label)
|
|
|
|
|
|
- # detect if a modifier key was pressed while the left mouse button was released
|
|
|
- self.modifiers = QtWidgets.QApplication.keyboardModifiers()
|
|
|
- if self.modifiers == QtCore.Qt.ShiftModifier:
|
|
|
- modifiers = 'Shift'
|
|
|
- elif self.modifiers == QtCore.Qt.ControlModifier:
|
|
|
- modifiers = 'Control'
|
|
|
+ grid3 = QtWidgets.QGridLayout()
|
|
|
+ self.resize_box.addLayout(grid3)
|
|
|
|
|
|
- if modifiers == self.app.defaults["global_mselect_key"]:
|
|
|
- for storage in self.storage_dict:
|
|
|
- for obj in self.storage_dict[storage].get_objects():
|
|
|
- if (sel_type is True and poly_selection.contains(obj.geo)) or \
|
|
|
- (sel_type is False and poly_selection.intersects(obj.geo)):
|
|
|
+ res_entry_lbl = QtWidgets.QLabel('%s:' % _('Resize Dia'))
|
|
|
+ res_entry_lbl.setToolTip(
|
|
|
+ _("Diameter to resize to.")
|
|
|
+ )
|
|
|
+ grid3.addWidget(res_entry_lbl, 0, 0)
|
|
|
|
|
|
- if obj in self.selected:
|
|
|
- # remove the shape object from the selected shapes storage
|
|
|
- self.selected.remove(obj)
|
|
|
- else:
|
|
|
- # add the shape object to the selected shapes storage
|
|
|
- self.selected.append(obj)
|
|
|
- else:
|
|
|
- # clear the selection shapes storage
|
|
|
- self.selected = []
|
|
|
- # then add to the selection shapes storage the shapes that are included (touched) by the selection rectangle
|
|
|
- for storage in self.storage_dict:
|
|
|
- for obj in self.storage_dict[storage].get_objects():
|
|
|
- if (sel_type is True and poly_selection.contains(obj.geo)) or \
|
|
|
- (sel_type is False and poly_selection.intersects(obj.geo)):
|
|
|
- self.selected.append(obj)
|
|
|
+ hlay2 = QtWidgets.QHBoxLayout()
|
|
|
+ self.resdrill_entry = FCDoubleSpinner()
|
|
|
+ self.resdrill_entry.set_precision(self.decimals)
|
|
|
+ self.resdrill_entry.set_range(0.0000, 9999.9999)
|
|
|
|
|
|
- try:
|
|
|
- self.tools_table_exc.cellPressed.disconnect()
|
|
|
- except Exception:
|
|
|
- pass
|
|
|
+ hlay2.addWidget(self.resdrill_entry)
|
|
|
|
|
|
- # first deselect all rows (tools) in the Tools Table
|
|
|
- self.tools_table_exc.clearSelection()
|
|
|
- # and select the rows (tools) in the tool table according to the diameter(s) of the selected shape(s)
|
|
|
- self.tools_table_exc.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
|
|
|
- for storage in self.storage_dict:
|
|
|
- for shape_s in self.selected:
|
|
|
- if shape_s in self.storage_dict[storage].get_objects():
|
|
|
- for key_tool_nr in self.tool2tooldia:
|
|
|
- if self.tool2tooldia[key_tool_nr] == storage:
|
|
|
- row_to_sel = key_tool_nr - 1
|
|
|
- # item = self.tools_table_exc.item(row_to_sel, 1)
|
|
|
- # self.tools_table_exc.setCurrentItem(item)
|
|
|
- # item.setSelected(True)
|
|
|
+ self.resize_btn = QtWidgets.QPushButton(_('Resize'))
|
|
|
+ self.resize_btn.setToolTip(
|
|
|
+ _("Resize drill(s)")
|
|
|
+ )
|
|
|
+ self.resize_btn.setFixedWidth(80)
|
|
|
+ hlay2.addWidget(self.resize_btn)
|
|
|
+ grid3.addLayout(hlay2, 0, 1)
|
|
|
|
|
|
- # if the row to be selected is not already in the selected rows then select it
|
|
|
- # otherwise don't do it as it seems that we have a toggle effect
|
|
|
- if row_to_sel not in set(index.row() for index in self.tools_table_exc.selectedIndexes()):
|
|
|
- self.tools_table_exc.selectRow(row_to_sel)
|
|
|
- self.last_tool_selected = int(key_tool_nr)
|
|
|
+ self.resize_frame.hide()
|
|
|
|
|
|
- self.tools_table_exc.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
|
|
|
+ # ####################################
|
|
|
+ # ### Add DRILL Array ################
|
|
|
+ # ####################################
|
|
|
|
|
|
- self.tools_table_exc.cellPressed.connect(self.on_row_selected)
|
|
|
- self.replot()
|
|
|
+ # add a frame and inside add a vertical box layout. Inside this vbox layout I add
|
|
|
+ # all the add drill array widgets
|
|
|
+ # this way I can hide/show the frame
|
|
|
+ self.array_frame = QtWidgets.QFrame()
|
|
|
+ self.array_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.tools_box.addWidget(self.array_frame)
|
|
|
+ self.array_box = QtWidgets.QVBoxLayout()
|
|
|
+ self.array_box.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.array_frame.setLayout(self.array_box)
|
|
|
|
|
|
- def on_canvas_move(self, event):
|
|
|
- """
|
|
|
- Called on 'mouse_move' event.
|
|
|
- It updates the mouse cursor if the grid snapping is ON.
|
|
|
- It decide if we have a mouse drag and if it is done with the right mouse click. Then it passes this info to a
|
|
|
- class object which is used in the "mouse_release" handler to decide if to pop-up the context menu or not.
|
|
|
- It draws utility_geometry for the Editor tools.
|
|
|
- Update the position labels from status bar.
|
|
|
- Decide if we have a right to left or a left to right mouse drag with left mouse button and call a function
|
|
|
- that will draw a selection shape on canvas.
|
|
|
+ self.emptyarray_label = QtWidgets.QLabel('')
|
|
|
+ self.array_box.addWidget(self.emptyarray_label)
|
|
|
|
|
|
- event.pos have canvas screen coordinates
|
|
|
+ self.drill_array_label = QtWidgets.QLabel('<b>%s</b>' % _("Add Drill Array"))
|
|
|
+ self.drill_array_label.setToolTip(
|
|
|
+ _("Add an array of drills (linear or circular array)")
|
|
|
+ )
|
|
|
+ self.array_box.addWidget(self.drill_array_label)
|
|
|
|
|
|
- :param event: Event object dispatched by VisPy SceneCavas
|
|
|
- :return: None
|
|
|
- """
|
|
|
+ self.array_type_combo = FCComboBox()
|
|
|
+ self.array_type_combo.setToolTip(
|
|
|
+ _("Select the type of drills array to create.\n"
|
|
|
+ "It can be Linear X(Y) or Circular")
|
|
|
+ )
|
|
|
+ self.array_type_combo.addItem(_("Linear"))
|
|
|
+ self.array_type_combo.addItem(_("Circular"))
|
|
|
|
|
|
- if self.app.is_legacy is False:
|
|
|
- event_pos = event.pos
|
|
|
- event_is_dragging = event.is_dragging
|
|
|
- right_button = 2
|
|
|
- else:
|
|
|
- event_pos = (event.xdata, event.ydata)
|
|
|
- event_is_dragging = self.app.plotcanvas.is_dragging
|
|
|
- right_button = 3
|
|
|
+ self.array_box.addWidget(self.array_type_combo)
|
|
|
|
|
|
- pos = self.canvas.translate_coords(event_pos)
|
|
|
- event.xdata, event.ydata = pos[0], pos[1]
|
|
|
+ self.array_form = QtWidgets.QFormLayout()
|
|
|
+ self.array_box.addLayout(self.array_form)
|
|
|
|
|
|
- self.x = event.xdata
|
|
|
- self.y = event.ydata
|
|
|
+ # Set the number of drill holes in the drill array
|
|
|
+ self.drill_array_size_label = QtWidgets.QLabel('%s:' % _('Nr of drills'))
|
|
|
+ self.drill_array_size_label.setToolTip(_("Specify how many drills to be in the array."))
|
|
|
+ self.drill_array_size_label.setMinimumWidth(100)
|
|
|
|
|
|
- self.app.ui.popMenu.mouse_is_panning = False
|
|
|
+ self.drill_array_size_entry = FCSpinner()
|
|
|
+ self.drill_array_size_entry.set_range(1, 9999)
|
|
|
+ self.array_form.addRow(self.drill_array_size_label, self.drill_array_size_entry)
|
|
|
|
|
|
- # if the RMB is clicked and mouse is moving over plot then 'panning_action' is True
|
|
|
- if event.button == right_button and event_is_dragging == 1:
|
|
|
- self.app.ui.popMenu.mouse_is_panning = True
|
|
|
- return
|
|
|
+ self.array_linear_frame = QtWidgets.QFrame()
|
|
|
+ self.array_linear_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.array_box.addWidget(self.array_linear_frame)
|
|
|
+ self.linear_box = QtWidgets.QVBoxLayout()
|
|
|
+ self.linear_box.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.array_linear_frame.setLayout(self.linear_box)
|
|
|
|
|
|
- try:
|
|
|
- x = float(event.xdata)
|
|
|
- y = float(event.ydata)
|
|
|
- except TypeError:
|
|
|
- return
|
|
|
+ self.linear_form = QtWidgets.QFormLayout()
|
|
|
+ self.linear_box.addLayout(self.linear_form)
|
|
|
|
|
|
- if self.active_tool is None:
|
|
|
- return
|
|
|
+ # Linear Drill Array direction
|
|
|
+ self.drill_axis_label = QtWidgets.QLabel('%s:' % _('Direction'))
|
|
|
+ self.drill_axis_label.setToolTip(
|
|
|
+ _("Direction on which the linear array is oriented:\n"
|
|
|
+ "- 'X' - horizontal axis \n"
|
|
|
+ "- 'Y' - vertical axis or \n"
|
|
|
+ "- 'Angle' - a custom angle for the array inclination")
|
|
|
+ )
|
|
|
+ self.drill_axis_label.setMinimumWidth(100)
|
|
|
|
|
|
- # ## Snap coordinates
|
|
|
- if self.app.grid_status():
|
|
|
- x, y = self.app.geo_editor.snap(x, y)
|
|
|
+ self.drill_axis_radio = RadioSet([{'label': _('X'), 'value': 'X'},
|
|
|
+ {'label': _('Y'), 'value': 'Y'},
|
|
|
+ {'label': _('Angle'), 'value': 'A'}])
|
|
|
+ self.linear_form.addRow(self.drill_axis_label, self.drill_axis_radio)
|
|
|
|
|
|
- # Update cursor
|
|
|
- self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D,
|
|
|
- edge_width=self.app.defaults["global_cursor_width"],
|
|
|
- size=self.app.defaults["global_cursor_size"])
|
|
|
+ # Linear Drill Array pitch distance
|
|
|
+ self.drill_pitch_label = QtWidgets.QLabel('%s:' % _('Pitch'))
|
|
|
+ self.drill_pitch_label.setToolTip(
|
|
|
+ _("Pitch = Distance between elements of the array.")
|
|
|
+ )
|
|
|
+ self.drill_pitch_label.setMinimumWidth(100)
|
|
|
|
|
|
- self.snap_x = x
|
|
|
- self.snap_y = y
|
|
|
+ self.drill_pitch_entry = FCDoubleSpinner()
|
|
|
+ self.drill_pitch_entry.set_precision(self.decimals)
|
|
|
+ self.drill_pitch_entry.set_range(0.0000, 9999.9999)
|
|
|
|
|
|
- if self.pos is None:
|
|
|
- self.pos = (0, 0)
|
|
|
- self.app.dx = x - self.pos[0]
|
|
|
- self.app.dy = y - self.pos[1]
|
|
|
+ self.linear_form.addRow(self.drill_pitch_label, self.drill_pitch_entry)
|
|
|
|
|
|
- # # update the position label in the infobar since the APP mouse event handlers are disconnected
|
|
|
- self.app.ui.position_label.setText(" <b>X</b>: %.4f "
|
|
|
- "<b>Y</b>: %.4f " % (x, y))
|
|
|
- # # update the reference position label in the infobar since the APP mouse event handlers are disconnected
|
|
|
- self.app.ui.rel_position_label.setText("<b>Dx</b>: %.4f <b>Dy</b>: "
|
|
|
- "%.4f " % (self.app.dx, self.app.dy))
|
|
|
+ # Linear Drill Array angle
|
|
|
+ self.linear_angle_label = QtWidgets.QLabel('%s:' % _('Angle'))
|
|
|
+ self.linear_angle_label.setToolTip(
|
|
|
+ _("Angle at which the linear array is placed.\n"
|
|
|
+ "The precision is of max 2 decimals.\n"
|
|
|
+ "Min value is: -360 degrees.\n"
|
|
|
+ "Max value is: 360.00 degrees.")
|
|
|
+ )
|
|
|
+ self.linear_angle_label.setMinimumWidth(100)
|
|
|
|
|
|
- units = self.app.defaults["units"].lower()
|
|
|
- self.app.plotcanvas.text_hud.text = \
|
|
|
- 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format(
|
|
|
- self.app.dx, units, self.app.dy, units, x, units, y, units)
|
|
|
+ self.linear_angle_spinner = FCDoubleSpinner()
|
|
|
+ self.linear_angle_spinner.set_precision(self.decimals)
|
|
|
+ self.linear_angle_spinner.setSingleStep(1.0)
|
|
|
+ self.linear_angle_spinner.setRange(-360.00, 360.00)
|
|
|
+ self.linear_form.addRow(self.linear_angle_label, self.linear_angle_spinner)
|
|
|
|
|
|
- # ## Utility geometry (animated)
|
|
|
- self.update_utility_geometry(data=(x, y))
|
|
|
+ self.array_circular_frame = QtWidgets.QFrame()
|
|
|
+ self.array_circular_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.array_box.addWidget(self.array_circular_frame)
|
|
|
+ self.circular_box = QtWidgets.QVBoxLayout()
|
|
|
+ self.circular_box.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.array_circular_frame.setLayout(self.circular_box)
|
|
|
|
|
|
- # ## Selection area on canvas section # ##
|
|
|
- if event_is_dragging == 1 and event.button == 1:
|
|
|
- # I make an exception for FCDrillAdd and FCDrillArray because clicking and dragging while making regions
|
|
|
- # can create strange issues. Also for FCSlot and FCSlotArray
|
|
|
- if isinstance(self.active_tool, FCDrillAdd) or isinstance(self.active_tool, FCDrillArray) or \
|
|
|
- isinstance(self.active_tool, FCSlot) or isinstance(self.active_tool, FCSlotArray):
|
|
|
- self.app.selection_type = None
|
|
|
- else:
|
|
|
- dx = pos[0] - self.pos[0]
|
|
|
- self.app.delete_selection_shape()
|
|
|
- if dx < 0:
|
|
|
- self.app.draw_moving_selection_shape((self.pos[0], self.pos[1]), (x, y),
|
|
|
- color=self.app.defaults["global_alt_sel_line"],
|
|
|
- face_color=self.app.defaults['global_alt_sel_fill'])
|
|
|
- self.app.selection_type = False
|
|
|
- else:
|
|
|
- self.app.draw_moving_selection_shape((self.pos[0], self.pos[1]), (x, y))
|
|
|
- self.app.selection_type = True
|
|
|
- else:
|
|
|
- self.app.selection_type = None
|
|
|
+ self.drill_direction_label = QtWidgets.QLabel('%s:' % _('Direction'))
|
|
|
+ self.drill_direction_label.setToolTip(_("Direction for circular array."
|
|
|
+ "Can be CW = clockwise or CCW = counter clockwise."))
|
|
|
+ self.drill_direction_label.setMinimumWidth(100)
|
|
|
|
|
|
- # Update cursor
|
|
|
- self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D,
|
|
|
- edge_width=self.app.defaults["global_cursor_width"],
|
|
|
- size=self.app.defaults["global_cursor_size"])
|
|
|
+ self.circular_form = QtWidgets.QFormLayout()
|
|
|
+ self.circular_box.addLayout(self.circular_form)
|
|
|
|
|
|
- def update_utility_geometry(self, data):
|
|
|
- # ### Utility geometry (animated) ###
|
|
|
- geo = self.active_tool.utility_geometry(data=data)
|
|
|
- if isinstance(geo, DrawToolShape) and geo.geo is not None:
|
|
|
- # Remove any previous utility shape
|
|
|
- self.tool_shape.clear(update=True)
|
|
|
- self.draw_utility_geometry(geo=geo)
|
|
|
+ self.drill_direction_radio = RadioSet([{'label': _('CW'), 'value': 'CW'},
|
|
|
+ {'label': _('CCW'), 'value': 'CCW'}])
|
|
|
+ self.circular_form.addRow(self.drill_direction_label, self.drill_direction_radio)
|
|
|
|
|
|
- def on_canvas_key_release(self, event):
|
|
|
- self.key = None
|
|
|
+ self.drill_angle_label = QtWidgets.QLabel('%s:' % _('Angle'))
|
|
|
+ self.drill_angle_label.setToolTip(_("Angle at which each element in circular array is placed."))
|
|
|
+ self.drill_angle_label.setMinimumWidth(100)
|
|
|
|
|
|
- def draw_utility_geometry(self, geo):
|
|
|
- # Add the new utility shape
|
|
|
- try:
|
|
|
- # this case is for the Font Parse
|
|
|
- for el in list(geo.geo):
|
|
|
- if type(el) == MultiPolygon:
|
|
|
- for poly in el:
|
|
|
- self.tool_shape.add(
|
|
|
- shape=poly,
|
|
|
- color=(self.app.defaults["global_draw_color"] + '80'),
|
|
|
- update=False,
|
|
|
- layer=0,
|
|
|
- tolerance=None
|
|
|
- )
|
|
|
- elif type(el) == MultiLineString:
|
|
|
- for linestring in el:
|
|
|
- self.tool_shape.add(
|
|
|
- shape=linestring,
|
|
|
- color=(self.app.defaults["global_draw_color"] + '80'),
|
|
|
- update=False,
|
|
|
- layer=0,
|
|
|
- tolerance=None
|
|
|
- )
|
|
|
- else:
|
|
|
- self.tool_shape.add(
|
|
|
- shape=el,
|
|
|
- color=(self.app.defaults["global_draw_color"] + '80'),
|
|
|
- update=False,
|
|
|
- layer=0,
|
|
|
- tolerance=None
|
|
|
- )
|
|
|
- except TypeError:
|
|
|
- self.tool_shape.add(
|
|
|
- shape=geo.geo, color=(self.app.defaults["global_draw_color"] + '80'),
|
|
|
- update=False, layer=0, tolerance=None)
|
|
|
- self.tool_shape.redraw()
|
|
|
+ self.drill_angle_entry = FCDoubleSpinner()
|
|
|
+ self.drill_angle_entry.set_precision(self.decimals)
|
|
|
+ self.drill_angle_entry.setSingleStep(1.0)
|
|
|
+ self.drill_angle_entry.setRange(-360.00, 360.00)
|
|
|
|
|
|
- def replot(self):
|
|
|
- self.plot_all()
|
|
|
+ self.circular_form.addRow(self.drill_angle_label, self.drill_angle_entry)
|
|
|
|
|
|
- def plot_all(self):
|
|
|
- """
|
|
|
- Plots all shapes in the editor.
|
|
|
+ self.array_circular_frame.hide()
|
|
|
|
|
|
- :return: None
|
|
|
- :rtype: None
|
|
|
- """
|
|
|
- # self.app.log.debug("plot_all()")
|
|
|
- self.shapes.clear(update=True)
|
|
|
+ self.linear_angle_spinner.hide()
|
|
|
+ self.linear_angle_label.hide()
|
|
|
|
|
|
- for storage in self.storage_dict:
|
|
|
- for shape_plus in self.storage_dict[storage].get_objects():
|
|
|
- if shape_plus.geo is None:
|
|
|
- continue
|
|
|
+ self.array_frame.hide()
|
|
|
|
|
|
- if shape_plus in self.selected:
|
|
|
- self.plot_shape(geometry=shape_plus.geo, color=self.app.defaults['global_sel_draw_color'] + 'FF',
|
|
|
- linewidth=2)
|
|
|
- continue
|
|
|
- self.plot_shape(geometry=shape_plus.geo, color=self.app.defaults['global_draw_color'] + 'FF')
|
|
|
+ # ######################################################
|
|
|
+ # ##### ADDING SLOTS ###################################
|
|
|
+ # ######################################################
|
|
|
|
|
|
- # for shape in self.storage.get_objects():
|
|
|
- # if shape.geo is None: # TODO: This shouldn't have happened
|
|
|
- # continue
|
|
|
- #
|
|
|
- # if shape in self.selected:
|
|
|
- # self.plot_shape(geometry=shape.geo, color=self.app.defaults['global_sel_draw_color'], linewidth=2)
|
|
|
- # continue
|
|
|
- #
|
|
|
- # self.plot_shape(geometry=shape.geo, color=self.app.defaults['global_draw_color'])
|
|
|
+ # add a frame and inside add a vertical box layout. Inside this vbox layout I add
|
|
|
+ # all the add slot widgets
|
|
|
+ # this way I can hide/show the frame
|
|
|
+ self.slot_frame = QtWidgets.QFrame()
|
|
|
+ self.slot_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.tools_box.addWidget(self.slot_frame)
|
|
|
+ self.slot_box = QtWidgets.QVBoxLayout()
|
|
|
+ self.slot_box.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.slot_frame.setLayout(self.slot_box)
|
|
|
|
|
|
- for shape_form in self.utility:
|
|
|
- self.plot_shape(geometry=shape_form.geo, linewidth=1)
|
|
|
- continue
|
|
|
+ self.emptyarray_label = QtWidgets.QLabel('')
|
|
|
+ self.slot_box.addWidget(self.emptyarray_label)
|
|
|
|
|
|
- self.shapes.redraw()
|
|
|
+ self.slot_label = QtWidgets.QLabel('<b>%s</b>' % _("Slot Parameters"))
|
|
|
+ self.slot_label.setToolTip(
|
|
|
+ _("Parameters for adding a slot (hole with oval shape)\n"
|
|
|
+ "either single or as an part of an array.")
|
|
|
+ )
|
|
|
+ self.slot_box.addWidget(self.slot_label)
|
|
|
|
|
|
- def plot_shape(self, geometry=None, color='0x000000FF', linewidth=1):
|
|
|
- """
|
|
|
- Plots a geometric object or list of objects without rendering. Plotted objects
|
|
|
- are returned as a list. This allows for efficient/animated rendering.
|
|
|
+ self.slot_form = QtWidgets.QFormLayout()
|
|
|
+ self.slot_box.addLayout(self.slot_form)
|
|
|
|
|
|
- :param geometry: Geometry to be plotted (Any Shapely.geom kind or list of such)
|
|
|
- :param color: Shape color
|
|
|
- :param linewidth: Width of lines in # of pixels.
|
|
|
- :return: List of plotted elements.
|
|
|
- """
|
|
|
- plot_elements = []
|
|
|
+ # Slot length
|
|
|
+ self.slot_length_label = QtWidgets.QLabel('%s:' % _('Length'))
|
|
|
+ self.slot_length_label.setToolTip(
|
|
|
+ _("Length = The length of the slot.")
|
|
|
+ )
|
|
|
+ self.slot_length_label.setMinimumWidth(100)
|
|
|
|
|
|
- if geometry is None:
|
|
|
- geometry = self.active_tool.geometry
|
|
|
+ self.slot_length_entry = FCDoubleSpinner()
|
|
|
+ self.slot_length_entry.set_precision(self.decimals)
|
|
|
+ self.slot_length_entry.setSingleStep(0.1)
|
|
|
+ self.slot_length_entry.setRange(0.0000, 9999.9999)
|
|
|
|
|
|
- try:
|
|
|
- for geo in geometry:
|
|
|
- plot_elements += self.plot_shape(geometry=geo, color=color, linewidth=linewidth)
|
|
|
+ self.slot_form.addRow(self.slot_length_label, self.slot_length_entry)
|
|
|
|
|
|
- # ## Non-iterable
|
|
|
- except TypeError:
|
|
|
- # ## DrawToolShape
|
|
|
- if isinstance(geometry, DrawToolShape):
|
|
|
- plot_elements += self.plot_shape(geometry=geometry.geo, color=color, linewidth=linewidth)
|
|
|
+ # Slot direction
|
|
|
+ self.slot_axis_label = QtWidgets.QLabel('%s:' % _('Direction'))
|
|
|
+ self.slot_axis_label.setToolTip(
|
|
|
+ _("Direction on which the slot is oriented:\n"
|
|
|
+ "- 'X' - horizontal axis \n"
|
|
|
+ "- 'Y' - vertical axis or \n"
|
|
|
+ "- 'Angle' - a custom angle for the slot inclination")
|
|
|
+ )
|
|
|
+ self.slot_axis_label.setMinimumWidth(100)
|
|
|
|
|
|
- # ## Polygon: Descend into exterior and each interior.
|
|
|
- if type(geometry) == Polygon:
|
|
|
- plot_elements += self.plot_shape(geometry=geometry.exterior, color=color, linewidth=linewidth)
|
|
|
- plot_elements += self.plot_shape(geometry=geometry.interiors, color=color, linewidth=linewidth)
|
|
|
+ self.slot_axis_radio = RadioSet([{'label': _('X'), 'value': 'X'},
|
|
|
+ {'label': _('Y'), 'value': 'Y'},
|
|
|
+ {'label': _('Angle'), 'value': 'A'}])
|
|
|
+ self.slot_form.addRow(self.slot_axis_label, self.slot_axis_radio)
|
|
|
|
|
|
- if type(geometry) == LineString or type(geometry) == LinearRing:
|
|
|
- plot_elements.append(self.shapes.add(shape=geometry, color=color, layer=0, tolerance=self.tolerance))
|
|
|
+ # Slot custom angle
|
|
|
+ self.slot_angle_label = QtWidgets.QLabel('%s:' % _('Angle'))
|
|
|
+ self.slot_angle_label.setToolTip(
|
|
|
+ _("Angle at which the slot is placed.\n"
|
|
|
+ "The precision is of max 2 decimals.\n"
|
|
|
+ "Min value is: -360 degrees.\n"
|
|
|
+ "Max value is: 360.00 degrees.")
|
|
|
+ )
|
|
|
+ self.slot_angle_label.setMinimumWidth(100)
|
|
|
|
|
|
- if type(geometry) == Point:
|
|
|
- pass
|
|
|
+ self.slot_angle_spinner = FCDoubleSpinner()
|
|
|
+ self.slot_angle_spinner.set_precision(self.decimals)
|
|
|
+ self.slot_angle_spinner.setWrapping(True)
|
|
|
+ self.slot_angle_spinner.setRange(-360.00, 360.00)
|
|
|
+ self.slot_angle_spinner.setSingleStep(1.0)
|
|
|
+ self.slot_form.addRow(self.slot_angle_label, self.slot_angle_spinner)
|
|
|
|
|
|
- return plot_elements
|
|
|
+ self.slot_frame.hide()
|
|
|
|
|
|
- def on_shape_complete(self):
|
|
|
- self.app.log.debug("on_shape_complete()")
|
|
|
+ # ######################################################
|
|
|
+ # ##### ADDING SLOT ARRAY #############################
|
|
|
+ # ######################################################
|
|
|
|
|
|
- # Add shape
|
|
|
- self.add_shape(self.active_tool.geometry)
|
|
|
+ # add a frame and inside add a vertical box layout. Inside this vbox layout I add
|
|
|
+ # all the add slot widgets
|
|
|
+ # this way I can hide/show the frame
|
|
|
+ self.slot_array_frame = QtWidgets.QFrame()
|
|
|
+ self.slot_array_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.tools_box.addWidget(self.slot_array_frame)
|
|
|
+ self.slot_array_box = QtWidgets.QVBoxLayout()
|
|
|
+ self.slot_array_box.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.slot_array_frame.setLayout(self.slot_array_box)
|
|
|
|
|
|
- # Remove any utility shapes
|
|
|
- self.delete_utility_geometry()
|
|
|
- self.tool_shape.clear(update=True)
|
|
|
+ self.emptyarray_label = QtWidgets.QLabel('')
|
|
|
+ self.slot_array_box.addWidget(self.emptyarray_label)
|
|
|
|
|
|
- # Replot and reset tool.
|
|
|
- self.replot()
|
|
|
- # self.active_tool = type(self.active_tool)(self)
|
|
|
+ self.slot_array_label = QtWidgets.QLabel('<b>%s</b>' % _("Slot Array Parameters"))
|
|
|
+ self.slot_array_label.setToolTip(
|
|
|
+ _("Parameters for the array of slots (linear or circular array)")
|
|
|
+ )
|
|
|
+ self.slot_array_box.addWidget(self.slot_array_label)
|
|
|
|
|
|
- def get_selected(self):
|
|
|
- """
|
|
|
- Returns list of shapes that are selected in the editor.
|
|
|
+ self.l_form = QtWidgets.QFormLayout()
|
|
|
+ self.slot_array_box.addLayout(self.l_form)
|
|
|
|
|
|
- :return: List of shapes.
|
|
|
- """
|
|
|
- # return [shape for shape in self.shape_buffer if shape["selected"]]
|
|
|
- return self.selected
|
|
|
+ self.slot_array_type_combo = FCComboBox()
|
|
|
+ self.slot_array_type_combo.setToolTip(
|
|
|
+ _("Select the type of slot array to create.\n"
|
|
|
+ "It can be Linear X(Y) or Circular")
|
|
|
+ )
|
|
|
+ self.slot_array_type_combo.addItem(_("Linear"))
|
|
|
+ self.slot_array_type_combo.addItem(_("Circular"))
|
|
|
|
|
|
- def delete_selected(self):
|
|
|
- temp_ref = [s for s in self.selected]
|
|
|
- for shape_sel in temp_ref:
|
|
|
- self.delete_shape(shape_sel)
|
|
|
+ self.slot_array_box.addWidget(self.slot_array_type_combo)
|
|
|
|
|
|
- self.selected = []
|
|
|
- self.build_ui()
|
|
|
- self.app.inform.emit('[success] %s' %
|
|
|
- _("Done. Drill(s) deleted."))
|
|
|
+ self.slot_array_form = QtWidgets.QFormLayout()
|
|
|
+ self.slot_array_box.addLayout(self.slot_array_form)
|
|
|
|
|
|
- def delete_shape(self, del_shape):
|
|
|
- self.is_modified = True
|
|
|
+ # Set the number of slot holes in the slot array
|
|
|
+ self.slot_array_size_label = QtWidgets.QLabel('%s:' % _('Nr of slots'))
|
|
|
+ self.slot_array_size_label.setToolTip(_("Specify how many slots to be in the array."))
|
|
|
+ self.slot_array_size_label.setMinimumWidth(100)
|
|
|
|
|
|
- if del_shape in self.utility:
|
|
|
- self.utility.remove(del_shape)
|
|
|
- return
|
|
|
+ self.slot_array_size_entry = FCSpinner()
|
|
|
+ self.slot_array_size_entry.set_range(0, 9999)
|
|
|
|
|
|
- for storage in self.storage_dict:
|
|
|
- # try:
|
|
|
- # self.storage_dict[storage].remove(shape)
|
|
|
- # except:
|
|
|
- # pass
|
|
|
- if del_shape in self.storage_dict[storage].get_objects():
|
|
|
- if isinstance(del_shape.geo, MultiLineString):
|
|
|
- self.storage_dict[storage].remove(del_shape)
|
|
|
- # a hack to make the tool_table display less drills per diameter
|
|
|
- # self.points_edit it's only useful first time when we load the data into the storage
|
|
|
- # but is still used as referecen when building tool_table in self.build_ui()
|
|
|
- # the number of drills displayed in column 2 is just a len(self.points_edit) therefore
|
|
|
- # deleting self.points_edit elements (doesn't matter who but just the number)
|
|
|
- # solved the display issue.
|
|
|
- del self.points_edit[storage][0]
|
|
|
- else:
|
|
|
- self.storage_dict[storage].remove(del_shape)
|
|
|
- del self.slot_points_edit[storage][0]
|
|
|
+ self.slot_array_form.addRow(self.slot_array_size_label, self.slot_array_size_entry)
|
|
|
|
|
|
- if del_shape in self.selected:
|
|
|
- self.selected.remove(del_shape)
|
|
|
+ self.slot_array_linear_frame = QtWidgets.QFrame()
|
|
|
+ self.slot_array_linear_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.slot_array_box.addWidget(self.slot_array_linear_frame)
|
|
|
+ self.slot_array_linear_box = QtWidgets.QVBoxLayout()
|
|
|
+ self.slot_array_linear_box.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.slot_array_linear_frame.setLayout(self.slot_array_linear_box)
|
|
|
|
|
|
- def delete_utility_geometry(self):
|
|
|
- for_deletion = [util_shape for util_shape in self.utility]
|
|
|
- for util_shape in for_deletion:
|
|
|
- self.delete_shape(util_shape)
|
|
|
+ self.slot_array_linear_form = QtWidgets.QFormLayout()
|
|
|
+ self.slot_array_linear_box.addLayout(self.slot_array_linear_form)
|
|
|
|
|
|
- self.tool_shape.clear(update=True)
|
|
|
- self.tool_shape.redraw()
|
|
|
+ # Linear Slot Array direction
|
|
|
+ self.slot_array_axis_label = QtWidgets.QLabel('%s:' % _('Direction'))
|
|
|
+ self.slot_array_axis_label.setToolTip(
|
|
|
+ _("Direction on which the linear array is oriented:\n"
|
|
|
+ "- 'X' - horizontal axis \n"
|
|
|
+ "- 'Y' - vertical axis or \n"
|
|
|
+ "- 'Angle' - a custom angle for the array inclination")
|
|
|
+ )
|
|
|
+ self.slot_array_axis_label.setMinimumWidth(100)
|
|
|
|
|
|
- def on_delete_btn(self):
|
|
|
- self.delete_selected()
|
|
|
- self.replot()
|
|
|
+ self.slot_array_axis_radio = RadioSet([{'label': _('X'), 'value': 'X'},
|
|
|
+ {'label': _('Y'), 'value': 'Y'},
|
|
|
+ {'label': _('Angle'), 'value': 'A'}])
|
|
|
+ self.slot_array_linear_form.addRow(self.slot_array_axis_label, self.slot_array_axis_radio)
|
|
|
|
|
|
- def select_tool(self, toolname):
|
|
|
- """
|
|
|
- Selects a drawing tool. Impacts the object and appGUI.
|
|
|
+ # Linear Slot Array pitch distance
|
|
|
+ self.slot_array_pitch_label = QtWidgets.QLabel('%s:' % _('Pitch'))
|
|
|
+ self.slot_array_pitch_label.setToolTip(
|
|
|
+ _("Pitch = Distance between elements of the array.")
|
|
|
+ )
|
|
|
+ self.slot_array_pitch_label.setMinimumWidth(100)
|
|
|
|
|
|
- :param toolname: Name of the tool.
|
|
|
- :return: None
|
|
|
- """
|
|
|
- self.tools_exc[toolname]["button"].setChecked(True)
|
|
|
- self.on_tool_select(toolname)
|
|
|
+ self.slot_array_pitch_entry = FCDoubleSpinner()
|
|
|
+ self.slot_array_pitch_entry.set_precision(self.decimals)
|
|
|
+ self.slot_array_pitch_entry.setSingleStep(0.1)
|
|
|
+ self.slot_array_pitch_entry.setRange(0.0000, 9999.9999)
|
|
|
|
|
|
- def set_selected(self, sel_shape):
|
|
|
+ self.slot_array_linear_form.addRow(self.slot_array_pitch_label, self.slot_array_pitch_entry)
|
|
|
|
|
|
- # Remove and add to the end.
|
|
|
- if sel_shape in self.selected:
|
|
|
- self.selected.remove(sel_shape)
|
|
|
+ # Linear Slot Array angle
|
|
|
+ self.slot_array_linear_angle_label = QtWidgets.QLabel('%s:' % _('Angle'))
|
|
|
+ self.slot_array_linear_angle_label.setToolTip(
|
|
|
+ _("Angle at which the linear array is placed.\n"
|
|
|
+ "The precision is of max 2 decimals.\n"
|
|
|
+ "Min value is: -360 degrees.\n"
|
|
|
+ "Max value is: 360.00 degrees.")
|
|
|
+ )
|
|
|
+ self.slot_array_linear_angle_label.setMinimumWidth(100)
|
|
|
|
|
|
- self.selected.append(sel_shape)
|
|
|
+ self.slot_array_linear_angle_spinner = FCDoubleSpinner()
|
|
|
+ self.slot_array_linear_angle_spinner.set_precision(self.decimals)
|
|
|
+ self.slot_array_linear_angle_spinner.setSingleStep(1.0)
|
|
|
+ self.slot_array_linear_angle_spinner.setRange(-360.00, 360.00)
|
|
|
+ self.slot_array_linear_form.addRow(self.slot_array_linear_angle_label, self.slot_array_linear_angle_spinner)
|
|
|
|
|
|
- def set_unselected(self, unsel_shape):
|
|
|
- if unsel_shape in self.selected:
|
|
|
- self.selected.remove(unsel_shape)
|
|
|
+ self.slot_array_circular_frame = QtWidgets.QFrame()
|
|
|
+ self.slot_array_circular_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.slot_array_box.addWidget(self.slot_array_circular_frame)
|
|
|
+ self.slot_array_circular_box = QtWidgets.QVBoxLayout()
|
|
|
+ self.slot_array_circular_box.setContentsMargins(0, 0, 0, 0)
|
|
|
+ self.slot_array_circular_frame.setLayout(self.slot_array_circular_box)
|
|
|
|
|
|
- def on_array_type_combo(self):
|
|
|
- if self.array_type_combo.currentIndex() == 0:
|
|
|
- self.array_circular_frame.hide()
|
|
|
- self.array_linear_frame.show()
|
|
|
- else:
|
|
|
- self.delete_utility_geometry()
|
|
|
- self.array_circular_frame.show()
|
|
|
- self.array_linear_frame.hide()
|
|
|
- self.app.inform.emit(_("Click on the circular array Center position"))
|
|
|
+ self.slot_array_direction_label = QtWidgets.QLabel('%s:' % _('Direction'))
|
|
|
+ self.slot_array_direction_label.setToolTip(_("Direction for circular array."
|
|
|
+ "Can be CW = clockwise or CCW = counter clockwise."))
|
|
|
+ self.slot_array_direction_label.setMinimumWidth(100)
|
|
|
|
|
|
- def on_slot_array_type_combo(self):
|
|
|
- if self.slot_array_type_combo.currentIndex() == 0:
|
|
|
- self.slot_array_circular_frame.hide()
|
|
|
- self.slot_array_linear_frame.show()
|
|
|
- else:
|
|
|
- self.delete_utility_geometry()
|
|
|
- self.slot_array_circular_frame.show()
|
|
|
- self.slot_array_linear_frame.hide()
|
|
|
- self.app.inform.emit(_("Click on the circular array Center position"))
|
|
|
+ self.slot_array_circular_form = QtWidgets.QFormLayout()
|
|
|
+ self.slot_array_circular_box.addLayout(self.slot_array_circular_form)
|
|
|
|
|
|
- def on_linear_angle_radio(self):
|
|
|
- val = self.drill_axis_radio.get_value()
|
|
|
- if val == 'A':
|
|
|
- self.linear_angle_spinner.show()
|
|
|
- self.linear_angle_label.show()
|
|
|
- else:
|
|
|
- self.linear_angle_spinner.hide()
|
|
|
- self.linear_angle_label.hide()
|
|
|
+ self.slot_array_direction_radio = RadioSet([{'label': _('CW'), 'value': 'CW'},
|
|
|
+ {'label': _('CCW'), 'value': 'CCW'}])
|
|
|
+ self.slot_array_circular_form.addRow(self.slot_array_direction_label, self.slot_array_direction_radio)
|
|
|
|
|
|
- def on_slot_array_linear_angle_radio(self):
|
|
|
- val = self.slot_array_axis_radio.get_value()
|
|
|
- if val == 'A':
|
|
|
- self.slot_array_linear_angle_spinner.show()
|
|
|
- self.slot_array_linear_angle_label.show()
|
|
|
- else:
|
|
|
- self.slot_array_linear_angle_spinner.hide()
|
|
|
- self.slot_array_linear_angle_label.hide()
|
|
|
+ self.slot_array_angle_label = QtWidgets.QLabel('%s:' % _('Angle'))
|
|
|
+ self.slot_array_angle_label.setToolTip(_("Angle at which each element in circular array is placed."))
|
|
|
+ self.slot_array_angle_label.setMinimumWidth(100)
|
|
|
|
|
|
- def on_slot_angle_radio(self):
|
|
|
- val = self.slot_axis_radio.get_value()
|
|
|
- if val == 'A':
|
|
|
- self.slot_angle_spinner.show()
|
|
|
- self.slot_angle_label.show()
|
|
|
- else:
|
|
|
- self.slot_angle_spinner.hide()
|
|
|
- self.slot_angle_label.hide()
|
|
|
+ self.slot_array_angle_entry = FCDoubleSpinner()
|
|
|
+ self.slot_array_angle_entry.set_precision(self.decimals)
|
|
|
+ self.slot_array_angle_entry.setSingleStep(1)
|
|
|
+ self.slot_array_angle_entry.setRange(-360.00, 360.00)
|
|
|
|
|
|
- def exc_add_drill(self):
|
|
|
- self.select_tool('drill_add')
|
|
|
- return
|
|
|
+ self.slot_array_circular_form.addRow(self.slot_array_angle_label, self.slot_array_angle_entry)
|
|
|
|
|
|
- def exc_add_drill_array(self):
|
|
|
- self.select_tool('drill_array')
|
|
|
- return
|
|
|
+ self.slot_array_linear_angle_spinner.hide()
|
|
|
+ self.slot_array_linear_angle_label.hide()
|
|
|
|
|
|
- def exc_add_slot(self):
|
|
|
- self.select_tool('slot_add')
|
|
|
- return
|
|
|
+ self.slot_array_frame.hide()
|
|
|
|
|
|
- def exc_add_slot_array(self):
|
|
|
- self.select_tool('slot_array')
|
|
|
- return
|
|
|
+ self.tools_box.addStretch()
|
|
|
|
|
|
- def exc_resize_drills(self):
|
|
|
- self.select_tool('drill_resize')
|
|
|
- return
|
|
|
+ layout.addStretch()
|
|
|
|
|
|
- def exc_copy_drills(self):
|
|
|
- self.select_tool('drill_copy')
|
|
|
- return
|
|
|
+ # Editor
|
|
|
+ self.exit_editor_button = QtWidgets.QPushButton(_('Exit Editor'))
|
|
|
+ self.exit_editor_button.setToolTip(
|
|
|
+ _("Exit from Editor.")
|
|
|
+ )
|
|
|
+ self.exit_editor_button.setStyleSheet("""
|
|
|
+ QPushButton
|
|
|
+ {
|
|
|
+ font-weight: bold;
|
|
|
+ }
|
|
|
+ """)
|
|
|
+ layout.addWidget(self.exit_editor_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 exc_move_drills(self):
|
|
|
- self.select_tool('drill_move')
|
|
|
- return
|
|
|
+ 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)
|
|
|
|
|
|
|
|
|
def get_shapely_list_bounds(geometry_list):
|