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

Added some additional checks for the types when exporting, and additional comments

grbd 9 лет назад
Родитель
Сommit
10e9fa74c3
2 измененных файлов с 25 добавлено и 7 удалено
  1. 18 5
      FlatCAMApp.py
  2. 7 2
      camlib.py

+ 18 - 5
FlatCAMApp.py

@@ -1598,6 +1598,18 @@ class App(QtCore.QObject):
             msgbox.exec_()
             return
 
+        # Check for more compatible types and add as required
+        # Excellon not yet supported, there seems to be a list within the Polygon Geometry that shapely's svg export doesn't like
+
+        if (not isinstance(obj, FlatCAMGeometry) and not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMCNCjob)):
+            msg = "ERROR: Only Geometry, Gerber and CNCJob objects can be used."
+            msgbox = QtGui.QMessageBox()
+            msgbox.setInformativeText(msg)
+            msgbox.setStandardButtons(QtGui.QMessageBox.Ok)
+            msgbox.setDefaultButton(QtGui.QMessageBox.Ok)
+            msgbox.exec_()
+            return
+
         name = self.collection.get_active().options["name"]
 
         try:
@@ -1714,10 +1726,6 @@ class App(QtCore.QObject):
         except:
             return "Could not retrieve object: %s" % obj_name
 
-        # TODO needs seperate colours for CNCPath Export
-        # The line thickness is only affected by the scaling factor not the tool size
-        # Use the tool size to determine the scaling factor for line thickness
-
         with self.proc_container.new("Exporting SVG") as proc:
             exported_svg = obj.export_svg()
 
@@ -1727,12 +1735,15 @@ class App(QtCore.QObject):
             minx = obj.solid_geometry.bounds[0]
             miny = obj.solid_geometry.bounds[1] - svgheight
 
+            # Convert everything to strings for use in the xml doc
             svgwidth = str(svgwidth)
             svgheight = str(svgheight)
             minx = str(minx)
             miny = str(miny)
             uom = obj.units.lower()
-            
+
+            # Add a SVG Header and footer to the svg output from shapely
+            # The transform flips the Y Axis so that everything renders properly within svg apps such as inkscape
             svg_header = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" '
             svg_header += 'width="' + svgwidth + uom + '" '
             svg_header += 'height="' + svgheight + uom + '" '
@@ -1740,6 +1751,8 @@ class App(QtCore.QObject):
             svg_header += '<g transform="scale(1,-1)">'
             svg_footer = '</g> </svg>'
             svg_elem = svg_header + exported_svg + svg_footer
+
+            # Parse the xml through a xml parser just to add line feeds and to make it look more pretty for the output
             doc = parse_xml_string(svg_elem)
             with open(filename, 'w') as fp:
                 fp.write(doc.toprettyxml())

+ 7 - 2
camlib.py

@@ -3333,19 +3333,24 @@ class CNCjob(Geometry):
         if scale == 0:
             scale = 0.05
 
+        # Seperate the list of cuts and travels into 2 distinct lists
+        # This way we can add different formatting / colors to both
         cuts = []
         travels = []
         for g in self.gcode_parsed:
             if g['kind'][0] == 'C': cuts.append(g)
             if g['kind'][0] == 'T': travels.append(g)
 
-        # Used to determine board size
+        # Used to determine the overall board size
         self.solid_geometry = cascaded_union([geo['geom'] for geo in self.gcode_parsed])
 
-        # Seperate the travels from the cuts for laser cutting under Visicut
+        # Convert the cuts and travels into single geometry objects we can render as svg xml
         travelsgeom = cascaded_union([geo['geom'] for geo in travels])
         cutsgeom = cascaded_union([geo['geom'] for geo in cuts])
 
+        # Render the SVG Xml
+        # The scale factor affects the size of the lines, and the stroke color adds different formatting for each set
+        # It's better to have the travels sitting underneath the cuts for visicut
         svg_elem = travelsgeom.svg(scale_factor=scale, stroke_color="#F0E24D")
         svg_elem += cutsgeom.svg(scale_factor=scale, stroke_color="#5E6CFF")