本文整理汇总了Python中Drawing.projectToSVG方法的典型用法代码示例。如果您正苦于以下问题:Python Drawing.projectToSVG方法的具体用法?Python Drawing.projectToSVG怎么用?Python Drawing.projectToSVG使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drawing
的用法示例。
在下文中一共展示了Drawing.projectToSVG方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
def execute(self, obj):
if obj.Source:
if hasattr(obj.Source.Proxy,"BaseProfile"):
p = obj.Source.Proxy.BaseProfile
n = obj.Source.Proxy.ExtrusionVector
import Drawing
svg1 = ""
svg2 = ""
result = ""
svg1 = Drawing.projectToSVG(p,DraftVecUtils.neg(n))
if svg1:
w = str(obj.LineWidth/obj.Scale) #don't let linewidth be influenced by the scale...
svg1 = svg1.replace('stroke-width="0.35"','stroke-width="'+w+'"')
svg1 = svg1.replace('stroke-width="1"','stroke-width="'+w+'"')
svg1 = svg1.replace('stroke-width:0.01','stroke-width:'+w)
svg1 = svg1.replace('scale(1,-1)','scale('+str(obj.Scale)+',-'+str(obj.Scale)+')')
if obj.Source.Tag:
svg2 = '<text id="tag'+obj.Name+'"'
svg2 += ' fill="'+Draft.getrgb(obj.TextColor)+'"'
svg2 += ' font-size="'+str(obj.FontSize)+'"'
svg2 += ' style="text-anchor:start;text-align:left;'
svg2 += ' font-family:'+obj.FontName+'" '
svg2 += ' transform="translate(' + str(obj.TextX) + ',' + str(obj.TextY) + ')">'
svg2 += '<tspan>'+obj.Source.Tag+'</tspan></text>\n'
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 += '">\n '
result += svg1
result += svg2
result += '</g>'
obj.ViewResult = result
示例2: export_to_svg
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
def export_to_svg(ai_solid, ai_vector, ai_depth, ai_output_file):
""" create a SVG of a slice of FreeCAD Part Object. The generated SVG is incomplete. SVG header must be added to it to be opened by Inkscape
"""
l_slice = Part.makeCompound(ai_solid.slice(ai_vector, ai_depth)) # slice the plank in the ai_vector plan at a the height ai_depth
r_dxf = Drawing.projectToSVG(l_slice, ai_vector) # it generates a snippet of svg not directly usable by Inkscape. It needs the svg head and document markers.
#r_dxf = Drawing.projectToSVG(ai_solid, ai_vector) # works also :)
fh_output = open(ai_output_file, 'w')
fh_output.write(r_dxf)
fh_output.close()
return(1)
示例3: updateSVG
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
def updateSVG(self, obj,join=False):
"encapsulates a svg fragment into a transformation node"
import Part, DraftGeomUtils
if hasattr(obj,"Source"):
if obj.Source:
if obj.Source.Objects:
objs = Draft.getGroupContents(obj.Source.Objects)
svg = ''
# generating SVG
linewidth = obj.LineWidth/obj.Scale
if obj.RenderingMode == "Solid":
# render using the Arch Vector Renderer
import ArchVRM
render = ArchVRM.Renderer()
render.setWorkingPlane(obj.Source.Placement)
render.addObjects(Draft.getGroupContents(objs,walls=True))
render.cut(obj.Source.Shape)
svg += render.getViewSVG(linewidth=linewidth)
svg += render.getSectionSVG(linewidth=linewidth*2)
# print render.info()
else:
# render using the Drawing module
import Drawing
shapes = []
for o in objs:
if o.isDerivedFrom("Part::Feature"):
shapes.append(o.Shape)
if shapes:
base = shape.pop()
for sh in shapes:
base = base.fuse(sh)
svgf = Drawing.projectToSVG(base,DraftVecUtils.neg(direction))
if svgf:
svgf = svgf.replace('stroke-width="0.35"','stroke-width="' + str(linewidth) + 'px"')
svgf = svgf.replace('stroke-width:0.01','stroke-width:' + str(linewidth) + 'px')
svg += svgf
result = ''
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 += '">\n'
result += svg
result += '</g>\n'
# print "complete node:",result
return result
return ''
示例4: updateSVG
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
def updateSVG(self, obj, join=False):
"encapsulates a svg fragment into a transformation node"
import Part
from draftlibs import fcgeo
if hasattr(obj, "Source"):
if obj.Source:
if obj.Source.Objects:
svg = ""
# generating SVG
linewidth = obj.LineWidth / obj.Scale
if obj.RenderingMode == "Solid":
# render using the Arch Vector Renderer
import ArchVRM
render = ArchVRM.Renderer()
render.setWorkingPlane(obj.Source.Placement)
render.addObjects(obj.Source.Objects)
render.cut(obj.Source.Shape)
svg += render.getViewSVG(linewidth=linewidth)
svg += render.getSectionSVG(linewidth=linewidth * 2)
# print render.info()
else:
# render using the Drawing module
shapes = []
for o in obj.Source.Objects:
if o.isDerivedFrom("Part::Feature"):
shapes.append(o.Shape)
if shapes:
base = shape.pop()
for sh in shapes:
base = base.fuse(sh)
svgf = Drawing.projectToSVG(base, fcvec.neg(direction))
if svgf:
svgf = svgf.replace('stroke-width="0.35"', 'stroke-width="' + str(linewidth) + 'px"')
svg += svgf
result = ""
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 += '">\n'
result += svg
result += "</g>\n"
# print "complete node:",result
return result
return ""
示例5: getSVG
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
def getSVG(shape, opts=None, view_vector=(-1.75, 1.1, 5.0)):
"""
Export a shape to SVG
"""
d = {'width':800,'height':240,'marginLeft':200,'marginTop':20}
if opts:
d.update(opts)
#need to guess the scale and the coordinate center
uom = guessUnitOfMeasure(shape)
width=float(d['width'])
height=float(d['height'])
marginLeft=float(d['marginLeft'])
marginTop=float(d['marginTop'])
#TODO: provide option to give 3 views
viewVector = FreeCAD.Base.Vector(view_vector)
(visibleG0,visibleG1,hiddenG0,hiddenG1) = Drawing.project(shape,viewVector)
(hiddenPaths,visiblePaths) = getPaths(Drawing.projectToSVG(shape,viewVector,"ShowHiddenLines")) #this param is totally undocumented!
#get bounding box -- these are all in 2-d space
bb = visibleG0.BoundBox
bb.add(visibleG1.BoundBox)
bb.add(hiddenG0.BoundBox)
bb.add(hiddenG1.BoundBox)
#width pixels for x, height pixesl for y
unitScale = min( width / bb.XLength * 0.75 , height / bb.YLength * 0.75 )
#compute amount to translate-- move the top left into view
(xTranslate,yTranslate) = ( (0 - bb.XMin) + marginLeft/unitScale ,(0- bb.YMax) - marginTop/unitScale)
#compute paths ( again -- had to strip out freecad crap )
hiddenContent = ""
for p in hiddenPaths:
hiddenContent += PATHTEMPLATE % p
visibleContent = ""
for p in visiblePaths:
visibleContent += PATHTEMPLATE % p
svg = SVG_TEMPLATE % (
{
'unitScale': str(unitScale),
'strokeWidth': str(1.0 / unitScale),
'hiddenContent': hiddenContent ,
'visibleContent': visibleContent,
'xTranslate': str(xTranslate),
'yTranslate': str(yTranslate),
'width': str(width),
'height': str(height),
'textboxY': str(height - 30),
'uom': str(uom)
}
)
#svg = SVG_TEMPLATE % (
# {"content": projectedContent}
#)
return svg
示例6: onChanged
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
def onChanged(self, obj, prop):
if prop in ["Source","RenderingMode","ShowCut"]:
import Part, DraftGeomUtils
if hasattr(obj,"Source"):
if obj.Source:
if obj.Source.Objects:
objs = Draft.getGroupContents(obj.Source.Objects,walls=True)
objs = Draft.removeHidden(objs)
# separate spaces
self.spaces = []
os = []
for o in objs:
if Draft.getType(o) == "Space":
self.spaces.append(o)
else:
os.append(o)
objs = os
self.svg = ''
fillpattern = '<pattern id="sectionfill" patternUnits="userSpaceOnUse" patternTransform="matrix(5,0,0,5,0,0)"'
fillpattern += ' x="0" y="0" width="10" height="10">'
fillpattern += '<g>'
fillpattern += '<rect width="10" height="10" style="stroke:none; fill:#ffffff" /><path style="stroke:#000000; stroke-width:1" d="M0,0 l10,10" /></g></pattern>'
# generating SVG
if obj.RenderingMode == "Solid":
# render using the Arch Vector Renderer
import ArchVRM, WorkingPlane
wp = WorkingPlane.plane()
wp.setFromPlacement(obj.Source.Placement)
wp.inverse()
render = ArchVRM.Renderer()
render.setWorkingPlane(wp)
render.addObjects(objs)
if hasattr(obj,"ShowCut"):
render.cut(obj.Source.Shape,obj.ShowCut)
else:
render.cut(obj.Source.Shape)
self.svg += render.getViewSVG(linewidth="LWPlaceholder")
self.svg += fillpattern
self.svg += render.getSectionSVG(linewidth="SWPlaceholder",fillpattern="sectionfill")
if hasattr(obj,"ShowCut"):
if obj.ShowCut:
self.svg += render.getHiddenSVG(linewidth="LWPlaceholder")
# print render.info()
else:
# render using the Drawing module
import Drawing, Part
shapes = []
hshapes = []
sshapes = []
p = FreeCAD.Placement(obj.Source.Placement)
self.direction = p.Rotation.multVec(FreeCAD.Vector(0,0,1))
for o in objs:
if o.isDerivedFrom("Part::Feature"):
if o.Shape.isNull():
pass
#FreeCAD.Console.PrintWarning(translate("Arch","Skipping empty object: ")+o.Name)
elif o.Shape.isValid():
if hasattr(obj.Source,"OnlySolids"):
if obj.Source.OnlySolids:
shapes.extend(o.Shape.Solids)
else:
shapes.append(o.Shape)
else:
shapes.extend(o.Shape.Solids)
else:
FreeCAD.Console.PrintWarning(translate("Arch","Skipping invalid object: ")+o.Name)
cutface,cutvolume,invcutvolume = ArchCommands.getCutVolume(obj.Source.Shape.copy(),shapes)
if cutvolume:
nsh = []
for sh in shapes:
for sol in sh.Solids:
if sol.Volume < 0:
sol.reverse()
c = sol.cut(cutvolume)
s = sol.section(cutface)
try:
wires = DraftGeomUtils.findWires(s.Edges)
for w in wires:
f = Part.Face(w)
sshapes.append(f)
#s = Part.Wire(s.Edges)
#s = Part.Face(s)
except Part.OCCError:
#print "ArchDrawingView: unable to get a face"
sshapes.append(s)
nsh.extend(c.Solids)
#sshapes.append(s)
if hasattr(obj,"ShowCut"):
if obj.ShowCut:
c = sol.cut(invcutvolume)
hshapes.append(c)
shapes = nsh
if shapes:
self.shapes = shapes
self.baseshape = Part.makeCompound(shapes)
svgf = Drawing.projectToSVG(self.baseshape,self.direction)
if svgf:
svgf = svgf.replace('stroke-width="0.35"','stroke-width="LWPlaceholder"')
#.........这里部分代码省略.........
示例7: buildSVG
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
def buildSVG(self, obj,join=False):
"creates a svg representation"
import Part, DraftGeomUtils
if hasattr(obj,"Source"):
if obj.Source:
if obj.Source.Objects:
objs = Draft.getGroupContents(obj.Source.Objects,walls=True)
objs = Draft.removeHidden(objs)
self.svg = ''
# generating SVG
if obj.RenderingMode == "Solid":
# render using the Arch Vector Renderer
import ArchVRM
render = ArchVRM.Renderer()
render.setWorkingPlane(obj.Source.Placement)
render.addObjects(objs)
if hasattr(obj,"ShowCut"):
render.cut(obj.Source.Shape,obj.ShowCut)
else:
render.cut(obj.Source.Shape)
self.svg += render.getViewSVG(linewidth="LWPlaceholder")
self.svg += render.getSectionSVG(linewidth="SWPLaceholder")
if hasattr(obj,"ShowCut"):
if obj.ShowCut:
self.svg += render.getHiddenSVG(linewidth="LWPlaceholder")
# print render.info()
else:
# render using the Drawing module
import Drawing, Part
shapes = []
hshapes = []
sshapes = []
p = FreeCAD.Placement(obj.Source.Placement)
self.direction = p.Rotation.multVec(FreeCAD.Vector(0,0,1))
for o in objs:
if o.isDerivedFrom("Part::Feature"):
if o.Shape.isNull():
pass
#FreeCAD.Console.PrintWarning(translate("Arch","Skipping empty object: ")+o.Name)
elif o.Shape.isValid():
shapes.extend(o.Shape.Solids)
else:
FreeCAD.Console.PrintWarning(translate("Arch","Skipping invalid object: ")+o.Name)
cutface,cutvolume,invcutvolume = ArchCommands.getCutVolume(obj.Source.Shape.copy(),shapes)
if cutvolume:
nsh = []
for sh in shapes:
for sol in sh.Solids:
if sol.Volume < 0:
sol.reverse()
c = sol.cut(cutvolume)
s = sol.section(cutface)
nsh.extend(c.Solids)
sshapes.append(s)
if hasattr(obj,"ShowCut"):
if obj.ShowCut:
c = sol.cut(invcutvolume)
hshapes.append(c)
shapes = nsh
if shapes:
self.shapes = shapes
self.baseshape = Part.makeCompound(shapes)
svgf = Drawing.projectToSVG(self.baseshape,self.direction)
if svgf:
svgf = svgf.replace('stroke-width="0.35"','stroke-width="LWPlaceholder"')
svgf = svgf.replace('stroke-width="1"','stroke-width="LWPlaceholder"')
svgf = svgf.replace('stroke-width:0.01','stroke-width:LWPlaceholder')
self.svg += svgf
if hshapes:
hshapes = Part.makeCompound(hshapes)
svgh = Drawing.projectToSVG(hshapes,self.direction)
if svgh:
svgh = svgh.replace('stroke-width="0.35"','stroke-width="LWPlaceholder"')
svgh = svgh.replace('stroke-width="1"','stroke-width="LWPlaceholder"')
svgh = svgh.replace('stroke-width:0.01','stroke-width:LWPlaceholder')
svgh = svgh.replace('fill="none"','fill="none"\nstroke-dasharray="0.09,0.05"')
self.svg += svgh
if sshapes:
edges = []
for s in sshapes:
edges.extend(s.Edges)
wires = DraftGeomUtils.findWires(edges)
faces = []
for w in wires:
if (w.ShapeType == "Wire") and w.isClosed():
faces.append(Part.Face(w))
sshapes = Part.makeCompound(faces)
svgs = Drawing.projectToSVG(sshapes,self.direction)
if svgs:
svgs = svgs.replace('stroke-width="0.35"','stroke-width="SWPlaceholder"')
svgs = svgs.replace('stroke-width="1"','stroke-width="SWPlaceholder"')
svgs = svgs.replace('stroke-width:0.01','stroke-width:SWPlaceholder')
self.svg += svgs
示例8: getSVG
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
def getSVG(section,allOn=False,renderMode="Wireframe",showHidden=False,showFill=False,scale=1,linewidth=1,fontsize=1,techdraw=False,rotation=0):
"""getSVG(section,[allOn,renderMode,showHidden,showFill,scale,linewidth,fontsize]) :
returns an SVG fragment from an Arch section plane. If
allOn is True, all cut objects are shown, regardless if they are visible or not.
renderMode can be Wireframe (default) or Solid to use the Arch solid renderer. If
showHidden is True, the hidden geometry above the section plane is shown in dashed line.
If showFill is True, the cut areas get filled with a pattern"""
if not section.Objects:
return
import Part,DraftGeomUtils
p = FreeCAD.Placement(section.Placement)
direction = p.Rotation.multVec(FreeCAD.Vector(0,0,1))
objs = Draft.getGroupContents(section.Objects,walls=True,addgroups=True)
if not allOn:
objs = Draft.removeHidden(objs)
# separate spaces and Draft objects
spaces = []
nonspaces = []
drafts = []
windows = []
cutface = None
for o in objs:
if Draft.getType(o) == "Space":
spaces.append(o)
elif Draft.getType(o) in ["Dimension","Annotation"]:
drafts.append(o)
elif o.isDerivedFrom("Part::Part2DObject"):
drafts.append(o)
else:
nonspaces.append(o)
if Draft.getType(o) == "Window":
windows.append(o)
objs = nonspaces
svg = ''
fillpattern = '<pattern id="sectionfill" patternUnits="userSpaceOnUse" patternTransform="matrix(5,0,0,5,0,0)"'
fillpattern += ' x="0" y="0" width="10" height="10">'
fillpattern += '<g>'
fillpattern += '<rect width="10" height="10" style="stroke:none; fill:#ffffff" /><path style="stroke:#000000; stroke-width:1" d="M0,0 l10,10" /></g></pattern>'
# generating SVG
if renderMode in ["Solid",1]:
# render using the Arch Vector Renderer
import ArchVRM, WorkingPlane
wp = WorkingPlane.plane()
wp.setFromPlacement(section.Placement)
#wp.inverse()
render = ArchVRM.Renderer()
render.setWorkingPlane(wp)
render.addObjects(objs)
if showHidden:
render.cut(section.Shape,showHidden)
else:
render.cut(section.Shape)
svg += '<g transform="scale(1,-1)">\n'
svg += render.getViewSVG(linewidth="LWPlaceholder")
svg += fillpattern
svg += render.getSectionSVG(linewidth="SWPlaceholder",fillpattern="sectionfill")
if showHidden:
svg += render.getHiddenSVG(linewidth="LWPlaceholder")
svg += '</g>\n'
# print render.info()
else:
# render using the Drawing module
import Drawing, Part
shapes,hshapes,sshapes,cutface,cutvolume,invcutvolume = getCutShapes(objs,section,showHidden)
if shapes:
baseshape = Part.makeCompound(shapes)
svgf = Drawing.projectToSVG(baseshape,direction)
if svgf:
svgf = svgf.replace('stroke-width="0.35"','stroke-width="LWPlaceholder"')
svgf = svgf.replace('stroke-width="1"','stroke-width="LWPlaceholder"')
svgf = svgf.replace('stroke-width:0.01','stroke-width:LWPlaceholder')
svg += svgf
if hshapes:
hshapes = Part.makeCompound(hshapes)
svgh = Drawing.projectToSVG(hshapes,direction)
if svgh:
svgh = svgh.replace('stroke-width="0.35"','stroke-width="LWPlaceholder"')
svgh = svgh.replace('stroke-width="1"','stroke-width="LWPlaceholder"')
svgh = svgh.replace('stroke-width:0.01','stroke-width:LWPlaceholder')
svgh = svgh.replace('fill="none"','fill="none"\nstroke-dasharray="DAPlaceholder"')
svg += svgh
if sshapes:
svgs = ""
if showFill:
#svgs += fillpattern
svgs += '<g transform="rotate(180)">\n'
for s in sshapes:
if s.Edges:
#f = Draft.getSVG(s,direction=direction.negative(),linewidth=0,fillstyle="sectionfill",color=(0,0,0))
# temporarily disabling fill patterns
f = Draft.getSVG(s,direction=direction.negative(),linewidth=0,fillstyle="#aaaaaa",color=(0,0,0))
svgs += f
svgs += "</g>\n"
sshapes = Part.makeCompound(sshapes)
svgs += Drawing.projectToSVG(sshapes,direction)
if svgs:
svgs = svgs.replace('stroke-width="0.35"','stroke-width="SWPlaceholder"')
svgs = svgs.replace('stroke-width="1"','stroke-width="SWPlaceholder"')
#.........这里部分代码省略.........
示例9: getSVG
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
#.........这里部分代码省略.........
svgcache = ''
# render using the Arch Vector Renderer
import ArchVRM, WorkingPlane
wp = WorkingPlane.plane()
wp.setFromPlacement(section.Placement)
#wp.inverse()
render = ArchVRM.Renderer()
render.setWorkingPlane(wp)
render.addObjects(objs)
if showHidden:
render.cut(section.Shape,showHidden)
else:
render.cut(section.Shape)
svgcache += '<g transform="scale(1,-1)">\n'
svgcache += render.getViewSVG(linewidth="SVGLINEWIDTH")
svgcache += fillpattern
svgcache += render.getSectionSVG(linewidth="SVGCUTLINEWIDTH",
fillpattern="sectionfill")
if showHidden:
svgcache += render.getHiddenSVG(linewidth="SVGLINEWIDTH")
svgcache += '</g>\n'
# print(render.info())
section.Proxy.svgcache = [svgcache,renderMode,showHidden,showFill]
else:
if not svgcache:
svgcache = ""
# render using the Drawing module
import Drawing, Part
shapes,hshapes,sshapes,cutface,cutvolume,invcutvolume = getCutShapes(objs,section,showHidden)
if shapes:
baseshape = Part.makeCompound(shapes)
style = {'stroke': "SVGLINECOLOR",
'stroke-width': "SVGLINEWIDTH"}
svgcache += Drawing.projectToSVG(
baseshape, direction,
hStyle=style, h0Style=style, h1Style=style,
vStyle=style, v0Style=style, v1Style=style)
if hshapes:
hshapes = Part.makeCompound(hshapes)
style = {'stroke': "SVGLINECOLOR",
'stroke-width': "SVGLINEWIDTH",
'stroke-dasharray': "SVGHIDDENPATTERN"}
svgcache += Drawing.projectToSVG(
hshapes, direction,
hStyle=style, h0Style=style, h1Style=style,
vStyle=style, v0Style=style, v1Style=style)
if sshapes:
if showFill:
#svgcache += fillpattern
svgcache += '<g transform="rotate(180)">\n'
for s in sshapes:
if s.Edges:
#svg += Draft.getSVG(s,direction=direction.negative(),linewidth=0,fillstyle="sectionfill",color=(0,0,0))
# temporarily disabling fill patterns
svgcache += Draft.getSVG(s, direction=direction.negative(),
linewidth=0,
fillstyle=Draft.getrgb(fillColor),
color=lineColor)
svgcache += "</g>\n"
sshapes = Part.makeCompound(sshapes)
style = {'stroke': "SVGLINECOLOR",
'stroke-width': "SVGCUTLINEWIDTH"}
svgcache += Drawing.projectToSVG(
sshapes, direction,
hStyle=style, h0Style=style, h1Style=style,
vStyle=style, v0Style=style, v1Style=style)
示例10: getSVG
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
def getSVG(section,allOn=False,renderMode="Wireframe",showHidden=False,showFill=False,scale=1,linewidth=1,fontsize=1):
"""getSVG(section,[allOn,renderMode,showHidden,showFill,scale,linewidth,fontsize]) :
returns an SVG fragment from an Arch section plane. If
allOn is True, all cut objects are shown, regardless if they are visible or not.
renderMode can be Wireframe (default) or Solid to use the Arch solid renderer. If
showHidden is True, the hidden geometry above the section plane is shown in dashed line.
If showFill is True, the cut areas get filled with a pattern"""
if not section.Objects:
return
import DraftGeomUtils
p = FreeCAD.Placement(section.Placement)
direction = p.Rotation.multVec(FreeCAD.Vector(0,0,1))
objs = Draft.getGroupContents(section.Objects,walls=True,addgroups=True)
if not allOn:
objs = Draft.removeHidden(objs)
# separate spaces
spaces = []
nonspaces = []
for o in objs:
if Draft.getType(o) == "Space":
spaces.append(o)
else:
nonspaces.append(o)
objs = nonspaces
svg = ''
fillpattern = '<pattern id="sectionfill" patternUnits="userSpaceOnUse" patternTransform="matrix(5,0,0,5,0,0)"'
fillpattern += ' x="0" y="0" width="10" height="10">'
fillpattern += '<g>'
fillpattern += '<rect width="10" height="10" style="stroke:none; fill:#ffffff" /><path style="stroke:#000000; stroke-width:1" d="M0,0 l10,10" /></g></pattern>'
# generating SVG
if renderMode == "Solid":
# render using the Arch Vector Renderer
import ArchVRM, WorkingPlane
wp = WorkingPlane.plane()
wp.setFromPlacement(section.Placement)
#wp.inverse()
render = ArchVRM.Renderer()
render.setWorkingPlane(wp)
render.addObjects(objs)
if showHidden:
render.cut(section.Shape,showHidden)
else:
render.cut(section.Shape)
svg += '<g transform="scale(1,-1)">\n'
svg += render.getViewSVG(linewidth="LWPlaceholder")
svg += fillpattern
svg += render.getSectionSVG(linewidth="SWPlaceholder",fillpattern="sectionfill")
if showHidden:
svg += render.getHiddenSVG(linewidth="LWPlaceholder")
svg += '</g>\n'
# print render.info()
else:
# render using the Drawing module
import Drawing, Part
shapes = []
hshapes = []
sshapes = []
for o in objs:
if o.isDerivedFrom("Part::Feature"):
if o.Shape.isNull():
pass
elif o.Shape.isValid():
if section.OnlySolids:
shapes.extend(o.Shape.Solids)
else:
shapes.append(o.Shape)
else:
print section.Label,": Skipping invalid object:",o.Label
cutface,cutvolume,invcutvolume = ArchCommands.getCutVolume(section.Shape.copy(),shapes)
if cutvolume:
nsh = []
for sh in shapes:
for sol in sh.Solids:
if sol.Volume < 0:
sol.reverse()
c = sol.cut(cutvolume)
s = sol.section(cutface)
try:
wires = DraftGeomUtils.findWires(s.Edges)
for w in wires:
f = Part.Face(w)
sshapes.append(f)
#s = Part.Wire(s.Edges)
#s = Part.Face(s)
except Part.OCCError:
#print "ArchDrawingView: unable to get a face"
sshapes.append(s)
nsh.extend(c.Solids)
#sshapes.append(s)
if showHidden:
c = sol.cut(invcutvolume)
hshapes.append(c)
shapes = nsh
if shapes:
baseshape = Part.makeCompound(shapes)
svgf = Drawing.projectToSVG(baseshape,direction)
if svgf:
#.........这里部分代码省略.........
示例11: len
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
Part.show(Part.makeBox(100,100,100).cut(Part.makeCylinder(80,100)).cut(Part.makeBox(90,40,100)).cut(Part.makeBox(20,85,100)))
# direct projection. The G0 means hard edge, the G1 is tangend continues.
Shape = App.ActiveDocument.Shape.Shape
[visiblyG0,visiblyG1,hiddenG0,hiddenG1] = Drawing.project(Shape)
print "visible edges:", len(visiblyG0.Edges)
print "hidden edges:", len(hiddenG0.Edges)
# all was projected on the Z-plane:
print "Bnd Box shape: X=",Shape.BoundBox.XLength," Y=",Shape.BoundBox.YLength," Z=",Shape.BoundBox.ZLength
print "Bnd Box project: X=",visiblyG0.BoundBox.XLength," Y=",visiblyG0.BoundBox.YLength," Z=",visiblyG0.BoundBox.ZLength
# different projection vector
[visiblyG0,visiblyG1,hiddenG0,hiddenG1] = Drawing.project(Shape,Base.Vector(1,1,1))
# project to SVG
resultSVG = Drawing.projectToSVG(Shape,App.Vector(1,1,1))
print resultSVG
# And now the parametric way
#
# insert a Page object and assign a template
App.activeDocument().addObject('Drawing::FeaturePage','Page')
App.activeDocument().Page.Template = App.ConfigGet('AppHomePath')+'Mod/Drawing/Templates/A3_Landscape.svg'
# create a view on the "Shape" object, define the position and scale and assign it to a Page
App.activeDocument().addObject('Drawing::FeatureViewPart','View')
App.activeDocument().View.Source = App.activeDocument().Shape
App.activeDocument().View.Direction = (0.0,0.0,1.0)
App.activeDocument().View.X = 10.0
App.activeDocument().View.Y = 10.0
App.activeDocument().Page.addObject(App.activeDocument().View)
示例12: getPath
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
def getPath(edges=[],wires=[],pathname=None):
import Part,DraftGeomUtils
svg = "<path "
if pathname is None:
svg += 'id="%s" ' % obj.Name
elif pathname != "":
svg += 'id="%s" ' % pathname
svg += ' d="'
if not wires:
egroups = Part.sortEdges(edges)
else:
egroups = []
for w in wires:
w1=w.copy()
w1.fixWire()
egroups.append(Part.__sortEdges__(w1.Edges))
for egroupindex, edges in enumerate(egroups):
edata = ""
vs=() #skipped for the first edge
for edgeindex,e in enumerate(edges):
previousvs = vs
# vertexes of an edge (reversed if needed)
vs = e.Vertexes
if previousvs:
if (vs[0].Point-previousvs[-1].Point).Length > 1e-6:
vs.reverse()
if edgeindex == 0:
v = getProj(vs[0].Point, plane)
edata += 'M '+ str(v.x) +' '+ str(v.y) + ' '
else:
if (vs[0].Point-previousvs[-1].Point).Length > 1e-6:
raise ValueError('edges not ordered')
iscircle = DraftGeomUtils.geomType(e) == "Circle"
isellipse = DraftGeomUtils.geomType(e) == "Ellipse"
if iscircle or isellipse:
import math
if hasattr(FreeCAD,"DraftWorkingPlane"):
drawing_plane_normal = FreeCAD.DraftWorkingPlane.axis
else:
drawing_plane_normal = FreeCAD.Vector(0,0,1)
if plane: drawing_plane_normal = plane.axis
c = e.Curve
if round(c.Axis.getAngle(drawing_plane_normal),2) in [0,3.14]:
occversion = Part.OCC_VERSION.split(".")
done = False
if (int(occversion[0]) >= 7) and (int(occversion[1]) >= 1):
# if using occ >= 7.1, use HLR algorithm
import Drawing
snip = Drawing.projectToSVG(e,drawing_plane_normal)
if snip:
try:
a = "A " + snip.split("path d=\"")[1].split("\"")[0].split("A")[1]
except:
pass
else:
edata += a
done = True
if not done:
if len(e.Vertexes) == 1 and iscircle: #complete curve
svg = getCircle(e)
return svg
elif len(e.Vertexes) == 1 and isellipse:
#svg = getEllipse(e)
#return svg
endpoints = (getProj(c.value((c.LastParameter-\
c.FirstParameter)/2.0), plane), \
getProj(vs[-1].Point, plane))
else:
endpoints = (getProj(vs[-1].Point), plane)
# arc
if iscircle:
rx = ry = c.Radius
rot = 0
else: #ellipse
rx = c.MajorRadius
ry = c.MinorRadius
rot = math.degrees(c.AngleXU * (c.Axis * \
FreeCAD.Vector(0,0,1)))
if rot > 90:
rot -=180
if rot < -90:
rot += 180
#be careful with the sweep flag
flag_large_arc = (((e.ParameterRange[1] - \
e.ParameterRange[0]) / math.pi) % 2) > 1
#flag_sweep = (c.Axis * drawing_plane_normal >= 0) \
# == (e.LastParameter > e.FirstParameter)
# == (e.Orientation == "Forward")
# other method: check the direction of the angle between tangents
t1 = e.tangentAt(e.FirstParameter)
t2 = e.tangentAt(e.FirstParameter + (e.LastParameter-e.FirstParameter)/10)
flag_sweep = (DraftVecUtils.angle(t1,t2,drawing_plane_normal) < 0)
for v in endpoints:
edata += 'A %s %s %s %s %s %s %s ' % \
(str(rx),str(ry),str(rot),\
str(int(flag_large_arc)),\
str(int(flag_sweep)),str(v.x),str(v.y))
else:
edata += getDiscretized(e, plane)
elif DraftGeomUtils.geomType(e) == "Line":
#.........这里部分代码省略.........
示例13: updateSVG
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
def updateSVG(self, obj,join=False):
"encapsulates a svg fragment into a transformation node"
import Part, DraftGeomUtils
if hasattr(obj,"Source"):
if obj.Source:
if obj.Source.Objects:
objs = Draft.getGroupContents(obj.Source.Objects)
objs = Draft.removeHidden(objs)
svg = ''
# generating SVG
linewidth = obj.LineWidth/obj.Scale
if obj.RenderingMode == "Solid":
# render using the Arch Vector Renderer
import ArchVRM
render = ArchVRM.Renderer()
render.setWorkingPlane(obj.Source.Placement)
render.addObjects(Draft.getGroupContents(objs,walls=True))
render.cut(obj.Source.Shape)
svg += render.getViewSVG(linewidth=linewidth)
svg += render.getSectionSVG(linewidth=linewidth*2)
# print render.info()
else:
# render using the Drawing module
import Drawing, Part
shapes = []
p = FreeCAD.Placement(obj.Source.Placement)
direction = p.Rotation.multVec(FreeCAD.Vector(0,0,1))
for o in objs:
if o.isDerivedFrom("Part::Feature"):
shapes.extend(o.Shape.Solids)
cutface,cutvolume = ArchCommands.getCutVolume(obj.Source.Shape.copy(),shapes)
if cutvolume:
nsh = []
for sh in shapes:
for sol in sh.Solids:
c = sol.cut(cutvolume)
nsh.append(c)
shapes = nsh
base = Part.makeCompound(shapes)
#if shapes:
# base = shapes.pop().copy()
#for sh in shapes:
# try:
# base = base.fuse(sh)
# except:
# print "unable to fuse, passing..."
svgf = Drawing.projectToSVG(base,direction)
if svgf:
svgf = svgf.replace('stroke-width="0.35"','stroke-width="' + str(linewidth) + 'px"')
svgf = svgf.replace('stroke-width="1"','stroke-width="' + str(linewidth) + 'px"')
svgf = svgf.replace('stroke-width:0.01','stroke-width:' + str(linewidth) + 'px')
svg += svgf
result = ''
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 += '">\n'
result += svg
result += '</g>\n'
# print "complete node:",result
return result
return ''
示例14: type
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import projectToSVG [as 别名]
return bb
# do something here...
svg = []
margin = 10
page = FreeCAD.BoundBox(margin,margin,0,210-margin,290-margin,0)
placed_bbox=[]
for obj in FreeCADGui.Selection.getSelectionEx():
for face in obj.SubObjects:
if type(face) != Part.Face:
continue
f = face.copy()
box = f.BoundBox
f.translate(box.Center * -1)
#f.translate(FreeCAD.Vector(box.XLength/2, box.YLength/2, box.ZLength/2))
svgproj = Drawing.projectToSVG(f,f.Surface.Axis)
FreeCAD.Console.PrintMessage( svgproj)
del f
l_size=5
root = fromstring(svgproj)
del root.attrib['stroke-width']
for node in root.findall('.//circle'):
print node
x = float(node.attrib.get('cx'))
y = float(node.attrib.get('cy'))
#node.attrib["style"]='stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none'
l1 = Element('line')
l1.attrib['x1']= str(x - l_size)
l1.attrib['y1']= str(y)
l1.attrib['x2']= str(x + l_size)