From 82db4a3e47358fc81462c47aff5c12f89d55d07f Mon Sep 17 00:00:00 2001 From: wandererfan Date: Fri, 15 Sep 2023 10:04:51 -0400 Subject: [PATCH] [TD]allow cosmetic deletion via DEL --- src/Mod/TechDraw/App/DrawUtil.cpp | 22 +++++++ src/Mod/TechDraw/App/DrawUtil.h | 2 + src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp | 61 +++++++++++++++++-- src/Mod/TechDraw/Gui/ViewProviderViewPart.h | 3 + 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index 986c4a43be..cc6a4c225a 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -69,6 +69,7 @@ #include "GeometryObject.h" #include "LineGroup.h" #include "Preferences.h" +#include "DrawViewPart.h" using namespace TechDraw; @@ -1625,6 +1626,27 @@ std::string DrawUtil::translateArbitrary(std::string context, std::string baseNa return ssTranslated + suffix; } +// true if owner->element is a cosmetic vertex +bool DrawUtil::isCosmeticVertex(App::DocumentObject* owner, std::string element) +{ + auto ownerView = static_cast(owner); + auto vertex = ownerView->getVertex(element); + if (vertex) { + return vertex->getCosmetic(); + } + return false; +} + +// true if owner->element is a cosmetic edge +bool DrawUtil::isCosmeticEdge(App::DocumentObject* owner, std::string element) +{ + auto ownerView = static_cast(owner); + auto edge = ownerView->getEdge(element); + if (edge) { + return edge->getCosmetic(); + } + return false; +} //============================ // various debugging routines. diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 0933fc909f..bbb7a64120 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -255,6 +255,8 @@ public: static std::string translateArbitrary(std::string context, std::string baseName, std::string uniqueName); + static bool isCosmeticVertex(App::DocumentObject* owner, std::string element); + static bool isCosmeticEdge(App::DocumentObject* owner, std::string element); //debugging routines static void dumpVertexes(const char* text, const TopoDS_Shape& s); diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp index a21bccd4fd..1340e668b4 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include "PreferencesGui.h" #include "QGIView.h" @@ -59,6 +60,7 @@ using namespace TechDrawGui; using namespace TechDraw; +using DU = DrawUtil; PROPERTY_SOURCE(TechDrawGui::ViewProviderViewPart, TechDrawGui::ViewProviderDrawingView) @@ -304,10 +306,20 @@ void ViewProviderViewPart::handleChangedPropertyType(Base::XMLReader &reader, co } } -bool ViewProviderViewPart::onDelete(const std::vector &) +bool ViewProviderViewPart::onDelete(const std::vector & subNames) { - // we cannot delete if the view has a section or detail view +// Base::Console().Message("VPVP::onDelete() - subs: %d\n", subNames.size()); + // if a cosmetic subelement is in the list of selected subNames then we treat this + // as a delete of the subelement and not a delete of the DVP + std::vector removables = getSelectedCosmetics(subNames); + if (!removables.empty()) { + // we have cosmetics, so remove them and tell Std_Delete not to remove the DVP + deleteCosmeticElements(removables); + getViewObject()->recomputeFeature(); + return false; + } + // we cannot delete if the view has a section or detail view QString bodyMessage; QTextStream bodyMessageStream(&bodyMessage); @@ -323,19 +335,58 @@ bool ViewProviderViewPart::onDelete(const std::vector &) QMessageBox::Ok); return false; } - else { - return true; - } + return true; } bool ViewProviderViewPart::canDelete(App::DocumentObject *obj) const { +// Base::Console().Message("VPVP::canDelete()\n"); // deletions of part objects (detail view, View etc.) are valid // that it cannot be deleted if it has a child view is handled in the onDelete() function Q_UNUSED(obj) return true; } +//! extract the names of cosmetic subelements from the list of all selected elements +std::vector ViewProviderViewPart::getSelectedCosmetics(std::vector subNames) +{ +// Base::Console().Message("VPVP::getSelectedCosmetics(%d removables)\n", subNames.size()); + + std::vector result; + // pick out any cosmetic vertices or edges in the selection + for (auto& sub : subNames) { + if (DU::getGeomTypeFromName(sub) == "Vertex") { + if (DU::isCosmeticVertex(getViewObject(), sub)) { + result.emplace_back(sub); + } + } else if (DU::getGeomTypeFromName(sub) == "Edge") { + if (DU::isCosmeticEdge(getViewObject(), sub)) { + result.emplace_back(sub); + } + } + } + return result; +} + +//! delete cosmetic elements for a list of subelement names +void ViewProviderViewPart::deleteCosmeticElements(std::vector removables) +{ +// Base::Console().Message("VPVP::deleteCosmeticElements(%d removables)\n", removables.size()); + for (auto& name : removables) { + if (DU::getGeomTypeFromName(name) == "Vertex") { + CosmeticVertex* vert = getViewObject()->getCosmeticVertexBySelection(name); + getViewObject()->removeCosmeticVertex(vert->getTagAsString()); + continue; + } + if (DU::getGeomTypeFromName(name) == "Edge") { + CosmeticEdge* edge = getViewObject()->getCosmeticEdgeBySelection(name); + // if not edge, something has gone very wrong! + getViewObject()->removeCosmeticEdge(edge->getTagAsString()); + continue; + } + } +} + App::Color ViewProviderViewPart::prefSectionColor() { return PreferencesGui::sectionLineColor(); diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewPart.h b/src/Mod/TechDraw/Gui/ViewProviderViewPart.h index 27dc8fa10b..bf1f5b3519 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewPart.h +++ b/src/Mod/TechDraw/Gui/ViewProviderViewPart.h @@ -78,6 +78,9 @@ public: std::vector claimChildren(void) const override; void fixSceneDependencies(); + std::vector getSelectedCosmetics(std::vector subNames); + void deleteCosmeticElements(std::vector removables); + TechDraw::DrawViewPart* getViewObject() const override; TechDraw::DrawViewPart* getViewPart() const; };