From cbd116b4517c8cc0faed92b998dd3f29f1f4e8a2 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 31 Dec 2024 13:29:01 +0100 Subject: [PATCH] Gui: Use bitmask instead of three booleans in setTemporaryVisibility to improve readability --- src/Gui/ViewProviderCoordinateSystem.cpp | 8 ++++---- src/Gui/ViewProviderCoordinateSystem.h | 16 +++++++++++++++- src/Mod/PartDesign/Gui/TaskFeaturePick.cpp | 15 ++++----------- src/Mod/PartDesign/Gui/TaskHelixParameters.cpp | 2 +- .../Gui/TaskLinearPatternParameters.cpp | 2 +- .../PartDesign/Gui/TaskMirroredParameters.cpp | 2 +- .../Gui/TaskPolarPatternParameters.cpp | 2 +- .../PartDesign/Gui/TaskPrimitiveParameters.cpp | 2 +- .../PartDesign/Gui/TaskRevolutionParameters.cpp | 2 +- 9 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/Gui/ViewProviderCoordinateSystem.cpp b/src/Gui/ViewProviderCoordinateSystem.cpp index 8333b1e76e5f..32d1465ec1fe 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(DatumElements elements) { 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(elements.testFlag(DatumElement::Axes)); } } @@ -120,7 +120,7 @@ void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane, if (saveState) { tempVisMap[vp] = vp->isVisible(); } - vp->setVisible(plane); + vp->setVisible(elements.testFlag(DatumElement::Planes)); } } @@ -130,7 +130,7 @@ void ViewProviderCoordinateSystem::setTemporaryVisibility(bool axis, bool plane, if (saveState) { tempVisMap[vp] = vp->isVisible(); } - vp->setVisible(points); + vp->setVisible(elements.testFlag(DatumElement::Origin)); } } catch (const Base::Exception &ex) { diff --git a/src/Gui/ViewProviderCoordinateSystem.h b/src/Gui/ViewProviderCoordinateSystem.h index d8177b0869ba..f18859fdd4e9 100644 --- a/src/Gui/ViewProviderCoordinateSystem.h +++ b/src/Gui/ViewProviderCoordinateSystem.h @@ -25,6 +25,7 @@ #define GUI_VIEWPROVIDER_ViewProviderOrigin_H #include +#include #include #include "ViewProviderGeoFeatureGroup.h" @@ -35,6 +36,17 @@ namespace Gui { class Document; class ViewProviderDatum; +enum class DatumElement +{ + // clang-format off + Origin = 1 << 0, + Axes = 1 << 1, + Planes = 1 << 2 + // clang-format on +}; + +using DatumElements = Base::Flags; + class GuiExport ViewProviderCoordinateSystem : public ViewProviderGeoFeatureGroup { PROPERTY_HEADER_WITH_OVERRIDE(Gui::ViewProviderCoordinateSystem); @@ -62,7 +74,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 (DatumElements elements); /// Returns true if the origin in temporary visibility mode bool isTemporaryVisibility (); /// Reset the visibility @@ -103,5 +115,7 @@ class GuiExport ViewProviderCoordinateSystem : public ViewProviderGeoFeatureGrou } // namespace Gui +ENABLE_BITMASK_OPERATORS(Gui::DatumElement) + #endif // GUI_VIEWPROVIDER_ViewProviderOrigin_H diff --git a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp index 2a039750c7fe..022898cfdd6e 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].setFlag(Gui::DatumElement::Planes, true); } else if ((*objIt)->isDerivedFrom(App::Line::getClassTypeId())) { - originVisStatus[origin].set(axisBit, true); + originVisStatus[origin].setFlag(Gui::DatumElement::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 e1b4b9aa2bf7..9d87827b1328 100644 --- a/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp @@ -174,7 +174,7 @@ void TaskHelixParameters::showCoordinateAxes() ViewProviderCoordinateSystem* vpOrigin; vpOrigin = static_cast( Gui::Application::Instance->getViewProvider(origin)); - vpOrigin->setTemporaryVisibility(true, false); + vpOrigin->setTemporaryVisibility(Gui::DatumElement::Axes); } catch (const Base::Exception& ex) { ex.ReportException(); diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp index de62a2b1cdad..13b7fffc1cbb 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp @@ -111,7 +111,7 @@ void TaskLinearPatternParameters::setupParameterUI(QWidget* widget) App::Origin* origin = body->getOrigin(); auto vpOrigin = static_cast( Gui::Application::Instance->getViewProvider(origin)); - vpOrigin->setTemporaryVisibility(true, false); + vpOrigin->setTemporaryVisibility(Gui::DatumElement::Axes); } 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 d8cb8a5fb5ae..91bf0916979e 100644 --- a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp @@ -92,7 +92,7 @@ void TaskMirroredParameters::setupParameterUI(QWidget* widget) App::Origin* origin = body->getOrigin(); auto vpOrigin = static_cast( Gui::Application::Instance->getViewProvider(origin)); - vpOrigin->setTemporaryVisibility(false, true); + vpOrigin->setTemporaryVisibility(Gui::DatumElement::Planes); } 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 8f55d949909e..61eb9dc36841 100644 --- a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp @@ -113,7 +113,7 @@ void TaskPolarPatternParameters::setupParameterUI(QWidget* widget) App::Origin* origin = body->getOrigin(); auto vpOrigin = static_cast( Gui::Application::Instance->getViewProvider(origin)); - vpOrigin->setTemporaryVisibility(true, false); + vpOrigin->setTemporaryVisibility(Gui::DatumElement::Axes); } 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 db6ac0873977..539ed471289e 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp @@ -262,7 +262,7 @@ 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); + vpOrigin->setTemporaryVisibility(Gui::DatumElement::Planes | Gui::DatumElement::Axes); } 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 2ba59e549bed..316abc9fb261 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -100,7 +100,7 @@ TaskRevolutionParameters::TaskRevolutionParameters(PartDesignGui::ViewProvider* // show the parts coordinate system axis for selection try { if (auto vpOrigin = getOriginView()) { - vpOrigin->setTemporaryVisibility(true, false); + vpOrigin->setTemporaryVisibility(Gui::DatumElement::Axes); } } catch (const Base::Exception &ex) {