diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index 52a04721bd..454906ec3f 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -266,6 +266,8 @@ ConfigOption* ConfigOptionDef::create_empty_option() const { if (this->nullable) { switch (this->type) { + case coFloat: return new ConfigOptionFloatNullable(); + case coInt: return new ConfigOptionIntNullable(); case coFloats: return new ConfigOptionFloatsNullable(); case coInts: return new ConfigOptionIntsNullable(); case coPercents: return new ConfigOptionPercentsNullable(); @@ -1433,6 +1435,9 @@ CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionSingle) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionSingle) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionSingle) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionSingle) +CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionSingleNullable) +CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionSingleNullable) +CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionSingleNullable) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionVectorBase) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionVector) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionVector) @@ -1440,9 +1445,11 @@ CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionVector) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionVector) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionVector) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionFloat) +CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionFloatNullable) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionFloats) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionFloatsNullable) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionInt) +CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionIntNullable) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionInts) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionIntsNullable) CEREAL_REGISTER_TYPE(Slic3r::ConfigOptionString) @@ -1469,6 +1476,9 @@ CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOption, Slic3r::ConfigOptionS CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOption, Slic3r::ConfigOptionSingle) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOption, Slic3r::ConfigOptionSingle) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOption, Slic3r::ConfigOptionSingle) +CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOption, Slic3r::ConfigOptionSingleNullable) +CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOption, Slic3r::ConfigOptionSingleNullable) +CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOption, Slic3r::ConfigOptionSingleNullable) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOption, Slic3r::ConfigOptionVectorBase) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionVectorBase, Slic3r::ConfigOptionVector) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionVectorBase, Slic3r::ConfigOptionVector) @@ -1476,9 +1486,11 @@ CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionVectorBase, Slic3r::Con CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionVectorBase, Slic3r::ConfigOptionVector) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionVectorBase, Slic3r::ConfigOptionVector) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionSingle, Slic3r::ConfigOptionFloat) +CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionSingleNullable, Slic3r::ConfigOptionFloatNullable) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionVector, Slic3r::ConfigOptionFloats) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionVector, Slic3r::ConfigOptionFloatsNullable) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionSingle, Slic3r::ConfigOptionInt) +CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionSingleNullable, Slic3r::ConfigOptionIntNullable) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionVector, Slic3r::ConfigOptionInts) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionVector, Slic3r::ConfigOptionIntsNullable) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ConfigOptionSingle, Slic3r::ConfigOptionString) diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index d8afe8e021..ce588151c2 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -332,16 +332,16 @@ public: { if (rhs->type() != this->type()) throw ConfigurationError("ConfigOptionSingle: Assigning an incompatible type"); - assert(dynamic_cast*>(rhs)); - this->value = static_cast*>(rhs)->value; + assert(dynamic_cast(rhs)); + this->value = static_cast(rhs)->value; } bool operator==(const ConfigOption &rhs) const override { if (rhs.type() != this->type()) throw ConfigurationError("ConfigOptionSingle: Comparing incompatible types"); - assert(dynamic_cast*>(&rhs)); - return this->value == static_cast*>(&rhs)->value; + assert(dynamic_cast(&rhs)); + return this->value == static_cast(&rhs)->value; } bool operator==(const T &rhs) const throw() { return this->value == rhs; } @@ -357,7 +357,7 @@ public: throw ConfigurationError("Cannot override a nullable ConfigOption."); if (rhs->type() != this->type()) throw ConfigurationError("ConfigOptionVector.overriden_by() applied to different types."); - auto rhs_vec = static_cast*>(rhs); + auto rhs_vec = static_cast(rhs); if (! rhs->nullable()) // Overridding a non-nullable object with another non-nullable object. return this->value != rhs_vec->value; @@ -370,7 +370,7 @@ public: throw ConfigurationError("Cannot override a nullable ConfigOption."); if (rhs->type() != this->type()) throw ConfigurationError("ConfigOptionVector.apply_override() applied to different types."); - auto rhs_vec = static_cast*>(rhs); + auto rhs_vec = static_cast(rhs); if (! rhs->nullable()) { // Overridding a non-nullable object with another non-nullable object. if (this->value != rhs_vec->value) { @@ -398,6 +398,9 @@ private: template void serialize(Archive & ar) { ar(this->value); } }; +template +using ConfigOptionSingleNullable = ConfigOptionSingle; + // Value of a vector valued option (bools, ints, floats, strings, points) class ConfigOptionVectorBase : public ConfigOption { public: @@ -653,7 +656,7 @@ public: private: friend class cereal::access; - template void serialize(Archive &ar) { ar(cereal::base_class>(this)); } + template void serialize(Archive &ar) { ar(cereal::base_class>(this)); } }; template @@ -784,19 +787,20 @@ using ConfigOptionFloatNullable = ConfigOptionFloatTempl; using ConfigOptionFloats = ConfigOptionFloatsTempl; using ConfigOptionFloatsNullable = ConfigOptionFloatsTempl; -class ConfigOptionInt : public ConfigOptionSingle +template +class ConfigOptionIntTempl : public ConfigOptionSingle { public: - ConfigOptionInt() : ConfigOptionSingle(0) {} - explicit ConfigOptionInt(int value) : ConfigOptionSingle(value) {} - explicit ConfigOptionInt(double _value) : ConfigOptionSingle(int(floor(_value + 0.5))) {} + ConfigOptionIntTempl() : ConfigOptionSingle(0) {} + explicit ConfigOptionIntTempl(int value) : ConfigOptionSingle(value) {} + explicit ConfigOptionIntTempl(double _value) : ConfigOptionSingle(int(floor(_value + 0.5))) {} static ConfigOptionType static_type() { return coInt; } ConfigOptionType type() const override { return static_type(); } int getInt() const override { return this->value; } void setInt(int val) override { this->value = val; } - ConfigOption* clone() const override { return new ConfigOptionInt(*this); } - bool operator==(const ConfigOptionInt &rhs) const throw() { return this->value == rhs.value; } + ConfigOption* clone() const override { return new ConfigOptionIntTempl(*this); } + bool operator==(const ConfigOptionIntTempl &rhs) const throw() { return this->value == rhs.value; } std::string serialize() const override { @@ -813,7 +817,7 @@ public: return !iss.fail(); } - ConfigOptionInt& operator=(const ConfigOption *opt) + ConfigOptionIntTempl& operator=(const ConfigOption *opt) { this->set(opt); return *this; @@ -821,9 +825,12 @@ public: private: friend class cereal::access; - template void serialize(Archive &ar) { ar(cereal::base_class>(this)); } + template void serialize(Archive &ar) { ar(cereal::base_class>(this)); } }; +using ConfigOptionInt = ConfigOptionIntTempl; +using ConfigOptionIntNullable = ConfigOptionIntTempl; + template class ConfigOptionIntsTempl : public ConfigOptionVector { @@ -1907,6 +1914,8 @@ public: template ConfigOption* load_option_from_archive(Archive &archive) const { if (this->nullable) { switch (this->type) { + case coFloat: { auto opt = new ConfigOptionFloatNullable(); archive(*opt); return opt; } + case coInt: { auto opt = new ConfigOptionIntNullable(); archive(*opt); return opt; } case coFloats: { auto opt = new ConfigOptionFloatsNullable(); archive(*opt); return opt; } case coInts: { auto opt = new ConfigOptionIntsNullable(); archive(*opt); return opt; } case coPercents: { auto opt = new ConfigOptionPercentsNullable();archive(*opt); return opt; } @@ -1939,6 +1948,8 @@ public: template ConfigOption* save_option_to_archive(Archive &archive, const ConfigOption *opt) const { if (this->nullable) { switch (this->type) { + case coFloat: archive(*static_cast(opt)); break; + case coInt: archive(*static_cast(opt)); break; case coFloats: archive(*static_cast(opt)); break; case coInts: archive(*static_cast(opt)); break; case coPercents: archive(*static_cast(opt));break; diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 2831900e06..f5e1aa7036 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -609,22 +609,22 @@ static std::vector s_Preset_sla_material_options { "compatible_printers", "compatible_printers_condition", "inherits", // overriden options - "material_support_head_front_diameter", - "material_support_head_penetration", - "material_support_head_width", - "material_support_pillar_diameter", + "material_ow_support_head_front_diameter", + "material_ow_support_head_penetration", + "material_ow_support_head_width", + "material_ow_support_pillar_diameter", - "material_branchingsupport_head_front_diameter", - "material_branchingsupport_head_penetration", - "material_branchingsupport_head_width", - "material_branchingsupport_pillar_diameter", + "material_ow_branchingsupport_head_front_diameter", + "material_ow_branchingsupport_head_penetration", + "material_ow_branchingsupport_head_width", + "material_ow_branchingsupport_pillar_diameter", - "material_support_points_density_relative", + "material_ow_support_points_density_relative", - "material_relative_correction_x", - "material_relative_correction_y", - "material_relative_correction_z", - "material_elefant_foot_compensation" + "material_ow_relative_correction_x", + "material_ow_relative_correction_y", + "material_ow_relative_correction_z", + "material_ow_elefant_foot_compensation" }; static std::vector s_Preset_sla_printer_options { diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 6285102d02..f7ead0b0da 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -4316,7 +4316,7 @@ void PrintConfigDef::init_sla_params() }) { auto it_opt = options.find(opt_key); assert(it_opt != options.end()); - def = this->add_nullable(std::string("material_") + opt_key, it_opt->second.type == coFloat ? coFloats : coInts); + def = this->add_nullable(std::string("material_ow_") + opt_key, it_opt->second.type); def->label = it_opt->second.label; def->full_label = it_opt->second.full_label; def->tooltip = it_opt->second.tooltip; @@ -4325,8 +4325,8 @@ void PrintConfigDef::init_sla_params() def->max = it_opt->second.max; def->mode = it_opt->second.mode; switch (def->type) { - case coFloats: def->set_default_value(new ConfigOptionFloatsNullable{ it_opt->second.default_value->getFloat() }); break; - case coInts: def->set_default_value(new ConfigOptionIntsNullable { it_opt->second.default_value->getInt() }); break; + case coFloat: def->set_default_value(new ConfigOptionFloatNullable{ it_opt->second.default_value->getFloat() }); break; + case coInt: def->set_default_value(new ConfigOptionIntNullable{ it_opt->second.default_value->getInt() }); break; default: assert(false); } } diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index f0443fd72f..7dd402ecaf 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -802,7 +802,7 @@ bool SLAPrint::invalidate_state_by_config_options(const std::vector steps; @@ -922,7 +933,9 @@ bool SLAPrintObject::invalidate_state_by_config_options(const std::vector(value) != 0 }; config.option(opt_key)->set_at(vec_new, opt_index, 0); break;} - case coInt: - config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast(value))); + case coInt: { + //config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast(value))); + int& val_new = config.opt_int(opt_key); + val_new = boost::any_cast(value); + } break; case coInts:{ ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast(value) }; diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index be5755974a..4a8e21e4be 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -867,6 +867,12 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config { switch (opt->type) { + case coFloat: + ret = double_to_string(config.option(opt_key)->value); + break; + case coInt: + ret = config.option(opt_key)->value; + break; case coPercents: case coFloats: { if (config.option(opt_key)->is_nil()) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 0666b58b02..b3c1f5b50c 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -5472,7 +5472,7 @@ void TabSLAPrint::build_sla_support_params(const std::vector get_override_opt_kyes_for_line(const std::string& title, const std::string& key) { - const std::string preprefix = "material_"; + const std::string preprefix = "material_ow_"; std::vector opt_keys; opt_keys.reserve(3); @@ -5494,9 +5494,9 @@ static std::vector get_override_opt_kyes_for_line(const std::string void TabSLAMaterial::create_line_with_near_label_widget(ConfigOptionsGroupShp optgroup, const std::string& key) { if (optgroup->title == "Support head" || optgroup->title == "Support pillar") - add_options_into_line(optgroup, { {"", L("Default")}, {"branching", L("Branching")} }, key, "material_"); + add_options_into_line(optgroup, { {"", L("Default")}, {"branching", L("Branching")} }, key, "material_ow_"); else { - const std::string opt_key = std::string("material_") + key; + const std::string opt_key = std::string("material_ow_") + key; if (key == "relative_correction") { Line line = Line{ m_preset_bundle->printers.get_edited_preset().config.def()->get("relative_correction")->full_label, "" }; for (auto& axis : { "X", "Y", "Z" }) { @@ -5573,7 +5573,7 @@ void TabSLAMaterial::update_line_with_near_label_widget(ConfigOptionsGroupShp op if (!m_overrides_options[key]) return; - const std::string preprefix = "material_"; + const std::string preprefix = "material_ow_"; std::vector opt_keys; opt_keys.reserve(3); @@ -5627,7 +5627,7 @@ void TabSLAMaterial::update_material_overrides_page() bool is_checked{ true }; - const static std::string preprefix = "material_"; + const static std::string preprefix = "material_ow_"; if (title == "Support head" || title == "Support pillar") { for (auto& prefix : { "", "branching" }) update_line_with_near_label_widget(*optgroup, preprefix + prefix + key, is_checked);