From 513decf8c8c8f408225426a40eeb0b52c0162b61 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Thu, 9 Feb 2017 13:18:22 -0500 Subject: [PATCH] Cleanup orphan features on DVP delete --- src/Mod/TechDraw/App/DrawPage.cpp | 10 +++--- src/Mod/TechDraw/App/DrawViewPart.cpp | 46 ++++++++++++++++++++++-- src/Mod/TechDraw/App/DrawViewPart.h | 2 ++ src/Mod/TechDraw/App/DrawViewSection.cpp | 1 + src/Mod/TechDraw/Gui/QGVPage.cpp | 9 +++-- 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index f2177ce07..360fa1f27 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -325,14 +325,14 @@ void DrawPage::unsetupObject() 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(); + while (Views.getValues().size() > 0 ) { + const std::vector 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 emptyViews; //probably superfluous Views.setValues(emptyViews); App::DocumentObject* tmp = Template.getValue(); diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index a280f33d2..a3981a197 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -90,6 +90,8 @@ #include "DrawViewPart.h" #include "DrawHatch.h" #include "DrawGeomHatch.h" +#include "DrawViewDimension.h" +#include "DrawPage.h" #include "EdgeWalker.h" @@ -422,6 +424,20 @@ std::vector DrawViewPart::getGeomHatches() const return result; } +std::vector DrawViewPart::getDimensions() const +{ + std::vector result; + std::vector children = getInList(); + for (std::vector::iterator it = children.begin(); it != children.end(); ++it) { + if ((*it)->getTypeId().isDerivedFrom(DrawViewDimension::getClassTypeId())) { + TechDraw::DrawViewDimension* dim = dynamic_cast(*it); + result.push_back(dim); + } + } + return result; +} + + const std::vector & DrawViewPart::getVertexGeometry() const { return geometryObject->getVertexGeometry(); @@ -642,22 +658,46 @@ bool DrawViewPart::showSectionEdges(void) return m_sectionEdges; } +//! remove features that are useless without this DVP +//! hatches, geomhatches, dimensions,... void DrawViewPart::unsetupObject() { nowDeleting = true; - - // Remove the View's Hatches from document App::Document* doc = getDocument(); std::string docName = doc->getName(); + // Remove the View's Hatches from document 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()); } + + // Remove the View's GeomHatches from document + std::vector gHatches = getGeomHatches(); + std::vector::iterator it2 = gHatches.begin(); + for (; it2 != gHatches.end(); it2++) { + std::string viewName = (*it2)->getNameInDocument(); + Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")", + docName.c_str(), viewName.c_str()); + } + + // Remove Dimensions which reference this DVP + // must use page->removeObject first + TechDraw::DrawPage* page = findParentPage(); + if (page != nullptr) { + std::vector dims = getDimensions(); + std::vector::iterator it3 = dims.begin(); + for (; it3 != dims.end(); it3++) { + page->removeView(*it3); + std::string viewName = (*it3)->getNameInDocument(); + Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")", + docName.c_str(), viewName.c_str()); + } + } + } diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 12fef1c53..07d3b90ae 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -57,6 +57,7 @@ class Face; namespace TechDraw { class DrawHatch; class DrawGeomHatch; +class DrawViewDimension; class DrawProjectSplit; class DrawViewSection; } @@ -100,6 +101,7 @@ public: std::vector getHatches(void) const; std::vector getGeomHatches(void) const; + std::vector getDimensions() const; //TODO: are there use-cases for Python access to TechDrawGeometry??? diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index 1639f205a..135bedb69 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -556,6 +556,7 @@ void DrawViewSection::unsetupObject() if (base != nullptr) { base->touch(); } + DrawViewPart::unsetupObject(); } TechDraw::DrawViewPart* DrawViewSection::getBaseDVP() diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index c9ed642e5..f0bace73d 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -195,11 +195,10 @@ int QGVPage::addQView(QGIView *view) Rez::guiX(view->getViewObject()->Y.getValue() * -1)); if(parent) { -// // Transfer the child vierw to the parent -// QPointF posRef(0.,0.); - -// QPointF mapPos = view->mapToItem(parent, posRef); //setPos is called later. this doesn't do anything? -// view->moveBy(-mapPos.x(), -mapPos.y()); + // move child view to center of parent + QPointF posRef(0.,0.); + QPointF mapPos = view->mapToItem(parent, posRef); + view->moveBy(-mapPos.x(), -mapPos.y()); parent->addToGroup(view); }