[TechDraw] Reimplement Rich Annotation parent linking

This commit is contained in:
pavltom
2024-02-15 17:06:21 +01:00
committed by WandererFan
parent df86220427
commit ed3a1a6184
18 changed files with 136 additions and 194 deletions

View File

@@ -242,8 +242,9 @@ int DrawPage::addView(App::DocumentObject* docObj)
}
DrawView* view = static_cast<DrawView*>(docObj);
//position all new views in center of Page (exceptDVDimension)
if (!docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())
//position all new views without owners in center of Page (exceptDVDimension)
if (!view->claimParent()
&& !docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())
&& !docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) {
view->X.setValue(getPageWidth() / 2.0);
view->Y.setValue(getPageHeight() / 2.0);

View File

@@ -57,6 +57,7 @@ public:
DrawView* getBaseView() const;
DrawPage* findParentPage() const override;
App::PropertyLink *getOwnerProperty() override { return &AnnoParent; }
protected:
void onChanged(const App::Property* prop) override;

View File

@@ -136,6 +136,31 @@ void DrawView::checkScale()
}
}
void DrawView::touchTreeOwner(App::DocumentObject *owner) const
{
auto ownerView = dynamic_cast<DrawView *>(owner);
if (ownerView) {
ownerView->touch();
}
else { // If no owner is specified, touch all parent pages
for (auto page : findAllParentPages()) {
page->touch();
}
}
}
void DrawView::onBeforeChange(const App::Property *prop)
{
// To avoid keeping the previous parent in some extra variable, we will mark
// the previous owner for update before the property is actually changed.
App::PropertyLink *ownerProp = getOwnerProperty();
if (ownerProp && prop == ownerProp && !isRestoring()) {
touchTreeOwner(ownerProp->getValue());
}
App::DocumentObject::onBeforeChange(prop);
}
void DrawView::onChanged(const App::Property* prop)
{
//Coding note: calling execute, recompute or recomputeFeature inside an onChanged
@@ -192,6 +217,11 @@ void DrawView::onChanged(const App::Property* prop)
Y.purgeTouched();
}
App::PropertyLink *ownerProp = getOwnerProperty();
if (ownerProp && prop == ownerProp) {
touchTreeOwner(ownerProp->getValue());
}
App::DocumentObject::onChanged(prop);
}
@@ -377,6 +407,11 @@ bool DrawView::isInClip()
DrawView *DrawView::claimParent() const
{
App::PropertyLink *ownerProp = const_cast<DrawView *>(this)->getOwnerProperty();
if (ownerProp) {
return dynamic_cast<DrawView *>(ownerProp->getValue());
}
return nullptr;
}

View File

@@ -118,7 +118,10 @@ public:
void translateLabel(std::string context, std::string baseName, std::string uniqueName);
virtual App::PropertyLink *getOwnerProperty() { return nullptr; }
protected:
void onBeforeChange(const App::Property *prop) override;
void onChanged(const App::Property* prop) override;
virtual void validateScale();
std::string pageFeatName;
@@ -128,6 +131,8 @@ protected:
int prefScaleType();
double prefScale();
void touchTreeOwner(App::DocumentObject *owner) const;
private:
static const char* ScaleTypeEnums[];
static App::PropertyFloatConstraint::Constraints scaleRange;

View File

