diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index e771d2d994..096deac1d4 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -256,7 +256,6 @@ bool CosmeticEdge::fromCSV(std::string& lineSpec) return false; } std::vector values = split(lineSpec); - Base::Console().Message("CE::fromCSV - values: %d\n",values.size()); if (values.size() < maxCells) { Base::Console().Message( "CosmeticEdge::fromCSV(%s) invalid CSV entry\n",lineSpec.c_str() ); return false; @@ -293,7 +292,7 @@ bool CosmeticEdge::fromCSV(std::string& lineSpec) //duplicate of CV routine. make static? or base class? std::vector CosmeticEdge::split(std::string csvLine) { - Base::Console().Message("CE::split - csvLine: %s\n",csvLine.c_str()); +// Base::Console().Message("CE::split - csvLine: %s\n",csvLine.c_str()); std::vector result; std::stringstream lineStream(csvLine); std::string cell; diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 5e7bc69187..2ee43cf081 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -1019,8 +1019,13 @@ int DrawViewPart::addRandomVertex(Base::Vector3d pos) int newIdx = -1; TechDraw::CosmeticVertex* rVert = new TechDraw::CosmeticVertex(pos); cosmoVertex.push_back(rVert); + stuffCosmeticVertexList(); + return newIdx; +} - //stuff stringList +void DrawViewPart::stuffCosmeticVertexList(void) +{ +// Base::Console().Message("DVP::stuffCosmeticVertexList()\n"); std::vector saveVerts; const std::vector cosVerts = getCosmeticVertex(); for (auto& cv: cosVerts) { @@ -1028,18 +1033,50 @@ int DrawViewPart::addRandomVertex(Base::Vector3d pos) saveVerts.push_back(csv); } CosmeticVertexList.setValues(saveVerts); - return newIdx; +} + +void DrawViewPart::removeRandomVertex(TechDraw::CosmeticVertex* cv) +{ +// Base::Console().Message("DVP::removeRandomVertex(cv) - cvs in: %d\n", cosmoVertex.size()); + bool found = false; + std::vector newCosmoVertex; + for (auto& v: cosmoVertex) { + if (cv == v) { + found = true; + continue; + } else { + newCosmoVertex.push_back(v); + } + } + if ( (cv != nullptr) && + (found) ) { + delete cv; + } + + cosmoVertex = newCosmoVertex; + stuffCosmeticVertexList(); + recomputeFeature(); +} + +void DrawViewPart::removeRandomVertex(int idx) +{ + if (idx < (int) cosmoVertex.size()) { + TechDraw::CosmeticVertex* cvSave = cosmoVertex.at(idx); + cosmoVertex.erase(cosmoVertex.begin() + idx); + delete cvSave; + } + + stuffCosmeticVertexList(); + recomputeFeature(); } TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertexByIndex(int idx) const { // Base::Console().Message("DVP::getCosmeticVertexByIndex(%d)\n", idx); - int cosmoOffset = 1000; - int realIdx = idx - cosmoOffset; CosmeticVertex* result = nullptr; const std::vector verts = getCosmeticVertex(); - if ((unsigned) realIdx < verts.size()) { - result = verts.at(realIdx); + if ((unsigned) idx < verts.size()) { + result = verts.at(idx); } return result; } @@ -1084,7 +1121,7 @@ int DrawViewPart::addRandomEdge(Base::Vector3d p1, Base::Vector3d p2) std::string csv = ce->toCSV(); saveEdges.push_back(csv); } - CosmeticEdgeList.setValues(saveEdges); + stuffCosmeticEdgeList(); return newIdx; } @@ -1094,15 +1131,7 @@ int DrawViewPart::addRandomEdge(TopoDS_Edge e) int newIdx = -1; TechDraw::CosmeticEdge* rEdge = new TechDraw::CosmeticEdge(e); cosmoEdge.push_back(rEdge); - - //stuff stringList - std::vector saveEdges; - const std::vector cosEdges = getCosmeticEdge(); - for (auto& ce: cosEdges) { - std::string csv = ce->toCSV(); - saveEdges.push_back(csv); - } - CosmeticEdgeList.setValues(saveEdges); + stuffCosmeticEdgeList(); return newIdx; } @@ -1111,8 +1140,13 @@ int DrawViewPart::addRandomEdge(CosmeticEdge* ce) // Base::Console().Message("DVP::addRandomEdge(CosmeticEdge)\n"); int newIdx = -1; cosmoEdge.push_back(ce); + stuffCosmeticEdgeList(); + return newIdx; +} - //stuff stringList +void DrawViewPart::stuffCosmeticEdgeList(void) +{ +// Base::Console().Message("DVP::stuffCosmeticEdgeList()\n"); std::vector saveEdges; const std::vector cosEdges = getCosmeticEdge(); for (auto& ce: cosEdges) { @@ -1120,18 +1154,49 @@ int DrawViewPart::addRandomEdge(CosmeticEdge* ce) saveEdges.push_back(csv); } CosmeticEdgeList.setValues(saveEdges); - return newIdx; +} + +void DrawViewPart::removeRandomEdge(TechDraw::CosmeticEdge* ce) +{ +// Base::Console().Message("DVP::removeRandomEdge(ce) - ces in: %d\n", cosmoEdge.size()); + bool found = false; + std::vector newCosmoEdge; + for (auto& e: cosmoEdge) { + if (ce == e) { + found = true; + continue; + } else { + newCosmoEdge.push_back(e); + } + } + if ( (ce != nullptr) && + (found) ) { + delete ce; + } + cosmoEdge = newCosmoEdge; + stuffCosmeticEdgeList(); + recomputeFeature(); +} + +void DrawViewPart::removeRandomEdge(int idx) +{ +// Base::Console().Message("DVP::removeRandomEdge(%d) - ces in: %d\n", idx, cosmoEdge.size()); + if (idx < (int) cosmoEdge.size()) { + TechDraw::CosmeticEdge* ceSave = cosmoEdge.at(idx); + cosmoEdge.erase(cosmoEdge.begin() + idx); + delete ceSave; + } + stuffCosmeticEdgeList(); + recomputeFeature(); } TechDraw::CosmeticEdge* DrawViewPart::getCosmeticEdgeByIndex(int idx) const { // Base::Console().Message("DVP::getCosmeticEdgeByIndex(%d)\n", idx); - int cosmoOffset = 1000; - int realIdx = idx - cosmoOffset; CosmeticEdge* result = nullptr; const std::vector edges = getCosmeticEdge(); - if ((unsigned) realIdx < edges.size()) { - result = edges.at(realIdx); + if (idx < (int) edges.size()) { + result = edges.at(idx); } return result; } diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 06a2bf575a..fde103cf6e 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -168,6 +168,8 @@ public: bool isIso(void) const; virtual int addRandomVertex(Base::Vector3d pos); + virtual void removeRandomVertex(TechDraw::CosmeticVertex* cv); + virtual void removeRandomVertex(int idx); const std::vector & getCosmeticVertex(void) const { return cosmoVertex; } TechDraw::CosmeticVertex* getCosmeticVertexByIndex(int idx) const; TechDraw::CosmeticVertex* getCosmeticVertexByLink(int idx) const; @@ -176,6 +178,8 @@ public: virtual int addRandomEdge(Base::Vector3d start, Base::Vector3d end); virtual int addRandomEdge(TopoDS_Edge e); virtual int addRandomEdge(TechDraw::CosmeticEdge*); + virtual void removeRandomEdge(TechDraw::CosmeticEdge* ce); + virtual void removeRandomEdge(int idx); const std::vector & getCosmeticEdge(void) const { return cosmoEdge; } TechDraw::CosmeticEdge* getCosmeticEdgeByIndex(int idx) const; TechDraw::CosmeticEdge* getCosmeticEdgeByLink(int idx) const; @@ -205,9 +209,12 @@ protected: //Cosmetics std::vector cosmoVertex; void rebuildCosmoVertex(void); + void stuffCosmeticVertexList(void); std::vector cosmoEdge; void rebuildCosmoEdge(void); + void stuffCosmeticEdgeList(void); + private: bool nowUnsetting; diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 6478b92556..804f775ea0 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -481,6 +481,18 @@ int GeometryObject::addRandomVertex(Base::Vector3d pos) return idx; } +//void GeometryObject::removeRandomVertex(TechDraw::CosmeticVertex* cv) +//{ +// Base::Console().Message("GO::removeRandomVertex(cv)\n"); + +//} + +//void GeometryObject::removeRandomVertex(int idx) +//{ +// Base::Console().Message("GO::removeRandomVertex(%d)\n", idx); + +//} + int GeometryObject::addRandomEdge(TechDrawGeometry::BaseGeom* base) { // Base::Console().Message("GO::addRandomEdge() - cosmetic: %d\n", base->cosmetic); @@ -490,6 +502,18 @@ int GeometryObject::addRandomEdge(TechDrawGeometry::BaseGeom* base) return idx; } +//void GeometryObject::removeRandomEdge(TechDraw::CosmeticEdge* ce) +//{ +// Base::Console().Message("GO::removeRandomEdge(ce)\n"); + +//} + +//void GeometryObject::removeRandomEdge(int idx) +//{ +// Base::Console().Message("GO::removeRandomEdge(%d)\n",idx); + +//} + //! empty Face geometry void GeometryObject::clearFaceGeom() { diff --git a/src/Mod/TechDraw/App/GeometryObject.h b/src/Mod/TechDraw/App/GeometryObject.h index 92a9da7dd4..f0785c99f0 100644 --- a/src/Mod/TechDraw/App/GeometryObject.h +++ b/src/Mod/TechDraw/App/GeometryObject.h @@ -127,8 +127,13 @@ public: TopoDS_Shape getHidSeam(void) { return hidSeam; } TopoDS_Shape getHidIso(void) { return hidIso; } + //Are removeXXXXX functions really needed for GO? int addRandomVertex(Base::Vector3d pos); +/* void removeRandomVertex(TechDraw::CosmeticVertex* cv);*/ +/* void removeRandomVertex(int idx);*/ int addRandomEdge(TechDrawGeometry::BaseGeom* bg); +/* void removeRandomEdge(TechDraw::CosmeticEdge* ce);*/ +/* void removeRandomEdge(int idx);*/ protected: //HLR output diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index c0e3c0043e..a3d7012cd7 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -659,6 +659,97 @@ bool CmdTechDrawCenterLine::isActive(void) return (havePage && haveView); } +//=========================================================================== +// TechDraw_CosmeticEraser +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawCosmeticEraser); + +CmdTechDrawCosmeticEraser::CmdTechDrawCosmeticEraser() + : Command("TechDraw_CosmeticEraser") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Remove a cosmetic object"); + sToolTipText = QT_TR_NOOP("Remove a cosmetic object"); + sWhatsThis = "TechDraw_CosmeticEraser"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-eraser"; +} + +void CmdTechDrawCosmeticEraser::activated(int iMsg) +{ + Q_UNUSED(iMsg); + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + if (dlg != nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), + QObject::tr("Close active task dialog and try again.")); + return; + } + + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + + std::vector selection = getSelection().getSelectionEx(); + + if (selection.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Nothing selected")); + return; + } + + bool selectionError = false; + for (auto& s: selection) { + TechDraw::DrawViewPart * objFeat = static_cast (s.getObject()); + if (!objFeat->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + selectionError = true; + break; + } + } + if (selectionError) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("At least 1 object in selection is not a part view")); + return; + } + + TechDraw::DrawViewPart * objFeat = nullptr; + std::vector SubNames; + std::vector::iterator itSel = selection.begin(); + for (; itSel != selection.end(); itSel++) { + if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + objFeat = static_cast ((*itSel).getObject()); + SubNames = (*itSel).getSubNames(); + } + for (auto& s: SubNames) { + int idx = TechDraw::DrawUtil::getIndexFromName(s); + std::string geomType = TechDraw::DrawUtil::getGeomTypeFromName(s); + if (geomType == "Edge") { + TechDraw::CosmeticEdge* ce = objFeat->getCosmeticEdgeByLink(idx); + if (ce != nullptr) { + objFeat->removeRandomEdge(ce); + } + } else if (geomType == "Vertex") { + TechDraw::CosmeticVertex* cv = objFeat->getCosmeticVertexByLink(idx); + if (cv != nullptr) { + objFeat->removeRandomVertex(cv); + } + } else { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Unknown object type in selection")); + return; + } + } + } +} + +bool CmdTechDrawCosmeticEraser::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this); + return (havePage && haveView); +} void CreateTechDrawCommandsAnnotate(void) { @@ -672,6 +763,7 @@ void CreateTechDrawCommandsAnnotate(void) rcCmdMgr.addCommand(new CmdTechDrawQuadrant()); rcCmdMgr.addCommand(new CmdTechDrawAnnotation()); rcCmdMgr.addCommand(new CmdTechDrawCenterLine()); + rcCmdMgr.addCommand(new CmdTechDrawCosmeticEraser()); } //=========================================================================== diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 442ba90f54..fac7020ae3 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -67,6 +67,7 @@ icons/actions/techdraw-midpoint.svg icons/actions/techdraw-quadrant.svg icons/actions/techdraw-centerline.svg + icons/actions/techdraw-eraser.svg icons/actions/section-up.svg icons/actions/section-down.svg icons/actions/section-left.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-eraser.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-eraser.svg new file mode 100644 index 0000000000..9acfc8f1a0 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-eraser.svg @@ -0,0 +1,476 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index d97cb5b2c2..647846c7ab 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -93,6 +93,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_CosmeticVertex"; *draw << "TechDraw_Midpoints"; *draw << "TechDraw_Quadrant"; + *draw << "TechDraw_CosmeticEraser"; return root; } @@ -112,7 +113,6 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *views << "TechDraw_ProjGroup"; *views << "TechDraw_NewViewSection"; *views << "TechDraw_NewViewDetail"; -// *views << "TechDraw_Annotation"; *views << "TechDraw_DraftView"; *views << "TechDraw_ArchView"; *views << "TechDraw_Spreadsheet"; @@ -157,9 +157,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *anno << "TechDraw_RichAnno"; *anno << "TechDraw_CosmeticVertexGrp"; *anno << "TechDraw_CenterLine"; -// *anno << "TechDraw_CosmeticVertex"; -// *anno << "TechDraw_Midpoints"; -// *anno << "TechDraw_Quadrant"; + *anno << "TechDraw_CosmeticEraser"; return root; } @@ -179,7 +177,6 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *views << "TechDraw_ProjGroup"; *views << "TechDraw_NewViewSection"; *views << "TechDraw_NewViewDetail"; -// *views << "TechDraw_Annotation"; *views << "TechDraw_DraftView"; *views << "TechDraw_Spreadsheet"; @@ -214,9 +211,6 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *decor << "TechDraw_Symbol"; *decor << "TechDraw_Image"; *decor << "TechDraw_ToggleFrame"; -// *decor << "TechDraw_RedrawPage"; -// *decor << "TechDraw_LeaderLine"; -// *decor << "TechDraw_RichAnno"; Gui::ToolBarItem *anno = new Gui::ToolBarItem(root); anno->setCommand("TechDraw Annotation"); @@ -225,9 +219,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *anno << "TechDraw_RichAnno"; *anno << "TechDraw_CosmeticVertexGrp"; *anno << "TechDraw_CenterLine"; -// *anno << "TechDraw_CosmeticVertex"; -// *anno << "TechDraw_Midpoints"; -// *anno << "TechDraw_Quadrant"; + *anno << "TechDraw_CosmeticEraser"; return root; }