Skip to content

Commit

Permalink
Clean up children on Page delete
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Jan 30, 2017
1 parent 6cad2bc commit 3ce9c48
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
34 changes: 31 additions & 3 deletions src/Mod/TechDraw/App/DrawPage.cpp
Expand Up @@ -66,6 +66,7 @@ const char* DrawPage::ProjectionTypeEnums[] = { "First Angle",
DrawPage::DrawPage(void)
{
static const char *group = "Page";
nowDeleting = false;

ADD_PROPERTY_TYPE(Template, (0), group, (App::PropertyType)(App::Prop_None), "Attached Template");
ADD_PROPERTY_TYPE(Views, (0), group, (App::PropertyType)(App::Prop_None), "Attached Views");
Expand Down Expand Up @@ -101,11 +102,13 @@ void DrawPage::onBeforeChange(const App::Property* prop)
void DrawPage::onChanged(const App::Property* prop)
{
if (prop == &Template) {
if (!isRestoring()) {
if (!isRestoring() &&
!isDeleting()) {
//TODO: reload if Template prop changes (ie different Template)
}
} else if (prop == &Views) {
if (!isRestoring()) {
if (!isRestoring() &&
!isDeleting() ) {
//TODO: reload if Views prop changes (ie adds/deletes)
}
} else if(prop == &Scale) {
Expand All @@ -130,7 +133,7 @@ void DrawPage::onChanged(const App::Property* prop)
// TODO: Also update Template graphic.

}
App::DocumentObject::onChanged(prop);
App::DocumentObject::onChanged(prop); //<<<<
}

App::DocumentObjectExecReturn *DrawPage::execute(void)
Expand Down Expand Up @@ -302,3 +305,28 @@ void DrawPage::onDocumentRestored()
recompute();
App::DocumentObject::onDocumentRestored();
}

void DrawPage::unsetupObject()
{
nowDeleting = true;

// Remove the Page's views & template from document
App::Document* doc = getDocument();
std::string docName = doc->getName();

const std::vector<App::DocumentObject*> currViews = Views.getValues();
std::vector<App::DocumentObject*> emptyViews;
std::vector<App::DocumentObject*>::const_iterator it = currViews.begin();
for (; it != currViews.end(); it++) {
std::string viewName = (*it)->getNameInDocument();
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
docName.c_str(), viewName.c_str());
}
Views.setValues(emptyViews);

std::string templateName = Template.getValue()->getNameInDocument();
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
docName.c_str(), templateName.c_str());
Template.setValue(nullptr);
}

6 changes: 6 additions & 0 deletions src/Mod/TechDraw/App/DrawPage.h
Expand Up @@ -81,14 +81,20 @@ class TechDrawExport DrawPage: public App::DocumentObject
*/
double getPageHeight() const;
const char* getPageOrientation() const;
bool isDeleting(void) { return nowDeleting; }


protected:
void onBeforeChange(const App::Property* prop);
void onChanged(const App::Property* prop);
virtual void onDocumentRestored();
virtual void unsetupObject();


private:
static const char* ProjectionTypeEnums[];
bool nowDeleting;

};

} //namespace TechDraw
Expand Down
21 changes: 21 additions & 0 deletions src/Mod/TechDraw/App/DrawViewPart.cpp
Expand Up @@ -69,6 +69,7 @@
#include <GeomLib_Tool.hxx>

#include <App/Application.h>
#include <App/Document.h>
#include <Base/BoundBox.h>
#include <Base/Console.h>
#include <Base/Exception.h>
Expand Down Expand Up @@ -103,6 +104,7 @@ DrawViewPart::DrawViewPart(void) : geometryObject(0)
static const char *group = "Projection";
static const char *fgroup = "Format";
static const char *sgroup = "Show";
nowDeleting = false;

//properties that affect Geometry
ADD_PROPERTY_TYPE(Source ,(0),group,App::Prop_None,"3D Shape to view");
Expand Down Expand Up @@ -577,6 +579,25 @@ bool DrawViewPart::showSectionEdges(void)
return m_sectionEdges;
}

void DrawViewPart::unsetupObject()
{
nowDeleting = true;

// Remove the View's Hatches from document
App::Document* doc = getDocument();
std::string docName = doc->getName();

std::vector<TechDraw::DrawHatch*> hatches = getHatches();

std::vector<TechDraw::DrawHatch*>::iterator it = hatches.begin();
for (; it != hatches.end(); it++) {
std::string viewName = (*it)->getNameInDocument();
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
docName.c_str(), viewName.c_str());
}
}


PyObject *DrawViewPart::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/TechDraw/App/DrawViewPart.h
Expand Up @@ -135,12 +135,15 @@ class TechDrawExport DrawViewPart : public DrawView
}
//return PyObject as DrawViewPartPy
virtual PyObject *getPyObject(void);
bool isDeleting(void) { return nowDeleting; }

protected:
TechDrawGeometry::GeometryObject *geometryObject;
Base::BoundBox3d bbox;

void onChanged(const App::Property* prop);
virtual void unsetupObject();

virtual TechDrawGeometry::GeometryObject* buildGeometryObject(TopoDS_Shape shape, gp_Ax2 viewAxis);
void extractFaces();

Expand All @@ -156,6 +159,7 @@ class TechDrawExport DrawViewPart : public DrawView
bool m_handleFaces;

private:
bool nowDeleting;

};

Expand Down
6 changes: 4 additions & 2 deletions src/Mod/TechDraw/Gui/ViewProviderPage.cpp
Expand Up @@ -127,11 +127,13 @@ void ViewProviderPage::hide(void)
void ViewProviderPage::updateData(const App::Property* prop)
{
if (prop == &(getDrawPage()->Views)) {
if(m_mdiView) {
if(m_mdiView &&
!getDrawPage()->isDeleting()) {
m_mdiView->updateDrawing();
}
} else if (prop == &(getDrawPage()->Template)) {
if(m_mdiView) {
if(m_mdiView &&
!getDrawPage()->isDeleting()) {
m_mdiView->updateTemplate();
}
}
Expand Down

0 comments on commit 3ce9c48

Please sign in to comment.