From 5298a59372305992b842e9bb0cc3e95b958b1bc2 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sun, 22 May 2022 04:37:16 +0300 Subject: [PATCH] - in Gerber Editor upgraded the Track sub-tool GUI --- CHANGELOG.md | 1 + appEditors/AppGerberEditor.py | 206 ++++++++++++++++++++--- appEditors/grb_plugins/GrbTracePlugin.py | 149 ---------------- appEditors/grb_plugins/GrbTrackPlugin.py | 196 +++++++++++++++++++++ 4 files changed, 376 insertions(+), 176 deletions(-) delete mode 100644 appEditors/grb_plugins/GrbTracePlugin.py create mode 100644 appEditors/grb_plugins/GrbTrackPlugin.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 383e2417..cb3f2367 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ CHANGELOG for FlatCAM Evo beta - in Gerber Editor upgraded the PadAdd GUI - in Gerber Editor upgraded the PadArray GUI +- in Gerber Editor upgraded the Track sub-tool GUI 21.05.2022 diff --git a/appEditors/AppGerberEditor.py b/appEditors/AppGerberEditor.py index c6423742..8dc14270 100644 --- a/appEditors/AppGerberEditor.py +++ b/appEditors/AppGerberEditor.py @@ -16,6 +16,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.GrbTrackPlugin import GrbTrackEditorTool from appEditors.grb_plugins.GrbSimplificationPlugin import SimplificationTool from appEditors.grb_plugins.GrbCopyPlugin import CopyEditorTool @@ -342,7 +343,6 @@ class PadEditorGrb(ShapeToolEditorGrb): # VisPy keys if self.pad_tool.length == self.draw_app.last_length: self.pad_tool.length = str(key.name) - self.new_segment = False else: self.pad_tool.length = str(self.pad_tool.length) + str(key.name) except AttributeError: @@ -1476,12 +1476,13 @@ class TrackEditorGrb(ShapeToolEditorGrb): DrawTool.__init__(self, draw_app) self.name = 'track' self.draw_app = draw_app + self.app = self.draw_app.app self.dont_execute = False self.steps_per_circle = self.draw_app.app.options["gerber_circle_steps"] try: - size_ap = float(self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['size']) + self.size_ap = float(self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['size']) except KeyError: self.draw_app.app.inform.emit('[ERROR_NOTCL] %s' % _("You need to preselect a aperture in the Aperture Table that has a size.")) @@ -1495,7 +1496,7 @@ class TrackEditorGrb(ShapeToolEditorGrb): self.draw_app.select_tool('select') return - self.buf_val = (size_ap / 2) if size_ap > 0 else 0.0000001 + self.buf_val = (self.size_ap / 2) if self.size_ap > 0 else 0.0000001 self.gridx_size = float(self.draw_app.app.ui.grid_gap_x_entry.get_value()) self.gridy_size = float(self.draw_app.app.ui.grid_gap_y_entry.get_value()) @@ -1514,17 +1515,54 @@ class TrackEditorGrb(ShapeToolEditorGrb): '/aero_path%s.png' % self.draw_app.bend_mode)) QtGui.QGuiApplication.setOverrideCursor(self.cursor) + # ############################################################################################################# + # Plugin UI + # ############################################################################################################# + self.track_tool = GrbTrackEditorTool(self.app, self.draw_app, plugin_name=_("Track")) + self.ui = self.track_tool.ui + self.track_tool.run() + + 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)) + self.track_tool.length = self.draw_app.last_length + 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, _("Track")) + 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_track) + + # self.draw_app.app.jump_signal.connect(lambda x: self.draw_app.update_utility_geometry(data=x)) + self.draw_app.app.inform.emit(_('Track Mode 1: 45 degrees ...')) + def set_plugin_ui(self): + self.ui.dia_entry.set_value(self.size_ap) + self.ui.x_entry.set_value(float(self.draw_app.snap_x)) + self.ui.y_entry.set_value(float(self.draw_app.snap_y)) + def click(self, point): self.draw_app.in_action = True - self.current_point = point if not self.points or point != self.points[-1]: self.points.append(point) + self.draw_app.last_length = self.track_tool.length + self.ui.x_entry.set_value(float(self.draw_app.snap_x)) + self.ui.y_entry.set_value(float(self.draw_app.snap_y)) else: return @@ -1650,9 +1688,68 @@ class TrackEditorGrb(ShapeToolEditorGrb): self.draw_app.in_action = False self.complete = True - self.draw_app.app.jump_signal.disconnect() + + try: + self.draw_app.app.jump_signal.disconnect() + except (TypeError, AttributeError): + pass + self.draw_app.app.inform.emit('[success] %s' % _("Done.")) + 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 + + # 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 + + if not self.points: + old_x = self.draw_app.snap_x + old_y = self.draw_app.snap_y + else: + old_x = self.points[-1][0] + old_y = self.points[-1][1] + + x = pos[0] + y = pos[1] + try: + length = abs(np.sqrt((x - old_x) ** 2 + (y - old_y) ** 2)) + 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): if key == 'Backspace' or key == QtCore.Qt.Key.Key_Backspace: if len(self.points) > 0: @@ -1749,6 +1846,61 @@ class TrackEditorGrb(ShapeToolEditorGrb): return msg + 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.track_tool.length == self.draw_app.last_length: + self.track_tool.length = str(key.name) + else: + self.track_tool.length = str(self.track_tool.length) + str(key.name) + except AttributeError: + # Qt keys + if self.track_tool.length == self.draw_app.last_length: + self.track_tool.length = chr(key) + else: + self.track_tool.length = str(self.track_tool.length) + chr(key) + + if key == 'Enter' or key == QtCore.Qt.Key.Key_Return or key == QtCore.Qt.Key.Key_Enter: + if self.track_tool.length != 0: + target_length = self.track_tool.length + if target_length is None: + self.track_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_track(track_pos=(new_x, new_y)) + + def add_track(self, track_pos): + self.draw_app.last_length = self.track_tool.length + self.click(track_pos) + self.ui.x_entry.set_value(track_pos[0]) + self.ui.y_entry.set_value(track_pos[1]) + self.draw_app.clicked_pos = track_pos + + def on_add_track(self): + x = self.ui.x_entry.get_value() + y = self.ui.y_entry.get_value() + self.add_track(track_pos=(x, y)) + def clean_up(self): self.draw_app.selected = [] self.draw_app.ui.apertures_table.clearSelection() @@ -3681,7 +3833,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) #noqa + 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()) @@ -5720,7 +5872,7 @@ class AppGerberEditor(QtCore.QObject): self.update_utility_geometry(data=(x, y)) if self.active_tool.name in [ - 'pad', 'array' + 'pad', 'array', 'track' ]: try: self.active_tool.draw_cursor_data(pos=self.app.mouse_pos) @@ -7030,22 +7182,22 @@ class TransformEditorTool(AppTool): self.ref_combo.currentIndexChanged.connect(self.on_reference_changed) self.point_button.clicked.connect(self.on_add_coords) - self.rotate_button.clicked.connect(self.on_rotate) + self.rotate_button.clicked.connect(lambda: self.on_rotate()) - self.skewx_button.clicked.connect(self.on_skewx) - self.skewy_button.clicked.connect(self.on_skewy) + self.skewx_button.clicked.connect(lambda: self.on_skewx()) + self.skewy_button.clicked.connect(lambda: self.on_skewy) - self.scalex_button.clicked.connect(self.on_scalex) - self.scaley_button.clicked.connect(self.on_scaley) + self.scalex_button.clicked.connect(lambda: self.on_scalex()) + self.scaley_button.clicked.connect(lambda: self.on_scaley()) - self.offx_button.clicked.connect(self.on_offx) - self.offy_button.clicked.connect(self.on_offy) + self.offx_button.clicked.connect(lambda: self.on_offx()) + self.offy_button.clicked.connect(lambda: self.on_offy()) - self.flipx_button.clicked.connect(self.on_flipx) - self.flipy_button.clicked.connect(self.on_flipy) + self.flipx_button.clicked.connect(lambda: self.on_flipx()) + self.flipy_button.clicked.connect(lambda: self.on_flipy()) - self.buffer_button.clicked.connect(self.on_buffer_by_distance) - self.buffer_factor_button.clicked.connect(self.on_buffer_by_factor) + self.buffer_button.clicked.connect(lambda: self.on_buffer_by_distance()) + self.buffer_factor_button.clicked.connect(lambda: self.on_buffer_by_factor()) # self.rotate_entry.editingFinished.connect(self.on_rotate) # self.skewx_entry.editingFinished.connect(self.on_skewx) @@ -7206,7 +7358,7 @@ class TransformEditorTool(AppTool): val = self.app.clipboard.text() self.point_entry.set_value(val) - def on_rotate(self, sig=None, val=None, ref=None): + def on_rotate(self, val=None, ref=None): value = float(self.rotate_entry.get_value()) if val is None else val if value == 0: self.app.inform.emit('[WARNING_NOTCL] %s' % _("Rotate transformation can not be done for a value of 0.")) @@ -7216,21 +7368,21 @@ class TransformEditorTool(AppTool): return self.app.worker_task.emit({'fcn': self.on_rotate_action, 'params': [value, point]}) - def on_flipx(self, signal=None, ref=None): + def on_flipx(self, ref=None): axis = 'Y' point = self.on_calculate_reference() if ref is None else self.on_calculate_reference(ref_index=ref) if point == 'fail': return self.app.worker_task.emit({'fcn': self.on_flip, 'params': [axis, point]}) - def on_flipy(self, signal=None, ref=None): + def on_flipy(self, ref=None): axis = 'X' point = self.on_calculate_reference() if ref is None else self.on_calculate_reference(ref_index=ref) if point == 'fail': return self.app.worker_task.emit({'fcn': self.on_flip, 'params': [axis, point]}) - def on_skewx(self, signal=None, val=None, ref=None): + def on_skewx(self, val=None, ref=None): xvalue = float(self.skewx_entry.get_value()) if val is None else val if xvalue == 0: @@ -7248,7 +7400,7 @@ class TransformEditorTool(AppTool): self.app.worker_task.emit({'fcn': self.on_skew, 'params': [axis, xvalue, yvalue, point]}) - def on_skewy(self, signal=None, val=None, ref=None): + def on_skewy(self, val=None, ref=None): xvalue = 0 yvalue = float(self.skewy_entry.get_value()) if val is None else val @@ -7262,7 +7414,7 @@ class TransformEditorTool(AppTool): self.app.worker_task.emit({'fcn': self.on_skew, 'params': [axis, xvalue, yvalue, point]}) - def on_scalex(self, signal=None, val=None, ref=None): + def on_scalex(self, val=None, ref=None): xvalue = float(self.scalex_entry.get_value()) if val is None else val if xvalue == 0 or xvalue == 1: @@ -7282,7 +7434,7 @@ class TransformEditorTool(AppTool): self.app.worker_task.emit({'fcn': self.on_scale, 'params': [axis, xvalue, yvalue, point]}) - def on_scaley(self, signal=None, val=None, ref=None): + def on_scaley(self, val=None, ref=None): xvalue = 1 yvalue = float(self.scaley_entry.get_value()) if val is None else val @@ -7298,7 +7450,7 @@ class TransformEditorTool(AppTool): self.app.worker_task.emit({'fcn': self.on_scale, 'params': [axis, xvalue, yvalue, point]}) - def on_offx(self, signal=None, val=None): + def on_offx(self, val=None): value = float(self.offx_entry.get_value()) if val is None else val if value == 0: self.app.inform.emit('[WARNING_NOTCL] %s' % _("Offset transformation can not be done for a value of 0.")) @@ -7307,7 +7459,7 @@ class TransformEditorTool(AppTool): self.app.worker_task.emit({'fcn': self.on_offset, 'params': [axis, value]}) - def on_offy(self, signal=None, val=None): + def on_offy(self, val=None): value = float(self.offy_entry.get_value()) if val is None else val if value == 0: self.app.inform.emit('[WARNING_NOTCL] %s' % _("Offset transformation can not be done for a value of 0.")) diff --git a/appEditors/grb_plugins/GrbTracePlugin.py b/appEditors/grb_plugins/GrbTracePlugin.py deleted file mode 100644 index b9c92c3f..00000000 --- a/appEditors/grb_plugins/GrbTracePlugin.py +++ /dev/null @@ -1,149 +0,0 @@ - -from appTool import * - -fcTranslate.apply_language('strings') -if '_' not in builtins.__dict__: - _ = gettext.gettext - - -class TraceEditorTool(AppToolEditor): - """ - Simple input for buffer distance. - """ - - 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 = PathEditorUI(layout=self.layout, path_class=self, plugin_name=plugin_name) - - self.connect_signals_at_init() - self.set_tool_ui() - - def connect_signals_at_init(self): - # Signals - self.ui.clear_btn.clicked.connect(self.on_clear) - - def disconnect_signals(self): - # Signals - try: - self.ui.clear_btn.clicked.disconnect() - except (TypeError, AttributeError): - pass - - def run(self): - self.app.defaults.report_usage("Geo Editor ToolPath()") - 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.length = 0.0 - - 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() - - @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): - self.ui.path_tool_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 PathEditorUI: - - def __init__(self, layout, path_class, plugin_name): - self.pluginName = plugin_name - self.path_class = path_class - self.decimals = self.path_class.app.decimals - self.layout = layout - - # 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.path_tool_frame = QtWidgets.QFrame() - self.path_tool_frame.setContentsMargins(0, 0, 0, 0) - self.layout.addWidget(self.path_tool_frame) - self.path_tool_box = QtWidgets.QVBoxLayout() - self.path_tool_box.setContentsMargins(0, 0, 0, 0) - self.path_tool_frame.setLayout(self.path_tool_box) - - # Grid Layout - grid_path = GLay(v_spacing=5, h_spacing=3) - self.path_tool_box.addLayout(grid_path) - - # Project distance - self.project_line_lbl = FCLabel('%s:' % _("Projection")) - self.project_line_lbl.setToolTip( - _("Length of the current segment/move.") - ) - self.project_line_entry = NumericalEvalEntry(border_color='#0069A9') - grid_path.addWidget(self.project_line_lbl, 0, 0) - grid_path.addWidget(self.project_line_entry, 0, 1) - - # self.buffer_corner_lbl = FCLabel('%s:' % _("Buffer corner")) - # self.buffer_corner_lbl.setToolTip( - # _("There are 3 types of corners:\n" - # " - 'Round': the corner is rounded for exterior buffer.\n" - # " - 'Square': the corner is met in a sharp angle for exterior buffer.\n" - # " - 'Beveled': the corner is a line that directly connects the features meeting in the corner") - # ) - # self.buffer_corner_cb = FCComboBox() - # self.buffer_corner_cb.addItem(_("Round")) - # self.buffer_corner_cb.addItem(_("Square")) - # self.buffer_corner_cb.addItem(_("Beveled")) - # grid_path.addWidget(self.buffer_corner_lbl, 2, 0) - # grid_path.addWidget(self.buffer_corner_cb, 2, 1) - - self.clear_btn = FCButton(_("Clear")) - grid_path.addWidget(self.clear_btn, 4, 0, 1, 2) - - self.layout.addStretch(1) diff --git a/appEditors/grb_plugins/GrbTrackPlugin.py b/appEditors/grb_plugins/GrbTrackPlugin.py new file mode 100644 index 00000000..253354e2 --- /dev/null +++ b/appEditors/grb_plugins/GrbTrackPlugin.py @@ -0,0 +1,196 @@ + +from appTool import * + +fcTranslate.apply_language('strings') +if '_' not in builtins.__dict__: + _ = gettext.gettext + + +class GrbTrackEditorTool(AppToolEditor): + """ + Simple input for buffer distance. + """ + + 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 = GrbTrackEditorUI(layout=self.layout, track_class=self, plugin_name=plugin_name) + + self.connect_signals_at_init() + self.set_tool_ui() + + def connect_signals_at_init(self): + # Signals + self.ui.clear_btn.clicked.connect(self.on_clear) + + def disconnect_signals(self): + # Signals + try: + self.ui.clear_btn.clicked.disconnect() + except (TypeError, AttributeError): + pass + + def run(self): + self.app.defaults.report_usage("Geo Editor ToolPath()") + 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.length = 0.0 + + 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() + + @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): + self.ui.drill_tool_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 GrbTrackEditorUI: + + def __init__(self, layout, track_class, plugin_name): + self.pluginName = plugin_name + self.ed_class = track_class + self.decimals = self.ed_class.app.decimals + self.layout = layout + + # 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.drill_tool_frame = QtWidgets.QFrame() + self.drill_tool_frame.setContentsMargins(0, 0, 0, 0) + self.layout.addWidget(self.drill_tool_frame) + self.editor_vbox = QtWidgets.QVBoxLayout() + self.editor_vbox.setContentsMargins(0, 0, 0, 0) + self.drill_tool_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) + + # ############################################################################################################# + # Projection Frame + # ############################################################################################################# + pro_frame = FCFrame() + self.editor_vbox.addWidget(pro_frame) + + pro_grid = GLay(v_spacing=5, h_spacing=3, c_stretch=[0, 1, 0]) + pro_frame.setLayout(pro_grid) + + # Project distance + self.project_line_lbl = FCLabel('%s:' % _("Projection")) + 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.ed_class.app.resource_location + '/trash32.png')) + pro_grid.addWidget(self.clear_btn, 0, 2) + + self.add_btn = FCButton(_("Add")) + self.add_btn.setIcon(QtGui.QIcon(self.ed_class.app.resource_location + '/plus32.png')) + self.editor_vbox.addWidget(self.add_btn) + + GLay.set_common_column_size([dia_grid, pos_grid, pro_grid], 0) + self.layout.addStretch(1)