diff --git a/CHANGELOG.md b/CHANGELOG.md index c4e4dc07..383e2417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG for FlatCAM Evo beta 22.05.2022 - in Gerber Editor upgraded the PadAdd GUI +- in Gerber Editor upgraded the PadArray GUI 21.05.2022 diff --git a/appEditors/AppExcEditor.py b/appEditors/AppExcEditor.py index 2c47de85..576ed827 100644 --- a/appEditors/AppExcEditor.py +++ b/appEditors/AppExcEditor.py @@ -584,6 +584,10 @@ class DrillArray(FCShapeTool): pass self.ui.add_btn.clicked.connect(self.on_add_drill_array) + if self.ui.array_type_radio.get_value() == 'linear': + self.draw_app.app.inform.emit(_("Click on target location ...")) + else: + self.draw_app.app.inform.emit(_("Click on the circular array Center position")) # self.draw_app.app.jump_signal.connect(lambda x: self.draw_app.update_utility_geometry(data=x)) def set_plugin_ui(self): diff --git a/appEditors/AppGerberEditor.py b/appEditors/AppGerberEditor.py index eb047b9f..c6423742 100644 --- a/appEditors/AppGerberEditor.py +++ b/appEditors/AppGerberEditor.py @@ -15,6 +15,7 @@ from appEditors.grb_plugins.GrbPadPlugin import PadEditorTool from appEditors.grb_plugins.GrbBufferPlugin import BufferEditorTool from appEditors.grb_plugins.GrbTransformationPlugin import TransformEditorTool +from appEditors.grb_plugins.GrbPadArrayPlugin import GrbPadArrayEditorTool from appEditors.grb_plugins.GrbSimplificationPlugin import SimplificationTool from appEditors.grb_plugins.GrbCopyPlugin import CopyEditorTool @@ -406,6 +407,7 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): DrawTool.__init__(self, draw_app) self.name = 'array' self.draw_app = draw_app + self.app = self.draw_app.app self.dont_execute = False try: @@ -448,18 +450,15 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): except KeyError: pass - self.draw_app.ui.array_frame.show() - self.selected_size = None - self.pad_axis = 'X' - self.pad_array = 'linear' # 'linear' + self.pad_array_dir = 'X' + self.array_type = 'linear' # 'linear' self.pad_array_size = None self.pad_pitch = None self.pad_linear_angle = None - self.pad_angle = None + self.pad_circular_angle = None self.pad_direction = None - self.pad_radius = None self.origin = None self.destination = None @@ -470,36 +469,82 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): self.pt = [] + # ############################################################################################################# + # Plugin UI + # ############################################################################################################# + self.parray_tool = GrbPadArrayEditorTool(self.app, self.draw_app, plugin_name=_("Pad Array")) + self.ui = self.parray_tool.ui + self.parray_tool.run() + geo = self.utility_geometry(data=(self.draw_app.snap_x, self.draw_app.snap_y), static=True) if isinstance(geo, DrawToolShape) and geo.geo is not None: self.draw_app.draw_utility_geometry(geo_shape=geo) - self.draw_app.app.inform.emit(_("Click on target location ...")) - + if self.app.use_3d_engine: + self.draw_app.app.plotcanvas.view.camera.zoom_callback = self.draw_cursor_data self.draw_app.app.jump_signal.connect(lambda x: self.draw_app.update_utility_geometry(data=x)) - # Switch notebook to Properties page - self.draw_app.app.ui.notebook.setCurrentWidget(self.draw_app.app.ui.properties_tab) + if not self.draw_app.snap_x: + self.draw_app.snap_x = 0.0 + if not self.draw_app.snap_y: + self.draw_app.snap_y = 0.0 + + self.app.ui.notebook.setTabText(2, _("Pad Array")) + if self.app.ui.splitter.sizes()[0] == 0: + self.app.ui.splitter.setSizes([1, 1]) + + self.set_plugin_ui() + + # Signals + try: + self.ui.add_btn.clicked.disconnect() + except (AttributeError, TypeError): + pass + self.ui.add_btn.clicked.connect(self.on_add_pad_array) + + if self.ui.array_type_radio.get_value() == 'linear': + self.draw_app.app.inform.emit(_("Click on target location ...")) + else: + self.draw_app.app.inform.emit(_("Click on the circular array Center position")) + + def set_plugin_ui(self): + dia = float(self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['size']) + self.ui.dia_entry.set_value(dia) + 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.array_type_radio.set_value(self.draw_app.last_parray_type) + 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_parray_size) + self.ui.axis_radio.set_value(self.draw_app.last_parray_lin_dir) + self.ui.pitch_entry.set_value(self.draw_app.last_parray_pitch) + self.ui.linear_angle_entry.set_value(self.draw_app.last_parray_lin_angle) + self.ui.array_dir_radio.set_value(self.draw_app.last_parray_circ_dir) + self.ui.circular_angle_entry.set_value(self.draw_app.last_parray_circ_angle) + self.ui.radius_entry.set_value(self.draw_app.last_parray_radius) def click(self, point): - - if self.draw_app.ui.array_type_radio.get_value() == 0: # 'Linear' + if self.ui.array_type_radio.get_value() == 'linear': # 'Linear' self.make() + self.ui.x_entry.set_value(float(self.draw_app.snap_x)) + self.ui.y_entry.set_value(float(self.draw_app.snap_y)) return - else: - if self.flag_for_circ_array is None: - self.draw_app.in_action = True - self.pt.append(point) - self.flag_for_circ_array = True - self.set_origin(point) - self.draw_app.app.inform.emit(_("Click on the Pad Circular Array Start position")) - else: - self.destination = point - self.make() - self.flag_for_circ_array = None - return + self.ui.x_entry.set_value(float(self.draw_app.snap_x)) + self.ui.y_entry.set_value(float(self.draw_app.snap_y)) + if self.flag_for_circ_array is None: + self.draw_app.in_action = True + self.pt.append(point) + + self.flag_for_circ_array = True + self.set_origin(point) + self.draw_app.app.inform.emit(_("Click on the circular array Center position")) + else: + self.destination = point + self.make() + self.flag_for_circ_array = None def set_origin(self, origin): self.origin = origin @@ -517,25 +562,26 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): self.draw_app.select_tool('select') return - self.pad_axis = self.draw_app.ui.pad_axis_radio.get_value() - self.pad_direction = self.draw_app.ui.pad_direction_radio.get_value() - self.pad_array = self.draw_app.ui.array_type_radio.get_value() + self.pad_array_dir = self.ui.axis_radio.get_value() + self.pad_direction = self.ui.array_dir_radio.get_value() + self.array_type = self.ui.array_type_radio.get_value() try: - self.pad_array_size = int(self.draw_app.ui.pad_array_size_entry.get_value()) - try: - self.pad_pitch = self.draw_app.ui.pad_pitch_entry.get_value() - self.pad_linear_angle = self.draw_app.ui.linear_angle_spinner.get_value() - self.pad_angle = self.draw_app.ui.pad_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 + self.pad_array_size = self.ui.array_size_entry.get_value() except Exception: self.draw_app.app.inform.emit('[ERROR_NOTCL] %s' % _("The value is mistyped. Check the value.")) return - if self.pad_array == 'linear': # 'Linear' + try: + self.pad_pitch = self.ui.pitch_entry.get_value() + self.pad_linear_angle = self.ui.linear_angle_entry.get_value() + self.pad_circular_angle = 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 + + if self.array_type == 'linear': # 'Linear' if data[0] is None and data[1] is None: dx = self.draw_app.x dy = self.draw_app.y @@ -548,11 +594,11 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): self.points = [dx, dy] for item in range(self.pad_array_size): - if self.pad_axis == 'X': + if self.pad_array_dir == 'X': geo_el = self.util_shape(((dx + (self.pad_pitch * item)), dy)) - if self.pad_axis == 'Y': + if self.pad_array_dir == 'Y': geo_el = self.util_shape((dx, (dy + (self.pad_pitch * item)))) - if self.pad_axis == 'A': + if self.pad_array_dir == 'A': x_adj = self.pad_pitch * math.cos(math.radians(self.pad_linear_angle)) y_adj = self.pad_pitch * math.sin(math.radians(self.pad_linear_angle)) geo_el = self.util_shape( @@ -579,7 +625,7 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): self.last_dx = dx self.last_dy = dy return DrawToolUtilityShape(geo_el_list) - elif self.pad_array == 'circular': # 'Circular' + elif self.array_type == 'circular': # 'Circular' if data[0] is None and data[1] is None: cdx = self.draw_app.x cdy = self.draw_app.y @@ -593,9 +639,9 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): radius = distance((cdx, cdy), self.origin) except Exception: radius = 0 - if radius == 0: self.draw_app.delete_utility_geometry() + self.ui.radius_entry.set_value(radius) if len(self.pt) >= 1 and radius > 0: try: @@ -732,13 +778,13 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): return None def circular_util_shape(self, radius, angle): - self.pad_direction = self.draw_app.ui.pad_direction_radio.get_value() - self.pad_angle = self.draw_app.ui.pad_angle_entry.get_value() + self.pad_direction = self.ui.array_dir_radio.get_value() + self.pad_circular_angle = self.ui.circular_angle_entry.get_value() circular_geo = [] if self.pad_direction == 'CW': for i in range(self.pad_array_size): - angle_radians = math.radians(self.pad_angle * i) + angle_radians = math.radians(self.pad_circular_angle * i) x = self.origin[0] + radius * math.cos(-angle_radians + angle) y = self.origin[1] + radius * math.sin(-angle_radians + angle) @@ -752,7 +798,7 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): circular_geo.append(DrawToolShape(geo_el)) else: for i in range(self.pad_array_size): - angle_radians = math.radians(self.pad_angle * i) + angle_radians = math.radians(self.pad_circular_angle * i) x = self.origin[0] + radius * math.cos(angle_radians + angle) y = self.origin[1] + radius * math.sin(angle_radians + angle) @@ -773,13 +819,13 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): self.draw_app.current_storage = self.storage_obj - if self.pad_array == 'linear': # 'Linear' + if self.array_type == 'linear': # 'Linear' for item in range(self.pad_array_size): - if self.pad_axis == 'X': + if self.pad_array_dir == 'X': geo = self.util_shape(((self.points[0] + (self.pad_pitch * item)), self.points[1])) - if self.pad_axis == 'Y': + if self.pad_array_dir == 'Y': geo = self.util_shape((self.points[0], (self.points[1] + (self.pad_pitch * item)))) - if self.pad_axis == 'A': + if self.pad_array_dir == 'A': x_adj = self.pad_pitch * math.cos(math.radians(self.pad_linear_angle)) y_adj = self.pad_pitch * math.sin(math.radians(self.pad_linear_angle)) geo = self.util_shape( @@ -788,7 +834,7 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): self.geometry.append(DrawToolShape(geo)) else: # 'Circular' - if (self.pad_angle * self.pad_array_size) > 360: + if (self.pad_circular_angle * self.pad_array_size) > 360: self.draw_app.app.inform.emit('[WARNING_NOTCL] %s' % _("Too many items for the selected spacing angle.")) return @@ -810,8 +856,70 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): self.complete = True self.draw_app.app.inform.emit('[success] %s' % _("Done.")) self.draw_app.in_action = False - self.draw_app.ui.array_frame.hide() - self.draw_app.app.jump_signal.disconnect() + + self.draw_app.last_parray_type = self.ui.array_type_radio.get_value() + self.draw_app.last_parray_size = self.ui.array_size_entry.get_value() + self.draw_app.last_parray_lin_dir = self.ui.axis_radio.get_value() + self.draw_app.last_parray_circ_dir = self.ui.array_dir_radio.get_value() + self.draw_app.last_parray_pitch = self.ui.pitch_entry.get_value() + self.draw_app.last_parray_lin_angle = self.ui.linear_angle_entry.get_value() + self.draw_app.last_parray_circ_angle = self.ui.circular_angle_entry.get_value() + self.draw_app.last_parray_radius = self.ui.radius_entry.get_value() + + try: + self.draw_app.app.jump_signal.disconnect() + except (AttributeError, TypeError): + pass + + def draw_cursor_data(self, pos=None, delete=False): + if pos is None: + pos = self.draw_app.snap_x, self.draw_app.snap_y + + if delete: + if self.draw_app.app.use_3d_engine: + self.draw_app.app.plotcanvas.text_cursor.parent = None + self.draw_app.app.plotcanvas.view.camera.zoom_callback = lambda *args: None + return + + if not self.points: + self.points = self.draw_app.snap_x, self.draw_app.snap_y + + # font size + qsettings = QtCore.QSettings("Open Source", "FlatCAM") + if qsettings.contains("hud_font_size"): + fsize = qsettings.value('hud_font_size', type=int) + else: + fsize = 8 + + x = pos[0] + y = pos[1] + try: + length = abs(self.ui.radius_entry.get_value()) + except IndexError: + length = self.draw_app.app.dec_format(0.0, self.draw_app.app.decimals) + + x_dec = str(self.draw_app.app.dec_format(x, self.draw_app.app.decimals)) if x else '0.0' + y_dec = str(self.draw_app.app.dec_format(y, self.draw_app.app.decimals)) if y else '0.0' + length_dec = str(self.draw_app.app.dec_format(length, self.draw_app.app.decimals)) if length else '0.0' + + units = self.draw_app.app.app_units.lower() + l1_txt = 'X: %s [%s]' % (x_dec, units) + l2_txt = 'Y: %s [%s]' % (y_dec, units) + l3_txt = 'L: %s [%s]' % (length_dec, units) + cursor_text = '%s\n%s\n\n%s' % (l1_txt, l2_txt, l3_txt) + + if self.draw_app.app.use_3d_engine: + new_pos = self.draw_app.app.plotcanvas.translate_coords_2((x, y)) + x, y, __, ___ = self.draw_app.app.plotcanvas.translate_coords((new_pos[0]+30, new_pos[1])) + + # text + self.draw_app.app.plotcanvas.text_cursor.font_size = fsize + self.draw_app.app.plotcanvas.text_cursor.text = cursor_text + self.draw_app.app.plotcanvas.text_cursor.pos = x, y + self.draw_app.app.plotcanvas.text_cursor.anchors = 'left', 'top' + + if self.draw_app.app.plotcanvas.text_cursor.parent is None: + self.draw_app.app.plotcanvas.text_cursor.parent = self.draw_app.app.plotcanvas.view.scene def on_key(self, key): key_modifier = QtWidgets.QApplication.keyboardModifiers() @@ -828,20 +936,55 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): elif mod_key is None: # Toggle Drill Array Direction if key == QtCore.Qt.Key.Key_Space: - if self.draw_app.ui.pad_axis_radio.get_value() == 'X': - self.draw_app.ui.pad_axis_radio.set_value('Y') - elif self.draw_app.ui.pad_axis_radio.get_value() == 'Y': - self.draw_app.ui.pad_axis_radio.set_value('A') - elif self.draw_app.ui.pad_axis_radio.get_value() == 'A': - self.draw_app.ui.pad_axis_radio.set_value('X') + if self.ui.pad_dir_radio.get_value() == 'X': + self.ui.pad_dir_radio.set_value('Y') + elif self.ui.pad_axis_radio.get_value() == 'Y': + self.ui.pad_axis_radio.set_value('A') + elif self.ui.pad_axis_radio.get_value() == 'A': + self.ui.pad_axis_radio.set_value('X') # ## Utility geometry (animated) self.draw_app.update_utility_geometry(data=(self.draw_app.snap_x, self.draw_app.snap_y)) + def add_pad_array(self, array_pos): + self.radius = self.ui.radius_entry.get_value() + self.array_type = 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.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_grb_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("select") + + self.draw_app.clicked_pos = curr_pos + + def on_add_pad_array(self): + x = self.ui.x_entry.get_value() + y = self.ui.y_entry.get_value() + self.add_pad_array(array_pos=(x, y)) + def clean_up(self): self.draw_app.selected = [] self.draw_app.ui.apertures_table.clearSelection() self.draw_app.plot_all() + + if self.draw_app.app.use_3d_engine: + self.draw_app.app.plotcanvas.text_cursor.parent = None + self.draw_app.app.plotcanvas.view.camera.zoom_callback = lambda *args: None + try: self.draw_app.app.jump_signal.disconnect() except (TypeError, AttributeError): @@ -3538,10 +3681,7 @@ class AppGerberEditor(QtCore.QObject): self.ui.delaperture_btn.clicked.connect(lambda: self.on_aperture_delete()) self.ui.apertures_table.cellPressed.connect(self.on_row_selected) - self.ui.apertures_table.selectionModel().selectionChanged.connect(self.on_table_selection) - - self.ui.array_type_radio.activated_custom.connect(self.on_array_type_radio) - self.ui.pad_axis_radio.activated_custom.connect(self.on_linear_angle_radio) + self.ui.apertures_table.selectionModel().selectionChanged.connect(self.on_table_selection) #noqa self.ui.simplification_btn.clicked.connect(self.on_simplification_click) self.ui.exit_editor_button.clicked.connect(lambda: self.app.editor2object()) @@ -3639,21 +3779,14 @@ class AppGerberEditor(QtCore.QObject): self.ui.apdim_entry.set_value(self.app.options["gerber_editor_newdim"]) # PAD Array - self.ui.array_type_radio.set_value('linear') # Linear - self.on_array_type_radio(val=self.ui.array_type_radio.get_value()) - self.ui.pad_array_size_entry.set_value(int(self.app.options["gerber_editor_array_size"])) - - # linear array - self.ui.pad_axis_radio.set_value('X') - self.on_linear_angle_radio(val=self.ui.pad_axis_radio.get_value()) - self.ui.pad_axis_radio.set_value(self.app.options["gerber_editor_lin_axis"]) - self.ui.pad_pitch_entry.set_value(float(self.app.options["gerber_editor_lin_pitch"])) - self.ui.linear_angle_spinner.set_value(self.app.options["gerber_editor_lin_angle"]) - - # circular array - self.ui.pad_direction_radio.set_value('CW') - self.ui.pad_direction_radio.set_value(self.app.options["gerber_editor_circ_dir"]) - self.ui.pad_angle_entry.set_value(float(self.app.options["gerber_editor_circ_angle"])) + self.last_parray_type = 'linear' + self.last_parray_size = int(self.app.options['gerber_editor_array_size']) + self.last_parray_lin_dir = self.app.options['gerber_editor_lin_dir'] + self.last_parray_circ_dir = self.app.options['gerber_editor_circ_dir'] + self.last_parray_pitch = float(self.app.options['gerber_editor_lin_pitch']) + self.last_parray_lin_angle = float(self.app.options['gerber_editor_lin_angle']) + self.last_parray_circ_angle = float(self.app.options['gerber_editor_circ_angle']) + self.last_parray_radius = 0.0 self.ui.geo_coords_entry.setText('') self.ui.geo_vertex_entry.set_value(0.0) @@ -5587,7 +5720,7 @@ class AppGerberEditor(QtCore.QObject): self.update_utility_geometry(data=(x, y)) if self.active_tool.name in [ - 'pad', + 'pad', 'array' ]: try: self.active_tool.draw_cursor_data(pos=self.app.mouse_pos) @@ -5920,48 +6053,6 @@ class AppGerberEditor(QtCore.QObject): if geo_el in self.selected: self.selected.remove(geo_el) - def on_array_type_radio(self, val): - if val == 'linear': - self.ui.pad_axis_label.show() - self.ui.pad_axis_radio.show() - self.ui.pad_pitch_label.show() - self.ui.pad_pitch_entry.show() - self.ui.linear_angle_label.show() - self.ui.linear_angle_spinner.show() - self.ui.lin_separator_line.show() - - self.ui.pad_direction_label.hide() - self.ui.pad_direction_radio.hide() - self.ui.pad_angle_label.hide() - self.ui.pad_angle_entry.hide() - self.ui.circ_separator_line.hide() - else: - self.delete_utility_geometry() - - self.ui.pad_axis_label.hide() - self.ui.pad_axis_radio.hide() - self.ui.pad_pitch_label.hide() - self.ui.pad_pitch_entry.hide() - self.ui.linear_angle_label.hide() - self.ui.linear_angle_spinner.hide() - self.ui.lin_separator_line.hide() - - self.ui.pad_direction_label.show() - self.ui.pad_direction_radio.show() - self.ui.pad_angle_label.show() - self.ui.pad_angle_entry.show() - self.ui.circ_separator_line.show() - - self.app.inform.emit(_("Click on the circular array Center position")) - - def on_linear_angle_radio(self, val): - if val == 'A': - self.ui.linear_angle_spinner.show() - self.ui.linear_angle_label.show() - else: - self.ui.linear_angle_spinner.hide() - self.ui.linear_angle_label.hide() - def on_copy_button(self): self.select_tool('copy') return @@ -6549,145 +6640,6 @@ class AppGerberEditorUI: ) hlay_ma.addWidget(self.ma_clear_button) - # ############################################################################################################# - # ######################################### Add Pad Array ##################################################### - # ############################################################################################################# - self.array_frame = QtWidgets.QFrame() - self.array_frame.setContentsMargins(0, 0, 0, 0) - self.custom_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) - - separator_line = QtWidgets.QFrame() - separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) - separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) - self.array_box.addWidget(separator_line) - - array_grid = GLay(v_spacing=5, h_spacing=3) - self.array_box.addLayout(array_grid) - - # Title - self.padarray_label = FCLabel('%s' % _("Add Pad Array"), bold=True) - self.padarray_label.setToolTip( - _("Add an array of pads (linear or circular array)") - ) - array_grid.addWidget(self.padarray_label, 0, 0, 1, 2) - - # Array Type - array_type_lbl = FCLabel('%s:' % _("Type")) - array_type_lbl.setToolTip( - _("Select the type of pads array to create.\n" - "It can be Linear X(Y) or Circular") - ) - - self.array_type_radio = RadioSet([{'label': _('Linear'), 'value': 'linear'}, - {'label': _('Circular'), 'value': 'circular'}]) - - array_grid.addWidget(array_type_lbl, 2, 0) - array_grid.addWidget(self.array_type_radio, 2, 1) - - # Number of Pads in Array - pad_array_size_label = FCLabel('%s:' % _('Nr of pads')) - pad_array_size_label.setToolTip( - _("Specify how many pads to be in the array.") - ) - - self.pad_array_size_entry = FCSpinner() - self.pad_array_size_entry.set_range(1, 10000) - - array_grid.addWidget(pad_array_size_label, 4, 0) - array_grid.addWidget(self.pad_array_size_entry, 4, 1) - - # ############################################################################################################# - # ############################ Linear Pad Array ############################################################### - # ############################################################################################################# - self.lin_separator_line = QtWidgets.QFrame() - self.lin_separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) - self.lin_separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) - array_grid.addWidget(self.lin_separator_line, 6, 0, 1, 2) - - # Linear Direction - self.pad_axis_label = FCLabel('%s:' % _('Direction')) - self.pad_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.pad_axis_radio = RadioSet([{'label': _('X'), 'value': 'X'}, - {'label': _('Y'), 'value': 'Y'}, - {'label': _('Angle'), 'value': 'A'}]) - - array_grid.addWidget(self.pad_axis_label, 8, 0) - array_grid.addWidget(self.pad_axis_radio, 8, 1) - - # Linear Pitch - self.pad_pitch_label = FCLabel('%s:' % _('Pitch')) - self.pad_pitch_label.setToolTip( - _("Pitch = Distance between elements of the array.") - ) - - self.pad_pitch_entry = FCDoubleSpinner() - self.pad_pitch_entry.set_precision(self.decimals) - self.pad_pitch_entry.set_range(0.0000, 10000.0000) - self.pad_pitch_entry.setSingleStep(0.1) - - array_grid.addWidget(self.pad_pitch_label, 10, 0) - array_grid.addWidget(self.pad_pitch_entry, 10, 1) - - # Linear Angle - self.linear_angle_label = FCLabel('%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.00 degrees.\n" - "Max value is: 360.00 degrees.") - ) - - self.linear_angle_spinner = FCDoubleSpinner() - self.linear_angle_spinner.set_precision(self.decimals) - self.linear_angle_spinner.setRange(-360.00, 360.00) - - array_grid.addWidget(self.linear_angle_label, 12, 0) - array_grid.addWidget(self.linear_angle_spinner, 12, 1) - - # ############################################################################################################# - # ################################### Circular Pad Array ###################################################### - # ############################################################################################################# - self.circ_separator_line = QtWidgets.QFrame() - self.circ_separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) - self.circ_separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) - array_grid.addWidget(self.circ_separator_line, 14, 0, 1, 2) - - # Circular Direction - self.pad_direction_label = FCLabel('%s:' % _('Direction')) - self.pad_direction_label.setToolTip( - _("Direction for circular array.\n" - "Can be CW = clockwise or CCW = counter clockwise.") - ) - - self.pad_direction_radio = RadioSet([{'label': _('CW'), 'value': 'CW'}, - {'label': _('CCW'), 'value': 'CCW'}]) - - array_grid.addWidget(self.pad_direction_label, 16, 0) - array_grid.addWidget(self.pad_direction_radio, 16, 1) - - # Circular Angle - self.pad_angle_label = FCLabel('%s:' % _('Angle')) - self.pad_angle_label.setToolTip( - _("Angle at which each element in circular array is placed.") - ) - - self.pad_angle_entry = FCDoubleSpinner() - self.pad_angle_entry.set_precision(self.decimals) - self.pad_angle_entry.set_range(-360.00, 360.00) - self.pad_angle_entry.setSingleStep(0.1) - - array_grid.addWidget(self.pad_angle_label, 18, 0) - array_grid.addWidget(self.pad_angle_entry, 18, 1) - self.custom_box.addStretch() layout.addStretch() diff --git a/appEditors/exc_plugins/ExcDrillArrayPlugin.py b/appEditors/exc_plugins/ExcDrillArrayPlugin.py index 382135ea..fea30e04 100644 --- a/appEditors/exc_plugins/ExcDrillArrayPlugin.py +++ b/appEditors/exc_plugins/ExcDrillArrayPlugin.py @@ -110,7 +110,7 @@ class ExcDrillArrayEditorUI: self.darray_frame.setLayout(self.editor_vbox) # Position - self.tool_lbl = FCLabel('%s' % _("Tool Diameter"), bold=True, color='blue') + self.tool_lbl = FCLabel('%s' % _("Diameter"), bold=True, color='blue') self.editor_vbox.addWidget(self.tool_lbl) # ############################################################################################################# # Diameter Frame diff --git a/appEditors/grb_plugins/GrbPadArrayPlugin.py b/appEditors/grb_plugins/GrbPadArrayPlugin.py index e69de29b..f8516e6b 100644 --- a/appEditors/grb_plugins/GrbPadArrayPlugin.py +++ b/appEditors/grb_plugins/GrbPadArrayPlugin.py @@ -0,0 +1,360 @@ + +from appTool import * + +fcTranslate.apply_language('strings') +if '_' not in builtins.__dict__: + _ = gettext.gettext + + +class GrbPadArrayEditorTool(AppToolEditor): + """ + Create an array of drill holes + """ + + def __init__(self, app, draw_app, plugin_name): + AppToolEditor.__init__(self, app) + + self.draw_app = draw_app + self.decimals = app.decimals + self.plugin_name = plugin_name + + self.ui = GrbPadArrayEditorUI(layout=self.layout, parray_class=self, plugin_name=plugin_name) + self.connect_signals_at_init() + + def connect_signals_at_init(self): + # Signals + pass + + def disconnect_signals(self): + # Signals + pass + + def run(self): + self.app.defaults.report_usage("Exc Editor ArrayTool()") + super().run() + + # if the splitter us hidden, display it + if self.app.ui.splitter.sizes()[0] == 0: + self.app.ui.splitter.setSizes([1, 1]) + + # if the Tool Tab is hidden display it, else hide it but only if the objectName is the same + found_idx = None + for idx in range(self.app.ui.notebook.count()): + if self.app.ui.notebook.widget(idx).objectName() == "plugin_tab": + found_idx = idx + break + # show the Tab + if not found_idx: + try: + self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin")) + except RuntimeError: + self.app.ui.plugin_tab = QtWidgets.QWidget() + self.app.ui.plugin_tab.setObjectName("plugin_tab") + self.app.ui.plugin_tab_layout = QtWidgets.QVBoxLayout(self.app.ui.plugin_tab) + self.app.ui.plugin_tab_layout.setContentsMargins(2, 2, 2, 2) + + self.app.ui.plugin_scroll_area = VerticalScrollArea() + self.app.ui.plugin_tab_layout.addWidget(self.app.ui.plugin_scroll_area) + self.app.ui.notebook.addTab(self.app.ui.plugin_tab, _("Plugin")) + + # focus on Tool Tab + self.app.ui.notebook.setCurrentWidget(self.app.ui.plugin_tab) + + # self.app.ui.notebook.callback_on_close = self.on_tab_close + + self.app.ui.notebook.setTabText(2, self.plugin_name) + + def set_tool_ui(self): + # Init appGUI + self.ui.array_type_radio.set_value('linear') + self.ui.on_array_type_radio(self.ui.array_type_radio.get_value()) + self.ui.axis_radio.set_value('X') + self.ui.on_linear_angle_radio(self.ui.axis_radio.get_value()) + + self.ui.array_dir_radio.set_value('CW') + + def on_tab_close(self): + self.disconnect_signals() + self.hide_tool() + # self.app.ui.notebook.callback_on_close = lambda: None + + def on_clear(self): + self.set_tool_ui() + + def hide_tool(self): + self.ui.parray_frame.hide() + self.app.ui.notebook.setCurrentWidget(self.app.ui.properties_tab) + if self.draw_app.active_tool.name != 'select': + self.draw_app.select_tool("select") + + +class GrbPadArrayEditorUI: + + def __init__(self, layout, parray_class, plugin_name): + self.pluginName = plugin_name + self.parray_class = parray_class + self.decimals = self.parray_class.app.decimals + self.layout = layout + self.app = self.parray_class.app + + # Title + title_label = FCLabel("%s" % ('Editor ' + self.pluginName), size=16, bold=True) + self.layout.addWidget(title_label) + + # this way I can hide/show the frame + self.parray_frame = QtWidgets.QFrame() + self.parray_frame.setContentsMargins(0, 0, 0, 0) + self.layout.addWidget(self.parray_frame) + self.editor_vbox = QtWidgets.QVBoxLayout() + self.editor_vbox.setContentsMargins(0, 0, 0, 0) + self.parray_frame.setLayout(self.editor_vbox) + + # Position + self.tool_lbl = FCLabel('%s' % _("Diameter"), bold=True, color='blue') + self.editor_vbox.addWidget(self.tool_lbl) + # ############################################################################################################# + # Diameter Frame + # ############################################################################################################# + dia_frame = FCFrame() + self.editor_vbox.addWidget(dia_frame) + + dia_grid = GLay(v_spacing=5, h_spacing=3, c_stretch=[0, 1, 0]) + dia_frame.setLayout(dia_grid) + + # Dia Value + self.dia_lbl = FCLabel('%s:' % _("Value")) + self.dia_entry = NumericalEvalEntry(border_color='#0069A9') + self.dia_entry.setDisabled(True) + self.dia_unit = FCLabel('%s' % 'mm') + + dia_grid.addWidget(self.dia_lbl, 0, 0) + dia_grid.addWidget(self.dia_entry, 0, 1) + dia_grid.addWidget(self.dia_unit, 0, 2) + + # Position + self.pos_lbl = FCLabel('%s' % _("Position"), bold=True, color='red') + self.editor_vbox.addWidget(self.pos_lbl) + # ############################################################################################################# + # Position Frame + # ############################################################################################################# + pos_frame = FCFrame() + self.editor_vbox.addWidget(pos_frame) + + pos_grid = GLay(v_spacing=5, h_spacing=3) + pos_frame.setLayout(pos_grid) + + # X Pos + self.x_lbl = FCLabel('%s:' % _("X")) + self.x_entry = FCDoubleSpinner() + self.x_entry.set_precision(self.decimals) + self.x_entry.set_range(-10000.0000, 10000.0000) + pos_grid.addWidget(self.x_lbl, 2, 0) + pos_grid.addWidget(self.x_entry, 2, 1) + + # Y Pos + self.y_lbl = FCLabel('%s:' % _("Y")) + self.y_entry = FCDoubleSpinner() + self.y_entry.set_precision(self.decimals) + self.y_entry.set_range(-10000.0000, 10000.0000) + pos_grid.addWidget(self.y_lbl, 4, 0) + pos_grid.addWidget(self.y_entry, 4, 1) + + # Position + self.par_lbl = FCLabel('%s' % _("Parameters"), bold=True, color='purple') + self.editor_vbox.addWidget(self.par_lbl) + # ############################################################################################################# + # ######################################## Add Array ########################################################## + # ############################################################################################################# + # add a frame and inside add a grid box layout. + self.array_frame = FCFrame() + self.editor_vbox.addWidget(self.array_frame) + + self.array_grid = GLay(v_spacing=5, h_spacing=3) + self.array_frame.setLayout(self.array_grid) + + # Array Type + array_type_lbl = FCLabel('%s:' % _("Type")) + array_type_lbl.setToolTip( + _("Select the type of array to create.\n" + "It can be Linear X(Y) or Circular") + ) + + self.array_type_radio = RadioSet([ + {'label': _('Linear'), 'value': 'linear'}, + {'label': _('Circular'), 'value': 'circular'} + ]) + + self.array_grid.addWidget(array_type_lbl, 2, 0) + self.array_grid.addWidget(self.array_type_radio, 2, 1) + + # Array Size + self.array_size_label = FCLabel('%s:' % _('Size')) + self.array_size_label.setToolTip(_("Specify how many items to be in the array.")) + + self.array_size_entry = FCSpinner(policy=False) + self.array_size_entry.set_range(1, 100000) + + self.array_grid.addWidget(self.array_size_label, 4, 0) + self.array_grid.addWidget(self.array_size_entry, 4, 1) + + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.Shape.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken) + self.array_grid.addWidget(separator_line, 6, 0, 1, 2) + + # ############################################################################################################# + # ############################ LINEAR Array ################################################################### + # ############################################################################################################# + self.array_linear_frame = QtWidgets.QFrame() + self.array_linear_frame.setContentsMargins(0, 0, 0, 0) + self.array_grid.addWidget(self.array_linear_frame, 8, 0, 1, 2) + + self.lin_grid = GLay(v_spacing=5, h_spacing=3) + self.lin_grid.setContentsMargins(0, 0, 0, 0) + self.array_linear_frame.setLayout(self.lin_grid) + + # Linear Drill Array direction + self.axis_label = FCLabel('%s:' % _('Direction')) + self.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.axis_radio = RadioSet([ + {'label': _('X'), 'value': 'X'}, + {'label': _('Y'), 'value': 'Y'}, + {'label': _('Angle'), 'value': 'A'} + ]) + + self.lin_grid.addWidget(self.axis_label, 0, 0) + self.lin_grid.addWidget(self.axis_radio, 0, 1) + + # Linear Array pitch distance + self.pitch_label = FCLabel('%s:' % _('Pitch')) + self.pitch_label.setToolTip( + _("Pitch = Distance between elements of the array.") + ) + + self.pitch_entry = FCDoubleSpinner(policy=False) + self.pitch_entry.set_precision(self.decimals) + self.pitch_entry.set_range(0.0000, 10000.0000) + + self.lin_grid.addWidget(self.pitch_label, 2, 0) + self.lin_grid.addWidget(self.pitch_entry, 2, 1) + + # Linear Array angle + self.linear_angle_label = FCLabel('%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.00 degrees.\n" + "Max value is: 360.00 degrees.") + ) + + self.linear_angle_entry = FCDoubleSpinner(policy=False) + self.linear_angle_entry.set_precision(self.decimals) + self.linear_angle_entry.setSingleStep(1.0) + 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_entry, 4, 1) + + # ############################################################################################################# + # ############################ CIRCULAR Array ################################################################# + # ############################################################################################################# + self.array_circular_frame = QtWidgets.QFrame() + self.array_circular_frame.setContentsMargins(0, 0, 0, 0) + self.array_grid.addWidget(self.array_circular_frame, 12, 0, 1, 2) + + self.circ_grid = GLay(v_spacing=5, h_spacing=3) + self.circ_grid.setContentsMargins(0, 0, 0, 0) + self.array_circular_frame.setLayout(self.circ_grid) + + # Array Direction + self.array_dir_lbl = FCLabel('%s:' % _('Direction')) + self.array_dir_lbl.setToolTip( + _("Direction for circular array.\n" + "Can be CW = clockwise or CCW = counter clockwise.")) + + self.array_dir_radio = RadioSet([ + {'label': _('CW'), 'value': 'CW'}, + {'label': _('CCW'), 'value': 'CCW'}]) + + self.circ_grid.addWidget(self.array_dir_lbl, 0, 0) + self.circ_grid.addWidget(self.array_dir_radio, 0, 1) + + # Array Angle + self.circular_angle_lbl = FCLabel('%s:' % _('Angle')) + self.circular_angle_lbl.setToolTip(_("Angle at which each element in circular array is placed.")) + + self.circular_angle_entry = FCDoubleSpinner(policy=False) + self.circular_angle_entry.set_precision(self.decimals) + self.circular_angle_entry.setSingleStep(1.0) + self.circular_angle_entry.setRange(-360.00, 360.00) + + self.circ_grid.addWidget(self.circular_angle_lbl, 2, 0) + self.circ_grid.addWidget(self.circular_angle_entry, 2, 1) + + # Radius + self.radius_lbl = FCLabel('%s:' % _('Radius')) + self.radius_lbl.setToolTip(_("Array radius.")) + + self.radius_entry = FCDoubleSpinner(policy=False) + self.radius_entry.set_precision(self.decimals) + self.radius_entry.setSingleStep(1.0) + self.radius_entry.setRange(-10000.0000,10000.000) + + self.circ_grid.addWidget(self.radius_lbl, 4, 0) + self.circ_grid.addWidget(self.radius_entry, 4, 1) + + # ############################################################################################################# + # Buttons + # ############################################################################################################# + self.add_btn = FCButton(_("Add")) + self.add_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/plus16.png')) + self.layout.addWidget(self.add_btn) + + GLay.set_common_column_size([dia_grid, pos_grid, self.array_grid, self.lin_grid, self.circ_grid], 0) + + self.layout.addStretch(1) + + # Signals + self.array_type_radio.activated_custom.connect(self.on_array_type_radio) + self.axis_radio.activated_custom.connect(self.on_linear_angle_radio) + + 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) + + 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) + + def on_array_type_radio(self, val): + if val == 'linear': + self.array_circular_frame.hide() + self.array_linear_frame.show() + + self.app.inform.emit(_("Click to place ...")) + else: # 'circular' + self.array_circular_frame.show() + self.array_linear_frame.hide() + + self.app.inform.emit(_("Click on the circular array Center position")) + + self.array_size_entry.setDisabled(False) + + def on_linear_angle_radio(self, val): + if val == 'A': + self.linear_angle_entry.setEnabled(True) + self.linear_angle_label.setEnabled(True) + else: + self.linear_angle_entry.setEnabled(False) + self.linear_angle_label.setEnabled(False) diff --git a/appGUI/preferences/PreferencesUIManager.py b/appGUI/preferences/PreferencesUIManager.py index 612e653e..a66ec630 100644 --- a/appGUI/preferences/PreferencesUIManager.py +++ b/appGUI/preferences/PreferencesUIManager.py @@ -175,7 +175,7 @@ class PreferencesUIManager(QtCore.QObject): "gerber_editor_newtype": self.ui.gerber_pref_form.gerber_editor_group.addtype_combo, "gerber_editor_newdim": self.ui.gerber_pref_form.gerber_editor_group.adddim_entry, "gerber_editor_array_size": self.ui.gerber_pref_form.gerber_editor_group.grb_array_size_entry, - "gerber_editor_lin_axis": self.ui.gerber_pref_form.gerber_editor_group.grb_axis_radio, + "gerber_editor_lin_dir": self.ui.gerber_pref_form.gerber_editor_group.grb_axis_radio, "gerber_editor_lin_pitch": self.ui.gerber_pref_form.gerber_editor_group.grb_pitch_entry, "gerber_editor_lin_angle": self.ui.gerber_pref_form.gerber_editor_group.grb_angle_entry, "gerber_editor_circ_dir": self.ui.gerber_pref_form.gerber_editor_group.grb_circular_dir_radio, diff --git a/defaults.py b/defaults.py index ac9e1f30..0db909a0 100644 --- a/defaults.py +++ b/defaults.py @@ -236,7 +236,7 @@ class AppDefaults: "gerber_editor_newtype": 'C', "gerber_editor_newdim": "0.5, 0.5", "gerber_editor_array_size": 5, - "gerber_editor_lin_axis": 'X', + "gerber_editor_lin_dir": 'X', "gerber_editor_lin_pitch": 0.1, "gerber_editor_lin_angle": 0.0, "gerber_editor_circ_dir": 'CW',