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