assembly: improve element auto naming

If a new element is created pointing to a named element, it will
inherit its name. If not, then check to see if the element is pointing
to an origin feature or datum, and inherit its name if so.
This commit is contained in:
Zheng, Lei 2020-02-05 12:00:12 +08:00
parent 9a9cdb8ac5
commit c59ad55f68

View File

@ -964,6 +964,7 @@ class AsmElement(AsmBase):
elements = group.Proxy.getAssembly().getElementGroup() elements = group.Proxy.getAssembly().getElementGroup()
idx = -1 idx = -1
newElement = False
if not element: if not element:
if not allowDuplicate: if not allowDuplicate:
# try to search the element group for an existing element # try to search the element group for an existing element
@ -976,6 +977,7 @@ class AsmElement(AsmBase):
r = getattr(e,'Radius',None) r = getattr(e,'Radius',None)
if (not radius and not r) or radius==r: if (not radius and not r) or radius==r:
return e return e
newElement = True
element = AsmElement.create(name,elements) element = AsmElement.create(name,elements)
if radius: if radius:
element.addProperty('App::PropertyFloat','Radius','','') element.addProperty('App::PropertyFloat','Radius','','')
@ -986,6 +988,31 @@ class AsmElement(AsmBase):
elements.cacheChildLabel() elements.cacheChildLabel()
element.setLink(sobj,subname[dot+1:]) element.setLink(sobj,subname[dot+1:])
if newElement:
linked = element.LinkedObject
objPath = None
if isinstance(linked,tuple):
objPath = logger.catchDebug('', linked[0].getSubObjectList, linked[1])
if objPath and len(objPath)>2 \
and isTypeOf(objPath[2], AsmElement) \
and objPath[2].Label != objPath[2].Name \
and objPath[2].Label != '_' + objPath[2].Name:
assembly = objPath[2].Proxy.getAssembly().Object
label = objPath[2].Label
idx = label.rfind('@')
if idx > 0:
label = label[:idx]
element.Label = label + '@' + assembly.Label
else:
target = element.getLinkedObject(True)
if target and (target.isDerivedFrom('App::OriginFeature') \
or target.isDerivedFrom('Part::Datum')):
label = target.Label
parent = target.getParentGeoFeatureGroup()
if parent:
label += '@' + parent.Label
element.Label = label
element.recompute() element.recompute()
if undo: if undo:
FreeCAD.closeActiveTransaction() FreeCAD.closeActiveTransaction()