Clean up children on Page delete
This commit is contained in:
parent
6cad2bc834
commit
3ce9c48c64
|
@ -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<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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
@ -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<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())) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user