adding tessellation to ellipses and adding a user parameter for line
segment length of ellipses and splines with a Shape2DView projection. This will make it useful for DXF output.
This commit is contained in:
parent
4d2d7b65ae
commit
91ab4c340a
|
@ -4174,11 +4174,13 @@ class _Shape2DView(_DraftObject):
|
|||
obj.addProperty("App::PropertyEnumeration","ProjectionMode","Draft","The way the viewed object must be projected")
|
||||
obj.addProperty("App::PropertyIntegerList","FaceNumbers","Draft","The indices of the faces to be projected in Individual Faces mode")
|
||||
obj.addProperty("App::PropertyBool","HiddenLines","Draft","Show hidden lines")
|
||||
obj.addProperty("App::PropertyBool","Tessellation","Draft","Tessellate BSplines into line segments using number of spline poles")
|
||||
obj.addProperty("App::PropertyBool","Tessellation","Draft","Tessellate Ellipses and BSplines into line segments")
|
||||
obj.addProperty("App::PropertyFloat","SegmentLength","Draft","Length of line segments if tessellating Ellipses or BSplines into line segments")
|
||||
obj.Projection = Vector(0,0,1)
|
||||
obj.ProjectionMode = ["Solid","Individual Faces","Cutlines","Cutfaces"]
|
||||
obj.HiddenLines = False
|
||||
obj.Tessellation = True
|
||||
obj.SegmentLength = .05
|
||||
_DraftObject.__init__(self,obj,"Shape2DView")
|
||||
|
||||
def getProjected(self,obj,shape,direction):
|
||||
|
@ -4193,10 +4195,11 @@ class _Shape2DView(_DraftObject):
|
|||
if obj.HiddenLines:
|
||||
for g in groups[5:]:
|
||||
edges.append(g)
|
||||
return Part.makeCompound(edges)
|
||||
#if hasattr(obj,"Tessellation"):
|
||||
#return DraftGeomUtils.cleanProjection(Part.makeCompound(edges),obj.Tessellation)
|
||||
#else:
|
||||
#return Part.makeCompound(edges)
|
||||
if hasattr(obj,"Tessellation"):
|
||||
return DraftGeomUtils.cleanProjection(Part.makeCompound(edges),obj.Tessellation,obj.SegmentLength)
|
||||
else:
|
||||
return Part.makeCompound(edges)
|
||||
#return DraftGeomUtils.cleanProjection(Part.makeCompound(edges))
|
||||
|
||||
def execute(self,obj):
|
||||
|
|
|
@ -1808,10 +1808,12 @@ def curvetowire(obj,steps):
|
|||
p0 = p
|
||||
return edgelist
|
||||
|
||||
def cleanProjection(shape,tessellate=False):
|
||||
def cleanProjection(shape,tessellate=True,seglength=.05):
|
||||
"returns a valid compound of edges, by recreating them"
|
||||
# this is because the projection algorithm somehow creates wrong shapes.
|
||||
# they dispay fine, but on loading the file the shape is invalid
|
||||
# Now with tanderson's fix to ProjectionAlgos, that isn't the case, but this
|
||||
# can be used for tessellating ellipses and splines for DXF output-DF
|
||||
oldedges = shape.Edges
|
||||
newedges = []
|
||||
for e in oldedges:
|
||||
|
@ -1826,15 +1828,18 @@ def cleanProjection(shape,tessellate=False):
|
|||
else:
|
||||
newedges.append(e.Curve.toShape())
|
||||
elif geomType(e) == "Ellipse":
|
||||
if len(e.Vertexes) > 1:
|
||||
a = Part.Arc(e.Curve,e.FirstParameter,e.LastParameter).toShape()
|
||||
newedges.append(a)
|
||||
if tessellate:
|
||||
newedges.append(Part.Wire(curvetowire(e, seglength)))
|
||||
else:
|
||||
newedges.append(e.Curve.toShape())
|
||||
if len(e.Vertexes) > 1:
|
||||
a = Part.Arc(e.Curve,e.FirstParameter,e.LastParameter).toShape()
|
||||
newedges.append(a)
|
||||
else:
|
||||
newedges.append(e.Curve.toShape())
|
||||
elif geomType(e) == "BSplineCurve" or \
|
||||
geomType(e) == "BezierCurve":
|
||||
if tessellate:
|
||||
newedges.append(Part.Wire(curvetowire(e,e.Curve.NbPoles)))
|
||||
newedges.append(Part.Wire(curvetowire(e,seglength)))
|
||||
else:
|
||||
if isLine(e.Curve):
|
||||
l = Part.Line(e.Vertexes[0].Point,e.Vertexes[-1].Point).toShape()
|
||||
|
@ -1847,6 +1852,36 @@ def cleanProjection(shape,tessellate=False):
|
|||
print "Debug: error cleaning edge ",e
|
||||
return Part.makeCompound(newedges)
|
||||
|
||||
def curvetosegment(curve,seglen):
|
||||
points = curve.discretize(seglen)
|
||||
p0 = points[0]
|
||||
edgelist = []
|
||||
for p in points[1:]:
|
||||
edge = Part.makeLine((p0.x,p0.y,p0.z),(p.x,p.y,p.z))
|
||||
edgelist.append(edge)
|
||||
p0 = p
|
||||
return edgelist
|
||||
|
||||
def tessellateProjection(shape,seglen):
|
||||
''' Returns projection with BSplines and Ellipses broken into line segments.
|
||||
Useful for exporting projected views to *dxf files.'''
|
||||
oldedges = shape.Edges
|
||||
newedges = []
|
||||
for e in oldedges:
|
||||
try:
|
||||
if geomType(e) == "Line":
|
||||
newedges.append(e.Curve.toShape())
|
||||
elif geomType(e) == "Circle":
|
||||
newedges.append(e.Curve.toShape())
|
||||
elif geomType(e) == "Ellipse":
|
||||
newedges.append(Part.Wire(curvetosegment(e,seglen)))
|
||||
elif geomType(e) == "BSplineCurve":
|
||||
newedges.append(Part.Wire(curvetosegment(e,seglen)))
|
||||
else:
|
||||
newedges.append(e)
|
||||
except:
|
||||
print "Debug: error cleaning edge ",e
|
||||
return Part.makeCompound(newedges)
|
||||
|
||||
# circle functions *********************************************************
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user