diff --git a/src/Mod/Assembly/App/AssemblyObject.cpp b/src/Mod/Assembly/App/AssemblyObject.cpp index 22f1514103..f37713ff7a 100644 --- a/src/Mod/Assembly/App/AssemblyObject.cpp +++ b/src/Mod/Assembly/App/AssemblyObject.cpp @@ -426,6 +426,12 @@ std::vector AssemblyObject::getJoints(bool updateJCS) } } + // add sub assemblies joints. + for (auto& assembly : getSubAssemblies()) { + auto subJoints = assembly->getJoints(updateJCS); + joints.insert(joints.end(), subJoints.begin(), subJoints.end()); + } + // Make sure the joints are up to date. if (updateJCS) { recomputeJointPlacements(joints); @@ -1194,6 +1200,46 @@ void AssemblyObject::setObjMasses(std::vector AssemblyObject::getSubAssemblies() +{ + std::vector subAssemblies = {}; + + App::Document* doc = getDocument(); + + std::vector assemblies = + doc->getObjectsOfType(Assembly::AssemblyObject::getClassTypeId()); + for (auto assembly : assemblies) { + if (hasObject(assembly)) { + subAssemblies.push_back(dynamic_cast(assembly)); + } + } + + return subAssemblies; +} + +void AssemblyObject::updateGroundedJointsPlacements() +{ + std::vector groundedJoints = getGroundedJoints(); + + for (auto gJoint : groundedJoints) { + if (!gJoint) { + continue; + } + + auto* propObj = + dynamic_cast(gJoint->getPropertyByName("ObjectToGround")); + auto* propPlc = + dynamic_cast(gJoint->getPropertyByName("Placement")); + + if (propObj && propPlc) { + App::DocumentObject* obj = propObj->getValue(); + auto* propObjPlc = + dynamic_cast(obj->getPropertyByName("Placement")); + propPlc->setValue(propObjPlc->getValue()); + } + } +} + // ======================================= Utils ====================================== void AssemblyObject::swapJCS(App::DocumentObject* joint) diff --git a/src/Mod/Assembly/App/AssemblyObject.h b/src/Mod/Assembly/App/AssemblyObject.h index b2cbd2e9e5..1971a07cb6 100644 --- a/src/Mod/Assembly/App/AssemblyObject.h +++ b/src/Mod/Assembly/App/AssemblyObject.h @@ -197,6 +197,8 @@ public: double getObjMass(App::DocumentObject* obj); void setObjMasses(std::vector> objectMasses); + std::vector getSubAssemblies(); + void updateGroundedJointsPlacements(); private: std::shared_ptr mbdAssembly; diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp index 4fd58c25d8..4058b5dff4 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp @@ -196,6 +196,12 @@ bool ViewProviderAssembly::setEdit(int ModNum) this->getObject()->getDocument()->getName(), this->getObject()->getNameInDocument()); + // When we set edit, we update the grounded joints placements to support : + // - If user transformed the grounded object + // - For nested assemblies where the grounded object moves around. + auto* assembly = static_cast(getObject()); + assembly->updateGroundedJointsPlacements(); + setDragger(); return true;