Draft: get_movable_children: prevent endless loop

Forum topic:
https://forum.freecad.org/viewtopic.php?t=81547
This commit is contained in:
Roy-043
2023-09-28 15:19:25 +02:00
parent 2f069bb94f
commit 4cf613ec31

View File

@@ -276,7 +276,7 @@ def getGroupContents(objectslist,
spaces, noarchchild)
def get_movable_children(objectslist, recursive=True):
def get_movable_children(objectslist, recursive=True, _donelist=[]):
"""Return a list of objects with child objects that move with a host.
Builds a list of objects with all child objects (`obj.OutList`)
@@ -295,6 +295,9 @@ def get_movable_children(objectslist, recursive=True):
Otherwise, only direct children of the input objects
are added to the output list.
_donelist: list
List of object names. Used internally to prevent an endless loop.
Returns
-------
list
@@ -306,8 +309,14 @@ def get_movable_children(objectslist, recursive=True):
objectslist = [objectslist]
for obj in objectslist:
if obj.Name in _donelist:
continue
_donelist.append(obj.Name)
# Skips some objects that should never move their children
if utils.get_type(obj) not in ("Clone", "SectionPlane",
if utils.get_type(obj) not in ("App::Part", "PartDesign::Body",
"Clone", "SectionPlane",
"Facebinder", "BuildingPart", "App::Link"):
children = obj.OutList
if (hasattr(obj, "Proxy") and obj.Proxy
@@ -318,17 +327,14 @@ def get_movable_children(objectslist, recursive=True):
for child in children:
if hasattr(child, "MoveWithHost") and child.MoveWithHost:
if hasattr(obj, "CloneOf"):
if obj.CloneOf:
if obj.CloneOf.Name != child.Name:
added.append(child)
else:
if hasattr(obj, "CloneOf") and obj.CloneOf:
if obj.CloneOf.Name != child.Name:
added.append(child)
else:
added.append(child)
if recursive:
added.extend(get_movable_children(children))
added.extend(get_movable_children(children, recursive, _donelist))
return added