From e7604e638304abb46a85fbe98d0b54ce98d3b45e Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 31 Dec 2024 00:08:38 +0100 Subject: [PATCH] Gui: Use bitset instead of three booleans in setTemporaryVisibility to improve readability --- src/Gui/ViewProviderCoordinateSystem.cpp | 8 ++++---- src/Gui/ViewProviderCoordinateSystem.h | 11 ++++++++++- src/Mod/PartDesign/Gui/TaskFeaturePick.cpp | 15 ++++----------- src/Mod/PartDesign/Gui/TaskHelixParameters.cpp | 4 +++- .../Gui/TaskLinearPatternParameters.cpp | 4 +++- src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp | 4 +++- .../PartDesign/Gui/TaskPolarPatternParameters.cpp | 4 +++- .../PartDesign/Gui/TaskPrimitiveParameters.cpp | 5 ++++- .../PartDesign/Gui/TaskRevolutionParameters.cpp | 4 +++- 9 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/Gui/ViewProviderCoordinateSystem.cpp b/src/Gui/ViewProviderCoordinateSystem.cpp index 8333b1e76e5f8..57291566537a3 100644 --- a/src/Gui/ViewProviderCoordinateSystem.cpp +++ b/src/Gui/ViewProviderCoordinateSystem.cpp @@ -97,7 +97,7 @@ void ViewProviderCoordinateSystem::setDisplayMode(const char* ModeName) ViewProviderDocumentObject::setDisplayMode(ModeName); } -void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane, bool points) +void ViewProviderCoordinateSystem::setTemporaryVisibility(DatumVisibilityFlags flags) { auto origin = getObject(); @@ -110,7 +110,7 @@ void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane, if (saveState) { tempVisMap[vp] = vp->isVisible(); } - vp->setVisible(axis); + vp->setVisible(flags.test(DatumVisibility::Axes)); } } @@ -120,7 +120,7 @@ void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane, if (saveState) { tempVisMap[vp] = vp->isVisible(); } - vp->setVisible(plane); + vp->setVisible(flags.test(DatumVisibility::Planes)); } } @@ -130,7 +130,7 @@ void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane, if (saveState) { tempVisMap[vp] = vp->isVisible(); } - vp->setVisible(points); + vp->setVisible(flags.test(DatumVisibility::Origin)); } } catch (const Base::Exception &ex) { diff --git a/src/Gui/ViewProviderCoordinateSystem.h b/src/Gui/ViewProviderCoordinateSystem.h index d8177b0869ba3..ffe470766a87d 100644 --- a/src/Gui/ViewProviderCoordinateSystem.h +++ b/src/Gui/ViewProviderCoordinateSystem.h @@ -35,6 +35,15 @@ namespace Gui { class Document; class ViewProviderDatum; +enum DatumVisibility +{ + Origin = 0, + Axes = 1, + Planes = 2 +}; + +using DatumVisibilityFlags = std::bitset<3>; + class GuiExport ViewProviderCoordinateSystem : public ViewProviderGeoFeatureGroup { PROPERTY_HEADER_WITH_OVERRIDE(Gui::ViewProviderCoordinateSystem); @@ -62,7 +71,7 @@ class GuiExport ViewProviderCoordinateSystem : public ViewProviderGeoFeatureGrou */ ///@{ /// Set temporary visibility of some of origin's objects e.g. while rotating or mirroring - void setTemporaryVisibility (bool axis, bool planes, bool points = false); + void setTemporaryVisibility (DatumVisibilityFlags flags); /// Returns true if the origin in temporary visibility mode bool isTemporaryVisibility (); /// Reset the visibility diff --git a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp index 2a039750c7fe9..89a38190caa28 100644 --- a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp @@ -110,14 +110,8 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, ui->listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); } - enum - { - axisBit = 0, - planeBit = 1 - }; - // NOTE: generally there shouldn't be more then one origin - std::map> originVisStatus; + std::map originVisStatus; auto statusIt = status.cbegin(); auto objIt = objects.begin(); @@ -144,10 +138,10 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, App::Origin* origin = dynamic_cast(datum->getLCS()); if (origin) { if ((*objIt)->isDerivedFrom(App::Plane::getClassTypeId())) { - originVisStatus[origin].set(planeBit, true); + originVisStatus[origin].set(Gui::DatumVisibility::Planes, true); } else if ((*objIt)->isDerivedFrom(App::Line::getClassTypeId())) { - originVisStatus[origin].set(axisBit, true); + originVisStatus[origin].set(Gui::DatumVisibility::Axes, true); } } } @@ -160,8 +154,7 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, Gui::ViewProviderCoordinateSystem* vpo = static_cast( Gui::Application::Instance->getViewProvider(origin)); if (vpo) { - vpo->setTemporaryVisibility(originVisStatus[origin][axisBit], - originVisStatus[origin][planeBit]); + vpo->setTemporaryVisibility(originVisStatus[origin]); vpo->setTemporaryScale(4.0); // NOLINT vpo->setPlaneLabelVisibility(true); origins.push_back(vpo); diff --git a/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp b/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp index e1b4b9aa2bf79..ae597c206927d 100644 --- a/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp @@ -174,7 +174,9 @@ void TaskHelixParameters::showCoordinateAxes() ViewProviderCoordinateSystem* vpOrigin; vpOrigin = static_cast( Gui::Application::Instance->getViewProvider(origin)); - vpOrigin->setTemporaryVisibility(true, false); + Gui::DatumVisibilityFlags flags; + flags.set(Gui::DatumVisibility::Axes); + vpOrigin->setTemporaryVisibility(flags); } catch (const Base::Exception& ex) { ex.ReportException(); diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp index de62a2b1cdad9..036fc4a3aa9fe 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp @@ -111,7 +111,9 @@ void TaskLinearPatternParameters::setupParameterUI(QWidget* widget) App::Origin* origin = body->getOrigin(); auto vpOrigin = static_cast( Gui::Application::Instance->getViewProvider(origin)); - vpOrigin->setTemporaryVisibility(true, false); + Gui::DatumVisibilityFlags flags; + flags.set(Gui::DatumVisibility::Axes); + vpOrigin->setTemporaryVisibility(flags); } catch (const Base::Exception& ex) { Base::Console().Error("%s\n", ex.what()); diff --git a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp index d8cb8a5fb5ae3..0dee58056e51b 100644 --- a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp @@ -92,7 +92,9 @@ void TaskMirroredParameters::setupParameterUI(QWidget* widget) App::Origin* origin = body->getOrigin(); auto vpOrigin = static_cast( Gui::Application::Instance->getViewProvider(origin)); - vpOrigin->setTemporaryVisibility(false, true); + Gui::DatumVisibilityFlags flags; + flags.set(Gui::DatumVisibility::Planes); + vpOrigin->setTemporaryVisibility(flags); } catch (const Base::Exception& ex) { Base::Console().Error("%s\n", ex.what()); diff --git a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp index 8f55d949909eb..c75934fed8819 100644 --- a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp @@ -113,7 +113,9 @@ void TaskPolarPatternParameters::setupParameterUI(QWidget* widget) App::Origin* origin = body->getOrigin(); auto vpOrigin = static_cast( Gui::Application::Instance->getViewProvider(origin)); - vpOrigin->setTemporaryVisibility(true, false); + Gui::DatumVisibilityFlags flags; + flags.set(Gui::DatumVisibility::Axes); + vpOrigin->setTemporaryVisibility(flags); } catch (const Base::Exception& ex) { Base::Console().Error("%s\n", ex.what()); diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp index db6ac08739778..cd20a4d48d6c4 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp @@ -262,7 +262,10 @@ TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent) App::Origin *origin = body->getOrigin(); Gui::ViewProviderCoordinateSystem* vpOrigin {}; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); - vpOrigin->setTemporaryVisibility(true, true); + Gui::DatumVisibilityFlags flags; + flags.set(Gui::DatumVisibility::Planes); + flags.set(Gui::DatumVisibility::Axes); + vpOrigin->setTemporaryVisibility(flags); } catch (const Base::Exception &ex) { Base::Console().Error ("%s\n", ex.what () ); } diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index 2ba59e549bed6..d578d7c4510d6 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -100,7 +100,9 @@ TaskRevolutionParameters::TaskRevolutionParameters(PartDesignGui::ViewProvider* // show the parts coordinate system axis for selection try { if (auto vpOrigin = getOriginView()) { - vpOrigin->setTemporaryVisibility(true, false); + Gui::DatumVisibilityFlags flags; + flags.set(Gui::DatumVisibility::Axes); + vpOrigin->setTemporaryVisibility(flags); } } catch (const Base::Exception &ex) {