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
This commit is contained in:
bubnikv 2018-09-27 17:41:01 +02:00
parent 3835a1cacf
commit b338eb0ce0
5 changed files with 37 additions and 17 deletions

View File

@ -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;
};

View File

@ -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));

View File

@ -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().

View File

@ -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();

View File

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