From 3fac8cd77e76da982219049629f3d9190cfcfbbf Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 7 Dec 2015 19:39:49 +0100 Subject: [PATCH] Large refactoring of the Config classes --- xs/src/libslic3r/Config.cpp | 136 ++++++++---- xs/src/libslic3r/Config.hpp | 128 +++++++----- xs/src/libslic3r/PlaceholderParser.cpp | 36 ++-- xs/src/libslic3r/PlaceholderParser.hpp | 2 +- xs/src/libslic3r/PrintConfig.cpp | 275 ++++++++++++++++++++++--- xs/src/libslic3r/PrintConfig.hpp | 220 +++----------------- xs/t/15_config.t | 1 + xs/xsp/Config.xsp | 5 +- 8 files changed, 467 insertions(+), 336 deletions(-) diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 366291ff2..102a07a2f 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -19,6 +19,21 @@ operator!= (const ConfigOption &a, const ConfigOption &b) return !(a == b); } +ConfigDef::~ConfigDef() +{ + for (t_optiondef_map::iterator it = this->options.begin(); it != this->options.end(); ++it) { + if (it->second.default_value != NULL) + delete it->second.default_value; + } +} + +const ConfigOptionDef* +ConfigDef::get(const t_config_option_key &opt_key) const +{ + if (this->options.count(opt_key) == 0) return NULL; + return &const_cast(this)->options[opt_key]; +} + bool ConfigBase::has(const t_config_option_key &opt_key) { return (this->option(opt_key, false) != NULL); @@ -72,10 +87,10 @@ ConfigBase::serialize(const t_config_option_key &opt_key) const { bool ConfigBase::set_deserialize(const t_config_option_key &opt_key, std::string str) { - if (this->def->count(opt_key) == 0) throw "Calling set_deserialize() on unknown option"; - ConfigOptionDef* optdef = &(*this->def)[opt_key]; + const ConfigOptionDef* optdef = this->def->get(opt_key); + if (optdef == NULL) throw "Calling set_deserialize() on unknown option"; if (!optdef->shortcut.empty()) { - for (std::vector::iterator it = optdef->shortcut.begin(); it != optdef->shortcut.end(); ++it) { + for (std::vector::const_iterator it = optdef->shortcut.begin(); it != optdef->shortcut.end(); ++it) { if (!this->set_deserialize(*it, str)) return false; } return true; @@ -91,8 +106,8 @@ ConfigBase::get_abs_value(const t_config_option_key &opt_key) { ConfigOption* opt = this->option(opt_key, false); if (ConfigOptionFloatOrPercent* optv = dynamic_cast(opt)) { // get option definition - assert(this->def->count(opt_key) != 0); - ConfigOptionDef* def = &(*this->def)[opt_key]; + const ConfigOptionDef* def = this->def->get(opt_key); + assert(def != NULL); // compute absolute value over the absolute value of the base option return optv->get_abs_value(this->get_abs_value(def->ratio_over)); @@ -150,44 +165,57 @@ SV* ConfigBase::get(t_config_option_key opt_key) { ConfigOption* opt = this->option(opt_key); if (opt == NULL) return &PL_sv_undef; - if (ConfigOptionFloat* optv = dynamic_cast(opt)) { + + const ConfigOptionDef* def = this->def->get(opt_key); + if (def->type == coFloat) { + ConfigOptionFloat* optv = dynamic_cast(opt); return newSVnv(optv->value); - } else if (ConfigOptionPercent* optv = dynamic_cast(opt)) { - return newSVnv(optv->value); - } else if (ConfigOptionFloats* optv = dynamic_cast(opt)) { + } else if (def->type == coFloats) { + ConfigOptionFloats* optv = dynamic_cast(opt); AV* av = newAV(); av_fill(av, optv->values.size()-1); for (std::vector::iterator it = optv->values.begin(); it != optv->values.end(); ++it) av_store(av, it - optv->values.begin(), newSVnv(*it)); return newRV_noinc((SV*)av); - } else if (ConfigOptionInt* optv = dynamic_cast(opt)) { + } else if (def->type == coPercent) { + ConfigOptionPercent* optv = dynamic_cast(opt); + return newSVnv(optv->value); + } else if (def->type == coInt) { + ConfigOptionInt* optv = dynamic_cast(opt); return newSViv(optv->value); - } else if (ConfigOptionInts* optv = dynamic_cast(opt)) { + } else if (def->type == coInts) { + ConfigOptionInts* optv = dynamic_cast(opt); AV* av = newAV(); av_fill(av, optv->values.size()-1); for (std::vector::iterator it = optv->values.begin(); it != optv->values.end(); ++it) av_store(av, it - optv->values.begin(), newSViv(*it)); return newRV_noinc((SV*)av); - } else if (ConfigOptionString* optv = dynamic_cast(opt)) { + } else if (def->type == coString) { + ConfigOptionString* optv = dynamic_cast(opt); // we don't serialize() because that would escape newlines return newSVpvn_utf8(optv->value.c_str(), optv->value.length(), true); - } else if (ConfigOptionStrings* optv = dynamic_cast(opt)) { + } else if (def->type == coStrings) { + ConfigOptionStrings* optv = dynamic_cast(opt); AV* av = newAV(); av_fill(av, optv->values.size()-1); for (std::vector::iterator it = optv->values.begin(); it != optv->values.end(); ++it) av_store(av, it - optv->values.begin(), newSVpvn_utf8(it->c_str(), it->length(), true)); return newRV_noinc((SV*)av); - } else if (ConfigOptionPoint* optv = dynamic_cast(opt)) { - return perl_to_SV_clone_ref(optv->point); - } else if (ConfigOptionPoints* optv = dynamic_cast(opt)) { + } else if (def->type == coPoint) { + ConfigOptionPoint* optv = dynamic_cast(opt); + return perl_to_SV_clone_ref(optv->value); + } else if (def->type == coPoints) { + ConfigOptionPoints* optv = dynamic_cast(opt); AV* av = newAV(); av_fill(av, optv->values.size()-1); for (Pointfs::iterator it = optv->values.begin(); it != optv->values.end(); ++it) av_store(av, it - optv->values.begin(), perl_to_SV_clone_ref(*it)); return newRV_noinc((SV*)av); - } else if (ConfigOptionBool* optv = dynamic_cast(opt)) { + } else if (def->type == coBool) { + ConfigOptionBool* optv = dynamic_cast(opt); return newSViv(optv->value ? 1 : 0); - } else if (ConfigOptionBools* optv = dynamic_cast(opt)) { + } else if (def->type == coBools) { + ConfigOptionBools* optv = dynamic_cast(opt); AV* av = newAV(); av_fill(av, optv->values.size()-1); for (std::vector::iterator it = optv->values.begin(); it != optv->values.end(); ++it) @@ -204,17 +232,23 @@ ConfigBase::get_at(t_config_option_key opt_key, size_t i) { ConfigOption* opt = this->option(opt_key); if (opt == NULL) return &PL_sv_undef; - if (ConfigOptionFloats* optv = dynamic_cast(opt)) { + const ConfigOptionDef* def = this->def->get(opt_key); + if (def->type == coFloats) { + ConfigOptionFloats* optv = dynamic_cast(opt); return newSVnv(optv->get_at(i)); - } else if (ConfigOptionInts* optv = dynamic_cast(opt)) { + } else if (def->type == coInts) { + ConfigOptionInts* optv = dynamic_cast(opt); return newSViv(optv->get_at(i)); - } else if (ConfigOptionStrings* optv = dynamic_cast(opt)) { + } else if (def->type == coStrings) { + ConfigOptionStrings* optv = dynamic_cast(opt); // we don't serialize() because that would escape newlines std::string val = optv->get_at(i); return newSVpvn_utf8(val.c_str(), val.length(), true); - } else if (ConfigOptionPoints* optv = dynamic_cast(opt)) { + } else if (def->type == coPoints) { + ConfigOptionPoints* optv = dynamic_cast(opt); return perl_to_SV_clone_ref(optv->get_at(i)); - } else if (ConfigOptionBools* optv = dynamic_cast(opt)) { + } else if (def->type == coBools) { + ConfigOptionBools* optv = dynamic_cast(opt); return newSViv(optv->get_at(i) ? 1 : 0); } else { return &PL_sv_undef; @@ -226,10 +260,13 @@ ConfigBase::set(t_config_option_key opt_key, SV* value) { ConfigOption* opt = this->option(opt_key, true); if (opt == NULL) CONFESS("Trying to set non-existing option"); - if (ConfigOptionFloat* optv = dynamic_cast(opt)) { + const ConfigOptionDef* def = this->def->get(opt_key); + if (def->type == coFloat) { if (!looks_like_number(value)) return false; + ConfigOptionFloat* optv = dynamic_cast(opt); optv->value = SvNV(value); - } else if (ConfigOptionFloats* optv = dynamic_cast(opt)) { + } else if (def->type == coFloats) { + ConfigOptionFloats* optv = dynamic_cast(opt); std::vector values; AV* av = (AV*)SvRV(value); const size_t len = av_len(av)+1; @@ -239,10 +276,12 @@ ConfigBase::set(t_config_option_key opt_key, SV* value) { values.push_back(SvNV(*elem)); } optv->values = values; - } else if (ConfigOptionInt* optv = dynamic_cast(opt)) { + } else if (def->type == coInt) { if (!looks_like_number(value)) return false; + ConfigOptionInt* optv = dynamic_cast(opt); optv->value = SvIV(value); - } else if (ConfigOptionInts* optv = dynamic_cast(opt)) { + } else if (def->type == coInts) { + ConfigOptionInts* optv = dynamic_cast(opt); std::vector values; AV* av = (AV*)SvRV(value); const size_t len = av_len(av)+1; @@ -252,9 +291,11 @@ ConfigBase::set(t_config_option_key opt_key, SV* value) { values.push_back(SvIV(*elem)); } optv->values = values; - } else if (ConfigOptionString* optv = dynamic_cast(opt)) { + } else if (def->type == coString) { + ConfigOptionString* optv = dynamic_cast(opt); optv->value = std::string(SvPV_nolen(value), SvCUR(value)); - } else if (ConfigOptionStrings* optv = dynamic_cast(opt)) { + } else if (def->type == coStrings) { + ConfigOptionStrings* optv = dynamic_cast(opt); optv->values.clear(); AV* av = (AV*)SvRV(value); const size_t len = av_len(av)+1; @@ -263,9 +304,11 @@ ConfigBase::set(t_config_option_key opt_key, SV* value) { if (elem == NULL) return false; optv->values.push_back(std::string(SvPV_nolen(*elem), SvCUR(*elem))); } - } else if (ConfigOptionPoint* optv = dynamic_cast(opt)) { - return optv->point.from_SV_check(value); - } else if (ConfigOptionPoints* optv = dynamic_cast(opt)) { + } else if (def->type == coPoint) { + ConfigOptionPoint* optv = dynamic_cast(opt); + return optv->value.from_SV_check(value); + } else if (def->type == coPoints) { + ConfigOptionPoints* optv = dynamic_cast(opt); std::vector values; AV* av = (AV*)SvRV(value); const size_t len = av_len(av)+1; @@ -276,9 +319,11 @@ ConfigBase::set(t_config_option_key opt_key, SV* value) { values.push_back(point); } optv->values = values; - } else if (ConfigOptionBool* optv = dynamic_cast(opt)) { + } else if (def->type == coBool) { + ConfigOptionBool* optv = dynamic_cast(opt); optv->value = SvTRUE(value); - } else if (ConfigOptionBools* optv = dynamic_cast(opt)) { + } else if (def->type == coBools) { + ConfigOptionBools* optv = dynamic_cast(opt); optv->values.clear(); AV* av = (AV*)SvRV(value); const size_t len = av_len(av)+1; @@ -345,7 +390,8 @@ ConfigOption* DynamicConfig::option(const t_config_option_key &opt_key, bool create) { if (this->options.count(opt_key) == 0) { if (create) { - ConfigOptionDef* optdef = &(*this->def)[opt_key]; + const ConfigOptionDef* optdef = this->def->get(opt_key); + assert(optdef != NULL); ConfigOption* opt; if (optdef->type == coFloat) { opt = new ConfigOptionFloat (); @@ -415,10 +461,24 @@ DynamicConfig::erase(const t_config_option_key &opt_key) { this->options.erase(opt_key); } +void +StaticConfig::set_defaults() +{ + // use defaults from definition + if (this->def == NULL) return; + t_config_option_keys keys = this->keys(); + for (t_config_option_keys::const_iterator it = keys.begin(); it != keys.end(); ++it) { + const ConfigOptionDef* def = this->def->get(*it); + + if (def->default_value != NULL) + this->option(*it)->set(*def->default_value); + } +} + t_config_option_keys StaticConfig::keys() const { t_config_option_keys keys; - for (t_optiondef_map::const_iterator it = this->def->begin(); it != this->def->end(); ++it) { + for (t_optiondef_map::const_iterator it = this->def->options.begin(); it != this->def->options.end(); ++it) { const ConfigOption* opt = this->option(it->first); if (opt != NULL) keys.push_back(it->first); } @@ -434,9 +494,9 @@ StaticConfig::option(const t_config_option_key &opt_key) const #ifdef SLIC3RXS bool StaticConfig::set(t_config_option_key opt_key, SV* value) { - ConfigOptionDef* optdef = &(*this->def)[opt_key]; + const ConfigOptionDef* optdef = this->def->get(opt_key); if (!optdef->shortcut.empty()) { - for (std::vector::iterator it = optdef->shortcut.begin(); it != optdef->shortcut.end(); ++it) { + for (std::vector::const_iterator it = optdef->shortcut.begin(); it != optdef->shortcut.end(); ++it) { if (!this->set(*it, value)) return false; } return true; diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index 2c997817a..126049579 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -22,12 +22,28 @@ class ConfigOption { virtual ~ConfigOption() {}; virtual std::string serialize() const = 0; virtual bool deserialize(std::string str) = 0; + virtual void set(const ConfigOption &option) = 0; virtual int getInt() const { return 0; }; + virtual double getFloat() const { return 0; }; + virtual bool getBool() const { return false; }; virtual void setInt(int val) {}; friend bool operator== (const ConfigOption &a, const ConfigOption &b); friend bool operator!= (const ConfigOption &a, const ConfigOption &b); }; +template +class ConfigOptionSingle : public ConfigOption { + public: + T value; + ConfigOptionSingle(T _value) : value(_value) {}; + operator T() const { return this->value; }; + + void set(const ConfigOption &option) { + const ConfigOptionSingle* other = dynamic_cast< const ConfigOptionSingle* >(&option); + if (other != NULL) this->value = other->value; + }; +}; + class ConfigOptionVectorBase : public ConfigOption { public: virtual ~ConfigOptionVectorBase() {}; @@ -41,6 +57,11 @@ class ConfigOptionVector : public ConfigOptionVectorBase virtual ~ConfigOptionVector() {}; std::vector values; + void set(const ConfigOption &option) { + const const ConfigOptionVector* other = dynamic_cast< const ConfigOptionVector* >(&option); + if (other != NULL) this->values = other->values; + }; + T get_at(size_t i) const { try { return this->values.at(i); @@ -50,14 +71,13 @@ class ConfigOptionVector : public ConfigOptionVectorBase }; }; -class ConfigOptionFloat : public ConfigOption +class ConfigOptionFloat : public ConfigOptionSingle { public: - double value; // use double instead of float for preserving compatibility with values coming from Perl - ConfigOptionFloat() : value(0) {}; + ConfigOptionFloat() : ConfigOptionSingle(0) {}; + ConfigOptionFloat(double _value) : ConfigOptionSingle(_value) {}; - operator float() const { return this->value; }; - operator double() const { return this->value; }; + double getFloat() const { return this->value; }; std::string serialize() const { std::ostringstream ss; @@ -108,13 +128,12 @@ class ConfigOptionFloats : public ConfigOptionVector }; }; -class ConfigOptionInt : public ConfigOption +class ConfigOptionInt : public ConfigOptionSingle { public: - int value; - ConfigOptionInt() : value(0) {}; + ConfigOptionInt() : ConfigOptionSingle(0) {}; + ConfigOptionInt(double _value) : ConfigOptionSingle(_value) {}; - operator int() const { return this->value; }; int getInt() const { return this->value; }; void setInt(int val) { this->value = val; }; @@ -167,13 +186,11 @@ class ConfigOptionInts : public ConfigOptionVector }; }; -class ConfigOptionString : public ConfigOption +class ConfigOptionString : public ConfigOptionSingle { public: - std::string value; - ConfigOptionString() : value("") {}; - - operator std::string() const { return this->value; }; + ConfigOptionString() : ConfigOptionSingle("") {}; + ConfigOptionString(std::string _value) : ConfigOptionSingle(_value) {}; std::string serialize() const { std::string str = this->value; @@ -230,11 +247,11 @@ class ConfigOptionStrings : public ConfigOptionVector }; }; -class ConfigOptionPercent : public ConfigOption +class ConfigOptionPercent : public ConfigOptionFloat { public: - double value; - ConfigOptionPercent() : value(0) {}; + ConfigOptionPercent() : ConfigOptionFloat(0) {}; + ConfigOptionPercent(double _value) : ConfigOptionFloat(_value) {}; double get_abs_value(double ratio_over) const { return ratio_over * this->value / 100; @@ -255,12 +272,21 @@ class ConfigOptionPercent : public ConfigOption }; }; -class ConfigOptionFloatOrPercent : public ConfigOption +class ConfigOptionFloatOrPercent : public ConfigOptionPercent { public: - double value; bool percent; - ConfigOptionFloatOrPercent() : value(0), percent(false) {}; + ConfigOptionFloatOrPercent() : ConfigOptionPercent(0), percent(false) {}; + ConfigOptionFloatOrPercent(double _value, bool _percent) + : ConfigOptionPercent(_value), percent(_percent) {}; + + void set(const ConfigOption &option) { + const ConfigOptionFloatOrPercent* other = dynamic_cast< const ConfigOptionFloatOrPercent* >(&option); + if (other != NULL) { + this->value = other->value; + this->percent = other->percent; + } + }; double get_abs_value(double ratio_over) const { if (this->percent) { @@ -285,28 +311,26 @@ class ConfigOptionFloatOrPercent : public ConfigOption }; }; -class ConfigOptionPoint : public ConfigOption +class ConfigOptionPoint : public ConfigOptionSingle { public: - Pointf point; - ConfigOptionPoint() : point(Pointf(0,0)) {}; - - operator Pointf() const { return this->point; }; + ConfigOptionPoint() : ConfigOptionSingle(Pointf(0,0)) {}; + ConfigOptionPoint(Pointf _value) : ConfigOptionSingle(_value) {}; std::string serialize() const { std::ostringstream ss; - ss << this->point.x; + ss << this->value.x; ss << ","; - ss << this->point.y; + ss << this->value.y; return ss.str(); }; bool deserialize(std::string str) { std::istringstream iss(str); - iss >> this->point.x; + iss >> this->value.x; iss.ignore(std::numeric_limits::max(), ','); iss.ignore(std::numeric_limits::max(), 'x'); - iss >> this->point.y; + iss >> this->value.y; return true; }; }; @@ -356,13 +380,13 @@ class ConfigOptionPoints : public ConfigOptionVector }; }; -class ConfigOptionBool : public ConfigOption +class ConfigOptionBool : public ConfigOptionSingle { public: - bool value; - ConfigOptionBool() : value(false) {}; + ConfigOptionBool() : ConfigOptionSingle(false) {}; + ConfigOptionBool(bool _value) : ConfigOptionSingle(_value) {}; - operator bool() const { return this->value; }; + bool getBool() const { return this->value; }; std::string serialize() const { return std::string(this->value ? "1" : "0"); @@ -411,12 +435,12 @@ class ConfigOptionBools : public ConfigOptionVector typedef std::map t_config_enum_values; template -class ConfigOptionEnum : public ConfigOption +class ConfigOptionEnum : public ConfigOptionSingle { public: - T value; - - operator T() const { return this->value; }; + // by default, use the first value (0) of the T enum type + ConfigOptionEnum() : ConfigOptionSingle(static_cast(0)) {}; + ConfigOptionEnum(T _value) : ConfigOptionSingle(_value) {}; std::string serialize() const { t_config_enum_values enum_keys_map = ConfigOptionEnum::get_enum_values(); @@ -438,16 +462,13 @@ class ConfigOptionEnum : public ConfigOption /* We use this one in DynamicConfig objects, otherwise it's better to use the specialized ConfigOptionEnum containers. */ -class ConfigOptionEnumGeneric : public ConfigOption +class ConfigOptionEnumGeneric : public ConfigOptionInt { public: - int value; - t_config_enum_values* keys_map; - - operator int() const { return this->value; }; + const t_config_enum_values* keys_map; std::string serialize() const { - for (t_config_enum_values::iterator it = this->keys_map->begin(); it != this->keys_map->end(); ++it) { + for (t_config_enum_values::const_iterator it = this->keys_map->begin(); it != this->keys_map->end(); ++it) { if (it->second == this->value) return it->first; } return ""; @@ -455,7 +476,7 @@ class ConfigOptionEnumGeneric : public ConfigOption bool deserialize(std::string str) { if (this->keys_map->count(str) == 0) return false; - this->value = (*this->keys_map)[str]; + this->value = (*const_cast(this->keys_map))[str]; return true; }; }; @@ -481,6 +502,7 @@ class ConfigOptionDef { public: ConfigOptionType type; + ConfigOption* default_value; std::string gui_type; std::string gui_flags; std::string label; @@ -503,17 +525,25 @@ class ConfigOptionDef std::vector enum_labels; t_config_enum_values enum_keys_map; - ConfigOptionDef() : type(coNone), + ConfigOptionDef() : type(coNone), default_value(NULL), multiline(false), full_width(false), readonly(false), height(-1), width(-1), min(INT_MIN), max(INT_MAX) {}; }; typedef std::map t_optiondef_map; +class ConfigDef +{ + public: + t_optiondef_map options; + ~ConfigDef(); + const ConfigOptionDef* get(const t_config_option_key &opt_key) const; +}; + class ConfigBase { public: - t_optiondef_map* def; + const ConfigDef* def; ConfigBase() : def(NULL) {}; bool has(const t_config_option_key &opt_key); @@ -539,7 +569,7 @@ class ConfigBase #endif }; -class DynamicConfig : public ConfigBase +class DynamicConfig : public virtual ConfigBase { public: DynamicConfig() {}; @@ -558,12 +588,14 @@ class DynamicConfig : public ConfigBase t_options_map options; }; -class StaticConfig : public ConfigBase +class StaticConfig : public virtual ConfigBase { public: + StaticConfig() : ConfigBase() {}; t_config_option_keys keys() const; virtual ConfigOption* option(const t_config_option_key &opt_key, bool create = false) = 0; const ConfigOption* option(const t_config_option_key &opt_key) const; + void set_defaults(); #ifdef SLIC3RXS bool set(t_config_option_key opt_key, SV* value); diff --git a/xs/src/libslic3r/PlaceholderParser.cpp b/xs/src/libslic3r/PlaceholderParser.cpp index 983905703..4a73cd12b 100644 --- a/xs/src/libslic3r/PlaceholderParser.cpp +++ b/xs/src/libslic3r/PlaceholderParser.cpp @@ -41,40 +41,28 @@ PlaceholderParser::update_timestamp() this->set("second", timeinfo->tm_sec); } -void PlaceholderParser::apply_config(DynamicPrintConfig &config) +void PlaceholderParser::apply_config(const DynamicPrintConfig &config) { - // options that are set and aren't text-boxes - t_config_option_keys opt_keys; - for (t_optiondef_map::iterator i = config.def->begin(); - i != config.def->end(); ++i) - { - const t_config_option_key &key = i->first; - const ConfigOptionDef &def = i->second; - - if (config.has(key) && !def.multiline) { - opt_keys.push_back(key); - } - } - - for (t_config_option_keys::iterator i = opt_keys.begin(); - i != opt_keys.end(); ++i) - { - const t_config_option_key &key = *i; - const ConfigOption* opt = config.option(key); + t_config_option_keys opt_keys = config.keys(); + for (t_config_option_keys::const_iterator i = opt_keys.begin(); i != opt_keys.end(); ++i) { + const t_config_option_key &opt_key = *i; + const ConfigOptionDef* def = config.def->get(opt_key); + if (def->multiline) continue; + const ConfigOption* opt = config.option(opt_key); if (const ConfigOptionVectorBase* optv = dynamic_cast(opt)) { // set placeholders for options with multiple values // TODO: treat [bed_shape] as single, not multiple - this->set(key, optv->vserialize()); + this->set(opt_key, optv->vserialize()); } else if (const ConfigOptionPoint* optp = dynamic_cast(opt)) { - this->set(key, optp->serialize()); + this->set(opt_key, optp->serialize()); Pointf val = *optp; - this->set(key + "_X", val.x); - this->set(key + "_Y", val.y); + this->set(opt_key + "_X", val.x); + this->set(opt_key + "_Y", val.y); } else { // set single-value placeholders - this->set(key, opt->serialize()); + this->set(opt_key, opt->serialize()); } } } diff --git a/xs/src/libslic3r/PlaceholderParser.hpp b/xs/src/libslic3r/PlaceholderParser.hpp index 882b60a92..20c1ace48 100644 --- a/xs/src/libslic3r/PlaceholderParser.hpp +++ b/xs/src/libslic3r/PlaceholderParser.hpp @@ -22,7 +22,7 @@ class PlaceholderParser PlaceholderParser(); void update_timestamp(); - void apply_config(DynamicPrintConfig &config); + void apply_config(const DynamicPrintConfig &config); void apply_env_variables(); void set(const std::string &key, const std::string &value); void set(const std::string &key, int value); diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 93725d25b..34e3dd747 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -2,18 +2,27 @@ namespace Slic3r { -t_optiondef_map -PrintConfigDef::build_def() { - t_optiondef_map Options; +PrintConfigDef::PrintConfigDef() +{ + t_optiondef_map &Options = this->options; Options["avoid_crossing_perimeters"].type = coBool; Options["avoid_crossing_perimeters"].label = "Avoid crossing perimeters"; Options["avoid_crossing_perimeters"].tooltip = "Optimize travel moves in order to minimize the crossing of perimeters. This is mostly useful with Bowden extruders which suffer from oozing. This feature slows down both the print and the G-code generation."; Options["avoid_crossing_perimeters"].cli = "avoid-crossing-perimeters!"; + Options["avoid_crossing_perimeters"].default_value = new ConfigOptionBool(false); Options["bed_shape"].type = coPoints; Options["bed_shape"].label = "Bed shape"; - + { + ConfigOptionPoints* opt = new ConfigOptionPoints(); + opt->values.push_back(Pointf(0,0)); + opt->values.push_back(Pointf(200,0)); + opt->values.push_back(Pointf(200,200)); + opt->values.push_back(Pointf(0,200)); + Options["bed_shape"].default_value = opt; + } + Options["bed_temperature"].type = coInt; Options["bed_temperature"].label = "Other layers"; Options["bed_temperature"].tooltip = "Bed temperature for layers after the first one. Set this to zero to disable bed temperature control commands in the output."; @@ -21,6 +30,7 @@ PrintConfigDef::build_def() { Options["bed_temperature"].full_label = "Bed temperature"; Options["bed_temperature"].min = 0; Options["bed_temperature"].max = 300; + Options["bed_temperature"].default_value = new ConfigOptionInt(0); Options["before_layer_gcode"].type = coString; Options["before_layer_gcode"].label = "Before layer change G-code"; @@ -29,6 +39,7 @@ PrintConfigDef::build_def() { Options["before_layer_gcode"].multiline = true; Options["before_layer_gcode"].full_width = true; Options["before_layer_gcode"].height = 50; + Options["before_layer_gcode"].default_value = new ConfigOptionString(""); Options["bottom_solid_layers"].type = coInt; Options["bottom_solid_layers"].label = "Bottom"; @@ -37,6 +48,7 @@ PrintConfigDef::build_def() { Options["bottom_solid_layers"].cli = "bottom-solid-layers=i"; Options["bottom_solid_layers"].full_label = "Bottom solid layers"; Options["bottom_solid_layers"].min = 0; + Options["bottom_solid_layers"].default_value = new ConfigOptionInt(3); Options["bridge_acceleration"].type = coFloat; Options["bridge_acceleration"].label = "Bridge"; @@ -44,6 +56,7 @@ PrintConfigDef::build_def() { Options["bridge_acceleration"].sidetext = "mm/s²"; Options["bridge_acceleration"].cli = "bridge-acceleration=f"; Options["bridge_acceleration"].min = 0; + Options["bridge_acceleration"].default_value = new ConfigOptionFloat(0); Options["bridge_fan_speed"].type = coInt; Options["bridge_fan_speed"].label = "Bridges fan speed"; @@ -52,6 +65,7 @@ PrintConfigDef::build_def() { Options["bridge_fan_speed"].cli = "bridge-fan-speed=i"; Options["bridge_fan_speed"].min = 0; Options["bridge_fan_speed"].max = 100; + Options["bridge_fan_speed"].default_value = new ConfigOptionInt(100); Options["bridge_flow_ratio"].type = coFloat; Options["bridge_flow_ratio"].label = "Bridge flow ratio"; @@ -59,6 +73,7 @@ PrintConfigDef::build_def() { Options["bridge_flow_ratio"].tooltip = "This factor affects the amount of plastic for bridging. You can decrease it slightly to pull the extrudates and prevent sagging, although default settings are usually good and you should experiment with cooling (use a fan) before tweaking this."; Options["bridge_flow_ratio"].cli = "bridge-flow-ratio=f"; Options["bridge_flow_ratio"].min = 0; + Options["bridge_flow_ratio"].default_value = new ConfigOptionFloat(1); Options["bridge_speed"].type = coFloat; Options["bridge_speed"].label = "Bridges"; @@ -68,6 +83,7 @@ PrintConfigDef::build_def() { Options["bridge_speed"].cli = "bridge-speed=f"; Options["bridge_speed"].aliases.push_back("bridge_feed_rate"); Options["bridge_speed"].min = 0; + Options["bridge_speed"].default_value = new ConfigOptionFloat(60); Options["brim_width"].type = coFloat; Options["brim_width"].label = "Brim width"; @@ -75,16 +91,19 @@ PrintConfigDef::build_def() { Options["brim_width"].sidetext = "mm"; Options["brim_width"].cli = "brim-width=f"; Options["brim_width"].min = 0; + Options["brim_width"].default_value = new ConfigOptionFloat(0); Options["complete_objects"].type = coBool; Options["complete_objects"].label = "Complete individual objects"; Options["complete_objects"].tooltip = "When printing multiple objects or copies, this feature will complete each object before moving onto next one (and starting it from its bottom layer). This feature is useful to avoid the risk of ruined prints. Slic3r should warn and prevent you from extruder collisions, but beware."; Options["complete_objects"].cli = "complete-objects!"; + Options["complete_objects"].default_value = new ConfigOptionBool(false); Options["cooling"].type = coBool; Options["cooling"].label = "Enable auto cooling"; Options["cooling"].tooltip = "This flag enables the automatic cooling logic that adjusts print speed and fan speed according to layer printing time."; Options["cooling"].cli = "cooling!"; + Options["cooling"].default_value = new ConfigOptionBool(true); Options["default_acceleration"].type = coFloat; Options["default_acceleration"].label = "Default"; @@ -92,6 +111,7 @@ PrintConfigDef::build_def() { Options["default_acceleration"].sidetext = "mm/s²"; Options["default_acceleration"].cli = "default-acceleration=f"; Options["default_acceleration"].min = 0; + Options["default_acceleration"].default_value = new ConfigOptionFloat(0); Options["disable_fan_first_layers"].type = coInt; Options["disable_fan_first_layers"].label = "Disable fan for the first"; @@ -100,12 +120,14 @@ PrintConfigDef::build_def() { Options["disable_fan_first_layers"].cli = "disable-fan-first-layers=i"; Options["disable_fan_first_layers"].min = 0; Options["disable_fan_first_layers"].max = 1000; + Options["disable_fan_first_layers"].default_value = new ConfigOptionInt(3); Options["dont_support_bridges"].type = coBool; Options["dont_support_bridges"].label = "Don't support bridges"; Options["dont_support_bridges"].category = "Support material"; Options["dont_support_bridges"].tooltip = "Experimental option for preventing support material from being generated under bridged areas."; Options["dont_support_bridges"].cli = "dont-support-bridges!"; + Options["dont_support_bridges"].default_value = new ConfigOptionBool(true); Options["duplicate_distance"].type = coFloat; Options["duplicate_distance"].label = "Distance between copies"; @@ -114,6 +136,7 @@ PrintConfigDef::build_def() { Options["duplicate_distance"].cli = "duplicate-distance=f"; Options["duplicate_distance"].aliases.push_back("multiply_distance"); Options["duplicate_distance"].min = 0; + Options["duplicate_distance"].default_value = new ConfigOptionFloat(6); Options["end_gcode"].type = coString; Options["end_gcode"].label = "End G-code"; @@ -122,6 +145,7 @@ PrintConfigDef::build_def() { Options["end_gcode"].multiline = true; Options["end_gcode"].full_width = true; Options["end_gcode"].height = 120; + Options["end_gcode"].default_value = new ConfigOptionString("M104 S0 ; turn off temperature\nG28 X0 ; home X axis\nM84 ; disable motors\n"); Options["external_fill_pattern"].type = coEnum; Options["external_fill_pattern"].label = "Top/bottom fill pattern"; @@ -140,6 +164,7 @@ PrintConfigDef::build_def() { Options["external_fill_pattern"].enum_labels.push_back("Archimedean Chords"); Options["external_fill_pattern"].enum_labels.push_back("Octagram Spiral"); Options["external_fill_pattern"].aliases.push_back("solid_fill_pattern"); + Options["external_fill_pattern"].default_value = new ConfigOptionEnum(ipRectilinear); Options["external_perimeter_extrusion_width"].type = coFloatOrPercent; Options["external_perimeter_extrusion_width"].label = "External perimeters"; @@ -147,6 +172,7 @@ PrintConfigDef::build_def() { Options["external_perimeter_extrusion_width"].tooltip = "Set this to a non-zero value to set a manual extrusion width for external perimeters. If left zero, an automatic value will be used that maximizes accuracy of the external visible surfaces. If expressed as percentage (for example 200%) it will be computed over layer height."; Options["external_perimeter_extrusion_width"].sidetext = "mm or % (leave 0 for default)"; Options["external_perimeter_extrusion_width"].cli = "external-perimeter-extrusion-width=s"; + Options["external_perimeter_extrusion_width"].default_value = new ConfigOptionFloatOrPercent(0, false); Options["external_perimeter_speed"].type = coFloatOrPercent; Options["external_perimeter_speed"].label = "External perimeters"; @@ -156,18 +182,21 @@ PrintConfigDef::build_def() { Options["external_perimeter_speed"].cli = "external-perimeter-speed=s"; Options["external_perimeter_speed"].ratio_over = "perimeter_speed"; Options["external_perimeter_speed"].min = 0; + Options["external_perimeter_speed"].default_value = new ConfigOptionFloatOrPercent(50, true); Options["external_perimeters_first"].type = coBool; Options["external_perimeters_first"].label = "External perimeters first"; Options["external_perimeters_first"].category = "Layers and Perimeters"; Options["external_perimeters_first"].tooltip = "Print contour perimeters from the outermost one to the innermost one instead of the default inverse order."; Options["external_perimeters_first"].cli = "external-perimeters-first!"; + Options["external_perimeters_first"].default_value = new ConfigOptionBool(false); Options["extra_perimeters"].type = coBool; Options["extra_perimeters"].label = "Extra perimeters if needed"; Options["extra_perimeters"].category = "Layers and Perimeters"; Options["extra_perimeters"].tooltip = "Add more perimeters when needed for avoiding gaps in sloping walls."; Options["extra_perimeters"].cli = "extra-perimeters!"; + Options["extra_perimeters"].default_value = new ConfigOptionBool(true); Options["extruder"].type = coInt; Options["extruder"].gui_type = "i_enum_open"; @@ -188,6 +217,7 @@ PrintConfigDef::build_def() { Options["extruder_clearance_height"].sidetext = "mm"; Options["extruder_clearance_height"].cli = "extruder-clearance-height=f"; Options["extruder_clearance_height"].min = 0; + Options["extruder_clearance_height"].default_value = new ConfigOptionFloat(20); Options["extruder_clearance_radius"].type = coFloat; Options["extruder_clearance_radius"].label = "Radius"; @@ -195,34 +225,48 @@ PrintConfigDef::build_def() { Options["extruder_clearance_radius"].sidetext = "mm"; Options["extruder_clearance_radius"].cli = "extruder-clearance-radius=f"; Options["extruder_clearance_radius"].min = 0; + Options["extruder_clearance_radius"].default_value = new ConfigOptionFloat(20); Options["extruder_offset"].type = coPoints; Options["extruder_offset"].label = "Extruder offset"; Options["extruder_offset"].tooltip = "If your firmware doesn't handle the extruder displacement you need the G-code to take it into account. This option lets you specify the displacement of each extruder with respect to the first one. It expects positive coordinates (they will be subtracted from the XY coordinate)."; Options["extruder_offset"].sidetext = "mm"; Options["extruder_offset"].cli = "extruder-offset=s@"; + { + ConfigOptionPoints* opt = new ConfigOptionPoints(); + opt->values.push_back(Pointf(0,0)); + Options["extruder_offset"].default_value = opt; + } Options["extrusion_axis"].type = coString; Options["extrusion_axis"].label = "Extrusion axis"; Options["extrusion_axis"].tooltip = "Use this option to set the axis letter associated to your printer's extruder (usually E but some printers use A)."; Options["extrusion_axis"].cli = "extrusion-axis=s"; + Options["extrusion_axis"].default_value = new ConfigOptionString("E"); Options["extrusion_multiplier"].type = coFloats; Options["extrusion_multiplier"].label = "Extrusion multiplier"; Options["extrusion_multiplier"].tooltip = "This factor changes the amount of flow proportionally. You may need to tweak this setting to get nice surface finish and correct single wall widths. Usual values are between 0.9 and 1.1. If you think you need to change this more, check filament diameter and your firmware E steps."; Options["extrusion_multiplier"].cli = "extrusion-multiplier=f@"; - + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(1); + Options["extrusion_multiplier"].default_value = opt; + } + Options["extrusion_width"].type = coFloatOrPercent; Options["extrusion_width"].label = "Default extrusion width"; Options["extrusion_width"].category = "Extrusion Width"; Options["extrusion_width"].tooltip = "Set this to a non-zero value to set a manual extrusion width. If left to zero, Slic3r calculates a width automatically. If expressed as percentage (for example: 230%) it will be computed over layer height."; Options["extrusion_width"].sidetext = "mm or % (leave 0 for auto)"; Options["extrusion_width"].cli = "extrusion-width=s"; + Options["extrusion_width"].default_value = new ConfigOptionFloatOrPercent(0, false); Options["fan_always_on"].type = coBool; Options["fan_always_on"].label = "Keep fan always on"; Options["fan_always_on"].tooltip = "If this is enabled, fan will never be disabled and will be kept running at least at its minimum speed. Useful for PLA, harmful for ABS."; Options["fan_always_on"].cli = "fan-always-on!"; + Options["fan_always_on"].default_value = new ConfigOptionBool(false); Options["fan_below_layer_time"].type = coInt; Options["fan_below_layer_time"].label = "Enable fan if layer print time is below"; @@ -232,12 +276,18 @@ PrintConfigDef::build_def() { Options["fan_below_layer_time"].width = 60; Options["fan_below_layer_time"].min = 0; Options["fan_below_layer_time"].max = 1000; + Options["fan_below_layer_time"].default_value = new ConfigOptionInt(60); Options["filament_colour"].type = coStrings; Options["filament_colour"].label = "Color"; Options["filament_colour"].tooltip = "This is only used in the Slic3r interface as a visual help."; Options["filament_colour"].cli = "filament-color=s@"; Options["filament_colour"].gui_type = "color"; + { + ConfigOptionStrings* opt = new ConfigOptionStrings(); + opt->values.push_back("#FFFFFF"); + Options["filament_colour"].default_value = opt; + } Options["filament_diameter"].type = coFloats; Options["filament_diameter"].label = "Diameter"; @@ -245,9 +295,15 @@ PrintConfigDef::build_def() { Options["filament_diameter"].sidetext = "mm"; Options["filament_diameter"].cli = "filament-diameter=f@"; Options["filament_diameter"].min = 0; + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(3); + Options["filament_diameter"].default_value = opt; + } Options["filament_settings_id"].type = coString; - + Options["filament_settings_id"].default_value = new ConfigOptionString(""); + Options["fill_angle"].type = coInt; Options["fill_angle"].label = "Fill angle"; Options["fill_angle"].category = "Infill"; @@ -256,6 +312,7 @@ PrintConfigDef::build_def() { Options["fill_angle"].cli = "fill-angle=i"; Options["fill_angle"].min = 0; Options["fill_angle"].max = 359; + Options["fill_angle"].default_value = new ConfigOptionFloat(45); Options["fill_density"].type = coPercent; Options["fill_density"].gui_type = "f_enum_open"; @@ -295,6 +352,7 @@ PrintConfigDef::build_def() { Options["fill_density"].enum_labels.push_back("80%"); Options["fill_density"].enum_labels.push_back("90%"); Options["fill_density"].enum_labels.push_back("100%"); + Options["fill_density"].default_value = new ConfigOptionPercent(20); Options["fill_pattern"].type = coEnum; Options["fill_pattern"].label = "Fill pattern"; @@ -320,6 +378,7 @@ PrintConfigDef::build_def() { Options["fill_pattern"].enum_labels.push_back("Hilbert Curve"); Options["fill_pattern"].enum_labels.push_back("Archimedean Chords"); Options["fill_pattern"].enum_labels.push_back("Octagram Spiral"); + Options["fill_pattern"].default_value = new ConfigOptionEnum(ipHoneycomb); Options["first_layer_acceleration"].type = coFloat; Options["first_layer_acceleration"].label = "First layer"; @@ -327,6 +386,7 @@ PrintConfigDef::build_def() { Options["first_layer_acceleration"].sidetext = "mm/s²"; Options["first_layer_acceleration"].cli = "first-layer-acceleration=f"; Options["first_layer_acceleration"].min = 0; + Options["first_layer_acceleration"].default_value = new ConfigOptionFloat(0); Options["first_layer_bed_temperature"].type = coInt; Options["first_layer_bed_temperature"].label = "First layer"; @@ -334,6 +394,7 @@ PrintConfigDef::build_def() { Options["first_layer_bed_temperature"].cli = "first-layer-bed-temperature=i"; Options["first_layer_bed_temperature"].max = 0; Options["first_layer_bed_temperature"].max = 300; + Options["first_layer_bed_temperature"].default_value = new ConfigOptionInt(0); Options["first_layer_extrusion_width"].type = coFloatOrPercent; Options["first_layer_extrusion_width"].label = "First layer"; @@ -342,6 +403,7 @@ PrintConfigDef::build_def() { Options["first_layer_extrusion_width"].sidetext = "mm or % (leave 0 for default)"; Options["first_layer_extrusion_width"].cli = "first-layer-extrusion-width=s"; Options["first_layer_extrusion_width"].ratio_over = "first_layer_height"; + Options["first_layer_extrusion_width"].default_value = new ConfigOptionFloatOrPercent(200, true); Options["first_layer_height"].type = coFloatOrPercent; Options["first_layer_height"].label = "First layer height"; @@ -350,6 +412,7 @@ PrintConfigDef::build_def() { Options["first_layer_height"].sidetext = "mm or %"; Options["first_layer_height"].cli = "first-layer-height=s"; Options["first_layer_height"].ratio_over = "layer_height"; + Options["first_layer_height"].default_value = new ConfigOptionFloatOrPercent(0.35, false); Options["first_layer_speed"].type = coFloatOrPercent; Options["first_layer_speed"].label = "First layer speed"; @@ -357,6 +420,7 @@ PrintConfigDef::build_def() { Options["first_layer_speed"].sidetext = "mm/s or %"; Options["first_layer_speed"].cli = "first-layer-speed=s"; Options["first_layer_speed"].min = 0; + Options["first_layer_speed"].default_value = new ConfigOptionFloatOrPercent(30, false); Options["first_layer_temperature"].type = coInts; Options["first_layer_temperature"].label = "First layer"; @@ -364,7 +428,12 @@ PrintConfigDef::build_def() { Options["first_layer_temperature"].cli = "first-layer-temperature=i@"; Options["first_layer_temperature"].min = 0; Options["first_layer_temperature"].max = 400; - + { + ConfigOptionInts* opt = new ConfigOptionInts(); + opt->values.push_back(200); + Options["first_layer_temperature"].default_value = opt; + } + Options["gap_fill_speed"].type = coFloat; Options["gap_fill_speed"].label = "Gap fill"; Options["gap_fill_speed"].category = "Speed"; @@ -372,16 +441,19 @@ PrintConfigDef::build_def() { Options["gap_fill_speed"].sidetext = "mm/s"; Options["gap_fill_speed"].cli = "gap-fill-speed=f"; Options["gap_fill_speed"].min = 0; + Options["gap_fill_speed"].default_value = new ConfigOptionFloat(20); Options["gcode_arcs"].type = coBool; Options["gcode_arcs"].label = "Use native G-code arcs"; Options["gcode_arcs"].tooltip = "This experimental feature tries to detect arcs from segments and generates G2/G3 arc commands instead of multiple straight G1 commands."; Options["gcode_arcs"].cli = "gcode-arcs!"; + Options["gcode_arcs"].default_value = new ConfigOptionBool(0); Options["gcode_comments"].type = coBool; Options["gcode_comments"].label = "Verbose G-code"; Options["gcode_comments"].tooltip = "Enable this to get a commented G-code file, with each line explained by a descriptive text. If you print from SD card, the additional weight of the file could make your firmware slow down."; Options["gcode_comments"].cli = "gcode-comments!"; + Options["gcode_comments"].default_value = new ConfigOptionBool(0); Options["gcode_flavor"].type = coEnum; Options["gcode_flavor"].label = "G-code flavor"; @@ -402,6 +474,7 @@ PrintConfigDef::build_def() { Options["gcode_flavor"].enum_labels.push_back("Mach3/LinuxCNC"); Options["gcode_flavor"].enum_labels.push_back("Machinekit"); Options["gcode_flavor"].enum_labels.push_back("No extrusion"); + Options["gcode_flavor"].default_value = new ConfigOptionEnum(gcfRepRap); Options["infill_acceleration"].type = coFloat; Options["infill_acceleration"].label = "Infill"; @@ -409,6 +482,7 @@ PrintConfigDef::build_def() { Options["infill_acceleration"].sidetext = "mm/s²"; Options["infill_acceleration"].cli = "infill-acceleration=f"; Options["infill_acceleration"].min = 0; + Options["infill_acceleration"].default_value = new ConfigOptionFloat(0); Options["infill_every_layers"].type = coInt; Options["infill_every_layers"].label = "Combine infill every"; @@ -418,6 +492,7 @@ PrintConfigDef::build_def() { Options["infill_every_layers"].cli = "infill-every-layers=i"; Options["infill_every_layers"].full_label = "Combine infill every n layers"; Options["infill_every_layers"].min = 1; + Options["infill_every_layers"].default_value = new ConfigOptionInt(1); Options["infill_extruder"].type = coInt; Options["infill_extruder"].label = "Infill extruder"; @@ -425,6 +500,7 @@ PrintConfigDef::build_def() { Options["infill_extruder"].tooltip = "The extruder to use when printing infill."; Options["infill_extruder"].cli = "infill-extruder=i"; Options["infill_extruder"].min = 1; + Options["infill_extruder"].default_value = new ConfigOptionInt(1); Options["infill_extrusion_width"].type = coFloatOrPercent; Options["infill_extrusion_width"].label = "Infill"; @@ -432,17 +508,20 @@ PrintConfigDef::build_def() { Options["infill_extrusion_width"].tooltip = "Set this to a non-zero value to set a manual extrusion width for infill. You may want to use fatter extrudates to speed up the infill and make your parts stronger. If expressed as percentage (for example 90%) it will be computed over layer height."; Options["infill_extrusion_width"].sidetext = "mm or % (leave 0 for default)"; Options["infill_extrusion_width"].cli = "infill-extrusion-width=s"; + Options["infill_extrusion_width"].default_value = new ConfigOptionFloatOrPercent(0, false); Options["infill_first"].type = coBool; Options["infill_first"].label = "Infill before perimeters"; Options["infill_first"].tooltip = "This option will switch the print order of perimeters and infill, making the latter first."; Options["infill_first"].cli = "infill-first!"; + Options["infill_first"].default_value = new ConfigOptionBool(false); Options["infill_only_where_needed"].type = coBool; Options["infill_only_where_needed"].label = "Only infill where needed"; Options["infill_only_where_needed"].category = "Infill"; Options["infill_only_where_needed"].tooltip = "This option will limit infill to the areas actually needed for supporting ceilings (it will act as internal support material). If enabled, slows down the G-code generation due to the multiple checks involved."; Options["infill_only_where_needed"].cli = "infill-only-where-needed!"; + Options["infill_only_where_needed"].default_value = new ConfigOptionBool(false); Options["infill_overlap"].type = coFloatOrPercent; Options["infill_overlap"].label = "Infill/perimeters overlap"; @@ -451,6 +530,7 @@ PrintConfigDef::build_def() { Options["infill_overlap"].sidetext = "mm or %"; Options["infill_overlap"].cli = "infill-overlap=s"; Options["infill_overlap"].ratio_over = "perimeter_extrusion_width"; + Options["infill_overlap"].default_value = new ConfigOptionFloatOrPercent(15, true); Options["infill_speed"].type = coFloat; Options["infill_speed"].label = "Infill"; @@ -461,12 +541,14 @@ PrintConfigDef::build_def() { Options["infill_speed"].aliases.push_back("print_feed_rate"); Options["infill_speed"].aliases.push_back("infill_feed_rate"); Options["infill_speed"].min = 0; + Options["infill_speed"].default_value = new ConfigOptionFloat(80); Options["interface_shells"].type = coBool; Options["interface_shells"].label = "Interface shells"; Options["interface_shells"].tooltip = "Force the generation of solid shells between adjacent materials/volumes. Useful for multi-extruder prints with translucent materials or manual soluble support material."; Options["interface_shells"].cli = "interface-shells!"; Options["interface_shells"].category = "Layers and Perimeters"; + Options["interface_shells"].default_value = new ConfigOptionBool(false); Options["layer_gcode"].type = coString; Options["layer_gcode"].label = "After layer change G-code"; @@ -475,6 +557,7 @@ PrintConfigDef::build_def() { Options["layer_gcode"].multiline = true; Options["layer_gcode"].full_width = true; Options["layer_gcode"].height = 50; + Options["layer_gcode"].default_value = new ConfigOptionString(""); Options["layer_height"].type = coFloat; Options["layer_height"].label = "Layer height"; @@ -483,6 +566,7 @@ PrintConfigDef::build_def() { Options["layer_height"].sidetext = "mm"; Options["layer_height"].cli = "layer-height=f"; Options["layer_height"].min = 0; + Options["layer_height"].default_value = new ConfigOptionFloat(0.3); Options["max_fan_speed"].type = coInt; Options["max_fan_speed"].label = "Max"; @@ -491,6 +575,23 @@ PrintConfigDef::build_def() { Options["max_fan_speed"].cli = "max-fan-speed=i"; Options["max_fan_speed"].min = 0; Options["max_fan_speed"].max = 100; + Options["max_fan_speed"].default_value = new ConfigOptionInt(100); + + Options["max_print_speed"].type = coFloat; + Options["max_print_speed"].label = "Max print speed"; + Options["max_print_speed"].tooltip = "When setting other speed settings to 0 Slic3r will autocalculate the optimal speed in order to keep constant extruder pressure. This experimental setting is used to set the highest print speed you want to allow."; + Options["max_print_speed"].sidetext = "mm/s"; + Options["max_print_speed"].cli = "max-print-speed=f"; + Options["max_print_speed"].min = 1; + Options["max_print_speed"].default_value = new ConfigOptionFloat(80); + + Options["max_volumetric_speed"].type = coFloat; + Options["max_volumetric_speed"].label = "Max volumetric speed"; + Options["max_volumetric_speed"].tooltip = "This experimental setting is used to set the maximum volumetric speed your extruder supports."; + Options["max_volumetric_speed"].sidetext = "mm³/s"; + Options["max_volumetric_speed"].cli = "max-volumetric-speed=f"; + Options["max_volumetric_speed"].min = 0; + Options["max_volumetric_speed"].default_value = new ConfigOptionFloat(0); Options["min_fan_speed"].type = coInt; Options["min_fan_speed"].label = "Min"; @@ -499,27 +600,15 @@ PrintConfigDef::build_def() { Options["min_fan_speed"].cli = "min-fan-speed=i"; Options["min_fan_speed"].min = 0; Options["min_fan_speed"].max = 100; + Options["min_fan_speed"].default_value = new ConfigOptionInt(35); - Options["min_print_speed"].type = coInt; + Options["min_print_speed"].type = coFloat; Options["min_print_speed"].label = "Min print speed"; Options["min_print_speed"].tooltip = "Slic3r will not scale speed down below this speed."; Options["min_print_speed"].sidetext = "mm/s"; Options["min_print_speed"].cli = "min-print-speed=f"; Options["min_print_speed"].min = 0; - - Options["max_print_speed"].type = coFloat; - Options["max_print_speed"].label = "Max print speed"; - Options["max_print_speed"].tooltip = "When setting other speed settings to 0 Slic3r will autocalculate the optimal speed in order to keep constant extruder pressure. This experimental setting is used to set the highest print speed you want to allow."; - Options["max_print_speed"].sidetext = "mm/s"; - Options["max_print_speed"].cli = "max-print-speed=f"; - Options["max_print_speed"].min = 1; - - Options["max_volumetric_speed"].type = coFloat; - Options["max_volumetric_speed"].label = "Max volumetric speed"; - Options["max_volumetric_speed"].tooltip = "This experimental setting is used to set the maximum volumetric speed your extruder supports."; - Options["max_volumetric_speed"].sidetext = "mm³/s"; - Options["max_volumetric_speed"].cli = "max-volumetric-speed=f"; - Options["max_volumetric_speed"].min = 0; + Options["min_print_speed"].default_value = new ConfigOptionFloat(10); Options["min_skirt_length"].type = coFloat; Options["min_skirt_length"].label = "Minimum extrusion length"; @@ -527,6 +616,7 @@ PrintConfigDef::build_def() { Options["min_skirt_length"].sidetext = "mm"; Options["min_skirt_length"].cli = "min-skirt-length=f"; Options["min_skirt_length"].min = 0; + Options["min_skirt_length"].default_value = new ConfigOptionFloat(0); Options["notes"].type = coString; Options["notes"].label = "Configuration notes"; @@ -535,50 +625,63 @@ PrintConfigDef::build_def() { Options["notes"].multiline = true; Options["notes"].full_width = true; Options["notes"].height = 130; + Options["notes"].default_value = new ConfigOptionString(""); Options["nozzle_diameter"].type = coFloats; Options["nozzle_diameter"].label = "Nozzle diameter"; Options["nozzle_diameter"].tooltip = "This is the diameter of your extruder nozzle (for example: 0.5, 0.35 etc.)"; Options["nozzle_diameter"].sidetext = "mm"; Options["nozzle_diameter"].cli = "nozzle-diameter=f@"; + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(0.5); + Options["nozzle_diameter"].default_value = opt; + } Options["octoprint_apikey"].type = coString; Options["octoprint_apikey"].label = "API Key"; Options["octoprint_apikey"].tooltip = "Slic3r can upload G-code files to OctoPrint. This field should contain the API Key required for authentication."; Options["octoprint_apikey"].cli = "octoprint-apikey=s"; - + Options["octoprint_apikey"].default_value = new ConfigOptionString(""); + Options["octoprint_host"].type = coString; Options["octoprint_host"].label = "Host or IP"; Options["octoprint_host"].tooltip = "Slic3r can upload G-code files to OctoPrint. This field should contain the hostname or IP address of the OctoPrint instance."; Options["octoprint_host"].cli = "octoprint-host=s"; + Options["octoprint_host"].default_value = new ConfigOptionString(""); Options["only_retract_when_crossing_perimeters"].type = coBool; Options["only_retract_when_crossing_perimeters"].label = "Only retract when crossing perimeters"; Options["only_retract_when_crossing_perimeters"].tooltip = "Disables retraction when the travel path does not exceed the upper layer's perimeters (and thus any ooze will be probably invisible)."; Options["only_retract_when_crossing_perimeters"].cli = "only-retract-when-crossing-perimeters!"; + Options["only_retract_when_crossing_perimeters"].default_value = new ConfigOptionBool(true); Options["ooze_prevention"].type = coBool; Options["ooze_prevention"].label = "Enable"; Options["ooze_prevention"].tooltip = "This option will drop the temperature of the inactive extruders to prevent oozing. It will enable a tall skirt automatically and move extruders outside such skirt when changing temperatures."; Options["ooze_prevention"].cli = "ooze-prevention!"; + Options["ooze_prevention"].default_value = new ConfigOptionBool(false); Options["output_filename_format"].type = coString; Options["output_filename_format"].label = "Output filename format"; Options["output_filename_format"].tooltip = "You can use all configuration options as variables inside this template. For example: [layer_height], [fill_density] etc. You can also use [timestamp], [year], [month], [day], [hour], [minute], [second], [version], [input_filename], [input_filename_base]."; Options["output_filename_format"].cli = "output-filename-format=s"; Options["output_filename_format"].full_width = true; + Options["output_filename_format"].default_value = new ConfigOptionString("[input_filename_base].gcode"); Options["overhangs"].type = coBool; Options["overhangs"].label = "Detect bridging perimeters"; Options["overhangs"].category = "Layers and Perimeters"; Options["overhangs"].tooltip = "Experimental option to adjust flow for overhangs (bridge flow will be used), to apply bridge speed to them and enable fan."; Options["overhangs"].cli = "overhangs!"; + Options["overhangs"].default_value = new ConfigOptionBool(true); Options["perimeter_acceleration"].type = coFloat; Options["perimeter_acceleration"].label = "Perimeters"; Options["perimeter_acceleration"].tooltip = "This is the acceleration your printer will use for perimeters. A high value like 9000 usually gives good results if your hardware is up to the job. Set zero to disable acceleration control for perimeters."; Options["perimeter_acceleration"].sidetext = "mm/s²"; Options["perimeter_acceleration"].cli = "perimeter-acceleration=f"; + Options["perimeter_acceleration"].default_value = new ConfigOptionFloat(0); Options["perimeter_extruder"].type = coInt; Options["perimeter_extruder"].label = "Perimeter extruder"; @@ -587,6 +690,7 @@ PrintConfigDef::build_def() { Options["perimeter_extruder"].cli = "perimeter-extruder=i"; Options["perimeter_extruder"].aliases.push_back("perimeters_extruder"); Options["perimeter_extruder"].min = 1; + Options["perimeter_extruder"].default_value = new ConfigOptionInt(1); Options["perimeter_extrusion_width"].type = coFloatOrPercent; Options["perimeter_extrusion_width"].label = "Perimeters"; @@ -595,6 +699,7 @@ PrintConfigDef::build_def() { Options["perimeter_extrusion_width"].sidetext = "mm or % (leave 0 for default)"; Options["perimeter_extrusion_width"].cli = "perimeter-extrusion-width=s"; Options["perimeter_extrusion_width"].aliases.push_back("perimeters_extrusion_width"); + Options["perimeter_extrusion_width"].default_value = new ConfigOptionFloatOrPercent(0, false); Options["perimeter_speed"].type = coFloat; Options["perimeter_speed"].label = "Perimeters"; @@ -604,6 +709,7 @@ PrintConfigDef::build_def() { Options["perimeter_speed"].cli = "perimeter-speed=f"; Options["perimeter_speed"].aliases.push_back("perimeter_feed_rate"); Options["perimeter_speed"].min = 0; + Options["perimeter_speed"].default_value = new ConfigOptionFloat(60); Options["perimeters"].type = coInt; Options["perimeters"].label = "Perimeters"; @@ -613,6 +719,7 @@ PrintConfigDef::build_def() { Options["perimeters"].cli = "perimeters=i"; Options["perimeters"].aliases.push_back("perimeter_offsets"); Options["perimeters"].min = 0; + Options["perimeters"].default_value = new ConfigOptionInt(3); Options["post_process"].type = coStrings; Options["post_process"].label = "Post-processing scripts"; @@ -624,13 +731,17 @@ PrintConfigDef::build_def() { Options["post_process"].height = 60; Options["print_settings_id"].type = coString; + Options["print_settings_id"].default_value = new ConfigOptionString(""); + Options["printer_settings_id"].type = coString; + Options["printer_settings_id"].default_value = new ConfigOptionString(""); Options["pressure_advance"].type = coFloat; Options["pressure_advance"].label = "Pressure advance"; Options["pressure_advance"].tooltip = "When set to a non-zero value, this experimental option enables pressure regulation. It's the K constant for the advance algorithm that pushes more or less filament upon speed changes. It's useful for Bowden-tube extruders. Reasonable values are in range 0-10."; Options["pressure_advance"].cli = "pressure-advance=f"; Options["pressure_advance"].min = 0; + Options["pressure_advance"].default_value = new ConfigOptionFloat(0); Options["raft_layers"].type = coInt; Options["raft_layers"].label = "Raft layers"; @@ -639,6 +750,7 @@ PrintConfigDef::build_def() { Options["raft_layers"].sidetext = "layers"; Options["raft_layers"].cli = "raft-layers=i"; Options["raft_layers"].min = 0; + Options["raft_layers"].default_value = new ConfigOptionInt(0); Options["resolution"].type = coFloat; Options["resolution"].label = "Resolution"; @@ -646,17 +758,28 @@ PrintConfigDef::build_def() { Options["resolution"].sidetext = "mm"; Options["resolution"].cli = "resolution=f"; Options["resolution"].min = 0; + Options["resolution"].default_value = new ConfigOptionFloat(0); Options["retract_before_travel"].type = coFloats; Options["retract_before_travel"].label = "Minimum travel after retraction"; Options["retract_before_travel"].tooltip = "Retraction is not triggered when travel moves are shorter than this length."; Options["retract_before_travel"].sidetext = "mm"; Options["retract_before_travel"].cli = "retract-before-travel=f@"; - + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(2); + Options["retract_before_travel"].default_value = opt; + } + Options["retract_layer_change"].type = coBools; Options["retract_layer_change"].label = "Retract on layer change"; Options["retract_layer_change"].tooltip = "This flag enforces a retraction whenever a Z move is done."; Options["retract_layer_change"].cli = "retract-layer-change!"; + { + ConfigOptionBools* opt = new ConfigOptionBools(); + opt->values.push_back(false); + Options["retract_layer_change"].default_value = opt; + } Options["retract_length"].type = coFloats; Options["retract_length"].label = "Length"; @@ -664,6 +787,11 @@ PrintConfigDef::build_def() { Options["retract_length"].tooltip = "When retraction is triggered, filament is pulled back by the specified amount (the length is measured on raw filament, before it enters the extruder)."; Options["retract_length"].sidetext = "mm (zero to disable)"; Options["retract_length"].cli = "retract-length=f@"; + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(2); + Options["retract_length"].default_value = opt; + } Options["retract_length_toolchange"].type = coFloats; Options["retract_length_toolchange"].label = "Length"; @@ -671,31 +799,56 @@ PrintConfigDef::build_def() { Options["retract_length_toolchange"].tooltip = "When retraction is triggered before changing tool, filament is pulled back by the specified amount (the length is measured on raw filament, before it enters the extruder)."; Options["retract_length_toolchange"].sidetext = "mm (zero to disable)"; Options["retract_length_toolchange"].cli = "retract-length-toolchange=f@"; + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(10); + Options["retract_length_toolchange"].default_value = opt; + } Options["retract_lift"].type = coFloats; Options["retract_lift"].label = "Lift Z"; Options["retract_lift"].tooltip = "If you set this to a positive value, Z is quickly raised every time a retraction is triggered. When using multiple extruders, only the setting for the first extruder will be considered."; Options["retract_lift"].sidetext = "mm"; Options["retract_lift"].cli = "retract-lift=f@"; + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(0); + Options["retract_lift"].default_value = opt; + } Options["retract_restart_extra"].type = coFloats; Options["retract_restart_extra"].label = "Extra length on restart"; Options["retract_restart_extra"].tooltip = "When the retraction is compensated after the travel move, the extruder will push this additional amount of filament. This setting is rarely needed."; Options["retract_restart_extra"].sidetext = "mm"; Options["retract_restart_extra"].cli = "retract-restart-extra=f@"; + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(0); + Options["retract_restart_extra"].default_value = opt; + } Options["retract_restart_extra_toolchange"].type = coFloats; Options["retract_restart_extra_toolchange"].label = "Extra length on restart"; Options["retract_restart_extra_toolchange"].tooltip = "When the retraction is compensated after changing tool, the extruder will push this additional amount of filament."; Options["retract_restart_extra_toolchange"].sidetext = "mm"; Options["retract_restart_extra_toolchange"].cli = "retract-restart-extra-toolchange=f@"; + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(0); + Options["retract_restart_extra_toolchange"].default_value = opt; + } - Options["retract_speed"].type = coInts; + Options["retract_speed"].type = coFloats; Options["retract_speed"].label = "Speed"; Options["retract_speed"].full_label = "Retraction Speed"; Options["retract_speed"].tooltip = "The speed for retractions (it only applies to the extruder motor)."; Options["retract_speed"].sidetext = "mm/s"; Options["retract_speed"].cli = "retract-speed=f@"; + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(40); + Options["retract_speed"].default_value = opt; + } Options["seam_position"].type = coEnum; Options["seam_position"].label = "Seam position"; @@ -709,6 +862,7 @@ PrintConfigDef::build_def() { Options["seam_position"].enum_labels.push_back("Random"); Options["seam_position"].enum_labels.push_back("Nearest"); Options["seam_position"].enum_labels.push_back("Aligned"); + Options["seam_position"].default_value = new ConfigOptionEnum(spAligned); Options["serial_port"].type = coString; Options["serial_port"].gui_type = "select_open"; @@ -717,6 +871,7 @@ PrintConfigDef::build_def() { Options["serial_port"].tooltip = "USB/serial port for printer connection."; Options["serial_port"].cli = "serial-port=s"; Options["serial_port"].width = 200; + Options["serial_port"].default_value = new ConfigOptionString(""); Options["serial_speed"].type = coInt; Options["serial_speed"].gui_type = "i_enum_open"; @@ -728,6 +883,7 @@ PrintConfigDef::build_def() { Options["serial_speed"].max = 300000; Options["serial_speed"].enum_values.push_back("115200"); Options["serial_speed"].enum_values.push_back("250000"); + Options["serial_speed"].default_value = new ConfigOptionInt(250000); Options["skirt_distance"].type = coFloat; Options["skirt_distance"].label = "Distance from object"; @@ -735,12 +891,14 @@ PrintConfigDef::build_def() { Options["skirt_distance"].sidetext = "mm"; Options["skirt_distance"].cli = "skirt-distance=f"; Options["skirt_distance"].min = 0; + Options["skirt_distance"].default_value = new ConfigOptionFloat(6); Options["skirt_height"].type = coInt; Options["skirt_height"].label = "Skirt height"; Options["skirt_height"].tooltip = "Height of skirt expressed in layers. Set this to a tall value to use skirt as a shield against drafts."; Options["skirt_height"].sidetext = "layers"; Options["skirt_height"].cli = "skirt-height=i"; + Options["skirt_height"].default_value = new ConfigOptionInt(1); Options["skirts"].type = coInt; Options["skirts"].label = "Loops (minimum)"; @@ -748,6 +906,7 @@ PrintConfigDef::build_def() { Options["skirts"].tooltip = "Number of loops for the skirt. If the Minimum Extrusion Length option is set, the number of loops might be greater than the one configured here. Set this to zero to disable skirt completely."; Options["skirts"].cli = "skirts=i"; Options["skirts"].min = 0; + Options["skirts"].default_value = new ConfigOptionInt(1); Options["slowdown_below_layer_time"].type = coInt; Options["slowdown_below_layer_time"].label = "Slow down if layer print time is below"; @@ -757,6 +916,7 @@ PrintConfigDef::build_def() { Options["slowdown_below_layer_time"].width = 60; Options["slowdown_below_layer_time"].min = 0; Options["slowdown_below_layer_time"].max = 1000; + Options["slowdown_below_layer_time"].default_value = new ConfigOptionInt(5); Options["small_perimeter_speed"].type = coFloatOrPercent; Options["small_perimeter_speed"].label = "Small perimeters"; @@ -766,6 +926,7 @@ PrintConfigDef::build_def() { Options["small_perimeter_speed"].cli = "small-perimeter-speed=s"; Options["small_perimeter_speed"].ratio_over = "perimeter_speed"; Options["small_perimeter_speed"].min = 0; + Options["small_perimeter_speed"].default_value = new ConfigOptionFloatOrPercent(15, false); Options["solid_infill_below_area"].type = coFloat; Options["solid_infill_below_area"].label = "Solid infill threshold area"; @@ -774,6 +935,7 @@ PrintConfigDef::build_def() { Options["solid_infill_below_area"].sidetext = "mm²"; Options["solid_infill_below_area"].cli = "solid-infill-below-area=f"; Options["solid_infill_below_area"].min = 0; + Options["solid_infill_below_area"].default_value = new ConfigOptionFloat(70); Options["solid_infill_extruder"].type = coInt; Options["solid_infill_extruder"].label = "Solid infill extruder"; @@ -781,6 +943,7 @@ PrintConfigDef::build_def() { Options["solid_infill_extruder"].tooltip = "The extruder to use when printing solid infill."; Options["solid_infill_extruder"].cli = "solid-infill-extruder=i"; Options["solid_infill_extruder"].min = 1; + Options["solid_infill_extruder"].default_value = new ConfigOptionInt(1); Options["solid_infill_every_layers"].type = coInt; Options["solid_infill_every_layers"].label = "Solid infill every"; @@ -789,6 +952,7 @@ PrintConfigDef::build_def() { Options["solid_infill_every_layers"].sidetext = "layers"; Options["solid_infill_every_layers"].cli = "solid-infill-every-layers=i"; Options["solid_infill_every_layers"].min = 0; + Options["solid_infill_every_layers"].default_value = new ConfigOptionInt(0); Options["solid_infill_extrusion_width"].type = coFloatOrPercent; Options["solid_infill_extrusion_width"].label = "Solid infill"; @@ -796,6 +960,7 @@ PrintConfigDef::build_def() { Options["solid_infill_extrusion_width"].tooltip = "Set this to a non-zero value to set a manual extrusion width for infill for solid surfaces. If expressed as percentage (for example 90%) it will be computed over layer height."; Options["solid_infill_extrusion_width"].sidetext = "mm or % (leave 0 for default)"; Options["solid_infill_extrusion_width"].cli = "solid-infill-extrusion-width=s"; + Options["solid_infill_extrusion_width"].default_value = new ConfigOptionFloatOrPercent(0, false); Options["solid_infill_speed"].type = coFloatOrPercent; Options["solid_infill_speed"].label = "Solid infill"; @@ -806,6 +971,7 @@ PrintConfigDef::build_def() { Options["solid_infill_speed"].ratio_over = "infill_speed"; Options["solid_infill_speed"].aliases.push_back("solid_infill_feed_rate"); Options["solid_infill_speed"].min = 0; + Options["solid_infill_speed"].default_value = new ConfigOptionFloatOrPercent(20, false); Options["solid_layers"].type = coInt; Options["solid_layers"].label = "Solid layers"; @@ -819,6 +985,7 @@ PrintConfigDef::build_def() { Options["spiral_vase"].label = "Spiral vase"; Options["spiral_vase"].tooltip = "This feature will raise Z gradually while printing a single-walled object in order to remove any visible seam. This option requires a single perimeter, no infill, no top solid layers and no support material. You can still set any number of bottom solid layers as well as skirt/brim loops. It won't work when printing more than an object."; Options["spiral_vase"].cli = "spiral-vase!"; + Options["spiral_vase"].default_value = new ConfigOptionBool(false); Options["standby_temperature_delta"].type = coInt; Options["standby_temperature_delta"].label = "Temperature variation"; @@ -827,6 +994,7 @@ PrintConfigDef::build_def() { Options["standby_temperature_delta"].cli = "standby-temperature-delta=i"; Options["standby_temperature_delta"].min = -400; Options["standby_temperature_delta"].max = 400; + Options["standby_temperature_delta"].default_value = new ConfigOptionInt(-5); Options["start_gcode"].type = coString; Options["start_gcode"].label = "Start G-code"; @@ -835,12 +1003,14 @@ PrintConfigDef::build_def() { Options["start_gcode"].multiline = true; Options["start_gcode"].full_width = true; Options["start_gcode"].height = 120; + Options["start_gcode"].default_value = new ConfigOptionString("G28 ; home all axes\nG1 Z5 F5000 ; lift nozzle\n"); Options["support_material"].type = coBool; Options["support_material"].label = "Generate support material"; Options["support_material"].category = "Support material"; Options["support_material"].tooltip = "Enable support material generation."; Options["support_material"].cli = "support-material!"; + Options["support_material"].default_value = new ConfigOptionBool(false); Options["support_material_angle"].type = coInt; Options["support_material_angle"].label = "Pattern angle"; @@ -850,6 +1020,7 @@ PrintConfigDef::build_def() { Options["support_material_angle"].cli = "support-material-angle=i"; Options["support_material_angle"].min = 0; Options["support_material_angle"].max = 359; + Options["support_material_angle"].default_value = new ConfigOptionInt(0); Options["support_material_contact_distance"].type = coFloat; Options["support_material_contact_distance"].gui_type = "f_enum_open"; @@ -863,6 +1034,7 @@ PrintConfigDef::build_def() { Options["support_material_contact_distance"].enum_values.push_back("0.2"); Options["support_material_contact_distance"].enum_labels.push_back("0 (soluble)"); Options["support_material_contact_distance"].enum_labels.push_back("0.2 (detachable)"); + Options["support_material_contact_distance"].default_value = new ConfigOptionFloat(0.2); Options["support_material_enforce_layers"].type = coInt; Options["support_material_enforce_layers"].label = "Enforce support for the first"; @@ -872,6 +1044,7 @@ PrintConfigDef::build_def() { Options["support_material_enforce_layers"].cli = "support-material-enforce-layers=f"; Options["support_material_enforce_layers"].full_label = "Enforce support for the first n layers"; Options["support_material_enforce_layers"].min = 0; + Options["support_material_enforce_layers"].default_value = new ConfigOptionInt(0); Options["support_material_extruder"].type = coInt; Options["support_material_extruder"].label = "Support material/raft/skirt extruder"; @@ -879,6 +1052,7 @@ PrintConfigDef::build_def() { Options["support_material_extruder"].tooltip = "The extruder to use when printing support material, raft and skirt."; Options["support_material_extruder"].cli = "support-material-extruder=i"; Options["support_material_extruder"].min = 1; + Options["support_material_extruder"].default_value = new ConfigOptionInt(1); Options["support_material_extrusion_width"].type = coFloatOrPercent; Options["support_material_extrusion_width"].label = "Support material"; @@ -886,6 +1060,7 @@ PrintConfigDef::build_def() { Options["support_material_extrusion_width"].tooltip = "Set this to a non-zero value to set a manual extrusion width for support material. If expressed as percentage (for example 90%) it will be computed over layer height."; Options["support_material_extrusion_width"].sidetext = "mm or % (leave 0 for default)"; Options["support_material_extrusion_width"].cli = "support-material-extrusion-width=s"; + Options["support_material_extrusion_width"].default_value = new ConfigOptionFloatOrPercent(0, false); Options["support_material_interface_extruder"].type = coInt; Options["support_material_interface_extruder"].label = "Support material/raft interface extruder"; @@ -893,6 +1068,7 @@ PrintConfigDef::build_def() { Options["support_material_interface_extruder"].tooltip = "The extruder to use when printing support material interface. This affects raft too."; Options["support_material_interface_extruder"].cli = "support-material-interface-extruder=i"; Options["support_material_interface_extruder"].min = 1; + Options["support_material_interface_extruder"].default_value = new ConfigOptionInt(1); Options["support_material_interface_layers"].type = coInt; Options["support_material_interface_layers"].label = "Interface layers"; @@ -901,6 +1077,7 @@ PrintConfigDef::build_def() { Options["support_material_interface_layers"].sidetext = "layers"; Options["support_material_interface_layers"].cli = "support-material-interface-layers=i"; Options["support_material_interface_layers"].min = 0; + Options["support_material_interface_layers"].default_value = new ConfigOptionInt(3); Options["support_material_interface_spacing"].type = coFloat; Options["support_material_interface_spacing"].label = "Interface pattern spacing"; @@ -909,6 +1086,7 @@ PrintConfigDef::build_def() { Options["support_material_interface_spacing"].sidetext = "mm"; Options["support_material_interface_spacing"].cli = "support-material-interface-spacing=f"; Options["support_material_interface_spacing"].min = 0; + Options["support_material_interface_spacing"].default_value = new ConfigOptionFloat(0); Options["support_material_interface_speed"].type = coFloatOrPercent; Options["support_material_interface_speed"].label = "Support material interface"; @@ -918,6 +1096,7 @@ PrintConfigDef::build_def() { Options["support_material_interface_speed"].cli = "support-material-interface-speed=s"; Options["support_material_interface_speed"].ratio_over = "support_material_speed"; Options["support_material_interface_speed"].min = 0; + Options["support_material_interface_speed"].default_value = new ConfigOptionFloatOrPercent(100, true); Options["support_material_pattern"].type = coEnum; Options["support_material_pattern"].label = "Pattern"; @@ -933,6 +1112,7 @@ PrintConfigDef::build_def() { Options["support_material_pattern"].enum_labels.push_back("rectilinear grid"); Options["support_material_pattern"].enum_labels.push_back("honeycomb"); Options["support_material_pattern"].enum_labels.push_back("pillars"); + Options["support_material_pattern"].default_value = new ConfigOptionEnum(smpPillars); Options["support_material_spacing"].type = coFloat; Options["support_material_spacing"].label = "Pattern spacing"; @@ -941,6 +1121,7 @@ PrintConfigDef::build_def() { Options["support_material_spacing"].sidetext = "mm"; Options["support_material_spacing"].cli = "support-material-spacing=f"; Options["support_material_spacing"].min = 0; + Options["support_material_spacing"].default_value = new ConfigOptionFloat(2.5); Options["support_material_speed"].type = coFloat; Options["support_material_speed"].label = "Support material"; @@ -949,6 +1130,7 @@ PrintConfigDef::build_def() { Options["support_material_speed"].sidetext = "mm/s"; Options["support_material_speed"].cli = "support-material-speed=f"; Options["support_material_speed"].min = 0; + Options["support_material_speed"].default_value = new ConfigOptionFloat(60); Options["support_material_threshold"].type = coInt; Options["support_material_threshold"].label = "Overhang threshold"; @@ -958,6 +1140,7 @@ PrintConfigDef::build_def() { Options["support_material_threshold"].cli = "support-material-threshold=i"; Options["support_material_threshold"].min = 0; Options["support_material_threshold"].max = 90; + Options["support_material_threshold"].default_value = new ConfigOptionInt(0); Options["temperature"].type = coInts; Options["temperature"].label = "Other layers"; @@ -966,12 +1149,18 @@ PrintConfigDef::build_def() { Options["temperature"].full_label = "Temperature"; Options["temperature"].max = 0; Options["temperature"].max = 400; - + { + ConfigOptionInts* opt = new ConfigOptionInts(); + opt->values.push_back(200); + Options["temperature"].default_value = opt; + } + Options["thin_walls"].type = coBool; Options["thin_walls"].label = "Detect thin walls"; Options["thin_walls"].category = "Layers and Perimeters"; Options["thin_walls"].tooltip = "Detect single-width walls (parts where two extrusions don't fit and we need to collapse them into a single trace)."; Options["thin_walls"].cli = "thin-walls!"; + Options["thin_walls"].default_value = new ConfigOptionBool(true); Options["threads"].type = coInt; Options["threads"].label = "Threads"; @@ -980,6 +1169,7 @@ PrintConfigDef::build_def() { Options["threads"].readonly = true; Options["threads"].min = 1; Options["threads"].max = 16; + Options["threads"].default_value = new ConfigOptionInt(2); Options["toolchange_gcode"].type = coString; Options["toolchange_gcode"].label = "Tool change G-code"; @@ -988,6 +1178,7 @@ PrintConfigDef::build_def() { Options["toolchange_gcode"].multiline = true; Options["toolchange_gcode"].full_width = true; Options["toolchange_gcode"].height = 50; + Options["toolchange_gcode"].default_value = new ConfigOptionString(""); Options["top_infill_extrusion_width"].type = coFloatOrPercent; Options["top_infill_extrusion_width"].label = "Top solid infill"; @@ -995,6 +1186,7 @@ PrintConfigDef::build_def() { Options["top_infill_extrusion_width"].tooltip = "Set this to a non-zero value to set a manual extrusion width for infill for top surfaces. You may want to use thinner extrudates to fill all narrow regions and get a smoother finish. If expressed as percentage (for example 90%) it will be computed over layer height."; Options["top_infill_extrusion_width"].sidetext = "mm or % (leave 0 for default)"; Options["top_infill_extrusion_width"].cli = "top-infill-extrusion-width=s"; + Options["top_infill_extrusion_width"].default_value = new ConfigOptionFloatOrPercent(0, false); Options["top_solid_infill_speed"].type = coFloatOrPercent; Options["top_solid_infill_speed"].label = "Top solid infill"; @@ -1004,6 +1196,7 @@ PrintConfigDef::build_def() { Options["top_solid_infill_speed"].cli = "top-solid-infill-speed=s"; Options["top_solid_infill_speed"].ratio_over = "solid_infill_speed"; Options["top_solid_infill_speed"].min = 0; + Options["top_solid_infill_speed"].default_value = new ConfigOptionFloatOrPercent(15, false); Options["top_solid_layers"].type = coInt; Options["top_solid_layers"].label = "Top"; @@ -1012,6 +1205,7 @@ PrintConfigDef::build_def() { Options["top_solid_layers"].cli = "top-solid-layers=i"; Options["top_solid_layers"].full_label = "Top solid layers"; Options["top_solid_layers"].min = 0; + Options["top_solid_layers"].default_value = new ConfigOptionInt(3); Options["travel_speed"].type = coFloat; Options["travel_speed"].label = "Travel"; @@ -1020,21 +1214,25 @@ PrintConfigDef::build_def() { Options["travel_speed"].cli = "travel-speed=f"; Options["travel_speed"].aliases.push_back("travel_feed_rate"); Options["travel_speed"].min = 1; + Options["travel_speed"].default_value = new ConfigOptionFloat(130); Options["use_firmware_retraction"].type = coBool; Options["use_firmware_retraction"].label = "Use firmware retraction"; Options["use_firmware_retraction"].tooltip = "This experimental setting uses G10 and G11 commands to have the firmware handle the retraction. This is only supported in recent Marlin."; Options["use_firmware_retraction"].cli = "use-firmware-retraction!"; + Options["use_firmware_retraction"].default_value = new ConfigOptionFloat(false); Options["use_relative_e_distances"].type = coBool; Options["use_relative_e_distances"].label = "Use relative E distances"; Options["use_relative_e_distances"].tooltip = "If your firmware requires relative E values, check this, otherwise leave it unchecked. Most firmwares use absolute values."; Options["use_relative_e_distances"].cli = "use-relative-e-distances!"; + Options["use_relative_e_distances"].default_value = new ConfigOptionFloat(false); Options["use_volumetric_e"].type = coBool; Options["use_volumetric_e"].label = "Use volumetric E"; Options["use_volumetric_e"].tooltip = "This experimental setting uses outputs the E values in cubic millimeters instead of linear millimeters. If your firmware doesn't already know filament diameter(s), you can put commands like 'M200 D[filament_diameter_0] T0' in your start G-code in order to turn volumetric mode on and use the filament diameter associated to the filament selected in Slic3r. This is only supported in recent Marlin."; Options["use_volumetric_e"].cli = "use-volumetric-e!"; + Options["use_volumetric_e"].default_value = new ConfigOptionFloat(false); Options["vibration_limit"].type = coFloat; Options["vibration_limit"].label = "Vibration limit (deprecated)"; @@ -1042,11 +1240,17 @@ PrintConfigDef::build_def() { Options["vibration_limit"].sidetext = "Hz"; Options["vibration_limit"].cli = "vibration-limit=f"; Options["vibration_limit"].min = 0; + Options["vibration_limit"].default_value = new ConfigOptionFloat(0); Options["wipe"].type = coBools; Options["wipe"].label = "Wipe while retracting"; Options["wipe"].tooltip = "This flag will move the nozzle while retracting to minimize the possible blob on leaky extruders."; Options["wipe"].cli = "wipe!"; + { + ConfigOptionBools* opt = new ConfigOptionBools(); + opt->values.push_back(false); + Options["wipe"].default_value = opt; + } Options["xy_size_compensation"].type = coFloat; Options["xy_size_compensation"].label = "XY Size Compensation"; @@ -1054,17 +1258,17 @@ PrintConfigDef::build_def() { Options["xy_size_compensation"].tooltip = "The object will be grown/shrunk in the XY plane by the configured value (negative = inwards, positive = outwards). This might be useful for fine-tuning hole sizes."; Options["xy_size_compensation"].sidetext = "mm"; Options["xy_size_compensation"].cli = "xy-size-compensation=f"; + Options["xy_size_compensation"].default_value = new ConfigOptionFloat(0); Options["z_offset"].type = coFloat; Options["z_offset"].label = "Z offset"; Options["z_offset"].tooltip = "This value will be added (or subtracted) from all the Z coordinates in the output G-code. It is used to compensate for bad Z endstop position: for example, if your endstop zero actually leaves the nozzle 0.3mm far from the print bed, set this to -0.3 (or fix your endstop)."; Options["z_offset"].sidetext = "mm"; Options["z_offset"].cli = "z-offset=f"; - - return Options; -}; + Options["z_offset"].default_value = new ConfigOptionFloat(0); +} -t_optiondef_map PrintConfigDef::def = PrintConfigDef::build_def(); +PrintConfigDef print_config_def; void DynamicPrintConfig::normalize() { @@ -1101,12 +1305,15 @@ DynamicPrintConfig::normalize() { } double -PrintConfig::min_object_distance() const +PrintConfigBase::min_object_distance() const { + double extruder_clearance_radius = this->option("extruder_clearance_radius")->getFloat(); + double duplicate_distance = this->option("duplicate_distance")->getFloat(); + // min object distance is max(duplicate_distance, clearance_radius) - return (this->complete_objects.value && this->extruder_clearance_radius.value > this->duplicate_distance.value) - ? this->extruder_clearance_radius.value - : this->duplicate_distance.value; + return (this->option("complete_objects")->getBool() && extruder_clearance_radius > duplicate_distance) + ? extruder_clearance_radius + : duplicate_distance; } #ifdef SLIC3RXS diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 22baa6306..2df6dd8d2 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -67,33 +67,38 @@ template<> inline t_config_enum_values ConfigOptionEnum::get_enum_ return keys_map; } -class PrintConfigDef +class PrintConfigDef : public ConfigDef { public: - static t_optiondef_map def; - - static t_optiondef_map build_def(); + PrintConfigDef(); }; -class DynamicPrintConfig : public DynamicConfig +extern PrintConfigDef print_config_def; + +class PrintConfigBase : public virtual ConfigBase { public: - DynamicPrintConfig() { - this->def = &PrintConfigDef::def; + PrintConfigBase() { + this->def = &print_config_def; }; + double min_object_distance() const; +}; + +class DynamicPrintConfig : public PrintConfigBase, public DynamicConfig +{ + public: + DynamicPrintConfig() : PrintConfigBase(), DynamicConfig() {}; void normalize(); }; -class StaticPrintConfig : public virtual StaticConfig +class StaticPrintConfigBase : public PrintConfigBase, public StaticConfig { public: - StaticPrintConfig() { - this->def = &PrintConfigDef::def; - }; + StaticPrintConfigBase() : PrintConfigBase(), StaticConfig() {}; }; -class PrintObjectConfig : public virtual StaticPrintConfig +class PrintObjectConfig : public virtual StaticPrintConfigBase { public: ConfigOptionBool dont_support_bridges; @@ -120,34 +125,8 @@ class PrintObjectConfig : public virtual StaticPrintConfig ConfigOptionInt support_material_threshold; ConfigOptionFloat xy_size_compensation; - PrintObjectConfig() : StaticPrintConfig() { - this->dont_support_bridges.value = true; - this->extrusion_width.value = 0; - this->extrusion_width.percent = false; - this->first_layer_height.value = 0.35; - this->first_layer_height.percent = false; - this->infill_only_where_needed.value = false; - this->interface_shells.value = false; - this->layer_height.value = 0.3; - this->raft_layers.value = 0; - this->seam_position.value = spAligned; - this->support_material.value = false; - this->support_material_angle.value = 0; - this->support_material_contact_distance.value = 0.2; - this->support_material_enforce_layers.value = 0; - this->support_material_extruder.value = 1; - this->support_material_extrusion_width.value = 0; - this->support_material_extrusion_width.percent = false; - this->support_material_interface_extruder.value = 1; - this->support_material_interface_layers.value = 3; - this->support_material_interface_spacing.value = 0; - this->support_material_interface_speed.value = 100; - this->support_material_interface_speed.percent = true; - this->support_material_pattern.value = smpPillars; - this->support_material_spacing.value = 2.5; - this->support_material_speed.value = 60; - this->support_material_threshold.value = 0; - this->xy_size_compensation.value = 0; + PrintObjectConfig() : StaticPrintConfigBase() { + this->set_defaults(); }; ConfigOption* option(const t_config_option_key &opt_key, bool create = false) { @@ -179,7 +158,7 @@ class PrintObjectConfig : public virtual StaticPrintConfig }; }; -class PrintRegionConfig : public virtual StaticPrintConfig +class PrintRegionConfig : public virtual StaticPrintConfigBase { public: ConfigOptionInt bottom_solid_layers; @@ -215,49 +194,8 @@ class PrintRegionConfig : public virtual StaticPrintConfig ConfigOptionInt top_solid_layers; ConfigOptionFloatOrPercent top_solid_infill_speed; - PrintRegionConfig() : StaticPrintConfig() { - this->bottom_solid_layers.value = 3; - this->bridge_flow_ratio.value = 1; - this->bridge_speed.value = 60; - this->external_fill_pattern.value = ipRectilinear; - this->external_perimeter_extrusion_width.value = 0; - this->external_perimeter_extrusion_width.percent = false; - this->external_perimeter_speed.value = 50; - this->external_perimeter_speed.percent = true; - this->external_perimeters_first.value = false; - this->extra_perimeters.value = true; - this->fill_angle.value = 45; - this->fill_density.value = 20; - this->fill_pattern.value = ipHoneycomb; - this->gap_fill_speed.value = 20; - this->infill_extruder.value = 1; - this->infill_extrusion_width.value = 0; - this->infill_extrusion_width.percent = false; - this->infill_every_layers.value = 1; - this->infill_overlap.value = 15; - this->infill_overlap.percent = true; - this->infill_speed.value = 80; - this->overhangs.value = true; - this->perimeter_extruder.value = 1; - this->perimeter_extrusion_width.value = 0; - this->perimeter_extrusion_width.percent = false; - this->perimeter_speed.value = 60; - this->perimeters.value = 3; - this->solid_infill_extruder.value = 1; - this->small_perimeter_speed.value = 15; - this->small_perimeter_speed.percent = false; - this->solid_infill_below_area.value = 70; - this->solid_infill_extrusion_width.value = 0; - this->solid_infill_extrusion_width.percent = false; - this->solid_infill_every_layers.value = 0; - this->solid_infill_speed.value = 20; - this->solid_infill_speed.percent = false; - this->thin_walls.value = true; - this->top_infill_extrusion_width.value = 0; - this->top_infill_extrusion_width.percent = false; - this->top_solid_infill_speed.value = 15; - this->top_solid_infill_speed.percent = false; - this->top_solid_layers.value = 3; + PrintRegionConfig() : StaticPrintConfigBase() { + this->set_defaults(); }; ConfigOption* option(const t_config_option_key &opt_key, bool create = false) { @@ -298,7 +236,7 @@ class PrintRegionConfig : public virtual StaticPrintConfig }; }; -class GCodeConfig : public virtual StaticPrintConfig +class GCodeConfig : public virtual StaticPrintConfigBase { public: ConfigOptionString before_layer_gcode; @@ -317,7 +255,7 @@ class GCodeConfig : public virtual StaticPrintConfig ConfigOptionFloats retract_lift; ConfigOptionFloats retract_restart_extra; ConfigOptionFloats retract_restart_extra_toolchange; - ConfigOptionInts retract_speed; + ConfigOptionFloats retract_speed; ConfigOptionString start_gcode; ConfigOptionString toolchange_gcode; ConfigOptionFloat travel_speed; @@ -325,38 +263,8 @@ class GCodeConfig : public virtual StaticPrintConfig ConfigOptionBool use_relative_e_distances; ConfigOptionBool use_volumetric_e; - GCodeConfig() : StaticPrintConfig() { - this->before_layer_gcode.value = ""; - this->end_gcode.value = "M104 S0 ; turn off temperature\nG28 X0 ; home X axis\nM84 ; disable motors\n"; - this->extrusion_axis.value = "E"; - this->extrusion_multiplier.values.resize(1); - this->extrusion_multiplier.values[0] = 1; - this->filament_diameter.values.resize(1); - this->filament_diameter.values[0] = 3; - this->gcode_comments.value = false; - this->gcode_flavor.value = gcfRepRap; - this->layer_gcode.value = ""; - this->max_print_speed.value = 80; - this->max_volumetric_speed.value = 0; - this->pressure_advance.value = 0; - this->retract_length.values.resize(1); - this->retract_length.values[0] = 2; - this->retract_length_toolchange.values.resize(1); - this->retract_length_toolchange.values[0] = 10; - this->retract_lift.values.resize(1); - this->retract_lift.values[0] = 0; - this->retract_restart_extra.values.resize(1); - this->retract_restart_extra.values[0] = 0; - this->retract_restart_extra_toolchange.values.resize(1); - this->retract_restart_extra_toolchange.values[0] = 0; - this->retract_speed.values.resize(1); - this->retract_speed.values[0] = 40; - this->start_gcode.value = "G28 ; home all axes\nG1 Z5 F5000 ; lift nozzle\n"; - this->toolchange_gcode.value = ""; - this->travel_speed.value = 130; - this->use_firmware_retraction.value = false; - this->use_relative_e_distances.value = false; - this->use_volumetric_e.value = false; + GCodeConfig() : StaticPrintConfigBase() { + this->set_defaults(); }; ConfigOption* option(const t_config_option_key &opt_key, bool create = false) { @@ -429,7 +337,7 @@ class PrintConfig : public GCodeConfig ConfigOptionBool infill_first; ConfigOptionInt max_fan_speed; ConfigOptionInt min_fan_speed; - ConfigOptionInt min_print_speed; + ConfigOptionFloat min_print_speed; ConfigOptionFloat min_skirt_length; ConfigOptionString notes; ConfigOptionFloats nozzle_diameter; @@ -454,68 +362,7 @@ class PrintConfig : public GCodeConfig ConfigOptionFloat z_offset; PrintConfig() : GCodeConfig() { - this->avoid_crossing_perimeters.value = false; - this->bed_shape.values.push_back(Pointf(0,0)); - this->bed_shape.values.push_back(Pointf(200,0)); - this->bed_shape.values.push_back(Pointf(200,200)); - this->bed_shape.values.push_back(Pointf(0,200)); - this->bed_temperature.value = 0; - this->bridge_acceleration.value = 0; - this->bridge_fan_speed.value = 100; - this->brim_width.value = 0; - this->complete_objects.value = false; - this->cooling.value = true; - this->default_acceleration.value = 0; - this->disable_fan_first_layers.value = 3; - this->duplicate_distance.value = 6; - this->extruder_clearance_height.value = 20; - this->extruder_clearance_radius.value = 20; - this->extruder_offset.values.resize(1); - this->extruder_offset.values[0] = Pointf(0,0); - this->fan_always_on.value = false; - this->fan_below_layer_time.value = 60; - this->filament_colour.values.resize(1); - this->filament_colour.values[0] = "#FFFFFF"; - this->first_layer_acceleration.value = 0; - this->first_layer_bed_temperature.value = 0; - this->first_layer_extrusion_width.value = 200; - this->first_layer_extrusion_width.percent = true; - this->first_layer_speed.value = 30; - this->first_layer_speed.percent = false; - this->first_layer_temperature.values.resize(1); - this->first_layer_temperature.values[0] = 200; - this->gcode_arcs.value = false; - this->infill_acceleration.value = 0; - this->infill_first.value = false; - this->max_fan_speed.value = 100; - this->min_fan_speed.value = 35; - this->min_print_speed.value = 10; - this->min_skirt_length.value = 0; - this->notes.value = ""; - this->nozzle_diameter.values.resize(1); - this->nozzle_diameter.values[0] = 0.5; - this->only_retract_when_crossing_perimeters.value = true; - this->ooze_prevention.value = false; - this->output_filename_format.value = "[input_filename_base].gcode"; - this->perimeter_acceleration.value = 0; - this->resolution.value = 0; - this->retract_before_travel.values.resize(1); - this->retract_before_travel.values[0] = 2; - this->retract_layer_change.values.resize(1); - this->retract_layer_change.values[0] = false; - this->skirt_distance.value = 6; - this->skirt_height.value = 1; - this->skirts.value = 1; - this->slowdown_below_layer_time.value = 5; - this->spiral_vase.value = false; - this->standby_temperature_delta.value = -5; - this->temperature.values.resize(1); - this->temperature.values[0] = 200; - this->threads.value = 2; - this->vibration_limit.value = 0; - this->wipe.values.resize(1); - this->wipe.values[0] = false; - this->z_offset.value = 0; + this->set_defaults(); }; ConfigOption* option(const t_config_option_key &opt_key, bool create = false) { @@ -576,11 +423,9 @@ class PrintConfig : public GCodeConfig return NULL; }; - - double min_object_distance() const; }; -class HostConfig : public virtual StaticPrintConfig +class HostConfig : public virtual StaticPrintConfigBase { public: ConfigOptionString octoprint_host; @@ -588,11 +433,8 @@ class HostConfig : public virtual StaticPrintConfig ConfigOptionString serial_port; ConfigOptionInt serial_speed; - HostConfig() : StaticPrintConfig() { - this->octoprint_host.value = ""; - this->octoprint_apikey.value = ""; - this->serial_port.value = ""; - this->serial_speed.value = 250000; + HostConfig() : StaticPrintConfigBase() { + this->set_defaults(); }; ConfigOption* option(const t_config_option_key &opt_key, bool create = false) { diff --git a/xs/t/15_config.t b/xs/t/15_config.t index 43bfe501c..a4d7751ea 100644 --- a/xs/t/15_config.t +++ b/xs/t/15_config.t @@ -30,6 +30,7 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Full->new) { is $config->serialize('first_layer_height'), '0.3', 'serialize absolute floatOrPercent'; $config->set('first_layer_height', '50%'); + $config->get_abs_value('first_layer_height'); ok abs($config->get_abs_value('first_layer_height') - 0.15) < 1e-4, 'set/get relative floatOrPercent'; is $config->serialize('first_layer_height'), '50%', 'serialize relative floatOrPercent'; diff --git a/xs/xsp/Config.xsp b/xs/xsp/Config.xsp index afdf4a684..bb8fa7b49 100644 --- a/xs/xsp/Config.xsp +++ b/xs/xsp/Config.xsp @@ -31,6 +31,7 @@ void erase(t_config_option_key opt_key); void normalize(); %name{setenv} void setenv_(); + double min_object_distance(); }; %name{Slic3r::Config::GCode} class GCodeConfig { @@ -158,11 +159,11 @@ PROTOTYPES: DISABLE SV* print_config_def() CODE: + t_optiondef_map &def = Slic3r::print_config_def.options; FullPrintConfig config; - t_optiondef_map* def = config.def; HV* options_hv = newHV(); - for (t_optiondef_map::iterator oit = def->begin(); oit != def->end(); ++oit) { + for (t_optiondef_map::iterator oit = def.begin(); oit != def.end(); ++oit) { HV* hv = newHV(); t_config_option_key opt_key = oit->first;