constraint: auto label constraint object with type name
This commit is contained in:
parent
a9b302c0ac
commit
ac5194a013
|
@ -1027,12 +1027,10 @@ class AsmConstraint(AsmGroup):
|
||||||
constraints = sel.Assembly.Proxy.getConstraintGroup()
|
constraints = sel.Assembly.Proxy.getConstraintGroup()
|
||||||
cstr = constraints.Document.addObject("App::FeaturePython",
|
cstr = constraints.Document.addObject("App::FeaturePython",
|
||||||
name,AsmConstraint(constraints),None,True)
|
name,AsmConstraint(constraints),None,True)
|
||||||
proxy = ViewProviderAsmConstraint(cstr.ViewObject)
|
ViewProviderAsmConstraint(cstr.ViewObject)
|
||||||
logger.debug('cstr viewobject {},{},{},{}'.format(
|
|
||||||
id(proxy),id(cstr.ViewObject.Proxy),
|
|
||||||
id(proxy.ViewObject),id(cstr.ViewObject)))
|
|
||||||
constraints.setLink({-1:cstr})
|
constraints.setLink({-1:cstr})
|
||||||
Constraint.setTypeID(cstr,typeid)
|
Constraint.setTypeID(cstr,typeid)
|
||||||
|
cstr.Label = Constraint.getTypeName(cstr)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for e in sel.Elements:
|
for e in sel.Elements:
|
||||||
|
|
|
@ -398,8 +398,13 @@ class Constraint(ProxyType):
|
||||||
def onChanged(mcs,obj,prop):
|
def onChanged(mcs,obj,prop):
|
||||||
if prop == mcs._disabled:
|
if prop == mcs._disabled:
|
||||||
obj.ViewObject.signalChangeIcon()
|
obj.ViewObject.signalChangeIcon()
|
||||||
return
|
if super(Constraint,mcs).onChanged(obj,prop):
|
||||||
return 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
|
@classmethod
|
||||||
def isDisabled(mcs,obj):
|
def isDisabled(mcs,obj):
|
||||||
|
|
10
utils.py
10
utils.py
|
@ -521,3 +521,13 @@ def edge2VertexIndex(obj,name,retInteger=False):
|
||||||
if retInteger:
|
if retInteger:
|
||||||
return idx-1,idx2-1
|
return idx-1,idx2-1
|
||||||
return 'Vertex{}'.format(idx),'Vertex{}'.format(idx2)
|
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user