ソースを参照

- added in Gerber editor a method for zoom fit that takes into consideration the current geometry of the edited object

Marius Stanciu 5 年 前
コミット
f4617034af
3 ファイル変更38 行追加2 行削除
  1. 1 0
      CHANGELOG.md
  2. 35 0
      flatcamEditors/FlatCAMGrbEditor.py
  3. 2 2
      flatcamGUI/FlatCAMGUI.py

+ 1 - 0
CHANGELOG.md

@@ -13,6 +13,7 @@ CHANGELOG for FlatCAM beta
 - solve parenting issues when trying to load a FlatScript from Menu -> File -> Scripting
 - added a first new example script and added some files to work with
 - added a new parameter that will store the home folder of the FlatCAM installation so we can access the example folder
+- added in Gerber editor a method for zoom fit that takes into consideration the current geometry of the edited object
 
 30.04.2020 
 

+ 35 - 0
flatcamEditors/FlatCAMGrbEditor.py

@@ -12,6 +12,8 @@ from shapely.geometry import LineString, LinearRing, MultiLineString, Point, Pol
 from shapely.ops import cascaded_union
 import shapely.affinity as affinity
 
+from vispy.geometry import Rect
+
 import threading
 import time
 from copy import copy, deepcopy
@@ -4927,6 +4929,39 @@ class FlatCAMGrbEditor(QtCore.QObject):
     #     self.app.app_cursor.enabled = False
     #     self.app.app_cursor.enabled = True
 
+    def on_zoom_fit(self):
+        """
+        Callback for zoom-fit request in Gerber Editor
+
+        :return:        None
+        """
+        log.debug("FlatCAMGrbEditor.on_zoom_fit()")
+
+        # calculate all the geometry in the edited Gerber object
+        edit_geo = []
+        for ap_code in self.storage_dict:
+            for geo_el in self.storage_dict[ap_code]['geometry']:
+                actual_geo = geo_el.geo
+                if 'solid' in actual_geo:
+                    edit_geo.append(actual_geo['solid'])
+
+        all_geo = cascaded_union(edit_geo)
+
+        # calculate the bounds values for the edited Gerber object
+        xmin, ymin, xmax, ymax = all_geo.bounds
+
+        if self.app.is_legacy is False:
+            new_rect = Rect(xmin, ymin, xmax, ymax)
+            self.app.plotcanvas.fit_view(rect=new_rect)
+        else:
+            width = xmax - xmin
+            height = ymax - ymin
+            xmin -= 0.05 * width
+            xmax += 0.05 * width
+            ymin -= 0.05 * height
+            ymax += 0.05 * height
+            self.app.plotcanvas.adjust_axes(xmin, ymin, xmax, ymax)
+
     def get_selected(self):
         """
         Returns list of shapes that are selected in the editor.

+ 2 - 2
flatcamGUI/FlatCAMGUI.py

@@ -3811,10 +3811,10 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                         self.app.grb_editor.select_tool('track')
                         return
 
-                    # Zoom Fit
+                    # Zoom fit
                     if key == QtCore.Qt.Key_V or key == 'V':
                         self.app.grb_editor.launched_from_shortcuts = True
-                        self.app.on_zoom_fit(None)
+                        self.app.grb_editor.on_zoom_fit()
                         return
 
                 # Show Shortcut list