From 9ede51b2f6d37dc62739cd35938ca18b1fa33ba6 Mon Sep 17 00:00:00 2001 From: Daniel Falck Date: Sat, 8 Feb 2014 15:16:36 -0800 Subject: [PATCH] added way of breaking BSplines into line segments in Shape2DView --- src/Mod/Draft/Draft.py | 4 +++- src/Mod/Draft/DraftGeomUtils.py | 25 +++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 491686ba7..c2ac83a67 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -4023,9 +4023,11 @@ class _Shape2DView(_DraftObject): "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.Projection = Vector(0,0,1) obj.ProjectionMode = ["Solid","Individual Faces","Cutlines"] obj.HiddenLines = False + obj.Tessellation = True _DraftObject.__init__(self,obj,"Shape2DView") def execute(self,obj): @@ -4048,7 +4050,7 @@ class _Shape2DView(_DraftObject): for g in groups[5:]: edges.append(g) #return Part.makeCompound(edges) - return DraftGeomUtils.cleanProjection(Part.makeCompound(edges)) + return DraftGeomUtils.cleanProjection(Part.makeCompound(edges),obj.Tessellation) def createGeometry(self,obj): import DraftGeomUtils diff --git a/src/Mod/Draft/DraftGeomUtils.py b/src/Mod/Draft/DraftGeomUtils.py index 537226c14..5491aa031 100755 --- a/src/Mod/Draft/DraftGeomUtils.py +++ b/src/Mod/Draft/DraftGeomUtils.py @@ -1783,8 +1783,18 @@ def getCircleFromSpline(edge): circle = Part.makeCircle(r,c,n) #print circle.Curve return circle - -def cleanProjection(shape): + +def curvetowire(obj,steps): + points = obj.copy().discretize(steps) + 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 cleanProjection(shape,tessellate): "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 @@ -1808,11 +1818,14 @@ def cleanProjection(shape): else: newedges.append(e.Curve.toShape()) elif geomType(e) == "BSplineCurve": - if isLine(e.Curve): - l = Part.Line(e.Vertexes[0].Point,e.Vertexes[-1].Point).toShape() - newedges.append(l) + if tessellate: + newedges.append(Part.Wire(curvetowire(e,e.Curve.NbPoles))) else: - newedges.append(e.Curve.toShape()) + if isLine(e.Curve): + l = Part.Line(e.Vertexes[0].Point,e.Vertexes[-1].Point).toShape() + newedges.append(l) + else: + newedges.append(e.Curve.toShape()) else: newedges.append(e) except: