Fix constraint toolbar active checking

This commit is contained in:
Zheng, Lei 2018-01-24 18:08:20 +08:00
parent 21e8c4dd84
commit 363a8cfeba
2 changed files with 30 additions and 31 deletions

View File

@ -908,18 +908,11 @@ class AsmConstraint(AsmGroup):
if len(sels)>1:
raise RuntimeError(
'The selections must have a common (grand)parent assembly')
subs = sels[0].SubElementNames
if not subs:
raise RuntimeError('no sub-object in selection')
if len(subs)>2:
raise RuntimeError('too many selection')
if len(subs)==2:
sobj = sels[0].Object.getSubObject(subs[1],1)
if isTypeOf(sobj,Assembly,True) or \
isTypeOf(sobj,(AsmConstraintGroup,AsmConstraint)):
subs = (subs[1],subs[0])
sel = sels[0]
subs = sel.SubElementNames
if not subs:
subs = ['']
cstr = None
elements = []
elementInfo = []
@ -931,22 +924,11 @@ class AsmConstraint(AsmGroup):
raise RuntimeError('Cannot find sub-object {}.{}'.format(
sel.Object.Name,sub))
ret = Assembly.find(sel.Object,sub,
recursive=True,relativeToChild=False)
recursive=True,relativeToChild=False,keepEmptyChild=True)
if not ret:
raise RuntimeError('Selection {}.{} is not from an '
'assembly'.format(sel.Object.Name,sub))
# check if the selection is a constraint group or a constraint
if isTypeOf(sobj,Assembly,True) or \
isTypeOf(sobj,(AsmConstraintGroup,Assembly,AsmConstraint)):
if assembly:
raise RuntimeError('no element selection')
assembly = ret[-1].Assembly
selSubname = sub[:-len(ret[-1].Subname)]
if isTypeOf(sobj,AsmConstraint):
cstr = sobj
continue
if not assembly:
assembly = ret[0].Assembly
selSubname = sub[:-len(ret[0].Subname)]
@ -962,14 +944,27 @@ class AsmConstraint(AsmGroup):
'assembly {}'.format(
sel.Object.Name,sub,objName(assembly)))
if isTypeOf(sobj,Assembly,True):
continue
# check if the selection is a constraint group or a constraint
if isTypeOf(sobj,Assembly,True) or \
isTypeOf(sobj,(AsmConstraintGroup,AsmConstraint)):
if isTypeOf(sobj,AsmConstraint):
if cstr:
raise RuntimeError('more than one constraint selected')
assembly = ret[-1].Assembly
selSubname = sub[:-len(ret[-1].Subname)]
cstr = sobj
continue
# because we call Assembly.find() above with relativeToChild=False,
# we shall adjust the element subname by popping the first '.'
sub = found.Subname
sub = sub[sub.index('.')+1:]
if sub[-1] == '.' and \
not isTypeOf(sobj,Assembly,True) and \
not isTypeOf(sobj,(AsmConstraint,AsmConstraintGroup,
AsmElement,AsmElementLink)):
not isTypeOf(sobj,(AsmElement,AsmElementLink)):
# Too bad, its a full selection, let's guess the sub element
if not utils.isElement((found.Object,sub)):
raise RuntimeError('no sub element (face, edge, vertex) in '
@ -1680,6 +1675,8 @@ class AsmWorkPlane(object):
def getSelection(sels=None):
if not sels:
sels = FreeCADGui.Selection.getSelectionEx('',False)
if not sels:
raise RuntimeError('no selection')
if len(sels)!=1 or len(sels[0].SubElementNames)>1:
raise RuntimeError('too many selections')
if sels[0].SubElementNames:

View File

@ -333,10 +333,10 @@ class ConstraintCommand:
return self.tp._toolbarName
def workbenchActivated(self):
pass
self._active = None
def workbenchDeactivated(self):
self._active = None
pass
def getContextMenuName(self):
pass
@ -739,8 +739,8 @@ class BaseMulti(Base):
_entityDef = (_wa,)
@classmethod
def check(cls,group,_checkCount=False):
if len(group)<2:
def check(cls,group,checkCount=False):
if checkCount and len(group)<2:
raise RuntimeError('Constraint "{}" requires at least two '
'elements'.format(cls.getName()))
for info in group:
@ -1089,10 +1089,12 @@ class SketchPlane(BaseSketch):
@classmethod
def getEntityDef(cls,group,checkCount,obj=None):
_ = checkCount
_ = obj
if not group:
# If no element, then this constraint serves the prupose of clearing
# the current sketch plane
return
return []
# if there is any child element in this constraint, we expect the first
# one to be a planar face or edge to define the work plane. The rest of
# entities must be from some draft wire or circle/arc.