From 599cfb8d51b566ced91f04d6f449cf3d0c3c02d4 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Wed, 27 Nov 2019 21:40:39 +0200 Subject: [PATCH] - updated the workspace functions to work in Legacy(@D) graphic mode --- FlatCAMApp.py | 36 ++++------ README.md | 1 + flatcamEditors/FlatCAMGeoEditor.py | 15 ++++- flatcamGUI/PlotCanvas.py | 7 +- flatcamGUI/PlotCanvasLegacy.py | 101 ++++++++++++++++++++++++++++- 5 files changed, 129 insertions(+), 31 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index feca29c4..36664e54 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -132,7 +132,7 @@ class App(QtCore.QObject): # ################## Version and VERSION DATE ############################## # ########################################################################## version = 8.99 - version_date = "2019/11/25" + version_date = "2019/11/30" beta = True engine = '3D' @@ -2093,12 +2093,6 @@ class App(QtCore.QObject): self.setup_recent_items() self.setup_component_editor() - # this does not work in Legacy Mode - if self.is_legacy is True: - self.ui.general_defaults_form.general_gui_group.workspace_cb.setDisabled(True) - self.ui.general_defaults_form.general_gui_group.workspace_type_lbl.setDisabled(True) - self.ui.general_defaults_form.general_gui_group.wk_cb.setDisabled(True) - # ##################################################################################### # ######################### Auto-complete KEYWORDS #################################### # ##################################################################################### @@ -5867,30 +5861,29 @@ class App(QtCore.QObject): if self.toggle_axis is False: if self.is_legacy is False: - # self.plotcanvas.v_line.set_data(color=(0.70, 0.3, 0.3, 1.0)) - # self.plotcanvas.h_line.set_data(color=(0.70, 0.3, 0.3, 1.0)) self.plotcanvas.v_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 1.0), vertical=True, parent=self.plotcanvas.view.scene) self.plotcanvas.h_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 1.0), vertical=False, parent=self.plotcanvas.view.scene) - # self.plotcanvas.redraw() else: - self.plotcanvas.axes.axhline(color=(0.70, 0.3, 0.3), linewidth=2) - self.plotcanvas.axes.axvline(color=(0.70, 0.3, 0.3), linewidth=2) - self.plotcanvas.canvas.draw() - pass + if self.plotcanvas.h_line not in self.plotcanvas.axes.lines and \ + self.plotcanvas.v_line not in self.plotcanvas.axes.lines: + self.plotcanvas.h_line = self.plotcanvas.axes.axhline(color=(0.70, 0.3, 0.3), linewidth=2) + self.plotcanvas.v_line = self.plotcanvas.axes.axvline(color=(0.70, 0.3, 0.3), linewidth=2) + self.plotcanvas.canvas.draw() + self.toggle_axis = True else: if self.is_legacy is False: - # self.plotcanvas.v_line.set_data(color=(0.0, 0.0, 0.0, 0.0)) - # self.plotcanvas.h_line.set_data(color=(0.0, 0.0, 0.0, 0.0)) - # self.plotcanvas.redraw() self.plotcanvas.v_line.parent = None self.plotcanvas.h_line.parent = None else: - self.plotcanvas.axes.lines[:] = [] - self.plotcanvas.canvas.draw() + if self.plotcanvas.h_line in self.plotcanvas.axes.lines and \ + self.plotcanvas.v_line in self.plotcanvas.axes.lines: + self.plotcanvas.axes.lines.remove(self.plotcanvas.h_line) + self.plotcanvas.axes.lines.remove(self.plotcanvas.v_line) + self.plotcanvas.canvas.draw() self.toggle_axis = False def on_toggle_grid(self): @@ -6670,13 +6663,12 @@ class App(QtCore.QObject): def on_workspace_modified(self): # self.save_defaults(silent=True) + if self.is_legacy is True: + self.plotcanvas.delete_workspace() self.defaults_read_form() self.plotcanvas.draw_workspace(workspace_size=self.defaults['global_workspaceT']) def on_workspace(self): - self.report_usage("on_workspace()") - log.debug("on_workspace()") - if self.ui.general_defaults_form.general_gui_group.workspace_cb.get_value(): self.plotcanvas.draw_workspace(workspace_size=self.defaults['global_workspaceT']) else: diff --git a/README.md b/README.md index 58b8bc2a..3fd7ae80 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ CAD program, and create G-Code for Isolation routing. - in Tool Film added the page size and page orientation in case of saving the film as PDF file - the application workspace has now a lot more options selectable in the Edit -> Preferences -> General -> GUI Preferences - updated the drawing of the workspace such that the application overall start time is improved and after first turn on of the workspace, toggling it will have no performance penalty +- updated the workspace functions to work in Legacy(@D) graphic mode 26.11.2019 diff --git a/flatcamEditors/FlatCAMGeoEditor.py b/flatcamEditors/FlatCAMGeoEditor.py index ddde8695..14ad7b98 100644 --- a/flatcamEditors/FlatCAMGeoEditor.py +++ b/flatcamEditors/FlatCAMGeoEditor.py @@ -4241,7 +4241,10 @@ class FlatCAMGeoEditor(QtCore.QObject): # # ## Grid snap if self.options["grid_snap"]: if self.options["global_gridx"] != 0: - snap_x_ = round(x / float(self.options["global_gridx"])) * float(self.options['global_gridx']) + try: + snap_x_ = round(x / float(self.options["global_gridx"])) * float(self.options['global_gridx']) + except TypeError: + snap_x_ = x else: snap_x_ = x @@ -4249,12 +4252,18 @@ class FlatCAMGeoEditor(QtCore.QObject): # and it will use the snap distance from GridX entry if self.app.ui.grid_gap_link_cb.isChecked(): if self.options["global_gridx"] != 0: - snap_y_ = round(y / float(self.options["global_gridx"])) * float(self.options['global_gridx']) + try: + snap_y_ = round(y / float(self.options["global_gridx"])) * float(self.options['global_gridx']) + except TypeError: + snap_y_ = y else: snap_y_ = y else: if self.options["global_gridy"] != 0: - snap_y_ = round(y / float(self.options["global_gridy"])) * float(self.options['global_gridy']) + try: + snap_y_ = round(y / float(self.options["global_gridy"])) * float(self.options['global_gridy']) + except TypeError: + snap_y_ = y else: snap_y_ = y nearest_grid_distance = distance((x, y), (snap_x_, snap_y_)) diff --git a/flatcamGUI/PlotCanvas.py b/flatcamGUI/PlotCanvas.py index 194972b7..5aa210d6 100644 --- a/flatcamGUI/PlotCanvas.py +++ b/flatcamGUI/PlotCanvas.py @@ -121,15 +121,14 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): self.container.addWidget(self.native) # ## AXIS # ## - self.v_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 1.0), vertical=True, + self.v_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 0.8), vertical=True, parent=self.view.scene) - self.h_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 1.0), vertical=False, + self.h_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 0.8), vertical=False, parent=self.view.scene) # draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area # all CNC have a limited workspace - if self.fcapp.defaults['global_workspace'] is True: self.draw_workspace(workspace_size=self.fcapp.defaults["global_workspaceT"]) @@ -181,7 +180,7 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): a = np.array([(0, 0), (dims[0], 0), (dims[0], dims[1]), (0, dims[1])]) if not self.workspace_line: - self.workspace_line = Line(pos=np.array((a[0], a[1], a[2], a[3], a[0])), color=(0.70, 0.3, 0.3, 1.0), + self.workspace_line = Line(pos=np.array((a[0], a[1], a[2], a[3], a[0])), color=(0.70, 0.3, 0.3, 0.7), antialias=True, method='agg', parent=self.view.scene) else: self.workspace_line.parent = self.view.scene diff --git a/flatcamGUI/PlotCanvasLegacy.py b/flatcamGUI/PlotCanvasLegacy.py index 609e2f02..af3d1ea2 100644 --- a/flatcamGUI/PlotCanvasLegacy.py +++ b/flatcamGUI/PlotCanvasLegacy.py @@ -30,6 +30,7 @@ from matplotlib import use as mpl_use mpl_use("Qt5Agg") from matplotlib.figure import Figure from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas +from matplotlib.lines import Line2D # from matplotlib.widgets import Cursor fcTranslate.apply_language('strings') @@ -152,6 +153,64 @@ class PlotCanvasLegacy(QtCore.QObject): theme_color = '#000000' tick_color = '#FFFFFF' + # workspace lines; I didn't use the rectangle because I didn't want to add another VisPy Node, + # which might decrease performance + # self.b_line, self.r_line, self.t_line, self.l_line = None, None, None, None + self.workspace_line = None + + self.pagesize_dict = dict() + self.pagesize_dict.update( + { + 'A0': (841, 1189), + 'A1': (594, 841), + 'A2': (420, 594), + 'A3': (297, 420), + 'A4': (210, 297), + 'A5': (148, 210), + 'A6': (105, 148), + 'A7': (74, 105), + 'A8': (52, 74), + 'A9': (37, 52), + 'A10': (26, 37), + + 'B0': (1000, 1414), + 'B1': (707, 1000), + 'B2': (500, 707), + 'B3': (353, 500), + 'B4': (250, 353), + 'B5': (176, 250), + 'B6': (125, 176), + 'B7': (88, 125), + 'B8': (62, 88), + 'B9': (44, 62), + 'B10': (31, 44), + + 'C0': (917, 1297), + 'C1': (648, 917), + 'C2': (458, 648), + 'C3': (324, 458), + 'C4': (229, 324), + 'C5': (162, 229), + 'C6': (114, 162), + 'C7': (81, 114), + 'C8': (57, 81), + 'C9': (40, 57), + 'C10': (28, 40), + + # American paper sizes + 'LETTER': (8.5*25.4, 11*25.4), + 'LEGAL': (8.5*25.4, 14*25.4), + 'ELEVENSEVENTEEN': (11*25.4, 17*25.4), + + # From https://en.wikipedia.org/wiki/Paper_size + 'JUNIOR_LEGAL': (5*25.4, 8*25.4), + 'HALF_LETTER': (5.5*25.4, 8*25.4), + 'GOV_LETTER': (8*25.4, 10.5*25.4), + 'GOV_LEGAL': (8.5*25.4, 13*25.4), + 'LEDGER': (17*25.4, 11*25.4), + } + ) + # Options self.x_margin = 15 # pixels self.y_margin = 25 # Pixels @@ -169,8 +228,8 @@ class PlotCanvasLegacy(QtCore.QObject): self.axes = self.figure.add_axes([0.05, 0.05, 0.9, 0.9], label="base", alpha=0.0) self.axes.set_aspect(1) self.axes.grid(True, color='gray') - self.axes.axhline(color=(0.70, 0.3, 0.3), linewidth=2) - self.axes.axvline(color=(0.70, 0.3, 0.3), linewidth=2) + self.h_line = self.axes.axhline(color=(0.70, 0.3, 0.3), linewidth=2) + self.v_line = self.axes.axvline(color=(0.70, 0.3, 0.3), linewidth=2) self.axes.tick_params(axis='x', color=tick_color, labelcolor=tick_color) self.axes.tick_params(axis='y', color=tick_color, labelcolor=tick_color) @@ -240,6 +299,44 @@ class PlotCanvasLegacy(QtCore.QObject): # signal if there is a doubleclick self.is_dblclk = False + # draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area + # all CNC have a limited workspace + if self.app.defaults['global_workspace'] is True: + self.draw_workspace(workspace_size=self.app.defaults["global_workspaceT"]) + + def draw_workspace(self, workspace_size): + """ + Draw a rectangular shape on canvas to specify our valid workspace. + :param workspace_size: the workspace size; tuple + :return: + """ + try: + if self.app.defaults['units'].upper() == 'MM': + dims = self.pagesize_dict[workspace_size] + else: + dims = (self.pagesize_dict[workspace_size][0]/25.4, self.pagesize_dict[workspace_size][1]/25.4) + except Exception as e: + log.debug("PlotCanvasLegacy.draw_workspace() --> %s" % str(e)) + return + + if self.app.defaults['global_workspace_orientation'] == 'l': + dims = (dims[1], dims[0]) + + xdata = [0, dims[0], dims[0], 0, 0] + ydata = [0, 0, dims[1], dims[1], 0] + + if self.workspace_line not in self.axes.lines: + self.workspace_line = Line2D(xdata=xdata, ydata=ydata, linewidth=2, antialiased=True, color='#b34d4d') + self.axes.add_line(self.workspace_line) + self.canvas.draw() + + def delete_workspace(self): + try: + self.axes.lines.remove(self.workspace_line) + self.canvas.draw() + except Exception: + pass + def graph_event_connect(self, event_name, callback): """ Attach an event handler to the canvas through the Matplotlib interface.