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

- fixed the camlib.Geometry.import_svg() and camlib.Gerber.bounds() to work when importing SVG files as Gerber

Marius Stanciu 6 лет назад
Родитель
Сommit
4bbdeaf844
2 измененных файлов с 13 добавлено и 12 удалено
  1. 1 1
      README.md
  2. 12 11
      camlib.py

+ 1 - 1
README.md

@@ -17,7 +17,7 @@ CAD program, and create G-Code for Isolation routing.
 - modified the calling of the editor2object() slot function to fix an issue with updating geometry imported from SVG file, after edit
 - modified the calling of the editor2object() slot function to fix an issue with updating geometry imported from SVG file, after edit
 - working on Gerber Editor - added the key shortcuts: wip
 - working on Gerber Editor - added the key shortcuts: wip
 - made saving of the project file non-blocking and also while saving the project file, if the user tries again to close the app while project file is being saved, the app will close only after saving is complete (the project file size is non zero)
 - made saving of the project file non-blocking and also while saving the project file, if the user tries again to close the app while project file is being saved, the app will close only after saving is complete (the project file size is non zero)
-- fixed the quit action when denying the save, to save the default values and the QSettings
+- fixed the camlib.Geometry.import_svg() and camlib.Gerber.bounds() to work when importing SVG files as Gerber
 
 
 31.03.2019
 31.03.2019
 
 

+ 12 - 11
camlib.py

@@ -621,7 +621,6 @@ class Geometry(object):
 
 
         # flatten the self.solid_geometry list for import_svg() to import SVG as Gerber
         # flatten the self.solid_geometry list for import_svg() to import SVG as Gerber
         self.solid_geometry = list(self.flatten_list(self.solid_geometry))
         self.solid_geometry = list(self.flatten_list(self.solid_geometry))
-        #self.solid_geometry = cascaded_union(self.solid_geometry)
 
 
         geos_text = getsvgtext(svg_root, object_type, units=units)
         geos_text = getsvgtext(svg_root, object_type, units=units)
         if geos_text is not None:
         if geos_text is not None:
@@ -632,7 +631,8 @@ class Geometry(object):
                     _, minimy, _, maximy = i.bounds
                     _, minimy, _, maximy = i.bounds
                     h2 = (maximy - minimy) * 0.5
                     h2 = (maximy - minimy) * 0.5
                     geos_text_f.append(translate(scale(i, 1.0, -1.0, origin=(0, 0)), yoff=(h + h2)))
                     geos_text_f.append(translate(scale(i, 1.0, -1.0, origin=(0, 0)), yoff=(h + h2)))
-            self.solid_geometry = [self.solid_geometry, geos_text_f]
+            if geos_text_f:
+                self.solid_geometry = self.solid_geometry + geos_text_f
 
 
     def import_dxf(self, filename, object_type=None, units='MM'):
     def import_dxf(self, filename, object_type=None, units='MM'):
         """
         """
@@ -3246,16 +3246,17 @@ class Gerber (Geometry):
                             maxx = max(maxx, maxx_)
                             maxx = max(maxx, maxx_)
                             maxy = max(maxy, maxy_)
                             maxy = max(maxy, maxy_)
                     else:
                     else:
-                        try:
-                            minx_, miny_, maxx_, maxy_ = bounds_rec(k)
-                        except Exception as e:
-                            log.debug("camlib.Geometry.bounds() --> %s" % str(e))
-                            return
+                        if not k.is_empty:
+                            try:
+                                minx_, miny_, maxx_, maxy_ = bounds_rec(k)
+                            except Exception as e:
+                                log.debug("camlib.Gerber.bounds() --> %s" % str(e))
+                                return
 
 
-                        minx = min(minx, minx_)
-                        miny = min(miny, miny_)
-                        maxx = max(maxx, maxx_)
-                        maxy = max(maxy, maxy_)
+                            minx = min(minx, minx_)
+                            miny = min(miny, miny_)
+                            maxx = max(maxx, maxx_)
+                            maxy = max(maxy, maxy_)
                 return minx, miny, maxx, maxy
                 return minx, miny, maxx, maxy
             else:
             else:
                 # it's a Shapely object, return it's bounds
                 # it's a Shapely object, return it's bounds