[FEM] handle deletion of solver objects

As it was, a deletion of non-empty solver could not be stopped, one could only decide if childs would be deleted too
Now you get a warning and can stop the deletion
This commit is contained in:
Uwe
2022-03-24 14:55:40 +01:00
parent f40770dd95
commit 0f0b635e65
2 changed files with 47 additions and 11 deletions

View File

@@ -20,30 +20,24 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Standard_math.hxx>
# include <QApplication>
# include <QMessageBox>
# include <QTextStream>
#endif
#include "ViewProviderSolver.h"
#include <Gui/Command.h>
#include <Gui/Document.h>
#include <Gui/Control.h>
#include <Gui/MainWindow.h>
#include <Mod/Fem/App/FemAnalysis.h>
#include "ViewProviderSolver.h"
#include "TaskDlgAnalysis.h"
using namespace FemGui;
PROPERTY_SOURCE(FemGui::ViewProviderSolver, Gui::ViewProviderDocumentObject)
ViewProviderSolver::ViewProviderSolver()
{
sPixmap = "FEM_SolverStandard";
@@ -59,6 +53,44 @@ std::vector<std::string> ViewProviderSolver::getDisplayModes(void) const
return { "Solver" };
}
bool ViewProviderSolver::onDelete(const std::vector<std::string>&)
{
// warn the user if the object has childs
auto objs = claimChildren();
if (!objs.empty())
{
// generate dialog
QString bodyMessage;
QTextStream bodyMessageStream(&bodyMessage);
bodyMessageStream << qApp->translate("Std_Delete",
"The page is not empty, therefore the\nfollowing referencing objects might be lost:");
bodyMessageStream << '\n';
for (auto ObjIterator : objs)
bodyMessageStream << '\n' << QString::fromUtf8(ObjIterator->Label.getValue());
bodyMessageStream << "\n\n" << QObject::tr("Are you sure you want to continue?");
// show and evaluate the dialog
int DialogResult = QMessageBox::warning(Gui::getMainWindow(),
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
QMessageBox::Yes, QMessageBox::No);
if (DialogResult == QMessageBox::Yes)
return true;
else
return false;
}
else {
return true;
}
}
bool ViewProviderSolver::canDelete(App::DocumentObject* obj) const
{
// deletions of objects from a FemSolver don't necesarily destroy anything
// thus we can pass this action
// we can warn the user if necessary in the object's ViewProvider in the onDelete() function
Q_UNUSED(obj)
return true;
}
// Python feature -----------------------------------------------------------------------