Assembly: Use canDragObjectToTarget in viewProviderAssembly

This commit is contained in:
PaddleStroke
2024-06-28 15:15:52 +02:00
committed by Yorik van Havre
parent 3e2bc7ad3d
commit 6088fdaa96
3 changed files with 24 additions and 9 deletions

View File

@@ -138,16 +138,27 @@ bool ViewProviderAssembly::canDragObject(App::DocumentObject* obj) const
return false;
}
// else if a solid is removed, remove associated joints if any.
return true;
}
bool ViewProviderAssembly::canDragObjectToTarget(App::DocumentObject* obj,
App::DocumentObject* target) const
{
// If a solid is removed from the assembly, its joints need to be removed.
bool prompted = false;
auto* assemblyPart = static_cast<AssemblyObject*>(getObject());
// If target is null then it's being dropped on a doc.
if (target && assemblyPart->hasObject(target)) {
// If the obj stays in assembly then its ok.
return true;
}
// Combine the joints and groundedJoints vectors into one for simplicity.
std::vector<App::DocumentObject*> allJoints = assemblyPart->getJoints();
std::vector<App::DocumentObject*> groundedJoints = assemblyPart->getGroundedJoints();
allJoints.insert(allJoints.end(), groundedJoints.begin(), groundedJoints.end());
Gui::Command::openCommand(tr("Delete associated joints").toStdString().c_str());
for (auto joint : allJoints) {
// getLinkObjFromProp returns nullptr if the property doesn't exist.
App::DocumentObject* obj1 = AssemblyObject::getObjFromProp(joint, "Object1");
@@ -175,7 +186,6 @@ bool ViewProviderAssembly::canDragObject(App::DocumentObject* obj) const
joint->getNameInDocument());
}
}
Gui::Command::commitCommand();
return true;
}