From 5016054a8b3a72598beba490008d1dea66565997 Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Thu, 27 Aug 2015 15:21:22 +0300 Subject: [PATCH] PartDesign/Body: move deletion of subobjects to view provider --- src/Mod/PartDesign/App/Body.cpp | 14 ++++------ src/Mod/PartDesign/App/Body.h | 4 ++- src/Mod/PartDesign/App/BodyPy.xml | 29 ++++++++++++--------- src/Mod/PartDesign/App/BodyPyImp.cpp | 8 ++++++ src/Mod/PartDesign/Gui/ViewProviderBody.cpp | 7 +++++ src/Mod/PartDesign/Gui/ViewProviderBody.h | 2 ++ 6 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index 7eb72256ea..a75ea93713 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -462,18 +462,14 @@ void Body::onSettingDocument() { if(connection.connected()) connection.disconnect(); - getDocument()->signalDeletedObject.connect(boost::bind(&Body::onDelete, this, _1)); - Part::BodyBase::onSettingDocument(); } -void Body::onDelete(const App::DocumentObject& obj) { - // TODO Handle this in view provider rather here (2015-08-06, Fat-Zer) - if(&obj == this) { - //delete all child objects if needed - std::vector grp = Model.getValues(); - for (auto obj : grp) - this->getDocument()->remObject(obj->getNameInDocument(), true); +void Body::removeModelFromDocument() { + //delete all child objects if needed + std::set grp ( Model.getValues().begin (), Model.getValues().end() ); + for (auto obj : grp) { + this->getDocument()->remObject(obj->getNameInDocument(), true); } } diff --git a/src/Mod/PartDesign/App/Body.h b/src/Mod/PartDesign/App/Body.h index 88a07f27cf..ca11c3e6bb 100644 --- a/src/Mod/PartDesign/App/Body.h +++ b/src/Mod/PartDesign/App/Body.h @@ -112,6 +112,9 @@ public: */ static Body *findBodyOf(const App::DocumentObject* feature); + /// Delets all the objects linked to the model. + void removeModelFromDocument(); + /// Return the bounding box of the Tip Shape, taking into account datum features Base::BoundBox3d getBoundBox(); @@ -138,7 +141,6 @@ protected: private: App::DocumentObject* rememberTip; boost::signals::scoped_connection connection; - void onDelete(const App::DocumentObject& obj); }; } //namespace PartDesign diff --git a/src/Mod/PartDesign/App/BodyPy.xml b/src/Mod/PartDesign/App/BodyPy.xml index 7bc4af422b..9569b1acc6 100644 --- a/src/Mod/PartDesign/App/BodyPy.xml +++ b/src/Mod/PartDesign/App/BodyPy.xml @@ -1,13 +1,13 @@  - @@ -18,11 +18,6 @@ addFeature(feat) - Add the given feature after the current Tip feature - - - removeFeature(feat) - Remove the given feature from the Body - - insertFeatureAfter(feature, target, after=False) @@ -38,5 +33,15 @@ + + + removeFeature(feat) - Remove the given feature from the Body + + + + + Delets all the objects linked to the model. + + diff --git a/src/Mod/PartDesign/App/BodyPyImp.cpp b/src/Mod/PartDesign/App/BodyPyImp.cpp index b5f1d63e59..4c1db1599a 100644 --- a/src/Mod/PartDesign/App/BodyPyImp.cpp +++ b/src/Mod/PartDesign/App/BodyPyImp.cpp @@ -113,4 +113,12 @@ PyObject* BodyPy::removeFeature(PyObject *args) Py_Return; } +PyObject* BodyPy::removeModelFromDocument(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + + getBodyPtr()->removeModelFromDocument(); + Py_Return; +} diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index 7a3a2f0316..7fa1a35d69 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -193,6 +193,13 @@ std::vector ViewProviderBody::claimChildren3D(void)const // } //} +bool ViewProviderBody::onDelete ( const std::vector &) { + Gui::Command::doCommand(Gui::Command::Doc, + "App.getDocument(\"%s\").getObject(\"%s\").removeModelFromDocument()" + ,getObject()->getDocument()->getName(), getObject()->getNameInDocument()); + return true; +} + void ViewProviderBody::updateData(const App::Property* prop) { //Base::Console().Error("ViewProviderBody::updateData for %s\n", getObject()->getNameInDocument()); diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.h b/src/Mod/PartDesign/Gui/ViewProviderBody.h index 9163efee1a..e12817e9ec 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.h +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.h @@ -57,6 +57,8 @@ public: virtual SoGroup* getChildRoot(void) const {return pcBodyChildren;} virtual std::vector claimChildren3D(void)const; + virtual bool onDelete(const std::vector &); + /// Update the children's highlighting when triggered void updateData(const App::Property* prop);