本文整理汇总了Python中Drawing.project方法的典型用法代码示例。如果您正苦于以下问题:Python Drawing.project方法的具体用法?Python Drawing.project怎么用?Python Drawing.project使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drawing
的用法示例。
在下文中一共展示了Drawing.project方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: computeAreas
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import project [as 别名]
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
示例2: getFlatShape
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import project [as 别名]
def getFlatShape(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)
return V0.Edges+V1.Edges
else:
FreeCAD.Console.PrintMessage(translate("Arch","No shape has been computed yet, select wireframe rendering and render again"))
return None
示例3: createSVG
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import project [as 别名]
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
示例4: computeAreas
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import project [as 别名]
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
示例5: getSVG
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import project [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: computeAreas
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import project [as 别名]
def computeAreas(self,obj):
if not obj.Shape:
return
if obj.Shape.isNull():
return
if not obj.Shape.isValid():
return
if not obj.Shape.Faces:
return
if not hasattr(obj,"Perimeter"): # check we have a latest version site
return
if not obj.Terrain:
return
# compute area
fset = []
for f in obj.Shape.Faces:
if f.normalAt(0,0).getAngle(FreeCAD.Vector(0,0,1)) < 1.5707:
fset.append(f)
if fset:
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 area. Better set it to zero than show a wrong value
if obj.ProjectedArea.Value != 0:
print("Error computing areas for ",obj.Label)
obj.ProjectedArea = 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.ProjectedArea.Value != self.flatarea.Area:
obj.ProjectedArea = self.flatarea.Area
# compute perimeter
lut = {}
for e in obj.Shape.Edges:
lut.setdefault(e.hashCode(),[]).append(e)
l = 0
for e in lut.values():
if len(e) == 1: # keep only border edges
l += e[0].Length
if l:
if obj.Perimeter.Value != l:
obj.Perimeter = l
# compute volumes
if obj.Terrain.Shape.Solids:
shapesolid = obj.Terrain.Shape.copy()
else:
shapesolid = obj.Terrain.Shape.extrude(obj.ExtrusionVector)
addvol = 0
subvol = 0
for sub in obj.Subtractions:
subvol += sub.Shape.common(shapesolid).Volume
for sub in obj.Additions:
addvol += sub.Shape.cut(shapesolid).Volume
if obj.SubtractionVolume.Value != subvol:
obj.SubtractionVolume = subvol
if obj.AdditionVolume.Value != addvol:
obj.AdditionVolume = addvol
示例7: len
# 需要导入模块: import Drawing [as 别名]
# 或者: from Drawing import project [as 别名]
# exampel how to use the scripting API of the drawing module
#
# first of all you need the Part and the Drawing module:
import FreeCAD, Part, Drawing
# create a small sample part
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