[FEM] improve deletion warning

- don't popup a warning if all children of an object are selected too when deleting the object
This commit is contained in:
Uwe
2023-03-16 06:14:37 +01:00
parent da38f16320
commit c1751bde4a
5 changed files with 53 additions and 92 deletions

View File

@@ -31,6 +31,7 @@
# include <Inventor/nodes/SoSeparator.h>
#endif
#include <App/Document.h>
#include <App/MaterialObject.h>
#include <App/TextDocument.h>
#include <Gui/ActionFunction.h>
@@ -38,6 +39,8 @@
#include <Gui/Control.h>
#include <Gui/Document.h>
#include <Gui/MainWindow.h>
#include <Gui/Selection.h>
#include <Gui/SelectionObject.h>
#include <Mod/Fem/App/FemAnalysis.h>
#include <Mod/Fem/App/FemConstraint.h>
#include <Mod/Fem/App/FemMeshObject.h>
@@ -251,15 +254,40 @@ void ViewProviderFemAnalysis::dropObject(App::DocumentObject *obj)
bool ViewProviderFemAnalysis::onDelete(const std::vector<std::string> &)
{
// warn the user if the object has childs
// warn the user if the object has unselected children
auto objs = claimChildren();
return checkSelectedChildren(objs, this->getDocument(), "analysis");
}
bool ViewProviderFemAnalysis::checkSelectedChildren(const std::vector<App::DocumentObject*> objs,
Gui::Document* docGui, std::string objectName)
{
// warn the user if the object has unselected children
if (!objs.empty()) {
// check if all children are in the selection
bool found = false;
auto selectionList = Gui::Selection().getSelectionEx(docGui->getDocument()->getName());
for (auto child : objs) {
found = false;
for (Gui::SelectionObject selection : selectionList) {
if (std::string(child->getNameInDocument())
== std::string(selection.getFeatName())) {
found = true;
break;
}
}
if (!found)
break;
}
if (found)// all children are selected too
return true;
// generate dialog
QString bodyMessage;
QTextStream bodyMessageStream(&bodyMessage);
bodyMessageStream << qApp->translate("Std_Delete",
"The analysis is not empty, therefore the\nfollowing referencing objects might be lost:");
("The " + objectName + " is not empty, therefore the\nfollowing "
"referencing objects might be lost:").c_str());
bodyMessageStream << '\n';
for (auto ObjIterator : objs)
bodyMessageStream << '\n' << QString::fromUtf8(ObjIterator->Label.getValue());