Skip to content

Commit

Permalink
Gui: Use bitmask instead of three booleans in setTemporaryVisibility …
Browse files Browse the repository at this point in the history
…to improve readability
  • Loading branch information
wwmayer committed Dec 31, 2024
1 parent 63088a2 commit cbd116b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/Gui/ViewProviderCoordinateSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<App::Origin>();

Expand All @@ -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));
}
}

Expand All @@ -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));
}
}

Expand All @@ -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) {
Expand Down
16 changes: 15 additions & 1 deletion src/Gui/ViewProviderCoordinateSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define GUI_VIEWPROVIDER_ViewProviderOrigin_H

#include <functional>
#include <Base/Bitmask.h>
#include <App/PropertyGeo.h>

#include "ViewProviderGeoFeatureGroup.h"
Expand All @@ -35,6 +36,17 @@ namespace Gui {
class Document;
class ViewProviderDatum;

enum class DatumElement

Check warning on line 39 in src/Gui/ViewProviderCoordinateSystem.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

enum 'DatumElement' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]
{
// clang-format off
Origin = 1 << 0,
Axes = 1 << 1,
Planes = 1 << 2
// clang-format on
};

using DatumElements = Base::Flags<DatumElement>;

class GuiExport ViewProviderCoordinateSystem : public ViewProviderGeoFeatureGroup

Check warning on line 50 in src/Gui/ViewProviderCoordinateSystem.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

class 'ViewProviderCoordinateSystem' defines a destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
{
PROPERTY_HEADER_WITH_OVERRIDE(Gui::ViewProviderCoordinateSystem);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -103,5 +115,7 @@ class GuiExport ViewProviderCoordinateSystem : public ViewProviderGeoFeatureGrou

} // namespace Gui

ENABLE_BITMASK_OPERATORS(Gui::DatumElement)

#endif // GUI_VIEWPROVIDER_ViewProviderOrigin_H

Check warning on line 120 in src/Gui/ViewProviderCoordinateSystem.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

#endif line should be "#endif // SRC_GUI_VIEWPROVIDERCOORDINATESYSTEM_H_" [build/header_guard] [5]

15 changes: 4 additions & 11 deletions src/Mod/PartDesign/Gui/TaskFeaturePick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,8 @@ TaskFeaturePick::TaskFeaturePick(std::vector<App::DocumentObject*>& objects,
ui->listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
}

enum
{
axisBit = 0,
planeBit = 1
};

// NOTE: generally there shouldn't be more then one origin
std::map<App::Origin*, std::bitset<2>> originVisStatus;
std::map<App::Origin*, Gui::DatumElements> originVisStatus;

auto statusIt = status.cbegin();
auto objIt = objects.begin();
Expand All @@ -144,10 +138,10 @@ TaskFeaturePick::TaskFeaturePick(std::vector<App::DocumentObject*>& objects,
App::Origin* origin = dynamic_cast<App::Origin*>(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);
}
}
}
Expand All @@ -160,8 +154,7 @@ TaskFeaturePick::TaskFeaturePick(std::vector<App::DocumentObject*>& objects,
Gui::ViewProviderCoordinateSystem* vpo = static_cast<Gui::ViewProviderCoordinateSystem*>(
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);
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/Gui/TaskHelixParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void TaskHelixParameters::showCoordinateAxes()
ViewProviderCoordinateSystem* vpOrigin;
vpOrigin = static_cast<ViewProviderCoordinateSystem*>(
Gui::Application::Instance->getViewProvider(origin));
vpOrigin->setTemporaryVisibility(true, false);
vpOrigin->setTemporaryVisibility(Gui::DatumElement::Axes);
}
catch (const Base::Exception& ex) {
ex.ReportException();
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void TaskLinearPatternParameters::setupParameterUI(QWidget* widget)
App::Origin* origin = body->getOrigin();
auto vpOrigin = static_cast<ViewProviderCoordinateSystem*>(
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());
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void TaskMirroredParameters::setupParameterUI(QWidget* widget)
App::Origin* origin = body->getOrigin();
auto vpOrigin = static_cast<ViewProviderCoordinateSystem*>(
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());
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void TaskPolarPatternParameters::setupParameterUI(QWidget* widget)
App::Origin* origin = body->getOrigin();
auto vpOrigin = static_cast<ViewProviderCoordinateSystem*>(
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());
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent)
App::Origin *origin = body->getOrigin();
Gui::ViewProviderCoordinateSystem* vpOrigin {};
vpOrigin = static_cast<Gui::ViewProviderCoordinateSystem*>(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 () );
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit cbd116b

Please sign in to comment.