@@ -61,28 +61,6 @@ DrawViewSymbol::DrawViewSymbol()
DrawViewSymbol::~DrawViewSymbol() {}
void DrawViewSymbol::touchTreeOwner()
{
auto owner = dynamic_cast<DrawView *>(Owner.getValue());
if (owner) {
owner->touch();
}
else { // If no owner is specified, touch all parent pages
for (auto page : findAllParentPages()) {
page->touch();
}
}
}
void DrawViewSymbol::onBeforeChange(const App::Property *prop)
{
if (prop == &Owner && !isRestoring()) {
touchTreeOwner();
}
TechDraw::DrawView::onBeforeChange(prop);
}
void DrawViewSymbol::onChanged(const App::Property* prop)
{
if (prop == &Symbol) {
@@ -97,11 +75,6 @@ void DrawViewSymbol::onChanged(const App::Property* prop)
//1 cycle
updateFieldsInSymbol();
}
else if (prop == &Owner) {
if (!isRestoring()) {
touchTreeOwner();
}
}
TechDraw::DrawView::onChanged(prop);
}
@@ -124,11 +97,6 @@ App::DocumentObjectExecReturn* DrawViewSymbol::execute()
return DrawView::execute();
}
DrawView *DrawViewSymbol::claimParent() const
{
return dynamic_cast<DrawView *>(Owner.getValue());
}
QRectF DrawViewSymbol::getRect() const
{
double w = 64.0;//must default to something

View File

@@ -61,16 +61,15 @@ public:
const char* getViewProviderName() const override {
return "TechDrawGui::ViewProviderSymbol";
}
DrawView *claimParent(void) const override;
QRectF getRect() const override;
bool checkFit(TechDraw::DrawPage* p) const override;
App::PropertyLink *getOwnerProperty() override { return &Owner; }
//return PyObject as DrawViewSymbolPy
PyObject *getPyObject() override;
protected:
void touchTreeOwner();
void onBeforeChange(const App::Property* prop) override;
void onChanged(const App::Property* prop) override;
Base::BoundBox3d bbox;

View File

@@ -1626,8 +1626,6 @@ void CmdTechDrawSurfaceFinishSymbols::activated(int iMsg)
{
TechDraw::DrawPage *page = DrawGuiUtil::findPage(this);
if (!page) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("SurfaceFinishSymbols"),
QObject::tr("No page to insert the symbol!"));
return;
}
@@ -1652,6 +1650,9 @@ void CmdTechDrawSurfaceFinishSymbols::activated(int iMsg)
}
Gui::Control().showDialog(new TechDrawGui::TaskDlgSurfaceFinishSymbols(ownerName));
updateActive();
Gui::Selection().clearSelection();
}
bool CmdTechDrawSurfaceFinishSymbols::isActive()

View File

@@ -669,16 +669,17 @@ void QGIView::switchParentItem(QGIView *targetParent)
if (currentParent != targetParent) {
if (targetParent) {
targetParent->addToGroup(this);
targetParent->updateView();
if (currentParent) {
currentParent->updateView();
}
}
else {
currentParent->removeFromGroup(this);
}
if (currentParent) {
currentParent->updateView();
}
if (targetParent) {
targetParent->updateView();
while (currentParent) {
currentParent->removeFromGroup(this);
currentParent->updateView();
currentParent = dynamic_cast<QGIView *>(this->parentItem());
}
}
}
}

View File

