mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2026-02-20 11:32:31 -07:00
ENH: config: process object config values after printer switch
jira: no-jira Change-Id: I01532c42c20aa63b1b9621e175a98cad06bdf577 (cherry picked from commit cc86a62d408cb40942c49277a7f239144d7a5567)
This commit is contained in:
parent
b8f8151340
commit
1297857f66
4 changed files with 189 additions and 3 deletions
|
|
@ -7903,6 +7903,65 @@ int DynamicPrintConfig::update_values_from_single_to_multi(DynamicPrintConfig& m
|
|||
return 0;
|
||||
}
|
||||
|
||||
//used for object/region config
|
||||
//duplicate single to multiple
|
||||
int DynamicPrintConfig::update_values_from_single_to_multi_2(DynamicPrintConfig& multi_config, std::set<std::string>& key_set)
|
||||
{
|
||||
const ConfigDef *config_def = this->def();
|
||||
if (!config_def) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(", Line %1%: can not find config define")%__LINE__;
|
||||
return -1;
|
||||
}
|
||||
|
||||
t_config_option_keys keys = this->keys();
|
||||
for (auto& key: keys)
|
||||
{
|
||||
if (key_set.find(key) == key_set.end())
|
||||
continue;
|
||||
|
||||
const ConfigOptionDef *optdef = config_def->get(key);
|
||||
if (!optdef) {
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: can not find opt define for %2%")%__LINE__%key;
|
||||
continue;
|
||||
}
|
||||
switch (optdef->type) {
|
||||
case coFloats:
|
||||
{
|
||||
ConfigOptionFloatsNullable * opt = this->option<ConfigOptionFloatsNullable>(key);
|
||||
ConfigOptionFloatsNullable* src_opt = multi_config.option<ConfigOptionFloatsNullable>(key);
|
||||
|
||||
if (!opt->is_nil(0))
|
||||
opt->values.resize(src_opt->size(), opt->values[0]);
|
||||
break;
|
||||
}
|
||||
case coFloatsOrPercents:
|
||||
{
|
||||
ConfigOptionFloatsOrPercentsNullable* opt = this->option<ConfigOptionFloatsOrPercentsNullable>(key);
|
||||
ConfigOptionFloatsOrPercentsNullable* src_opt = multi_config.option<ConfigOptionFloatsOrPercentsNullable>(key);
|
||||
|
||||
if (!opt->is_nil(0))
|
||||
opt->values.resize(src_opt->size(), opt->values[0]);
|
||||
break;
|
||||
}
|
||||
case coBools:
|
||||
{
|
||||
ConfigOptionBoolsNullable* opt = this->option<ConfigOptionBoolsNullable>(key);
|
||||
ConfigOptionBoolsNullable* src_opt = multi_config.option<ConfigOptionBoolsNullable>(key);
|
||||
|
||||
if (!opt->is_nil(0))
|
||||
opt->values.resize(src_opt->size(), opt->values[0]);
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: unsupported option type for %2%")%__LINE__%key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DynamicPrintConfig::update_values_from_multi_to_single(DynamicPrintConfig& single_config, std::set<std::string>& key_set, std::string id_name, std::string variant_name, std::vector<std::string>& extruder_variants)
|
||||
{
|
||||
int extruder_count = extruder_variants.size();
|
||||
|
|
@ -8017,6 +8076,94 @@ int DynamicPrintConfig::update_values_from_multi_to_single(DynamicPrintConfig& s
|
|||
return 0;
|
||||
}
|
||||
|
||||
//used for object/region config
|
||||
//use the smallest of multiple to single
|
||||
int DynamicPrintConfig::update_values_from_multi_to_single_2(std::set<std::string>& key_set)
|
||||
{
|
||||
const ConfigDef *config_def = this->def();
|
||||
if (!config_def) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(", Line %1%: can not find config define")%__LINE__;
|
||||
return -1;
|
||||
}
|
||||
|
||||
t_config_option_keys keys = this->keys();
|
||||
for (auto& key: keys)
|
||||
{
|
||||
if (key_set.find(key) == key_set.end())
|
||||
continue;
|
||||
|
||||
const ConfigOptionDef *optdef = config_def->get(key);
|
||||
if (!optdef) {
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: can not find opt define for %2%")%__LINE__%key;
|
||||
continue;
|
||||
}
|
||||
switch (optdef->type) {
|
||||
case coFloats:
|
||||
{
|
||||
ConfigOptionFloatsNullable* opt = this->option<ConfigOptionFloatsNullable>(key);
|
||||
double min = 9999.0;
|
||||
bool has_value = false;
|
||||
|
||||
for (int index = 0; index < opt->values.size(); index++)
|
||||
{
|
||||
if (!opt->is_nil(index) && (opt->values[index] < min)) {
|
||||
min = opt->values[index];
|
||||
has_value = true;
|
||||
}
|
||||
}
|
||||
|
||||
opt->values.erase(opt->values.begin() + 1, opt->values.end());
|
||||
if (has_value)
|
||||
opt->values[0] = min;
|
||||
break;
|
||||
}
|
||||
case coFloatsOrPercents:
|
||||
{
|
||||
ConfigOptionFloatsOrPercentsNullable * opt = this->option<ConfigOptionFloatsOrPercentsNullable>(key);
|
||||
FloatOrPercent min{9999.f, true};
|
||||
bool has_value = false;
|
||||
|
||||
for (int index = 0; index < opt->values.size(); index++)
|
||||
{
|
||||
if (!opt->is_nil(index) && (opt->values[index].value < min.value)) {
|
||||
min = opt->values[index];
|
||||
has_value = true;
|
||||
}
|
||||
}
|
||||
|
||||
opt->values.erase(opt->values.begin() + 1, opt->values.end());
|
||||
if (has_value)
|
||||
opt->values[0] = min;
|
||||
break;
|
||||
}
|
||||
case coBools:
|
||||
{
|
||||
ConfigOptionBoolsNullable* opt = this->option<ConfigOptionBoolsNullable>(key);
|
||||
|
||||
bool min, has_value = false;
|
||||
for (int index = 0; index < opt->values.size(); index++)
|
||||
{
|
||||
if (!opt->is_nil(index)) {
|
||||
min = opt->values[index];
|
||||
has_value = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
opt->values.erase(opt->values.begin() + 1, opt->values.end());
|
||||
if (has_value)
|
||||
opt->values[0] = min;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: unsupported option type for %2%")%__LINE__%key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DynamicPrintConfig::update_values_to_printer_extruders(DynamicPrintConfig& printer_config, std::set<std::string>& key_set, std::string id_name, std::string variant_name, unsigned int stride, unsigned int extruder_id)
|
||||
{
|
||||
int extruder_count;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue