TechDraw: Fix child of linked view.

This commit is contained in:
PaddleStroke
2024-04-17 19:38:11 +02:00
committed by WandererFan
parent 156ae209f5
commit 4f3bb4e543
4 changed files with 61 additions and 39 deletions

View File

@@ -366,8 +366,13 @@ std::vector<App::DocumentObject*> DrawPage::getViews() const
std::vector<App::DocumentObject*> views = Views.getValues();
std::vector<App::DocumentObject*> allViews;
for (auto& v : views) {
bool addChildren = false;
if (v->isDerivedFrom<App::Link>()) {
// In the case of links, child object of the view need to be added since
// they are not in the page Views property.
v = static_cast<App::Link*>(v)->getLinkedObject();
addChildren = true;
}
if (!v->isDerivedFrom<DrawView>()) {
@@ -375,6 +380,14 @@ std::vector<App::DocumentObject*> DrawPage::getViews() const
}
allViews.push_back(v);
if (addChildren) {
for (auto* dep : v->getInList()) {
if (dep && dep->isDerivedFrom<TechDraw::DrawView>()) {
allViews.push_back(dep);
}
}
}
}
return allViews;
}

View File

@@ -385,16 +385,16 @@ std::vector<DrawPage*> DrawView::findAllParentPages() const
{
std::vector<DrawPage*> pages;
for (auto parent : getInList()) {
if (parent->isDerivedFrom<App::Link>()) {
for (auto& linkParent : parent->getInList()) {
if (linkParent->isDerivedFrom<DrawPage>()
|| linkParent->isDerivedFrom<DrawViewCollection>()) {
parent = linkParent;
break;
}
}
}
for (auto parent : getInList()) {
if (parent->isDerivedFrom<App::Link>()) {
for (auto& linkParent : parent->getInList()) {
if (linkParent->isDerivedFrom<DrawPage>()
|| linkParent->isDerivedFrom<DrawViewCollection>()) {
parent = linkParent;
break;
}
}
}
if (parent->isDerivedFrom<DrawPage>()) {
pages.emplace_back(static_cast<TechDraw::DrawPage*>(parent));
@@ -415,9 +415,8 @@ std::vector<DrawPage*> DrawView::findAllParentPages() const
bool DrawView::isInClip()
{
std::vector<App::DocumentObject*> parent = getInList();
for (std::vector<App::DocumentObject*>::iterator it = parent.begin(); it != parent.end(); ++it) {
if ((*it)->isDerivedFrom<DrawViewClip>()) {
for (auto* parent : getInList()) {
if (parent->isDerivedFrom<DrawViewClip>()) {
return true;
}
}
@@ -440,14 +439,9 @@ DrawView *DrawView::claimParent() const
DrawViewClip* DrawView::getClipGroup()
{
std::vector<App::DocumentObject*> parent = getInList();
App::DocumentObject* obj = nullptr;
for (std::vector<App::DocumentObject*>::iterator it = parent.begin(); it != parent.end(); ++it) {
if ((*it)->isDerivedFrom<DrawViewClip>()) {
obj = (*it);
DrawViewClip* result = dynamic_cast<DrawViewClip*>(obj);
return result;
for (auto* obj : getInList()) {
if (obj->isDerivedFrom<DrawViewClip>()) {
return dynamic_cast<DrawViewClip*>(obj);
}
}
return nullptr;
@@ -455,14 +449,11 @@ DrawViewClip* DrawView::getClipGroup()
DrawViewCollection *DrawView::getCollection() const
{
std::vector<App::DocumentObject *> parents = getInList();
for (auto it = parents.begin(); it != parents.end(); ++it) {
auto parentCollection = dynamic_cast<DrawViewCollection *>(*it);
if (parentCollection) {
return parentCollection;
for (auto* obj : getInList()) {
if (obj->isDerivedFrom<DrawViewCollection>()) {
return dynamic_cast<DrawViewCollection*>(obj);
}
}
return nullptr;
}

View File

@@ -112,7 +112,6 @@ 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
std::vector<App::DocumentObject*> childViews;
for (auto* view : m_vpPage->getDrawPage()->getViews()) {
attachView(view);
auto* collect = dynamic_cast<TechDraw::DrawViewCollection*>(view);
@@ -833,7 +832,8 @@ void QGSPage::fixOrphans(bool force)
}
else {
//DrawView exists in Document. Does it belong to this DrawPage?
int numParentPages = qv->getViewObject()->countParentPages();
TechDraw::DrawView* viewObj = qv->getViewObject();
int numParentPages = viewObj->countParentPages();
if (numParentPages == 0) {
//DrawView does not belong to any DrawPage
//remove QGItem from QGScene
@@ -841,8 +841,16 @@ void QGSPage::fixOrphans(bool force)
}
else if (numParentPages == 1) {
//Does DrawView belong to this DrawPage?
TechDraw::DrawPage* parentPage = qv->getViewObject()->findParentPage();
TechDraw::DrawPage* parentPage = viewObj->findParentPage();
if (thisPage != parentPage) {
// The view could be a child of a link (ea Dimension).
TechDraw::DrawView* parentView = viewObj->claimParent();
for (auto* v : thisPage->getViews()) {
if (v == parentView) {
continue;
}
}
//DrawView does not belong to this DrawPage
//remove QGItem from QGScene
removeQView(qv);

View File

@@ -129,25 +129,35 @@ void ViewProviderPageExtension::dropObject(App::DocumentObject* obj)
}
if (obj->isDerivedFrom<App::Link>()) {
auto* link = static_cast<App::Link*>(obj);
if (!link->getLinkedObject()->isDerivedFrom<TechDraw::DrawView>()) {
obj = link->getLinkedObject();
if (!obj->isDerivedFrom<TechDraw::DrawView>()) {
return;
}
TechDraw::DrawPage* page = nullptr;
for (auto& parent : obj->getInListRecursive()) {
if (parent->isDerivedFrom<TechDraw::DrawPage>()) {
page = static_cast<TechDraw::DrawPage*>(parent);
std::vector<App::DocumentObject*> deps;
for (auto& inObj : obj->getInList()) {
if (inObj && inObj->isDerivedFrom<TechDraw::DrawView>()) {
deps.push_back(inObj);
}
}
if (page) {
break;
TechDraw::DrawPage* page = nullptr;
for (auto& inObj : link->getInList()) {
if (inObj->isDerivedFrom<TechDraw::DrawPage>()) {
page = static_cast<TechDraw::DrawPage*>(inObj);
}
}
if (page) {
page->removeView(obj);
for (auto* dep : deps) {
page->removeView(dep);
}
page->removeView(link);
}
getViewProviderPage()->getDrawPage()->addView(obj);
getViewProviderPage()->getDrawPage()->addView(link, false);
for (auto* dep : deps) {
getViewProviderPage()->getDrawPage()->addView(dep, false);
}
return;
}