- In Excellon Editor, finished th upgrade work on the Drill Array Plugin

This commit is contained in:
Marius Stanciu
2022-04-30 14:27:09 +03:00
committed by Marius
parent 5e504f168b
commit 092451038e
3 changed files with 98 additions and 138 deletions

View File

@@ -12,6 +12,7 @@ CHANGELOG for FlatCAM Evo beta
- in Excellon Editor, Slot Plugin, made sure that once the Editor is active any change for this plugin parameters will be kept until editor is exit or that parameter is changed again - in Excellon Editor, Slot Plugin, made sure that once the Editor is active any change for this plugin parameters will be kept until editor is exit or that parameter is changed again
- In Excellon Editor, Drill Array Plugin, upgraded the UI and work in progress for the features - In Excellon Editor, Drill Array Plugin, upgraded the UI and work in progress for the features
- prettified some GUI elements (some of those that are used in the popup messages) - prettified some GUI elements (some of those that are used in the popup messages)
- In Excellon Editor, finished th upgrade work on the Drill Array Plugin
29.04.2022 29.04.2022

View File

@@ -594,25 +594,25 @@ class DrillArray(FCShapeTool):
self.ui.x_entry.set_value(float(self.draw_app.snap_x)) self.ui.x_entry.set_value(float(self.draw_app.snap_x))
self.ui.y_entry.set_value(float(self.draw_app.snap_y)) self.ui.y_entry.set_value(float(self.draw_app.snap_y))
self.ui.array_type_radio.set_value('linear') self.ui.array_type_radio.set_value(self.draw_app.last_darray_type)
self.ui.on_array_type_radio(val=self.ui.array_type_radio.get_value()) self.ui.on_array_type_radio(val=self.ui.array_type_radio.get_value())
self.ui.array_size_entry.set_value(self.draw_app.last_darray_size) self.ui.array_size_entry.set_value(self.draw_app.last_darray_size)
self.ui.axis_radio.set_value(self.draw_app.last_darray_lin_dir) self.ui.axis_radio.set_value(self.draw_app.last_darray_lin_dir)
self.ui.pitch_entry.set_value(self.draw_app.last_darray_pitch) self.ui.pitch_entry.set_value(self.draw_app.last_darray_pitch)
self.ui.linear_angle_spinner.set_value(self.draw_app.last_darray_lin_angle) self.ui.linear_angle_entry.set_value(self.draw_app.last_darray_lin_angle)
self.ui.array_dir_radio.set_value(self.draw_app.last_darray_circ_dir) self.ui.array_dir_radio.set_value(self.draw_app.last_darray_circ_dir)
self.ui.angle_entry.set_value(self.draw_app.last_darray_circ_angle) self.ui.circular_angle_entry.set_value(self.draw_app.last_darray_circ_angle)
self.ui.radius_entry.set_value(self.draw_app.last_darray_radius)
def click(self, point): def click(self, point):
self.draw_app.last_length = self.darray_tool.length
self.ui.x_entry.set_value(float(self.draw_app.snap_x)) self.ui.x_entry.set_value(float(self.draw_app.snap_x))
self.ui.y_entry.set_value(float(self.draw_app.snap_y)) self.ui.y_entry.set_value(float(self.draw_app.snap_y))
if self.drill_array == 'linear': # 'Linear' if self.drill_array == 'linear': # 'Linear'
self.make() self.make()
return return
else:
if self.flag_for_circ_array is None: if self.flag_for_circ_array is None:
self.draw_app.in_action = True self.draw_app.in_action = True
self.pt.append(point) self.pt.append(point)
@@ -624,7 +624,6 @@ class DrillArray(FCShapeTool):
self.destination = point self.destination = point
self.make() self.make()
self.flag_for_circ_array = None self.flag_for_circ_array = None
return
def set_origin(self, origin): def set_origin(self, origin):
self.origin = origin self.origin = origin
@@ -633,25 +632,16 @@ class DrillArray(FCShapeTool):
self.drill_axis = self.ui.axis_radio.get_value() self.drill_axis = self.ui.axis_radio.get_value()
self.drill_direction = self.ui.array_dir_radio.get_value() self.drill_direction = self.ui.array_dir_radio.get_value()
self.drill_array = self.ui.array_type_radio.get_value() self.drill_array = self.ui.array_type_radio.get_value()
try:
self.drill_array_size = int(self.ui.array_size_entry.get_value()) self.drill_array_size = int(self.ui.array_size_entry.get_value())
try:
self.drill_pitch = float(self.ui.pitch_entry.get_value()) self.drill_pitch = float(self.ui.pitch_entry.get_value())
self.drill_linear_angle = float(self.ui.linear_angle_spinner.get_value()) self.drill_linear_angle = float(self.ui.linear_angle_entry.get_value())
self.drill_angle = float(self.ui.angle_entry.get_value()) self.drill_angle = float(self.ui.circular_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."))
return
except Exception as e:
self.draw_app.app.inform.emit('[ERROR_NOTCL] %s. %s' %
(_("The value is mistyped. Check the value"), str(e)))
return
if self.drill_array == 'linear': # 'Linear' if self.drill_array == 'linear': # 'Linear'
if data[0] is None and data[1] is None: if data[0] is None and data[1] is None:
dx = self.draw_app.x dx = self.draw_app.snap_x
dy = self.draw_app.y dy = self.draw_app.snap_y
else: else:
dx = data[0] dx = data[0]
dy = data[1] dy = data[1]
@@ -683,21 +673,22 @@ class DrillArray(FCShapeTool):
return DrawToolUtilityShape(geo_list) return DrawToolUtilityShape(geo_list)
elif self.drill_array == 'circular': # 'Circular' elif self.drill_array == 'circular': # 'Circular'
if data[0] is None and data[1] is None: if data[0] is None and data[1] is None:
cdx = self.draw_app.x cdx = self.draw_app.snap_x
cdy = self.draw_app.y cdy = self.draw_app.snap_y
else: else:
cdx = data[0] cdx = data[0]
cdy = data[1] cdy = data[1]
utility_list = [] utility_list = []
self.points = [cdx, cdy]
try: try:
radius = distance((cdx, cdy), self.origin) radius = distance((cdx, cdy), self.origin)
except Exception: except Exception:
radius = 0 radius = 0
if radius == 0: if radius == 0:
self.draw_app.delete_utility_geometry() self.draw_app.delete_utility_geometry()
self.ui.radius_entry.set_value(radius)
if len(self.pt) >= 1 and radius > 0: if len(self.pt) >= 1 and radius > 0:
try: try:
@@ -724,7 +715,7 @@ class DrillArray(FCShapeTool):
def circular_util_shape(self, radius, angle): def circular_util_shape(self, radius, angle):
self.drill_direction = self.ui.array_dir_radio.get_value() self.drill_direction = self.ui.array_dir_radio.get_value()
self.drill_angle = self.ui.angle_entry.get_value() self.drill_angle = self.ui.circular_angle_entry.get_value()
circular_geo = [] circular_geo = []
if self.drill_direction == 'CW': if self.drill_direction == 'CW':
@@ -825,7 +816,19 @@ class DrillArray(FCShapeTool):
self.draw_app.app.inform.emit('[success] %s' % _("Done.")) self.draw_app.app.inform.emit('[success] %s' % _("Done."))
self.draw_app.in_action = False self.draw_app.in_action = False
self.draw_app.last_darray_type = self.ui.array_type_radio.get_value()
self.draw_app.last_darray_size = self.ui.array_size_entry.get_value()
self.draw_app.last_darray_lin_dir = self.ui.axis_radio.get_value()
self.draw_app.last_darray_circ_dir = self.ui.array_dir_radio.get_value()
self.draw_app.last_darray_pitch = self.ui.pitch_entry.get_value()
self.draw_app.last_darray_lin_angle = self.ui.linear_angle_entry.get_value()
self.draw_app.last_darray_circ_angle = self.ui.circular_angle_entry.get_value()
self.draw_app.last_darray_radius = self.ui.radius_entry.get_value()
try:
self.draw_app.app.jump_signal.disconnect() self.draw_app.app.jump_signal.disconnect()
except (AttributeError, TypeError):
pass
def draw_cursor_data(self, pos=None, delete=False): def draw_cursor_data(self, pos=None, delete=False):
if pos is None: if pos is None:
@@ -850,7 +853,7 @@ class DrillArray(FCShapeTool):
x = pos[0] x = pos[0]
y = pos[1] y = pos[1]
try: try:
length = abs(np.sqrt((x - self.points[0]) ** 2 + (y - self.points[1]) ** 2)) length = abs(self.ui.radius_entry.get_value())
except IndexError: except IndexError:
length = self.draw_app.app.dec_format(0.0, self.draw_app.app.decimals) length = self.draw_app.app.dec_format(0.0, self.draw_app.app.decimals)
@@ -887,9 +890,7 @@ class DrillArray(FCShapeTool):
else: else:
mod_key = None mod_key = None
if mod_key == 'Control': if mod_key is None:
pass
elif mod_key is None:
# Toggle Drill Array Direction # Toggle Drill Array Direction
if key == QtCore.Qt.Key.Key_Space: if key == QtCore.Qt.Key.Key_Space:
if self.ui.axis_radio.get_value() == 'X': if self.ui.axis_radio.get_value() == 'X':
@@ -906,54 +907,35 @@ class DrillArray(FCShapeTool):
if key == QtCore.Qt.Key.Key_J or key == 'J': if key == QtCore.Qt.Key.Key_J or key == 'J':
self.draw_app.app.on_jump_to() self.draw_app.app.on_jump_to()
if key in [str(i) for i in range(10)] + ['.', ',', '+', '-', '/', '*'] or \
key in [QtCore.Qt.Key.Key_0, QtCore.Qt.Key.Key_1, QtCore.Qt.Key.Key_2,
QtCore.Qt.Key.Key_3, QtCore.Qt.Key.Key_4, QtCore.Qt.Key.Key_5, QtCore.Qt.Key.Key_6,
QtCore.Qt.Key.Key_7, QtCore.Qt.Key.Key_8, QtCore.Qt.Key.Key_9, QtCore.Qt.Key.Key_Minus,
QtCore.Qt.Key.Key_Plus, QtCore.Qt.Key.Key_Comma, QtCore.Qt.Key.Key_Period,
QtCore.Qt.Key.Key_Slash, QtCore.Qt.Key.Key_Asterisk]:
try:
# VisPy keys
if self.darray_tool.length == self.draw_app.last_length:
self.darray_tool.length = str(key.name)
else:
self.darray_tool.length = str(self.darray_tool.length) + str(key.name)
except AttributeError:
# Qt keys
if self.darray_tool.length == self.draw_app.last_length:
self.darray_tool.length = chr(key)
else:
self.darray_tool.length = str(self.darray_tool.length) + chr(key)
if key == 'Enter' or key == QtCore.Qt.Key.Key_Return or key == QtCore.Qt.Key.Key_Enter:
if self.darray_tool.length != 0:
target_length = self.darray_tool.length
if target_length is None:
self.darray_tool.length = 0.0
return _("Failed.")
first_pt = self.ui.x_entry.get_value(), self.ui.y_entry.get_value()
last_pt = self.draw_app.snap_x, self.draw_app.snap_y
seg_length = math.sqrt((last_pt[0] - first_pt[0]) ** 2 + (last_pt[1] - first_pt[1]) ** 2)
if seg_length == 0.0:
return
try:
new_x = first_pt[0] + (last_pt[0] - first_pt[0]) / seg_length * target_length
new_y = first_pt[1] + (last_pt[1] - first_pt[1]) / seg_length * target_length
except ZeroDivisionError as err:
self.clean_up()
return '[ERROR_NOTCL] %s %s' % (_("Failed."), str(err).capitalize())
if first_pt != (new_x, new_y):
self.draw_app.app.on_jump_to(custom_location=(new_x, new_y), fit_center=False)
self.add_drill_array(drill_pos=(new_x, new_y))
def add_drill_array(self, array_pos): def add_drill_array(self, array_pos):
pass self.drill_radius = self.ui.radius_entry.get_value()
self.drill_array = self.ui.array_type_radio.get_value()
curr_pos = self.draw_app.app.geo_editor.snap(array_pos[0], array_pos[1])
self.draw_app.snap_x = curr_pos[0]
self.draw_app.snap_y = curr_pos[1]
self.points = [self.draw_app.snap_x, self.draw_app.snap_y]
self.origin = [self.draw_app.snap_x, self.draw_app.snap_y]
self.destination = ((self.origin[0] + self.drill_radius), self.origin[1])
self.flag_for_circ_array = True
self.make()
if self.draw_app.current_storage is not None:
self.draw_app.on_exc_shape_complete(self.draw_app.current_storage)
self.draw_app.build_ui()
if self.draw_app.active_tool.complete:
self.draw_app.on_shape_complete()
self.draw_app.select_tool("drill_select")
self.draw_app.clicked_pos = curr_pos
def on_add_drill_array(self): def on_add_drill_array(self):
pass x = self.ui.x_entry.get_value()
y = self.ui.y_entry.get_value()
self.add_drill_array(array_pos=(x, y))
def clean_up(self): def clean_up(self):
self.draw_app.selected = [] self.draw_app.selected = []
@@ -2312,6 +2294,7 @@ class AppExcEditor(QtCore.QObject):
self.last_darray_pitch = None self.last_darray_pitch = None
self.last_darray_lin_angle = None self.last_darray_lin_angle = None
self.last_darray_circ_angle = None self.last_darray_circ_angle = None
self.last_darray_radius = None
self.last_slot_length = None self.last_slot_length = None
self.last_slot_direction = None self.last_slot_direction = None
@@ -2484,6 +2467,7 @@ class AppExcEditor(QtCore.QObject):
self.last_darray_pitch = float(self.app.options['excellon_editor_lin_pitch']) self.last_darray_pitch = float(self.app.options['excellon_editor_lin_pitch'])
self.last_darray_lin_angle = float(self.app.options['excellon_editor_lin_angle']) self.last_darray_lin_angle = float(self.app.options['excellon_editor_lin_angle'])
self.last_darray_circ_angle = float(self.app.options['excellon_editor_circ_angle']) self.last_darray_circ_angle = float(self.app.options['excellon_editor_circ_angle'])
self.last_darray_radius = 0.0
self.last_slot_length = self.app.options['excellon_editor_slot_length'] self.last_slot_length = self.app.options['excellon_editor_slot_length']
self.last_slot_direction = self.app.options['excellon_editor_slot_direction'] self.last_slot_direction = self.app.options['excellon_editor_slot_direction']

View File

@@ -19,19 +19,14 @@ class ExcDrillArrayEditorTool(AppTool):
self.plugin_name = plugin_name self.plugin_name = plugin_name
self.ui = ExcDrillArrayEditorUI(layout=self.layout, darray_class=self, plugin_name=plugin_name) self.ui = ExcDrillArrayEditorUI(layout=self.layout, darray_class=self, plugin_name=plugin_name)
self.connect_signals_at_init() self.connect_signals_at_init()
self.set_tool_ui()
def connect_signals_at_init(self): def connect_signals_at_init(self):
# Signals # Signals
self.ui.clear_btn.clicked.connect(self.on_clear) pass
def disconnect_signals(self): def disconnect_signals(self):
# Signals # Signals
try:
self.ui.clear_btn.clicked.disconnect()
except (TypeError, AttributeError):
pass pass
def run(self): def run(self):
@@ -71,8 +66,6 @@ class ExcDrillArrayEditorTool(AppTool):
def set_tool_ui(self): def set_tool_ui(self):
# Init appGUI # Init appGUI
self.length = 0.0
self.ui.array_type_radio.set_value('linear') self.ui.array_type_radio.set_value('linear')
self.ui.on_array_type_radio(self.ui.array_type_radio.get_value()) self.ui.on_array_type_radio(self.ui.array_type_radio.get_value())
self.ui.axis_radio.set_value('X') self.ui.axis_radio.set_value('X')
@@ -88,14 +81,6 @@ class ExcDrillArrayEditorTool(AppTool):
def on_clear(self): def on_clear(self):
self.set_tool_ui() self.set_tool_ui()
@property
def length(self):
return self.ui.project_line_entry.get_value()
@length.setter
def length(self, val):
self.ui.project_line_entry.set_value(val)
def hide_tool(self): def hide_tool(self):
self.ui.darray_frame.hide() self.ui.darray_frame.hide()
self.app.ui.notebook.setCurrentWidget(self.app.ui.properties_tab) self.app.ui.notebook.setCurrentWidget(self.app.ui.properties_tab)
@@ -275,13 +260,13 @@ class ExcDrillArrayEditorUI:
"Max value is: 360.00 degrees.") "Max value is: 360.00 degrees.")
) )
self.linear_angle_spinner = FCDoubleSpinner(policy=False) self.linear_angle_entry = FCDoubleSpinner(policy=False)
self.linear_angle_spinner.set_precision(self.decimals) self.linear_angle_entry.set_precision(self.decimals)
self.linear_angle_spinner.setSingleStep(1.0) self.linear_angle_entry.setSingleStep(1.0)
self.linear_angle_spinner.setRange(-360.00, 360.00) self.linear_angle_entry.setRange(-360.00, 360.00)
self.lin_grid.addWidget(self.linear_angle_label, 4, 0) self.lin_grid.addWidget(self.linear_angle_label, 4, 0)
self.lin_grid.addWidget(self.linear_angle_spinner, 4, 1) self.lin_grid.addWidget(self.linear_angle_entry, 4, 1)
# ############################################################################################################# # #############################################################################################################
# ############################ CIRCULAR Array ################################################################# # ############################ CIRCULAR Array #################################################################
@@ -308,38 +293,28 @@ class ExcDrillArrayEditorUI:
self.circ_grid.addWidget(self.array_dir_radio, 0, 1) self.circ_grid.addWidget(self.array_dir_radio, 0, 1)
# Array Angle # Array Angle
self.array_angle_lbl = FCLabel('%s:' % _('Angle')) self.circular_angle_lbl = FCLabel('%s:' % _('Angle'))
self.array_angle_lbl.setToolTip(_("Angle at which each element in circular array is placed.")) self.circular_angle_lbl.setToolTip(_("Angle at which each element in circular array is placed."))
self.angle_entry = FCDoubleSpinner(policy=False) self.circular_angle_entry = FCDoubleSpinner(policy=False)
self.angle_entry.set_precision(self.decimals) self.circular_angle_entry.set_precision(self.decimals)
self.angle_entry.setSingleStep(1.0) self.circular_angle_entry.setSingleStep(1.0)
self.angle_entry.setRange(-360.00, 360.00) self.circular_angle_entry.setRange(-360.00, 360.00)
self.circ_grid.addWidget(self.array_angle_lbl, 2, 0) self.circ_grid.addWidget(self.circular_angle_lbl, 2, 0)
self.circ_grid.addWidget(self.angle_entry, 2, 1) self.circ_grid.addWidget(self.circular_angle_entry, 2, 1)
# ############################################################################################################# # Radius
# Projection Frame self.radius_lbl = FCLabel('%s:' % _('Radius'))
# ############################################################################################################# self.radius_lbl.setToolTip(_("Array radius."))
pro_frame = FCFrame()
self.editor_vbox.addWidget(pro_frame)
pro_grid = GLay(v_spacing=5, h_spacing=3, c_stretch=[0, 1, 0]) self.radius_entry = FCDoubleSpinner(policy=False)
pro_frame.setLayout(pro_grid) self.radius_entry.set_precision(self.decimals)
self.radius_entry.setSingleStep(1.0)
self.radius_entry.setRange(-10000.0000,10000.000)
# Project distance self.circ_grid.addWidget(self.radius_lbl, 4, 0)
self.project_line_lbl = FCLabel('%s:' % _("Projection")) self.circ_grid.addWidget(self.radius_entry, 4, 1)
self.project_line_lbl.setToolTip(
_("Length of the current segment/move.")
)
self.project_line_entry = NumericalEvalEntry(border_color='#0069A9')
pro_grid.addWidget(self.project_line_lbl, 0, 0)
pro_grid.addWidget(self.project_line_entry, 0, 1)
self.clear_btn = QtWidgets.QToolButton()
self.clear_btn.setIcon(QtGui.QIcon(self.darray_class.app.resource_location + '/trash32.png'))
pro_grid.addWidget(self.clear_btn, 0, 2)
# ############################################################################################################# # #############################################################################################################
# Buttons # Buttons
@@ -348,7 +323,7 @@ class ExcDrillArrayEditorUI:
self.add_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/plus16.png')) self.add_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/plus16.png'))
self.layout.addWidget(self.add_btn) self.layout.addWidget(self.add_btn)
GLay.set_common_column_size([dia_grid, pro_grid, pos_grid, self.array_grid, self.lin_grid, self.circ_grid], 0) GLay.set_common_column_size([dia_grid, pos_grid, self.array_grid, self.lin_grid, self.circ_grid], 0)
self.layout.addStretch(1) self.layout.addStretch(1)
@@ -385,8 +360,8 @@ class ExcDrillArrayEditorUI:
def on_linear_angle_radio(self, val): def on_linear_angle_radio(self, val):
if val == 'A': if val == 'A':
self.linear_angle_spinner.setEnabled(True) self.linear_angle_entry.setEnabled(True)
self.linear_angle_label.setEnabled(True) self.linear_angle_label.setEnabled(True)
else: else:
self.linear_angle_spinner.setEnabled(False) self.linear_angle_entry.setEnabled(False)
self.linear_angle_label.setEnabled(False) self.linear_angle_label.setEnabled(False)