diff --git a/src/Mod/PartDesign/Gui/ViewProvider.cpp b/src/Mod/PartDesign/Gui/ViewProvider.cpp
index a343beeb66..636573b028 100644
--- a/src/Mod/PartDesign/Gui/ViewProvider.cpp
+++ b/src/Mod/PartDesign/Gui/ViewProvider.cpp
@@ -36,6 +36,7 @@
#include
#include
#include
+#include
#include "TaskFeatureParameters.h"
@@ -202,26 +203,37 @@ void ViewProvider::onChanged(const App::Property* prop) {
bool ViewProvider::onDelete(const std::vector &)
{
PartDesign::Feature* feature = static_cast(getObject());
- App::DocumentObject* previous = feature->getBaseObject(/* silent = */ true );
- // Make the tip or the previous feature visiable again with preference to the previous one
- // if the feature was visiable itself
- if (isShow()) {
- // TODO TaskDlgFeatureParameters::reject has the same code. May be this one is excess?
- // (2015-07-24, Fat-Zer)
- if (previous && Gui::Application::Instance->getViewProvider(previous)) {
- Gui::Application::Instance->getViewProvider(previous)->show();
- } else {
- // Body feature housekeeping
- Part::BodyBase* body = PartDesign::Body::findBodyOf(getObject());
- if (body != NULL) {
- App::DocumentObject* tip = body->Tip.getValue();
- if (tip && Gui::Application::Instance->getViewProvider(tip)) {
- Gui::Application::Instance->getViewProvider(tip)->show();
- }
- }
- }
+ App::DocumentObject* previousfeat = feature->BaseFeature.getValue();
+
+ // Visibility - we want:
+ // 1. If the visible object is not the one being deleted, we leave that one visible.
+ // 2. If the visible object is the one being deleted, we make the previous object visible.
+ if (isShow() && previousfeat && Gui::Application::Instance->getViewProvider(previousfeat)) {
+ Gui::Application::Instance->getViewProvider(previousfeat)->show();
}
+
+ // find surrounding features in the tree
+ Part::BodyBase* body = PartDesign::Body::findBodyOf(getObject());
+
+ if (body != NULL) {
+ // Deletion from the tree of a feature is handled by Document.removeObject, which has no clue
+ // about what a body is. Therefore, Bodies, although an "activable" container, know nothing
+ // about what happens at Document level with the features they contain.
+ //
+ // The Deletion command StdCmdDelete::activated, however does notify the viewprovider corresponding
+ // to the feature (not body) of the imminent deletion (before actually doing it).
+ //
+ // Consequently, the only way of notifying a body of the imminent deletion of one of its features
+ // so as to do the clean up required (moving basefeature references, tip management) is from the
+ // viewprovider, so we call it here.
+ //
+ // fixes (#3084)
+
+ Gui::Command::doCommand ( Gui::Command::Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)",
+ body->getNameInDocument(), feature->getNameInDocument() );
+ }
+
return true;
}