Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'xs/src/libslic3r/Config.hpp')
-rw-r--r--xs/src/libslic3r/Config.hpp90
1 files changed, 52 insertions, 38 deletions
diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp
index 3dccedbf0..e3cd14335 100644
--- a/xs/src/libslic3r/Config.hpp
+++ b/xs/src/libslic3r/Config.hpp
@@ -49,9 +49,9 @@ enum ConfigOptionType {
coPercents = coPercent + coVectorType,
// a fraction or an absolute value
coFloatOrPercent = 5,
- // single 2d point. Currently not used.
+ // single 2d point (Point2f). Currently not used.
coPoint = 6,
- // vector of 2d points. Currently used for the definition of the print bed and for the extruder offsets.
+ // vector of 2d points (Point2f). Currently used for the definition of the print bed and for the extruder offsets.
coPoints = coPoint + coVectorType,
// single boolean value
coBool = 7,
@@ -291,6 +291,8 @@ public:
ConfigOptionFloats() : ConfigOptionVector<double>() {}
explicit ConfigOptionFloats(size_t n, double value) : ConfigOptionVector<double>(n, value) {}
explicit ConfigOptionFloats(std::initializer_list<double> il) : ConfigOptionVector<double>(std::move(il)) {}
+ explicit ConfigOptionFloats(const std::vector<double> &vec) : ConfigOptionVector<double>(vec) {}
+ explicit ConfigOptionFloats(std::vector<double> &&vec) : ConfigOptionVector<double>(std::move(vec)) {}
static ConfigOptionType static_type() { return coFloats; }
ConfigOptionType type() const override { return static_type(); }
@@ -620,11 +622,11 @@ public:
}
};
-class ConfigOptionPoint : public ConfigOptionSingle<Pointf>
+class ConfigOptionPoint : public ConfigOptionSingle<Vec2d>
{
public:
- ConfigOptionPoint() : ConfigOptionSingle<Pointf>(Pointf(0,0)) {}
- explicit ConfigOptionPoint(const Pointf &value) : ConfigOptionSingle<Pointf>(value) {}
+ ConfigOptionPoint() : ConfigOptionSingle<Vec2d>(Vec2d(0,0)) {}
+ explicit ConfigOptionPoint(const Vec2d &value) : ConfigOptionSingle<Vec2d>(value) {}
static ConfigOptionType static_type() { return coPoint; }
ConfigOptionType type() const override { return static_type(); }
@@ -635,30 +637,28 @@ public:
std::string serialize() const override
{
std::ostringstream ss;
- ss << this->value.x;
+ ss << this->value(0);
ss << ",";
- ss << this->value.y;
+ ss << this->value(1);
return ss.str();
}
bool deserialize(const std::string &str, bool append = false) override
{
UNUSED(append);
- std::istringstream iss(str);
- iss >> this->value.x;
- iss.ignore(std::numeric_limits<std::streamsize>::max(), ',');
- iss.ignore(std::numeric_limits<std::streamsize>::max(), 'x');
- iss >> this->value.y;
- return true;
+ char dummy;
+ return sscanf(str.data(), " %lf , %lf %c", &this->value(0), &this->value(1), &dummy) == 2 ||
+ sscanf(str.data(), " %lf x %lf %c", &this->value(0), &this->value(1), &dummy) == 2;
}
};
-class ConfigOptionPoints : public ConfigOptionVector<Pointf>
+class ConfigOptionPoints : public ConfigOptionVector<Vec2d>
{
public:
- ConfigOptionPoints() : ConfigOptionVector<Pointf>() {}
- explicit ConfigOptionPoints(size_t n, const Pointf &value) : ConfigOptionVector<Pointf>(n, value) {}
- explicit ConfigOptionPoints(std::initializer_list<Pointf> il) : ConfigOptionVector<Pointf>(std::move(il)) {}
+ ConfigOptionPoints() : ConfigOptionVector<Vec2d>() {}
+ explicit ConfigOptionPoints(size_t n, const Vec2d &value) : ConfigOptionVector<Vec2d>(n, value) {}
+ explicit ConfigOptionPoints(std::initializer_list<Vec2d> il) : ConfigOptionVector<Vec2d>(std::move(il)) {}
+ explicit ConfigOptionPoints(const std::vector<Vec2d> &values) : ConfigOptionVector<Vec2d>(values) {}
static ConfigOptionType static_type() { return coPoints; }
ConfigOptionType type() const override { return static_type(); }
@@ -671,9 +671,9 @@ public:
std::ostringstream ss;
for (Pointfs::const_iterator it = this->values.begin(); it != this->values.end(); ++it) {
if (it - this->values.begin() != 0) ss << ",";
- ss << it->x;
+ ss << (*it)(0);
ss << "x";
- ss << it->y;
+ ss << (*it)(1);
}
return ss.str();
}
@@ -696,13 +696,13 @@ public:
std::istringstream is(str);
std::string point_str;
while (std::getline(is, point_str, ',')) {
- Pointf point;
+ Vec2d point(Vec2d::Zero());
std::istringstream iss(point_str);
std::string coord_str;
if (std::getline(iss, coord_str, 'x')) {
- std::istringstream(coord_str) >> point.x;
+ std::istringstream(coord_str) >> point(0);
if (std::getline(iss, coord_str, 'x')) {
- std::istringstream(coord_str) >> point.y;
+ std::istringstream(coord_str) >> point(1);
}
}
this->values.push_back(point);
@@ -821,12 +821,7 @@ public:
bool deserialize(const std::string &str, bool append = false) override
{
UNUSED(append);
- const t_config_enum_values &enum_keys_map = ConfigOptionEnum<T>::get_enum_values();
- auto it = enum_keys_map.find(str);
- if (it == enum_keys_map.end())
- return false;
- this->value = static_cast<T>(it->second);
- return true;
+ return from_string(str, this->value);
}
static bool has(T value)
@@ -838,7 +833,7 @@ public:
}
// Map from an enum name to an enum integer value.
- static t_config_enum_names& get_enum_names()
+ static const t_config_enum_names& get_enum_names()
{
static t_config_enum_names names;
if (names.empty()) {
@@ -855,7 +850,17 @@ public:
return names;
}
// Map from an enum name to an enum integer value.
- static t_config_enum_values& get_enum_values();
+ static const t_config_enum_values& get_enum_values();
+
+ static bool from_string(const std::string &str, T &value)
+ {
+ const t_config_enum_values &enum_keys_map = ConfigOptionEnum<T>::get_enum_values();
+ auto it = enum_keys_map.find(str);
+ if (it == enum_keys_map.end())
+ return false;
+ value = static_cast<T>(it->second);
+ return true;
+ }
};
// Generic enum configuration value.
@@ -900,7 +905,7 @@ public:
// What type? bool, int, string etc.
ConfigOptionType type = coNone;
// Default value of this option. The default value object is owned by ConfigDef, it is released in its destructor.
- ConfigOption *default_value = nullptr;
+ const ConfigOption *default_value = nullptr;
// Usually empty.
// Special values - "i_enum_open", "f_enum_open" to provide combo box for int or float selection,
@@ -958,7 +963,7 @@ public:
std::vector<std::string> enum_labels;
// For enums (when type == coEnum). Maps enum_values to enums.
// Initialized by ConfigOptionEnum<xxx>::get_enum_values()
- t_config_enum_values *enum_keys_map = nullptr;
+ const t_config_enum_values *enum_keys_map = nullptr;
bool has_enum_value(const std::string &value) const {
for (const std::string &v : enum_values)
@@ -1030,7 +1035,7 @@ public:
TYPE* option(const t_config_option_key &opt_key, bool create = false)
{
ConfigOption *opt = this->optptr(opt_key, create);
- assert(opt == nullptr || opt->type() == TYPE::static_type());
+// assert(opt == nullptr || opt->type() == TYPE::static_type());
return (opt == nullptr || opt->type() != TYPE::static_type()) ? nullptr : static_cast<TYPE*>(opt);
}
template<typename TYPE>
@@ -1046,6 +1051,10 @@ public:
void apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent = false);
bool equals(const ConfigBase &other) const { return this->diff(other).empty(); }
t_config_option_keys diff(const ConfigBase &other) const;
+ // Use deep_diff to correct return of changed options,
+ // considering individual options for each extruder
+ t_config_option_keys deep_diff(const ConfigBase &other) const;
+ t_config_option_keys equal(const ConfigBase &other) const;
std::string serialize(const t_config_option_key &opt_key) const;
// Set a configuration value from a string, it will call an overridable handle_legacy()
// to resolve renamed and removed configuration keys.
@@ -1232,17 +1241,22 @@ protected:
};
/// Specialization of std::exception to indicate that an unknown config option has been encountered.
-class UnknownOptionException : public std::exception
-{
+class UnknownOptionException : public std::runtime_error {
public:
- const char* what() const noexcept override { return "Unknown config option"; }
+ UnknownOptionException() :
+ std::runtime_error("Unknown option exception") {}
+ UnknownOptionException(const std::string &opt_key) :
+ std::runtime_error(std::string("Unknown option exception: ") + opt_key) {}
};
/// Indicate that the ConfigBase derived class does not provide config definition (the method def() returns null).
-class NoDefinitionException : public std::exception
+class NoDefinitionException : public std::runtime_error
{
public:
- const char* what() const noexcept override { return "No config definition"; }
+ NoDefinitionException() :
+ std::runtime_error("No definition exception") {}
+ NoDefinitionException(const std::string &opt_key) :
+ std::runtime_error(std::string("No definition exception: ") + opt_key) {}
};
}