diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp index 05b17e800d..9358bba53b 100644 --- a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp @@ -98,6 +98,12 @@ void DrawWeldSymbol::onSettingDocument() void DrawWeldSymbol::onChanged(const App::Property* prop) { DrawView::onChanged(prop); + + // If leader was switched, our coordinates were adjusted, but we want to stick to the new leader line + if (prop == &Leader && Leader.getValue()) { + X.setValue(0.0); + Y.setValue(0.0); + } } short DrawWeldSymbol::mustExecute() const diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.h b/src/Mod/TechDraw/App/DrawWeldSymbol.h index 0e85712990..bf6d50a3cc 100644 --- a/src/Mod/TechDraw/App/DrawWeldSymbol.h +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.h @@ -62,6 +62,8 @@ public: bool isTailRightSide(); std::vector getTiles() const; + App::PropertyLink *getOwnerProperty() override { return &Leader; } + protected: void onChanged(const App::Property* prop) override; diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp index df264cdbbb..df6e67e093 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp @@ -52,12 +52,9 @@ using namespace TechDrawGui; //************************************************************** -QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent) : - m_weldFeat(nullptr), - m_leadFeat(nullptr), +QGIWeldSymbol::QGIWeldSymbol() : m_arrowFeat(nullptr), m_otherFeat(nullptr), - m_qgLead(myParent), m_tailText(nullptr), m_fieldFlag(nullptr), m_allAround(nullptr), @@ -67,9 +64,6 @@ QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent) : setFlag(QGraphicsItem::ItemIsMovable, false); setCacheMode(QGraphicsItem::NoCache); - - setParentItem(m_qgLead); - m_leadFeat = m_qgLead->getFeature(); setZValue(ZVALUE::DIMENSION); m_tailText = new QGCustomText(); @@ -126,15 +120,17 @@ void QGIWeldSymbol::updateView(bool update) { // Base::Console().Message("QGIWS::updateView()\n"); Q_UNUSED(update); - auto viewWeld( dynamic_cast(getViewObject()) ); - if (!viewWeld) - return; - if (!getFeature()) { + TechDraw::DrawWeldSymbol *feature = getFeature(); + if (!feature) { Base::Console().Warning("QGIWS::updateView - no feature!\n"); return; } + if (feature->isRestoring() || !getLeader()) { + return; + } + draw(); } @@ -171,16 +167,17 @@ void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* tileFeat) return; } - const auto sym( dynamic_cast(getViewObject()) ); + const auto sym = getFeature(); if (!sym) return; - auto vp = static_cast(getViewProvider(getViewObject())); + auto vp = dynamic_cast(getViewProvider(sym)); if (!vp) return; std::string fontName = vp->Font.getValue(); int fontSize = QGIView::exactFontSize(vp->Font.getValue(), vp->TileFontSize.getValue()); - double featScale = m_leadFeat->getScale(); + + double featScale = getLeader()->getScale(); std::string tileTextL = tileFeat->LeftText.getValue(); std::string tileTextR = tileFeat->RightText.getValue(); @@ -202,8 +199,8 @@ void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* tileFeat) // tile->setSymbolFile(symbolFile); tile->setZValue(ZVALUE::DIMENSION); tile->setTileScale(featScale); - tile->setTailRight(m_weldFeat->isTailRightSide()); - tile->setAltWeld(m_weldFeat->AlternatingWeld.getValue()); + tile->setTailRight(getFeature()->isTailRightSide()); + tile->setAltWeld(getFeature()->AlternatingWeld.getValue()); tile->draw(); } @@ -227,8 +224,11 @@ void QGIWeldSymbol::drawAllAround() m_allAround->setFill(Qt::NoBrush); // m_allAround->setRadius(calculateFontPixelSize(getDimFontSize())); m_allAround->setRadius(PreferencesGui::dimFontSizePX()); - double width = m_qgLead->getLineWidth(); - m_allAround->setWidth(width); + + auto qgiLead = dynamic_cast(getQGIVByName(getLeader()->getNameInDocument())); + if (qgiLead) { + m_allAround->setWidth(qgiLead->getLineWidth()); + } m_allAround->setZValue(ZVALUE::DIMENSION); } @@ -244,10 +244,10 @@ void QGIWeldSymbol::drawTailText() } else { m_tailText->show(); } - const auto sym( dynamic_cast(getViewObject()) ); + const auto sym = getFeature(); if (!sym) return; - auto vp = static_cast(getViewProvider(getViewObject())); + auto vp = dynamic_cast(getViewProvider(sym)); if (!vp) { return; } @@ -305,8 +305,10 @@ void QGIWeldSymbol::drawFieldFlag() path.lineTo(flagPoints.at(i) * scale); } - double width = m_qgLead->getLineWidth(); - m_fieldFlag->setWidth(width); + auto qgiLead = dynamic_cast(getQGIVByName(getLeader()->getNameInDocument())); + if (qgiLead) { + m_fieldFlag->setWidth(qgiLead->getLineWidth()); + } m_fieldFlag->setZValue(ZVALUE::DIMENSION); m_fieldFlag->setPath(path); @@ -449,35 +451,38 @@ void QGIWeldSymbol::setPrettySel() QPointF QGIWeldSymbol::getTileOrigin() { - Base::Vector3d org = m_leadFeat->getTileOrigin(); + Base::Vector3d org = getLeader()->getTileOrigin(); QPointF result(org.x, org.y); return result; } QPointF QGIWeldSymbol::getKinkPoint() { - Base::Vector3d org = m_leadFeat->getKinkPoint(); + Base::Vector3d org = getLeader()->getKinkPoint(); QPointF result(org.x, org.y); return result; } QPointF QGIWeldSymbol::getTailPoint() { - Base::Vector3d org = m_leadFeat->getTailPoint(); + Base::Vector3d org = getLeader()->getTailPoint(); QPointF result(org.x, org.y); return result; } -void QGIWeldSymbol::setFeature(TechDraw::DrawWeldSymbol* feat) -{ -// Base::Console().Message("QGIWS::setFeature(%s)\n", feat->getNameInDocument()); - m_weldFeat = feat; - m_weldFeatName = feat->getNameInDocument(); -} - TechDraw::DrawWeldSymbol* QGIWeldSymbol::getFeature() { - return m_weldFeat; + return dynamic_cast(getViewObject()); +} + +TechDraw::DrawLeaderLine *QGIWeldSymbol::getLeader() +{ + DrawWeldSymbol *feature = getFeature(); + if (!feature) { + return nullptr; + } + + return dynamic_cast(feature->Leader.getValue()); } //preference diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.h b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h index 4d8ceeedb7..416dce3849 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.h +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h @@ -63,7 +63,7 @@ class TechDrawGuiExport QGIWeldSymbol : public QGIView public: enum {Type = QGraphicsItem::UserType + 340}; - explicit QGIWeldSymbol(QGILeaderLine* myParent = nullptr); + explicit QGIWeldSymbol(); ~QGIWeldSymbol() override = default; int type() const override { return Type;} @@ -78,7 +78,7 @@ public: void updateView(bool update = false) override; virtual TechDraw::DrawWeldSymbol* getFeature(); - virtual void setFeature(TechDraw::DrawWeldSymbol* feat); + virtual TechDraw::DrawLeaderLine *getLeader(); QPointF getTileOrigin(); QPointF getKinkPoint(); @@ -110,14 +110,11 @@ protected: double prefArrowSize(); double prefFontSize() const; - TechDraw::DrawWeldSymbol* m_weldFeat; - TechDraw::DrawLeaderLine* m_leadFeat; TechDraw::DrawTileWeld* m_arrowFeat; TechDraw::DrawTileWeld* m_otherFeat; std::string m_arrowName; std::string m_otherName; - QGILeaderLine* m_qgLead; QGCustomText* m_tailText; QGIPrimPath* m_fieldFlag; QGIVertex* m_allAround; @@ -126,7 +123,6 @@ protected: bool m_blockDraw; //prevent redraws while updating. - std::string m_weldFeatName; virtual QRectF customBoundingRect() const; }; diff --git a/src/Mod/TechDraw/Gui/QGSPage.cpp b/src/Mod/TechDraw/Gui/QGSPage.cpp index 3f722b8eb0..49edc5febb 100644 --- a/src/Mod/TechDraw/Gui/QGSPage.cpp +++ b/src/Mod/TechDraw/Gui/QGSPage.cpp @@ -623,28 +623,11 @@ QGIView* QGSPage::addRichAnno(TechDraw::DrawRichAnno* richFeat) QGIView* QGSPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weldFeat) { - // Base::Console().Message("QGSP::addWeldSymbol()\n"); - QGIWeldSymbol* weldGroup = nullptr; - TechDraw::DrawView* parentDV = nullptr; + QGIWeldSymbol *weldView = new QGIWeldSymbol; + weldView->setViewFeature(weldFeat); - App::DocumentObject* parentObj = weldFeat->Leader.getValue(); - if (parentObj) { - parentDV = dynamic_cast(parentObj); - } - else { - // Base::Console().Message("QGSP::addWeldSymbol - no parent doc obj\n"); - } - if (parentDV) { - QGIView* parentQV = findQViewForDocObj(parentObj); - QGILeaderLine* leadParent = dynamic_cast(parentQV); - if (leadParent) { - weldGroup = new QGIWeldSymbol(leadParent); - weldGroup->setFeature(weldFeat); //for QGIWS - weldGroup->setViewFeature(weldFeat);//for QGIV - weldGroup->updateView(true); - } - } - return weldGroup; + addQView(weldView); + return weldView; } void QGSPage::setDimensionGroups(void) diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp index 8e99d56215..4cf17056aa 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp @@ -456,78 +456,32 @@ void TaskWeldingSymbol::getTileFeats() TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol() { // Base::Console().Message("TWS::createWeldingSymbol()\n"); - - const std::string objectName{QT_TR_NOOP("SectionView")}; - std::string symbolName = m_leadFeat->getDocument()->getUniqueObjectName(objectName.c_str()); - std::string generatedSuffix {symbolName.substr(objectName.length())}; - - std::string symbolType = "TechDraw::DrawWeldSymbol"; - - TechDraw::DrawPage* page = m_leadFeat->findParentPage(); - std::string pageName = page->getNameInDocument(); - - Command::doCommand(Command::Doc, "App.activeDocument().addObject('%s', '%s')", - symbolType.c_str(), symbolName.c_str()); - Command::doCommand(Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", - pageName.c_str(), symbolName.c_str()); - Command::doCommand(Command::Doc, "App.activeDocument().%s.Leader = App.activeDocument().%s", - symbolName.c_str(), m_leadFeat->getNameInDocument()); - - bool allAround = ui->cbAllAround->isChecked(); - std::string allAroundText = allAround ? "True" : "False"; - Command::doCommand(Command::Doc, "App.activeDocument().%s.AllAround = %s", - symbolName.c_str(), allAroundText.c_str()); - - bool fieldWeld = ui->cbFieldWeld->isChecked(); - std::string fieldWeldText = fieldWeld ? "True" : "False"; - Command::doCommand(Command::Doc, "App.activeDocument().%s.FieldWeld = %s", - symbolName.c_str(), fieldWeldText.c_str()); - - bool altWeld = ui->cbAltWeld->isChecked(); - std::string altWeldText = altWeld ? "True" : "False"; - Command::doCommand(Command::Doc, "App.activeDocument().%s.AlternatingWeld = %s", - symbolName.c_str(), altWeldText.c_str()); - - std::string tailText = ui->leTailText->text().toStdString(); - tailText = Base::Tools::escapeEncodeString(tailText); - Command::doCommand(Command::Doc, "App.activeDocument().%s.TailText = '%s'", - symbolName.c_str(), tailText.c_str()); - - App::DocumentObject* newObj = m_leadFeat->getDocument()->getObject(symbolName.c_str()); - TechDraw::DrawWeldSymbol* newSym = dynamic_cast(newObj); - if (!newObj || !newSym) + App::Document *doc = Application::Instance->activeDocument()->getDocument(); + auto weldSymbol = dynamic_cast(doc->addObject("TechDraw::DrawWeldSymbol", "WeldSymbol")); + if (!weldSymbol) { throw Base::RuntimeError("TaskWeldingSymbol - new symbol object not found"); + } - std::string translatedObjectName{tr(objectName.c_str()).toStdString()}; - newObj->Label.setValue(translatedObjectName + generatedSuffix); + weldSymbol->AllAround.setValue(ui->cbAllAround->isChecked()); + weldSymbol->FieldWeld.setValue(ui->cbFieldWeld->isChecked()); + weldSymbol->AlternatingWeld.setValue(ui->cbAltWeld->isChecked()); + weldSymbol->TailText.setValue(ui->leTailText->text().toStdString()); + weldSymbol->Leader.setValue(m_leadFeat); - return newSym; + TechDraw::DrawPage *page = m_leadFeat->findParentPage(); + if (page) { + page->addView(weldSymbol); + } + + return weldSymbol; } void TaskWeldingSymbol::updateWeldingSymbol() { -// Base::Console().Message("TWS::updateWeldingSymbol()\n"); - std::string symbolName = m_weldFeat->getNameInDocument(); - - bool allAround = ui->cbAllAround->isChecked(); - std::string allAroundText = allAround ? "True" : "False"; - Command::doCommand(Command::Doc, "App.activeDocument().%s.AllAround = %s", - symbolName.c_str(), allAroundText.c_str()); - - bool fieldWeld = ui->cbFieldWeld->isChecked(); - std::string fieldWeldText = fieldWeld ? "True" : "False"; - Command::doCommand(Command::Doc, "App.activeDocument().%s.FieldWeld = %s", - symbolName.c_str(), fieldWeldText.c_str()); - - bool altWeld = ui->cbAltWeld->isChecked(); - std::string altWeldText = altWeld ? "True" : "False"; - Command::doCommand(Command::Doc, "App.activeDocument().%s.AlternatingWeld = %s", - symbolName.c_str(), altWeldText.c_str()); - - std::string tailText = ui->leTailText->text().toStdString(); - tailText = Base::Tools::escapeEncodeString(tailText); - Command::doCommand(Command::Doc, "App.activeDocument().%s.TailText = '%s'", - symbolName.c_str(), tailText.c_str()); + m_weldFeat->AllAround.setValue(ui->cbAllAround->isChecked()); + m_weldFeat->FieldWeld.setValue(ui->cbFieldWeld->isChecked()); + m_weldFeat->AlternatingWeld.setValue(ui->cbAltWeld->isChecked()); + m_weldFeat->TailText.setValue(ui->leTailText->text().toStdString()); } void TaskWeldingSymbol::updateTiles() diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp index 2a81118880..20477f7b82 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp @@ -393,7 +393,6 @@ std::vector ViewProviderPage::claimChildren(void) const // DrawViewBalloon // any FeatuerView in a DrawViewClip // DrawHatch - // DrawWeldSymbol const std::vector& views = getDrawPage()->Views.getValues(); @@ -413,7 +412,6 @@ std::vector ViewProviderPage::claimChildren(void) const || docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) || docObj->isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) || docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId()) - || docObj->isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId()) || (featView && featView->isInClip())) continue; else