issue #0002080: Attempt to remove FEM analysis result (displacement & stress) results in false warning

This commit is contained in:
wmayer
2017-10-18 19:46:20 +02:00
parent 9bb1454ef4
commit 48155db774
5 changed files with 36 additions and 14 deletions

View File

@@ -1110,19 +1110,14 @@ void StdCmdDelete::activated(int iMsg)
if (!links.empty()) {
// check if the referenced objects are groups or are selected too
for (std::vector<App::DocumentObject*>::iterator lt = links.begin(); lt != links.end(); ++lt) {
if (
(!(*lt)->hasExtension(App::GroupExtension::getExtensionClassTypeId())) &&
(!(*lt)->isDerivedFrom(App::Origin::getClassTypeId())) &&
(!rSel.isSelected(*lt))
){
autoDeletion = false;
affectedLabels.insert(QString::fromUtf8((*lt)->Label.getValue()));
if (!rSel.isSelected(*lt)) {
ViewProvider* vp = pGuiDoc->getViewProvider(*lt);
if (!vp->canDelete(obj)) {
autoDeletion = false;
affectedLabels.insert(QString::fromUtf8((*lt)->Label.getValue()));
}
}
}
if (!autoDeletion) {
break;
}
}
}
@@ -1148,12 +1143,14 @@ void StdCmdDelete::activated(int iMsg)
Gui::ViewProvider* vp = pGuiDoc->getViewProvider(ft->getObject());
if (vp) {
// ask the ViewProvider if it wants to do some clean up
if (vp->onDelete(ft->getSubNames()))
if (vp->onDelete(ft->getSubNames())) {
doCommand(Doc,"App.getDocument(\"%s\").removeObject(\"%s\")"
,(*it)->getName(), ft->getFeatName());
}
}
}
(*it)->commitTransaction();
Gui::getMainWindow()->setUpdatesEnabled(true);
Gui::getMainWindow()->update();
}

View File

@@ -614,6 +614,11 @@ bool ViewProvider::onDelete(const vector< string >& subNames) {
return del;
}
bool ViewProvider::canDelete(App::DocumentObject*) const
{
return false;
}
bool ViewProvider::canDragObject(App::DocumentObject* obj) const {
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();

View File

@@ -137,9 +137,16 @@ public:
* Get called if the object is about to get deleted.
* Here you can delete other objects, switch their visibility or prevent the deletion of the object.
* @param subNames list of selected subelements
* @return true if the deletion is approoved by the view provider.
* @return true if the deletion is approved by the view provider.
*/
virtual bool onDelete(const std::vector<std::string> &subNames);
/**
* @brief Asks the view provider if the given object that is part of its
* outlist can be removed from there without breaking it.
* @param obj is part of the outlist of the object associated to the view provider
* @return true if the removal is approved by the view provider.
*/
virtual bool canDelete(App::DocumentObject* obj) const;
//@}

View File

@@ -35,7 +35,8 @@
/// Here the FreeCAD includes sorted by Base,App,Gui......
#include <Base/Console.h>
#include <App/Material.h>
#include <App/DocumentObject.h>
#include <App/DocumentObjectGroup.h>
#include <App/Origin.h>
#include "Application.h"
#include "Document.h"
#include "Selection.h"
@@ -286,6 +287,16 @@ void ViewProviderDocumentObject::setActiveMode()
ViewProvider::hide();
}
bool ViewProviderDocumentObject::canDelete(App::DocumentObject* obj) const
{
Q_UNUSED(obj)
if (getObject()->hasExtension(App::GroupExtension::getExtensionClassTypeId()))
return true;
if (getObject()->isDerivedFrom(App::Origin::getClassTypeId()))
return true;
return false;
}
PyObject* ViewProviderDocumentObject::getPyObject()
{
if (!pyViewObject)

View File

@@ -77,6 +77,8 @@ public:
void updateView();
/// Get the object of this ViewProvider object
App::DocumentObject *getObject(void) const {return pcObject;}
/// Asks the view provider if the given object can be deleted.
virtual bool canDelete(App::DocumentObject* obj) const;
/// Get the GUI document to this ViewProvider object
Gui::Document* getDocument() const;
/// Get the python wrapper for that ViewProvider