constraint: auto label constraint object with type name

This commit is contained in:
Zheng, Lei 2018-01-28 06:14:17 +08:00
parent a9b302c0ac
commit ac5194a013
3 changed files with 19 additions and 6 deletions

View File

@ -1027,12 +1027,10 @@ class AsmConstraint(AsmGroup):
constraints = sel.Assembly.Proxy.getConstraintGroup()
cstr = constraints.Document.addObject("App::FeaturePython",
name,AsmConstraint(constraints),None,True)
proxy = ViewProviderAsmConstraint(cstr.ViewObject)
logger.debug('cstr viewobject {},{},{},{}'.format(
id(proxy),id(cstr.ViewObject.Proxy),
id(proxy.ViewObject),id(cstr.ViewObject)))
ViewProviderAsmConstraint(cstr.ViewObject)
constraints.setLink({-1:cstr})
Constraint.setTypeID(cstr,typeid)
cstr.Label = Constraint.getTypeName(cstr)
try:
for e in sel.Elements:

View File

@ -398,8 +398,13 @@ class Constraint(ProxyType):
def onChanged(mcs,obj,prop):
if prop == mcs._disabled:
obj.ViewObject.signalChangeIcon()
return
return super(Constraint,mcs).onChanged(obj,prop)
if super(Constraint,mcs).onChanged(obj,prop):
try:
if obj.Name==obj.Label or \
mcs.getType(utils.getLabel(obj)):
obj.Label = mcs.getTypeName(obj)
except Exception as e:
logger.debug('auto constraint label failed: {}'.format(e))
@classmethod
def isDisabled(mcs,obj):

View File

@ -521,3 +521,13 @@ def edge2VertexIndex(obj,name,retInteger=False):
if retInteger:
return idx-1,idx2-1
return 'Vertex{}'.format(idx),'Vertex{}'.format(idx2)
def getLabel(obj):
'''Return object's label without trailing index'''
label = obj.Label
for i,c in enumerate(reversed(label)):
if not c.isdigit():
if i:
label = label[:-i]
break
return label