[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());

View File

@@ -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<App::DocumentObject*> claimChildren()const override;
// handling when object is deleted
/// handling when object is deleted
bool onDelete(const std::vector<std::string>&) 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<App::DocumentObject*> 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<App::DocumentObject*> 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<std::string> getDisplayModes() const override;
// shows solid in the tree
/// shows solid in the tree
bool isShow() const override {
return Visibility.getValue();
}

View File

@@ -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<std::string>&)
{
// 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");

View File

@@ -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<std::string>&)
{
// 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

View File

@@ -32,6 +32,7 @@
#include <Gui/MainWindow.h>
#include "ViewProviderSolver.h"
#include "ViewProviderAnalysis.h"
using namespace FemGui;
@@ -44,9 +45,7 @@ ViewProviderSolver::ViewProviderSolver()
}
ViewProviderSolver::~ViewProviderSolver()
{
}
{}
std::vector<std::string> ViewProviderSolver::getDisplayModes() const
{
@@ -55,32 +54,9 @@ std::vector<std::string> ViewProviderSolver::getDisplayModes() const
bool ViewProviderSolver::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();
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