@@ -80,6 +80,7 @@
#include "QGIWeldSymbol.h"
#include "QGSPage.h"
#include "Rez.h"
#include "ViewProviderDrawingView.h"
#include "ViewProviderPage.h"
#include "ZVALUE.h"
@@ -129,7 +130,6 @@ void QGSPage::addChildrenToPage()
setDimensionGroups();
setBalloonGroups();
setLeaderGroups();
setRichAnnoGroups();
App::DocumentObject* obj = m_vpPage->getDrawPage()->Template.getValue();
auto pageTemplate(dynamic_cast<TechDraw::DrawTemplate*>(obj));
@@ -251,23 +251,23 @@ int QGSPage::addQView(QGIView* view)
if (!existing) {
addItem(view);
TechDraw::DrawView *viewObj = view->getViewObject();
// Preserve the desired position, as addToGroup() adjusts the child view's position
QPointF viewPos(Rez::guiX(viewObj->X.getValue()), -Rez::guiX(viewObj->Y.getValue()));
// Find if it belongs to a parent
QGIView* parent = nullptr;
parent = findParent(view);
QPointF viewPos(Rez::guiX(view->getViewObject()->X.getValue()),
Rez::guiX(view->getViewObject()->Y.getValue() * -1));
QGIView *parent = findParent(view);
if (parent) {
// move child view to center of parent
QPointF posRef(0., 0.);
QPointF mapPos = view->mapToItem(parent, posRef);
view->moveBy(-mapPos.x(), -mapPos.y());
parent->addToGroup(view);
}
view->setPos(viewPos);
auto viewProvider = dynamic_cast<ViewProviderDrawingView *>(QGIView::getViewProvider(view->getViewObject()));
if (viewProvider) {
view->setZValue(viewProvider->StackOrder.getValue());
}
view->updateView(true);
}
return 0;
@@ -447,19 +447,11 @@ QGIView* QGSPage::addDrawViewAnnotation(TechDraw::DrawViewAnnotation* annoFeat)
QGIView* QGSPage::addDrawViewSymbol(TechDraw::DrawViewSymbol* symbolFeat)
{
auto qview(new QGIViewSymbol);
qview->setViewFeature(symbolFeat);
QGIViewSymbol *symbolView = new QGIViewSymbol;
symbolView->setViewFeature(symbolFeat);
auto owner = dynamic_cast<TechDraw::DrawView *>(symbolFeat->Owner.getValue());
if (owner) {
auto parent = dynamic_cast<QGIView *>(findQViewForDocObj(owner));
if (parent) {
qview->switchParentItem(parent);
}
}
addQView(qview);
return qview;
addQView(symbolView);
return symbolView;
}
QGIView* QGSPage::addDrawViewClip(TechDraw::DrawViewClip* view)
@@ -631,27 +623,13 @@ void QGSPage::addLeaderToParent(QGILeaderLine* lead, QGIView* parent)
QGIView* QGSPage::addRichAnno(TechDraw::DrawRichAnno* richFeat)
{
QGIRichAnno* annoGroup = new QGIRichAnno();
addItem(annoGroup);
annoGroup->setViewFeature(richFeat);
QGIRichAnno *richView = new QGIRichAnno;
richView->setViewFeature(richFeat);
QGIView* parent = findParent(annoGroup);
if (parent)
addAnnoToParent(annoGroup, parent);
annoGroup->updateView(true);
return annoGroup;
addQView(richView);
return richView;
}
void QGSPage::addAnnoToParent(QGIRichAnno* anno, QGIView* parent)
{
// Base::Console().Message("QGSP::addAnnoToParent()\n");
parent->addToGroup(anno);
anno->setZValue(ZVALUE::DIMENSION);
}
QGIView* QGSPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weldFeat)
{
// Base::Console().Message("QGSP::addWeldSymbol()\n");
@@ -729,24 +707,6 @@ void QGSPage::setLeaderGroups(void)
}
}
void QGSPage::setRichAnnoGroups(void)
{
// Base::Console().Message("QGSP::setRichAnnoGroups()\n");
const std::vector<QGIView*>& allItems = getViews();
int annoItemType = QGraphicsItem::UserType + 233;
//make sure that qgirichanno belongs to correct parent.
for (auto& item : allItems) {
if (item->type() == annoItemType && !item->group()) {
QGIView* parent = findParent(item);
if (parent) {
QGIRichAnno* anno = dynamic_cast<QGIRichAnno*>(item);
addAnnoToParent(anno, parent);
}
}
}
}
//! find the graphic for a DocumentObject
QGIView* QGSPage::findQViewForDocObj(App::DocumentObject* obj) const
{
@@ -762,7 +722,7 @@ QGIView* QGSPage::findQViewForDocObj(App::DocumentObject* obj) const
}
//! find the graphic for DocumentObject with name
QGIView* QGSPage::getQGIVByName(std::string name)
QGIView* QGSPage::getQGIVByName(std::string name) const
{
QList<QGraphicsItem*> qgItems = items();
QList<QGraphicsItem*>::iterator it = qgItems.begin();
@@ -785,6 +745,14 @@ QGIView* QGSPage::findParent(QGIView* view) const
const std::vector<QGIView*> qviews = getViews();
TechDraw::DrawView* myFeat = view->getViewObject();
TechDraw::DrawView *ownerFeat = myFeat->claimParent();
if (ownerFeat) {
QGIView *ownerView = getQGIVByName(ownerFeat->getNameInDocument());
if (ownerView) {
return ownerView;
}
}
//If type is dimension we check references first
TechDraw::DrawViewDimension* dim = nullptr;
dim = dynamic_cast<TechDraw::DrawViewDimension*>(myFeat);
@@ -838,21 +806,6 @@ QGIView* QGSPage::findParent(QGIView* view) const
}
}
//if type is a RichTextAnno we check AnnoParent
TechDraw::DrawRichAnno* anno = dynamic_cast<TechDraw::DrawRichAnno*>(myFeat);
if (anno) {
App::DocumentObject* obj = anno->AnnoParent.getValue();
if (obj) {
std::string parentName = obj->getNameInDocument();
for (std::vector<QGIView*>::const_iterator it = qviews.begin(); it != qviews.end();
++it) {
if (strcmp((*it)->getViewName(), parentName.c_str()) == 0) {
return *it;
}
}
}
}
// Check if part of view collection
for (std::vector<QGIView*>::const_iterator it = qviews.begin(); it != qviews.end(); ++it) {
QGIViewCollection* grp = nullptr;
@@ -1014,8 +967,6 @@ void QGSPage::fixOrphans(bool force)
}
}
}
setRichAnnoGroups();//hack to fix QGIRA parentage;
}
bool QGSPage::orphanExists(const char* viewName, const std::vector<App::DocumentObject*>& list)

View File

