From ac5194a0133d3074cecdd4f77de4378cd4f03001 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sun, 28 Jan 2018 06:14:17 +0800 Subject: [PATCH] constraint: auto label constraint object with type name --- assembly.py | 6 ++---- constraint.py | 9 +++++++-- utils.py | 10 ++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/assembly.py b/assembly.py index 08a8c22..91e710c 100644 --- a/assembly.py +++ b/assembly.py @@ -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: diff --git a/constraint.py b/constraint.py index 545894d..af2b4df 100644 --- a/constraint.py +++ b/constraint.py @@ -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): diff --git a/utils.py b/utils.py index 54d8139..24d55d0 100644 --- a/utils.py +++ b/utils.py @@ -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