Fix constraint toolbar active checking
This commit is contained in:
parent
21e8c4dd84
commit
363a8cfeba
49
assembly.py
49
assembly.py
|
@ -908,18 +908,11 @@ class AsmConstraint(AsmGroup):
|
||||||
if len(sels)>1:
|
if len(sels)>1:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
'The selections must have a common (grand)parent assembly')
|
'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]
|
sel = sels[0]
|
||||||
|
subs = sel.SubElementNames
|
||||||
|
if not subs:
|
||||||
|
subs = ['']
|
||||||
|
|
||||||
cstr = None
|
cstr = None
|
||||||
elements = []
|
elements = []
|
||||||
elementInfo = []
|
elementInfo = []
|
||||||
|
@ -931,22 +924,11 @@ class AsmConstraint(AsmGroup):
|
||||||
raise RuntimeError('Cannot find sub-object {}.{}'.format(
|
raise RuntimeError('Cannot find sub-object {}.{}'.format(
|
||||||
sel.Object.Name,sub))
|
sel.Object.Name,sub))
|
||||||
ret = Assembly.find(sel.Object,sub,
|
ret = Assembly.find(sel.Object,sub,
|
||||||
recursive=True,relativeToChild=False)
|
recursive=True,relativeToChild=False,keepEmptyChild=True)
|
||||||
if not ret:
|
if not ret:
|
||||||
raise RuntimeError('Selection {}.{} is not from an '
|
raise RuntimeError('Selection {}.{} is not from an '
|
||||||
'assembly'.format(sel.Object.Name,sub))
|
'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:
|
if not assembly:
|
||||||
assembly = ret[0].Assembly
|
assembly = ret[0].Assembly
|
||||||
selSubname = sub[:-len(ret[0].Subname)]
|
selSubname = sub[:-len(ret[0].Subname)]
|
||||||
|
@ -962,14 +944,27 @@ class AsmConstraint(AsmGroup):
|
||||||
'assembly {}'.format(
|
'assembly {}'.format(
|
||||||
sel.Object.Name,sub,objName(assembly)))
|
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,
|
# because we call Assembly.find() above with relativeToChild=False,
|
||||||
# we shall adjust the element subname by popping the first '.'
|
# we shall adjust the element subname by popping the first '.'
|
||||||
sub = found.Subname
|
sub = found.Subname
|
||||||
sub = sub[sub.index('.')+1:]
|
sub = sub[sub.index('.')+1:]
|
||||||
if sub[-1] == '.' and \
|
if sub[-1] == '.' and \
|
||||||
not isTypeOf(sobj,Assembly,True) and \
|
not isTypeOf(sobj,(AsmElement,AsmElementLink)):
|
||||||
not isTypeOf(sobj,(AsmConstraint,AsmConstraintGroup,
|
|
||||||
AsmElement,AsmElementLink)):
|
|
||||||
# Too bad, its a full selection, let's guess the sub element
|
# Too bad, its a full selection, let's guess the sub element
|
||||||
if not utils.isElement((found.Object,sub)):
|
if not utils.isElement((found.Object,sub)):
|
||||||
raise RuntimeError('no sub element (face, edge, vertex) in '
|
raise RuntimeError('no sub element (face, edge, vertex) in '
|
||||||
|
@ -1680,6 +1675,8 @@ class AsmWorkPlane(object):
|
||||||
def getSelection(sels=None):
|
def getSelection(sels=None):
|
||||||
if not sels:
|
if not sels:
|
||||||
sels = FreeCADGui.Selection.getSelectionEx('',False)
|
sels = FreeCADGui.Selection.getSelectionEx('',False)
|
||||||
|
if not sels:
|
||||||
|
raise RuntimeError('no selection')
|
||||||
if len(sels)!=1 or len(sels[0].SubElementNames)>1:
|
if len(sels)!=1 or len(sels[0].SubElementNames)>1:
|
||||||
raise RuntimeError('too many selections')
|
raise RuntimeError('too many selections')
|
||||||
if sels[0].SubElementNames:
|
if sels[0].SubElementNames:
|
||||||
|
|
|
@ -333,10 +333,10 @@ class ConstraintCommand:
|
||||||
return self.tp._toolbarName
|
return self.tp._toolbarName
|
||||||
|
|
||||||
def workbenchActivated(self):
|
def workbenchActivated(self):
|
||||||
pass
|
self._active = None
|
||||||
|
|
||||||
def workbenchDeactivated(self):
|
def workbenchDeactivated(self):
|
||||||
self._active = None
|
pass
|
||||||
|
|
||||||
def getContextMenuName(self):
|
def getContextMenuName(self):
|
||||||
pass
|
pass
|
||||||
|
@ -739,8 +739,8 @@ class BaseMulti(Base):
|
||||||
_entityDef = (_wa,)
|
_entityDef = (_wa,)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def check(cls,group,_checkCount=False):
|
def check(cls,group,checkCount=False):
|
||||||
if len(group)<2:
|
if checkCount and len(group)<2:
|
||||||
raise RuntimeError('Constraint "{}" requires at least two '
|
raise RuntimeError('Constraint "{}" requires at least two '
|
||||||
'elements'.format(cls.getName()))
|
'elements'.format(cls.getName()))
|
||||||
for info in group:
|
for info in group:
|
||||||
|
@ -1089,10 +1089,12 @@ class SketchPlane(BaseSketch):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getEntityDef(cls,group,checkCount,obj=None):
|
def getEntityDef(cls,group,checkCount,obj=None):
|
||||||
|
_ = checkCount
|
||||||
|
_ = obj
|
||||||
if not group:
|
if not group:
|
||||||
# If no element, then this constraint serves the prupose of clearing
|
# If no element, then this constraint serves the prupose of clearing
|
||||||
# the current sketch plane
|
# the current sketch plane
|
||||||
return
|
return []
|
||||||
# if there is any child element in this constraint, we expect the first
|
# 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
|
# 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.
|
# entities must be from some draft wire or circle/arc.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user