Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft Bspline parameterization property #179

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/Mod/Draft/Draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -4590,18 +4590,47 @@ def __init__(self, obj):
obj.MakeFace = getParam("fillmode",True)
obj.Closed = False
obj.Points = []
self.assureProperties(obj)

def assureProperties(self, obj): # for Compatibility with older versions
if not hasattr(obj, "Parameterization"):
obj.addProperty("App::PropertyFloat","Parameterization","Draft","Parameterization factor")
obj.Parameterization = 1.0
self.knotSeq = []

def parameterization (self, pts, a, closed):
# Computes a knot Sequence for a set of points
# fac (0-1) : parameterization factor
# fac=0 -> Uniform / fac=0.5 -> Centripetal / fac=1.0 -> Chord-Length
if closed: # we need to add the first point as the end point
pts.append(pts[0])
params = [0]
for i in range(1,len(pts)):
p = pts[i].sub(pts[i-1])
pl = pow(p.Length,a)
params.append(params[-1] + pl)
return params

def onChanged(self, fp, prop):
if prop == "Parameterization":
if fp.Parameterization < 0.:
fp.Parameterization = 0.
if fp.Parameterization > 1.0:
fp.Parameterization = 1.0

def execute(self, obj):
import Part
from DraftTools import msg,translate
self.assureProperties(obj)
if obj.Points:
self.knotSeq = self.parameterization(obj.Points, obj.Parameterization, obj.Closed)
plm = obj.Placement
if obj.Closed and (len(obj.Points) > 2):
if obj.Points[0] == obj.Points[-1]: # should not occur, but OCC will crash
msg(translate('draft', "_BSpline.createGeometry: Closed with same first/last Point. Geometry not updated.\n"), "error")
return
spline = Part.BSplineCurve()
spline.interpolate(obj.Points, True)
spline.interpolate(obj.Points, PeriodicFlag = True, Parameters = self.knotSeq)
# DNC: bug fix: convert to face if closed
shape = Part.Wire(spline.toShape())
# Creating a face from a closed spline cannot be expected to always work
Expand All @@ -4617,7 +4646,7 @@ def execute(self, obj):
obj.Shape = shape
else:
spline = Part.BSplineCurve()
spline.interpolate(obj.Points, False)
spline.interpolate(obj.Points, PeriodicFlag = False, Parameters = self.knotSeq)
obj.Shape = spline.toShape()
obj.Placement = plm
obj.positionBySupport()
Expand Down