diff --git a/src/Mod/Fem/Gui/ViewProviderAnalysis.cpp b/src/Mod/Fem/Gui/ViewProviderAnalysis.cpp index 7b8a387cc5..6cf3adb674 100644 --- a/src/Mod/Fem/Gui/ViewProviderAnalysis.cpp +++ b/src/Mod/Fem/Gui/ViewProviderAnalysis.cpp @@ -31,6 +31,7 @@ # include #endif +#include #include #include #include @@ -38,6 +39,8 @@ #include #include #include +#include +#include #include #include #include @@ -251,15 +254,40 @@ void ViewProviderFemAnalysis::dropObject(App::DocumentObject *obj) bool ViewProviderFemAnalysis::onDelete(const std::vector &) { - // 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 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()); diff --git a/src/Mod/Fem/Gui/ViewProviderAnalysis.h b/src/Mod/Fem/Gui/ViewProviderAnalysis.h index e993a8b2dc..4f62db2a8d 100644 --- a/src/Mod/Fem/Gui/ViewProviderAnalysis.h +++ b/src/Mod/Fem/Gui/ViewProviderAnalysis.h @@ -52,10 +52,10 @@ class FemGuiExport ViewProviderFemAnalysis : public Gui::ViewProviderDocumentObj PROPERTY_HEADER_WITH_OVERRIDE(FemGui::ViewProviderAnalysis); public: - /// constructor. + /// constructor ViewProviderFemAnalysis(); - /// destructor. + /// destructor ~ViewProviderFemAnalysis() override; void attach(App::DocumentObject*) override; @@ -63,17 +63,19 @@ public: std::vector claimChildren()const override; - // handling when object is deleted + /// handling when object is deleted bool onDelete(const std::vector&) override; - /// Asks the view provider if the given object can be deleted. + /// warning on deletion when there are children + static bool checkSelectedChildren(const std::vector objs, + Gui::Document* docGui, std::string objectName); + /// asks the view provider if the given object can be deleted bool canDelete(App::DocumentObject* obj) const override; - //virtual std::vector claimChildren3D(void)const; void setupContextMenu(QMenu*, QObject*, const char*) override; - /// A list of all possible display modes + /// list of all possible display modes std::vector getDisplayModes() const override; - // shows solid in the tree + /// shows solid in the tree bool isShow() const override { return Visibility.getValue(); } diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp index 467f735d84..a4a0e1b089 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp @@ -56,6 +56,7 @@ #include "ViewProviderFemPostFunction.h" #include "FemSettings.h" #include "TaskPostBoxes.h" +#include "ViewProviderAnalysis.h" #include "ui_BoxWidget.h" #include "ui_CylinderWidget.h" @@ -133,32 +134,10 @@ void ViewProviderFemPostFunctionProvider::updateSize() bool ViewProviderFemPostFunctionProvider::onDelete(const std::vector&) { - // warn the user if the object has childs - + // warn the user if the object has unselected children auto objs = claimChildren(); - if (!objs.empty()) - { - // generate dialog - QString bodyMessage; - QTextStream bodyMessageStream(&bodyMessage); - bodyMessageStream << qApp->translate("Std_Delete", - "The functions list 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; - } + return ViewProviderFemAnalysis::checkSelectedChildren( + objs, this->getDocument(), "functions list"); } bool ViewProviderFemPostFunctionProvider::canDelete(App::DocumentObject* obj) const @@ -178,7 +157,6 @@ PROPERTY_SOURCE(FemGui::ViewProviderFemPostFunction, Gui::ViewProviderDocumentOb ViewProviderFemPostFunction::ViewProviderFemPostFunction() : m_manip(nullptr), m_autoscale(false), m_isDragging(false), m_autoRecompute(false) { - ADD_PROPERTY_TYPE(AutoScaleFactorX, (1), "AutoScale", App::Prop_Hidden, "Automatic scaling factor"); ADD_PROPERTY_TYPE(AutoScaleFactorY, (1), "AutoScale", App::Prop_Hidden, "Automatic scaling factor"); ADD_PROPERTY_TYPE(AutoScaleFactorZ, (1), "AutoScale", App::Prop_Hidden, "Automatic scaling factor"); diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp index ce952cd086..65969063da 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp @@ -62,6 +62,7 @@ #include "ViewProviderFemPostObject.h" #include "TaskPostBoxes.h" +#include "ViewProviderAnalysis.h" using namespace FemGui; @@ -836,8 +837,8 @@ void ViewProviderFemPostObject::setupTaskDialog(TaskDlgPost* dlg) dlg->appendBox(new TaskPostDisplay(this)); } -void ViewProviderFemPostObject::unsetEdit(int ModNum) { - +void ViewProviderFemPostObject::unsetEdit(int ModNum) +{ if (ModNum == ViewProvider::Default) { // and update the pad //getSketchObject()->getDocument()->recompute(); @@ -903,33 +904,9 @@ void ViewProviderFemPostObject::OnChange(Base::Subject< int >& /*rCaller*/, int bool ViewProviderFemPostObject::onDelete(const std::vector&) { - // warn the user if the object has childs - + // warn the user if the object has unselected children auto objs = claimChildren(); - if (!objs.empty()) - { - // generate dialog - QString bodyMessage; - QTextStream bodyMessageStream(&bodyMessage); - bodyMessageStream << qApp->translate("Std_Delete", - "The pipeline 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; - } + return ViewProviderFemAnalysis::checkSelectedChildren(objs, this->getDocument(), "pipeline"); } bool ViewProviderFemPostObject::canDelete(App::DocumentObject* obj) const diff --git a/src/Mod/Fem/Gui/ViewProviderSolver.cpp b/src/Mod/Fem/Gui/ViewProviderSolver.cpp index 3eabd41722..d69125f49a 100644 --- a/src/Mod/Fem/Gui/ViewProviderSolver.cpp +++ b/src/Mod/Fem/Gui/ViewProviderSolver.cpp @@ -32,6 +32,7 @@ #include #include "ViewProviderSolver.h" +#include "ViewProviderAnalysis.h" using namespace FemGui; @@ -44,9 +45,7 @@ ViewProviderSolver::ViewProviderSolver() } ViewProviderSolver::~ViewProviderSolver() -{ - -} +{} std::vector ViewProviderSolver::getDisplayModes() const { @@ -55,32 +54,9 @@ std::vector ViewProviderSolver::getDisplayModes() const bool ViewProviderSolver::onDelete(const std::vector&) { - // warn the user if the object has childs - + // warn the user if the object has unselected children auto objs = claimChildren(); - if (!objs.empty()) - { - // generate dialog - QString bodyMessage; - QTextStream bodyMessageStream(&bodyMessage); - bodyMessageStream << qApp->translate("Std_Delete", - "The solver 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; - } + return ViewProviderFemAnalysis::checkSelectedChildren(objs, this->getDocument(), "solver"); } bool ViewProviderSolver::canDelete(App::DocumentObject* obj) const