Explorar el Código

- 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

Marius Stanciu hace 6 años
padre
commit
1f63a16a24
Se han modificado 4 ficheros con 86 adiciones y 139 borrados
  1. 17 12
      FlatCAMApp.py
  2. 1 0
      README.md
  3. 1 1
      flatcamGUI/FlatCAMGUI.py
  4. 67 126
      flatcamGUI/PlotCanvas.py

+ 17 - 12
FlatCAMApp.py

@@ -1799,7 +1799,7 @@ class App(QtCore.QObject):
         self.ui.menuview_toggle_grid.triggered.connect(self.on_toggle_grid)
         self.ui.menuview_toggle_grid.triggered.connect(self.on_toggle_grid)
         self.ui.menuview_toggle_grid_lines.triggered.connect(self.on_toggle_grid_lines)
         self.ui.menuview_toggle_grid_lines.triggered.connect(self.on_toggle_grid_lines)
         self.ui.menuview_toggle_axis.triggered.connect(self.on_toggle_axis)
         self.ui.menuview_toggle_axis.triggered.connect(self.on_toggle_axis)
-        self.ui.menuview_toggle_workspace.triggered.connect(self.on_workspace_menu)
+        self.ui.menuview_toggle_workspace.triggered.connect(self.on_workspace_toggle)
 
 
         self.ui.menutoolshell.triggered.connect(self.on_toggle_shell)
         self.ui.menutoolshell.triggered.connect(self.on_toggle_shell)
 
 
@@ -6669,24 +6669,29 @@ class App(QtCore.QObject):
         self.delete_selection_shape()
         self.delete_selection_shape()
 
 
     def on_workspace_modified(self):
     def on_workspace_modified(self):
-        self.save_defaults(silent=True)
-        self.plotcanvas.draw_workspace(pagesize=self.defaults['global_workspaceT'])
+        # self.save_defaults(silent=True)
+        self.defaults_read_form()
+        self.plotcanvas.draw_workspace(workspace_size=self.defaults['global_workspaceT'])
 
 
     def on_workspace(self):
     def on_workspace(self):
         self.report_usage("on_workspace()")
         self.report_usage("on_workspace()")
+        log.debug("on_workspace()")
 
 
-        if self.ui.general_defaults_form.general_gui_group.workspace_cb.isChecked():
-            self.plotcanvas.restore_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:
         else:
             self.plotcanvas.delete_workspace()
             self.plotcanvas.delete_workspace()
+        self.defaults_read_form()
+        # self.save_defaults(silent=True)
 
 
-        self.save_defaults(silent=True)
-
-    def on_workspace_menu(self):
-        if self.ui.general_defaults_form.general_gui_group.workspace_cb.isChecked():
-            self.ui.general_defaults_form.general_gui_group.workspace_cb.setChecked(False)
-        else:
-            self.ui.general_defaults_form.general_gui_group.workspace_cb.setChecked(True)
+    def on_workspace_toggle(self):
+        state = False if self.ui.general_defaults_form.general_gui_group.workspace_cb.get_value() else True
+        try:
+            self.ui.general_defaults_form.general_gui_group.workspace_cb.stateChanged.disconnect(self.on_workspace)
+        except TypeError:
+            pass
+        self.ui.general_defaults_form.general_gui_group.workspace_cb.set_value(state)
+        self.ui.general_defaults_form.general_gui_group.workspace_cb.stateChanged.connect(self.on_workspace)
         self.on_workspace()
         self.on_workspace()
 
 
     def on_layout(self, index=None, lay=None):
     def on_layout(self, index=None, lay=None):

+ 1 - 0
README.md

@@ -13,6 +13,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
 - 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
 - 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
 
 
 26.11.2019
 26.11.2019
 
 

+ 1 - 1
flatcamGUI/FlatCAMGUI.py

@@ -2481,7 +2481,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
 
 
                 # Toggle Workspace
                 # Toggle Workspace
                 if key == QtCore.Qt.Key_W:
                 if key == QtCore.Qt.Key_W:
-                    self.app.on_workspace_menu()
+                    self.app.on_workspace_toggle()
                     return
                     return
 
 
                 # Skew on X axis
                 # Skew on X axis

+ 67 - 126
flatcamGUI/PlotCanvas.py

@@ -57,108 +57,11 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
 
 
         # workspace lines; I didn't use the rectangle because I didn't want to add another VisPy Node,
         # workspace lines; I didn't use the rectangle because I didn't want to add another VisPy Node,
         # which might decrease performance
         # which might decrease performance
