Draft: Draft-to-Drawing command now works on groups
This commit is contained in:
parent
a39397cf89
commit
61837b6ef8
|
@ -1447,75 +1447,77 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif getType(obj) == "Dimension":
|
elif getType(obj) == "Dimension":
|
||||||
p1,p2,p3,p4,tbase,norm,rot = obj.ViewObject.Proxy.calcGeom(obj)
|
svg = ""
|
||||||
dimText = getParam("dimPrecision")
|
if obj.ViewObject.Proxy:
|
||||||
dimText = "%."+str(dimText)+"f"
|
p1,p2,p3,p4,tbase,norm,rot = obj.ViewObject.Proxy.calcGeom(obj)
|
||||||
p1 = getProj(p1)
|
dimText = getParam("dimPrecision")
|
||||||
p2 = getProj(p2)
|
dimText = "%."+str(dimText)+"f"
|
||||||
p3 = getProj(p3)
|
p1 = getProj(p1)
|
||||||
p4 = getProj(p4)
|
p2 = getProj(p2)
|
||||||
tbase = getProj(tbase)
|
p3 = getProj(p3)
|
||||||
svg = '<g id="'+obj.Name+'"><path '
|
p4 = getProj(p4)
|
||||||
if obj.ViewObject.DisplayMode == "2D":
|
tbase = getProj(tbase)
|
||||||
m = FreeCAD.Placement()
|
svg = '<g id="'+obj.Name+'"><path '
|
||||||
m.Rotation.Q = rot
|
if obj.ViewObject.DisplayMode == "2D":
|
||||||
m = m.toMatrix()
|
m = FreeCAD.Placement()
|
||||||
if plane:
|
m.Rotation.Q = rot
|
||||||
vtext = m.multiply(plane.u)
|
m = m.toMatrix()
|
||||||
|
if plane:
|
||||||
|
vtext = m.multiply(plane.u)
|
||||||
|
else:
|
||||||
|
vtext = m.multiply(Vector(1,0,0))
|
||||||
|
angle = -DraftVecUtils.angle(vtext)
|
||||||
|
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
|
||||||
|
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
|
||||||
|
svg += 'L '+str(p3.x)+' '+str(p3.y)+' '
|
||||||
|
svg += 'L '+str(p4.x)+' '+str(p4.y)+'" '
|
||||||
else:
|
else:
|
||||||
vtext = m.multiply(Vector(1,0,0))
|
ts = (len(dimText)*obj.ViewObject.FontSize)/4
|
||||||
angle = -DraftVecUtils.angle(vtext)
|
rm = ((p3.sub(p2)).Length/2)-ts
|
||||||
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
|
p2a = getProj(p2.add(DraftVecUtils.scaleTo(p3.sub(p2),rm)))
|
||||||
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
|
p2b = getProj(p3.add(DraftVecUtils.scaleTo(p2.sub(p3),rm)))
|
||||||
svg += 'L '+str(p3.x)+' '+str(p3.y)+' '
|
angle = 0
|
||||||
svg += 'L '+str(p4.x)+' '+str(p4.y)+'" '
|
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
|
||||||
else:
|
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
|
||||||
ts = (len(dimText)*obj.ViewObject.FontSize)/4
|
svg += 'L '+str(p2a.x)+' '+str(p2a.y)+' '
|
||||||
rm = ((p3.sub(p2)).Length/2)-ts
|
svg += 'M '+str(p2b.x)+' '+str(p2b.y)+' '
|
||||||
p2a = getProj(p2.add(DraftVecUtils.scaleTo(p3.sub(p2),rm)))
|
svg += 'L '+str(p3.x)+' '+str(p3.y)+' '
|
||||||
p2b = getProj(p3.add(DraftVecUtils.scaleTo(p2.sub(p3),rm)))
|
svg += 'L '+str(p4.x)+' '+str(p4.y)+'" '
|
||||||
angle = 0
|
svg += 'fill="none" stroke="'
|
||||||
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
|
svg += getrgb(obj.ViewObject.LineColor) + '" '
|
||||||
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
|
svg += 'stroke-width="' + str(linewidth) + ' px" '
|
||||||
svg += 'L '+str(p2a.x)+' '+str(p2a.y)+' '
|
svg += 'style="stroke-width:'+ str(linewidth)
|
||||||
svg += 'M '+str(p2b.x)+' '+str(p2b.y)+' '
|
svg += ';stroke-miterlimit:4;stroke-dasharray:none" '
|
||||||
svg += 'L '+str(p3.x)+' '+str(p3.y)+' '
|
svg += 'freecad:basepoint1="'+str(p1.x)+' '+str(p1.y)+'" '
|
||||||
svg += 'L '+str(p4.x)+' '+str(p4.y)+'" '
|
svg += 'freecad:basepoint2="'+str(p4.x)+' '+str(p4.y)+'" '
|
||||||
svg += 'fill="none" stroke="'
|
svg += 'freecad:dimpoint="'+str(p2.x)+' '+str(p2.y)+'"'
|
||||||
svg += getrgb(obj.ViewObject.LineColor) + '" '
|
svg += '/>\n'
|
||||||
svg += 'stroke-width="' + str(linewidth) + ' px" '
|
svg += '<circle cx="'+str(p2.x)+'" cy="'+str(p2.y)
|
||||||
svg += 'style="stroke-width:'+ str(linewidth)
|
svg += '" r="'+str(fontsize/pointratio)+'" '
|
||||||
svg += ';stroke-miterlimit:4;stroke-dasharray:none" '
|
svg += 'fill="'+ getrgb(obj.ViewObject.LineColor) +'" stroke="none" '
|
||||||
svg += 'freecad:basepoint1="'+str(p1.x)+' '+str(p1.y)+'" '
|
svg += 'style="stroke-miterlimit:4;stroke-dasharray:none" '
|
||||||
svg += 'freecad:basepoint2="'+str(p4.x)+' '+str(p4.y)+'" '
|
svg += 'freecad:skip="1"'
|
||||||
svg += 'freecad:dimpoint="'+str(p2.x)+' '+str(p2.y)+'"'
|
svg += '/>\n'
|
||||||
svg += '/>\n'
|
svg += '<circle cx="'+str(p3.x)+'" cy="'+str(p3.y)
|
||||||
svg += '<circle cx="'+str(p2.x)+'" cy="'+str(p2.y)
|
svg += '" r="'+str(fontsize/pointratio)+'" '
|
||||||
svg += '" r="'+str(fontsize/pointratio)+'" '
|
svg += 'fill="#000000" stroke="none" '
|
||||||
svg += 'fill="'+ getrgb(obj.ViewObject.LineColor) +'" stroke="none" '
|
svg += 'style="stroke-miterlimit:4;stroke-dasharray:none" '
|
||||||
svg += 'style="stroke-miterlimit:4;stroke-dasharray:none" '
|
svg += 'freecad:skip="1"'
|
||||||
svg += 'freecad:skip="1"'
|
svg += '/>\n'
|
||||||
svg += '/>\n'
|
svg += '<text id="' + obj.Name + '" fill="'
|
||||||
svg += '<circle cx="'+str(p3.x)+'" cy="'+str(p3.y)
|
svg += getrgb(obj.ViewObject.LineColor) +'" font-size="'
|
||||||
svg += '" r="'+str(fontsize/pointratio)+'" '
|
svg += str(fontsize)+'" '
|
||||||
svg += 'fill="#000000" stroke="none" '
|
svg += 'style="text-anchor:middle;text-align:center;'
|
||||||
svg += 'style="stroke-miterlimit:4;stroke-dasharray:none" '
|
svg += 'font-family:'+obj.ViewObject.FontName+'" '
|
||||||
svg += 'freecad:skip="1"'
|
svg += 'transform="rotate('+str(math.degrees(angle))
|
||||||
svg += '/>\n'
|
svg += ','+ str(tbase.x) + ',' + str(tbase.y) + ') '
|
||||||
svg += '<text id="' + obj.Name + '" fill="'
|
svg += 'translate(' + str(tbase.x) + ',' + str(tbase.y) + ') '
|
||||||
svg += getrgb(obj.ViewObject.LineColor) +'" font-size="'
|
#svg += 'scale('+str(tmod/2000)+',-'+str(tmod/2000)+') '
|
||||||
svg += str(fontsize)+'" '
|
svg += 'scale(1,-1) '
|
||||||
svg += 'style="text-anchor:middle;text-align:center;'
|
svg += '" freecad:skip="1"'
|
||||||
svg += 'font-family:'+obj.ViewObject.FontName+'" '
|
svg += '>\n'
|
||||||
svg += 'transform="rotate('+str(math.degrees(angle))
|
svg += dimText % p3.sub(p2).Length
|
||||||
svg += ','+ str(tbase.x) + ',' + str(tbase.y) + ') '
|
svg += '</text>\n</g>\n'
|
||||||
svg += 'translate(' + str(tbase.x) + ',' + str(tbase.y) + ') '
|
|
||||||
#svg += 'scale('+str(tmod/2000)+',-'+str(tmod/2000)+') '
|
|
||||||
svg += 'scale(1,-1) '
|
|
||||||
svg += '" freecad:skip="1"'
|
|
||||||
svg += '>\n'
|
|
||||||
svg += dimText % p3.sub(p2).Length
|
|
||||||
svg += '</text>\n</g>\n'
|
|
||||||
|
|
||||||
elif getType(obj) == "Annotation":
|
elif getType(obj) == "Annotation":
|
||||||
"returns an svg representation of a document annotation"
|
"returns an svg representation of a document annotation"
|
||||||
|
@ -1595,10 +1597,13 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
lstyle = getLineStyle(obj)
|
lstyle = getLineStyle(obj)
|
||||||
name = obj.Name
|
name = obj.Name
|
||||||
if gui:
|
if gui:
|
||||||
if obj.ViewObject.DisplayMode == "Shaded":
|
try:
|
||||||
stroke = "none"
|
if obj.ViewObject.DisplayMode == "Shaded":
|
||||||
else:
|
stroke = "none"
|
||||||
stroke = getrgb(obj.ViewObject.LineColor)
|
else:
|
||||||
|
stroke = getrgb(obj.ViewObject.LineColor)
|
||||||
|
except:
|
||||||
|
stroke = "#000000"
|
||||||
else:
|
else:
|
||||||
stroke = "#000000"
|
stroke = "#000000"
|
||||||
|
|
||||||
|
@ -3442,16 +3447,25 @@ class _DrawingView(_DraftObject):
|
||||||
|
|
||||||
def updateSVG(self, obj):
|
def updateSVG(self, obj):
|
||||||
"encapsulates a svg fragment into a transformation node"
|
"encapsulates a svg fragment into a transformation node"
|
||||||
svg = getSVG(obj.Source,obj.Scale,obj.LineWidth,obj.FontSize,obj.FillStyle,obj.Direction)
|
result = ""
|
||||||
result = ''
|
if hasattr(obj,"Source"):
|
||||||
result += '<g id="' + obj.Name + '"'
|
if obj.Source:
|
||||||
result += ' transform="'
|
if obj.Source.isDerivedFrom("App::DocumentObjectGroup"):
|
||||||
result += 'rotate('+str(obj.Rotation)+','+str(obj.X)+','+str(obj.Y)+') '
|
svg = ""
|
||||||
result += 'translate('+str(obj.X)+','+str(obj.Y)+') '
|
shapes = []
|
||||||
result += 'scale('+str(obj.Scale)+','+str(-obj.Scale)+')'
|
others = []
|
||||||
result += '">'
|
for o in obj.Source.Group:
|
||||||
result += svg
|
svg += getSVG(o,obj.Scale,obj.LineWidth,obj.FontSize,obj.FillStyle,obj.Direction)
|
||||||
result += '</g>'
|
else:
|
||||||
|
svg = getSVG(obj.Source,obj.Scale,obj.LineWidth,obj.FontSize,obj.FillStyle,obj.Direction)
|
||||||
|
result += '<g id="' + obj.Name + '"'
|
||||||
|
result += ' transform="'
|
||||||
|
result += 'rotate('+str(obj.Rotation)+','+str(obj.X)+','+str(obj.Y)+') '
|
||||||
|
result += 'translate('+str(obj.X)+','+str(obj.Y)+') '
|
||||||
|
result += 'scale('+str(obj.Scale)+','+str(-obj.Scale)+')'
|
||||||
|
result += '">'
|
||||||
|
result += svg
|
||||||
|
result += '</g>'
|
||||||
return result
|
return result
|
||||||
|
|
||||||
class _BSpline(_DraftObject):
|
class _BSpline(_DraftObject):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user