From 32e654cb24ab94c3670bdeb026496859d2a9c63e Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Fri, 26 Jan 2024 16:25:35 +0100 Subject: [PATCH] Assembly : Fixes for sketches in bodies --- src/Mod/Assembly/App/AssemblyObject.cpp | 6 +++--- src/Mod/Assembly/JointObject.py | 13 ++++++++++++ src/Mod/Assembly/UtilsAssembly.py | 27 ++++++++++++++++--------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/Mod/Assembly/App/AssemblyObject.cpp b/src/Mod/Assembly/App/AssemblyObject.cpp index fab9d80184..359d00ef4c 100644 --- a/src/Mod/Assembly/App/AssemblyObject.cpp +++ b/src/Mod/Assembly/App/AssemblyObject.cpp @@ -1643,16 +1643,16 @@ App::DocumentObject* AssemblyObject::getObjFromNameProp(App::DocumentObject* joi return containingPart; } - if (containingPart->getTypeId().isDerivedFrom(App::Link::getClassTypeId())) { + /*if (containingPart->getTypeId().isDerivedFrom(App::Link::getClassTypeId())) { App::Link* link = dynamic_cast(containingPart); containingPart = link->getLinkedObject(); if (!containingPart) { return nullptr; } - } + }*/ - for (auto obj : containingPart->getOutList()) { + for (auto obj : containingPart->getOutListRecursive()) { if (objName == obj->getNameInDocument()) { return obj; } diff --git a/src/Mod/Assembly/JointObject.py b/src/Mod/Assembly/JointObject.py index f186a7da89..d927806c45 100644 --- a/src/Mod/Assembly/JointObject.py +++ b/src/Mod/Assembly/JointObject.py @@ -81,6 +81,19 @@ def solveIfAllowed(assembly, storePrev=False): assembly.solve(storePrev) +# The joint object consists of 2 JCS (joint coordinate systems) and a Joint Type. +# A JCS is a placement that is computed (unless it is detached) from : +# - An Object name: this is the name of the solid. It can be any Part::Feature solid. +# Or a PartDesign Body. Or a App::Link to those. We use the name and not directly the DocumentObject +# because the object can be external. +# - A Part DocumentObject : This is the lowest level containing part. It can be either the Object itself if it +# stands alone. Or a App::Part. Or a App::Link to a App::Part. +# For example : +# Assembly.Assembly1.Part1.Part2.Box : Object is Box, part is 'Part1' +# Assembly.Assembly1.LinkToPart1.Part2.Box : Object is Box, part is 'LinkToPart1' +# - An element name: This can be either a face, an edge, a vertex or empty. Empty means that the Object placement will be used +# - A vertex name: For faces and edges, we need to specify which vertex of said face/edge to use +# From these a placement is computed. It is relative to the Object. class Joint: def __init__(self, joint, type_index): joint.Proxy = self diff --git a/src/Mod/Assembly/UtilsAssembly.py b/src/Mod/Assembly/UtilsAssembly.py index 7e2630160a..ce7b09bb72 100644 --- a/src/Mod/Assembly/UtilsAssembly.py +++ b/src/Mod/Assembly/UtilsAssembly.py @@ -132,7 +132,11 @@ def getObject(full_name): linked_obj = obj.getLinkedObject() if linked_obj.TypeId == "PartDesign::Body": if i + 1 < len(names): - obj2 = doc.getObject(names[i + 1]) + obj2 = None + for obji in obj.OutList: + if obji.Name == names[i + 1]: + obj2 = obji + break if obj2 and isBodySubObject(obj2.TypeId): return obj2 return obj @@ -148,7 +152,11 @@ def getObject(full_name): elif obj.TypeId == "PartDesign::Body": if i + 1 < len(names): - obj2 = doc.getObject(names[i + 1]) + obj2 = None + for obji in obj.OutList: + if obji.Name == names[i + 1]: + obj2 = obji + break if obj2 and isBodySubObject(obj2.TypeId): return obj2 return obj @@ -174,6 +182,7 @@ def getContainingPart(full_name, selected_object, activeAssemblyOrPart=None): # full_name is "Assembly.Assembly1.LinkOrPart1.LinkOrBox.Edge16" -> LinkOrPart1 # or "Assembly.Assembly1.LinkOrPart1.LinkOrBody.pad.Edge16" -> LinkOrPart1 # or "Assembly.Assembly1.LinkOrPart1.LinkOrBody.Sketch.Edge1" -> LinkOrBody + if selected_object is None: App.Console.PrintError("getContainingPart() in UtilsAssembly.py selected_object is None") return None @@ -196,15 +205,15 @@ def getContainingPart(full_name, selected_object, activeAssemblyOrPart=None): return selected_object if obj.TypeId == "PartDesign::Body" and isBodySubObject(selected_object.TypeId): - if obj.hasObject(selected_object, True): + if selected_object in obj.OutListRecursive: return obj # Note here we may want to specify a specific behavior for Assembly::AssemblyObject. if obj.TypeId == "App::Part": - if obj.hasObject(selected_object, True): + if selected_object in obj.OutListRecursive: if not activeAssemblyOrPart: return obj - elif obj.hasObject(activeAssemblyOrPart, True) or obj == activeAssemblyOrPart: + elif activeAssemblyOrPart in obj.OutListRecursive or obj == activeAssemblyOrPart: continue else: return obj @@ -212,16 +221,16 @@ def getContainingPart(full_name, selected_object, activeAssemblyOrPart=None): elif obj.TypeId == "App::Link": linked_obj = obj.getLinkedObject() if linked_obj.TypeId == "PartDesign::Body" and isBodySubObject(selected_object.TypeId): - if linked_obj.hasObject(selected_object, True): + if selected_object in linked_obj.OutListRecursive: return obj if linked_obj.TypeId == "App::Part": # linked_obj_doc = linked_obj.Document # selected_obj_in_doc = doc.getObject(selected_object.Name) - if linked_obj.hasObject(selected_object, True): + if selected_object in linked_obj.OutListRecursive: if not activeAssemblyOrPart: return obj elif (linked_obj.Document == activeAssemblyOrPart.Document) and ( - linked_obj.hasObject(activeAssemblyOrPart, True) + activeAssemblyOrPart in linked_obj.OutListRecursive or linked_obj == activeAssemblyOrPart ): continue @@ -245,7 +254,7 @@ def getObjectInPart(objName, part): "App::DocumentObjectGroup", "PartDesign::Body", }: - for obji in part.OutList: + for obji in part.OutListRecursive: if obji.Name == objName: return obji