From 139baaff6468a0d85fd062c6b7d058c74ea860b4 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sun, 5 Apr 2020 21:50:32 +0300 Subject: [PATCH] - fixed issue #386 - multiple Cut operation on a edited object created a crash due of the bounds() method --- FlatCAMApp.py | 2 +- README.md | 2 ++ camlib.py | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index cc33ca1b..3d225531 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -3520,7 +3520,7 @@ class App(QtCore.QObject): # update the geo object options so it is including the bounding box values try: - xmin, ymin, xmax, ymax = edited_obj.bounds() + xmin, ymin, xmax, ymax = edited_obj.bounds(flatten=True) edited_obj.options['xmin'] = xmin edited_obj.options['ymin'] = ymin edited_obj.options['xmax'] = xmax diff --git a/README.md b/README.md index 8fe6e57d..aa96371a 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ CAD program, and create G-Code for Isolation routing. - fixed bug in Gerber parser that allowed loading as Gerber of a file that is not a Gerber - fixed a bug in extension detection for Gerber files that allowed in the filtered list files that extension *.gb* - added a processEvents method in the Gerber parser parse_lines() method +- fixed issue #386 - multiple Cut operation on a edited object created a crash due of the bounds() method + 4.04.2020 diff --git a/camlib.py b/camlib.py index 2770021c..bb192a4b 100644 --- a/camlib.py +++ b/camlib.py @@ -614,10 +614,12 @@ class Geometry(object): log.warning("Not implemented.") self.solid_geometry = cascaded_union(diffs) - def bounds(self): + def bounds(self, flatten=False): """ Returns coordinates of rectangular bounds of geometry: (xmin, ymin, xmax, ymax). + :param flatten: will flatten the solid_geometry if True + :return: """ # fixed issue of getting bounds only for one level lists of objects # now it can get bounds for nested lists of objects @@ -661,7 +663,13 @@ class Geometry(object): maxy_list = [] for tool in self.tools: - minx, miny, maxx, maxy = bounds_rec(self.tools[tool]['solid_geometry']) + working_geo = self.tools[tool]['solid_geometry'] + + if flatten: + self.flatten(geometry=working_geo, reset=True) + working_geo = self.flat_geometry + + minx, miny, maxx, maxy = bounds_rec(working_geo) minx_list.append(minx) miny_list.append(miny) maxx_list.append(maxx) @@ -669,6 +677,10 @@ class Geometry(object): return(min(minx_list), min(miny_list), max(maxx_list), max(maxy_list)) else: + if flatten: + self.flatten(reset=True) + self.solid_geometry = self.flat_geometry + bounds_coords = bounds_rec(self.solid_geometry) return bounds_coords