+ Fixed get_config_value for coFloatOrPercent (percent mode allow non-just-int values)
This commit is contained in:
YuSanka 2019-09-02 14:02:26 +02:00
parent 107bb1a308
commit 94712544aa
3 changed files with 14 additions and 15 deletions

View file

@ -138,7 +138,7 @@ bool Field::is_matched(const std::string& string, const std::string& pattern)
static wxString na_value() { return _(L("N/A")); } static wxString na_value() { return _(L("N/A")); }
void Field::get_value_by_opt_type(wxString& str) void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true*/)
{ {
switch (m_opt.type) { switch (m_opt.type) {
case coInt: case coInt:
@ -150,7 +150,7 @@ void Field::get_value_by_opt_type(wxString& str)
case coFloat:{ case coFloat:{
if (m_opt.type == coPercent && !str.IsEmpty() && str.Last() == '%') if (m_opt.type == coPercent && !str.IsEmpty() && str.Last() == '%')
str.RemoveLast(); str.RemoveLast();
else if (!str.IsEmpty() && str.Last() == '%') { else if (check_value && !str.IsEmpty() && str.Last() == '%') {
wxString label = m_Label->GetLabel(); wxString label = m_Label->GetLabel();
if (label.Last() == '\n') label.RemoveLast(); if (label.Last() == '\n') label.RemoveLast();
while (label.Last() == ' ') label.RemoveLast(); while (label.Last() == ' ') label.RemoveLast();
@ -169,12 +169,12 @@ void Field::get_value_by_opt_type(wxString& str)
{ {
if (m_opt.nullable && str == na_value()) if (m_opt.nullable && str == na_value())
val = ConfigOptionFloatsNullable::nil_value(); val = ConfigOptionFloatsNullable::nil_value();
else if (!str.ToCDouble(&val)) else if (check_value && !str.ToCDouble(&val))
{ {
show_error(m_parent, _(L("Invalid numeric input."))); show_error(m_parent, _(L("Invalid numeric input.")));
set_value(double_to_string(val), true); set_value(double_to_string(val), true);
} }
if (m_opt.min > val || val > m_opt.max) if (check_value && (m_opt.min > val || val > m_opt.max))
{ {
show_error(m_parent, _(L("Input value is out of range"))); show_error(m_parent, _(L("Input value is out of range")));
if (m_opt.min > val) val = m_opt.min; if (m_opt.min > val) val = m_opt.min;
@ -192,12 +192,12 @@ void Field::get_value_by_opt_type(wxString& str)
double val; double val;
// Replace the first occurence of comma in decimal number. // Replace the first occurence of comma in decimal number.
str.Replace(",", ".", false); str.Replace(",", ".", false);
if (!str.ToCDouble(&val)) if (check_value && !str.ToCDouble(&val))
{ {
show_error(m_parent, _(L("Invalid numeric input."))); show_error(m_parent, _(L("Invalid numeric input.")));
set_value(double_to_string(val), true); set_value(double_to_string(val), true);
} }
else if ((m_opt.sidetext.rfind("mm/s") != std::string::npos && val > m_opt.max || else if (check_value && (m_opt.sidetext.rfind("mm/s") != std::string::npos && val > m_opt.max ||
m_opt.sidetext.rfind("mm ") != std::string::npos && val > 1) && m_opt.sidetext.rfind("mm ") != std::string::npos && val > 1) &&
(m_value.empty() || std::string(str.ToUTF8().data()) != boost::any_cast<std::string>(m_value))) (m_value.empty() || std::string(str.ToUTF8().data()) != boost::any_cast<std::string>(m_value)))
{ {
@ -206,7 +206,7 @@ void Field::get_value_by_opt_type(wxString& str)
const wxString msg_text = wxString::Format(_(L("Do you mean %s%% instead of %s %s?\n" const wxString msg_text = wxString::Format(_(L("Do you mean %s%% instead of %s %s?\n"
"Select YES if you want to change this value to %s%%, \n" "Select YES if you want to change this value to %s%%, \n"
"or NO if you are sure that %s %s is a correct value.")), stVal, stVal, sidetext, stVal, stVal, sidetext); "or NO if you are sure that %s %s is a correct value.")), stVal, stVal, sidetext, stVal, stVal, sidetext);
wxMessageDialog dialog(m_parent, msg_text, _(L("Parameter validation")), wxICON_WARNING | wxYES | wxNO); wxMessageDialog dialog(m_parent, msg_text, _(L("Parameter validation")) + ": " + m_opt_id , wxICON_WARNING | wxYES | wxNO);
if (dialog.ShowModal() == wxID_YES) { if (dialog.ShowModal() == wxID_YES) {
set_value(wxString::Format("%s%%", stVal), false/*true*/); set_value(wxString::Format("%s%%", stVal), false/*true*/);
str += "%%"; str += "%%";
@ -396,8 +396,9 @@ void TextCtrl::set_value(const boost::any& value, bool change_event/* = false*/)
if (!change_event) { if (!change_event) {
wxString ret_str = static_cast<wxTextCtrl*>(window)->GetValue(); wxString ret_str = static_cast<wxTextCtrl*>(window)->GetValue();
// update m_value to correct work of next value_was_changed() // update m_value to correct work of next value_was_changed(),
get_value_by_opt_type(ret_str); // but don't check/change inputed value and don't show a warning message
get_value_by_opt_type(ret_str, false);
} }
} }

View file

@ -152,7 +152,7 @@ public:
virtual wxWindow* getWindow() { return nullptr; } virtual wxWindow* getWindow() { return nullptr; }
bool is_matched(const std::string& string, const std::string& pattern); bool is_matched(const std::string& string, const std::string& pattern);
void get_value_by_opt_type(wxString& str); void get_value_by_opt_type(wxString& str, const bool check_value = true);
/// Factory method for generating new derived classes. /// Factory method for generating new derived classes.
template<class T> template<class T>

View file

@ -589,13 +589,11 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config
switch (opt->type) { switch (opt->type) {
case coFloatOrPercent:{ case coFloatOrPercent:{
const auto &value = *config.option<ConfigOptionFloatOrPercent>(opt_key); const auto &value = *config.option<ConfigOptionFloatOrPercent>(opt_key);
if (value.percent)
{
text_value = wxString::Format(_T("%i"), int(value.value));
text_value += "%";
}
else
text_value = double_to_string(value.value); text_value = double_to_string(value.value);
if (value.percent)
text_value += "%";
ret = text_value; ret = text_value;
break; break;
} }