From 26822347ed42f5d0d650d78f2608f472525e9796 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Thu, 1 Jul 2021 08:44:02 +0200 Subject: [PATCH] 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. --- src/libslic3r/Config.cpp | 15 ++++++++++++--- src/libslic3r/Config.hpp | 14 ++++++++++---- src/slic3r/GUI/GUI.cpp | 14 +++++++++----- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index dbe038c5b..46cbd9891 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -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(opt)->deserialize_with_substitutions(value, append, true) : - static_cast(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*>(optdef->default_value.get())); + auto &values = static_cast*>(optdef->default_value.get())->values; + if (values.size() == 1 && values.front() == 1) + default_value = ConfigHelpers::DeserializationSubstitution::DefaultsToTrue; + } + auto result = nullable ? + static_cast(opt)->deserialize_with_substitutions(value, append, default_value) : + static_cast(opt)->deserialize_with_substitutions(value, append, default_value); success = result != ConfigHelpers::DeserializationResult::Failed; substituted = result == ConfigHelpers::DeserializationResult::Substituted; } else { diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 7d66264f5..a3d86d145 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -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: diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index 5b3058fd6..17a46d369 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -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) {