constraint: fix line plane parallel and perpendicular

This commit is contained in:
Zheng, Lei 2018-02-12 19:13:41 +08:00
parent 2dd360882a
commit 0e7e94941a
2 changed files with 41 additions and 10 deletions

View File

@ -207,6 +207,17 @@ def _ln(solver,partInfo,subname,shape,retAll=False):
return _l(solver,partInfo,subname,shape,retAll) return _l(solver,partInfo,subname,shape,retAll)
return _n(solver,partInfo,subname,shape) return _n(solver,partInfo,subname,shape)
def _lw(solver,partInfo,subname,shape,retAll=False):
'return a handle for either a line or a plane depending on the shape'
_ = retAll
if not solver:
if utils.isLinearEdge(shape) or utils.isPlanar(shape):
return
return 'a linear edge or edge/face with planar surface'
if utils.isLinearEdge(shape):
return _l(solver,partInfo,subname,shape,False)
return _wa(solver,partInfo,subname,shape)
def _w(solver,partInfo,subname,shape,retAll=False): def _w(solver,partInfo,subname,shape,retAll=False):
'return a handle of a transformed plane/workplane from "shape"' 'return a handle of a transformed plane/workplane from "shape"'
if not solver: if not solver:
@ -908,7 +919,7 @@ class SameOrientation(BaseMulti):
class MultiParallel(BaseMulti): class MultiParallel(BaseMulti):
_id = 291 _id = 291
_entityDef = (_ln,) _entityDef = (_lw,)
_iconName = 'Assembly_ConstraintMultiParallel.svg' _iconName = 'Assembly_ConstraintMultiParallel.svg'
_props = ['LockAngle','Angle'] _props = ['LockAngle','Angle']
_tooltip = 'Add a "{}" constraint to make planes normal or linear edges\n'\ _tooltip = 'Add a "{}" constraint to make planes normal or linear edges\n'\
@ -937,12 +948,28 @@ class Angle(Base2):
class Perpendicular(Base2): class Perpendicular(Base2):
_id = 28 _id = 28
_entityDef = (_ln,_ln) _entityDef = (_lw,_lw)
_workplane = True _workplane = True
_iconName = 'Assembly_ConstraintPerpendicular.svg' _iconName = 'Assembly_ConstraintPerpendicular.svg'
_tooltip = 'Add a "{}" constraint to make planes or linear edges of two\n'\ _tooltip = 'Add a "{}" constraint to make planes or linear edges of two\n'\
'parts perpendicular.' 'parts perpendicular.'
@classmethod
def prepare(cls,obj,solver):
system = solver.system
params = cls.getEntities(obj,solver)
e1,e2 = params[0],params[1]
isPlane = isinstance(e1,list),isinstance(e2,list)
if all(isPlane):
ret = system.addPerpendicular(e1[2],e2[2],group=solver.group)
elif not any(isPlane):
ret = system.addPerpendicular(e1,e2,group=solver.group)
elif isPlane[0]:
ret = system.addParallel(e1[2],e2,group=solver.group)
else:
ret = system.addParallel(e1,e2[2],group=solver.group)
return ret
class Parallel(Base2): class Parallel(Base2):
_id = -1 _id = -1
@ -993,7 +1020,7 @@ class PointsDistance(Base2):
class PointsProjectDistance(Base2): class PointsProjectDistance(Base2):
_id = 6 _id = 6
_entityDef = (_p,_p,_ln) _entityDef = (_p,_p,_l)
_props = ["Distance"] _props = ["Distance"]
_iconName = 'Assembly_ConstraintPointsProjectDistance.svg' _iconName = 'Assembly_ConstraintPointsProjectDistance.svg'
_tooltip = 'Add a "{}" to constrain the distance of two points\n' \ _tooltip = 'Add a "{}" to constrain the distance of two points\n' \

View File

@ -161,16 +161,20 @@ class SystemExtension(object):
w2,p2,n2,nx2 = e2 w2,p2,n2,nx2 = e2
h = [] h = []
h.append(self.addPointsCoincident(p1,p2,w2,group=group)) h.append(self.addPointsCoincident(p1,p2,w2,group=group))
h.append(self.addParallel(n1,n2,group=group)) return self.setOrientation(h,lockAngle,angle,n1,n2,nx1,nx2,group)
if lockAngle:
h.append(self.addAngle(angle,False,nx1,nx2,group=group))
return h
def addMultiParallel(self,lockAngle,angle,e1,e2,group=0): def addMultiParallel(self,lockAngle,angle,e1,e2,group=0):
h = [] h = []
isPlane = isinstance(e1,list),isinstance(e2,list)
if all(isPlane):
return self.setOrientation(
h,lockAngle,angle,e1[2],e2[2],e1[3],e2[3],group);
if not any(isPlane):
h.append(self.addParallel(e1,e2,group=group)) h.append(self.addParallel(e1,e2,group=group))
if lockAngle: elif isPlane[0]:
h.append(self.addAngle(angle,False,e1,e2,group=group)) h.append(self.addPerpendicular(e1[2],e2,group=group))
else:
h.append(self.addPerpendicular(e1,e2[2],group=group))
return h return h
def addColinear(self,e1,e2,wrkpln=0,group=0): def addColinear(self,e1,e2,wrkpln=0,group=0):