-        self.b_line, self.r_line, self.t_line, self.l_line = None, None, None, None
+        # self.b_line, self.r_line, self.t_line, self.l_line = None, None, None, None
+        self.workspace_line = None
 
 
-        # <VisPyCanvas>
-        self.create_native()
-        self.native.setParent(self.fcapp.ui)
-
-        # <QtCore.QObject>
-        self.container.addWidget(self.native)
-
-        # ## AXIS # ##
-        self.v_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 1.0), vertical=True,
-                                   parent=self.view.scene)
-
-        self.h_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 1.0), 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
-
-        self.draw_workspace(pagesize=self.fcapp.defaults["global_workspaceT"])
-
-        self.line_parent = None
-        self.cursor_v_line = InfiniteLine(pos=None, color=self.line_color, vertical=True,
-                                          parent=self.line_parent)
-
-        self.cursor_h_line = InfiniteLine(pos=None, color=self.line_color, vertical=False,
-                                          parent=self.line_parent)
-
-        # if self.app.defaults['global_workspace'] is True:
-        #     if self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper() == 'MM':
-        #         self.wkspace_t = Line(pos=)
-
-        self.shape_collections = []
-
-        self.shape_collection = self.new_shape_collection()
-        self.fcapp.pool_recreated.connect(self.on_pool_recreated)
-        self.text_collection = self.new_text_collection()
-
-        # TODO: Should be setting to show/hide CNC job annotations (global or per object)
-        self.text_collection.enabled = True
-
-        self.c = None
-        self.big_cursor = None
-        # Keep VisPy canvas happy by letting it be "frozen" again.
-        self.freeze()
-
-        self.graph_event_connect('mouse_wheel', self.on_mouse_scroll)
-
-    # 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
-    # def draw_workspace(self):
-    #     a = np.empty((0, 0))
-    #
-    #     a4p_in = np.array([(0, 0), (8.3, 0), (8.3, 11.7), (0, 11.7)])
-    #     a4l_in = np.array([(0, 0), (11.7, 0), (11.7, 8.3), (0, 8.3)])
-    #     a3p_in = np.array([(0, 0), (11.7, 0), (11.7, 16.5), (0, 16.5)])
-    #     a3l_in = np.array([(0, 0), (16.5, 0), (16.5, 11.7), (0, 11.7)])
-    #
-    #     a4p_mm = np.array([(0, 0), (210, 0), (210, 297), (0, 297)])
-    #     a4l_mm = np.array([(0, 0), (297, 0), (297, 210), (0, 210)])
-    #     a3p_mm = np.array([(0, 0), (297, 0), (297, 420), (0, 420)])
-    #     a3l_mm = np.array([(0, 0), (420, 0), (420, 297), (0, 297)])
-    #
-    #     if self.fcapp.defaults['units'].upper() == 'MM':
-    #         if self.fcapp.defaults['global_workspaceT'] == 'A4P':
-    #             a = a4p_mm
-    #         elif self.fcapp.defaults['global_workspaceT'] == 'A4L':
-    #             a = a4l_mm
-    #         elif self.fcapp.defaults['global_workspaceT'] == 'A3P':
-    #             a = a3p_mm
-    #         elif self.fcapp.defaults['global_workspaceT'] == 'A3L':
-    #             a = a3l_mm
-    #     else:
-    #         if self.fcapp.defaults['global_workspaceT'] == 'A4P':
-    #             a = a4p_in
-    #         elif self.fcapp.defaults['global_workspaceT'] == 'A4L':
-    #             a = a4l_in
-    #         elif self.fcapp.defaults['global_workspaceT'] == 'A3P':
-    #             a = a3p_in
-    #         elif self.fcapp.defaults['global_workspaceT'] == 'A3L':
-    #             a = a3l_in
-    #
-    #     self.delete_workspace()
-    #
-    #     self.b_line = Line(pos=a[0:2], color=(0.70, 0.3, 0.3, 1.0),
-    #                        antialias=True, method='agg', parent=self.view.scene)
-    #     self.r_line = Line(pos=a[1:3], color=(0.70, 0.3, 0.3, 1.0),
-    #                        antialias=True, method='agg', parent=self.view.scene)
-    #
-    #     self.t_line = Line(pos=a[2:4], color=(0.70, 0.3, 0.3, 1.0),
-    #                        antialias=True, method='agg', parent=self.view.scene)
-    #     self.l_line = Line(pos=np.array((a[0], a[3])), color=(0.70, 0.3, 0.3, 1.0),
-    #                        antialias=True, method='agg', parent=self.view.scene)
-    #
-    #     if self.fcapp.defaults['global_workspace'] is False:
-    #         self.delete_workspace()
-
-    # delete the workspace lines from the plot by removing the parent
-
-    def draw_workspace(self, pagesize):
-        pagesize_dict = dict()
-        pagesize_dict.update(
+        self.pagesize_dict = dict()
+        self.pagesize_dict.update(
             {
             {
                 'A0': (841, 1189),
                 'A0': (841, 1189),
                 'A1': (594, 841),
                 'A1': (594, 841),
@@ -210,11 +113,64 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
             }
             }
         )
         )
 
 
