diff --git a/src/Mod/TechDraw/App/DrawTile.cpp b/src/Mod/TechDraw/App/DrawTile.cpp index 9965b97f7f..51af3ca07c 100644 --- a/src/Mod/TechDraw/App/DrawTile.cpp +++ b/src/Mod/TechDraw/App/DrawTile.cpp @@ -47,12 +47,10 @@ DrawTile::DrawTile(void) { static const char *group = "Tile"; -// Base::Vector3d defOrg(0.0, 0.0, 0.0); ADD_PROPERTY_TYPE(TileParent,(0),group,(App::PropertyType)(App::Prop_None), "Object to which this tile is attached"); ADD_PROPERTY_TYPE(TileRow, (0), group, App::Prop_None, "Row in parent"); ADD_PROPERTY_TYPE(TileColumn, (0), group, App::Prop_None, "Column in parent"); -// ADD_PROPERTY_TYPE(TileOrigin, (defOrg), group, App::Prop_None, "Width limit before auto wrap"); } DrawTile::~DrawTile() diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp index c3ecb1e29b..d179718796 100644 --- a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp @@ -95,7 +95,7 @@ App::DocumentObjectExecReturn *DrawWeldSymbol::execute(void) std::vector DrawWeldSymbol::getTiles(void) const { // Base::Console().Message("DWS::getTiles()\n"); - std::vector temp; +// std::vector temp; std::vector result; std::vector tiles = getInList(); diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index a153cb62f1..9145b203db 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -85,6 +85,8 @@ #include #include #include +#include +#include #include "Rez.h" #include "QGIDrawingTemplate.h" @@ -101,6 +103,8 @@ #include "QGILeaderLine.h" #include "QGIRichAnno.h" #include "QGMText.h" +#include "QGIWeldSymbol.h" +#include "QGITile.h" using namespace TechDrawGui; diff --git a/src/Mod/TechDraw/Gui/QGITile.cpp b/src/Mod/TechDraw/Gui/QGITile.cpp index 0e00d33729..6d367d8ef4 100644 --- a/src/Mod/TechDraw/Gui/QGITile.cpp +++ b/src/Mod/TechDraw/Gui/QGITile.cpp @@ -42,33 +42,41 @@ #include "Rez.h" #include "DrawGuiUtil.h" #include "QGIView.h" +#include "QGIWeldSymbol.h" #include "QGITile.h" using namespace TechDrawGui; -QGITile::QGITile(TechDraw::DrawTileWeld* feat) : - m_tileFeat(feat), +QGITile::QGITile() : m_textL(QString()), m_textR(QString()), m_textC(QString()), - m_scale(1.0) + m_scale(1.0), + m_row(0), + m_col(0), + m_tailRight(true), + m_altWeld(false) { m_qgSvg = new QGCustomSvg(); - m_qgSvg->setParentItem(this); - m_effect = new QGraphicsColorizeEffect(); + addToGroup(m_qgSvg); + +// m_effect = new QGraphicsColorizeEffect(); + m_qgTextL = new QGCustomText(); - m_qgTextL->setParentItem(this); + addToGroup(m_qgTextL); + m_qgTextR = new QGCustomText(); - m_qgTextR->setParentItem(this); + addToGroup(m_qgTextR); + m_qgTextC = new QGCustomText(); - m_qgTextC->setParentItem(this); + addToGroup(m_qgTextC); m_wide = getSymbolWidth(); - m_high = getFontSize(); + m_high = prefFontSize(); m_textL = QString(); m_textR = QString(); m_textC = QString(); - m_fontName = getTextFont(); + m_fontName = prefTextFont(); m_font = QFont(m_fontName); #if PY_MAJOR_VERSION < 3 @@ -87,6 +95,11 @@ QGITile::QGITile(TechDraw::DrawTileWeld* feat) : m_colCurrent = m_colNormal; } +QGITile::~QGITile(void) +{ + +} + QVariant QGITile::itemChange(GraphicsItemChange change, const QVariant &value) { // Base::Console().Message("QGIT::itemChange(%d)\n", change); @@ -106,13 +119,11 @@ void QGITile::draw(void) double textWidthL = m_qgTextL->boundingRect().width(); double textWidthR = m_qgTextR->boundingRect().width(); double totalWidth = m_wide + textWidthL + textWidthR; - int row = m_tileFeat->TileRow.getValue(); - int col = m_tileFeat->TileColumn.getValue(); - if (row == 0) { //arrowSide + if (m_row == 0) { //arrowSide double x = m_origin.x(); double y = m_origin.y() - (m_high * 0.5); //inverted y!! setPos(x,y); - } else if (row == -1) { //otherSide + } else if (m_row == -1) { //otherSide if (getAltWeld()) { if (isTailRight()) { double x = m_origin.x() + (0.5 * totalWidth); //move to right 1/2 tile width @@ -129,8 +140,8 @@ void QGITile::draw(void) setPos(x,y); } } else { - double x = m_origin.x() + col * totalWidth; - double y = m_origin.y() - (row * m_high) - (m_high * 0.5); //inverted y!! + double x = m_origin.x() + m_col * totalWidth; + double y = m_origin.y() - (m_row * m_high) - (m_high * 0.5); //inverted y!! setPos(x,y); } } @@ -138,14 +149,14 @@ void QGITile::draw(void) void QGITile::makeSymbol(void) { // Base::Console().Message("QGIT::makeSymbol()\n"); - m_effect->setColor(m_colCurrent); +// m_effect->setColor(m_colCurrent); if (m_svgPath.isEmpty()) { Base::Console().Warning("QGIT::makeSymbol - no symbol file set\n"); return; } - m_qgSvg->setGraphicsEffect(m_effect); +// m_qgSvg->setGraphicsEffect(m_effect); QFileInfo fi(m_svgPath); if (fi.isReadable()) { @@ -166,18 +177,15 @@ void QGITile::makeSymbol(void) Base::Console().Error("QGIT::makeSymbol - file: **%s** is not readable\n",qPrintable(m_svgPath)); return; } - } void QGITile::makeText(void) { // Base::Console().Message("QGIT::makeText()\n"); prepareGeometryChange(); - m_font.setPixelSize(getFontSize()); + m_font.setPixelSize(prefFontSize()); double verticalFudge = 0.10; - int row = m_tileFeat->TileRow.getValue(); - //(0, 0) is 1/2 up (above line symbol)! m_qgTextL->setFont(m_font); m_qgTextL->setPlainText(m_textL); @@ -188,7 +196,7 @@ void QGITile::makeText(void) double textHeightL = m_qgTextL->boundingRect().height(); double vOffset = 0.0; - if (row < 0) { // below line + if (m_row < 0) { // below line vOffset = textHeightL * verticalFudge; } else { vOffset = 0.0; @@ -202,7 +210,7 @@ void QGITile::makeText(void) charWidth = textWidth / m_textR.size(); hMargin = (m_wide / 2.0) + (charWidth / 2.0); double textHeightR = m_qgTextR->boundingRect().height(); - if (row < 0) { // below line + if (m_row < 0) { // below line vOffset = textHeightR * verticalFudge; } else { vOffset = 0.0; @@ -214,7 +222,7 @@ void QGITile::makeText(void) m_qgTextC->setColor(m_colCurrent); double textHeightC = m_qgTextC->boundingRect().height(); textHeightC = textHeightC; - if (row < 0) { // below line + if (m_row < 0) { // below line vOffset = m_high * (1 + verticalFudge); } else { vOffset = -0.5 * (m_high + textHeightC); @@ -222,10 +230,11 @@ void QGITile::makeText(void) m_qgTextC->centerAt(0.0, vOffset); } -void QGITile::setTilePosition(QPointF org) - +void QGITile::setTilePosition(QPointF org, int r, int c) { m_origin = org; + m_row = r; + m_col = c; } void QGITile::setTileScale(double s) @@ -266,7 +275,7 @@ void QGITile::setSymbolFile(std::string s) void QGITile::setPrettyNormal() { m_colCurrent = m_colNormal; - m_effect->setColor(m_colNormal); +// m_effect->setColor(m_colNormal); m_qgTextL->setColor(m_colNormal); m_qgTextR->setColor(m_colNormal); m_qgTextC->setColor(m_colNormal); @@ -277,7 +286,7 @@ void QGITile::setPrettyNormal() { void QGITile::setPrettyPre() { m_colCurrent = prefPreColor(); - m_effect->setColor(m_colCurrent); +// m_effect->setColor(m_colCurrent); m_qgTextL->setColor(m_colCurrent); m_qgTextR->setColor(m_colCurrent); m_qgTextC->setColor(m_colCurrent); @@ -288,7 +297,7 @@ void QGITile::setPrettyPre() { void QGITile::setPrettySel() { m_colCurrent = prefSelectColor(); - m_effect->setColor(m_colCurrent); +// m_effect->setColor(m_colCurrent); m_qgTextL->setColor(m_colCurrent); m_qgTextR->setColor(m_colCurrent); m_qgTextC->setColor(m_colCurrent); @@ -298,26 +307,12 @@ void QGITile::setPrettySel() { bool QGITile::isTailRight(void) { - bool right = false; - App::DocumentObject* obj = m_tileFeat->TileParent.getValue(); - TechDraw::DrawWeldSymbol* realParent = dynamic_cast(obj); - if (realParent != nullptr) { - right = realParent->isTailRightSide(); - } - return right; + return m_tailRight; } bool QGITile::getAltWeld(void) { - bool alt = false; - App::DocumentObject* obj = m_tileFeat->TileParent.getValue(); - TechDraw::DrawWeldSymbol* realParent = dynamic_cast(obj); - if (realParent != nullptr) { - alt = realParent->AlternatingWeld.getValue(); - } else { - Base::Console().Message("QGIT::getAltWeld - real parent not found!\n"); - } - return alt; + return m_altWeld; } //TODO: this is Pen, not Brush. sb Brush to colour background @@ -362,7 +357,7 @@ double QGITile::getSymbolFactor(void) const return s; } -double QGITile::getFontSize(void) const +double QGITile::prefFontSize(void) const { Base::Reference hGrp = App::GetApplication().GetUserParameter(). GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); @@ -374,14 +369,14 @@ double QGITile::getFontSize(void) const //factor to scale symbol to match font size double QGITile::scaleToFont(void) const { - double fpx = getFontSize(); + double fpx = prefFontSize(); double spx = getSymbolHeight(); double factor = getSymbolFactor(); double sf = (fpx / spx) * factor; return sf; } -QString QGITile::getTextFont(void) const +QString QGITile::prefTextFont(void) const { Base::Reference hGrp = App::GetApplication().GetUserParameter(). GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Labels"); diff --git a/src/Mod/TechDraw/Gui/QGITile.h b/src/Mod/TechDraw/Gui/QGITile.h index 0a67d9247c..43887a918b 100644 --- a/src/Mod/TechDraw/Gui/QGITile.h +++ b/src/Mod/TechDraw/Gui/QGITile.h @@ -47,12 +47,13 @@ class DrawTileWeld; namespace TechDrawGui { +class QGIWeldSymbol; class TechDrawGuiExport QGITile : public QGIDecoration { public: - explicit QGITile(TechDraw::DrawTileWeld* tileFeat); - ~QGITile(void) {} + explicit QGITile(); + ~QGITile(void); enum {Type = QGraphicsItem::UserType + 325}; int type(void) const { return Type;} @@ -65,11 +66,12 @@ public: void setTileTextCenter(std::string s); void setFont(QFont f, double fsize); void setSymbolFile(std::string s); - void setTilePosition(QPointF org); + void setTilePosition(QPointF org, int r, int c); void setTileScale(double s); - virtual void draw(void); + void setTailRight(bool b) { m_tailRight = b; } + void setAltWeld(bool b) { m_altWeld = b; } bool isTailRight(void); - + virtual void draw(void); protected: virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); @@ -82,8 +84,8 @@ protected: double getSymbolWidth(void) const; double getSymbolHeight(void) const; double getSymbolFactor(void) const; - QString getTextFont(void) const; - double getFontSize(void) const; + QString prefTextFont(void) const; + double prefFontSize(void) const; double scaleToFont(void) const; void makeSymbol(void); void makeText(void); @@ -91,7 +93,6 @@ protected: bool getAltWeld(void); private: - TechDraw::DrawTileWeld* m_tileFeat; QGCustomText* m_qgTextL; QGCustomText* m_qgTextR; QGCustomText* m_qgTextC; @@ -107,6 +108,10 @@ private: double m_wide; double m_high; double m_scale; + int m_row; + int m_col; + bool m_tailRight; + bool m_altWeld; }; } diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp index ea436f3151..ac40646062 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp @@ -74,13 +74,14 @@ using namespace TechDrawGui; //************************************************************** -QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent, - TechDraw::DrawWeldSymbol* weld) : - m_weldFeat(weld), +QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent) : + m_weldFeat(nullptr), + m_leadFeat(nullptr), + m_arrowFeat(nullptr), + m_otherFeat(nullptr), m_qgLead(myParent), m_blockDraw(false) { - #if PY_MAJOR_VERSION < 3 setHandlesChildEvents(true); //qt4 deprecated in qt5 #else @@ -91,7 +92,6 @@ QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent, setCacheMode(QGraphicsItem::NoCache); setParentItem(m_qgLead); - setViewFeature(weld); m_leadFeat = m_qgLead->getFeature(); setZValue(ZVALUE::DIMENSION); @@ -101,11 +101,24 @@ QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent, m_tailText->setPos(0.0, 0.0); //avoid bRect issues m_allAround = new QGIVertex(-1); - m_allAround->setParentItem(this); - m_fieldFlag = new QGIPrimPath(); - m_fieldFlag->setParentItem(this); + addToGroup(m_allAround); + m_allAround->setAcceptHoverEvents(false); + m_allAround->setFlag(QGraphicsItem::ItemIsSelectable, false); + m_allAround->setFlag(QGraphicsItem::ItemIsMovable, false); + m_allAround->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); + m_allAround->setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); + m_allAround->setFlag(QGraphicsItem::ItemStacksBehindParent, true); - m_colCurrent = getNormalColor(); //preference + m_fieldFlag = new QGIPrimPath(); + addToGroup(m_fieldFlag); + m_fieldFlag->setAcceptHoverEvents(false); + m_fieldFlag->setFlag(QGraphicsItem::ItemIsSelectable, false); + m_fieldFlag->setFlag(QGraphicsItem::ItemIsMovable, false); + m_fieldFlag->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); + m_fieldFlag->setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); + m_fieldFlag->setFlag(QGraphicsItem::ItemStacksBehindParent, true); + + m_colCurrent = prefNormalColor(); m_colSetting = m_colCurrent; } @@ -126,104 +139,90 @@ QVariant QGIWeldSymbol::itemChange(GraphicsItemChange change, const QVariant &va void QGIWeldSymbol::updateView(bool update) { -// Base::Console().Message("QGIWS::updateView() %s\n",m_weldFeat->getNameInDocument()); +// Base::Console().Message("QGIWS::updateView()\n"); Q_UNUSED(update); - if ( m_weldFeat == nullptr ) { + auto viewWeld( dynamic_cast(getViewObject()) ); + if( viewWeld == nullptr ) { + return; + } + + if ( getFeature() == nullptr ) { Base::Console().Warning("QGIWS::updateView - no feature!\n"); return; } + draw(); } void QGIWeldSymbol::draw() { -// Base::Console().Message("QGIWS::draw()- %s\n", m_weldFeat->getNameInDocument()); +// Base::Console().Message("QGIWS::draw()- %s\n", getFeature()->getNameInDocument()); if (!isVisible()) { return; } + getTileFeats(); - removeDecorations(); + removeQGITiles(); - std::vector tiles = m_weldFeat->getTiles(); - - TechDraw::DrawTileWeld* arrowTile = nullptr; - TechDraw::DrawTileWeld* otherTile = nullptr; - if (!tiles.empty()) { - TechDraw::DrawTileWeld* tempTile = tiles.at(0); - if (tempTile->TileRow.getValue() == 0) { - arrowTile = tempTile; - } else { - otherTile = tempTile; - } - } - if (tiles.size() > 1) { - TechDraw::DrawTileWeld* tempTile = tiles.at(1); - if (tempTile->TileRow.getValue() == 0) { - arrowTile = tempTile; - } else { - otherTile = tempTile; - } + if (m_arrowFeat != nullptr) { + drawTile(m_arrowFeat); } - if (arrowTile != nullptr) { - QGITile* qt = new QGITile(arrowTile); - m_arrowTile = qt; - qt->setParentItem(this); - drawTile(arrowTile, m_arrowTile); + if (m_otherFeat != nullptr) { + drawTile(m_otherFeat); } - if (otherTile != nullptr) { - QGITile* qt = new QGITile(otherTile); - m_otherTile = qt; - qt->setParentItem(this); - drawTile(otherTile, m_otherTile); - } + drawAllAround(); - if (m_weldFeat->AllAround.getValue()) { - drawAllAround(); - } - - if (m_weldFeat->FieldWeld.getValue()) { - drawFieldFlag(); - } + drawFieldFlag(); drawTailText(); } -void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* dtw, - QGITile* tile) +void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* tileFeat) { -// Base::Console().Message("QGIWS::drawTile()\n"); +// Base::Console().Message("QGIWS::drawTile() - tileFeat: %X\n", tileFeat); + if (tileFeat == nullptr) { + Base::Console().Message("QGIWS::drawTile - tile is null\n"); + return; + } + double featScale = m_leadFeat->getScale(); - std::string tileTextL = dtw->LeftText.getValue(); - std::string tileTextR = dtw->RightText.getValue(); - std::string tileTextC = dtw->CenterText.getValue(); - tile->setSymbolFile(dtw->SymbolFile.getValue()); - tile->setTileScale(featScale); - + std::string tileTextL = tileFeat->LeftText.getValue(); + std::string tileTextR = tileFeat->RightText.getValue(); + std::string tileTextC = tileFeat->CenterText.getValue(); + std::string symbolFile = tileFeat->SymbolFile.getValue(); + int row = tileFeat->TileRow.getValue(); + int col = tileFeat->TileColumn.getValue(); + + QGITile* tile = new QGITile(); + addToGroup(tile); + QPointF org = getTileOrigin(); - tile->setTilePosition(org); + tile->setTilePosition(org, row, col); tile->setColor(getCurrentColor()); tile->setTileTextLeft(tileTextL); tile->setTileTextRight(tileTextR); tile->setTileTextCenter(tileTextC); + tile->setSymbolFile(symbolFile); tile->setZValue(ZVALUE::DIMENSION); + tile->setTileScale(featScale); + tile->setTailRight(m_weldFeat->isTailRightSide()); + tile->setAltWeld(m_weldFeat->AlternatingWeld.getValue()); + tile->draw(); } void QGIWeldSymbol::drawAllAround(void) { // Base::Console().Message("QGIWS::drawAllAround()\n"); - m_allAround = new QGIVertex(-1); - m_allAround->setParentItem(this); - - m_allAround->setAcceptHoverEvents(false); - m_allAround->setFlag(QGraphicsItem::ItemIsSelectable, false); - m_allAround->setFlag(QGraphicsItem::ItemIsMovable, false); - m_allAround->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); - m_allAround->setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); - m_allAround->setFlag(QGraphicsItem::ItemStacksBehindParent, true); + if (getFeature()->AllAround.getValue()) { + m_allAround->show(); + } else { + m_allAround->hide(); + return; + } m_allAround->setNormalColor(getCurrentColor()); @@ -242,7 +241,7 @@ void QGIWeldSymbol::drawTailText(void) // Base::Console().Message("QGIWS::drawTailText()\n"); QPointF textPos = getTailPoint(); m_tailText->setPos(textPos); //avoid messing up brect with empty item at 0,0 - std::string tText = m_weldFeat->TailText.getValue(); + std::string tText = getFeature()->TailText.getValue(); if (tText.empty()) { m_tailText->hide(); return; @@ -261,7 +260,7 @@ void QGIWeldSymbol::drawTailText(void) double textWidth = m_tailText->boundingRect().width(); double charWidth = textWidth / tText.size(); - double hMargin = charWidth + getPrefArrowSize(); + double hMargin = charWidth + prefArrowSize(); if (getFeature()->isTailRightSide()) { m_tailText->justifyLeftAt(textPos.x() + hMargin, textPos.y(), true); @@ -273,6 +272,12 @@ void QGIWeldSymbol::drawTailText(void) void QGIWeldSymbol::drawFieldFlag() { // Base::Console().Message("QGIWS::drawFieldFlag()\n"); + if (getFeature()->FieldWeld.getValue()) { + m_fieldFlag->show(); + } else { + m_fieldFlag->hide(); + return; + } std::vector flagPoints = { QPointF(0.0, 0.0), QPointF(0.0, -3.0), QPointF(-2.0, -2.5), @@ -287,16 +292,6 @@ void QGIWeldSymbol::drawFieldFlag() path.lineTo(flagPoints.at(i) * scale); } - m_fieldFlag = new QGIPrimPath(); - m_fieldFlag->setParentItem(this); - - m_fieldFlag->setAcceptHoverEvents(false); - m_fieldFlag->setFlag(QGraphicsItem::ItemIsSelectable, false); - m_fieldFlag->setFlag(QGraphicsItem::ItemIsMovable, false); - m_fieldFlag->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); - m_fieldFlag->setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); - m_fieldFlag->setFlag(QGraphicsItem::ItemStacksBehindParent, true); - m_fieldFlag->setNormalColor(getCurrentColor()); //penColor double width = m_qgLead->getLineWidth(); @@ -312,26 +307,57 @@ void QGIWeldSymbol::drawFieldFlag() m_fieldFlag->setPos(fieldFlagPos); } -void QGIWeldSymbol::removeDecorations() +void QGIWeldSymbol::getTileFeats(void) { -// Base::Console().Message("QGIWS::removeDecorations()\n"); + std::vector tiles = getFeature()->getTiles(); + m_arrowFeat = nullptr; + m_otherFeat = nullptr; + + if (!tiles.empty()) { + TechDraw::DrawTileWeld* tempTile = tiles.at(0); + if (tempTile->TileRow.getValue() == 0) { + m_arrowFeat = tempTile; + } else { + m_otherFeat = tempTile; + } + } + if (tiles.size() > 1) { + TechDraw::DrawTileWeld* tempTile = tiles.at(1); + if (tempTile->TileRow.getValue() == 0) { + m_arrowFeat = tempTile; + } else { + m_otherFeat = tempTile; + } + } +} + +void QGIWeldSymbol::removeQGITiles(void) +{ + std::vector tiles = getQGITiles(); + for (auto t: tiles) { + QList tChildren = t->childItems(); + for (auto tc: tChildren) { + t->removeFromGroup(tc); + scene()->removeItem(tc); + //tc gets deleted when QGIWS gets deleted + } + removeFromGroup(t); + scene()->removeItem(t); + delete t; + } +} + +std::vector QGIWeldSymbol::getQGITiles(void) +{ + std::vector result; QList children = childItems(); for (auto& c:children) { QGITile* tile = dynamic_cast(c); - QGIPrimPath* prim = dynamic_cast(c); //allAround, fieldFlag if (tile) { - scene()->removeItem(tile); - delete tile; - } else if (prim) { - scene()->removeItem(prim); - delete tile; + result.push_back(tile); } - } - m_arrowTile = nullptr; - m_otherTile = nullptr; - -// std::vector noTiles; -// m_tiles = noTiles; + } + return result; } void QGIWeldSymbol::hoverEnterEvent(QGraphicsSceneHoverEvent *event) @@ -368,19 +394,11 @@ void QGIWeldSymbol::drawBorder() void QGIWeldSymbol::setPrettyNormal() { -// for (auto t: m_tiles) { -// t->setColor(m_colNormal); -// t->draw(); -// } - if (m_arrowTile != nullptr) { - m_arrowTile->setColor(m_colNormal); - m_arrowTile->draw(); + std::vector tiles = getQGITiles(); + for (auto t: tiles) { + t->setColor(m_colNormal); + t->draw(); } - if (m_otherTile != nullptr) { - m_otherTile->setColor(m_colNormal); - m_otherTile->draw(); - } - m_colCurrent = m_colNormal; m_fieldFlag->setNormalColor(m_colCurrent); m_fieldFlag->setFillColor(m_colCurrent); @@ -393,19 +411,12 @@ void QGIWeldSymbol::setPrettyNormal() void QGIWeldSymbol::setPrettyPre() { -// Base::Console().Message("QGIWS::setPrettyPre()\n"); -// for (auto t: m_tiles) { -// t->setColor(getPreColor()); -// t->draw(); -// } - if (m_arrowTile != nullptr) { - m_arrowTile->setColor(getPreColor()); - m_arrowTile->draw(); - } - if (m_otherTile != nullptr) { - m_otherTile->setColor(getPreColor()); - m_otherTile->draw(); + std::vector tiles = getQGITiles(); + for (auto t: tiles) { + t->setColor(getPreColor()); + t->draw(); } + m_colCurrent = getPreColor(); m_fieldFlag->setNormalColor(getPreColor()); m_fieldFlag->setFillColor(getPreColor()); @@ -418,19 +429,12 @@ void QGIWeldSymbol::setPrettyPre() void QGIWeldSymbol::setPrettySel() { -// Base::Console().Message("QGIWS::setPrettySel()\n"); -// for (auto t: m_tiles) { -// t->setColor(getSelectColor()); -// t->draw(); -// } - if (m_arrowTile != nullptr) { - m_arrowTile->setColor(getSelectColor()); - m_arrowTile->draw(); - } - if (m_otherTile != nullptr) { - m_otherTile->setColor(getSelectColor()); - m_otherTile->draw(); + std::vector tiles = getQGITiles(); + for (auto t: tiles) { + t->setColor(getSelectColor()); + t->draw(); } + m_colCurrent = getSelectColor(); m_fieldFlag->setNormalColor(getSelectColor()); m_fieldFlag->setFillColor(getSelectColor()); @@ -462,26 +466,20 @@ QPointF QGIWeldSymbol::getTailPoint(void) return result; } -//bool QGIWeldSymbol::isTailRightSide() -//{ -// bool result = true; -// Base::Vector3d tail = m_leadFeat->getTailPoint(); -// Base::Vector3d kink = m_leadFeat->getKinkPoint(); -// if (tail.x < kink.x) { //tail is to left -// result = false; -// } -// 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(void) { - TechDraw::DrawWeldSymbol* result = - static_cast(getViewObject()); - return result; + return m_weldFeat; } //preference -QColor QGIWeldSymbol::getNormalColor() +QColor QGIWeldSymbol::prefNormalColor() { Base::Reference hGrp = App::GetApplication().GetUserParameter() .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/LeaderLines"); @@ -491,7 +489,7 @@ QColor QGIWeldSymbol::getNormalColor() return m_colNormal; } -double QGIWeldSymbol::getPrefArrowSize() +double QGIWeldSymbol::prefArrowSize() { Base::Reference hGrp = App::GetApplication().GetUserParameter(). GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.h b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h index 7b30becd6f..2b38a08404 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.h +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h @@ -36,9 +36,13 @@ #include #include "QGIView.h" +namespace App { +class Document; +} + namespace TechDraw { class DrawWeldSymbol; -class DrawWeldSymbol; +class DrawTileWeld; class DrawView; } @@ -48,6 +52,7 @@ class QGIPrimPath; class QGITile; class QGIVertex; class QGCustomText; +class QGILeaderLine; //******************************************************************* @@ -58,8 +63,7 @@ class TechDrawGuiExport QGIWeldSymbol : public QGIView public: enum {Type = QGraphicsItem::UserType + 340}; - explicit QGIWeldSymbol(QGILeaderLine* myParent = nullptr, - TechDraw::DrawWeldSymbol* lead = nullptr); + explicit QGIWeldSymbol(QGILeaderLine* myParent = nullptr); ~QGIWeldSymbol() = default; int type() const override { return Type;} @@ -74,6 +78,8 @@ public: virtual void updateView(bool update = false) override; virtual TechDraw::DrawWeldSymbol* getFeature(void); + virtual void setFeature(TechDraw::DrawWeldSymbol* feat); + QPointF getTileOrigin(void); QPointF getKinkPoint(void); QPointF getTailPoint(void); @@ -82,6 +88,8 @@ public: virtual void setPrettySel(); virtual void setPrettyPre(); + void getTileFeats(void); + protected: virtual QVariant itemChange( GraphicsItemChange change, const QVariant &value ) override; @@ -89,23 +97,26 @@ protected: virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; virtual void draw() override; - void drawTile(TechDraw::DrawTileWeld* dtw, - QGITile* tile); + void drawTile(TechDraw::DrawTileWeld* tileFeat); void drawAllAround(void); void drawTailText(void); void drawFieldFlag(); - void removeDecorations(); protected: - virtual QColor getNormalColor() override; - double getPrefArrowSize(); + void removeQGITiles(void); + std::vector getQGITiles(void); + + virtual QColor prefNormalColor(); + double prefArrowSize(); 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; - QGITile* m_arrowTile; - QGITile* m_otherTile; QGCustomText* m_tailText; QGIPrimPath* m_fieldFlag; QGIVertex* m_allAround; @@ -113,6 +124,8 @@ protected: QFont m_font; bool m_blockDraw; //prevent redraws while updating. + + std::string m_weldFeatName; }; } diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 3cabcef82d..e2c77e2043 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -76,6 +76,8 @@ #include #include #include +#include +#include #include #include "Rez.h" @@ -98,6 +100,7 @@ #include "QGILeaderLine.h" #include "QGIRichAnno.h" #include "QGIWeldSymbol.h" +#include "QGITile.h" #include "ZVALUE.h" #include "ViewProviderPage.h" @@ -114,8 +117,6 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent) m_renderer(Native), drawBkg(true), m_vpPage(0) -// , -// m_borderState(true) { assert(vp); m_vpPage = vp; @@ -557,19 +558,21 @@ QGIView * QGVPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weld) if (parentObj != nullptr) { parentDV = dynamic_cast(parentObj); } else { - Base::Console().Message("QGVP::addWeldSymbol - no parent doc obj\n"); +// Base::Console().Message("QGVP::addWeldSymbol - no parent doc obj\n"); } if (parentDV != nullptr) { QGIView* parentQV = findQViewForDocObj(parentObj); QGILeaderLine* leadParent = dynamic_cast(parentQV); if (leadParent != nullptr) { - weldGroup = new QGIWeldSymbol(leadParent, weld); + weldGroup = new QGIWeldSymbol(leadParent); + weldGroup->setFeature(weld); //for QGIWS + weldGroup->setViewFeature(weld); //for QGIV weldGroup->updateView(true); } else { - Base::Console().Message("QGVP::addWeldSymbol - no parent QGILL\n"); + Base::Console().Error("QGVP::addWeldSymbol - no parent QGILL\n"); } } else { - Base::Console().Message("QGVP::addWeldSymbol - parent is not DV!\n"); + Base::Console().Error("QGVP::addWeldSymbol - parent is not DV!\n"); } return weldGroup; } @@ -735,8 +738,16 @@ void QGVPage::refreshViews(void) { // Base::Console().Message("QGVP::refreshViews()\n"); QList list = scene()->items(); - for (QList::iterator it = list.begin(); it != list.end(); ++it) { - QGIView *itemView = dynamic_cast(*it); + QList qgiv; + //find only QGIV's + for (auto q: list) { + QString tileFamily = QString::fromUtf8("QGIV"); + if (tileFamily == q->data(0).toString()) { + qgiv.push_back(q); + } + } + for (auto q: qgiv) { + QGIView *itemView = dynamic_cast(q); if(itemView) { itemView->updateView(true); } diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index 65f350730f..923abefcb0 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -57,6 +57,7 @@ class ViewProviderPage; class QGIViewBalloon; class QGILeaderLine; class QGIRichAnno; +class QGITile; class TechDrawGuiExport QGVPage : public QGraphicsView { @@ -95,7 +96,6 @@ public: void addDimToParent(QGIViewDimension* dim, QGIView* parent); void addLeaderToParent(QGILeaderLine* lead, QGIView* parent); -// const std::vector & getViews() const { return views; } //only used in MDIVP std::vector getViews() const; int addQView(QGIView * view); @@ -103,7 +103,6 @@ public: int removeQViewByName(const char* name); void removeQViewFromScene(QGIView *view); - //void setViews(const std::vector &view) {views = view; } void setPageTemplate(TechDraw::DrawTemplate *pageTemplate); QGITemplate * getTemplate() const; @@ -119,8 +118,6 @@ public: void saveSvg(QString filename); void postProcessXml(QTemporaryFile& tempFile, QString filename, QString pagename); -/* int balloonIndex;*/ - public Q_SLOTS: void setHighQualityAntialiasing(bool highQualityAntialiasing); @@ -156,7 +153,6 @@ private: double m_zoomIncrement; int m_reversePan; int m_reverseScroll; -/* bool m_borderState;*/ QLabel *balloonCursor; QPoint balloonCursorPos; void cancelBalloonPlacing(void); diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp index 369098f957..7ac76ce6af 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp @@ -417,7 +417,6 @@ void TaskWeldingSymbol::collectOtherData(void) TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol(void) { // Base::Console().Message("TWS::createWeldingSymbol()\n"); - Gui::Command::openCommand("Create WeldSymbol"); std::string symbolName = m_leadFeat->getDocument()->getUniqueObjectName("DrawWeldSymbol"); std::string symbolType = "TechDraw::DrawWeldSymbol"; @@ -458,8 +457,6 @@ TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol(void) throw Base::RuntimeError("TaskWeldingSymbol - new symbol object not found"); } - Gui::Command::updateActive(); - Gui::Command::commitCommand(); return newSym; } @@ -556,7 +553,7 @@ std::vector TaskWeldingSymbol::createTiles(void) std::vector TaskWeldingSymbol::updateTiles(void) { -// Base::Console().Message("TWS::updateTiles()\n"); + Base::Console().Message("TWS::updateTiles()\n"); std::vector tileFeats; std::string tileType("TechDraw::DrawTileWeld"); std::string tileName; @@ -566,7 +563,7 @@ std::vector TaskWeldingSymbol::updateTiles(void) if (m_arrowIn != nullptr) { tileName = m_arrowIn->getNameInDocument(); } - if (m_arrowIn == nullptr) { + if (m_arrowIn == nullptr) { // this should never happen on an update! tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", tileType.c_str(),tileName.c_str()); @@ -606,7 +603,7 @@ std::vector TaskWeldingSymbol::updateTiles(void) tileName = m_otherIn->getNameInDocument(); } - if ( (m_otherIn == nullptr) && + if ( (m_otherIn == nullptr) && //m_otherIn can be nullptr if otherside added in edit session. (m_otherOut.toBeSaved) ) { tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", @@ -675,15 +672,19 @@ bool TaskWeldingSymbol::accept() { // Base::Console().Message("TWS::accept()\n"); if (m_createMode) { + Gui::Command::openCommand("Create WeldSymbol"); m_weldFeat = createWeldingSymbol(); std::vector tileFeats = createTiles(); for (auto& obj: tileFeats) { TechDraw::DrawTileWeld* tile = dynamic_cast(obj); tile->TileParent.setValue(m_weldFeat); } + Gui::Command::updateActive(); + Gui::Command::commitCommand(); m_weldFeat->recomputeFeature(); // m_weldFeat->requestPaint(); //not a dv! } else { + Gui::Command::openCommand("Edit WeldSymbol"); try { updateWeldingSymbol(); std::vector tileFeats = updateTiles(); @@ -691,7 +692,9 @@ bool TaskWeldingSymbol::accept() TechDraw::DrawTileWeld* tile = dynamic_cast(obj); tile->TileParent.setValue(m_weldFeat); } + for (auto name: m_toRemove) { + //QGIV is removed from scene by MDIVP/QGVP on objectDelete Command::doCommand(Command::Doc, "App.activeDocument().removeObject('%s')", name.c_str()); } @@ -701,6 +704,8 @@ bool TaskWeldingSymbol::accept() Base::Console().Error("TWS::accept - failed to update symbol\n"); } + Gui::Command::updateActive(); + Gui::Command::commitCommand(); m_weldFeat->recomputeFeature(); // m_weldFeat->requestPaint(); //not a dv! }