Assembly: define nested assemblies. Fixes 12440
This commit is contained in:
committed by
Yorik van Havre
parent
9f8810aa4c
commit
2cf789a45f
@@ -426,6 +426,12 @@ std::vector<App::DocumentObject*> 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<std::pair<App::DocumentObject*, do
|
||||
objMasses = objectMasses;
|
||||
}
|
||||
|
||||
std::vector<AssemblyObject*> AssemblyObject::getSubAssemblies()
|
||||
{
|
||||
std::vector<AssemblyObject*> subAssemblies = {};
|
||||
|
||||
App::Document* doc = getDocument();
|
||||
|
||||
std::vector<DocumentObject*> assemblies =
|
||||
doc->getObjectsOfType(Assembly::AssemblyObject::getClassTypeId());
|
||||
for (auto assembly : assemblies) {
|
||||
if (hasObject(assembly)) {
|
||||
subAssemblies.push_back(dynamic_cast<AssemblyObject*>(assembly));
|
||||
}
|
||||
}
|
||||
|
||||
return subAssemblies;
|
||||
}
|
||||
|
||||
void AssemblyObject::updateGroundedJointsPlacements()
|
||||
{
|
||||
std::vector<App::DocumentObject*> groundedJoints = getGroundedJoints();
|
||||
|
||||
for (auto gJoint : groundedJoints) {
|
||||
if (!gJoint) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* propObj =
|
||||
dynamic_cast<App::PropertyLink*>(gJoint->getPropertyByName("ObjectToGround"));
|
||||
auto* propPlc =
|
||||
dynamic_cast<App::PropertyPlacement*>(gJoint->getPropertyByName("Placement"));
|
||||
|
||||
if (propObj && propPlc) {
|
||||
App::DocumentObject* obj = propObj->getValue();
|
||||
auto* propObjPlc =
|
||||
dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName("Placement"));
|
||||
propPlc->setValue(propObjPlc->getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ======================================= Utils ======================================
|
||||
|
||||
void AssemblyObject::swapJCS(App::DocumentObject* joint)
|
||||
|
||||
@@ -197,6 +197,8 @@ public:
|
||||
double getObjMass(App::DocumentObject* obj);
|
||||
void setObjMasses(std::vector<std::pair<App::DocumentObject*, double>> objectMasses);
|
||||
|
||||
std::vector<AssemblyObject*> getSubAssemblies();
|
||||
void updateGroundedJointsPlacements();
|
||||
|
||||
private:
|
||||
std::shared_ptr<MbD::ASMTAssembly> mbdAssembly;
|
||||
|
||||
@@ -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<AssemblyObject*>(getObject());
|
||||
assembly->updateGroundedJointsPlacements();
|
||||
|
||||
setDragger();
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user