diff --git a/CHANGELOG.md b/CHANGELOG.md index 9450c7a3..21767916 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/flatcamEditors/FlatCAMGrbEditor.py b/flatcamEditors/FlatCAMGrbEditor.py index 31a1d2d6..1183f1be 100644 --- a/flatcamEditors/FlatCAMGrbEditor.py +++ b/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. diff --git a/flatcamGUI/FlatCAMGUI.py b/flatcamGUI/FlatCAMGUI.py index 4410b1c9..26b08692 100644 --- a/flatcamGUI/FlatCAMGUI.py +++ b/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