FIX: support config editing of type FloatsOrPercents

Change-Id: If0821dc357b14f1b72aa1c89b3b0378947e80a5c
Jira: none
(cherry picked from commit 115fb9ce072273acf8df558a33fe48cf71f8e35b)
This commit is contained in:
chunmao.guo 2024-07-19 09:59:23 +08:00 committed by Lane.Wei
parent 0b92ffee35
commit 0c03a6b361
5 changed files with 55 additions and 32 deletions

View File

@ -2686,6 +2686,7 @@ inline t_config_option_keys deep_diff(const ConfigBase &config_this, const Confi
case coFloats: add_correct_opts_to_diff<ConfigOptionFloats >(opt_key, diff, config_other, config_this); break; case coFloats: add_correct_opts_to_diff<ConfigOptionFloats >(opt_key, diff, config_other, config_this); break;
case coStrings: add_correct_opts_to_diff<ConfigOptionStrings >(opt_key, diff, config_other, config_this); break; case coStrings: add_correct_opts_to_diff<ConfigOptionStrings >(opt_key, diff, config_other, config_this); break;
case coPercents:add_correct_opts_to_diff<ConfigOptionPercents >(opt_key, diff, config_other, config_this); break; case coPercents:add_correct_opts_to_diff<ConfigOptionPercents >(opt_key, diff, config_other, config_this); break;
case coFloatsOrPercents: add_correct_opts_to_diff<ConfigOptionFloatsOrPercents>(opt_key, diff, config_other, config_this); break;
case coPoints: add_correct_opts_to_diff<ConfigOptionPoints >(opt_key, diff, config_other, config_this); break; case coPoints: add_correct_opts_to_diff<ConfigOptionPoints >(opt_key, diff, config_other, config_this); break;
// BBS // BBS
case coEnums: add_correct_opts_to_diff<ConfigOptionInts >(opt_key, diff, config_other, config_this); break; case coEnums: add_correct_opts_to_diff<ConfigOptionInts >(opt_key, diff, config_other, config_this); break;

View File

@ -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. // 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 // 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 (getWindow()) {
if (m_opt.readonly) { if (m_opt.readonly) {
this->disable(); this->disable();
} else { } else {
this->enable(); this->enable();
@ -213,7 +213,7 @@ wxString Field::get_tooltip_text(const wxString &default_string)
} }
if (tooltip.length() > 0) if (tooltip.length() > 0)
tooltip_text = tooltip + "\n" + tooltip_text = tooltip + "\n" +
_(L("parameter name")) + "\t: " + opt_id; _(L("parameter name")) + "\t: " + opt_id;
#endif #endif
return tooltip_text; 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 = is_decimal_separator_point() ? '.' : ',';
const char dec_sep_alt = dec_sep == '.' ? ',' : '.'; 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 this value doesn't "N/A" value in some language
if (!is_na_value && str.Replace(dec_sep_alt, dec_sep, false) != 0) if (!is_na_value && str.Replace(dec_sep_alt, dec_sep, false) != 0)
set_value(str, false); 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; m_value = val;
break; } break; }
case coString: case coString:
case coStrings: case coStrings:
case coFloatOrPercent: { case coFloatOrPercent:
case coFloatsOrPercents: {
if (m_opt.type == coFloatOrPercent && !str.IsEmpty() && str.Last() != '%') if (m_opt.type == coFloatOrPercent && !str.IsEmpty() && str.Last() != '%')
{ {
double val = 0.; double val = 0.;
@ -565,9 +566,9 @@ struct myEvtHandler : wxEvtHandler
// In Field, All Bind has id, but for TextInput, ComboBox, SpinInput, all not // In Field, All Bind has id, but for TextInput, ComboBox, SpinInput, all not
if (entry->m_id != wxID_ANY && entry->m_lastId == wxID_ANY) if (entry->m_id != wxID_ANY && entry->m_lastId == wxID_ANY)
Unbind(entry->m_eventType, Unbind(entry->m_eventType,
wxEventFunctorRef{entry->m_fn}, wxEventFunctorRef{entry->m_fn},
entry->m_id, entry->m_id,
entry->m_lastId, entry->m_lastId,
entry->m_callbackUserData); entry->m_callbackUserData);
//DoUnbind(entry->m_id, entry->m_lastId, entry->m_eventType, *entry->m_fn, 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() void TextCtrl::propagate_value()
{ {
if (!is_defined_input_value<wxTextCtrl>(text_ctrl(), m_opt.type)) { // BBS if (!is_defined_input_value<wxTextCtrl>(text_ctrl(), m_opt.type)) { // BBS
// on_kill_focus() cause a call of OptionsGroup::reload_config(), // on_kill_focus() cause a call of OptionsGroup::reload_config(),
// Thus, do it only when it's really needed (when undefined value was input) // Thus, do it only when it's really needed (when undefined value was input)
@ -894,7 +895,7 @@ void CheckBox::BUILD() {
// BBS: use ::CheckBox // BBS: use ::CheckBox
static Builder<::CheckBox> builder; static Builder<::CheckBox> builder;
auto temp = builder.build(m_parent); auto temp = builder.build(m_parent);
if (!wxOSX) temp->SetBackgroundStyle(wxBG_STYLE_PAINT); if (!wxOSX) temp->SetBackgroundStyle(wxBG_STYLE_PAINT);
//temp->SetBackgroundColour(*wxWHITE); //temp->SetBackgroundColour(*wxWHITE);
temp->SetValue(check_value); temp->SetValue(check_value);
@ -1045,8 +1046,8 @@ void SpinCtrl::BUILD() {
propagate_value(); propagate_value();
}), temp->GetId()); }), 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) temp->Bind(wxEVT_TEXT_ENTER, ([this](wxCommandEvent & e)
{ {
e.Skip(); e.Skip();
@ -1116,7 +1117,7 @@ void SpinCtrl::propagate_value()
} }
#endif #endif
auto ctrl = dynamic_cast<SpinInput *>(window); auto ctrl = dynamic_cast<SpinInput *>(window);
if (m_value.empty() if (m_value.empty()
? !ctrl->GetTextCtrl()->GetLabel().IsEmpty() ? !ctrl->GetTextCtrl()->GetLabel().IsEmpty()
: ctrl->GetValue() != boost::any_cast<int>(m_value)) : ctrl->GetValue() != boost::any_cast<int>(m_value))
on_change_field(); on_change_field();
@ -1199,7 +1200,7 @@ void Choice::BUILD()
auto dynamic_list = dynamic_lists.find(m_opt.opt_key); auto dynamic_list = dynamic_lists.find(m_opt.opt_key);
if (dynamic_list != dynamic_lists.end()) if (dynamic_list != dynamic_lists.end())
m_list = dynamic_list->second; 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_list == nullptr) {
m_is_editable = true; m_is_editable = true;
static Builder<choice_ctrl> builder1; static Builder<choice_ctrl> builder1;
@ -1451,7 +1452,7 @@ void Choice::set_value(const boost::any& value, bool change_event)
field->SetSelection(idx); field->SetSelection(idx);
if (!m_value.empty() && m_opt.opt_key == "sparse_infill_density") { 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(), // when control's value is already changed from the ConfigManipulation::update_print_fff_config(),
// but m_value doesn't respect it. // but m_value doesn't respect it.
if (double val; text_value.ToDouble(&val)) if (double val; text_value.ToDouble(&val))

View File

@ -108,8 +108,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
try{ try{
if (config.def()->get(opt_key)->type == coBools && config.def()->get(opt_key)->nullable) { if (config.def()->get(opt_key)->type == coBools && config.def()->get(opt_key)->nullable) {
ConfigOptionBoolsNullable* vec_new = new ConfigOptionBoolsNullable{ boost::any_cast<unsigned char>(value) }; auto vec_new = std::make_unique<ConfigOptionBoolsNullable>(1, boost::any_cast<unsigned char>(value) );
config.option<ConfigOptionBoolsNullable>(opt_key)->set_at(vec_new, opt_index, 0); config.option<ConfigOptionBoolsNullable>(opt_key)->set_at(vec_new.get(), opt_index, 0);
return; 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) 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)); config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(val, percent));
break;} break;}
case coFloatsOrPercents:{
std::string str = boost::any_cast<std::string>(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<ConfigOptionFloatOrPercent>(val, percent);
config.option<ConfigOptionFloatsOrPercents>(opt_key)->set_at(vec_new.get(), opt_index, opt_index);
break;}
case coPercent: case coPercent:
config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast<double>(value))); config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast<double>(value)));
break; break;
@ -134,13 +145,13 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
break; break;
} }
case coPercents:{ case coPercents:{
ConfigOptionPercents* vec_new = new ConfigOptionPercents{ boost::any_cast<double>(value) }; auto vec_new = std::make_unique <ConfigOptionPercent>(boost::any_cast<double>(value));
config.option<ConfigOptionPercents>(opt_key)->set_at(vec_new, opt_index, opt_index); config.option<ConfigOptionPercents>(opt_key)->set_at(vec_new.get(), opt_index, opt_index);
break; break;
} }
case coFloats:{ case coFloats:{
ConfigOptionFloats* vec_new = new ConfigOptionFloats{ boost::any_cast<double>(value) }; auto vec_new = std::make_unique<ConfigOptionFloat>(boost::any_cast<double>(value));
config.option<ConfigOptionFloats>(opt_key)->set_at(vec_new, opt_index, opt_index); config.option<ConfigOptionFloats>(opt_key)->set_at(vec_new.get(), opt_index, opt_index);
break; break;
} }
case coString: case coString:
@ -165,8 +176,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
config.option<ConfigOptionStrings>(opt_key)->values = values; config.option<ConfigOptionStrings>(opt_key)->values = values;
} }
else{ else{
ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast<std::string>(value) }; auto vec_new = std::make_unique<ConfigOptionString>(boost::any_cast<std::string>(value));
config.option<ConfigOptionStrings>(opt_key)->set_at(vec_new, opt_index, 0); config.option<ConfigOptionStrings>(opt_key)->set_at(vec_new.get(), opt_index, 0);
} }
} }
break; 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<bool>(value))); config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast<bool>(value)));
break; break;
case coBools:{ case coBools:{
ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast<unsigned char>(value) != 0 }; auto vec_new = std::make_unique<ConfigOptionBool>(boost::any_cast<unsigned char>(value) != 0);
config.option<ConfigOptionBools>(opt_key)->set_at(vec_new, opt_index, 0); config.option<ConfigOptionBools>(opt_key)->set_at(vec_new.get(), opt_index, 0);
break;} break;}
case coInt: case coInt:
config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast<int>(value))); config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast<int>(value)));
break; break;
case coInts:{ case coInts:{
ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast<int>(value) }; auto vec_new = std::make_unique<ConfigOptionInt>(boost::any_cast<int>(value));
config.option<ConfigOptionInts>(opt_key)->set_at(vec_new, opt_index, 0); config.option<ConfigOptionInts>(opt_key)->set_at(vec_new.get(), opt_index, 0);
} }
break; break;
case coEnum:{ case coEnum:{
@ -193,9 +204,9 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
break; break;
// BBS // BBS
case coEnums:{ case coEnums:{
ConfigOptionEnumsGeneric* vec_new = new ConfigOptionEnumsGeneric{ boost::any_cast<int>(value) }; auto vec_new = std::make_unique<ConfigOptionEnumsGeneric>(std::vector<int>{boost::any_cast<int>(value)});
if (config.has(opt_key)) if (config.has(opt_key))
config.option<ConfigOptionEnumsGeneric>(opt_key)->set_at(vec_new, opt_index, 0); config.option<ConfigOptionEnumsGeneric>(opt_key)->set_at(vec_new.get(), opt_index, 0);
} }
break; break;
case coPoint:{ case coPoint:{
@ -207,8 +218,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
config.option<ConfigOptionPoints>(opt_key)->values = boost::any_cast<std::vector<Vec2d>>(value); config.option<ConfigOptionPoints>(opt_key)->values = boost::any_cast<std::vector<Vec2d>>(value);
break; break;
} }
ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast<Vec2d>(value) }; auto vec_new = std::make_unique<ConfigOptionPoint>(boost::any_cast<Vec2d>(value));
config.option<ConfigOptionPoints>(opt_key)->set_at(vec_new, opt_index, 0); config.option<ConfigOptionPoints>(opt_key)->set_at(vec_new.get(), opt_index, 0);
} }
break; break;
case coNone: case coNone:

