From e881dcd860858b1801b7475320f24784c2febc76 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sat, 6 Jul 2019 11:44:55 -0400 Subject: [PATCH] [TD]Add restore invisible lines --- src/Mod/TechDraw/App/DrawViewPart.cpp | 6 +- src/Mod/TechDraw/App/DrawViewPart.h | 2 +- src/Mod/TechDraw/Gui/CMakeLists.txt | 3 + src/Mod/TechDraw/Gui/CommandAnnotate.cpp | 10 +- src/Mod/TechDraw/Gui/TaskLineDecor.cpp | 239 ++++++++++++++++++++--- src/Mod/TechDraw/Gui/TaskLineDecor.h | 39 ++++ src/Mod/TechDraw/Gui/TaskRestoreLines.ui | 93 +++++++++ 7 files changed, 354 insertions(+), 38 deletions(-) create mode 100644 src/Mod/TechDraw/Gui/TaskRestoreLines.ui diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index da51af4dcb..0f22d6c4db 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -1276,7 +1276,7 @@ int DrawViewPart::addCenterLine(CenterLine* cl) return newIdx; } -void DrawViewPart::writeCListProp(void) +void DrawViewPart::writeCLineProp(void) { std::vector saveLines; const std::vector cLines = getCenterLines(); @@ -1309,7 +1309,7 @@ void DrawViewPart::removeCenterLine(int idx) { if (idx < (int) CLineTable.size()) { CLineTable.erase(CLineTable.begin() + idx); - writeCListProp(); + writeCLineProp(); recomputeFeature(); } } @@ -1319,7 +1319,7 @@ void DrawViewPart::replaceCenterLine(int idx, TechDraw::CenterLine* cl) std::vector lines = getCenterLines(); if (idx < (int) lines.size()) { lines.at(idx) = cl; - writeCListProp(); + writeCLineProp(); recomputeFeature(); } } diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 6ef27e0d26..f72681aac8 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -188,7 +188,7 @@ public: void clearCosmeticEdges(void); virtual int addCenterLine(TechDraw::CenterLine*); - virtual void writeCListProp(void); + virtual void writeCLineProp(void); virtual void removeCenterLine(TechDraw::CenterLine* cl); virtual void removeCenterLine(int idx); const std::vector & getCenterLines(void) const { return CLineTable; } diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 7844b7b41e..5ce68e42e3 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -89,6 +89,7 @@ set(TechDrawGui_UIC_SRCS TaskCosVertex.ui TaskCenterLine.ui TaskLineDecor.ui + TaskRestoreLines.ui ) if(BUILD_QT5) @@ -164,6 +165,7 @@ SET(TechDrawGui_SRCS TaskLineDecor.ui TaskLineDecor.cpp TaskLineDecor.h + TaskRestoreLines.ui DrawGuiUtil.cpp DrawGuiUtil.h Rez.cpp @@ -317,6 +319,7 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskBalloon.ui TaskCenterLine.ui TaskLineDecor.ui + TaskRestoreLines.ui ) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index b2d7d06e57..2f9c3fdcdd 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -842,7 +842,7 @@ void CmdTechDrawDecorateLine::activated(int iMsg) } } else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), - QObject::tr("You must select line(s) in a View.")); + QObject::tr("You must select a View and/or line(s).")); return; } @@ -863,14 +863,8 @@ void CmdTechDrawDecorateLine::activated(int iMsg) } } - if ( edgeNames.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), - QObject::tr("You must select line(s) to edit.")); - return; - } else { - Gui::Control().showDialog(new TaskDlgLineDecor(baseFeat, + Gui::Control().showDialog(new TaskDlgLineDecor(baseFeat, edgeNames)); - } } bool CmdTechDrawDecorateLine::isActive(void) diff --git a/src/Mod/TechDraw/Gui/TaskLineDecor.cpp b/src/Mod/TechDraw/Gui/TaskLineDecor.cpp index 0ecf65738f..1113111395 100644 --- a/src/Mod/TechDraw/Gui/TaskLineDecor.cpp +++ b/src/Mod/TechDraw/Gui/TaskLineDecor.cpp @@ -48,8 +48,10 @@ #include #include -#include "TaskLineDecor.h" #include +#include + +#include "TaskLineDecor.h" using namespace Gui; using namespace TechDraw; @@ -107,31 +109,33 @@ void TaskLineDecor::getDefaults(void) m_visible = 1; //set defaults to format of 1st edge - int num = DrawUtil::getIndexFromName(m_edges.front()); - BaseGeom* bg = m_partFeat->getGeomByIndex(num); - if (bg != nullptr) { - if (bg->cosmetic) { - if (bg->source() == 1) { - TechDraw::CosmeticEdge* ce = m_partFeat->getCosmeticEdgeByIndex(bg->sourceIndex()); - m_style = ce->m_format.m_style; - m_color = ce->m_format.m_color; - m_weight = ce->m_format.m_weight; - m_visible = ce->m_format.m_visible; - } else if (bg->source() == 2) { - TechDraw::CenterLine* cl = m_partFeat->getCenterLineByIndex(bg->sourceIndex()); - m_style = cl->m_format.m_style; - m_color = cl->m_format.m_color; - m_weight = cl->m_format.m_weight; - m_visible = cl->m_format.m_visible; - } - } else { - TechDraw::GeomFormat* gf = m_partFeat->getGeomFormatByGeom(num); - if (gf != nullptr) { - m_style = gf->m_format.m_style; - m_color = gf->m_format.m_color; - m_weight = gf->m_format.m_weight; - m_visible = gf->m_format.m_visible; + if (!m_edges.empty()) { + int num = DrawUtil::getIndexFromName(m_edges.front()); + BaseGeom* bg = m_partFeat->getGeomByIndex(num); + if (bg != nullptr) { + if (bg->cosmetic) { + if (bg->source() == 1) { + TechDraw::CosmeticEdge* ce = m_partFeat->getCosmeticEdgeByIndex(bg->sourceIndex()); + m_style = ce->m_format.m_style; + m_color = ce->m_format.m_color; + m_weight = ce->m_format.m_weight; + m_visible = ce->m_format.m_visible; + } else if (bg->source() == 2) { + TechDraw::CenterLine* cl = m_partFeat->getCenterLineByIndex(bg->sourceIndex()); + m_style = cl->m_format.m_style; + m_color = cl->m_format.m_color; + m_weight = cl->m_format.m_weight; + m_visible = cl->m_format.m_visible; } + } else { + TechDraw::GeomFormat* gf = m_partFeat->getGeomFormatByGeom(num); + if (gf != nullptr) { + m_style = gf->m_format.m_style; + m_color = gf->m_format.m_color; + m_weight = gf->m_format.m_weight; + m_visible = gf->m_format.m_visible; + } + } } } } @@ -162,7 +166,7 @@ void TaskLineDecor::onVisibleChanged(void) void TaskLineDecor::applyDecorations(void) { -// Base::Console().Message("TLD::applyDecorations()\n"); + Base::Console().Message("TLD::applyDecorations()\n"); for (auto& e: m_edges) { int num = DrawUtil::getIndexFromName(e); BaseGeom* bg = m_partFeat->getGeomByIndex(num); @@ -174,6 +178,7 @@ void TaskLineDecor::applyDecorations(void) ce->m_format.m_color = m_color; ce->m_format.m_weight = m_weight; ce->m_format.m_visible = m_visible; + Base::Console().Message("TLD::applyDecorations()\n"); } else if (bg->source() == 2) { TechDraw::CenterLine* cl = m_partFeat->getCenterLineByIndex(bg->sourceIndex()); cl->m_format.m_style = m_style; @@ -201,14 +206,20 @@ void TaskLineDecor::applyDecorations(void) } } } + } bool TaskLineDecor::accept() { + Base::Console().Message("TLD::accept()\n"); Gui::Document* doc = Gui::Application::Instance->getDocument(m_partFeat->getDocument()); if (!doc) return false; applyDecorations(); + m_partFeat->writeGFormatProp(); + m_partFeat->writeCEdgeProp(); + m_partFeat->writeCLineProp(); + m_partFeat->requestPaint(); //Gui::Command::updateActive(); //no chain of updates here @@ -219,6 +230,7 @@ bool TaskLineDecor::accept() bool TaskLineDecor::reject() { + Base::Console().Message("TLD::reject()\n"); Gui::Document* doc = Gui::Application::Instance->getDocument(m_partFeat->getDocument()); if (!doc) return false; @@ -232,6 +244,170 @@ void TaskLineDecor::changeEvent(QEvent *e) ui->retranslateUi(this); } } +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +TaskRestoreLines::TaskRestoreLines(TechDraw::DrawViewPart* partFeat) : + ui(new Ui_TaskRestoreLines), + m_partFeat(partFeat) +{ + ui->setupUi(this); + + connect(ui->pb_All, SIGNAL(clicked( )), this, SLOT(onAllPressed(void))); + connect(ui->pb_Geometry, SIGNAL(clicked( )), this, SLOT(onGeometryPressed(void))); + connect(ui->pb_Cosmetic, SIGNAL(clicked( )), this, SLOT(onCosmeticPressed( void ))); + connect(ui->pb_Center, SIGNAL(clicked( )), this, SLOT(onCenterPressed( void ))); + + initUi(); +} + +TaskRestoreLines::~TaskRestoreLines() +{ + delete ui; +} + +void TaskRestoreLines::initUi() +{ + ui->l_All->setText(QString::number(countInvisibleLines())); + ui->l_Geometry->setText(QString::number(countInvisibleGeoms())); + ui->l_Cosmetic->setText(QString::number(countInvisibleCosmetics())); + ui->l_Center->setText(QString::number(countInvisibleCenters())); +} + +void TaskRestoreLines::onAllPressed(void) +{ + Base::Console().Message("TRL::onAllPressed()\n"); + onGeometryPressed(); + onCosmeticPressed(); + onCenterPressed(); +} + +void TaskRestoreLines::onGeometryPressed(void) +{ + Base::Console().Message("TRL::onGeometryPressed()\n"); + restoreInvisibleGeoms(); + ui->l_Geometry->setText(QString::number(0)); + ui->l_All->setText(QString::number(countInvisibleLines())); + m_partFeat->writeGFormatProp(); +} + +void TaskRestoreLines::onCosmeticPressed(void) +{ + Base::Console().Message("TRL::onCosmeticPressed()\n"); + restoreInvisibleCosmetics(); + ui->l_Cosmetic->setText(QString::number(0)); + ui->l_All->setText(QString::number(countInvisibleLines())); + m_partFeat->writeCEdgeProp(); +} + +void TaskRestoreLines::onCenterPressed(void) +{ + Base::Console().Message("TRL::onCenterPressed()\n"); + restoreInvisibleCenters(); + ui->l_Center->setText(QString::number(0)); + ui->l_All->setText(QString::number(countInvisibleLines())); + m_partFeat->writeCLineProp(); +} + +int TaskRestoreLines::countInvisibleLines(void) +{ + int result = 0; + result += countInvisibleGeoms(); + result += countInvisibleCosmetics(); + result += countInvisibleCenters(); + return result; +} + +int TaskRestoreLines::countInvisibleGeoms(void) +{ + int iGeoms = 0; + const std::vector geoms = m_partFeat->getGeomFormats(); + for (auto& g : geoms) { + if (!g->m_format.m_visible) { + iGeoms++; + } + } + return iGeoms; +} + +int TaskRestoreLines::countInvisibleCosmetics(void) +{ + int iCosmos = 0; + const std::vector cosmos = m_partFeat->getCosmeticEdges(); + for (auto& c : cosmos) { + if (!c->m_format.m_visible) { + iCosmos++; + } + } + return iCosmos++; +} + +int TaskRestoreLines::countInvisibleCenters(void) +{ + int iCenter = 0; + const std::vector centers = m_partFeat->getCenterLines(); + for (auto& c : centers) { + if (!c->m_format.m_visible) { + iCenter++; + } + } + return iCenter++; +} + +void TaskRestoreLines::restoreInvisibleLines(void) +{ + restoreInvisibleGeoms(); + restoreInvisibleCosmetics(); + restoreInvisibleCenters(); +} + +void TaskRestoreLines::restoreInvisibleGeoms(void) +{ + const std::vector geoms = m_partFeat->getGeomFormats(); + for (auto& g : geoms) { + if (!g->m_format.m_visible) { + g->m_format.m_visible = true; + } + } +} + +void TaskRestoreLines::restoreInvisibleCosmetics(void) +{ + const std::vector cosmos = m_partFeat->getCosmeticEdges(); + for (auto& c : cosmos) { + if (!c->m_format.m_visible) { + c->m_format.m_visible = true; + } + } +} + +void TaskRestoreLines::restoreInvisibleCenters(void) +{ + const std::vector centers = m_partFeat->getCenterLines(); + for (auto& c : centers) { + if (!c->m_format.m_visible) { + c->m_format.m_visible = true; + } + } +} + + +bool TaskRestoreLines::accept() +{ + Base::Console().Message("TRL::accept()\n"); + return true; +} + +bool TaskRestoreLines::reject() +{ + Base::Console().Message("TRL::reject()\n"); + return false; +} + +void TaskRestoreLines::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TaskDlgLineDecor::TaskDlgLineDecor(TechDraw::DrawViewPart* partFeat, @@ -243,6 +419,15 @@ TaskDlgLineDecor::TaskDlgLineDecor(TechDraw::DrawViewPart* partFeat, widget->windowTitle(), true, 0); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); + if (edgeNames.empty()) { + taskbox->hideGroupBox(); + } + + restore = new TaskRestoreLines(partFeat); + restoreBox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-linedecor"), + tr("Restore Invisible Lines"), true, 0); + restoreBox->groupLayout()->addWidget(restore); + Content.push_back(restoreBox); } TaskDlgLineDecor::~TaskDlgLineDecor() @@ -262,12 +447,14 @@ void TaskDlgLineDecor::clicked(int i) bool TaskDlgLineDecor::accept() { + Base::Console().Message("TDLD::accept()\n"); widget->accept(); return true; } bool TaskDlgLineDecor::reject() { + Base::Console().Message("TDLD::reject()\n"); widget->reject(); return true; } diff --git a/src/Mod/TechDraw/Gui/TaskLineDecor.h b/src/Mod/TechDraw/Gui/TaskLineDecor.h index 8443f20f18..ca644d3e31 100644 --- a/src/Mod/TechDraw/Gui/TaskLineDecor.h +++ b/src/Mod/TechDraw/Gui/TaskLineDecor.h @@ -29,6 +29,7 @@ #include #include +#include //???? class Ui_TaskLineDecor; @@ -76,6 +77,42 @@ private: bool m_visible; }; +class TaskRestoreLines : public QWidget +{ + Q_OBJECT + +public: + TaskRestoreLines(TechDraw::DrawViewPart* partFeat); + ~TaskRestoreLines(); + +public: + virtual bool accept(); + virtual bool reject(); + +protected Q_SLOTS: + void onAllPressed(void); + void onGeometryPressed(void); + void onCosmeticPressed(void); + void onCenterPressed(void); + +protected: + void changeEvent(QEvent *e); + void initUi(void); + int countInvisibleLines(void); + int countInvisibleGeoms(void); + int countInvisibleCosmetics(void); + int countInvisibleCenters(void); + void restoreInvisibleLines(void); + void restoreInvisibleGeoms(void); + void restoreInvisibleCosmetics(void); + void restoreInvisibleCenters(void); + +private: + Ui_TaskRestoreLines* ui; + TechDraw::DrawViewPart* m_partFeat; +}; + + class TaskDlgLineDecor : public Gui::TaskView::TaskDialog { Q_OBJECT @@ -103,7 +140,9 @@ protected: private: TaskLineDecor * widget; + TaskRestoreLines* restore; Gui::TaskView::TaskBox* taskbox; + Gui::TaskView::TaskBox* restoreBox; }; } //namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/TaskRestoreLines.ui b/src/Mod/TechDraw/Gui/TaskRestoreLines.ui new file mode 100644 index 0000000000..db6338b64c --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskRestoreLines.ui @@ -0,0 +1,93 @@ + + + TechDrawGui::TaskRestoreLines + + + + 0 + 0 + 227 + 180 + + + + Restore Invisible Lines + + + + + + + + All + + + + + + + Geometry + + + + + + + CenterLine + + + + + + + Cosmetic + + + + + + + 0 + + + Qt::AlignCenter + + + + + + + 0 + + + Qt::AlignCenter + + + + + + + 0 + + + Qt::AlignCenter + + + + + + + 0 + + + Qt::AlignCenter + + + + + + + + + +