constraint: fix negative distance in composite constraints

This commit is contained in:
Zheng, Lei 2018-03-21 15:43:48 +08:00
parent 55ba2c2b3c
commit 8cf3c3f48b
2 changed files with 17 additions and 22 deletions

View File

@ -124,9 +124,9 @@ def _n(solver,partInfo,subname,shape,retAll=False):
h.append(system.addTransform(e,*partInfo.Params,group=partInfo.Group))
# also add x axis pointing quaterion for convenience
rot = FreeCAD.Rotation(FreeCAD.Vector(0,1,0),90).multiply(rot)
xrot = FreeCAD.Rotation(FreeCAD.Vector(0,1,0),90).multiply(rot)
system.NameTag = nameTag + 'x'
e = system.addNormal3dV(*utils.getNormal(rot))
e = system.addNormal3dV(*utils.getNormal(xrot))
system.NameTag = nameTag + 'xt'
h.append(system.addTransform(e,*partInfo.Params,group=partInfo.Group))
@ -234,8 +234,8 @@ def _w(solver,partInfo,subname,shape,retAll=False):
p = _p(solver,partInfo,subname,shape)
n = _n(solver,partInfo,subname,shape,True)
system.NameTag = partInfo.PartName + '.' + key
h = system.addWorkplane(p,n[0],group=partInfo.Group)
h = [h,p] + n
w = system.addWorkplane(p,n[0],group=partInfo.Group)
h = [w,p] + n
system.log('{}: {},{}'.format(key,h,partInfo.Group))
partInfo.EntityMap[key] = h
return h if retAll else h[0]
@ -268,7 +268,7 @@ def _c(solver,partInfo,subname,shape,requireArc=False,retAll=False):
if utils.isDraftCircle(partInfo.Part):
part = partInfo.Part
w,p,n,_ = partInfo.Workplane
w,p,n = partInfo.Workplane[:3]
if system.sketchPlane and not solver.isFixedElement(part,subname):
system.NameTag = nameTag + '.o'
@ -312,7 +312,7 @@ def _c(solver,partInfo,subname,shape,requireArc=False,retAll=False):
sub = subname + '.c' if requireArc else '.a'
partInfo.EntityMap[sub] = h
else:
w,p,n,_ = _w(solver,partInfo,subname,shape,True)
w,p,n = _w(solver,partInfo,subname,shape,True)[:3]
r = utils.getElementCircular(shape)
if not r:
raise RuntimeError('shape is not cicular')

View File

@ -130,15 +130,12 @@ class SystemExtension(object):
def addPlaneCoincident(self,d,lockAngle,angle,e1,e2,group=0):
if not group:
group = self.GroupHandle
w1,p1,n1,nx1 = e1
w2,p2,n2,nx2 = e2
w1,p1,n1,nx1 = e1[:4]
_,p2,n2,nx2 = e2[:4]
h = []
if d:
if d>0.0:
h.append(self.addPointPlaneDistance(d,p1,w2,group=group))
else:
h.append(self.addPointPlaneDistance(d,p2,w1,group=group))
h.append(self.addPointsCoincident(p1,p2,w2,group=group))
h.append(self.addPointPlaneDistance(d,p2,w1,group=group))
h.append(self.addPointsCoincident(p1,p2,w1,group=group))
else:
h.append(self.addPointsCoincident(p1,p2,group=group))
return self.setOrientation(h,lockAngle,angle,n1,n2,nx1,nx2,group)
@ -146,24 +143,22 @@ class SystemExtension(object):
def addPlaneAlignment(self,d,lockAngle,angle,e1,e2,group=0):
if not group:
group = self.GroupHandle
w1,p1,n1,nx1 = e1
w2,p2,n2,nx2 = e2
w1,_,n1,nx1 = e1[:4]
_,p2,n2,nx2 = e2[:4]
h = []
if d>0.0:
h.append(self.addPointPlaneDistance(d,p1,w2,group=group))
elif d<0.0:
if d:
h.append(self.addPointPlaneDistance(d,p2,w1,group=group))
else:
h.append(self.addPointInPlane(p1,w2,group=group))
h.append(self.addPointInPlane(p2,w1,group=group))
return self.setOrientation(h,lockAngle,angle,n1,n2,nx1,nx2,group)
def addAxialAlignment(self,lockAngle,angle,e1,e2,group=0):
if not group:
group = self.GroupHandle
_,p1,n1,nx1 = e1
w2,p2,n2,nx2 = e2
w1,p1,n1,nx1 = e1[:4]
_,p2,n2,nx2 = e2[:4]
h = []
h.append(self.addPointsCoincident(p1,p2,w2,group=group))
h.append(self.addPointsCoincident(p1,p2,w1,group=group))
return self.setOrientation(h,lockAngle,angle,n1,n2,nx1,nx2,group)
def addMultiParallel(self,lockAngle,angle,e1,e2,group=0):