PD: replace error-prone strings with enum to handle different helix modes
This commit is contained in:
@@ -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<HelixMode>(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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<HelixMode>(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;
|
||||
|
||||
Reference in New Issue
Block a user