+        # <VisPyCanvas>
+        self.create_native()
+        self.native.setParent(self.fcapp.ui)
+
+        # <QtCore.QObject>
+        self.container.addWidget(self.native)
+
+        # ## AXIS # ##
+        self.v_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 1.0), vertical=True,
+                                   parent=self.view.scene)
+
+        self.h_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 1.0), 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"])
+
+        self.line_parent = None
+        self.cursor_v_line = InfiniteLine(pos=None, color=self.line_color, vertical=True,
+                                          parent=self.line_parent)
+
+        self.cursor_h_line = InfiniteLine(pos=None, color=self.line_color, vertical=False,
+                                          parent=self.line_parent)
+
+        # if self.app.defaults['global_workspace'] is True:
+        #     if self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper() == 'MM':
+        #         self.wkspace_t = Line(pos=)
+
+        self.shape_collections = []
+
+        self.shape_collection = self.new_shape_collection()
+        self.fcapp.pool_recreated.connect(self.on_pool_recreated)
+        self.text_collection = self.new_text_collection()
+
+        # TODO: Should be setting to show/hide CNC job annotations (global or per object)
+        self.text_collection.enabled = True
+
+        self.c = None
+        self.big_cursor = None
+        # Keep VisPy canvas happy by letting it be "frozen" again.
+        self.freeze()
+
+        self.graph_event_connect('mouse_wheel', self.on_mouse_scroll)
+
+    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:
         try:
             if self.fcapp.defaults['units'].upper() == 'MM':
             if self.fcapp.defaults['units'].upper() == 'MM':
-                dims = pagesize_dict[pagesize]
+                dims = self.pagesize_dict[workspace_size]
             else:
             else:
-                dims = (pagesize_dict[pagesize][0]/25.4, pagesize_dict[pagesize][1]/25.4)
+                dims = (self.pagesize_dict[workspace_size][0]/25.4, self.pagesize_dict[workspace_size][1]/25.4)
         except Exception as e:
         except Exception as e:
             log.debug("PlotCanvas.draw_workspace() --> %s" % str(e))
             log.debug("PlotCanvas.draw_workspace() --> %s" % str(e))
             return
             return
@@ -224,37 +180,22 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
 
 
         a = np.array([(0, 0), (dims[0], 0), (dims[0], dims[1]), (0, dims[1])])
         a = np.array([(0, 0), (dims[0], 0), (dims[0], dims[1]), (0, dims[1])])
 
 
-        self.delete_workspace()
-
-        self.b_line = Line(pos=a[0:2], color=(0.70, 0.3, 0.3, 1.0),
-                           antialias=True, method='agg', parent=self.view.scene)
-        self.r_line = Line(pos=a[1:3], color=(0.70, 0.3, 0.3, 1.0),
-                           antialias=True, method='agg', parent=self.view.scene)
-
-        self.t_line = Line(pos=a[2:4], color=(0.70, 0.3, 0.3, 1.0),
-                           antialias=True, method='agg', parent=self.view.scene)
-        self.l_line = Line(pos=np.array((a[0], a[3])), color=(0.70, 0.3, 0.3, 1.0),
-                           antialias=True, method='agg', parent=self.view.scene)
-
-        if self.fcapp.defaults['global_workspace'] is False:
-            self.delete_workspace()
+        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),
+                                       antialias=True, method='agg', parent=self.view.scene)
+        else:
+            self.workspace_line.parent = self.view.scene
 
 
     def delete_workspace(self):
     def delete_workspace(self):
         try:
         try:
-            self.b_line.parent = None
-            self.r_line.parent = None
-            self.t_line.parent = None
-            self.l_line.parent = None
+            self.workspace_line.parent = None
         except Exception:
         except Exception:
             pass
             pass
 
 
-    # redraw the workspace lines on the plot by readding them to the parent view.scene
+    # redraw the workspace lines on the plot by re adding them to the parent view.scene
     def restore_workspace(self):
     def restore_workspace(self):
         try:
         try:
-            self.b_line.parent = self.view.scene
-            self.r_line.parent = self.view.scene
-            self.t_line.parent = self.view.scene
-            self.l_line.parent = self.view.scene
+            self.workspace_line.parent = self.view.scene
         except Exception:
         except Exception:
             pass
             pass