[TD]improve handling of View in multiple Pages

This commit is contained in:
Wanderer Fan
2022-01-10 10:08:53 -05:00
committed by WandererFan
parent 4cc744c920
commit 3a7a12e436
5 changed files with 106 additions and 7 deletions

View File

@@ -349,6 +349,38 @@ void DrawProjGroupItem::unsetupObject()
DrawViewPart::unsetupObject();
}
//DPGIs have DPG as parent, not Page, so we need to ask the DPG how many Pages own it.
int DrawProjGroupItem::countParentPages() const
{
DrawProjGroup* dpg = getPGroup();
if (dpg != nullptr) {
int count = dpg->countParentPages();
return count;
}
return 0;
}
DrawPage* DrawProjGroupItem::findParentPage() const
{
DrawProjGroup* dpg = getPGroup();
if (dpg != nullptr) {
DrawPage* dp = dpg->findParentPage();
return dp;
}
return nullptr;
}
std::vector<DrawPage*> DrawProjGroupItem::findAllParentPages() const
{
DrawProjGroup* dpg = getPGroup();
if (dpg != nullptr) {
std::vector<DrawPage*> dps = dpg->findAllParentPages();
return dps;
}
std::vector<DrawPage*> empty;
return empty;
}
PyObject *DrawProjGroupItem::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {

View File

@@ -89,6 +89,10 @@ public:
virtual bool checkFit(void) const override { return true; }
virtual bool checkFit(DrawPage*) const override { return true; }
virtual int countParentPages() const override;
virtual DrawPage* findParentPage() const override;
virtual std::vector<DrawPage*> findAllParentPages() const override;
protected:
void onChanged(const App::Property* prop) override;
virtual bool isLocked(void) const override;

View File

@@ -246,6 +246,7 @@ void DrawView::onDocumentRestored()
* in case it is also a child of another duplicate page
* @return
*/
//note this won't find parent pages for DrawProjItem since their parent is DrawProjGroup!
int DrawView::countParentPages() const
{
int count = 0;
@@ -260,6 +261,9 @@ int DrawView::countParentPages() const
return count;
}
//finds the first DrawPage in this Document that claims to own this DrawView
//note that it is possible to manipulate the Views property of DrawPage so that
//more than 1 DrawPage claims a DrawView.
DrawPage* DrawView::findParentPage() const
{
// Get Feature Page
@@ -283,6 +287,33 @@ DrawPage* DrawView::findParentPage() const
return page;
}
std::vector<DrawPage*> DrawView::findAllParentPages() const
{
// Get Feature Page
std::vector<DrawPage*> result;
DrawPage *page = 0;
DrawViewCollection *collection = 0;
std::vector<App::DocumentObject*> parent = getInList();
for (std::vector<App::DocumentObject*>::iterator it = parent.begin(); it != parent.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawPage::getClassTypeId())) {
page = static_cast<TechDraw::DrawPage *>(*it);
}
if ((*it)->getTypeId().isDerivedFrom(DrawViewCollection::getClassTypeId())) {
collection = static_cast<TechDraw::DrawViewCollection *>(*it);
page = collection->findParentPage();
}
if(page) {
result.emplace_back(page);
}
}
return result;
}
bool DrawView::isInClip()
{
std::vector<App::DocumentObject*> parent = getInList();

View File

@@ -23,6 +23,8 @@
#ifndef _DrawView_h_
#define _DrawView_h_
#include <Mod/TechDraw/TechDrawGlobal.h>
#include <boost_signals2.hpp>
#include <QCoreApplication>
@@ -85,6 +87,7 @@ public:
virtual PyObject *getPyObject(void) override;
virtual DrawPage* findParentPage() const;
virtual std::vector<DrawPage*> findAllParentPages() const;
virtual int countParentPages() const;
virtual QRectF getRect() const; //must be overridden by derived class
virtual double autoScale(void) const;