TechDraw: Enable App::Links to work with TechDraw views.
This commit is contained in:
committed by
WandererFan
parent
5ed00d52dc
commit
fc32946149
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user