Просмотр исходного кода

- fixed the Export PNG function when using the 2D legacy graphic engine
- added a new capability to toggle the grid lines for both graphic engines: menu link in View and key shortcut combo ALT+G

Marius Stanciu 6 лет назад
Родитель
Сommit
168f4a7646
5 измененных файлов с 73 добавлено и 17 удалено
  1. 44 7
      FlatCAMApp.py
  2. 9 4
      FlatCAMObj.py
  3. 6 0
      README.md
  4. 10 3
      flatcamGUI/FlatCAMGUI.py
  5. 4 3
      flatcamGUI/VisPyCanvas.py

+ 44 - 7
FlatCAMApp.py

@@ -33,6 +33,8 @@ from multiprocessing import Pool, cpu_count
 import socket
 from array import array
 
+import vispy.scene as scene
+
 # #######################################
 # #      Imports part of FlatCAM       ##
 # #######################################
@@ -1866,6 +1868,7 @@ class App(QtCore.QObject):
         self.ui.menuview_toggle_notebook.triggered.connect(self.on_toggle_notebook)
         self.ui.menu_toggle_nb.triggered.connect(self.on_toggle_notebook)
         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_axis.triggered.connect(self.on_toggle_axis)
         self.ui.menuview_toggle_workspace.triggered.connect(self.on_workspace_menu)
 
@@ -2515,6 +2518,9 @@ class App(QtCore.QObject):
         # Variable to hold the status of the axis
         self.toggle_axis = True
 
+        # Variable to hold the status of the grid lines
+        self.toggle_grid_lines = True
+
         # Variable to store the status of the fullscreen event
         self.toggle_fscreen = False
 
@@ -5934,6 +5940,32 @@ class App(QtCore.QObject):
 
         self.ui.grid_snap_btn.trigger()
 
+    def on_toggle_grid_lines(self):
+        self.report_usage("on_toggle_grd_lines()")
+
+        if self.toggle_grid_lines is False:
+            if self.is_legacy is False:
+                self.plotcanvas.grid._grid_color_fn['color'] = Color('dimgray').rgba
+
+            else:
+                self.plotcanvas.axes.grid(True)
+                try:
+                    self.plotcanvas.canvas.draw()
+                except IndexError:
+                    pass
+                pass
+            self.toggle_grid_lines = True
+        else:
+            if self.is_legacy is False:
+                self.plotcanvas.grid._grid_color_fn['color'] = Color('#FFFFFFFF').rgba
+            else:
+                self.plotcanvas.axes.grid(False)
+                try:
+                    self.plotcanvas.canvas.draw()
+                except IndexError:
+                    pass
+            self.toggle_grid_lines = False
+
     def on_options_combo_change(self, sel):
         """
         Called when the combo box to choose between application defaults and
@@ -8899,12 +8931,13 @@ class App(QtCore.QObject):
         self.date = ''.join(c for c in self.date if c not in ':-')
         self.date = self.date.replace(' ', '_')
 
-        image = _screenshot()
-        data = np.asarray(image)
-        if not data.ndim == 3 and data.shape[-1] in (3, 4):
-            self.inform.emit('[[WARNING_NOTCL]] %s' %
-                             _('Data must be a 3D array with last dimension 3 or 4'))
-            return
+        if self.is_legacy is False:
+            image = _screenshot()
+            data = np.asarray(image)
+            if not data.ndim == 3 and data.shape[-1] in (3, 4):
+                self.inform.emit('[[WARNING_NOTCL]] %s' %
+                                 _('Data must be a 3D array with last dimension 3 or 4'))
+                return
 
         filter_ = "PNG File (*.png);;All Files (*.*)"
         try:
@@ -8921,7 +8954,11 @@ class App(QtCore.QObject):
             self.inform.emit(_("Export PNG cancelled."))
             return
         else:
-            write_png(filename, data)
+            if self.is_legacy is False:
+                write_png(filename, data)
+            else:
+                self.plotcanvas.figure.savefig(filename)
+
             if self.defaults["global_open_style"] is False:
                 self.file_opened.emit("png", filename)
             self.file_saved.emit("png", filename)

+ 9 - 4
FlatCAMObj.py

@@ -2041,6 +2041,11 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
         :return: None
         """
 
+        try:
+            decimals_exc = self.decimals
+        except AttributeError:
+            decimals_exc = 4
+
         # flag to signal that we need to reorder the tools dictionary and drills and slots lists
         flag_order = False
 
@@ -2067,7 +2072,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
                         exc.app.log.warning("Failed to copy option.", option)
 
             for drill in exc.drills:
-                exc_tool_dia = float('%.*f' % (self.decimals, exc.tools[drill['tool']]['C']))
+                exc_tool_dia = float('%.*f' % (decimals_exc, exc.tools[drill['tool']]['C']))
 
                 if exc_tool_dia not in custom_dict_drills:
                     custom_dict_drills[exc_tool_dia] = [drill['point']]