View File

@ -983,7 +983,16 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config
ret = text_value; ret = text_value;
break; break;
} }
case coPercent:{ case coFloatsOrPercents: {
const auto &value = config.option<ConfigOptionFloatsOrPercents>(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<ConfigOptionPercent>(opt_key)->value; double val = config.option<ConfigOptionPercent>(opt_key)->value;
text_value = wxString::Format(_T("%i"), int(val)); text_value = wxString::Format(_T("%i"), int(val));
ret = text_value;// += "%"; ret = text_value;// += "%";

View File

@ -875,6 +875,7 @@ void TabPrinter::init_options_list()
case coFloats: add_correct_opts_to_options_list<ConfigOptionFloats >(opt_key, m_options_list, this, m_opt_status_value); break; case coFloats: add_correct_opts_to_options_list<ConfigOptionFloats >(opt_key, m_options_list, this, m_opt_status_value); break;
case coStrings: add_correct_opts_to_options_list<ConfigOptionStrings >(opt_key, m_options_list, this, m_opt_status_value); break; case coStrings: add_correct_opts_to_options_list<ConfigOptionStrings >(opt_key, m_options_list, this, m_opt_status_value); break;
case coPercents:add_correct_opts_to_options_list<ConfigOptionPercents >(opt_key, m_options_list, this, m_opt_status_value); break; case coPercents:add_correct_opts_to_options_list<ConfigOptionPercents >(opt_key, m_options_list, this, m_opt_status_value); break;
case coFloatsOrPercents: add_correct_opts_to_options_list<ConfigOptionFloatsOrPercents>(opt_key, m_options_list, this, m_opt_status_value); break;
case coPoints: add_correct_opts_to_options_list<ConfigOptionPoints >(opt_key, m_options_list, this, m_opt_status_value); break; case coPoints: add_correct_opts_to_options_list<ConfigOptionPoints >(opt_key, m_options_list, this, m_opt_status_value); break;
// BBS // BBS
case coEnums: add_correct_opts_to_options_list<ConfigOptionInts >(opt_key, m_options_list, this, m_opt_status_value); break; case coEnums: add_correct_opts_to_options_list<ConfigOptionInts >(opt_key, m_options_list, this, m_opt_status_value); break;