mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-20 20:03:47 +00:00
FIX: support config editing of type FloatsOrPercents
Change-Id: If0821dc357b14f1b72aa1c89b3b0378947e80a5c Jira: none (cherry picked from commit 115fb9ce072273acf8df558a33fe48cf71f8e35b) (cherry picked from commit 0c03a6b3616b855ccad5e629834d09672de334d7)
This commit is contained in:
@@ -358,8 +358,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.;
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -1024,7 +1024,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;
|
||||||
ret = double_to_string(val);// += "%";
|
ret = double_to_string(val);// += "%";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -963,6 +963,7 @@ void Tab::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;
|
||||||
|
|||||||
Reference in New Issue
Block a user