From 8d4ddac85e081c59062b9784a02abc6a64a3e93f Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 30 Dec 2024 18:42:50 +0100 Subject: [PATCH] Gui: Reduce code duplication in ViewProviderCoordinateSystem --- src/Gui/ViewProviderCoordinateSystem.cpp | 25 ++++++++++++------------ src/Gui/ViewProviderCoordinateSystem.h | 7 +++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Gui/ViewProviderCoordinateSystem.cpp b/src/Gui/ViewProviderCoordinateSystem.cpp index 2d57a94c8e..1d3fb7eaf1 100644 --- a/src/Gui/ViewProviderCoordinateSystem.cpp +++ b/src/Gui/ViewProviderCoordinateSystem.cpp @@ -183,30 +183,31 @@ void ViewProviderCoordinateSystem::setPlaneLabelVisibility(bool val) } -void ViewProviderCoordinateSystem::setTemporaryScale(double factor) +void ViewProviderCoordinateSystem::applyDatumObjects(const DatumObjectFunc& func) { auto lcs = getObject(); - auto& objs = lcs->OriginFeatures.getValues(); + const auto& objs = lcs->OriginFeatures.getValues(); for (auto* obj : objs) { auto* vp = dynamic_cast( Gui::Application::Instance->getViewProvider(obj)); if (vp) { - vp->setTemporaryScale(factor); + func(vp); } } } +void ViewProviderCoordinateSystem::setTemporaryScale(double factor) +{ + applyDatumObjects([factor](ViewProviderDatum* vp) { + vp->setTemporaryScale(factor); + }); +} + void ViewProviderCoordinateSystem::resetTemporarySize() { - auto lcs = getObject(); - auto& objs = lcs->OriginFeatures.getValues(); - for (auto* obj : objs) { - auto* vp = dynamic_cast( - Gui::Application::Instance->getViewProvider(obj)); - if (vp) { - vp->resetTemporarySize(); - } - } + applyDatumObjects([](ViewProviderDatum* vp) { + vp->resetTemporarySize(); + }); } void ViewProviderCoordinateSystem::updateData(const App::Property* prop) { diff --git a/src/Gui/ViewProviderCoordinateSystem.h b/src/Gui/ViewProviderCoordinateSystem.h index 1f812a5a66..d8177b0869 100644 --- a/src/Gui/ViewProviderCoordinateSystem.h +++ b/src/Gui/ViewProviderCoordinateSystem.h @@ -24,6 +24,7 @@ #ifndef GUI_VIEWPROVIDER_ViewProviderOrigin_H #define GUI_VIEWPROVIDER_ViewProviderOrigin_H +#include #include #include "ViewProviderGeoFeatureGroup.h" @@ -32,6 +33,7 @@ namespace Gui { class Document; +class ViewProviderDatum; class GuiExport ViewProviderCoordinateSystem : public ViewProviderGeoFeatureGroup { @@ -84,10 +86,15 @@ public: // default color for origini: light-blue (50, 150, 250, 255 stored as 0xRRGGBBAA) static const uint32_t defaultColor = 0x3296faff; + protected: void updateData(const App::Property*) override; bool onDelete(const std::vector &) override; +private: + using DatumObjectFunc = std::function; + void applyDatumObjects(const DatumObjectFunc& func); + private: SoGroup *pcGroupChildren;