From 4d84efb0610addcb1272bcac47375da477f6a98b Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Fri, 29 Mar 2024 11:44:01 +0100 Subject: [PATCH] TechDraw: Enable App::Links to work with TechDraw views. --- src/Mod/TechDraw/App/DrawPage.cpp | 102 ++++++++++++------ src/Mod/TechDraw/App/DrawPage.h | 3 +- src/Mod/TechDraw/App/DrawPagePy.xml | 5 + src/Mod/TechDraw/App/DrawPagePyImp.cpp | 32 ++++++ src/Mod/TechDraw/App/DrawView.cpp | 55 ++++++---- src/Mod/TechDraw/App/DrawViewClip.cpp | 79 ++++++++++---- src/Mod/TechDraw/App/DrawViewClip.h | 6 +- src/Mod/TechDraw/App/DrawViewCollection.cpp | 102 ++++++++++++------ src/Mod/TechDraw/App/DrawViewCollection.h | 5 +- src/Mod/TechDraw/Gui/Command.cpp | 4 +- src/Mod/TechDraw/Gui/QGSPage.cpp | 72 +++++-------- src/Mod/TechDraw/Gui/TaskLinkDim.cpp | 14 +-- src/Mod/TechDraw/Gui/ViewProviderPage.cpp | 20 ++-- .../Gui/ViewProviderPageExtension.cpp | 65 +++++++++-- .../TechDraw/Gui/ViewProviderProjGroup.cpp | 5 +- 15 files changed, 380 insertions(+), 189 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index 074eae4a91..98960e1cd1 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -114,10 +115,8 @@ void DrawPage::onChanged(const App::Property* prop) // WF: not sure this loop is required. Views figure out their scale as required. but maybe // this is needed just to mark the Views to recompute?? if (!isRestoring()) { - const std::vector& vals = Views.getValues(); - for (std::vector::const_iterator it = vals.begin(); - it < vals.end(); ++it) { - TechDraw::DrawView* view = dynamic_cast(*it); + for (auto* obj : getViews()) { + auto* view = dynamic_cast(obj); if (view && view->ScaleType.isValue("Page")) { if (std::abs(view->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) { view->Scale.setValue(Scale.getValue()); @@ -128,10 +127,8 @@ void DrawPage::onChanged(const App::Property* prop) } else if (prop == &ProjectionType) { // touch all ortho views in the Page as they may be dependent on Projection Type //(is this true?) - const std::vector& vals = Views.getValues(); - for (std::vector::const_iterator it = vals.begin(); it < vals.end(); - ++it) { - TechDraw::DrawProjGroup* view = dynamic_cast(*it); + for (auto* obj : getViews()) { + auto* view = dynamic_cast(obj); if (view && view->ProjectionType.isValue("Default")) { view->ProjectionType.touch(); } @@ -228,8 +225,8 @@ int DrawPage::getOrientation() const { App::DocumentObject* obj = Template.getValue(); - if (obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) { - TechDraw::DrawTemplate* templ = static_cast(obj); + if (obj && obj->isDerivedFrom(DrawTemplate::getClassTypeId())) { + auto* templ = static_cast(obj); return templ->Orientation.getValue(); } throw Base::RuntimeError("Template not set for Page"); @@ -237,25 +234,39 @@ int DrawPage::getOrientation() const int DrawPage::addView(App::DocumentObject* docObj) { - if (!docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { + if (!docObj->isDerivedFrom() + && !docObj->isDerivedFrom()) { return -1; } - DrawView* view = static_cast(docObj); + + auto* view = dynamic_cast(docObj); + + if (!view) { + auto* link = dynamic_cast(docObj); + if (!link) { + return -1; + } + + view = dynamic_cast(link->getLinkedObject()); + if (!view) { + return -1; + } + } //position all new views without owners in center of Page (exceptDVDimension) if (!view->claimParent() - && !docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) - && !docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) { + && !docObj->isDerivedFrom() + && !docObj->isDerivedFrom()) { view->X.setValue(getPageWidth() / 2.0); view->Y.setValue(getPageHeight() / 2.0); } //add view to list - const std::vector currViews = Views.getValues(); - std::vector newViews(currViews); + std::vector newViews(Views.getValues()); newViews.push_back(docObj); Views.setValues(newViews); + //check if View fits on Page if (!view->checkFit(this)) { Base::Console().Warning("%s is larger than page. Will be scaled.\n", @@ -271,7 +282,7 @@ int DrawPage::addView(App::DocumentObject* docObj) //Note Views might be removed from document elsewhere so need to check if a View is still in Document here int DrawPage::removeView(App::DocumentObject* docObj) { - if (!docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { + if (!docObj->isDerivedFrom() && !docObj->isDerivedFrom()) { return -1; } @@ -283,18 +294,16 @@ int DrawPage::removeView(App::DocumentObject* docObj) if (!docObj->isAttachedToDocument()) { return -1; } - const std::vector currViews = Views.getValues(); std::vector newViews; - std::vector::const_iterator it = currViews.begin(); - for (; it != currViews.end(); it++) { - App::Document* viewDoc = (*it)->getDocument(); + for (auto* view : Views.getValues()) { + App::Document* viewDoc = view->getDocument(); if (!viewDoc) { continue; } std::string viewName = docObj->getNameInDocument(); - if (viewName.compare((*it)->getNameInDocument()) != 0) { - newViews.push_back((*it)); + if (viewName.compare(view->getNameInDocument()) != 0) { + newViews.push_back(view); } } Views.setValues(newViews); @@ -324,12 +333,12 @@ void DrawPage::redrawCommand() void DrawPage::updateAllViews() { // Base::Console().Message("DP::updateAllViews()\n"); - std::vector featViews = - getAllViews();//unordered list of views within page + //unordered list of views within page + std::vector featViews = getAllViews(); //first, make sure all the Parts have been executed so GeometryObjects exist for (auto& v : featViews) { - TechDraw::DrawViewPart* part = dynamic_cast(v); + auto* part = dynamic_cast(v); if (part) { //view, section, detail, dpgi part->recomputeFeature(); @@ -338,12 +347,12 @@ void DrawPage::updateAllViews() //second, do the rest of the views that may depend on a part view //TODO: check if we have 2 layers of dependency (ex. leader > weld > tile?) for (auto& v : featViews) { - TechDraw::DrawViewPart* part = dynamic_cast(v); + auto* part = dynamic_cast(v); if (part) { continue; } - TechDraw::DrawView* view = dynamic_cast(v); + auto* view = dynamic_cast(v); if (view) { view->overrideKeepUpdated(true); view->recomputeFeature(); @@ -351,14 +360,40 @@ void DrawPage::updateAllViews() } } -std::vector DrawPage::getAllViews(void) +std::vector DrawPage::getViews() const { - auto views = Views.getValues();//list of docObjects + std::vector views = Views.getValues(); std::vector allViews; for (auto& v : views) { + if (v->isDerivedFrom()) { + v = static_cast(v)->getLinkedObject(); + } + + if (!v->isDerivedFrom()) { + continue; + } + allViews.push_back(v); - if (v->isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId())) { - TechDraw::DrawProjGroup* dpg = static_cast(v); + } + return allViews; +} + +std::vector DrawPage::getAllViews() const +{ + std::vector views = Views.getValues(); + std::vector allViews; + for (auto& v : views) { + if (v->isDerivedFrom()) { + v = static_cast(v)->getLinkedObject(); + } + + if (!v->isDerivedFrom()) { + continue; + } + + allViews.push_back(v); + if (v->isDerivedFrom()) { + auto* dpg = static_cast(v); if (dpg) {//can't really happen! std::vector pgViews = dpg->Views.getValues(); allViews.insert(allViews.end(), pgViews.begin(), pgViews.end()); @@ -378,8 +413,7 @@ void DrawPage::unsetupObject() std::string pageName = getNameInDocument(); try { - const std::vector currViews = Views.getValues(); - for (auto& v : currViews) { + for (auto& v : Views.getValues()) { //NOTE: the order of objects in Page.Views does not reflect the object hierarchy // this means that a ProjGroup could be deleted before its child ProjGroupItems. // this causes problems when removing objects from document diff --git a/src/Mod/TechDraw/App/DrawPage.h b/src/Mod/TechDraw/App/DrawPage.h index a637190930..593722cb68 100644 --- a/src/Mod/TechDraw/App/DrawPage.h +++ b/src/Mod/TechDraw/App/DrawPage.h @@ -91,7 +91,8 @@ public: int getOrientation() const; bool isUnsetting() { return nowUnsetting; } void requestPaint(); - std::vector getAllViews(); + std::vector getViews() const; + std::vector getAllViews() const; int getNextBalloonIndex(); diff --git a/src/Mod/TechDraw/App/DrawPagePy.xml b/src/Mod/TechDraw/App/DrawPagePy.xml index b0eda4c9d2..53faba733c 100644 --- a/src/Mod/TechDraw/App/DrawPagePy.xml +++ b/src/Mod/TechDraw/App/DrawPagePy.xml @@ -23,6 +23,11 @@ removeView(DrawView) - Remove a View to this Page + + + getViews() - returns a list of all the views on page excluding Views inside Collections + + getAllViews() - returns a list of all the views on page including Views inside Collections diff --git a/src/Mod/TechDraw/App/DrawPagePyImp.cpp b/src/Mod/TechDraw/App/DrawPagePyImp.cpp index aec6cdc6aa..e1d203bc3f 100644 --- a/src/Mod/TechDraw/App/DrawPagePyImp.cpp +++ b/src/Mod/TechDraw/App/DrawPagePyImp.cpp @@ -77,6 +77,38 @@ PyObject* DrawPagePy::removeView(PyObject* args) return PyLong_FromLong(rc); } +PyObject* DrawPagePy::getViews(PyObject* args) +{ + if (!PyArg_ParseTuple(args, "")) { + return nullptr; + } + + DrawPage* page = getDrawPagePtr(); + std::vector allViews = page->getViews(); + + Py::List ret; + for (auto v: allViews) { + if (v->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) { + TechDraw::DrawProjGroupItem* dpgi = static_cast(v); + ret.append(Py::asObject(new TechDraw::DrawProjGroupItemPy(dpgi))); + } + else if (v->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + TechDraw::DrawViewPart* dvp = static_cast(v); + ret.append(Py::asObject(new TechDraw::DrawViewPartPy(dvp))); + } + else if (v->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) { + TechDraw::DrawViewAnnotation* dva = static_cast(v); + ret.append(Py::asObject(new TechDraw::DrawViewAnnotationPy(dva))); + } + else { + TechDraw::DrawView* dv = static_cast(v); + ret.append(Py::asObject(new TechDraw::DrawViewPy(dv))); + } + } + + return Py::new_reference_to(ret); +} + PyObject* DrawPagePy::getAllViews(PyObject* args) { if (!PyArg_ParseTuple(args, "")) { diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index 6773d625e2..99c1b4c278 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include // generated from DrawViewPy.xml @@ -324,7 +325,22 @@ void DrawView::validateScale() int DrawView::countParentPages() const { int count = 0; - std::vector parentAll = getInList(); + std::vector parentRaw = getInList(); + std::vector parentAll; + + // Some parents are Links, we need the pages. + for (auto& parent : parentRaw) { + if (parent->isDerivedFrom()) { + for (auto& linkParent : parent->getInList()) { + if (linkParent->isDerivedFrom()) { + parentAll.push_back(linkParent); + } + } + } + else { + parentAll.push_back(parent); + } + } //it can happen that a page is repeated in the InList, so we need to //prune the duplicates @@ -367,31 +383,34 @@ DrawPage* DrawView::findParentPage() const std::vector DrawView::findAllParentPages() const { - // Get Feature Page - std::vector result; - DrawPage *page = nullptr; - DrawViewCollection *collection = nullptr; - std::vector parentsAll = getInList(); + std::vector pages; + + for (auto parent : getInList()) { + if (parent->isDerivedFrom()) { + for (auto& linkParent : parent->getInList()) { + if (linkParent->isDerivedFrom() + || linkParent->isDerivedFrom()) { + parent = linkParent; + break; + } + } + } - for (auto& parent : parentsAll) { if (parent->isDerivedFrom()) { - page = static_cast(parent); - } else if (parent->isDerivedFrom()) { - collection = static_cast(parent); - page = collection->findParentPage(); + pages.emplace_back(static_cast(parent)); } - - if(page) { - result.emplace_back(page); + else if (parent->isDerivedFrom()) { + auto* collection = static_cast(parent); + pages.emplace_back(collection->findParentPage()); } } //prune the duplicates - std::sort(result.begin(), result.end()); - auto last = std::unique(result.begin(), result.end()); - result.erase(last, result.end()); + std::sort(pages.begin(), pages.end()); + auto last = std::unique(pages.begin(), pages.end()); + pages.erase(last, pages.end()); - return result; + return pages; } bool DrawView::isInClip() diff --git a/src/Mod/TechDraw/App/DrawViewClip.cpp b/src/Mod/TechDraw/App/DrawViewClip.cpp index 4596b8f228..56282cb460 100644 --- a/src/Mod/TechDraw/App/DrawViewClip.cpp +++ b/src/Mod/TechDraw/App/DrawViewClip.cpp @@ -23,6 +23,8 @@ #include "PreCompiled.h" +#include + #include "DrawViewClip.h" #include "DrawPage.h" #include // generated from DrawViewClipPy.xml @@ -65,11 +67,30 @@ void DrawViewClip::onChanged(const App::Property* prop) DrawView::onChanged(prop); } -void DrawViewClip::addView(DrawView *view) +void DrawViewClip::addView(App::DocumentObject* docObj) { - const std::vector currViews = Views.getValues(); - std::vector newViews(currViews); - newViews.push_back(view); + if (!docObj->isDerivedFrom() && !docObj->isDerivedFrom()) { + return; + } + + auto* view = dynamic_cast(docObj); + + if (!view) { + auto* link = dynamic_cast(docObj); + if (!link) { + return; + } + + if (link) { + view = dynamic_cast(link->getLinkedObject()); + if (!view) { + return; + } + } + } + + std::vector newViews(Views.getValues()); + newViews.push_back(docObj); Views.setValues(newViews); QRectF viewRect = view->getRectAligned(); QPointF clipPoint(X.getValue(), Y.getValue()); @@ -91,30 +112,46 @@ void DrawViewClip::addView(DrawView *view) page->Views.touch(); } -void DrawViewClip::removeView(DrawView *view) +void DrawViewClip::removeView(App::DocumentObject* docObj) { - std::vector currViews = Views.getValues(); std::vector newViews; - std::vector::iterator it = currViews.begin(); - for (; it != currViews.end(); it++) { - std::string viewName = view->getNameInDocument(); - if (viewName.compare((*it)->getNameInDocument()) != 0) { - newViews.push_back((*it)); + std::string viewName = docObj->getNameInDocument(); + for (auto* view : Views.getValues()) { + if (viewName.compare(view->getNameInDocument()) != 0) { + newViews.push_back(view); } } Views.setValues(newViews); } +std::vector DrawViewClip::getViews() const +{ + std::vector views = Views.getValues(); + std::vector allViews; + for (auto& v : views) { + if (v->isDerivedFrom(App::Link::getClassTypeId())) { + v = static_cast(v)->getLinkedObject(); + } + + if (!v->isDerivedFrom(DrawView::getClassTypeId())) { + continue; + } + + allViews.push_back(v); + } + return allViews; +} + App::DocumentObjectExecReturn *DrawViewClip::execute() { if (!keepUpdated()) { return App::DocumentObject::StdReturn; } - std::vector children = Views.getValues(); - for (std::vector::iterator it = children.begin(); it != children.end(); ++it) { - if ((*it)->isDerivedFrom()) { - TechDraw::DrawView *view = static_cast(*it); + std::vector children = getViews(); + for (auto* obj : getViews()) { + if (obj->isDerivedFrom()) { + auto* view = static_cast(obj); view->requestPaint(); } } @@ -140,10 +177,9 @@ short DrawViewClip::mustExecute() const std::vector DrawViewClip::getChildViewNames() { std::vector childNames; - std::vector children = Views.getValues(); - for (std::vector::iterator it = children.begin(); it != children.end(); ++it) { - if ((*it)->isDerivedFrom()) { - std::string name = (*it)->getNameInDocument(); + for (auto* obj : getViews()) { + if (obj->isDerivedFrom()) { + std::string name = obj->getNameInDocument(); childNames.push_back(name); } } @@ -152,9 +188,8 @@ std::vector DrawViewClip::getChildViewNames() bool DrawViewClip::isViewInClip(App::DocumentObject* view) { - std::vector children = Views.getValues(); - for (std::vector::iterator it = children.begin(); it != children.end(); ++it) { - if ((*it) == view) { + for (auto* obj : getViews()) { + if (obj == view) { return true; } } diff --git a/src/Mod/TechDraw/App/DrawViewClip.h b/src/Mod/TechDraw/App/DrawViewClip.h index fa6e915362..9a8362832f 100644 --- a/src/Mod/TechDraw/App/DrawViewClip.h +++ b/src/Mod/TechDraw/App/DrawViewClip.h @@ -49,10 +49,12 @@ public: App::PropertyBool ShowFrame; App::PropertyLinkList Views; - void addView(DrawView *view); - void removeView(DrawView *view); + void addView(App::DocumentObject* docObj); + void removeView(App::DocumentObject* docObj); short mustExecute() const override; + std::vector getViews() const; + /** @name methods override Feature */ //@{ /// recalculate the Feature diff --git a/src/Mod/TechDraw/App/DrawViewCollection.cpp b/src/Mod/TechDraw/App/DrawViewCollection.cpp index e90160e95a..b90498b896 100644 --- a/src/Mod/TechDraw/App/DrawViewCollection.cpp +++ b/src/Mod/TechDraw/App/DrawViewCollection.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -80,26 +81,46 @@ App::DocumentObjectExecReturn *DrawViewCollection::execute() return DrawView::execute(); } -int DrawViewCollection::addView(DrawView *view) +int DrawViewCollection::addView(App::DocumentObject* docObj) { // Add the new view to the collection - std::vector newViews(Views.getValues()); - newViews.push_back(view); + + if (!docObj->isDerivedFrom() + && !docObj->isDerivedFrom()) { + return -1; + } + + auto* view = dynamic_cast(docObj); + + if (!view) { + auto* link = dynamic_cast(docObj); + if (!link) { + return -1; + } + + if (link) { + view = dynamic_cast(link->getLinkedObject()); + if (!view) { + return -1; + } + } + } + + std::vector newViews(Views.getValues()); + newViews.push_back(docObj); Views.setValues(newViews); return Views.getSize(); } -int DrawViewCollection::removeView(DrawView *view) +int DrawViewCollection::removeView(App::DocumentObject* docObj) { // Remove the view from the collection - const std::vector currViews = Views.getValues(); std::vector newViews; - std::vector::const_iterator it = currViews.begin(); - for (; it != currViews.end(); it++) { - std::string viewName = view->getNameInDocument(); - if (viewName.compare((*it)->getNameInDocument()) != 0) { - newViews.push_back((*it)); + std::string viewName = docObj->getNameInDocument(); + for (auto* view : Views.getValues()) { + if (viewName.compare(view->getNameInDocument()) != 0) { + newViews.push_back(view); } } Views.setValues(newViews); @@ -107,23 +128,42 @@ int DrawViewCollection::removeView(DrawView *view) return Views.getSize(); } +std::vector DrawViewCollection::getViews() const +{ + std::vector views = Views.getValues(); + std::vector allViews; + for (auto& v : views) { + if (v->isDerivedFrom(App::Link::getClassTypeId())) { + v = static_cast(v)->getLinkedObject(); + } + + if (!v->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { + continue; + } + + allViews.push_back(v); + } + return allViews; +} + //make sure everything in View list represents a real DrawView docObj and occurs only once void DrawViewCollection::rebuildViewList() { const std::vector currViews = Views.getValues(); std::vector newViews; - std::vector children = getOutList(); - for (std::vector::iterator it = children.begin(); it != children.end(); ++it) { - if ((*it)->isDerivedFrom()) { + for (auto* child : getOutList()) { + if (child->isDerivedFrom() || + (child->isDerivedFrom() + && static_cast(child)->getLinkedObject()->isDerivedFrom())) { bool found = false; for (auto& v:currViews) { - if (v == (*it)) { + if (v == child) { found = true; break; } } if (found) { - newViews.push_back((*it)); + newViews.push_back(child); } } } // newViews contains only valid items, but may have duplicates @@ -137,13 +177,12 @@ int DrawViewCollection::countChildren() //Count the children recursively if needed int numChildren = 0; - const std::vector &views = Views.getValues(); - for(std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { - - if((*it)->isDerivedFrom()) { - TechDraw::DrawViewCollection *viewCollection = static_cast(*it); + for(auto* view : Views.getValues()) { + if(view->isDerivedFrom()) { + auto *viewCollection = static_cast(view); numChildren += viewCollection->countChildren() + 1; - } else { + } + else { numChildren += 1; } } @@ -157,9 +196,8 @@ void DrawViewCollection::onDocumentRestored() void DrawViewCollection::lockChildren() { -// Base::Console().Message("DVC::lockChildren()\n"); - for (auto& v:Views.getValues()) { - TechDraw::DrawView *view = dynamic_cast(v); + for (auto& v : getViews()) { + auto *view = dynamic_cast(v); if (!view) { throw Base::ValueError("DrawViewCollection::lockChildren bad View\n"); } @@ -172,25 +210,23 @@ void DrawViewCollection::unsetupObject() nowUnsetting = true; // Remove the collection's views from document - App::Document* doc = getDocument(); - std::string docName = doc->getName(); + std::string docName = getDocument()->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(); + for (auto* view : Views.getValues()) { + std::string viewName = view->getNameInDocument(); Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")", docName.c_str(), viewName.c_str()); } + + std::vector emptyViews; Views.setValues(emptyViews); } QRectF DrawViewCollection::getRect() const { QRectF result; - for (auto& v:Views.getValues()) { - TechDraw::DrawView *view = dynamic_cast(v); + for (auto& v : getViews()) { + auto *view = dynamic_cast(v); if (!view) { throw Base::ValueError("DrawViewCollection::getRect bad View\n"); } diff --git a/src/Mod/TechDraw/App/DrawViewCollection.h b/src/Mod/TechDraw/App/DrawViewCollection.h index ab310bf754..43fd8c78ad 100644 --- a/src/Mod/TechDraw/App/DrawViewCollection.h +++ b/src/Mod/TechDraw/App/DrawViewCollection.h @@ -48,8 +48,9 @@ public: ~DrawViewCollection() override; short mustExecute() const override; - int addView(DrawView *view); - int removeView(DrawView *view); + int addView(App::DocumentObject* obj); + int removeView(App::DocumentObject* obj); + std::vector getViews() const; void rebuildViewList(); bool isUnsetting() { return nowUnsetting; } diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 9ed2f98be9..b918943a6a 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -1360,7 +1360,7 @@ void CmdTechDrawClipGroupRemove::activated(int iMsg) auto view(static_cast(dObj.front())); TechDraw::DrawPage* page = view->findParentPage(); - const std::vector pViews = page->Views.getValues(); + const std::vector pViews = page->getViews(); TechDraw::DrawViewClip* clip(nullptr); for (auto& v : pViews) { clip = dynamic_cast(v); @@ -1721,7 +1721,7 @@ void CmdTechDrawExportPageDXF::activated(int iMsg) return; } - std::vector views = page->Views.getValues(); + std::vector views = page->getViews(); for (auto& v : views) { if (v->isDerivedFrom(TechDraw::DrawViewArch::getClassTypeId())) { QMessageBox::StandardButton rc = QMessageBox::question( diff --git a/src/Mod/TechDraw/Gui/QGSPage.cpp b/src/Mod/TechDraw/Gui/QGSPage.cpp index 176b9ca67b..e3b0a9b5aa 100644 --- a/src/Mod/TechDraw/Gui/QGSPage.cpp +++ b/src/Mod/TechDraw/Gui/QGSPage.cpp @@ -112,17 +112,13 @@ void QGSPage::addChildrenToPage() // A fresh page is added and we iterate through its collected children and add these to Canvas View -MLP // if docobj is a featureviewcollection (ex orthogroup), add its child views. if there are ever children that have children, // we'll have to make this recursive. -WF - const std::vector& grp = m_vpPage->getDrawPage()->Views.getValues(); std::vector childViews; - for (std::vector::const_iterator it = grp.begin(); it != grp.end(); - ++it) { - attachView(*it); - TechDraw::DrawViewCollection* collect = dynamic_cast(*it); + for (auto* view : m_vpPage->getDrawPage()->getViews()) { + attachView(view); + auto* collect = dynamic_cast(view); if (collect) { - childViews = collect->Views.getValues(); - for (std::vector::iterator itChild = childViews.begin(); - itChild != childViews.end(); ++itChild) { - attachView(*itChild); + for (auto* childView : collect->getViews()) { + attachView(childView); } } } @@ -246,9 +242,8 @@ std::vector QGSPage::getViews() const int QGSPage::addQView(QGIView* view) { - //don't add twice! QGIView* existing = getQGIVByName(view->getViewName()); - if (!existing) { + if (!existing) { //don't add twice! addItem(view); TechDraw::DrawView *viewObj = view->getViewObject(); @@ -261,7 +256,7 @@ int QGSPage::addQView(QGIView* view) } view->setPos(viewPos); - auto viewProvider = dynamic_cast(QGIView::getViewProvider(view->getViewObject())); + auto viewProvider = dynamic_cast(QGIView::getViewProvider(viewObj)); if (viewProvider) { view->setZValue(viewProvider->StackOrder.getValue()); } @@ -704,36 +699,30 @@ QGIView* QGSPage::findParent(QGIView* view) const } //If type is dimension we check references first - TechDraw::DrawViewDimension* dim = nullptr; - dim = dynamic_cast(myFeat); + auto* dim = dynamic_cast(myFeat); if (dim) { std::vector objs = dim->References2D.getValues(); if (!objs.empty()) { - std::vector objs = dim->References2D.getValues(); // Attach the dimension to the first object's group - for (std::vector::const_iterator it = qviews.begin(); it != qviews.end(); - ++it) { - if (strcmp((*it)->getViewName(), objs.at(0)->getNameInDocument()) == 0) { - return *it; + for (auto* qview : qviews) { + if (strcmp(qview->getViewName(), objs.at(0)->getNameInDocument()) == 0) { + return qview; } } } } //If type is balloon we check references first - TechDraw::DrawViewBalloon* balloon = nullptr; - balloon = dynamic_cast(myFeat); - + auto* balloon = dynamic_cast(myFeat); if (balloon) { App::DocumentObject* obj = balloon->SourceView.getValue(); if (obj) { // Attach the Balloon to the first object's group - for (std::vector::const_iterator it = qviews.begin(); it != qviews.end(); - ++it) { - if (strcmp((*it)->getViewName(), obj->getNameInDocument()) == 0) { - return *it; + for (auto* qview : qviews) { + if (strcmp(qview->getViewName(), obj->getNameInDocument()) == 0) { + return qview; } } } @@ -782,23 +771,20 @@ void QGSPage::refreshViews() void QGSPage::findMissingViews(const std::vector& list, std::vector& missing) { - for (std::vector::const_iterator it = list.begin(); it != list.end(); - ++it) { + for (auto* obj : list) { - if (!hasQView(*it)) - missing.push_back(*it); + if (!hasQView(obj)) + missing.push_back(obj); - if ((*it)->isDerivedFrom()) { + if (obj->isDerivedFrom()) { std::vector missingChildViews; - TechDraw::DrawViewCollection* collection = - dynamic_cast(*it); + auto* collection = dynamic_cast(obj); // Find Child Views recursively - findMissingViews(collection->Views.getValues(), missingChildViews); + findMissingViews(collection->getViews(), missingChildViews); // Append the views to current missing list - for (std::vector::const_iterator it = missingChildViews.begin(); - it != missingChildViews.end(); ++it) { - missing.push_back(*it); + for (auto* missingChild : missingChildViews) { + missing.push_back(missingChild); } } } @@ -886,19 +872,17 @@ void QGSPage::fixOrphans(bool force) bool QGSPage::orphanExists(const char* viewName, const std::vector& list) { - for (std::vector::const_iterator it = list.begin(); it != list.end(); - ++it) { + for (auto* obj : list) { //Check child objects too recursively - if ((*it)->isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) { - TechDraw::DrawViewCollection* collection = - dynamic_cast(*it); - if (orphanExists(viewName, collection->Views.getValues())) + if (obj->isDerivedFrom()) { + auto* collection = dynamic_cast(obj); + if (orphanExists(viewName, collection->getViews())) return true; } // Unsure if we can compare pointers so rely on name - if (strcmp(viewName, (*it)->getNameInDocument()) == 0) { + if (strcmp(viewName, obj->getNameInDocument()) == 0) { return true; } } diff --git a/src/Mod/TechDraw/Gui/TaskLinkDim.cpp b/src/Mod/TechDraw/Gui/TaskLinkDim.cpp index 7eeb6e4161..a1fe165e2d 100644 --- a/src/Mod/TechDraw/Gui/TaskLinkDim.cpp +++ b/src/Mod/TechDraw/Gui/TaskLinkDim.cpp @@ -89,24 +89,24 @@ void TaskLinkDim::loadAvailDims() if (!guiDoc) return; - std::vector pageViews = m_page->Views.getValues(); - std::vector::iterator itView = pageViews.begin(); std::string result; int selRefType = TechDraw::DrawViewDimension::getRefTypeSubElements(m_subs); //int found = 0; - for (; itView != pageViews.end(); itView++) { - if ((*itView)->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) { - TechDraw::DrawViewDimension* dim = static_cast((*itView)); + for (auto* view : m_page->getViews()) { + if (view->isDerivedFrom()) { + auto* dim = static_cast(view); int dimRefType = dim->getRefType(); if (dimRefType == selRefType) { //potential matches // found++; if (dim->has3DReferences()) { if (dimReferencesSelection(dim)) { loadToTree(dim, true, guiDoc); - } else { + } + else { continue; //already linked to something else } - } else { + } + else { loadToTree(dim, false, guiDoc); } } diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp index 488facd561..c78b9cfa8f 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp @@ -405,27 +405,23 @@ std::vector ViewProviderPage::claimChildren(void) const // any FeatuerView in a DrawViewClip // DrawHatch - const std::vector& views = getDrawPage()->Views.getValues(); - try { - for (std::vector::const_iterator it = views.begin(); - it != views.end(); ++it) { - TechDraw::DrawView* featView = dynamic_cast(*it); + for (auto* obj : getDrawPage()->Views.getValues()) { + auto* featView = dynamic_cast(obj); // If the child view appoints a parent, skip it if (featView && featView->claimParent()) { continue; } - App::DocumentObject* docObj = *it; // Don't collect if dimension, balloon, hatch or member of ClipGroup as these should be grouped elsewhere - if (docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) - || docObj->isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) - || docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId()) + if (obj->isDerivedFrom() + || obj->isDerivedFrom() + || obj->isDerivedFrom() || (featView && featView->isInClip())) continue; else - temp.push_back(*it); + temp.push_back(obj); } return temp; } @@ -455,7 +451,7 @@ void ViewProviderPage::setTemplateMarkers(bool state) templateFeat = getDrawPage()->Template.getValue(); Gui::Document* guiDoc = Gui::Application::Instance->getDocument(templateFeat->getDocument()); Gui::ViewProvider* vp = guiDoc->getViewProvider(templateFeat); - ViewProviderTemplate* vpt = dynamic_cast(vp); + auto* vpt = dynamic_cast(vp); if (vpt) { vpt->setMarkers(state); QGITemplate* t = vpt->getQTemplate(); @@ -570,7 +566,7 @@ void ViewProviderPage::fixSceneDependencies() if (!vp) { continue;// can't fix this one } - TechDrawGui::ViewProviderViewPart* vpvp = dynamic_cast(vp); + auto* vpvp = dynamic_cast(vp); if (!vpvp) { continue;// can't fix this one } diff --git a/src/Mod/TechDraw/Gui/ViewProviderPageExtension.cpp b/src/Mod/TechDraw/Gui/ViewProviderPageExtension.cpp index 4659048517..1caf0b0799 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPageExtension.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderPageExtension.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #include +#include #include #include #include @@ -59,11 +60,17 @@ bool ViewProviderPageExtension::extensionCanDropObjects() const { return true; } bool ViewProviderPageExtension::extensionCanDropObject(App::DocumentObject* obj) const { + // Accept links to views as well. + if (obj->isDerivedFrom(App::Link::getClassTypeId())) { + auto* link = static_cast(obj); + obj = link->getLinkedObject(); + } + //only DrawView objects can live on pages (except special case Template) - if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { + if (obj->isDerivedFrom()) { return true; } - if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) { + if (obj->isDerivedFrom()) { //don't let another extension try to drop templates return true; } @@ -78,11 +85,18 @@ bool ViewProviderPageExtension::extensionCanDropObjectEx(App::DocumentObject* ob Q_UNUSED(owner); Q_UNUSED(subname); Q_UNUSED(elements); + + // Accept links to views as well. + if (obj->isDerivedFrom()) { + auto* link = static_cast(obj); + obj = link->getLinkedObject(); + } + //only DrawView objects can live on pages (except special case Template) - if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { + if (obj->isDerivedFrom()) { return true; } - if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) { + if (obj->isDerivedFrom()) { //don't let another extension try to drop templates return true; } @@ -92,21 +106,54 @@ bool ViewProviderPageExtension::extensionCanDropObjectEx(App::DocumentObject* ob void ViewProviderPageExtension::extensionDropObject(App::DocumentObject* obj) { - if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { + bool linkToView = false; + if (obj->isDerivedFrom(App::Link::getClassTypeId())) { + auto* link = static_cast(obj); + if (link->getLinkedObject()->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { + linkToView = true; + } + } + + if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()) || linkToView) { dropObject(obj); return; } } //this code used to live in ViewProviderPage -void ViewProviderPageExtension::dropObject(App::DocumentObject* docObj) +void ViewProviderPageExtension::dropObject(App::DocumentObject* obj) { - if (docObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) { + if (obj->isDerivedFrom()) { //DPGI can not be dropped onto the Page as it belongs to DPG, not Page return; } - if (docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { - auto dv = static_cast(docObj); + if (obj->isDerivedFrom()) { + auto* link = static_cast(obj); + if (!link->getLinkedObject()->isDerivedFrom()) { + return; + } + + TechDraw::DrawPage* page = nullptr; + for (auto& parent : obj->getInListRecursive()) { + if (parent->isDerivedFrom()) { + page = static_cast(parent); + } + + if (page) { + break; + } + } + if (page) { + page->removeView(obj); + } + + getViewProviderPage()->getDrawPage()->addView(obj); + + return; + } + + if (obj->isDerivedFrom()) { + auto dv = static_cast(obj); if (dv->findParentPage()) { dv->findParentPage()->removeView(dv); } diff --git a/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp b/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp index e0453cc1bd..37b1153128 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp @@ -185,10 +185,9 @@ std::vector ViewProviderProjGroup::claimChildren() const { // Collect any child fields std::vector temp; - const std::vector &views = getObject()->Views.getValues(); try { - for (std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { - temp.push_back(*it); + for (auto* view : getObject()->Views.getValues()) { + temp.push_back(view); } return temp; } catch (...) {