diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index d43d1ca1a3..ce1a8d6799 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -318,19 +318,6 @@ ConfigOption* ConfigOptionDef::create_default_option() const return this->create_empty_option(); } -bool ConfigOptionDef::is_value_valid(const double value, const int max_precision /*= 4*/) const -{ - if (this->min == 0.f && value < 0) { // Special handling of 0 - return false; - } - - const double ep = std::pow(0.1, max_precision); - if (is_approx(value, (double) this->min, ep) || is_approx(value, (double) this->max, ep)) - return true; - - return this->min <= value && value <= this->max; -} - // Assignment of the serialization IDs is not thread safe. The Defs shall be initialized from the main thread! ConfigOptionDef* ConfigDef::add(const t_config_option_key &opt_key, ConfigOptionType type) { diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 1c7a2dcd67..f99b07c8d2 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -2456,11 +2455,10 @@ public: // Optional width of an input field. int width = -1; // limit of a numeric input. - // If not set, the is set to <-FLT_MAX, FLT_MAX> + // If not set, the is set to // By setting min=0, only nonnegative input is allowed. - float min = -FLT_MAX; - float max = FLT_MAX; - bool is_value_valid(double value, int max_precision = 4) const; + int min = INT_MIN; + int max = INT_MAX; // To check if it's not a typo and a % is missing double max_literal = 1; ConfigOptionMode mode = comSimple; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 290d89edc5..7549eb821d 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -2150,7 +2150,7 @@ void PrintConfigDef::init_fff_params() "\n\nThe final object flow ratio is this value multiplied by the filament flow ratio."); def->mode = comAdvanced; def->max = 2; - def->min = 0.01f; + def->min = 0.01; def->set_default_value(new ConfigOptionFloat(1)); def = this->add("enable_pressure_advance", coBools); @@ -3245,7 +3245,7 @@ void PrintConfigDef::init_fff_params() def->category = L("Others"); def->tooltip = L("The average distance between the random points introduced on each line segment."); def->sidetext = L("mm"); // milimeters, CIS languages need translation - def->min = 0.01f; // point distance cannot be 0! Otherwise we get infinite loop + OOM due to infinite line division. + def->min = 0; def->max = 5; def->mode = comSimple; def->set_default_value(new ConfigOptionFloat(0.3)); @@ -3308,7 +3308,7 @@ void PrintConfigDef::init_fff_params() def->category = L("Others"); def->tooltip = L("The base size of the coherent noise features, in mm. Higher values will result in larger features."); def->sidetext = L("mm"); // milimeters, CIS languages need translation - def->min = 0.1f; + def->min = 0.1; def->max = 500; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloat(1.0)); @@ -3326,7 +3326,7 @@ void PrintConfigDef::init_fff_params() def->label = L("Fuzzy skin noise persistence"); def->category = L("Others"); def->tooltip = L("The decay rate for higher octaves of the coherent noise. Lower values will result in smoother noise."); - def->min = 0.01f; + def->min = 0.01; def->max = 1; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloat(0.5)); @@ -9555,13 +9555,13 @@ std::map validate(const FullPrintConfig &cfg, bool und case coFloatOrPercent: { auto *fopt = static_cast(opt); - out_of_range = !optdef->is_value_valid(fopt->value); + out_of_range = fopt->value < optdef->min || fopt->value > optdef->max; break; } case coFloats: case coPercents: for (double v : static_cast*>(opt)->values) - if (!optdef->is_value_valid(v)) { + if (v < optdef->min || v > optdef->max) { out_of_range = true; break; } @@ -9569,12 +9569,12 @@ std::map validate(const FullPrintConfig &cfg, bool und case coInt: { auto *iopt = static_cast(opt); - out_of_range = !optdef->is_value_valid(iopt->value); + out_of_range = iopt->value < optdef->min || iopt->value > optdef->max; break; } case coInts: for (int v : static_cast*>(opt)->values) - if (!optdef->is_value_valid(v)) { + if (v < optdef->min || v > optdef->max) { out_of_range = true; break; } diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 0bd3874af5..55f754e91a 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -309,7 +309,7 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true show_error(m_parent, _(L("Invalid numeric."))); set_value(double_to_string(val), true); } - if (!m_opt.is_value_valid(val)) + if (m_opt.min > val || val > m_opt.max) { if (!check_value) { m_value.clear(); @@ -1107,8 +1107,8 @@ void SpinCtrl::BUILD() { break; } - const int min_val = m_opt.min == -FLT_MAX ? 0 : (int)m_opt.min; - const int max_val = m_opt.max < FLT_MAX ? (int)m_opt.max : INT_MAX; + const int min_val = m_opt.min == INT_MIN ? 0 : m_opt.min; + const int max_val = m_opt.max < 2147483647 ? m_opt.max : 2147483647; static Builder builder; auto temp = builder.build(m_parent, "", "", wxDefaultPosition, size, @@ -1164,7 +1164,7 @@ void SpinCtrl::BUILD() { if (!parsed || value < INT_MIN || value > INT_MAX) tmp_value = UNDEF_VALUE; else { - tmp_value = std::min(std::max((int)value, temp->GetMin()), temp->GetMax()); + tmp_value = std::min(std::max((int)value, m_opt.min), m_opt.max); #ifdef __WXOSX__ #ifdef UNDEFINED__WXOSX__ // BBS // Forcibly set the input value for SpinControl, since the value @@ -1217,7 +1217,7 @@ void SpinCtrl::set_value(const boost::any& value, bool change_event) { m_disable_change_event = !change_event; m_value = value; if (value.empty()) { // BBS: null value - dynamic_cast(window)->SetValue(dynamic_cast(window)->GetMin()); + dynamic_cast(window)->SetValue(m_opt.min); dynamic_cast(window)->GetTextCtrl()->SetValue(""); } else { @@ -2158,8 +2158,8 @@ boost::any& PointCtrl::get_value() show_error(m_parent, _L("Invalid numeric.")); } else - if (!m_opt.is_value_valid(x) || - !m_opt.is_value_valid(y)) + if (m_opt.min > x || x > m_opt.max || + m_opt.min > y || y > m_opt.max) { if (m_opt.min > x) x = m_opt.min; if (x > m_opt.max) x = m_opt.max; @@ -2218,8 +2218,8 @@ void SliderCtrl::BUILD() auto temp = new wxBoxSizer(wxHORIZONTAL); auto def_val = m_opt.get_default_value()->value; - auto min = m_opt.min == -FLT_MAX ? 0 : (int)m_opt.min; - auto max = m_opt.max == FLT_MAX ? 100 : INT_MAX; + auto min = m_opt.min == INT_MIN ? 0 : m_opt.min; + auto max = m_opt.max == INT_MAX ? 100 : m_opt.max; m_slider = new wxSlider(m_parent, wxID_ANY, def_val * m_scale, min * m_scale, max * m_scale, diff --git a/src/slic3r/GUI/Widgets/SpinInput.hpp b/src/slic3r/GUI/Widgets/SpinInput.hpp index 275d42a95d..030eb56942 100644 --- a/src/slic3r/GUI/Widgets/SpinInput.hpp +++ b/src/slic3r/GUI/Widgets/SpinInput.hpp @@ -78,9 +78,6 @@ public: void SetRange(int min, int max); - int GetMin() const { return this->min; } - int GetMax() const { return this->max; } - protected: void DoSetToolTipText(wxString const &tip) override;