From f33f2fbc7d34c08586ce723241c9f3d352ff0f8a Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Fri, 19 Jul 2024 09:59:23 +0800 Subject: [PATCH] FIX: support config editing of type FloatsOrPercents Change-Id: If0821dc357b14f1b72aa1c89b3b0378947e80a5c Jira: none (cherry picked from commit 115fb9ce072273acf8df558a33fe48cf71f8e35b) (cherry picked from commit 0c03a6b3616b855ccad5e629834d09672de334d7) --- src/slic3r/GUI/Field.cpp | 29 +++++++++++----------- src/slic3r/GUI/GUI.cpp | 43 +++++++++++++++++++++------------ src/slic3r/GUI/OptionsGroup.cpp | 11 ++++++++- src/slic3r/GUI/Tab.cpp | 1 + 4 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 517352d0a9..47100c31e7 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -144,7 +144,7 @@ void Field::PostInitialize() // For the mode, when settings are in non-modal dialog, neither dialog nor tabpanel doesn't receive wxEVT_KEY_UP event, when some field is selected. // So, like a workaround check wxEVT_KEY_UP event for the Filed and switch between tabs if Ctrl+(1-4) was pressed if (getWindow()) { - if (m_opt.readonly) { + if (m_opt.readonly) { this->disable(); } else { this->enable(); @@ -236,7 +236,7 @@ wxString Field::get_tooltip_text(const wxString &default_string) } if (tooltip.length() > 0) - tooltip_text = tooltip + "\n" + + tooltip_text = tooltip + "\n" + _(L("parameter name")) + "\t: " + opt_id; #endif return tooltip_text; @@ -289,7 +289,7 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true const char dec_sep = is_decimal_separator_point() ? '.' : ','; const char dec_sep_alt = dec_sep == '.' ? ',' : '.'; - // Replace the first incorrect separator in decimal number, + // Replace the first incorrect separator in decimal number, // if this value doesn't "N/A" value in some language if (!is_na_value && str.Replace(dec_sep_alt, dec_sep, false) != 0) set_value(str, false); @@ -358,8 +358,9 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true m_value = val; break; } case coString: - case coStrings: - case coFloatOrPercent: { + case coStrings: + case coFloatOrPercent: + case coFloatsOrPercents: { if (m_opt.type == coFloatOrPercent && !str.IsEmpty() && str.Last() != '%') { double val = 0.; @@ -645,9 +646,9 @@ struct myEvtHandler : wxEvtHandler // In Field, All Bind has id, but for TextInput, ComboBox, SpinInput, all not if (entry->m_id != wxID_ANY && entry->m_lastId == wxID_ANY) Unbind(entry->m_eventType, - wxEventFunctorRef{entry->m_fn}, - entry->m_id, - entry->m_lastId, + wxEventFunctorRef{entry->m_fn}, + entry->m_id, + entry->m_lastId, entry->m_callbackUserData); //DoUnbind(entry->m_id, entry->m_lastId, entry->m_eventType, *entry->m_fn, entry->m_callbackUserData); } @@ -985,7 +986,7 @@ void CheckBox::BUILD() { // BBS: use ::CheckBox static Builder<::CheckBox> builder; - auto temp = builder.build(m_parent); + auto temp = builder.build(m_parent); if (!wxOSX) temp->SetBackgroundStyle(wxBG_STYLE_PAINT); //temp->SetBackgroundColour(*wxWHITE); temp->SetValue(check_value); @@ -1133,8 +1134,8 @@ void SpinCtrl::BUILD() { propagate_value(); }), temp->GetId()); - temp->Bind(wxEVT_SPINCTRL, ([this](wxCommandEvent e) { propagate_value(); }), temp->GetId()); - + temp->Bind(wxEVT_SPINCTRL, ([this](wxCommandEvent e) { propagate_value(); }), temp->GetId()); + temp->Bind(wxEVT_TEXT_ENTER, ([this](wxCommandEvent & e) { e.Skip(); @@ -1196,7 +1197,7 @@ void SpinCtrl::propagate_value() on_kill_focus(); } else { auto ctrl = dynamic_cast(window); - if (m_value.empty() + if (m_value.empty() ? !ctrl->GetTextCtrl()->GetLabel().IsEmpty() : ctrl->GetValue() != boost::any_cast(m_value)) on_change_field(); @@ -1279,7 +1280,7 @@ void Choice::BUILD() auto dynamic_list = dynamic_lists.find(m_opt.opt_key); if (dynamic_list != dynamic_lists.end()) m_list = dynamic_list->second; - if (m_opt.gui_type != ConfigOptionDef::GUIType::undefined && m_opt.gui_type != ConfigOptionDef::GUIType::select_open + if (m_opt.gui_type != ConfigOptionDef::GUIType::undefined && m_opt.gui_type != ConfigOptionDef::GUIType::select_open && m_list == nullptr) { m_is_editable = true; static Builder builder1; @@ -1531,7 +1532,7 @@ void Choice::set_value(const boost::any& value, bool change_event) field->SetSelection(idx); if (!m_value.empty() && m_opt.opt_key == "sparse_infill_density") { - // If m_value was changed before, then update m_value here too to avoid case + // If m_value was changed before, then update m_value here too to avoid case // when control's value is already changed from the ConfigManipulation::update_print_fff_config(), // but m_value doesn't respect it. if (double val; text_value.ToDouble(&val)) diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index 715512ced4..fb6deb4ed3 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -108,8 +108,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt try{ if (config.def()->get(opt_key)->type == coBools && config.def()->get(opt_key)->nullable) { - ConfigOptionBoolsNullable* vec_new = new ConfigOptionBoolsNullable{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, 0); + auto vec_new = std::make_unique(1, boost::any_cast(value) ); + config.option(opt_key)->set_at(vec_new.get(), opt_index, 0); return; } @@ -125,6 +125,17 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field) config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(val, percent)); break;} + case coFloatsOrPercents:{ + std::string str = boost::any_cast(value); + bool percent = false; + if (str.back() == '%') { + str.pop_back(); + percent = true; + } + double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field) + auto vec_new = std::make_unique(val, percent); + config.option(opt_key)->set_at(vec_new.get(), opt_index, opt_index); + break;} case coPercent: config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast(value))); break; @@ -134,13 +145,13 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt break; } case coPercents:{ - ConfigOptionPercents* vec_new = new ConfigOptionPercents{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, opt_index); + auto vec_new = std::make_unique (boost::any_cast(value)); + config.option(opt_key)->set_at(vec_new.get(), opt_index, opt_index); break; } case coFloats:{ - ConfigOptionFloats* vec_new = new ConfigOptionFloats{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, opt_index); + auto vec_new = std::make_unique(boost::any_cast(value)); + config.option(opt_key)->set_at(vec_new.get(), opt_index, opt_index); break; } case coString: @@ -165,8 +176,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt config.option(opt_key)->values = values; } else{ - ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, 0); + auto vec_new = std::make_unique(boost::any_cast(value)); + config.option(opt_key)->set_at(vec_new.get(), opt_index, 0); } } break; @@ -174,15 +185,15 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast(value))); break; case coBools:{ - ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast(value) != 0 }; - config.option(opt_key)->set_at(vec_new, opt_index, 0); + auto vec_new = std::make_unique(boost::any_cast(value) != 0); + config.option(opt_key)->set_at(vec_new.get(), opt_index, 0); break;} case coInt: config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast(value))); break; case coInts:{ - ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, 0); + auto vec_new = std::make_unique(boost::any_cast(value)); + config.option(opt_key)->set_at(vec_new.get(), opt_index, 0); } break; case coEnum:{ @@ -193,9 +204,9 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt break; // BBS case coEnums:{ - ConfigOptionEnumsGeneric* vec_new = new ConfigOptionEnumsGeneric{ boost::any_cast(value) }; + auto vec_new = std::make_unique(std::vector{boost::any_cast(value)}); if (config.has(opt_key)) - config.option(opt_key)->set_at(vec_new, opt_index, 0); + config.option(opt_key)->set_at(vec_new.get(), opt_index, 0); } break; case coPoint:{ @@ -207,8 +218,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt config.option(opt_key)->values = boost::any_cast>(value); break; } - ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, 0); + auto vec_new = std::make_unique(boost::any_cast(value)); + config.option(opt_key)->set_at(vec_new.get(), opt_index, 0); } break; case coNone: diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 4ef1fd87e6..a8deb2ec42 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -1024,7 +1024,16 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config ret = text_value; break; } - case coPercent:{ + case coFloatsOrPercents: { + const auto &value = config.option(opt_key)->get_at(idx); + + text_value = double_to_string(value.value); + if (value.percent) text_value += "%"; + + ret = text_value; + break; + } + case coPercent: { double val = config.option(opt_key)->value; ret = double_to_string(val);// += "%"; } diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 41ef1a8b17..337e0b939e 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -963,6 +963,7 @@ void Tab::init_options_list() case coFloats: add_correct_opts_to_options_list(opt_key, m_options_list, this, m_opt_status_value); break; case coStrings: add_correct_opts_to_options_list(opt_key, m_options_list, this, m_opt_status_value); break; case coPercents:add_correct_opts_to_options_list(opt_key, m_options_list, this, m_opt_status_value); break; + case coFloatsOrPercents: add_correct_opts_to_options_list(opt_key, m_options_list, this, m_opt_status_value); break; case coPoints: add_correct_opts_to_options_list(opt_key, m_options_list, this, m_opt_status_value); break; // BBS case coEnums: add_correct_opts_to_options_list(opt_key, m_options_list, this, m_opt_status_value); break;