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:
bubnikv 2021-07-01 08:44:02 +02:00 committed by Vojtech Bubnik
parent 3a0b71deed
commit 26822347ed
3 changed files with 31 additions and 12 deletions

View file

@ -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: