Skip to content

Commit

Permalink
Merge pull request #512 from WandererFan/Fix2888
Browse files Browse the repository at this point in the history
TechDraw Fix #2888
  • Loading branch information
wwmayer committed Feb 9, 2017
2 parents 81c3bc6 + 513decf commit 72d2349
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 178 deletions.
10 changes: 5 additions & 5 deletions src/Mod/TechDraw/App/DrawPage.cpp
Expand Up @@ -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();
Expand Down
46 changes: 43 additions & 3 deletions src/Mod/TechDraw/App/DrawViewPart.cpp
Expand Up @@ -90,6 +90,8 @@
#include "DrawViewPart.h"
#include "DrawHatch.h"
#include "DrawGeomHatch.h"
#include "DrawViewDimension.h"
#include "DrawPage.h"
#include "EdgeWalker.h"


Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
}
}

}


Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/DrawViewPart.h
Expand Up @@ -57,6 +57,7 @@ class Face;
namespace TechDraw {
class DrawHatch;
class DrawGeomHatch;
class DrawViewDimension;
class DrawProjectSplit;
class DrawViewSection;
}
Expand Down Expand Up @@ -100,6 +101,7 @@ class TechDrawExport DrawViewPart : public DrawView

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???

Expand Down
18 changes: 13 additions & 5 deletions src/Mod/TechDraw/App/DrawViewSection.cpp
Expand Up @@ -552,15 +552,21 @@ std::vector<TopoDS_Wire> DrawViewSection::getWireForFace(int idx) const

void DrawViewSection::unsetupObject()
{
getBaseDVP()->touch();
TechDraw::DrawViewPart* base = getBaseDVP();
if (base != nullptr) {
base->touch();
}
DrawViewPart::unsetupObject();
}

TechDraw::DrawViewPart* DrawViewSection::getBaseDVP()
{
TechDraw::DrawViewPart* baseDVP = nullptr;
App::DocumentObject* base = BaseView.getValue();
if (base->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
baseDVP = static_cast<TechDraw::DrawViewPart*>(base);
if (base != nullptr) {
if (base->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
baseDVP = static_cast<TechDraw::DrawViewPart*>(base);
}
}
return baseDVP;
}
Expand All @@ -569,8 +575,10 @@ TechDraw::DrawProjGroupItem* DrawViewSection::getBaseDPGI()
{
TechDraw::DrawProjGroupItem* baseDPGI = nullptr;
App::DocumentObject* base = BaseView.getValue();
if (base->getTypeId().isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
baseDPGI = static_cast<TechDraw::DrawProjGroupItem*>(base);
if (base != nullptr) {
if (base->getTypeId().isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
baseDPGI = static_cast<TechDraw::DrawProjGroupItem*>(base);
}
}
return baseDPGI;
}
Expand Down
113 changes: 28 additions & 85 deletions src/Mod/TechDraw/Gui/MDIViewPage.cpp
Expand Up @@ -320,6 +320,7 @@ bool MDIViewPage::attachView(App::DocumentObject *obj)
} else if (typeId.isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) ) {
//Hatch is not attached like other Views (since it isn't really a View)
return true;
//DrawGeomHatch??

} else {
Base::Console().Log("Logic Error - Unknown view type in MDIViewPage::attachView\n");
Expand All @@ -328,11 +329,6 @@ bool MDIViewPage::attachView(App::DocumentObject *obj)
return (qview != nullptr);
}

void MDIViewPage::removeView(QGIView *view)
{
(void) m_view->removeView(view);
}

void MDIViewPage::onDeleteObject(const App::DocumentObject& obj)
{
if (obj.isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
Expand All @@ -341,7 +337,7 @@ void MDIViewPage::onDeleteObject(const App::DocumentObject& obj)
TechDraw::DrawPage* dvPg = dv->findParentPage();
if (dvPg == m_vpPage->getDrawPage()) {
//this is a DV that is on our page
(void) m_view->removeView(dv);
(void) m_view->removeQViewByDrawView(dv);
}
}
}
Expand Down Expand Up @@ -374,88 +370,35 @@ void MDIViewPage::updateTemplate(bool forceUpdate)

void MDIViewPage::updateDrawing(bool forceUpdate)
{
// We cannot guarantee if the number of graphical representations (QGIVxxxx) have changed so check the number (MLP)
// WF: this should be fixed now with onDeletedObject signal from App side?
// WF: the QGVP views list may still not be 100% reliable
// TODO: build list of QGIV's from scene everytime?
//logging counters
// int qgvpIn = 0;
// int qgvpValid = 0;
// int qgvpClean = 0;
// int dpIn = 0;
const std::vector<QGIView *> &graphicsList = m_view->getViews();
// qgvpIn = graphicsList.size();
const std::vector<App::DocumentObject*> &pageChildren = m_vpPage->getDrawPage()->Views.getValues();

// Count total # DocumentObjects in Page
unsigned int docObjCount = 0;
for(std::vector<App::DocumentObject*>::const_iterator it = pageChildren.begin(); it != pageChildren.end(); ++it) {
App::DocumentObject *docObj = *it;
if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) {
TechDraw::DrawViewCollection *collection = dynamic_cast<TechDraw::DrawViewCollection *>(docObj);
docObjCount += collection->countChildren(); // Include self
// get all the DrawViews for this page, including the second level ones
// if we ever have collections of collections, we'll need to revisit this
std::vector<App::DocumentObject*> pChildren = m_vpPage->getDrawPage()->Views.getValues();
std::vector<App::DocumentObject*> appendChildren;
for (auto& pc: pChildren) {
if(pc->getTypeId().isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) {
TechDraw::DrawViewCollection *collect = dynamic_cast<TechDraw::DrawViewCollection *>(pc);
std::vector<App::DocumentObject*> cChildren = collect->Views.getValues();
appendChildren.insert(std::end(appendChildren), std::begin(cChildren), std::end(cChildren));
}
docObjCount += 1;
}
// dpIn = docObjCount;


//TODO: should prune QGVP.views first always, then check if view in Page missing QGIVP
// this makes assumption that = numbers mean everythign is OK, but could be double failure - 1 extra QGIV, 1 DV missing graphics!

if(graphicsList.size() < docObjCount) {
// there are more DocumentObjects than graphical representations (QGIVxxxx's)
// Find which DocumentObjects have no graphical representation (QGIVxxxx)
// Iterate over DocumentObjects without graphical representations and create the QGIVxxxx
// TODO think of a better algorithm to deal with any changes to views list
std::vector<App::DocumentObject*> notFnd;
findMissingViews(pageChildren, notFnd);
for(std::vector<App::DocumentObject*>::const_iterator it = notFnd.begin(); it != notFnd.end(); ++it) {
attachView(*it);
}
} else if(graphicsList.size() > docObjCount) {
// prune any invalid entries in QGVP.views
// TODO: revisit this mess. is it still required with onDeletedItem signal implementation?
std::vector<QGIView *> newGraphicsList;
QList<QGraphicsItem *> items = m_view->scene()->items();
for (auto& v: graphicsList) { //check that everything in QGVP views is valid
for (auto& i:items) {
if (v == i) { //this one is OK
newGraphicsList.push_back(v);
break;
}
}
pChildren.insert(std::end(pChildren),std::begin(appendChildren),std::end(appendChildren));

// if dv doesn't have a graphic, make one
for (auto& dv: pChildren) {
QGIView* qv = m_view->findQViewForDocObj(dv);
if (qv == nullptr) {
attachView(dv);
}
// qgvpValid = newGraphicsList.size();
//newGraphicsList now only contains valid QGIV's
//now prune the ones without docObjs
std::vector<QGIView *> cleanItems;
for (auto& i: newGraphicsList) {
std::string viewName = (i->data(1).toString()).toStdString();
App::DocumentObject* dObj = getAppDocument()->getObject(viewName.c_str());
if (dObj == nullptr) {
//need to remove from group/scene
QGraphicsItemGroup* grp = i->group();
if (grp) {
grp->removeFromGroup(i);
}
if (i->parentItem()) { //not top level
i->setParentItem(0);
}
if (i->scene()) {
i->scene()->removeItem(i);
}
//should delete i too to prevent leak? might be garbage pointer, though.
//add to delete list and delete outside of loop
} else {
QGIView* v = static_cast<QGIView*>(i);
cleanItems.push_back(v);
}
}

// if qView doesn't have a Feature, delete it
std::vector<QGIView*> qvs = m_view->getViews();
App::Document* doc = getAppDocument();
for (auto& qv: qvs) {
App::DocumentObject* obj = doc->getObject(qv->getViewName());
if (obj == nullptr) {
m_view->removeQView(qv);
}
// qgvpClean = cleanItems.size();
m_view->setViews(cleanItems);
// Base::Console().Message("Log - MDIVP::updateDrawing pruning: docObjs: %d views in: %d valid views: %d views out: %d\n",
// dpIn,qgvpIn,qgvpValid, qgvpClean);
}

// Update all the QGIVxxxx
Expand Down Expand Up @@ -1004,7 +947,7 @@ void MDIViewPage::selectFeature(App::DocumentObject *obj, const bool isSelected)
if (hatchObj) { //Hatch does not have a QGIV of it's own. mark parent as selected.
objCopy = hatchObj->getSourceView(); //possible to highlight subObject?
}
QGIView *view = m_view->findView(objCopy);
QGIView *view = m_view->findQViewForDocObj(objCopy);

blockSelection(true);
if(view) {
Expand Down
1 change: 0 additions & 1 deletion src/Mod/TechDraw/Gui/MDIViewPage.h
Expand Up @@ -65,7 +65,6 @@ class TechDrawGuiExport MDIViewPage : public Gui::MDIView, public Gui::Selection
void attachTemplate(TechDraw::DrawTemplate *obj);
void updateTemplate(bool force = false);
void updateDrawing(bool force = false);
void removeView(QGIView *view);

bool onMsg(const char* pMsg,const char** ppReturn);
bool onHasMsg(const char* pMsg) const;
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/TechDraw/Gui/QGIView.cpp
Expand Up @@ -287,7 +287,9 @@ const char * QGIView::getViewName() const

TechDraw::DrawView * QGIView::getViewObject() const
{
return viewObj;
//DocumentObject* obj = doc->getObject(viewName.c_str());
//TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(obj);
return viewObj;
}

void QGIView::setViewFeature(TechDraw::DrawView *obj)
Expand Down

0 comments on commit 72d2349

Please sign in to comment.