Forward compatibility, parameter susbtitution: Substitute vector values
(extruder specific) with their default, if the default is a single value vector. Show the "Physical Printers" label in the substitution window.
This commit is contained in:
parent
3a0b71deed
commit
26822347ed
@ -546,9 +546,18 @@ bool ConfigBase::set_deserialize_raw(const t_config_option_key &opt_key_src, con
|
||||
bool substituted = false;
|
||||
if (optdef->type == coBools && substitutions_ctxt.rule != ForwardCompatibilitySubstitutionRule::Disable) {
|
||||
//FIXME Special handling of vectors of bools, quick and not so dirty solution before PrusaSlicer 2.3.2 release.
|
||||
auto result = opt->nullable() ?
|
||||
static_cast<ConfigOptionBoolsNullable*>(opt)->deserialize_with_substitutions(value, append, true) :
|
||||
static_cast<ConfigOptionBools*>(opt)->deserialize_with_substitutions(value, append, true);
|
||||
bool nullable = opt->nullable();
|
||||
ConfigHelpers::DeserializationSubstitution default_value = ConfigHelpers::DeserializationSubstitution::DefaultsToFalse;
|
||||
if (optdef->default_value) {
|
||||
// Default value for vectors of booleans used in a "per extruder" context, thus the default contains just a single value.
|
||||
assert(dynamic_cast<const ConfigOptionVector<unsigned char>*>(optdef->default_value.get()));
|
||||
auto &values = static_cast<const ConfigOptionVector<unsigned char>*>(optdef->default_value.get())->values;
|
||||
if (values.size() == 1 && values.front() == 1)
|
||||
default_value = ConfigHelpers::DeserializationSubstitution::DefaultsToTrue;
|
||||
}
|
||||
auto result = nullable ?
|
||||
static_cast<ConfigOptionBoolsNullable*>(opt)->deserialize_with_substitutions(value, append, default_value) :
|
||||
static_cast<ConfigOptionBools*>(opt)->deserialize_with_substitutions(value, append, default_value);
|
||||
success = result != ConfigHelpers::DeserializationResult::Failed;
|
||||
substituted = result == ConfigHelpers::DeserializationResult::Substituted;
|
||||
} else {
|
||||
|
@ -97,6 +97,12 @@ namespace ConfigHelpers {
|
||||
return boost::iequals(value, "enabled") || boost::iequals(value, "on");
|
||||
}
|
||||
|
||||
enum DeserializationSubstitution {
|
||||
Disabled,
|
||||
DefaultsToFalse,
|
||||
DefaultsToTrue
|
||||
};
|
||||
|
||||
enum DeserializationResult {
|
||||
Loaded,
|
||||
Substituted,
|
||||
@ -1425,7 +1431,7 @@ public:
|
||||
return vv;
|
||||
}
|
||||
|
||||
ConfigHelpers::DeserializationResult deserialize_with_substitutions(const std::string &str, bool append, bool substitute)
|
||||
ConfigHelpers::DeserializationResult deserialize_with_substitutions(const std::string &str, bool append, ConfigHelpers::DeserializationSubstitution substitution)
|
||||
{
|
||||
if (! append)
|
||||
this->values.clear();
|
||||
@ -1444,8 +1450,8 @@ public:
|
||||
new_value = true;
|
||||
} else if (item_str == "0") {
|
||||
new_value = false;
|
||||
} else if (substitute && ConfigHelpers::looks_like_enum_value(item_str)) {
|
||||
new_value = ConfigHelpers::enum_looks_like_true_value(item_str);
|
||||
} else if (substitution != ConfigHelpers::DeserializationSubstitution::Disabled && ConfigHelpers::looks_like_enum_value(item_str)) {
|
||||
new_value = ConfigHelpers::enum_looks_like_true_value(item_str) || substituted == ConfigHelpers::DeserializationSubstitution::DefaultsToTrue;
|
||||
substituted = true;
|
||||
} else
|
||||
return ConfigHelpers::DeserializationResult::Failed;
|
||||
@ -1456,7 +1462,7 @@ public:
|
||||
|
||||
bool deserialize(const std::string &str, bool append = false) override
|
||||
{
|
||||
return this->deserialize_with_substitutions(str, append, false) == ConfigHelpers::DeserializationResult::Loaded;
|
||||
return this->deserialize_with_substitutions(str, append, ConfigHelpers::DeserializationSubstitution::Disabled) == ConfigHelpers::DeserializationResult::Loaded;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -316,11 +316,15 @@ void show_substitutions_info(const PresetsConfigSubstitutions& presets_config_su
|
||||
wxString changes;
|
||||
|
||||
auto preset_type_name = [](Preset::Type type) {
|
||||
return type == Slic3r::Preset::TYPE_PRINT ? _L("Print settings") :
|
||||
type == Slic3r::Preset::TYPE_SLA_PRINT ? _L("SLA print settings") :
|
||||
type == Slic3r::Preset::TYPE_FILAMENT ? _L("Filament") :
|
||||
type == Slic3r::Preset::TYPE_SLA_MATERIAL ? _L("SLA material") :
|
||||
type == Slic3r::Preset::TYPE_PRINTER ? _L("Printer") : "" ;
|
||||
switch (type) {
|
||||
case Preset::TYPE_PRINT: return _L("Print settings");
|
||||
case Preset::TYPE_SLA_PRINT: return _L("SLA print settings");
|
||||
case Preset::TYPE_FILAMENT: return _L("Filament");
|
||||
case Preset::TYPE_SLA_MATERIAL: return _L("SLA material");
|
||||
case Preset::TYPE_PRINTER: return _L("Printer");
|
||||
case Preset::TYPE_PHYSICAL_PRINTER: return _L("Physical Printer");
|
||||
default: assert(false); return wxString();
|
||||
}
|
||||
};
|
||||
|
||||
for (const PresetConfigSubstitutions& substitution : presets_config_substitutions) {
|
||||
|
Loading…
Reference in New Issue
Block a user