@@ -66,7 +66,6 @@ class QGITemplate;
class ViewProviderPage;
class QGIViewBalloon;
class QGILeaderLine;
class QGIRichAnno;
class QGITile;
class TechDrawGuiExport QGSPage: public QGraphicsScene
@@ -102,7 +101,7 @@ public:
void redraw1View(TechDraw::DrawView* dView);
QGIView* findQViewForDocObj(App::DocumentObject* obj) const;
QGIView* getQGIVByName(std::string name);
QGIView* getQGIVByName(std::string name) const;
QGIView* findParent(QGIView*) const;
void findMissingViews(const std::vector<App::DocumentObject*>& list,
std::vector<App::DocumentObject*>& missing);
@@ -113,7 +112,6 @@ public:
void addDimToParent(QGIViewDimension* dim, QGIView* parent);
void addLeaderToParent(QGILeaderLine* lead, QGIView* parent);
void addAnnoToParent(QGIRichAnno* anno, QGIView* parent);
std::vector<QGIView*> getViews() const;
@@ -142,7 +140,6 @@ public:
void setDimensionGroups();
void setBalloonGroups();
void setLeaderGroups();
void setRichAnnoGroups();
protected:
QColor getBackgroundColor();

View File

@@ -374,14 +374,6 @@ bool TaskSurfaceFinishSymbols::accept()
surfaceSymbol->Rotation.setValue(ui->leAngle->text().toDouble());
auto view = dynamic_cast<TechDraw::DrawView *>(owner);
auto page = dynamic_cast<TechDraw::DrawPage *>(owner);
if (!page && view) {
page = view->findParentPage();
}
if (page) {
page->addView(surfaceSymbol);
}
surfaceSymbol->Owner.setValue(view);
surfaceSymbol->X.setValue(placement.x);
surfaceSymbol->Y.setValue(placement.y);
@@ -391,6 +383,14 @@ bool TaskSurfaceFinishSymbols::accept()
viewProvider->StackOrder.setValue(ZVALUE::DIMENSION);
}
auto page = dynamic_cast<TechDraw::DrawPage *>(owner);
if (!page && view) {
page = view->findParentPage();
}
if (page) {
page->addView(surfaceSymbol);
}
Gui::Command::commitCommand();
return true;
}

View File

