TechDraw: Enable App::Links to work with TechDraw views.

This commit is contained in:
PaddleStroke
2024-03-29 11:44:01 +01:00
committed by WandererFan
parent ed6c12773e
commit 4d84efb061
15 changed files with 380 additions and 189 deletions

View File

@@ -29,6 +29,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <App/Link.h>
#include <Base/Console.h>
#include <Base/Parameter.h>
@@ -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<App::DocumentObject*>& vals = Views.getValues();
for (std::vector<App::DocumentObject*>::const_iterator it = vals.begin();
it < vals.end(); ++it) {
TechDraw::DrawView* view = dynamic_cast<TechDraw::DrawView*>(*it);
for (auto* obj : getViews()) {
auto* view = dynamic_cast<DrawView*>(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<App::DocumentObject*>& vals = Views.getValues();
for (std::vector<App::DocumentObject*>::const_iterator it = vals.begin(); it < vals.end();
++it) {
TechDraw::DrawProjGroup* view = dynamic_cast<TechDraw::DrawProjGroup*>(*it);
for (auto* obj : getViews()) {
auto* view = dynamic_cast<DrawProjGroup*>(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<TechDraw::DrawTemplate*>(obj);
if (obj && obj->isDerivedFrom(DrawTemplate::getClassTypeId())) {
auto* templ = static_cast<DrawTemplate*>(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<DrawView>()
&& !docObj->isDerivedFrom<App::Link>()) {
return -1;
}
DrawView* view = static_cast<DrawView*>(docObj);
auto* view = dynamic_cast<DrawView*>(docObj);
if (!view) {
auto* link = dynamic_cast<App::Link*>(docObj);
if (!link) {
return -1;
}
view = dynamic_cast<DrawView*>(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<DrawViewDimension>()
&& !docObj->isDerivedFrom<DrawViewBalloon>()) {
view->X.setValue(getPageWidth() / 2.0);
view->Y.setValue(getPageHeight() / 2.0);
}
//add view to list
const std::vector<App::DocumentObject*> currViews = Views.getValues();
std::vector<App::DocumentObject*> newViews(currViews);
std::vector<App::DocumentObject*> 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<DrawView>() && !docObj->isDerivedFrom<App::Link>()) {
return -1;
}
@@ -283,18 +294,16 @@ int DrawPage::removeView(App::DocumentObject* docObj)
if (!docObj->isAttachedToDocument()) {
return -1;
}
const std::vector<App::DocumentObject*> currViews = Views.getValues();
std::vector<App::DocumentObject*> newViews;
std::vector<App::DocumentObject*>::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<App::DocumentObject*> featViews =
getAllViews();//unordered list of views within page
//unordered list of views within page
std::vector<App::DocumentObject*> featViews = getAllViews();
//first, make sure all the Parts have been executed so GeometryObjects exist
for (auto& v : featViews) {
TechDraw::DrawViewPart* part = dynamic_cast<TechDraw::DrawViewPart*>(v);
auto* part = dynamic_cast<DrawViewPart*>(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<TechDraw::DrawViewPart*>(v);
auto* part = dynamic_cast<DrawViewPart*>(v);
if (part) {
continue;
}
TechDraw::DrawView* view = dynamic_cast<TechDraw::DrawView*>(v);
auto* view = dynamic_cast<DrawView*>(v);
if (view) {
view->overrideKeepUpdated(true);
view->recomputeFeature();
@@ -351,14 +360,40 @@ void DrawPage::updateAllViews()
}
}
std::vector<App::DocumentObject*> DrawPage::getAllViews(void)
std::vector<App::DocumentObject*> DrawPage::getViews() const
{
auto views = Views.getValues();//list of docObjects
std::vector<App::DocumentObject*> views = Views.getValues();
std::vector<App::DocumentObject*> allViews;
for (auto& v : views) {
if (v->isDerivedFrom<App::Link>()) {
v = static_cast<App::Link*>(v)->getLinkedObject();
}
if (!v->isDerivedFrom<DrawView>()) {
continue;
}
allViews.push_back(v);
if (v->isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId())) {
TechDraw::DrawProjGroup* dpg = static_cast<TechDraw::DrawProjGroup*>(v);
}
return allViews;
}
std::vector<App::DocumentObject*> DrawPage::getAllViews() const
{
std::vector<App::DocumentObject*> views = Views.getValues();
std::vector<App::DocumentObject*> allViews;
for (auto& v : views) {
if (v->isDerivedFrom<App::Link>()) {
v = static_cast<App::Link*>(v)->getLinkedObject();
}
if (!v->isDerivedFrom<DrawView>()) {
continue;
}
allViews.push_back(v);
if (v->isDerivedFrom<DrawProjGroup>()) {
auto* dpg = static_cast<DrawProjGroup*>(v);
if (dpg) {//can't really happen!
std::vector<App::DocumentObject*> 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<App::DocumentObject*> 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

View File

@@ -91,7 +91,8 @@ public:
int getOrientation() const;
bool isUnsetting() { return nowUnsetting; }
void requestPaint();
std::vector<App::DocumentObject*> getAllViews();
std::vector<App::DocumentObject*> getViews() const;
std::vector<App::DocumentObject*> getAllViews() const;
int getNextBalloonIndex();

View File

@@ -23,6 +23,11 @@
<UserDocu>removeView(DrawView) - Remove a View to this Page</UserDocu>
</Documentation>
</Methode>
<Methode Name="getViews">
<Documentation>
<UserDocu>getViews() - returns a list of all the views on page excluding Views inside Collections</UserDocu>
</Documentation>
</Methode>
<Methode Name="getAllViews">
<Documentation>
<UserDocu>getAllViews() - returns a list of all the views on page including Views inside Collections</UserDocu>

View File

@@ -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<App::DocumentObject*> allViews = page->getViews();
Py::List ret;
for (auto v: allViews) {
if (v->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
TechDraw::DrawProjGroupItem* dpgi = static_cast<TechDraw::DrawProjGroupItem*>(v);
ret.append(Py::asObject(new TechDraw::DrawProjGroupItemPy(dpgi)));
}
else if (v->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(v);
ret.append(Py::asObject(new TechDraw::DrawViewPartPy(dvp)));
}
else if (v->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) {
TechDraw::DrawViewAnnotation* dva = static_cast<TechDraw::DrawViewAnnotation*>(v);
ret.append(Py::asObject(new TechDraw::DrawViewAnnotationPy(dva)));
}
else {
TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(v);
ret.append(Py::asObject(new TechDraw::DrawViewPy(dv)));
}
}
return Py::new_reference_to(ret);
}
PyObject* DrawPagePy::getAllViews(PyObject* args)
{
if (!PyArg_ParseTuple(args, "")) {

View File

@@ -31,6 +31,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <App/Link.h>
#include <Base/Reader.h>
#include <Base/Tools.h>
#include <Mod/TechDraw/App/DrawViewPy.h> // generated from DrawViewPy.xml
@@ -324,7 +325,22 @@ void DrawView::validateScale()
int DrawView::countParentPages() const
{
int count = 0;
std::vector<App::DocumentObject*> parentAll = getInList();
std::vector<App::DocumentObject*> parentRaw = getInList();
std::vector<App::DocumentObject*> parentAll;
// Some parents are Links, we need the pages.
for (auto& parent : parentRaw) {
if (parent->isDerivedFrom<App::Link>()) {
for (auto& linkParent : parent->getInList()) {
if (linkParent->isDerivedFrom<DrawPage>()) {
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<DrawPage*> DrawView::findAllParentPages() const
{
// Get Feature Page
std::vector<DrawPage*> result;
DrawPage *page = nullptr;
DrawViewCollection *collection = nullptr;
std::vector<App::DocumentObject*> parentsAll = getInList();
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 : parentsAll) {
if (parent->isDerivedFrom<DrawPage>()) {
page = static_cast<TechDraw::DrawPage*>(parent);
} else if (parent->isDerivedFrom<DrawViewCollection>()) {
collection = static_cast<TechDraw::DrawViewCollection *>(parent);
page = collection->findParentPage();
pages.emplace_back(static_cast<TechDraw::DrawPage*>(parent));
}
if(page) {
result.emplace_back(page);
else if (parent->isDerivedFrom<DrawViewCollection>()) {
auto* collection = static_cast<TechDraw::DrawViewCollection*>(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()

View File

@@ -23,6 +23,8 @@
#include "PreCompiled.h"
#include <App/Link.h>
#include "DrawViewClip.h"
#include "DrawPage.h"
#include <Mod/TechDraw/App/DrawViewClipPy.h> // 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<App::DocumentObject*> currViews = Views.getValues();
std::vector<App::DocumentObject *> newViews(currViews);
newViews.push_back(view);
if (!docObj->isDerivedFrom<DrawView>() && !docObj->isDerivedFrom<App::Link>()) {
return;
}
auto* view = dynamic_cast<DrawView*>(docObj);
if (!view) {
auto* link = dynamic_cast<App::Link*>(docObj);
if (!link) {
return;
}
if (link) {
view = dynamic_cast<DrawView*>(link->getLinkedObject());
if (!view) {
return;
}
}
}
std::vector<App::DocumentObject*> 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<App::DocumentObject *> currViews = Views.getValues();
std::vector<App::DocumentObject *> newViews;
std::vector<App::DocumentObject*>::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<App::DocumentObject*> DrawViewClip::getViews() const
{
std::vector<App::DocumentObject*> views = Views.getValues();
std::vector<App::DocumentObject*> allViews;
for (auto& v : views) {
if (v->isDerivedFrom(App::Link::getClassTypeId())) {
v = static_cast<App::Link*>(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<App::DocumentObject*> children = Views.getValues();
for (std::vector<App::DocumentObject*>::iterator it = children.begin(); it != children.end(); ++it) {
if ((*it)->isDerivedFrom<DrawView>()) {
TechDraw::DrawView *view = static_cast<TechDraw::DrawView *>(*it);
std::vector<App::DocumentObject*> children = getViews();
for (auto* obj : getViews()) {
if (obj->isDerivedFrom<DrawView>()) {
auto* view = static_cast<TechDraw::DrawView*>(obj);
view->requestPaint();
}
}
@@ -140,10 +177,9 @@ short DrawViewClip::mustExecute() const
std::vector<std::string> DrawViewClip::getChildViewNames()
{
std::vector<std::string> childNames;
std::vector<App::DocumentObject*> children = Views.getValues();
for (std::vector<App::DocumentObject*>::iterator it = children.begin(); it != children.end(); ++it) {
if ((*it)->isDerivedFrom<DrawView>()) {
std::string name = (*it)->getNameInDocument();
for (auto* obj : getViews()) {
if (obj->isDerivedFrom<DrawView>()) {
std::string name = obj->getNameInDocument();
childNames.push_back(name);
}
}
@@ -152,9 +188,8 @@ std::vector<std::string> DrawViewClip::getChildViewNames()
bool DrawViewClip::isViewInClip(App::DocumentObject* view)
{
std::vector<App::DocumentObject*> children = Views.getValues();
for (std::vector<App::DocumentObject*>::iterator it = children.begin(); it != children.end(); ++it) {
if ((*it) == view) {
for (auto* obj : getViews()) {
if (obj == view) {
return true;
}
}

View File

@@ -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<App::DocumentObject*> getViews() const;
/** @name methods override Feature */
//@{
/// recalculate the Feature

View File

@@ -28,6 +28,7 @@
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <App/Link.h>
#include <Base/Console.h>
#include <Base/Interpreter.h>
@@ -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<App::DocumentObject *> newViews(Views.getValues());
newViews.push_back(view);
if (!docObj->isDerivedFrom<DrawView>()
&& !docObj->isDerivedFrom<App::Link>()) {
return -1;
}
auto* view = dynamic_cast<DrawView*>(docObj);
if (!view) {
auto* link = dynamic_cast<App::Link*>(docObj);
if (!link) {
return -1;
}
if (link) {
view = dynamic_cast<DrawView*>(link->getLinkedObject());
if (!view) {
return -1;
}
}
}
std::vector<App::DocumentObject*> 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<App::DocumentObject*> currViews = Views.getValues();
std::vector<App::DocumentObject*> newViews;
std::vector<App::DocumentObject*>::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<App::DocumentObject*> DrawViewCollection::getViews() const
{
std::vector<App::DocumentObject*> views = Views.getValues();
std::vector<App::DocumentObject*> allViews;
for (auto& v : views) {
if (v->isDerivedFrom(App::Link::getClassTypeId())) {
v = static_cast<App::Link*>(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<App::DocumentObject*> currViews = Views.getValues();
std::vector<App::DocumentObject*> newViews;
std::vector<App::DocumentObject*> children = getOutList();
for (std::vector<App::DocumentObject*>::iterator it = children.begin(); it != children.end(); ++it) {
if ((*it)->isDerivedFrom<DrawView>()) {
for (auto* child : getOutList()) {
if (child->isDerivedFrom<DrawView>() ||
(child->isDerivedFrom<App::Link>()
&& static_cast<App::Link*>(child)->getLinkedObject()->isDerivedFrom<DrawView>())) {
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<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
if((*it)->isDerivedFrom<TechDraw::DrawViewCollection>()) {
TechDraw::DrawViewCollection *viewCollection = static_cast<TechDraw::DrawViewCollection *>(*it);
for(auto* view : Views.getValues()) {
if(view->isDerivedFrom<DrawViewCollection>()) {
auto *viewCollection = static_cast<DrawViewCollection *>(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<TechDraw::DrawView *>(v);
for (auto& v : getViews()) {
auto *view = dynamic_cast<DrawView *>(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<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();
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<App::DocumentObject*> emptyViews;
Views.setValues(emptyViews);
}
QRectF DrawViewCollection::getRect() const
{
QRectF result;
for (auto& v:Views.getValues()) {
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(v);
for (auto& v : getViews()) {
auto *view = dynamic_cast<DrawView*>(v);
if (!view) {
throw Base::ValueError("DrawViewCollection::getRect bad View\n");
}

View File

@@ -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<App::DocumentObject*> getViews() const;
void rebuildViewList();
bool isUnsetting() { return nowUnsetting; }

View File

@@ -1360,7 +1360,7 @@ void CmdTechDrawClipGroupRemove::activated(int iMsg)
auto view(static_cast<TechDraw::DrawView*>(dObj.front()));
TechDraw::DrawPage* page = view->findParentPage();
const std::vector<App::DocumentObject*> pViews = page->Views.getValues();
const std::vector<App::DocumentObject*> pViews = page->getViews();
TechDraw::DrawViewClip* clip(nullptr);
for (auto& v : pViews) {
clip = dynamic_cast<TechDraw::DrawViewClip*>(v);
@@ -1721,7 +1721,7 @@ void CmdTechDrawExportPageDXF::activated(int iMsg)
return;
}
std::vector<App::DocumentObject*> views = page->Views.getValues();
std::vector<App::DocumentObject*> views = page->getViews();
for (auto& v : views) {
if (v->isDerivedFrom(TechDraw::DrawViewArch::getClassTypeId())) {
QMessageBox::StandardButton rc = QMessageBox::question(

View File

@@ -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<App::DocumentObject*>& grp = m_vpPage->getDrawPage()->Views.getValues();
std::vector<App::DocumentObject*> childViews;
for (std::vector<App::DocumentObject*>::const_iterator it = grp.begin(); it != grp.end();
++it) {
attachView(*it);
TechDraw::DrawViewCollection* collect = dynamic_cast<TechDraw::DrawViewCollection*>(*it);
for (auto* view : m_vpPage->getDrawPage()->getViews()) {
attachView(view);
auto* collect = dynamic_cast<TechDraw::DrawViewCollection*>(view);
if (collect) {
childViews = collect->Views.getValues();
for (std::vector<App::DocumentObject*>::iterator itChild = childViews.begin();
itChild != childViews.end(); ++itChild) {
attachView(*itChild);
for (auto* childView : collect->getViews()) {
attachView(childView);
}
}
}
@@ -246,9 +242,8 @@ std::vector<QGIView*> 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<ViewProviderDrawingView *>(QGIView::getViewProvider(view->getViewObject()));
auto viewProvider = dynamic_cast<ViewProviderDrawingView *>(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<TechDraw::DrawViewDimension*>(myFeat);
auto* dim = dynamic_cast<TechDraw::DrawViewDimension*>(myFeat);
if (dim) {
std::vector<App::DocumentObject*> objs = dim->References2D.getValues();
if (!objs.empty()) {
std::vector<App::DocumentObject*> objs = dim->References2D.getValues();
// Attach the dimension to the first object's group
for (std::vector<QGIView*>::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<TechDraw::DrawViewBalloon*>(myFeat);
auto* balloon = dynamic_cast<TechDraw::DrawViewBalloon*>(myFeat);
if (balloon) {
App::DocumentObject* obj = balloon->SourceView.getValue();
if (obj) {
// Attach the Balloon to the first object's group
for (std::vector<QGIView*>::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<App::DocumentObject*>& list,
std::vector<App::DocumentObject*>& missing)
{
for (std::vector<App::DocumentObject*>::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<TechDraw::DrawViewCollection>()) {
if (obj->isDerivedFrom<TechDraw::DrawViewCollection>()) {
std::vector<App::DocumentObject*> missingChildViews;
TechDraw::DrawViewCollection* collection =
dynamic_cast<TechDraw::DrawViewCollection*>(*it);
auto* collection = dynamic_cast<TechDraw::DrawViewCollection*>(obj);
// Find Child Views recursively
findMissingViews(collection->Views.getValues(), missingChildViews);
findMissingViews(collection->getViews(), missingChildViews);
// Append the views to current missing list
for (std::vector<App::DocumentObject*>::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<App::DocumentObject*>& list)
{
for (std::vector<App::DocumentObject*>::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<TechDraw::DrawViewCollection*>(*it);
if (orphanExists(viewName, collection->Views.getValues()))
if (obj->isDerivedFrom<TechDraw::DrawViewCollection>()) {
auto* collection = dynamic_cast<TechDraw::DrawViewCollection*>(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;
}
}

View File

@@ -89,24 +89,24 @@ void TaskLinkDim::loadAvailDims()
if (!guiDoc)
return;
std::vector<App::DocumentObject*> pageViews = m_page->Views.getValues();
std::vector<App::DocumentObject*>::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<TechDraw::DrawViewDimension*>((*itView));
for (auto* view : m_page->getViews()) {
if (view->isDerivedFrom<TechDraw::DrawViewDimension>()) {
auto* dim = static_cast<TechDraw::DrawViewDimension*>(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);
}
}

View File

@@ -405,27 +405,23 @@ std::vector<App::DocumentObject*> ViewProviderPage::claimChildren(void) const
// any FeatuerView in a DrawViewClip
// DrawHatch
const std::vector<App::DocumentObject*>& views = getDrawPage()->Views.getValues();
try {
for (std::vector<App::DocumentObject*>::const_iterator it = views.begin();
it != views.end(); ++it) {
TechDraw::DrawView* featView = dynamic_cast<TechDraw::DrawView*>(*it);
for (auto* obj : getDrawPage()->Views.getValues()) {
auto* featView = dynamic_cast<TechDraw::DrawView*>(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<TechDraw::DrawViewDimension>()
|| obj->isDerivedFrom<TechDraw::DrawHatch>()
|| obj->isDerivedFrom<TechDraw::DrawViewBalloon>()
|| (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<ViewProviderTemplate*>(vp);
auto* vpt = dynamic_cast<ViewProviderTemplate*>(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<TechDrawGui::ViewProviderViewPart*>(vp);
auto* vpvp = dynamic_cast<TechDrawGui::ViewProviderViewPart*>(vp);
if (!vpvp) {
continue;// can't fix this one
}

View File

@@ -23,6 +23,7 @@
#include "PreCompiled.h"
#include <App/DocumentObject.h>
#include <App/Link.h>
#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
#include <Mod/TechDraw/App/DrawTemplate.h>
@@ -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<App::Link*>(obj);
obj = link->getLinkedObject();
}
//only DrawView objects can live on pages (except special case Template)
if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
if (obj->isDerivedFrom<TechDraw::DrawView>()) {
return true;
}
if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
if (obj->isDerivedFrom<TechDraw::DrawTemplate>()) {
//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<App::Link>()) {
auto* link = static_cast<App::Link*>(obj);
obj = link->getLinkedObject();
}
//only DrawView objects can live on pages (except special case Template)
if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
if (obj->isDerivedFrom<TechDraw::DrawView>()) {
return true;
}
if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
if (obj->isDerivedFrom<TechDraw::DrawTemplate>()) {
//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<App::Link*>(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<TechDraw::DrawProjGroupItem>()) {
//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<TechDraw::DrawView*>(docObj);
if (obj->isDerivedFrom<App::Link>()) {
auto* link = static_cast<App::Link*>(obj);
if (!link->getLinkedObject()->isDerivedFrom<TechDraw::DrawView>()) {
return;
}
TechDraw::DrawPage* page = nullptr;
for (auto& parent : obj->getInListRecursive()) {
if (parent->isDerivedFrom<TechDraw::DrawPage>()) {
page = static_cast<TechDraw::DrawPage*>(parent);
}
if (page) {
break;
}
}
if (page) {
page->removeView(obj);
}
getViewProviderPage()->getDrawPage()->addView(obj);
return;
}
if (obj->isDerivedFrom<TechDraw::DrawView>()) {
auto dv = static_cast<TechDraw::DrawView*>(obj);
if (dv->findParentPage()) {
dv->findParentPage()->removeView(dv);
}

View File

@@ -185,10 +185,9 @@ std::vector<App::DocumentObject*> ViewProviderProjGroup::claimChildren() const
{
// Collect any child fields
std::vector<App::DocumentObject*> temp;
const std::vector<App::DocumentObject *> &views = getObject()->Views.getValues();
try {
for (std::vector<App::DocumentObject *>::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 (...) {