Fix handling of orphan objects during Page delete

This commit is contained in:
wandererfan
2019-04-25 14:53:52 -04:00
committed by WandererFan
parent a0250a7be3
commit 408ac94416
3 changed files with 25 additions and 11 deletions

View File

@@ -372,16 +372,29 @@ void DrawPage::unsetupObject()
// Remove the Page's views & template from document
App::Document* doc = getDocument();
std::string docName = doc->getName();
std::string pageName = getNameInDocument();
while (Views.getValues().size() > 0 ) {
try {
const std::vector<App::DocumentObject*> currViews = Views.getValues();
App::DocumentObject* child = currViews.front();
std::string viewName = child->getNameInDocument();
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
docName.c_str(), viewName.c_str());
}
std::vector<App::DocumentObject*> emptyViews; //probably superfluous
Views.setValues(emptyViews);
for (auto& v: currViews) {
//NOTE: the order of objects in Page.Views does not reflect the object hierarchy
// this means that a ProjGroup could be deleted before it's child ProjGroupItems.
// this causes problems when removing objects from document
if (v->isAttachedToDocument()) {
std::string viewName = v->getNameInDocument();
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
docName.c_str(), viewName.c_str());
} else {
Base::Console().Log("DP::unsetupObject - v(%s) is not in document. skipping\n", pageName.c_str());
}
}
std::vector<App::DocumentObject*> emptyViews; //probably superfluous
Views.setValues(emptyViews);
}
catch (...) {
Base::Console().Warning("DP::unsetupObject - %s - error while deleting children\n", getNameInDocument());
}
App::DocumentObject* tmp = Template.getValue();
if (tmp != nullptr) {

View File

@@ -91,6 +91,7 @@ DrawView::~DrawView()
App::DocumentObjectExecReturn *DrawView::execute(void)
{
// Base::Console().Message("DV::execute() - %s\n",getNameInDocument());
handleXYLock();
requestPaint();
return App::DocumentObject::execute();

View File

@@ -160,7 +160,6 @@ DrawViewPart::~DrawViewPart()
TopoDS_Shape DrawViewPart::getSourceShape(void) const
{
// Base::Console().Message("DVP::getSourceShape() - %s\n", getNameInDocument());
TopoDS_Shape result;
const std::vector<App::DocumentObject*>& links = Source.getValues();
if (links.empty()) {
@@ -276,7 +275,7 @@ TopoDS_Shape DrawViewPart::getSourceShapeFused(void) const
App::DocumentObjectExecReturn *DrawViewPart::execute(void)
{
// Base::Console().Message("DVP::execute() - %s\n", getNameInDocument());
// Base::Console().Message("DVP::execute() - %s\n",getNameInDocument());
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}
@@ -346,6 +345,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
#endif //#if MOD_TECHDRAW_HANDLE_FACES
requestPaint();
// Base::Console().Message("DVP::execute - %s - exits\n",getNameInDocument());
return App::DocumentObject::StdReturn;
}
@@ -442,11 +442,11 @@ TechDrawGeometry::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape
go->extractGeometry(TechDrawGeometry::ecUVISO,
false);
}
auto end = chrono::high_resolution_clock::now();
auto diff = end - start;
double diffOut = chrono::duration <double, milli> (diff).count();
Base::Console().Log("TIMING - %s DVP spent: %.3f millisecs in GO::extractGeometry\n",getNameInDocument(),diffOut);
const std::vector<TechDrawGeometry::BaseGeom *> & edges = go->getEdgeGeometry();
if (edges.empty()) {
Base::Console().Log("DVP::buildGO - NO extracted edges!\n");