From 0e7e94941ab6d2ab8c01080d6d9d80008d7c7aa3 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Mon, 12 Feb 2018 19:13:41 +0800 Subject: [PATCH] constraint: fix line plane parallel and perpendicular --- constraint.py | 33 ++++++++++++++++++++++++++++++--- system.py | 18 +++++++++++------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/constraint.py b/constraint.py index b784168..bc0a4e7 100644 --- a/constraint.py +++ b/constraint.py @@ -207,6 +207,17 @@ def _ln(solver,partInfo,subname,shape,retAll=False): return _l(solver,partInfo,subname,shape,retAll) 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): 'return a handle of a transformed plane/workplane from "shape"' if not solver: @@ -908,7 +919,7 @@ class SameOrientation(BaseMulti): class MultiParallel(BaseMulti): _id = 291 - _entityDef = (_ln,) + _entityDef = (_lw,) _iconName = 'Assembly_ConstraintMultiParallel.svg' _props = ['LockAngle','Angle'] _tooltip = 'Add a "{}" constraint to make planes normal or linear edges\n'\ @@ -937,12 +948,28 @@ class Angle(Base2): class Perpendicular(Base2): _id = 28 - _entityDef = (_ln,_ln) + _entityDef = (_lw,_lw) _workplane = True _iconName = 'Assembly_ConstraintPerpendicular.svg' _tooltip = 'Add a "{}" constraint to make planes or linear edges of two\n'\ '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): _id = -1 @@ -993,7 +1020,7 @@ class PointsDistance(Base2): class PointsProjectDistance(Base2): _id = 6 - _entityDef = (_p,_p,_ln) + _entityDef = (_p,_p,_l) _props = ["Distance"] _iconName = 'Assembly_ConstraintPointsProjectDistance.svg' _tooltip = 'Add a "{}" to constrain the distance of two points\n' \ diff --git a/system.py b/system.py index fbebf1c..dbd4a1f 100644 --- a/system.py +++ b/system.py @@ -161,16 +161,20 @@ class SystemExtension(object): w2,p2,n2,nx2 = e2 h = [] h.append(self.addPointsCoincident(p1,p2,w2,group=group)) - h.append(self.addParallel(n1,n2,group=group)) - if lockAngle: - h.append(self.addAngle(angle,False,nx1,nx2,group=group)) - return h + return self.setOrientation(h,lockAngle,angle,n1,n2,nx1,nx2,group) def addMultiParallel(self,lockAngle,angle,e1,e2,group=0): h = [] - h.append(self.addParallel(e1,e2,group=group)) - if lockAngle: - h.append(self.addAngle(angle,False,e1,e2,group=group)) + 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)) + elif isPlane[0]: + h.append(self.addPerpendicular(e1[2],e2,group=group)) + else: + h.append(self.addPerpendicular(e1,e2[2],group=group)) return h def addColinear(self,e1,e2,wrkpln=0,group=0):