From ca3ad00da8791d7e26e89fbee4c6f381e4b9298c Mon Sep 17 00:00:00 2001 From: Sebastian Hoogen Date: Tue, 23 Dec 2014 11:43:36 +0100 Subject: [PATCH] SVG export: minor improvements and bugfixes export Names as "id" attributes and Lables to "title" elements. avoid duplicate path names in SVG export handle faces with holes in SVG export sort the edges in given wires using fixWire() --- src/Mod/Draft/Draft.py | 52 +++++++++++++++++++++++--------------- src/Mod/Draft/importSVG.py | 10 +++++--- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 75b656fa4..9b5b17533 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -1735,29 +1735,38 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct return svgpatterns()[pat][0] return '' - def getPath(edges=[],wires=[]): + def getPath(edges=[],wires=[],pathname=None): import DraftGeomUtils - svg =' 1e-6: + raise ValueError('edges not ordered') iscircle = DraftGeomUtils.geomType(e) == "Circle" isellipse = DraftGeomUtils.geomType(e) == "Ellipse" if iscircle or isellipse: + import math c = e.Curve if len(e.Vertexes) == 1 and iscircle: #complete curve svg = getCircle(e) @@ -1774,7 +1783,6 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct rx = ry = c.Radius rot = 0 else: #ellipse - import math rx = c.MajorRadius ry = c.MinorRadius rot = math.degrees(c.AngleXU * (c.Axis * \ @@ -1819,7 +1827,8 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct v = getProj(pole) svg += str(v.x) +' '+ str(v.y) + ' ' else: - print("Debug: one edge (hash ",e.hashCode(),") has been discretized with parameter 0.1") + print("Debug: one edge (hash ",e.hashCode(),\ + ") has been discretized with parameter 0.1") for linepoint in bspline.discretize(0.1)[1:]: v = getProj(linepoint) svg += 'L '+ str(v.x) +' '+ str(v.y) + ' ' @@ -1849,7 +1858,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct svg += ';fill:' + fill + '"' svg += '/>\n' return svg - + def getArrow(arrowtype,point,arrowsize,color,linewidth,angle=0): svg = "" if obj.ViewObject.ArrowType == "Circle": @@ -2121,17 +2130,20 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct if len(obj.Shape.Vertexes) > 1: wiredEdges = [] if obj.Shape.Faces: - for f in obj.Shape.Faces: - svg += getPath(wires=f.Wires) + for i,f in enumerate(obj.Shape.Faces): + svg += getPath(wires=f.Wires,pathname='%s_f%04d' % \ + (obj.Name,i)) wiredEdges.extend(f.Edges) else: - for w in obj.Shape.Wires: - svg += getPath(w.Edges) + for i,w in enumerate(obj.Shape.Wires): + svg += getPath(w.Edges,pathname='%s_w%04d' % \ + (obj.Name,i)) wiredEdges.extend(w.Edges) if len(wiredEdges) != len(obj.Shape.Edges): - for e in obj.Shape.Edges: + for i,e in enumerate(obj.Shape.Edges): if (DraftGeomUtils.findEdge(e,wiredEdges) == None): - svg += getPath([e]) + svg += getPath([e],pathname='%s_nwe%04d' % \ + (obj.Name,i)) else: # closed circle or spline if isinstance(obj.Shape.Edges[0].Curve,Part.Circle): diff --git a/src/Mod/Draft/importSVG.py b/src/Mod/Draft/importSVG.py index f9f48bd8a..986002bba 100644 --- a/src/Mod/Draft/importSVG.py +++ b/src/Mod/Draft/importSVG.py @@ -1176,13 +1176,17 @@ def export(exportList,filename): if svg_export_style == 0: # translated-style exports have the entire sketch translated to fit in the X>0, Y>0 quadrant #svg.write('\n') - svg.write('\n') + svg.write('\n'% (ob.Name,-minx,maxy)) else: # raw-style exports do not translate the sketch - svg.write('\n') + svg.write('\n' %\ + ob.Name) svg.write(Draft.getSVG(ob)) + svg.write('%s\n' % ob.Label.encode('utf8')\ + .replace('<','<').replace('>','>')) + # replace('"',\ """) svg.write('\n') - # closing svg.write('') svg.close()