From 0c03a6b3616b855ccad5e629834d09672de334d7 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) --- src/libslic3r/Preset.cpp | 1 + src/slic3r/GUI/Field.cpp | 31 ++++++++++++------------ src/slic3r/GUI/GUI.cpp | 43 +++++++++++++++++++++------------ src/slic3r/GUI/OptionsGroup.cpp | 11 ++++++++- src/slic3r/GUI/Tab.cpp | 1 + 5 files changed, 55 insertions(+), 32 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 684841755..11050d5f0 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -2686,6 +2686,7 @@ inline t_config_option_keys deep_diff(const ConfigBase &config_this, const Confi case coFloats: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; case coStrings: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; case coPercents:add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; + case coFloatsOrPercents: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; case coPoints: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; // BBS case coEnums: add_correct_opts_to_diff(opt_key, diff, config_other, config_this); break; diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 2de72c195..353e25f8c 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -126,7 +126,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(); @@ -213,7 +213,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; @@ -268,7 +268,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); @@ -337,8 +337,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.; @@ -565,9 +566,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); } @@ -771,7 +772,7 @@ bool TextCtrl::value_was_changed() void TextCtrl::propagate_value() { - + if (!is_defined_input_value(text_ctrl(), m_opt.type)) { // BBS // on_kill_focus() cause a call of OptionsGroup::reload_config(), // Thus, do it only when it's really needed (when undefined value was input) @@ -894,7 +895,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); @@ -1045,8 +1046,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(); @@ -1116,7 +1117,7 @@ void SpinCtrl::propagate_value() } #endif 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(); @@ -1199,7 +1200,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; @@ -1451,7 +1452,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 a9dca1d57..89992cea1 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 eb7bd8806..9d5e8beab 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -983,7 +983,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; text_value = wxString::Format(_T("%i"), int(val)); ret = text_value;// += "%"; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 09e557581..698f8d0e8 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -875,6 +875,7 @@ void TabPrinter::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;