Cleanup orphan features on DVP delete

This commit is contained in:
WandererFan 2017-02-09 13:18:22 -05:00
parent 63d5749b67
commit 513decf8c8
5 changed files with 55 additions and 13 deletions

View File

@ -325,14 +325,14 @@ void DrawPage::unsetupObject()
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();
while (Views.getValues().size() > 0 ) {
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);
App::DocumentObject* tmp = Template.getValue();

View File

@ -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<TechDraw::DrawGeomHatch*> DrawViewPart::getGeomHatches() const
return result;
}
std::vector<TechDraw::DrawViewDimension*> DrawViewPart::getDimensions() const
{
std::vector<TechDraw::DrawViewDimension*> result;
std::vector<App::DocumentObject*> children = getInList();
for (std::vector<App::DocumentObject*>::iterator it = children.begin(); it != children.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawViewDimension::getClassTypeId())) {
TechDraw::DrawViewDimension* dim = dynamic_cast<TechDraw::DrawViewDimension*>(*it);
result.push_back(dim);
}
}
return result;
}
const std::vector<TechDrawGeometry::Vertex *> & 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<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());
}
// Remove the View's GeomHatches from document
std::vector<TechDraw::DrawGeomHatch*> gHatches = getGeomHatches();
std::vector<TechDraw::DrawGeomHatch*>::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<TechDraw::DrawViewDimension*> dims = getDimensions();
std::vector<TechDraw::DrawViewDimension*>::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());
}
}
}

View File

@ -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<TechDraw::DrawHatch*> getHatches(void) const;
std::vector<TechDraw::DrawGeomHatch*> getGeomHatches(void) const;
std::vector<TechDraw::DrawViewDimension*> getDimensions() const;
//TODO: are there use-cases for Python access to TechDrawGeometry???

View File

@ -556,6 +556,7 @@ void DrawViewSection::unsetupObject()
if (base != nullptr) {
base->touch();
}
DrawViewPart::unsetupObject();
}
TechDraw::DrawViewPart* DrawViewSection::getBaseDVP()

View File

@ -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);
}