Added "Notes" page to the filament configuration.

Added "filament_max_volumetric_speed", a cap on the maximum volumetric
extrusion role, filament specific. This is very useful when mixing
rigid filament with a soft filament.

Extended the import / export of multi-string values into configuration
values, including the test cases. Multi-line strings will be enclosed
into quotes, quotes escaped using a C-style escape sequences. Single
word strings could still be stored without quotes.
This commit is contained in:
bubnikv 2016-11-01 13:41:24 +01:00
parent 4e66ed81d2
commit 3d3654707b
7 changed files with 280 additions and 46 deletions

View file

@ -18,6 +18,11 @@ namespace Slic3r {
typedef std::string t_config_option_key;
typedef std::vector<std::string> t_config_option_keys;
extern std::string escape_string_cstyle(const std::string &str);
extern std::string escape_strings_cstyle(const std::vector<std::string> &strs);
extern bool unescape_string_cstyle(const std::string &str, std::string &out);
extern bool unescape_strings_cstyle(const std::string &str, std::vector<std::string> &out);
// A generic value of a configuration option.
class ConfigOption {
public:
@ -112,6 +117,7 @@ class ConfigOptionFloats : public ConfigOptionVector<double>
std::vector<std::string> vserialize() const {
std::vector<std::string> vv;
vv.reserve(this->values.size());
for (std::vector<double>::const_iterator it = this->values.begin(); it != this->values.end(); ++it) {
std::ostringstream ss;
ss << *it;
@ -171,6 +177,7 @@ class ConfigOptionInts : public ConfigOptionVector<int>
std::vector<std::string> vserialize() const {
std::vector<std::string> vv;
vv.reserve(this->values.size());
for (std::vector<int>::const_iterator it = this->values.begin(); it != this->values.end(); ++it) {
std::ostringstream ss;
ss << *it;
@ -199,29 +206,12 @@ class ConfigOptionString : public ConfigOptionSingle<std::string>
ConfigOptionString() : ConfigOptionSingle<std::string>("") {};
ConfigOptionString(std::string _value) : ConfigOptionSingle<std::string>(_value) {};
std::string serialize() const {
std::string str = this->value;
// s/\R/\\n/g
size_t pos = 0;
while ((pos = str.find("\n", pos)) != std::string::npos || (pos = str.find("\r", pos)) != std::string::npos) {
str.replace(pos, 1, "\\n");
pos += 2; // length of "\\n"
}
return str;
};
std::string serialize() const {
return escape_string_cstyle(this->value);
}
bool deserialize(std::string str) {
// s/\\n/\n/g
size_t pos = 0;
while ((pos = str.find("\\n", pos)) != std::string::npos) {
str.replace(pos, 2, "\n");
pos += 1; // length of "\n"
}
this->value = str;
return true;
return unescape_string_cstyle(str, this->value);
};
};
@ -231,12 +221,7 @@ class ConfigOptionStrings : public ConfigOptionVector<std::string>
public:
std::string serialize() const {
std::ostringstream ss;
for (std::vector<std::string>::const_iterator it = this->values.begin(); it != this->values.end(); ++it) {
if (it - this->values.begin() != 0) ss << ";";
ss << *it;
}
return ss.str();
return escape_strings_cstyle(this->values);
};
std::vector<std::string> vserialize() const {
@ -244,13 +229,7 @@ class ConfigOptionStrings : public ConfigOptionVector<std::string>
};
bool deserialize(std::string str) {
this->values.clear();
std::istringstream is(str);
std::string item_str;
while (std::getline(is, item_str, ';')) {
this->values.push_back(item_str);
}
return true;
return unescape_strings_cstyle(str, this->values);
};
};
@ -637,8 +616,8 @@ class ConfigBase
std::string serialize(const t_config_option_key &opt_key) const;
bool set_deserialize(const t_config_option_key &opt_key, std::string str);
double get_abs_value(const t_config_option_key &opt_key);
double get_abs_value(const t_config_option_key &opt_key, double ratio_over);
double get_abs_value(const t_config_option_key &opt_key) const;
double get_abs_value(const t_config_option_key &opt_key, double ratio_over) const;
void setenv_();
};