constraint: add OffsetX and offsetY to PlaneCoincident
This commit is contained in:
parent
094828561b
commit
fe7a1757cb
|
@ -519,6 +519,8 @@ def _makeProp(name,tp,doc='',getter=propGet,internal=False,default=None):
|
||||||
_makeProp('Distance','App::PropertyDistance',getter=propGetValue)
|
_makeProp('Distance','App::PropertyDistance',getter=propGetValue)
|
||||||
_makeProp('Length','App::PropertyDistance',getter=propGetValue,default=5.0)
|
_makeProp('Length','App::PropertyDistance',getter=propGetValue,default=5.0)
|
||||||
_makeProp('Offset','App::PropertyDistance',getter=propGetValue)
|
_makeProp('Offset','App::PropertyDistance',getter=propGetValue)
|
||||||
|
_makeProp('OffsetX','App::PropertyDistance',getter=propGetValue)
|
||||||
|
_makeProp('OffsetY','App::PropertyDistance',getter=propGetValue)
|
||||||
_makeProp('Cascade','App::PropertyBool',internal=True)
|
_makeProp('Cascade','App::PropertyBool',internal=True)
|
||||||
_makeProp('Angle','App::PropertyAngle',getter=propGetValue)
|
_makeProp('Angle','App::PropertyAngle',getter=propGetValue)
|
||||||
|
|
||||||
|
@ -910,7 +912,7 @@ class BaseCascade(BaseMulti):
|
||||||
class PlaneCoincident(BaseCascade):
|
class PlaneCoincident(BaseCascade):
|
||||||
_id = 35
|
_id = 35
|
||||||
_iconName = 'Assembly_ConstraintCoincidence.svg'
|
_iconName = 'Assembly_ConstraintCoincidence.svg'
|
||||||
_props = ['Cascade','Offset'] + _AngleProps
|
_props = ['Cascade','Offset','OffsetX','OffsetY'] + _AngleProps
|
||||||
_tooltip = \
|
_tooltip = \
|
||||||
'Add a "{}" constraint to conincide planes of two or more parts.\n'\
|
'Add a "{}" constraint to conincide planes of two or more parts.\n'\
|
||||||
'The planes are coincided at their centers with an optional distance.'
|
'The planes are coincided at their centers with an optional distance.'
|
||||||
|
|
61
system.py
61
system.py
|
@ -152,11 +152,11 @@ class SystemExtension(object):
|
||||||
else:
|
else:
|
||||||
logger.info('auto relax ' + msg, frame=1)
|
logger.info('auto relax ' + msg, frame=1)
|
||||||
|
|
||||||
def countConstraints(self,increment,count,*names):
|
def countConstraints(self,increment,limit,*names):
|
||||||
first,second = self.firstInfo,self.secondInfo
|
first,second = self.firstInfo,self.secondInfo
|
||||||
if not first or not second:
|
if not first or not second:
|
||||||
return
|
return 0
|
||||||
ret = 0
|
count = 0
|
||||||
for name in names:
|
for name in names:
|
||||||
cstrs = first.CstrMap.get(second.Part,{}).get(name,None)
|
cstrs = first.CstrMap.get(second.Part,{}).get(name,None)
|
||||||
if not cstrs:
|
if not cstrs:
|
||||||
|
@ -167,23 +167,34 @@ class SystemExtension(object):
|
||||||
cstrs = second.CstrMap.get(first.Part,{}).get(name,[])
|
cstrs = second.CstrMap.get(first.Part,{}).get(name,[])
|
||||||
if increment:
|
if increment:
|
||||||
cstrs += [None]*increment
|
cstrs += [None]*increment
|
||||||
ret += len(cstrs)
|
count += len(cstrs)
|
||||||
if count and ret>=count:
|
if limit and count>=limit:
|
||||||
if ret>count:
|
if count>limit:
|
||||||
self.reportRedundancy(True)
|
self.reportRedundancy(True)
|
||||||
return -1
|
return -1
|
||||||
elif ret!=len(cstrs):
|
elif count>len(cstrs):
|
||||||
self.reportRedundancy()
|
self.reportRedundancy()
|
||||||
return ret
|
return count
|
||||||
|
|
||||||
def addPlaneCoincident(
|
def addPlaneCoincident(
|
||||||
self, d, lockAngle, yaw, pitch, roll, pln1, pln2, group=0):
|
self, d, dx, dy, lockAngle, yaw, pitch, roll, pln1, pln2, group=0):
|
||||||
if not group:
|
if not group:
|
||||||
group = self.GroupHandle
|
group = self.GroupHandle
|
||||||
h = []
|
h = []
|
||||||
count = self.countConstraints(2 if lockAngle else 1,2,'Coincident')
|
|
||||||
if count<0:
|
count=self.countConstraints(2 if lockAngle else 1,2,'Coincident')
|
||||||
|
if count < 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if d or dx or dy:
|
||||||
|
dx,dy,d = pln2.normal.rot.multVec(FreeCAD.Vector(dx,dy,d))
|
||||||
|
v = pln2.origin.vertex+FreeCAD.Vector(dx,dy,d)
|
||||||
|
e = self.addTransform(
|
||||||
|
self.addPoint3dV(*v),*pln2.origin.params,group=group)
|
||||||
|
else:
|
||||||
|
v = pln2.origin.vertex
|
||||||
|
e = pln2.origin.entity
|
||||||
|
|
||||||
if not lockAngle and count==2:
|
if not lockAngle and count==2:
|
||||||
# if there is already some other plane coincident constraint set for
|
# if there is already some other plane coincident constraint set for
|
||||||
# this pair of parts, we reduce this second constraint to either a
|
# this pair of parts, we reduce this second constraint to either a
|
||||||
|
@ -193,23 +204,17 @@ class SystemExtension(object):
|
||||||
# We project the initial points to the first element plane, and
|
# We project the initial points to the first element plane, and
|
||||||
# check for differences in x and y components of the points to
|
# check for differences in x and y components of the points to
|
||||||
# determine whether to use horizontal or vertical constraint.
|
# determine whether to use horizontal or vertical constraint.
|
||||||
v1,v2 = project2D(pln1.normal.rot,
|
v1,v2 = project2D(pln1.normal.rot, pln1.origin.vertex, v)
|
||||||
pln1.origin.vertex, pln2.origin.vertex)
|
|
||||||
if abs(v1.x-v2.x) < abs(v1.y-v2.y):
|
if abs(v1.x-v2.x) < abs(v1.y-v2.y):
|
||||||
h.append(self.addPointsHorizontal(pln1.origin.entity,
|
h.append(self.addPointsHorizontal(
|
||||||
pln2.origin.entity, pln1.entity, group=group))
|
pln1.origin.entity, e, pln1.entity, group=group))
|
||||||
else:
|
else:
|
||||||
h.append(self.addPointsVertical(pln1.origin.entity,
|
h.append(self.addPointsVertical(
|
||||||
pln2.origin.entity, pln1.entity, group=group))
|
pln1.origin.entity, e, pln1.entity, group=group))
|
||||||
return h
|
return h
|
||||||
if d:
|
|
||||||
h.append(self.addPointPlaneDistance(
|
h.append(self.addPointsCoincident(pln1.origin.entity, e, group=group))
|
||||||
d, pln2.origin.entity, pln1.entity, group=group))
|
|
||||||
h.append(self.addPointsCoincident(pln1.origin.entity,
|
|
||||||
pln2.origin.entity, pln1.entity, group=group))
|
|
||||||
else:
|
|
||||||
h.append(self.addPointsCoincident(
|
|
||||||
pln1.origin.entity, pln2.origin.entity, group=group))
|
|
||||||
return self.setOrientation(h, lockAngle, yaw, pitch, roll,
|
return self.setOrientation(h, lockAngle, yaw, pitch, roll,
|
||||||
pln1.normal, pln2.normal, group)
|
pln1.normal, pln2.normal, group)
|
||||||
|
|
||||||
|
@ -219,7 +224,7 @@ class SystemExtension(object):
|
||||||
h = []
|
h = []
|
||||||
if self.relax:
|
if self.relax:
|
||||||
count = self.countConstraints(2 if lockAngle else 1,3,'Alignment')
|
count = self.countConstraints(2 if lockAngle else 1,3,'Alignment')
|
||||||
if count<0:
|
if count < 0:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
count = 0
|
count = 0
|
||||||
|
@ -240,10 +245,10 @@ class SystemExtension(object):
|
||||||
if not group:
|
if not group:
|
||||||
group = self.GroupHandle
|
group = self.GroupHandle
|
||||||
count = self.countConstraints(0,2,'Coincident')
|
count = self.countConstraints(0,2,'Coincident')
|
||||||
if count<0:
|
if count < 0:
|
||||||
return
|
return
|
||||||
if count:
|
if count:
|
||||||
return self.addPlaneCoincident(0,False,0,0,0,pln1,pln2,group)
|
return self.addPlaneCoincident(0,0,0,False,0,0,0,pln1,pln2,group)
|
||||||
h = []
|
h = []
|
||||||
h.append(self.addPointsCoincident(pln1.origin.entity,
|
h.append(self.addPointsCoincident(pln1.origin.entity,
|
||||||
pln2.origin.entity, pln2.entity, group=group))
|
pln2.origin.entity, pln2.entity, group=group))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user