From 2df88592ec952c1c3ab3a5a264e3013826240e9a Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 28 Mar 2021 13:37:13 +0200 Subject: [PATCH] PD: replace error-prone strings with enum to handle different helix modes --- src/Mod/PartDesign/App/FeatureHelix.cpp | 10 +++++----- src/Mod/PartDesign/App/FeatureHelix.h | 7 +++++++ src/Mod/PartDesign/Gui/TaskHelixParameters.cpp | 11 ++++++----- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureHelix.cpp b/src/Mod/PartDesign/App/FeatureHelix.cpp index aa51eeb12c..07a1825dfd 100644 --- a/src/Mod/PartDesign/App/FeatureHelix.cpp +++ b/src/Mod/PartDesign/App/FeatureHelix.cpp @@ -111,26 +111,26 @@ short Helix::mustExecute() const App::DocumentObjectExecReturn *Helix::execute(void) { // Validate and normalize parameters - std::string mode = Mode.getValueAsString(); - if (mode == "pitch-height-angle") { + HelixMode mode = static_cast(Mode.getValue()); + if (mode == HelixMode::pitch_height_angle) { if (Pitch.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Error: Pitch too small"); if (Height.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Error: height too small!"); Turns.setValue(Height.getValue()/Pitch.getValue()); - } else if (mode == "pitch-turns-angle") { + } else if (mode == HelixMode::pitch_turns_angle) { if (Pitch.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Error: pitch too small!"); if (Turns.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Error: turns too small!"); Height.setValue(Turns.getValue()*Pitch.getValue()); - } else if (mode == "height-turns-angle") { + } else if (mode == HelixMode::height_turns_angle) { if (Height.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Error: height too small!"); if (Turns.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Error turns too small!"); Pitch.setValue(Height.getValue()/Turns.getValue()); - } else if (mode == "height-turns-growth") { + } else if (mode == HelixMode::height_turns_growth) { if (Turns.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Error turns too small!"); Pitch.setValue(Height.getValue()/Turns.getValue()); diff --git a/src/Mod/PartDesign/App/FeatureHelix.h b/src/Mod/PartDesign/App/FeatureHelix.h index 194eb22b82..0f12c3ac67 100644 --- a/src/Mod/PartDesign/App/FeatureHelix.h +++ b/src/Mod/PartDesign/App/FeatureHelix.h @@ -31,6 +31,13 @@ namespace PartDesign { +enum class HelixMode { + pitch_height_angle, + pitch_turns_angle, + height_turns_angle, + height_turns_growth +}; + class PartDesignExport Helix : public ProfileBased { PROPERTY_HEADER(PartDesign::Helix); diff --git a/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp b/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp index 03f89adf03..eeb1e6bb83 100644 --- a/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp @@ -55,6 +55,7 @@ #include "TaskHelixParameters.h" using namespace PartDesignGui; +using PartDesign::HelixMode; using namespace Gui; @@ -287,20 +288,20 @@ void TaskHelixParameters::updateUI() if(pcHelix->getAddSubType() == PartDesign::FeatureAddSub::Subtractive) isOutsideVisible = true; - std::string mode = propMode->getValueAsString(); - if (mode == "pitch-height-angle") { + HelixMode mode = static_cast(propMode->getValue()); + if (mode == HelixMode::pitch_height_angle) { isPitchVisible = true; isHeightVisible = true; isAngleVisible = true; - } else if (mode == "pitch-turns-angle") { + } else if (mode == HelixMode::pitch_turns_angle) { isPitchVisible = true; isTurnsVisible = true; isAngleVisible = true; - } else if (mode == "height-turns-angle") { + } else if (mode == HelixMode::height_turns_angle) { isHeightVisible = true; isTurnsVisible = true; isAngleVisible = true; - } else if (mode == "height-turns-growth") { + } else if (mode == HelixMode::height_turns_growth) { isHeightVisible = true; isTurnsVisible = true; isGrowthVisible = true;