From ae8684a4a46bdaa8fb7dda03b38561ffe170cb47 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Mon, 21 Aug 2023 17:45:07 +0200 Subject: [PATCH] Added handle_legacy_composite() callback to configuration layer to support conversion of multiple configuration keys into one or multiple other configuration keys. --- src/libslic3r/Config.cpp | 3 +++ src/libslic3r/Config.hpp | 4 ++++ src/libslic3r/PrintConfig.cpp | 7 +++++++ src/libslic3r/PrintConfig.hpp | 9 +++++++++ 4 files changed, 23 insertions(+) diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index 51870e93d7..28224d9baf 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -797,6 +797,9 @@ ConfigSubstitutions ConfigBase::load(const boost::property_tree::ptree &tree, Fo // ignore } } + // Do legacy conversion on a completely loaded dictionary. + // Perform composite conversions, for example merging multiple keys into one key. + this->handle_legacy_composite(); return std::move(substitutions_ctxt.substitutions); } diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 28410b87dc..c0ab5266f7 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -2160,6 +2160,10 @@ protected: // If the opt_key is no more valid in this version of Slic3r, opt_key is cleared by handle_legacy(). // handle_legacy() is called internally by set_deserialize(). virtual void handle_legacy(t_config_option_key &/*opt_key*/, std::string &/*value*/) const {} + // Called after a config is loaded as a whole. + // Perform composite conversions, for example merging multiple keys into one key. + // For conversion of single options, the handle_legacy() method above is called. + virtual void handle_legacy_composite() {} public: using ConfigOptionResolver::option; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 3001e2924b..5ccfdf9981 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -4323,6 +4323,13 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va } } +// Called after a config is loaded as a whole. +// Perform composite conversions, for example merging multiple keys into one key. +// Don't convert single options here, implement such conversion in PrintConfigDef::handle_legacy() instead. +void PrintConfigDef::handle_legacy_composite(DynamicPrintConfig &config) +{ +} + const PrintConfigDef print_config_def; DynamicPrintConfig DynamicPrintConfig::full_print_config() diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index e79e520648..ab6f1ea907 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -166,6 +166,8 @@ CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(PerimeterGeneratorType) #undef CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS +class DynamicPrintConfig; + // Defines each and every confiuration option of Slic3r, including the properties of the GUI dialogs. // Does not store the actual values, but defines default values. class PrintConfigDef : public ConfigDef @@ -174,6 +176,7 @@ public: PrintConfigDef(); static void handle_legacy(t_config_option_key &opt_key, std::string &value); + static void handle_legacy_composite(DynamicPrintConfig &config); // Array options growing with the number of extruders const std::vector& extruder_option_keys() const { return m_extruder_option_keys; } @@ -258,6 +261,12 @@ public: // handle_legacy() is called internally by set_deserialize(). void handle_legacy(t_config_option_key &opt_key, std::string &value) const override { PrintConfigDef::handle_legacy(opt_key, value); } + + // Called after a config is loaded as a whole. + // Perform composite conversions, for example merging multiple keys into one key. + // For conversion of single options, the handle_legacy() method above is called. + void handle_legacy_composite() override + { PrintConfigDef::handle_legacy_composite(*this); } }; void handle_legacy_sla(DynamicPrintConfig &config);