PartDesign/Body: move deletion of subobjects to view provider

This commit is contained in:
Alexander Golubev 2015-08-27 15:21:22 +03:00 committed by Stefan Tröger
parent aa32522115
commit 5016054a8b
6 changed files with 42 additions and 22 deletions

View File

@ -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<DocumentObject*> grp = Model.getValues();
for (auto obj : grp)
this->getDocument()->remObject(obj->getNameInDocument(), true);
void Body::removeModelFromDocument() {
//delete all child objects if needed
std::set<DocumentObject*> grp ( Model.getValues().begin (), Model.getValues().end() );
for (auto obj : grp) {
this->getDocument()->remObject(obj->getNameInDocument(), true);
}
}

View File

@ -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

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="BodyBasePy"
<PythonExport
Father="BodyBasePy"
Name="BodyPy"
Twin="Body"
TwinPointer="Body"
Include="Mod/PartDesign/App/Body.h"
Namespace="PartDesign"
FatherInclude="Mod/Part/App/BodyBasePy.h"
Twin="Body"
TwinPointer="Body"
Include="Mod/PartDesign/App/Body.h"
Namespace="PartDesign"
FatherInclude="Mod/Part/App/BodyBasePy.h"
FatherNamespace="Part">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
@ -18,11 +18,6 @@
<UserDocu>addFeature(feat) - Add the given feature after the current Tip feature</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeFeature">
<Documentation>
<UserDocu>removeFeature(feat) - Remove the given feature from the Body</UserDocu>
</Documentation>
</Methode>
<Methode Name="insertFeature">
<Documentation>
<UserDocu>insertFeatureAfter(feature, target, after=False)
@ -38,5 +33,15 @@
</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeFeature">
<Documentation>
<UserDocu>removeFeature(feat) - Remove the given feature from the Body</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeModelFromDocument">
<Documentation>
<UserDocu>Delets all the objects linked to the model.</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>

View File

@ -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;
}

View File

@ -193,6 +193,13 @@ std::vector<App::DocumentObject*> ViewProviderBody::claimChildren3D(void)const
// }
//}
bool ViewProviderBody::onDelete ( const std::vector<std::string> &) {
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());

View File

@ -57,6 +57,8 @@ public:
virtual SoGroup* getChildRoot(void) const {return pcBodyChildren;}
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;
virtual bool onDelete(const std::vector<std::string> &);
/// Update the children's highlighting when triggered
void updateData(const App::Property* prop);