diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index 86a8ff2c3..561d252b3 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -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"); @@ -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) { @@ -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) @@ -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 currViews = Views.getValues(); + std::vector emptyViews; + std::vector::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); +} + diff --git a/src/Mod/TechDraw/App/DrawPage.h b/src/Mod/TechDraw/App/DrawPage.h index 8f9865a33..cc6b1ff92 100644 --- a/src/Mod/TechDraw/App/DrawPage.h +++ b/src/Mod/TechDraw/App/DrawPage.h @@ -81,14 +81,20 @@ public: */ 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 diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index ca58c4855..e584023ac 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -69,6 +69,7 @@ #include #include +#include #include #include #include @@ -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"); @@ -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 hatches = getHatches(); + + std::vector::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())) { diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 9abc81247..d33727c5b 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -135,12 +135,15 @@ public: } //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(); @@ -156,6 +159,7 @@ protected: bool m_handleFaces; private: + bool nowDeleting; }; diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp index db6581247..c122f5cb5 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp @@ -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(); } }