@@ -2075,7 +2080,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
                     custom_dict_drills[exc_tool_dia].append(drill['point'])
 
             for slot in exc.slots:
-                exc_tool_dia = float('%.*f' % (self.decimals, exc.tools[slot['tool']]['C']))
+                exc_tool_dia = float('%.*f' % (decimals_exc, exc.tools[slot['tool']]['C']))
 
                 if exc_tool_dia not in custom_dict_slots:
                     custom_dict_slots[exc_tool_dia] = [[slot['start'], slot['stop']]]
@@ -2168,7 +2173,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
                 temp_tools[tool_name_temp] = spec_temp
 
                 for drill in exc_final.drills:
-                    exc_tool_dia = float('%.*f' % (self.decimals, exc_final.tools[drill['tool']]['C']))
+                    exc_tool_dia = float('%.*f' % (decimals_exc, exc_final.tools[drill['tool']]['C']))
                     if exc_tool_dia == ordered_dia:
                         temp_drills.append(
                             {
@@ -2178,7 +2183,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
                         )
 
                 for slot in exc_final.slots:
-                    slot_tool_dia = float('%.*f' % (self.decimals, exc_final.tools[slot['tool']]['C']))
+                    slot_tool_dia = float('%.*f' % (decimals_exc, exc_final.tools[slot['tool']]['C']))
                     if slot_tool_dia == ordered_dia:
                         temp_slots.append(
                             {

+ 6 - 0
README.md

@@ -9,6 +9,12 @@ CAD program, and create G-Code for Isolation routing.
 
 =================================================
 
+13.10.2019
+
+- fixed a bug in the Merge functions
+- fixed the Export PNG function when using the 2D legacy graphic engine
+- added a new capability to toggle the grid lines for both graphic engines: menu link in View and key shortcut combo ALT+G
+
 12.10.2019
 
 - fixed the Gerber Parser convert units unnecessary usage. The only units conversion should be done when creating the new object, after the parsing

+ 10 - 3
flatcamGUI/FlatCAMGUI.py

@@ -393,7 +393,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
         self.menuview.addSeparator()
 
         self.menuview_toggle_code_editor = self.menuview.addAction(QtGui.QIcon('share/code_editor32.png'),
-                                                                   _('Toggle Code Editor\tCTRL+E'))
+                                                                   _('Toggle Code Editor\tSHIFT+E'))
         self.menuview.addSeparator()
         self.menuview_toggle_fscreen = self.menuview.addAction(
             QtGui.QIcon('share/fscreen32.png'), _("&Toggle FullScreen\tALT+F10"))
@@ -403,8 +403,10 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
             QtGui.QIcon('share/notebook32.png'), _("&Toggle Project/Sel/Tool\t`"))
 
         self.menuview.addSeparator()
-        self.menuview_toggle_grid = self.menuview.addAction(QtGui.QIcon('share/grid32.png'), _("&Toggle Grid Snap\tG")
-                                                            )
+        self.menuview_toggle_grid = self.menuview.addAction(QtGui.QIcon('share/grid32.png'),
+                                                            _("&Toggle Grid Snap\tG"))
+        self.menuview_toggle_grid_lines = self.menuview.addAction(QtGui.QIcon('share/grid32.png'),
+                                                                  _("&Toggle Grid Lines\tALT+G"))
         self.menuview_toggle_axis = self.menuview.addAction(QtGui.QIcon('share/axis32.png'), _("&Toggle Axis\tSHIFT+G")
                                                             )
         self.menuview_toggle_workspace = self.menuview.addAction(QtGui.QIcon('share/workspace24.png'),
@@ -2449,6 +2451,11 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                     self.app.transform_tool.run(toggle=True)
                     return
 
+                # Toggle Grid lines
+                if key == QtCore.Qt.Key_G:
+                    self.app.on_toggle_grid_lines()
+                    return
+
                 # Solder Paste Dispensing Tool
                 if key == QtCore.Qt.Key_K:
                     self.app.paste_tool.run(toggle=True)

+ 4 - 3
flatcamGUI/VisPyCanvas.py

@@ -83,11 +83,12 @@ class VisPyCanvas(scene.SceneCanvas):
         self.xaxis.link_view(view)
         self.yaxis.link_view(view)
 
-        grid1 = scene.GridLines(parent=view.scene, color='dimgray')
-        grid1.set_gl_state(depth_test=False)
+        # grid1 = scene.GridLines(parent=view.scene, color='dimgray')
+        # grid1.set_gl_state(depth_test=False)
 
         self.view = view
-        self.grid = grid1
+        self.grid = scene.GridLines(parent=self.view.scene, color='dimgray')
+        self.grid.set_gl_state(depth_test=False)
 
         self.freeze()