@@ -220,12 +220,45 @@ void ViewProviderDrawingView::finishRestoring()
void ViewProviderDrawingView::updateData(const App::Property* prop)
{
TechDraw::DrawView *obj = getViewObject();
App::PropertyLink *ownerProp = obj->getOwnerProperty();
//only move the view on X, Y change
if (prop == &(getViewObject()->X) ||
prop == &(getViewObject()->Y) ){
if (prop == &obj->X
|| prop == &obj->Y) {
QGIView* qgiv = getQView();
if (qgiv) {
qgiv->QGIView::updateView(true);
// Update also the owner/parent view, if there is any
if (ownerProp) {
auto owner = dynamic_cast<TechDraw::DrawView *>(ownerProp->getValue());
if (owner) {
auto page = dynamic_cast<QGSPage *>(qgiv->scene());
if (page) {
QGIView *ownerView = page->getQGIVByName(owner->getNameInDocument());
if (ownerView) {
ownerView->updateView();
}
}
}
}
}
}
else if (ownerProp && prop == ownerProp) {
QGIView* qgiv = getQView();
if (qgiv) {
QGIView *ownerView = nullptr;
auto owner = dynamic_cast<TechDraw::DrawView *>(ownerProp->getValue());
if (owner) {
auto page = dynamic_cast<QGSPage *>(qgiv->scene());
if (page) {
ownerView = page->getQGIVByName(owner->getNameInDocument());
}
}
qgiv->switchParentItem(ownerView);
qgiv->updateView();
}
}
@@ -442,23 +475,3 @@ TechDraw::DrawView* ViewProviderDrawingView::getViewObject() const
{
return dynamic_cast<TechDraw::DrawView*>(pcObject);
}
void ViewProviderDrawingView::switchOwnerProperty(App::PropertyLink &prop)
{
QGIView *qv = getQView();
if (!qv) {
return;
}
QGIView *targetParent = nullptr;
auto owner = dynamic_cast<TechDraw::DrawView *>(prop.getValue());
if (owner) {
auto vp = dynamic_cast<ViewProviderDrawingView *>(QGIView::getViewProvider(owner));
if (vp) {
targetParent = vp->getQView();
}
}
qv->switchParentItem(targetParent);
qv->updateView();
}

View File

@@ -99,8 +99,6 @@ public:
const char* whoAmI() const;
void switchOwnerProperty(App::PropertyLink &prop);
private:
void multiParentPaint(std::vector<TechDraw::DrawPage*>& pages);
void singleParentPaint(const TechDraw::DrawView* dv);

View File

@@ -135,22 +135,19 @@ void ViewProviderLeader::onChanged(const App::Property* p)
std::vector<App::DocumentObject*> ViewProviderLeader::claimChildren() const
{
// Collect any child Document Objects and put them in the right place in the Feature tree
// valid children of a ViewLeader are:
// - Rich Annotations
// - Weld Symbols
// Valid children of a ViewLeader are any drawing views declaring the leader line as their parent,
// notably Rich Annotations, Weld Symbols and Surface Finish Symbols
std::vector<App::DocumentObject*> temp;
const std::vector<App::DocumentObject *> &views = getFeature()->getInList();
try {
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
auto view = dynamic_cast<TechDraw::DrawView *>(*it);
if (view && view->claimParent() == getViewObject()) {
temp.push_back(view);
continue;
}
if ((*it)->isDerivedFrom<TechDraw::DrawRichAnno>()) {
temp.push_back((*it));
} else if ((*it)->isDerivedFrom<TechDraw::DrawWeldSymbol>()) {
if ((*it)->isDerivedFrom<TechDraw::DrawWeldSymbol>()) {
temp.push_back((*it));
}
}

View File

@@ -45,7 +45,6 @@
#include <Mod/TechDraw/App/DrawLeaderLine.h>
#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
#include <Mod/TechDraw/App/DrawRichAnno.h>
#include <Mod/TechDraw/App/DrawTemplate.h>
#include <Mod/TechDraw/App/DrawView.h>
#include <Mod/TechDraw/App/DrawViewBalloon.h>
@@ -394,7 +393,6 @@ std::vector<App::DocumentObject*> ViewProviderPage::claimChildren(void) const
// DrawViewDimension
// DrawViewBalloon
// DrawLeaderLine
// DrawRichAnno
// any FeatuerView in a DrawViewClip
// DrawHatch
// DrawWeldSymbol
@@ -412,21 +410,11 @@ std::vector<App::DocumentObject*> ViewProviderPage::claimChildren(void) const
}
App::DocumentObject* docObj = *it;
//DrawRichAnno with no parent is child of Page
TechDraw::DrawRichAnno* dra = dynamic_cast<TechDraw::DrawRichAnno*>(*it);
if (dra) {
if (!dra->AnnoParent.getValue()) {
temp.push_back(*it);//no parent, belongs to page
}
continue;//has a parent somewhere else
}
// Don't collect if dimension, projection group item, hatch or member of ClipGroup as these should be grouped elsewhere
if (docObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())
|| docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())
|| docObj->isDerivedFrom(TechDraw::DrawHatch::getClassTypeId())
|| docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())
|| docObj->isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId())
|| docObj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())
|| docObj->isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId())
|| (featView && featView->isInClip()))

View File

@@ -95,14 +95,6 @@ void ViewProviderRichAnno::updateData(const App::Property* p)
}
}
if (p == &(getViewObject()->AnnoParent)) {
// Base::Console().Message("VPRA::updateData(AnnoParent) - vpp: %X\n", getViewProviderPage());
if (getViewProviderPage() &&
getViewProviderPage()->getQGSPage()) {
getViewProviderPage()->getQGSPage()->setRichAnnoGroups();
}
}
ViewProviderDrawingView::updateData(p);
}

View File

@@ -51,9 +51,6 @@ void ViewProviderSymbol::updateData(const App::Property* prop)
|| prop == &obj->EditableTexts) {
onGuiRepaint(obj);
}
else if (prop == &obj->Owner) {
switchOwnerProperty(obj->Owner);
}
ViewProviderDrawingView::updateData(prop);
}

View File

@@ -214,7 +214,7 @@ std::vector<App::DocumentObject*> ViewProviderViewPart::claimChildren() const
// - Leaders
// - Hatches
// - GeomHatches
// - Leaders
// - any drawing views declaring this view as their parent
std::vector<App::DocumentObject*> temp;
const std::vector<App::DocumentObject *> &views = getViewPart()->getInList();
try {
@@ -245,8 +245,6 @@ std::vector<App::DocumentObject*> ViewProviderViewPart::claimChildren() const
temp.push_back((*it));
} else if ((*it)->isDerivedFrom<TechDraw::DrawViewBalloon>()) {
temp.push_back((*it));
} else if ((*it)->isDerivedFrom<TechDraw::DrawRichAnno>()) {
temp.push_back((*it));
} else if ((*it)->isDerivedFrom<TechDraw::DrawLeaderLine>()) {
temp.push_back((*it));
}