本文整理汇总了Python中Drawing类的典型用法代码示例。如果您正苦于以下问题:Python Drawing类的具体用法?Python Drawing怎么用?Python Drawing使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Drawing类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getDXF
def getDXF(self):
"returns a flat shape representation of the view"
if hasattr(self,"baseshape"):
import Drawing
[V0,V1,H0,H1] = Drawing.project(self.baseshape,self.direction)
DxfOutput = Drawing.projectToDXF(self.baseshape,self.direction)
return DxfOutput
else:
FreeCAD.Console.PrintMessage(translate("Arch","No shape has been computed yet, select wireframe rendering and render again"))
return None
示例2: execute
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
示例3: computeAreas
def computeAreas(self, obj):
"computes the area properties"
if not obj.Shape:
return
if obj.Shape.isNull():
return
if not obj.Shape.isValid():
return
if not obj.Shape.Faces:
return
import Drawing, Part
a = 0
fset = []
for i, f in enumerate(obj.Shape.Faces):
try:
ang = f.normalAt(0, 0).getAngle(FreeCAD.Vector(0, 0, 1))
except Part.OCCError:
print "Debug: Error computing areas for ", obj.Label, ": normalAt() Face ", i
return
else:
if (ang > 1.57) and (ang < 1.571):
a += f.Area
if ang < 1.5707:
fset.append(f)
if a and hasattr(obj, "VerticalArea"):
if obj.VerticalArea.Value != a:
obj.VerticalArea = a
if fset and hasattr(obj, "HorizontalArea"):
pset = []
for f in fset:
if f.normalAt(0, 0).getAngle(FreeCAD.Vector(0, 0, 1)) < 0.00001:
# already horizontal
pset.append(f)
else:
try:
pf = Part.Face(Part.Wire(Drawing.project(f, FreeCAD.Vector(0, 0, 1))[0].Edges))
except Part.OCCError:
# error in computing the areas. Better set them to zero than show a wrong value
if obj.HorizontalArea.Value != 0:
print "Debug: Error computing areas for ", obj.Label, ": unable to project face: ", str(
[v.Point for v in f.Vertexes]
), " (face normal:", f.normalAt(0, 0), ")"
obj.HorizontalArea = 0
if hasattr(obj, "PerimeterLength"):
if obj.PerimeterLength.Value != 0:
obj.PerimeterLength = 0
else:
pset.append(pf)
if pset:
self.flatarea = pset.pop()
for f in pset:
self.flatarea = self.flatarea.fuse(f)
self.flatarea = self.flatarea.removeSplitter()
if obj.HorizontalArea.Value != self.flatarea.Area:
obj.HorizontalArea = self.flatarea.Area
if hasattr(obj, "PerimeterLength") and (len(self.flatarea.Faces) == 1):
if obj.PerimeterLength.Value != self.flatarea.Faces[0].OuterWire.Length:
obj.PerimeterLength = self.flatarea.Faces[0].OuterWire.Length
示例4: export_xyz_to_dxf
def export_xyz_to_dxf(ai_solid, ai_size_x, ai_size_y, ai_size_z, ai_xy_slice_list, ai_xz_slice_list, ai_yz_slice_list, ai_output_file):
""" Cut a FreeCAD Part Object in many slices in the three directions X, Y and Z and put all those slices in a DXF file
"""
# calculate the space between two drawings
l_space = max(ai_size_x/5.0, ai_size_y/5.0, ai_size_z/5.0)
#
vec_z_unit = Base.Vector(0,0,1)
#
l_slice_list = []
l_pos_y = 0
for lo in ['xy','xz','yz']:
#l_solid = ai_solid
l_solid = ai_solid.copy()
l_depth_list = []
l_shift_x = 0
l_gauge_max = 0
if(lo=='xy'):
l_solid.rotate(Base.Vector(ai_size_x/2.0, ai_size_y/2.0, ai_size_z/2.0), Base.Vector(0,0,1), 0)
l_solid.translate(Base.Vector(0,0,0)) # place the module corner at origin (0,0,0)
l_solid.translate(Base.Vector(0,2*ai_size_z+7*l_space,0))
l_pos_y = 2*ai_size_z+6*l_space
l_depth_list = ai_xy_slice_list
l_shift_x = ai_size_x
l_gauge_max = ai_size_z
elif(lo=='xz'):
l_solid.rotate(Base.Vector(ai_size_x/2.0, ai_size_y/2.0, ai_size_z/2.0), Base.Vector(1,0,0), -90)
l_solid.translate(Base.Vector((ai_size_x-ai_size_x)/2.0, (ai_size_z-ai_size_y)/2.0, (ai_size_y-ai_size_z)/2.0)) # place the module corner at origin (0,0,0)
l_solid.translate(Base.Vector(0,1*ai_size_z+4*l_space,0))
l_pos_y = 1*ai_size_z+3*l_space
l_depth_list = ai_xz_slice_list
l_shift_x = ai_size_x
l_gauge_max = ai_size_y
elif(lo=='yz'):
l_solid.rotate(Base.Vector(ai_size_x/2.0, ai_size_y/2.0, ai_size_z/2.0), Base.Vector(0,0,1), -90)
l_solid.rotate(Base.Vector(ai_size_x/2.0, ai_size_y/2.0, ai_size_z/2.0), Base.Vector(1,0,0), -90)
l_solid.translate(Base.Vector((ai_size_y-ai_size_x)/2.0, (ai_size_z-ai_size_y)/2.0, (ai_size_x-ai_size_z)/2.0)) # place the module corner at origin (0,0,0)
l_solid.translate(Base.Vector(0,l_space,0))
l_pos_y = 0*ai_size_z+0*l_space
l_depth_list = ai_yz_slice_list
l_shift_x = ai_size_y
l_gauge_max = ai_size_x
l_pos_x = 0
for l_depth in l_depth_list:
#print("dbg163: l_shift_x l_space l_gauge_max l_depth l_pos_x l_pos_y", l_shift_x, l_space, l_gauge_max, l_depth, l_pos_x, l_pos_y)
l_slice_list.extend(draw_gauge(l_shift_x, l_space/2.0, l_gauge_max, l_depth, l_pos_x, l_pos_y))
l_pos_x += l_shift_x+2*l_space
ll_depth = l_depth
if(lo=='xz'):
ll_depth = ai_size_y-l_depth
#print("dbg168: ll_depth:", ll_depth)
l_slice_list.extend(l_solid.slice(vec_z_unit, ll_depth))
l_solid.translate(Base.Vector(l_shift_x+2*l_space,0,0))
l_slice = Part.makeCompound(l_slice_list)
r_dxf = Drawing.projectToDXF(l_slice, vec_z_unit)
#r_dxf = Drawing.projectToDXF(ai_solid, ai_vector)
fh_output = open(ai_output_file, 'w')
fh_output.write(r_dxf)
fh_output.close()
return(1)
示例5: export_to_dxf
def export_to_dxf(ai_solid, ai_vector, ai_depth, ai_output_file):
""" create a DXF of a slice of FreeCAD Part Object
"""
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.projectToDXF(l_slice, ai_vector)
#r_dxf = Drawing.projectToDXF(ai_solid, ai_vector) # works also :)
fh_output = open(ai_output_file, 'w')
fh_output.write(r_dxf)
fh_output.close()
return(1)
示例6: export_to_svg
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)
示例7: getDXF
def getDXF(self,obj):
"returns a DXF representation of the view"
if obj.RenderingMode == "Solid":
print "Unable to get DXF from Solid mode: ",obj.Label
return ""
result = []
import Drawing
if not hasattr(self,"baseshape"):
self.onChanged(obj,"Source")
if hasattr(self,"baseshape"):
if self.baseshape:
result.append(Drawing.projectToDXF(self.baseshape,self.direction))
if hasattr(self,"sectionshape"):
if self.sectionshape:
result.append(Drawing.projectToDXF(self.sectionshape,self.direction))
if hasattr(self,"hiddenshape"):
if self.hiddenshape:
result.append(Drawing.projectToDXF(self.hiddenshape,self.direction))
return result
示例8: getProjected
def getProjected(shape,direction):
"returns projected edges from a shape and a direction"
import Part,Drawing
edges = []
groups = Drawing.projectEx(shape,direction)
for g in groups[0:5]:
if g:
edges.append(g)
# if hasattr(obj,"Tessellation") and obj.Tessellation:
# return DraftGeomUtils.cleanProjection(Part.makeCompound(edges),obj.Tessellation,obj.SegmentLength)
# else:
return Part.makeCompound(edges)
示例9: updateSVG
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 ""
示例10: updateSVG
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 ''
示例11: getDXF
def getDXF(obj):
"returns a DXF representation from a TechDraw/Drawing view"
allOn = True
if hasattr(obj,"AllOn"):
allOn = obj.AllOn
elif hasattr(obj,"AlwaysOn"):
allOn = obj.AlwaysOn
showHidden = False
if hasattr(obj,"showCut"):
showHidden = obj.showCut
elif hasattr(obj,"showHidden"):
showHidden = obj.showHidden
result = []
import Drawing,Part
if not obj.Source:
return result
section = obj.Source
if not section.Objects:
return result
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 = []
objs = [o for o in objs if ((not(Draft.getType(o) in ["Space","Dimension","Annotation"])) and (not (o.isDerivedFrom("Part::Part2DObject"))))]
shapes,hshapes,sshapes,cutface,cutvolume,invcutvolume = getCutShapes(objs,section,showHidden)
if shapes:
result.append(Drawing.projectToDXF(Part.makeCompound(shapes),direction))
if sshapes:
result.append(Drawing.projectToDXF(Part.makeCompound(sshapes),direction))
if hshapes:
result.append(Drawing.projectToDXF(Part.makeCompound(hshapes),direction))
return result
示例12: createSVG
def createSVG(Part):
# projecting with HLR
[Visibly,Hidden] = Drawing.project(Part)
buffer = startSVG
for i in Hidden.Edges:
buffer += '<line x1="' +`i.Vertexes[0].X` +'" y1="' +`i.Vertexes[0].Y` +'" x2="'+ `i.Vertexes[1].X`+ '" y2="'+ `i.Vertexes[1].Y`+ '" stroke="#fff000" stroke-width="1px" />\n'
for i in Visibly.Edges:
buffer += '<line x1="' +`i.Vertexes[0].X` +'" y1="' +`i.Vertexes[0].Y` +'" x2="'+ `i.Vertexes[1].X`+ '" y2="'+ `i.Vertexes[1].Y`+ '" stroke="#000000" stroke-width="1px" />\n'
buffer += '</svg>'
return buffer
示例13: computeAreas
def computeAreas(self,obj):
"computes the area properties"
if not obj.Shape:
return
if obj.Shape.isNull():
return
if not obj.Shape.isValid():
return
if not obj.Shape.Faces:
return
a = 0
fset = []
for f in obj.Shape.Faces:
ang = f.normalAt(0,0).getAngle(FreeCAD.Vector(0,0,1))
if (ang > 1.57) and (ang < 1.571):
a += f.Area
if ang < 1.5707:
fset.append(f)
if a and hasattr(obj,"VerticalArea"):
if obj.VerticalArea.Value != a:
obj.VerticalArea = a
if fset and hasattr(obj,"HorizontalArea"):
import Drawing,Part
pset = []
for f in fset:
try:
pf = Part.Face(Part.Wire(Drawing.project(f,FreeCAD.Vector(0,0,1))[0].Edges))
except Part.OCCError:
# error in computing the areas. Better set them to zero than show a wrong value
if obj.HorizontalArea.Value != 0:
print "Error computing areas for ",obj.Label
obj.HorizontalArea = 0
if hasattr(obj,"PerimeterLength"):
if obj.PerimeterLength.Value != 0:
obj.PerimeterLength = 0
else:
pset.append(pf)
if pset:
self.flatarea = pset.pop()
for f in pset:
self.flatarea = self.flatarea.fuse(f)
self.flatarea = self.flatarea.removeSplitter()
if obj.HorizontalArea.Value != self.flatarea.Area:
obj.HorizontalArea = self.flatarea.Area
if hasattr(obj,"PerimeterLength") and (len(self.flatarea.Faces) == 1):
if obj.PerimeterLength.Value != self.flatarea.Faces[0].OuterWire.Length:
obj.PerimeterLength = self.flatarea.Faces[0].OuterWire.Length
示例14: getSVG
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"')
#.........这里部分代码省略.........
示例15: getPath
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":
#.........这里部分代码省略.........