[TechDraw] Add Owner property to Symbols
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
#include <Mod/TechDraw/App/DrawView.h>
|
||||
#include <Mod/TechDraw/App/DrawViewAnnotation.h>
|
||||
#include <Mod/TechDraw/App/DrawViewPart.h>
|
||||
#include <Mod/TechDraw/App/DrawViewSymbol.h>
|
||||
#include <Mod/TechDraw/App/DrawWeldSymbol.h>
|
||||
#include <Mod/TechDraw/App/DrawUtil.h>
|
||||
|
||||
@@ -1618,19 +1619,39 @@ CmdTechDrawSurfaceFinishSymbols::CmdTechDrawSurfaceFinishSymbols()
|
||||
void CmdTechDrawSurfaceFinishSymbols::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
|
||||
std::string ownerName;
|
||||
std::vector<Gui::SelectionObject> selection = this->getSelection().getSelectionEx();
|
||||
if (selection.empty())
|
||||
{
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("SurfaceFinishSymbols"), QObject::tr("Selection is empty"));
|
||||
return;
|
||||
TechDraw::DrawPage *page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("SurfaceFinishSymbols"),
|
||||
QObject::tr("No page to insert the symbol!"));
|
||||
return;
|
||||
}
|
||||
|
||||
ownerName = page->getNameInDocument();
|
||||
}
|
||||
TechDraw::DrawViewPart* objFeat = dynamic_cast<TechDraw::DrawViewPart*> (selection[0].getObject());
|
||||
if(!objFeat)
|
||||
{
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("SurfaceFinishSymbols"), QObject::tr("No object selected"));
|
||||
return;
|
||||
else {
|
||||
auto objFeat = dynamic_cast<TechDraw::DrawView *>(selection.front().getObject());
|
||||
if (!objFeat->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())
|
||||
&& !objFeat->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("SurfaceFinishSymbols"),
|
||||
QObject::tr("Selected object is not a part view, nor a leader line"));
|
||||
return;
|
||||
}
|
||||
|
||||
ownerName = objFeat->getNameInDocument();
|
||||
|
||||
const std::vector<std::string> &subNames = selection.front().getSubNames();
|
||||
if (!subNames.empty()) {
|
||||
ownerName += '.';
|
||||
ownerName += subNames.front();
|
||||
}
|
||||
}
|
||||
Gui::Control().showDialog(new TechDrawGui::TaskDlgSurfaceFinishSymbols(objFeat));
|
||||
|
||||
Gui::Control().showDialog(new TechDrawGui::TaskDlgSurfaceFinishSymbols(ownerName));
|
||||
}
|
||||
|
||||
bool CmdTechDrawSurfaceFinishSymbols::isActive()
|
||||
|
||||
@@ -663,6 +663,26 @@ void QGIView::addArbitraryItem(QGraphicsItem* qgi)
|
||||
}
|
||||
}
|
||||
|
||||
void QGIView::switchParentItem(QGIView *targetParent)
|
||||
{
|
||||
auto currentParent = dynamic_cast<QGIView *>(this->parentItem());
|
||||
if (currentParent != targetParent) {
|
||||
if (targetParent) {
|
||||
targetParent->addToGroup(this);
|
||||
}
|
||||
else {
|
||||
currentParent->removeFromGroup(this);
|
||||
}
|
||||
|
||||
if (currentParent) {
|
||||
currentParent->updateView();
|
||||
}
|
||||
if (targetParent) {
|
||||
targetParent->updateView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QGIView::setStack(int z)
|
||||
{
|
||||
m_zOrder = z;
|
||||
|
||||
@@ -155,8 +155,8 @@ public:
|
||||
static int exactFontSize(std::string fontFamily, double nominalSize);
|
||||
|
||||
virtual void removeChild(QGIView* child);
|
||||
|
||||
virtual void addArbitraryItem(QGraphicsItem* qgi);
|
||||
virtual void switchParentItem(QGIView *targetParent);
|
||||
|
||||
// Mouse handling
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
@@ -448,9 +448,16 @@ QGIView* QGSPage::addDrawViewAnnotation(TechDraw::DrawViewAnnotation* annoFeat)
|
||||
QGIView* QGSPage::addDrawViewSymbol(TechDraw::DrawViewSymbol* symbolFeat)
|
||||
{
|
||||
auto qview(new QGIViewSymbol);
|
||||
|
||||
qview->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;
|
||||
}
|
||||
|
||||
@@ -32,10 +32,14 @@
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Mod/TechDraw/App/DrawPage.h>
|
||||
#include <Mod/TechDraw/App/DrawUtil.h>
|
||||
#include <Mod/TechDraw/App/DrawViewSymbol.h>
|
||||
|
||||
#include "QGIView.h"
|
||||
#include "ui_TaskSurfaceFinishSymbols.h"
|
||||
#include "TaskSurfaceFinishSymbols.h"
|
||||
#include "ViewProviderSymbol.h"
|
||||
#include "ZVALUE.h"
|
||||
|
||||
|
||||
using namespace Gui;
|
||||
@@ -79,16 +83,60 @@ std::string SvgString::finish()
|
||||
// TaskSurfaceFinishSymbols
|
||||
//===========================================================================
|
||||
|
||||
TaskSurfaceFinishSymbols::TaskSurfaceFinishSymbols(TechDraw::DrawViewPart* view) :
|
||||
selectedView(view),
|
||||
TaskSurfaceFinishSymbols::TaskSurfaceFinishSymbols(const std::string &ownerName) :
|
||||
ui(new Ui_TaskSurfaceFinishSymbols)
|
||||
{
|
||||
App::Document *doc = App::GetApplication().getActiveDocument();
|
||||
if (doc) {
|
||||
owner = doc->getObject(ownerName.c_str());
|
||||
std::string subName;
|
||||
if (!owner) {
|
||||
size_t dot = ownerName.rfind('.');
|
||||
if (dot != std::string::npos) {
|
||||
subName = ownerName.substr(dot + 1);
|
||||
owner = doc->getObject(ownerName.substr(0, dot).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
auto page = dynamic_cast<TechDraw::DrawPage *>(owner);
|
||||
if (page) {
|
||||
placement.x = page->getPageWidth()/2.0;
|
||||
placement.y = page->getPageHeight()/2.0;
|
||||
}
|
||||
|
||||
auto viewPart = dynamic_cast<TechDraw::DrawViewPart *>(owner);
|
||||
if (viewPart && !subName.empty()) {
|
||||
std::string subType = DrawUtil::getGeomTypeFromName(subName);
|
||||
if (subType == "Vertex") {
|
||||
TechDraw::VertexPtr vertex = viewPart->getVertex(subName);
|
||||
if (vertex) {
|
||||
placement = vertex->point();
|
||||
}
|
||||
}
|
||||
else if (subType == "Edge") {
|
||||
TechDraw::BaseGeomPtr edge = viewPart->getEdge(subName);
|
||||
if (edge) {
|
||||
placement = edge->getMidPoint();
|
||||
}
|
||||
}
|
||||
else if (subType == "Face") {
|
||||
TechDraw::FacePtr face = viewPart->getFace(subName);
|
||||
if (face) {
|
||||
placement = face->getCenter();
|
||||
}
|
||||
}
|
||||
|
||||
placement = DrawUtil::invertY(placement);
|
||||
}
|
||||
}
|
||||
|
||||
raValues = {"Ra50", "Ra25", "Ra12, 5", "Ra6, 3",
|
||||
"Ra3, 2", "Ra1, 6", "Ra0, 8", "Ra0, 4",
|
||||
"Ra0, 2", "Ra0, 1", "Ra0, 05", "Ra0, 025"};
|
||||
laySymbols = {"", "=", "⟂", "X", "M", "C", "R"};
|
||||
roughGrades = {"", "N1", "N2", "N3", "N4", "N5",
|
||||
"N6", "N7", "N8", "N9", "N10", "N11"};
|
||||
|
||||
ui->setupUi(this);
|
||||
setUiEdit();
|
||||
}
|
||||
@@ -324,8 +372,25 @@ bool TaskSurfaceFinishSymbols::accept()
|
||||
TechDraw::DrawViewSymbol *surfaceSymbol = dynamic_cast<TechDraw::DrawViewSymbol*>(docObject);
|
||||
surfaceSymbol->Symbol.setValue(completeSymbol());
|
||||
surfaceSymbol->Rotation.setValue(ui->leAngle->text().toDouble());
|
||||
TechDraw::DrawPage* page = selectedView->findParentPage();
|
||||
page->addView(surfaceSymbol);
|
||||
|
||||
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);
|
||||
|
||||
auto viewProvider = dynamic_cast<ViewProviderSymbol *>(QGIView::getViewProvider(surfaceSymbol));
|
||||
if (viewProvider) {
|
||||
viewProvider->StackOrder.setValue(ZVALUE::DIMENSION);
|
||||
}
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
return true;
|
||||
}
|
||||
@@ -339,10 +404,10 @@ bool TaskSurfaceFinishSymbols::reject()
|
||||
// TaskDlgSurfaceFinishSymbols//
|
||||
//===========================================================================
|
||||
|
||||
TaskDlgSurfaceFinishSymbols::TaskDlgSurfaceFinishSymbols(TechDraw::DrawViewPart* view)
|
||||
TaskDlgSurfaceFinishSymbols::TaskDlgSurfaceFinishSymbols(const std::string &ownerName)
|
||||
: TaskDialog()
|
||||
{
|
||||
widget = new TaskSurfaceFinishSymbols(view);
|
||||
widget = new TaskSurfaceFinishSymbols(ownerName);
|
||||
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_SurfaceFinishSymbols"),
|
||||
widget->windowTitle(), true, nullptr);
|
||||
taskbox->groupLayout()->addWidget(widget);
|
||||
|
||||
@@ -78,7 +78,7 @@ class TaskSurfaceFinishSymbols : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TaskSurfaceFinishSymbols(TechDraw::DrawViewPart* view);
|
||||
explicit TaskSurfaceFinishSymbols(const std::string &ownerName);
|
||||
~TaskSurfaceFinishSymbols() override = default;
|
||||
|
||||
virtual bool accept();
|
||||
@@ -89,12 +89,14 @@ protected:
|
||||
void changeEvent(QEvent *event) override;
|
||||
void setUiEdit();
|
||||
|
||||
App::DocumentObject *owner;
|
||||
Base::Vector3d placement;
|
||||
|
||||
private:
|
||||
enum symbolType {anyMethod=0, removeProhibit, removeRequired,
|
||||
anyMethodAll, removeProhibitAll, removeRequiredAll};
|
||||
QPixmap baseSymbol(symbolType type);
|
||||
std::string completeSymbol();
|
||||
TechDraw::DrawViewPart* selectedView;
|
||||
QGraphicsScene* symbolScene; //note this is not QGSPage, but another scene only used to
|
||||
//display symbols in this task's ui
|
||||
std::vector<std::string> raValues, laySymbols, roughGrades;
|
||||
@@ -117,7 +119,7 @@ class TaskDlgSurfaceFinishSymbols : public Gui::TaskView::TaskDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TaskDlgSurfaceFinishSymbols(TechDraw::DrawViewPart* view);
|
||||
explicit TaskDlgSurfaceFinishSymbols(const std::string &ownerName);
|
||||
~TaskDlgSurfaceFinishSymbols() override;
|
||||
|
||||
/// is called the TaskView when the dialog is opened
|
||||
|
||||
@@ -442,3 +442,23 @@ 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();
|
||||
}
|
||||
|
||||
@@ -99,6 +99,8 @@ public:
|
||||
|
||||
const char* whoAmI() const;
|
||||
|
||||
void switchOwnerProperty(App::PropertyLink &prop);
|
||||
|
||||
private:
|
||||
void multiParentPaint(std::vector<TechDraw::DrawPage*>& pages);
|
||||
void singleParentPaint(const TechDraw::DrawView* dv);
|
||||
|
||||
@@ -142,6 +142,12 @@ std::vector<App::DocumentObject*> ViewProviderLeader::claimChildren() const
|
||||
const std::vector<App::DocumentObject *> &views = getFeature()->getInList();
|
||||
try {
|
||||
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>()) {
|
||||
|
||||
@@ -405,6 +405,12 @@ std::vector<App::DocumentObject*> ViewProviderPage::claimChildren(void) const
|
||||
for (std::vector<App::DocumentObject*>::const_iterator it = views.begin();
|
||||
it != views.end(); ++it) {
|
||||
TechDraw::DrawView* featView = dynamic_cast<TechDraw::DrawView*>(*it);
|
||||
|
||||
// If the child view appoints a parent, skip it
|
||||
if (featView && featView->claimParent()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
App::DocumentObject* docObj = *it;
|
||||
//DrawRichAnno with no parent is child of Page
|
||||
TechDraw::DrawRichAnno* dra = dynamic_cast<TechDraw::DrawRichAnno*>(*it);
|
||||
|
||||
@@ -44,15 +44,17 @@ ViewProviderSymbol::~ViewProviderSymbol()
|
||||
|
||||
void ViewProviderSymbol::updateData(const App::Property* prop)
|
||||
{
|
||||
if (prop == &getViewObject()->Scale) {
|
||||
onGuiRepaint(getViewObject());
|
||||
} else if (prop == &getViewObject()->Rotation) {
|
||||
onGuiRepaint(getViewObject());
|
||||
} else if (prop == &getViewObject()->Symbol) {
|
||||
onGuiRepaint(getViewObject());
|
||||
} else if (prop == &getViewObject()->EditableTexts) {
|
||||
onGuiRepaint(getViewObject());
|
||||
TechDraw::DrawViewSymbol *obj = getViewObject();
|
||||
if (prop == &obj->Scale
|
||||
|| prop == &obj->Rotation
|
||||
|| prop == &obj->Symbol
|
||||
|| prop == &obj->EditableTexts) {
|
||||
onGuiRepaint(obj);
|
||||
}
|
||||
else if (prop == &obj->Owner) {
|
||||
switchOwnerProperty(obj->Owner);
|
||||
}
|
||||
|
||||
ViewProviderDrawingView::updateData(prop);
|
||||
}
|
||||
|
||||
|
||||
@@ -217,6 +217,12 @@ std::vector<App::DocumentObject*> ViewProviderViewPart::claimChildren() const
|
||||
const std::vector<App::DocumentObject *> &views = getViewPart()->getInList();
|
||||
try {
|
||||
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() == getViewPart()) {
|
||||
temp.push_back(view);
|
||||
continue;
|
||||
}
|
||||
|
||||
if((*it)->isDerivedFrom<TechDraw::DrawViewDimension>()) {
|
||||
//TODO: make a list, then prune it. should be faster?
|
||||
bool skip = false;
|
||||
|
||||
Reference in New Issue
Block a user