diff options
author | bubnikv <bubnikv@gmail.com> | 2018-09-27 18:41:01 +0300 |
---|---|---|
committer | bubnikv <bubnikv@gmail.com> | 2018-09-27 18:41:01 +0300 |
commit | b338eb0ce0e5b88ab57940fc0bca4046660237b1 (patch) | |
tree | 6a8945ebe8b370966301aeaf662a59ff9dd05663 /xs | |
parent | 3835a1cacf6ea58a50739ff60e8ebb84c2f52a61 (diff) |
Fix of
https://github.com/prusa3d/Slic3r/issues/1142
https://github.com/prusa3d/Slic3r/issues/1257
The preset keys not belonging into the config group are removed
and the problem is reported into the boost::log
Diffstat (limited to 'xs')
-rw-r--r-- | xs/src/libslic3r/Config.hpp | 3 | ||||
-rw-r--r-- | xs/src/libslic3r/PrintConfig.cpp | 20 | ||||
-rw-r--r-- | xs/src/libslic3r/PrintConfig.hpp | 4 | ||||
-rw-r--r-- | xs/src/slic3r/GUI/Preset.cpp | 9 | ||||
-rw-r--r-- | xs/src/slic3r/GUI/PresetBundle.cpp | 18 |
5 files changed, 37 insertions, 17 deletions
diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index 377bdbea4..2d995551c 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -1171,6 +1171,7 @@ public: // Allow DynamicConfig to be instantiated on ints own without a definition. // If the definition is not defined, the method requiring the definition will throw NoDefinitionException. const ConfigDef* def() const override { return nullptr; }; + bool has(const t_config_option_key &opt_key) const { return this->options.find(opt_key) != this->options.end(); } template<class T> T* opt(const t_config_option_key &opt_key, bool create = false) { return dynamic_cast<T*>(this->option(opt_key, create)); } template<class T> const T* opt(const t_config_option_key &opt_key) const @@ -1214,7 +1215,7 @@ public: bool opt_bool(const t_config_option_key &opt_key) const { return this->option<ConfigOptionBool>(opt_key)->value != 0; } bool opt_bool(const t_config_option_key &opt_key, unsigned int idx) const { return this->option<ConfigOptionBools>(opt_key)->get_at(idx) != 0; } -private: +protected: typedef std::map<t_config_option_key,ConfigOption*> t_options_map; t_options_map options; }; diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index cad23337a..a5418f0a9 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1,6 +1,7 @@ #include "PrintConfig.hpp" #include "I18N.hpp" +#include <algorithm> #include <set> #include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/case_conv.hpp> @@ -2241,6 +2242,25 @@ std::string DynamicPrintConfig::validate() return fpc.validate(); } +size_t DynamicPrintConfig::remove_keys_not_in(const DynamicPrintConfig &default_config, std::string &removed_keys_message) +{ + size_t n_removed_keys = 0; + for (const auto &kvp : this->options) { + const std::string &key = kvp.first; + if (! default_config.has(key)) { + if (removed_keys_message.empty()) + removed_keys_message = key; + else { + removed_keys_message += ", "; + removed_keys_message += key; + } + this->erase(key); + ++ n_removed_keys; + } + } + return n_removed_keys; +} + double PrintConfig::min_object_distance() const { return PrintConfig::min_object_distance(static_cast<const ConfigBase*>(this)); diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 89ba81124..28d5aa8f4 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -168,6 +168,10 @@ public: // Validate the PrintConfig. Returns an empty string on success, otherwise an error message is returned. std::string validate(); + // Remove all keys not in "valid_keys", return number of removed keys and add the list of keys to "removed_keys_message. + // valid_keys has to be sorted lexicographically. + size_t remove_keys_not_in(const DynamicPrintConfig &default_config, std::string &removed_keys_message); + // Verify whether the opt_key has not been obsoleted or renamed. // Both opt_key and value may be modified by handle_legacy(). // If the opt_key is no more valid in this version of Slic3r, opt_key is cleared by handle_legacy(). diff --git a/xs/src/slic3r/GUI/Preset.cpp b/xs/src/slic3r/GUI/Preset.cpp index cede4c707..8af10d293 100644 --- a/xs/src/slic3r/GUI/Preset.cpp +++ b/xs/src/slic3r/GUI/Preset.cpp @@ -417,7 +417,14 @@ void PresetCollection::load_presets(const std::string &dir_path, const std::stri try { Preset preset(m_type, name, false); preset.file = dir_entry.path().string(); - preset.load(keys); + DynamicPrintConfig &config = preset.load(keys); + // Report configuration fields, which are misplaced into a wrong group. + std::string incorrect_keys; + if (config.remove_keys_not_in(this->default_preset().config, incorrect_keys) > 0) + BOOST_LOG_TRIVIAL(error) << "Error in \"" << dir_entry.path().string() << "\": The preset contains the following incorrect keys: " << + incorrect_keys << ", which were ignored"; + // Normalize once again to set the length of the filament specific vectors to 1. + Preset::normalize(config); m_presets.emplace_back(preset); } catch (const std::runtime_error &err) { errors_cummulative += err.what(); diff --git a/xs/src/slic3r/GUI/PresetBundle.cpp b/xs/src/slic3r/GUI/PresetBundle.cpp index 94baa0e0e..e7ae4ebd9 100644 --- a/xs/src/slic3r/GUI/PresetBundle.cpp +++ b/xs/src/slic3r/GUI/PresetBundle.cpp @@ -919,24 +919,12 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla DynamicPrintConfig config(default_config); for (auto &kvp : section.second) config.set_deserialize(kvp.first, kvp.second.data()); - Preset::normalize(config); // Report configuration fields, which are misplaced into a wrong group. std::string incorrect_keys; - size_t n_incorrect_keys = 0; - for (const std::string &key : config.keys()) - if (! default_config.has(key)) { - if (incorrect_keys.empty()) - incorrect_keys = key; - else { - incorrect_keys += ", "; - incorrect_keys += key; - } - config.erase(key); - ++ n_incorrect_keys; - } - if (! incorrect_keys.empty()) + if (config.remove_keys_not_in(default_config, incorrect_keys) > 0) BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << - section.first << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed"; + section.first << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed"; + Preset::normalize(config); if ((flags & LOAD_CFGBNDLE_SYSTEM) && presets == &printers) { // Filter out printer presets, which are not mentioned in the vendor profile. // These presets are considered not installed. |