From e4cd11e4e85a5315010386d69df1ff25847f25b3 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Mon, 6 Jan 2020 09:04:36 -0500 Subject: [PATCH] [TD]correct PropertyFileIncluded handling in Welding --- src/Mod/TechDraw/App/DrawTileWeld.cpp | 30 +++ src/Mod/TechDraw/App/DrawTileWeld.h | 5 + src/Mod/TechDraw/App/DrawWeldSymbol.cpp | 39 ++- src/Mod/TechDraw/App/DrawWeldSymbol.h | 1 + src/Mod/TechDraw/Gui/QGITile.cpp | 44 +-- src/Mod/TechDraw/Gui/QGITile.h | 6 +- src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp | 6 +- src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp | 300 +++++++-------------- src/Mod/TechDraw/Gui/TaskWeldingSymbol.h | 17 +- 9 files changed, 197 insertions(+), 251 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawTileWeld.cpp b/src/Mod/TechDraw/App/DrawTileWeld.cpp index 0664e1ace7..400ae9f081 100644 --- a/src/Mod/TechDraw/App/DrawTileWeld.cpp +++ b/src/Mod/TechDraw/App/DrawTileWeld.cpp @@ -25,10 +25,14 @@ #ifndef _PreComp_ #endif +#include +#include + #include #include #include #include +#include #include "DrawUtil.h" @@ -52,6 +56,9 @@ DrawTileWeld::DrawTileWeld(void) ADD_PROPERTY_TYPE(RightText, (0), group, App::Prop_None, "Text RHS"); ADD_PROPERTY_TYPE(CenterText, (0), group, App::Prop_None, "Text above Symbol"); ADD_PROPERTY_TYPE(SymbolFile, (""), group, App::Prop_None, "Svg Symbol File"); + + SymbolFile.setStatus(App::Property::ReadOnly,true); + } DrawTileWeld::~DrawTileWeld() @@ -78,6 +85,29 @@ App::DocumentObjectExecReturn *DrawTileWeld::execute(void) return DrawTile::execute(); } +void DrawTileWeld::replaceSymbol(std::string newSymbolFile) +{ +// Base::Console().Message("DTW::replaceSymbol(%s)\n", newSymbolFile.c_str()); + std::string special = getNameInDocument(); + special += "Symbol.svg"; + std::string tempName = SymbolFile.getExchangeTempFile(); + copyFile(newSymbolFile, tempName); + SymbolFile.setValue(tempName.c_str(), special.c_str()); +} + +//copy whole text file from inSpec to outSpec +void DrawTileWeld::copyFile(std::string inSpec, std::string outSpec) +{ +// Base::Console().Message("DTW::copyFile(%s, %s)\n", inSpec.c_str(), outSpec.c_str()); + if (inSpec.empty()) { + std::ofstream dst(outSpec); //make an empty file + } else { + std::ifstream src(inSpec); + std::ofstream dst(outSpec); + dst << src.rdbuf(); + } +} + PyObject *DrawTileWeld::getPyObject(void) { if (PythonObject.is(Py::_None())) { diff --git a/src/Mod/TechDraw/App/DrawTileWeld.h b/src/Mod/TechDraw/App/DrawTileWeld.h index a8070e5c8b..c2ff31691f 100644 --- a/src/Mod/TechDraw/App/DrawTileWeld.h +++ b/src/Mod/TechDraw/App/DrawTileWeld.h @@ -23,6 +23,8 @@ #ifndef _TechDraw_DrawTileWeld_h_ #define _TechDraw_DrawTileWeld_h_ +#include + #include #include #include @@ -56,8 +58,11 @@ public: virtual PyObject *getPyObject(void); virtual QRectF getRect() const { return QRectF(0,0,1,1);} + void replaceSymbol(std::string newSymbolFile); + protected: virtual void onChanged(const App::Property* prop); + void copyFile(std::string inSpec, std::string outSpec); private: }; diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp index d179718796..638ee17b03 100644 --- a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp @@ -62,13 +62,49 @@ DrawWeldSymbol::DrawWeldSymbol(void) Caption.setStatus(App::Property::Hidden,true); Scale.setStatus(App::Property::Hidden,true); ScaleType.setStatus(App::Property::Hidden,true); - } DrawWeldSymbol::~DrawWeldSymbol() { } +//DWS always has exactly 2 child tiles - ArrowSide and OtherSide. +//OtherSide tile may be hidden; +//once DWS has been added to the document, add 2x DrawTileWeld +//but if this is a restore of an existing DWS, the tiles will loaded elsewhere +void DrawWeldSymbol::onSettingDocument() +{ +// Base::Console().Message("DWS::onSettingDocument() - doc: %s\n", getDocument()->getName()); + App::Document* doc = getDocument(); + + if (doc->testStatus(App::Document::Status::Restoring)) { +// Base::Console().Message("DWS::onSettingDocument() - restoring!\n"); + return; + } + + std::vector existingTiles = getTiles(); + if (!existingTiles.empty()) { + return; + } + + std::string tileName1 = doc->getUniqueObjectName("DrawTileWeld"); + auto tile1Obj( doc->addObject( "TechDraw::DrawTileWeld", tileName1.c_str() ) ); + DrawTileWeld* tile1 = dynamic_cast(tile1Obj); + if (tile1 != nullptr) { + tile1->TileParent.setValue(this); + } + + std::string tileName2 = doc->getUniqueObjectName("DrawTileWeld"); + auto tile2Obj( doc->addObject( "TechDraw::DrawTileWeld", tileName2.c_str() ) ); + DrawTileWeld* tile2 = dynamic_cast(tile2Obj); + if (tile2 != nullptr) { + tile2->TileParent.setValue(this); + } + tile2->TileRow.setValue(-1); //other side is row -1 + + DrawView::onSettingDocument(); +} + void DrawWeldSymbol::onChanged(const App::Property* prop) { if (!isRestoring()) { @@ -95,7 +131,6 @@ App::DocumentObjectExecReturn *DrawWeldSymbol::execute(void) std::vector DrawWeldSymbol::getTiles(void) const { // Base::Console().Message("DWS::getTiles()\n"); -// std::vector temp; std::vector result; std::vector tiles = getInList(); diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.h b/src/Mod/TechDraw/App/DrawWeldSymbol.h index 59d89e7496..7e8e60787d 100644 --- a/src/Mod/TechDraw/App/DrawWeldSymbol.h +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.h @@ -50,6 +50,7 @@ public: virtual short mustExecute() const; virtual App::DocumentObjectExecReturn *execute(void); + virtual void onSettingDocument(void); virtual const char* getViewProviderName(void) const { return "TechDrawGui::ViewProviderWeld"; diff --git a/src/Mod/TechDraw/Gui/QGITile.cpp b/src/Mod/TechDraw/Gui/QGITile.cpp index 2d36fb0b45..f7dec4b892 100644 --- a/src/Mod/TechDraw/Gui/QGITile.cpp +++ b/src/Mod/TechDraw/Gui/QGITile.cpp @@ -49,7 +49,7 @@ using namespace TechDrawGui; -QGITile::QGITile() : +QGITile::QGITile(TechDraw::DrawTileWeld* dtw) : m_textL(QString::fromUtf8(" ")), m_textR(QString::fromUtf8(" ")), m_textC(QString::fromUtf8(" ")), @@ -57,7 +57,8 @@ QGITile::QGITile() : m_row(0), m_col(0), m_tailRight(true), - m_altWeld(false) + m_altWeld(false), + m_tileFeat(dtw) { m_qgSvg = new QGCustomSvg(); addToGroup(m_qgSvg); @@ -154,17 +155,11 @@ void QGITile::makeSymbol(void) { // Base::Console().Message("QGIT::makeSymbol()\n"); // 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); - QByteArray qba = getSvgString(m_svgPath); + std::string symbolString = getStringFromFile(m_tileFeat->SymbolFile.getValue()); + QByteArray qba(symbolString.c_str(), symbolString.length()); if (qba.isEmpty()) { - Base::Console().Message("QGIT::makeSymbol - no data from file: %s\n", qPrintable(m_svgPath)); return; } if (!m_qgSvg->load(&qba)) { @@ -175,26 +170,6 @@ void QGITile::makeSymbol(void) m_qgSvg->centerAt(0.0, 0.0); //(0,0) is based on symbol size } -//re PropertyFileIncluded locking problem - ensure Qt file functions destroyed by going out of scope -QByteArray QGITile::getSvgString(QString svgPath) -{ - QByteArray qba; - QFileInfo fi(svgPath); - if (fi.isReadable()) { - QFile svgFile(svgPath); - if(svgFile.open(QIODevice::ReadOnly)) { - qba = svgFile.readAll(); - svgFile.close(); - } else { - Base::Console().Error("Error - Could not open file **%s**\n", qPrintable(svgPath)); - } - } else { - Base::Console().Error("QGIT::makeSymbol - file: **%s** is not readable\n",qPrintable(svgPath)); - } - return qba; -} - - void QGITile::makeText(void) { // Base::Console().Message("QGIT::makeText()\n"); @@ -257,6 +232,15 @@ void QGITile::makeText(void) m_qgTextC->centerAt(0.0, vOffset); } +//read whole text file into std::string +std::string QGITile::getStringFromFile(std::string inSpec) +{ + std::ifstream f(inSpec); + std::stringstream ss; + ss << f.rdbuf(); + return ss.str(); +} + void QGITile::setTilePosition(QPointF org, int r, int c) { m_origin = org; diff --git a/src/Mod/TechDraw/Gui/QGITile.h b/src/Mod/TechDraw/Gui/QGITile.h index 6389125958..73333495fc 100644 --- a/src/Mod/TechDraw/Gui/QGITile.h +++ b/src/Mod/TechDraw/Gui/QGITile.h @@ -52,7 +52,7 @@ class QGIWeldSymbol; class TechDrawGuiExport QGITile : public QGIDecoration { public: - explicit QGITile(); + explicit QGITile(TechDraw::DrawTileWeld*); ~QGITile(void); enum {Type = QGraphicsItem::UserType + 325}; @@ -93,6 +93,9 @@ protected: void makeText(void); bool getAltWeld(void); + bool isReadable(QString filePath); + std::string getStringFromFile(std::string inSpec); + private: QGCustomText* m_qgTextL; @@ -114,6 +117,7 @@ private: int m_col; bool m_tailRight; bool m_altWeld; + TechDraw::DrawTileWeld* m_tileFeat; }; } diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp index 450113d06f..ea5c1e042b 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp @@ -212,11 +212,11 @@ void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* tileFeat) std::string tileTextL = tileFeat->LeftText.getValue(); std::string tileTextR = tileFeat->RightText.getValue(); std::string tileTextC = tileFeat->CenterText.getValue(); - std::string symbolFile = tileFeat->SymbolFile.getValue(); +// std::string symbolFile = tileFeat->SymbolFile.getValue(); int row = tileFeat->TileRow.getValue(); int col = tileFeat->TileColumn.getValue(); - QGITile* tile = new QGITile(); + QGITile* tile = new QGITile(tileFeat); addToGroup(tile); QPointF org = getTileOrigin(); @@ -226,7 +226,7 @@ void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* tileFeat) tile->setTileTextLeft(tileTextL); tile->setTileTextRight(tileTextR); tile->setTileTextCenter(tileTextC); - tile->setSymbolFile(symbolFile); +// tile->setSymbolFile(symbolFile); tile->setZValue(ZVALUE::DIMENSION); tile->setTileScale(featScale); tile->setTailRight(m_weldFeat->isTailRightSide()); diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp index 1c72e7c4fe..18829d0d05 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp @@ -82,12 +82,11 @@ TaskWeldingSymbol::TaskWeldingSymbol(TechDraw::DrawLeaderLine* leader) : ui(new Ui_TaskWeldingSymbol), m_leadFeat(leader), m_weldFeat(nullptr), - m_arrowIn(nullptr), - m_otherIn(nullptr), m_createMode(true), m_arrowDirty(false), m_otherDirty(false) { +//TODO: why does DWS nedd DLL as parent? // Base::Console().Message("TWS::TWS() - create mode\n"); if (m_leadFeat == nullptr) { //should be caught in CMD caller @@ -129,8 +128,6 @@ TaskWeldingSymbol::TaskWeldingSymbol(TechDraw::DrawWeldSymbol* weld) : ui(new Ui_TaskWeldingSymbol), m_leadFeat(nullptr), m_weldFeat(weld), - m_arrowIn(nullptr), - m_otherIn(nullptr), m_createMode(false), m_arrowDirty(false), m_otherDirty(false) @@ -211,8 +208,10 @@ void TaskWeldingSymbol::setUiPrimary() ui->pbArrowSymbol->setFocus(); m_arrowOut.init(); m_arrowPath = QString(); + m_arrowSymbol = QString(); m_otherOut.init(); m_otherPath = QString(); + m_otherSymbol = QString(); } void TaskWeldingSymbol::setUiEdit() @@ -228,44 +227,48 @@ void TaskWeldingSymbol::setUiEdit() ui->cbAltWeld->setChecked(m_weldFeat->AlternatingWeld.getValue()); ui->leTailText->setText(QString::fromUtf8(m_weldFeat->TailText.getValue())); - //save existing tiles done in saveState - if (m_arrowIn != nullptr) { - QString qTemp = QString::fromUtf8(m_arrowIn->LeftText.getValue()); + getTileFeats(); + if (m_arrowFeat != nullptr) { + QString qTemp = QString::fromUtf8(m_arrowFeat->LeftText.getValue()); ui->leArrowTextL->setText(qTemp); - qTemp = QString::fromUtf8(m_arrowIn->RightText.getValue()); + qTemp = QString::fromUtf8(m_arrowFeat->RightText.getValue()); ui->leArrowTextR->setText(qTemp); - qTemp = QString::fromUtf8(m_arrowIn->CenterText.getValue()); + qTemp = QString::fromUtf8(m_arrowFeat->CenterText.getValue()); ui->leArrowTextC->setText(qTemp); - std::string inFile = m_arrowIn->SymbolFile.getValue(); + std::string inFile = m_arrowFeat->SymbolFile.getValue(); auto fi = Base::FileInfo(inFile); if (fi.isReadable()) { - qTemp = QString::fromUtf8(m_arrowIn->SymbolFile.getValue()); + qTemp = QString::fromUtf8(m_arrowFeat->SymbolFile.getValue()); QIcon targetIcon(qTemp); QSize iconSize(32,32); ui->pbArrowSymbol->setIcon(targetIcon); ui->pbArrowSymbol->setIconSize(iconSize); ui->pbArrowSymbol->setText(QString()); + } else { + ui->pbArrowSymbol->setText(QString::fromUtf8("Symbol")); } } - if (m_otherIn != nullptr) { - QString qTemp = QString::fromUtf8(m_otherIn->LeftText.getValue()); + if (m_otherFeat != nullptr) { + QString qTemp = QString::fromUtf8(m_otherFeat->LeftText.getValue()); ui->leOtherTextL->setText(qTemp); - qTemp = QString::fromUtf8(m_otherIn->RightText.getValue()); + qTemp = QString::fromUtf8(m_otherFeat->RightText.getValue()); ui->leOtherTextR->setText(qTemp); - qTemp = QString::fromUtf8(m_otherIn->CenterText.getValue()); + qTemp = QString::fromUtf8(m_otherFeat->CenterText.getValue()); ui->leOtherTextC->setText(qTemp); - std::string inFile = m_otherIn->SymbolFile.getValue(); + std::string inFile = m_otherFeat->SymbolFile.getValue(); auto fi = Base::FileInfo(inFile); if (fi.isReadable()) { - qTemp = QString::fromUtf8(m_otherIn->SymbolFile.getValue()); + qTemp = QString::fromUtf8(m_otherFeat->SymbolFile.getValue()); QIcon targetIcon(qTemp); QSize iconSize(32,32); ui->pbOtherSymbol->setIcon(targetIcon); ui->pbOtherSymbol->setIconSize(iconSize); ui->pbOtherSymbol->setText(QString()); + } else { + ui->pbOtherSymbol->setText(QString::fromUtf8("Symbol")); } } @@ -306,6 +309,7 @@ void TaskWeldingSymbol::onOtherEraseClicked(bool b) { // Base::Console().Message("TWS::onOtherEraseClicked()\n"); Q_UNUSED(b); + m_otherDirty = true; m_otherOut.init(); ui->leOtherTextL->setText(QString()); @@ -313,12 +317,8 @@ void TaskWeldingSymbol::onOtherEraseClicked(bool b) ui->leOtherTextR->setText(QString()); ui->pbOtherSymbol->setIcon(QIcon()); ui->pbOtherSymbol->setText(QString::fromUtf8("Symbol")); - - if ( (!m_createMode) && - (m_otherIn != nullptr) ) { - m_toRemove.push_back(m_otherIn->getNameInDocument()); - } - m_otherIn = nullptr; + m_otherOut.init(); + m_otherPath = QString(); } void TaskWeldingSymbol::onArrowTextChanged(const QString& qs) @@ -371,18 +371,9 @@ void TaskWeldingSymbol::blockButtons(bool b) Q_UNUSED(b); } +//obsolete. tiles are only updated on accept. void TaskWeldingSymbol::saveState(void) { - std::vector tiles = m_weldFeat->getTiles(); - for (auto t: tiles) { - if (t->TileRow.getValue() == 0) { - m_arrowIn = t; - } else if (t->TileRow.getValue() == -1) { - m_otherIn = t; - } else { - Base::Console().Message("TWS::saveState - bad row: %d\n", t->TileRow.getValue()); - } - } } void TaskWeldingSymbol::collectArrowData(void) @@ -409,10 +400,35 @@ void TaskWeldingSymbol::collectOtherData(void) m_otherOut.leftText = Base::Tools::toStdString(ui->leOtherTextL->text()); m_otherOut.centerText = Base::Tools::toStdString(ui->leOtherTextC->text()); m_otherOut.rightText = Base::Tools::toStdString(ui->leOtherTextR->text()); - m_otherOut.symbolPath= Base::Tools::toStdString(m_otherPath); + m_otherOut.symbolPath = Base::Tools::toStdString(m_otherPath); m_otherOut.tileName = ""; } +void TaskWeldingSymbol::getTileFeats(void) +{ +// Base::Console().Message("TWS::getTileFeats()\n"); + std::vector tiles = m_weldFeat->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; + } + } +} + //****************************************************************************** TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol(void) { @@ -487,178 +503,57 @@ void TaskWeldingSymbol::updateWeldingSymbol(void) symbolName.c_str(), tailText.c_str()); } -std::vector TaskWeldingSymbol::createTiles(void) -{ -// Base::Console().Message("TWS::createTiles()\n"); - std::vector tileFeats; - std::string tileType("TechDraw::DrawTileWeld"); - - collectArrowData(); - if (m_arrowOut.toBeSaved) { - std::string tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); - std::string symbolPath = Base::Tools::escapeEncodeString(m_arrowOut.symbolPath); - std::string leftText = Base::Tools::escapeEncodeString(m_arrowOut.leftText); - std::string rightText = Base::Tools::escapeEncodeString(m_arrowOut.rightText); - std::string centerText = Base::Tools::escapeEncodeString(m_arrowOut.centerText); - Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", - tileType.c_str(),tileName.c_str()); - Command::doCommand(Command::Doc,"App.activeDocument().%s.TileRow = %d", - tileName.c_str(), m_arrowOut.row); - Command::doCommand(Command::Doc,"App.activeDocument().%s.TileColumn = %d", - tileName.c_str(), m_arrowOut.col); - Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'", - tileName.c_str(), symbolPath.c_str()); - Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'", - tileName.c_str(), leftText.c_str()); - Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'", - tileName.c_str(), rightText.c_str()); - Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'", - tileName.c_str(), centerText.c_str()); - App::DocumentObject* newTile = m_leadFeat->getDocument()->getObject(tileName.c_str()); - if (newTile == nullptr) { - throw Base::RuntimeError("TaskWeldingSymbol - new tile object not found"); - } - tileFeats.push_back(newTile); - } - - if (m_otherDirty) { - collectOtherData(); - if (m_otherOut.toBeSaved) { - std::string tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); - Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", - tileType.c_str(),tileName.c_str()); - Command::doCommand(Command::Doc,"App.activeDocument().%s.TileRow = %d", - tileName.c_str(), m_otherOut.row); - Command::doCommand(Command::Doc,"App.activeDocument().%s.TileColumn = %d", - tileName.c_str(), m_otherOut.col); - - if (m_otherOut.symbolPath.empty()) { - Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = ''", - tileName.c_str()); - } else { - std::string symbolPath = Base::Tools::escapeEncodeString(m_otherOut.symbolPath); - Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'", - tileName.c_str(), symbolPath.c_str()); - } - - std::string leftText = Base::Tools::escapeEncodeString(m_otherOut.leftText); - std::string rightText = Base::Tools::escapeEncodeString(m_otherOut.rightText); - std::string centerText = Base::Tools::escapeEncodeString(m_otherOut.centerText); - Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'", - tileName.c_str(), leftText.c_str()); - Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'", - tileName.c_str(), rightText.c_str()); - Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'", - tileName.c_str(), centerText.c_str()); - App::DocumentObject* newTile = m_leadFeat->getDocument()->getObject(tileName.c_str()); - if (newTile == nullptr) { - throw Base::RuntimeError("TaskWeldingSymbol - new tile object not found"); - } - tileFeats.push_back(newTile); - } - } - - return tileFeats; -} - -std::vector TaskWeldingSymbol::updateTiles(void) +void TaskWeldingSymbol::updateTiles(void) { // Base::Console().Message("TWS::updateTiles()\n"); - std::vector tileFeats; - std::string tileType("TechDraw::DrawTileWeld"); - std::string tileName; + getTileFeats(); - collectArrowData(); - - if (m_arrowIn != nullptr) { - tileName = m_arrowIn->getNameInDocument(); - } - if (m_arrowIn == nullptr) { - tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); - Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", - tileType.c_str(),tileName.c_str()); - App::DocumentObject* newTile = m_leadFeat->getDocument()->getObject(tileName.c_str()); - if (newTile == nullptr) { - throw Base::RuntimeError("TaskWeldingSymbol - new tile object not found"); - } - tileFeats.push_back(newTile); - } - - if (m_arrowOut.toBeSaved) { - Command::doCommand(Command::Doc,"App.activeDocument().%s.TileRow = %d", - tileName.c_str(), m_arrowOut.row); - Command::doCommand(Command::Doc,"App.activeDocument().%s.TileColumn = %d", - tileName.c_str(), m_arrowOut.col); - - if (m_arrowOut.symbolPath.empty()) { - Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = ''", - tileName.c_str()); - } else { - std::string symbolPath = Base::Tools::escapeEncodeString(m_arrowOut.symbolPath); - Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'", - tileName.c_str(), symbolPath.c_str()); - } - - std::string leftText = Base::Tools::escapeEncodeString(m_arrowOut.leftText); - std::string rightText = Base::Tools::escapeEncodeString(m_arrowOut.rightText); - std::string centerText = Base::Tools::escapeEncodeString(m_arrowOut.centerText); - Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'", - tileName.c_str(), leftText.c_str()); - Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'", - tileName.c_str(), rightText.c_str()); - Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'", - tileName.c_str(), centerText.c_str()); - } - - if (m_otherDirty) { - collectOtherData(); - - if (m_otherIn != nullptr) { - tileName = m_otherIn->getNameInDocument(); - } - - 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')", - tileType.c_str(),tileName.c_str()); - App::DocumentObject* newTile = m_leadFeat->getDocument()->getObject(tileName.c_str()); - if (newTile == nullptr) { - throw Base::RuntimeError("TaskWeldingSymbol - new tile object not found"); - } - tileFeats.push_back(newTile); - } - - if (m_otherOut.toBeSaved) { - Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", - tileType.c_str(),tileName.c_str()); - Command::doCommand(Command::Doc,"App.activeDocument().%s.TileRow = %d", - tileName.c_str(), m_otherOut.row); + if (m_arrowFeat == nullptr) { + Base::Console().Message("TWS::updateTiles - no arrow tile!\n"); + } else { + collectArrowData(); + if (m_arrowOut.toBeSaved) { + std::string tileName = m_arrowFeat->getNameInDocument(); + std::string leftText = Base::Tools::escapeEncodeString(m_arrowOut.leftText); + std::string rightText = Base::Tools::escapeEncodeString(m_arrowOut.rightText); + std::string centerText = Base::Tools::escapeEncodeString(m_arrowOut.centerText); Command::doCommand(Command::Doc,"App.activeDocument().%s.TileColumn = %d", - tileName.c_str(), m_otherOut.col); - - if (m_otherOut.symbolPath.empty()) { - Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = ''", - tileName.c_str()); - } else { - std::string symbolPath = Base::Tools::escapeEncodeString(m_otherOut.symbolPath); - Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'", - tileName.c_str(), symbolPath.c_str()); - } - - std::string leftText = Base::Tools::escapeEncodeString(m_otherOut.leftText); - std::string rightText = Base::Tools::escapeEncodeString(m_otherOut.rightText); - std::string centerText = Base::Tools::escapeEncodeString(m_otherOut.centerText); + tileName.c_str(), m_arrowOut.col); Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'", tileName.c_str(), leftText.c_str()); Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'", tileName.c_str(), rightText.c_str()); Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'", tileName.c_str(), centerText.c_str()); + if (!m_arrowOut.symbolPath.empty()) { + m_arrowFeat->replaceSymbol(m_arrowOut.symbolPath); + } } } - return tileFeats; + if (m_otherFeat == nullptr) { +// Base::Console().Message("TWS::updateTiles - no other tile!\n"); + } else { + if (m_otherDirty) { + collectOtherData(); + if (m_otherOut.toBeSaved) { + std::string tileName = m_otherFeat->getNameInDocument(); + std::string leftText = Base::Tools::escapeEncodeString(m_otherOut.leftText); + std::string rightText = Base::Tools::escapeEncodeString(m_otherOut.rightText); + std::string centerText = Base::Tools::escapeEncodeString(m_otherOut.centerText); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TileColumn = %d", + tileName.c_str(), m_otherOut.col); + Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'", + tileName.c_str(), leftText.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'", + tileName.c_str(), rightText.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'", + tileName.c_str(), centerText.c_str()); + m_otherFeat->replaceSymbol(m_otherOut.symbolPath); + } + } + } + return; } void TaskWeldingSymbol::saveButtons(QPushButton* btnOK, @@ -692,11 +587,7 @@ bool TaskWeldingSymbol::accept() 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); - } + updateTiles(); Gui::Command::updateActive(); Gui::Command::commitCommand(); m_weldFeat->recomputeFeature(); @@ -705,19 +596,8 @@ bool TaskWeldingSymbol::accept() Gui::Command::openCommand("Edit WeldSymbol"); try { updateWeldingSymbol(); - std::vector tileFeats = updateTiles(); - for (auto& obj: tileFeats) { //new tiles only - 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()); - } + updateTiles(); } - catch (...) { Base::Console().Error("TWS::accept - failed to update symbol\n"); } diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h index 231cb3bdf9..83e5064613 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h @@ -76,6 +76,7 @@ public: std::string centerText; std::string rightText; std::string symbolPath; + std::string symbolString; std::string tileName; void init(void) { toBeSaved = false; @@ -86,6 +87,7 @@ public: centerText = ""; rightText = ""; symbolPath= ""; + symbolString = ""; tileName = ""; } @@ -132,8 +134,9 @@ protected: TechDraw::DrawWeldSymbol* createWeldingSymbol(void); void updateWeldingSymbol(void); - std::vector createTiles(void); - std::vector updateTiles(void); +/* std::vector createTiles(void);*/ + void getTileFeats(void); + void updateTiles(void); void collectArrowData(void); void collectOtherData(void); @@ -148,16 +151,20 @@ private: TechDraw::DrawLeaderLine* m_leadFeat; TechDraw::DrawWeldSymbol* m_weldFeat; - TechDraw::DrawTileWeld* m_arrowIn; - TechDraw::DrawTileWeld* m_otherIn; +/* TechDraw::DrawTileWeld* m_arrowIn; //save starting values*/ +/* TechDraw::DrawTileWeld* m_otherIn;*/ + TechDraw::DrawTileWeld* m_arrowFeat; + TechDraw::DrawTileWeld* m_otherFeat; TileImage m_arrowOut; TileImage m_otherOut; QString m_arrowPath; QString m_otherPath; + QString m_arrowSymbol; + QString m_otherSymbol; - std::vector m_toRemove; +/* std::vector m_toRemove;*/ QPushButton* m_btnOK; QPushButton* m_btnCancel;