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

Fixed the scaling issues with the svg export

grbd 9 лет назад
Родитель
Сommit
17b4edb94b
1 измененных файлов с 20 добавлено и 3 удалено
  1. 20 3
      FlatCAMApp.py

+ 20 - 3
FlatCAMApp.py

@@ -1714,15 +1714,32 @@ class App(QtCore.QObject):
         except:
         except:
             return "Could not retrieve object: %s" % obj_name
             return "Could not retrieve object: %s" % obj_name
 
 
-        # TODO needs size of board determining
         # TODO needs seperate colours for CNCPath Export
         # 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:
         with self.proc_container.new("Exporting SVG") as proc:
+            exported_svg = obj.export_svg()
+
+            # Determine bounding area for svg export
+            svgwidth = obj.solid_geometry.bounds[2] - obj.solid_geometry.bounds[0]
+            svgheight = obj.solid_geometry.bounds[3] - obj.solid_geometry.bounds[1]
+            minx = obj.solid_geometry.bounds[0]
+            miny = obj.solid_geometry.bounds[1] - svgheight
+
+            svgwidth = str(svgwidth)
+            svgheight = str(svgheight)
+            minx = str(minx)
+            miny = str(miny)
+            uom = obj.units.lower()
+            
             svg_header = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" '
             svg_header = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" '
-            svg_header += 'width="50mm" height="50mm" viewBox="0 -50 50 50">'
+            svg_header += 'width="' + svgwidth + uom + '" '
+            svg_header += 'height="' + svgheight + uom + '" '
+            svg_header += 'viewBox="' + minx + ' ' + miny + ' ' + svgwidth + ' ' + svgheight + '">' 
             svg_header += '<g transform="scale(1,-1)">'
             svg_header += '<g transform="scale(1,-1)">'
             svg_footer = '</g> </svg>'
             svg_footer = '</g> </svg>'
-            svg_elem = svg_header + obj.export_svg() + svg_footer
+            svg_elem = svg_header + exported_svg + svg_footer
             doc = parse_xml_string(svg_elem)
             doc = parse_xml_string(svg_elem)
             with open(filename, 'w') as fp:
             with open(filename, 'w') as fp:
                 fp.write(doc.toprettyxml())
                 fp.write(doc.toprettyxml())