Skip to content

Commit

Permalink
Gui: Use bitset instead of three booleans in setTemporaryVisibility t…
Browse files Browse the repository at this point in the history
…o improve readability
  • Loading branch information
wwmayer committed Dec 30, 2024
1 parent 63088a2 commit e7604e6
Show file tree
Hide file tree
Showing 9 changed files with 37 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(DatumVisibilityFlags flags)
{
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(flags.test(DatumVisibility::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(flags.test(DatumVisibility::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(flags.test(DatumVisibility::Origin));
}
}
catch (const Base::Exception &ex) {
Expand Down
11 changes: 10 additions & 1 deletion src/Gui/ViewProviderCoordinateSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
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::DatumVisibilityFlags> 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].set(Gui::DatumVisibility::Planes, true);
}
else if ((*objIt)->isDerivedFrom(App::Line::getClassTypeId())) {
originVisStatus[origin].set(axisBit, true);
originVisStatus[origin].set(Gui::DatumVisibility::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
4 changes: 3 additions & 1 deletion src/Mod/PartDesign/Gui/TaskHelixParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ void TaskHelixParameters::showCoordinateAxes()
ViewProviderCoordinateSystem* vpOrigin;
vpOrigin = static_cast<ViewProviderCoordinateSystem*>(
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();
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ void TaskLinearPatternParameters::setupParameterUI(QWidget* widget)
App::Origin* origin = body->getOrigin();
auto vpOrigin = static_cast<ViewProviderCoordinateSystem*>(
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());
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ void TaskMirroredParameters::setupParameterUI(QWidget* widget)
App::Origin* origin = body->getOrigin();
auto vpOrigin = static_cast<ViewProviderCoordinateSystem*>(
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());
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ void TaskPolarPatternParameters::setupParameterUI(QWidget* widget)
App::Origin* origin = body->getOrigin();
auto vpOrigin = static_cast<ViewProviderCoordinateSystem*>(
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());
Expand Down
5 changes: 4 additions & 1 deletion src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ 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);
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 () );
}
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e7604e6

Please sign in to comment.