Assembly: Prevent crash when toggling rigid of grounded sub assembly (#24761)
* Assembly: Prevent crash when toggling rigid of grounded sub assembly * to squash * to squash * Update AssemblyLink.cpp
This commit is contained in:
@@ -101,6 +101,26 @@ void AssemblyLink::onChanged(const App::Property* prop)
|
||||
if (prop == &Rigid) {
|
||||
Base::Placement movePlc;
|
||||
|
||||
// A flexible sub-assembly cannot be grounded.
|
||||
// If a rigid sub-assembly has an object that is grounded, we also remove it.
|
||||
auto groundedJoints = getParentAssembly()->getGroundedJoints();
|
||||
for (auto* joint : groundedJoints) {
|
||||
auto* propObj =
|
||||
dynamic_cast<App::PropertyLink*>(joint->getPropertyByName("ObjectToGround"));
|
||||
if (!propObj) {
|
||||
continue;
|
||||
}
|
||||
auto* groundedObj = propObj->getValue();
|
||||
if (auto* linkElt = dynamic_cast<App::LinkElement*>(groundedObj)) {
|
||||
// hasObject does not handle link groups so we must handle it manually.
|
||||
groundedObj = linkElt->getLinkGroup();
|
||||
}
|
||||
|
||||
if (Rigid.getValue() ? hasObject(groundedObj) : groundedObj == this) {
|
||||
getDocument()->removeObject(joint->getNameInDocument());
|
||||
}
|
||||
}
|
||||
|
||||
if (Rigid.getValue()) {
|
||||
// movePlc needs to be computed before updateContents.
|
||||
App::DocumentObject* firstLink = nullptr;
|
||||
|
||||
@@ -781,6 +781,11 @@ std::unordered_set<App::DocumentObject*> AssemblyObject::getGroundedParts()
|
||||
if (propObj) {
|
||||
App::DocumentObject* objToGround = propObj->getValue();
|
||||
if (objToGround) {
|
||||
if (auto* asmLink = dynamic_cast<AssemblyLink*>(objToGround)) {
|
||||
if (!asmLink->isRigid()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
groundedSet.insert(objToGround);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -628,6 +628,12 @@ bool ViewProviderAssembly::canDragObjectIn3d(App::DocumentObject* obj) const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (auto* asmLink = dynamic_cast<Assembly::AssemblyLink*>(obj)) {
|
||||
if (!asmLink->isRigid()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto* assemblyPart = getObject<AssemblyObject>();
|
||||
|
||||
// Check if the selected object is a child of the assembly
|
||||
|
||||
Reference in New Issue
Block a user