diff options
author | YuSanka <yusanka@gmail.com> | 2019-07-31 14:05:47 +0300 |
---|---|---|
committer | YuSanka <yusanka@gmail.com> | 2019-07-31 14:05:47 +0300 |
commit | 3bade450b8a4d1189138bb3cbed325a479fe6b94 (patch) | |
tree | ce2cbe63accbf59226ec785790e83130b640504a /src/slic3r/GUI/Field.cpp | |
parent | aeb29b11849e2e3e9a0282c289a9a7d165bfdbc8 (diff) | |
parent | 7c2e199472524c40bbd3f50650c2a0c7345bd4dd (diff) |
Merge remote-tracking branch 'origin/ys_overrides'
Diffstat (limited to 'src/slic3r/GUI/Field.cpp')
-rw-r--r-- | src/slic3r/GUI/Field.cpp | 123 |
1 files changed, 102 insertions, 21 deletions
diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index db935cc05..39fa9c54b 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -136,6 +136,8 @@ bool Field::is_matched(const std::string& string, const std::string& pattern) return std::regex_match(string, regex_pattern); } +static wxString na_value() { return _(L("N/A")); } + void Field::get_value_by_opt_type(wxString& str) { switch (m_opt.type) { @@ -165,7 +167,9 @@ void Field::get_value_by_opt_type(wxString& str) val = 0.0; else { - if (!str.ToCDouble(&val)) + if (m_opt.nullable && str == na_value()) + val = ConfigOptionFloatsNullable::nil_value(); + else if (!str.ToCDouble(&val)) { show_error(m_parent, _(L("Invalid numeric input."))); set_value(double_to_string(val), true); @@ -256,6 +260,7 @@ void TextCtrl::BUILD() { m_opt.default_value->getFloat() : m_opt.get_default_value<ConfigOptionPercents>()->get_at(m_opt_idx); text_value = double_to_string(val); + m_last_meaningful_value = text_value; break; } case coString: @@ -325,24 +330,7 @@ void TextCtrl::BUILD() { } propagate_value(); }), temp->GetId()); - /* - temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent& evt) - { -#ifdef __WXGTK__ - if (bChangedValueEvent) -#endif //__WXGTK__ - if(is_defined_input_value()) - on_change_field(); - }), temp->GetId()); -#ifdef __WXGTK__ - // to correct value updating on GTK we should: - // call on_change_field() on wxEVT_KEY_UP instead of wxEVT_TEXT - // and prevent value updating on wxEVT_KEY_DOWN - temp->Bind(wxEVT_KEY_DOWN, &TextCtrl::change_field_value, this); - temp->Bind(wxEVT_KEY_UP, &TextCtrl::change_field_value, this); -#endif //__WXGTK__ -*/ // select all text using Ctrl+A temp->Bind(wxEVT_CHAR, ([temp](wxKeyEvent& event) { @@ -355,14 +343,70 @@ void TextCtrl::BUILD() { window = dynamic_cast<wxWindow*>(temp); } +bool TextCtrl::value_was_changed() +{ + if (m_value.empty()) + return true; + + boost::any val = m_value; + wxString ret_str = static_cast<wxTextCtrl*>(window)->GetValue(); + // update m_value! + get_value_by_opt_type(ret_str); + + switch (m_opt.type) { + case coInt: + return boost::any_cast<int>(m_value) != boost::any_cast<int>(val); + case coPercent: + case coPercents: + case coFloats: + case coFloat: { + if (m_opt.nullable && std::isnan(boost::any_cast<double>(m_value)) && + std::isnan(boost::any_cast<double>(val))) + return false; + return boost::any_cast<double>(m_value) != boost::any_cast<double>(val); + } + case coString: + case coStrings: + case coFloatOrPercent: + return boost::any_cast<std::string>(m_value) != boost::any_cast<std::string>(val); + default: + return true; + } +} + void TextCtrl::propagate_value() { - if (is_defined_input_value<wxTextCtrl>(window, m_opt.type)) + if (is_defined_input_value<wxTextCtrl>(window, m_opt.type) && value_was_changed()) on_change_field(); else on_kill_focus(); } +void TextCtrl::set_value(const boost::any& value, bool change_event/* = false*/) { + m_disable_change_event = !change_event; + if (m_opt.nullable) { + const bool m_is_na_val = boost::any_cast<wxString>(value) == na_value(); + if (!m_is_na_val) + m_last_meaningful_value = value; + dynamic_cast<wxTextCtrl*>(window)->SetValue(m_is_na_val ? na_value() : boost::any_cast<wxString>(value)); + } + else + dynamic_cast<wxTextCtrl*>(window)->SetValue(boost::any_cast<wxString>(value)); + m_disable_change_event = false; +} + +void TextCtrl::set_last_meaningful_value() +{ + dynamic_cast<wxTextCtrl*>(window)->SetValue(boost::any_cast<wxString>(m_last_meaningful_value)); + propagate_value(); +} + +void TextCtrl::set_na_value() +{ + dynamic_cast<wxTextCtrl*>(window)->SetValue(na_value()); + propagate_value(); +} + boost::any& TextCtrl::get_value() { wxString ret_str = static_cast<wxTextCtrl*>(window)->GetValue(); @@ -409,6 +453,8 @@ void CheckBox::BUILD() { m_opt.get_default_value<ConfigOptionBools>()->get_at(m_opt_idx) : false; + m_last_meaningful_value = static_cast<unsigned char>(check_value); + // Set Label as a string of at least one space simbol to correct system scaling of a CheckBox auto temp = new wxCheckBox(m_parent, wxID_ANY, wxString(" "), wxDefaultPosition, size); temp->SetFont(Slic3r::GUI::wxGetApp().normal_font()); @@ -416,7 +462,10 @@ void CheckBox::BUILD() { temp->SetValue(check_value); if (m_opt.readonly) temp->Disable(); - temp->Bind(wxEVT_CHECKBOX, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId()); + temp->Bind(wxEVT_CHECKBOX, ([this](wxCommandEvent e) { + m_is_na_val = false; + on_change_field(); + }), temp->GetId()); temp->SetToolTip(get_tooltip_text(check_value ? "true" : "false")); @@ -424,6 +473,38 @@ void CheckBox::BUILD() { window = dynamic_cast<wxWindow*>(temp); } +void CheckBox::set_value(const boost::any& value, bool change_event) +{ + m_disable_change_event = !change_event; + if (m_opt.nullable) { + m_is_na_val = boost::any_cast<unsigned char>(value) == ConfigOptionBoolsNullable::nil_value(); + if (!m_is_na_val) + m_last_meaningful_value = value; + dynamic_cast<wxCheckBox*>(window)->SetValue(m_is_na_val ? false : boost::any_cast<unsigned char>(value) != 0); + } + else + dynamic_cast<wxCheckBox*>(window)->SetValue(boost::any_cast<bool>(value)); + m_disable_change_event = false; +} + +void CheckBox::set_last_meaningful_value() +{ + if (m_opt.nullable) { + m_is_na_val = false; + dynamic_cast<wxCheckBox*>(window)->SetValue(boost::any_cast<unsigned char>(m_last_meaningful_value) != 0); + on_change_field(); + } +} + +void CheckBox::set_na_value() +{ + if (m_opt.nullable) { + m_is_na_val = true; + dynamic_cast<wxCheckBox*>(window)->SetValue(false); + on_change_field(); + } +} + boost::any& CheckBox::get_value() { // boost::any m_value; @@ -431,7 +512,7 @@ boost::any& CheckBox::get_value() if (m_opt.type == coBool) m_value = static_cast<bool>(value); else - m_value = static_cast<unsigned char>(value); + m_value = m_is_na_val ? ConfigOptionBoolsNullable::nil_value() : static_cast<unsigned char>(value); return m_value; } |