From 462e3ac2ec8756b1a0d636cf4085cd0fb0b5c1fa Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Wed, 11 Sep 2019 05:19:35 +0300 Subject: [PATCH] - made faster the Gerber parser for the case of having a not valid geometry when loading a Gerber file without buffering --- README.md | 1 + camlib.py | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9717fa8a..877db7d9 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ CAD program, and create G-Code for Isolation routing. - added the Gerber code as source for the panelized object in Panelize Tool - whenever a Gerber file is deleted, the mark_shapes objects are deleted also +- made faster the Gerber parser for the case of having a not valid geometry when loading a Gerber file without buffering 10.09.2019 diff --git a/camlib.py b/camlib.py index 625167b2..97767e3f 100644 --- a/camlib.py +++ b/camlib.py @@ -3396,15 +3396,35 @@ class Gerber (Geometry): if current_polarity == 'D': self.app.inform.emit('%s' % _("Gerber processing. Applying Gerber polarity.")) - try: + if new_poly.is_valid: self.solid_geometry = self.solid_geometry.union(new_poly) - except Exception as e: - # in case in the new_poly are some self intersections try to avoid making union with them - for poly in new_poly: - try: - self.solid_geometry = self.solid_geometry.union(poly) - except: - pass + else: + # I do this so whenever the parsed geometry of the file is not valid (intersections) it is still + # loaded. Instead of applying a union I add to a list of polygons. + final_poly = [] + try: + for poly in new_poly: + final_poly.append(poly) + except TypeError: + final_poly.append(new_poly) + + try: + for poly in self.solid_geometry: + final_poly.append(poly) + except TypeError: + final_poly.append(self.solid_geometry) + + self.solid_geometry = final_poly + + # try: + # self.solid_geometry = self.solid_geometry.union(new_poly) + # except Exception as e: + # # in case in the new_poly are some self intersections try to avoid making union with them + # for poly in new_poly: + # try: + # self.solid_geometry = self.solid_geometry.union(poly) + # except: + # pass else: self.solid_geometry = self.solid_geometry.difference(new_poly) except Exception as err: