Fixed bug #592 - SVG export of shapes containing full circles

This commit is contained in:
Yorik van Havre 2012-02-13 13:42:48 -02:00
parent 601d292b54
commit edb20f1876

View File

@ -871,6 +871,18 @@ def offset(obj,delta,copy=False,bind=False,sym=False,occ=False):
import Part
from draftlibs import fcgeo
def getrgb(color):
"getRGB(color): returns a rgb value #000000 from a freecad color"
r = str(hex(int(color[0]*255)))[2:].zfill(2)
g = str(hex(int(color[1]*255)))[2:].zfill(2)
b = str(hex(int(color[2]*255)))[2:].zfill(2)
col = "#"+r+g+b
if col == "#ffffff":
print getParam('SvgLinesBlack')
if getParam('SvgLinesBlack'):
col = "#000000"
return col
def getRect(p,obj):
"returns length,heigh,placement"
pl = obj.Placement.copy()
@ -1024,18 +1036,6 @@ def draftify(objectslist,makeblock=False):
return newobjlist[0]
return newobjlist
def getrgb(color):
"getRGB(color): returns a rgb value #000000 from a freecad color"
r = str(hex(int(color[0]*255)))[2:].zfill(2)
g = str(hex(int(color[1]*255)))[2:].zfill(2)
b = str(hex(int(color[2]*255)))[2:].zfill(2)
col = "#"+r+g+b
if col == "#ffffff":
print getParam('SvgLinesBlack')
if getParam('SvgLinesBlack'):
col = "#000000"
return col
def getSVG(obj,modifier=100,textmodifier=100,linestyle="continuous",fillstyle="shape color",direction=None):
'''getSVG(object,[modifier],[textmodifier],[linestyle],[fillstyle],[direction]):
returns a string containing a SVG representation of the given object. the modifier attribute
@ -1082,6 +1082,10 @@ def getSVG(obj,modifier=100,textmodifier=100,linestyle="continuous",fillstyle="s
v = getProj(e.Vertexes[-1].Point)
svg += 'L '+ str(v.x) +' '+ str(v.y) + ' '
elif isinstance(e.Curve,Part.Circle):
if len(e.Vertexes) == 1:
# complete circle
svg = getCircle(e)
return svg
r = e.Curve.Radius
drawing_plane_normal = FreeCAD.DraftWorkingPlane.axis
if plane: drawing_plane_normal = plane.axis
@ -1102,6 +1106,21 @@ def getSVG(obj,modifier=100,textmodifier=100,linestyle="continuous",fillstyle="s
svg += '/>\n'
return svg
def getCircle(edge):
cen = getProj(edge.Curve.Center)
rad = edge.Curve.Radius
svg = '<circle cx="' + str(cen.x)
svg += '" cy="' + str(cen.y)
svg += '" r="' + str(rad)+'" '
svg += 'stroke="' + stroke + '" '
svg += 'stroke-width="' + str(width) + ' px" '
svg += 'style="stroke-width:'+ str(width)
svg += ';stroke-miterlimit:4'
svg += ';stroke-dasharray:' + lstyle
svg += ';fill:' + fill + '"'
svg += '/>\n'
return svg
if getType(obj) == "Dimension":
p1,p2,p3,p4,tbase,norm,rot = obj.ViewObject.Proxy.calcGeom(obj)
dimText = getParam("dimPrecision")
@ -1235,18 +1254,7 @@ def getSVG(obj,modifier=100,textmodifier=100,linestyle="continuous",fillstyle="s
if (fcgeo.findEdge(e,wiredEdges) == None):
svg += getPath([e])
else:
cen = getProj(obj.Shape.Edges[0].Curve.Center)
rad = obj.Shape.Edges[0].Curve.Radius
svg = '<circle cx="' + str(cen.x)
svg += '" cy="' + str(cen.y)
svg += '" r="' + str(rad)+'" '
svg += 'stroke="' + stroke + '" '
svg += 'stroke-width="' + str(width) + ' px" '
svg += 'style="stroke-width:'+ str(width)
svg += ';stroke-miterlimit:4'
svg += ';stroke-dasharray:' + lstyle
svg += ';fill:' + fill + '"'
svg += '/>\n'
svg = getCircle(obj.Shape.Edges[0])
return svg
def makeDrawingView(obj,page,lwmod=None,tmod=None):