From 754bfd926b46924df2e1c56adb945c12ba900f02 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 10 May 2018 11:10:44 +0200 Subject: [PATCH] Auto-correction of the input values according to the admissible range --- xs/src/libslic3r/PrintConfig.cpp | 3 ++- xs/src/slic3r/GUI/Field.cpp | 25 ++++++++++++++++++------- xs/src/slic3r/GUI/Field.hpp | 1 - 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index f70a42182..697a6f0d4 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -111,7 +111,8 @@ PrintConfigDef::PrintConfigDef() "with cooling (use a fan) before tweaking this."); def->cli = "bridge-flow-ratio=f"; def->min = 0; - def->default_value = new ConfigOptionFloat(1); + def->max = 2; + def->default_value = new ConfigOptionFloat(1); def = this->add("bridge_speed", coFloat); def->label = L("Bridges"); diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 5cae9172e..a5a14d368 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -82,10 +82,8 @@ namespace Slic3r { namespace GUI { return std::regex_match(string, regex_pattern); } -// boost::any Field::get_value_by_opt_type(wxString& str) void Field::get_value_by_opt_type(wxString& str) { -// boost::any m_value; switch (m_opt.type){ case coInt: m_value = wxAtoi(str); @@ -96,9 +94,24 @@ namespace Slic3r { namespace GUI { case coFloat:{ if (m_opt.type == coPercent && str.Last() == '%') str.RemoveLast(); + else if (str.Last() == '%') { + show_error(m_parent, _(L("Current option doesn't support percentage"))); + set_value(double_to_string(m_opt.min), true); + m_value = double(m_opt.min); + break; + } double val; str.ToCDouble(&val); - m_value = val; + if (m_opt.min <= val && val <= m_opt.max) + m_value = val; + else + { + show_error(m_parent, _(L("Input value is out of range"))); + if (m_opt.min > val) val = m_opt.min; + if (val > m_opt.max) val = m_opt.max; + set_value(double_to_string(val), true); + m_value = val; + } break; } case coString: case coStrings: @@ -108,8 +121,6 @@ namespace Slic3r { namespace GUI { default: break; } - -// return m_value; } void TextCtrl::BUILD() { @@ -188,9 +199,9 @@ namespace Slic3r { namespace GUI { boost::any& TextCtrl::get_value() { wxString ret_str = static_cast(window)->GetValue(); - /*boost::any ret_val*/get_value_by_opt_type(ret_str); + get_value_by_opt_type(ret_str); - return m_value;//ret_val; + return m_value; } void TextCtrl::enable() { dynamic_cast(window)->Enable(); dynamic_cast(window)->SetEditable(true); } diff --git a/xs/src/slic3r/GUI/Field.hpp b/xs/src/slic3r/GUI/Field.hpp index 729f73d16..7e421244b 100644 --- a/xs/src/slic3r/GUI/Field.hpp +++ b/xs/src/slic3r/GUI/Field.hpp @@ -124,7 +124,6 @@ public: virtual wxWindow* getWindow() { return nullptr; } bool is_matched(const std::string& string, const std::string& pattern); -// boost::any get_value_by_opt_type(wxString& str); void get_value_by_opt_type(wxString& str); /// Factory method for generating new derived classes.