From c6de3e84eb42969c78f4fdb64f7e413d43674f6b Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Fri, 22 Oct 2021 16:34:20 +0200 Subject: [PATCH] Trying to solve forward compatibility for SLA relative_corrections --- src/libslic3r/Model.cpp | 2 + src/libslic3r/Preset.cpp | 8 ++++ src/libslic3r/PrintConfig.cpp | 82 +++++++++++++++++++++++++++++++++-- src/libslic3r/PrintConfig.hpp | 8 ++++ src/libslic3r/SLAPrint.cpp | 18 +++++--- src/slic3r/GUI/Tab.cpp | 28 +++++------- 6 files changed, 119 insertions(+), 27 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 3b6731337..b561b1a44 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -182,6 +182,8 @@ Model Model::read_from_archive(const std::string& input_file, DynamicPrintConfig CustomGCode::update_custom_gcode_per_print_z_from_config(model.custom_gcode_per_print_z, config); CustomGCode::check_mode_for_custom_gcode_per_print_z(model.custom_gcode_per_print_z); + handle_legacy_sla(*config); + return model; } diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index eff6c8a8d..a19eb4d52 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -303,6 +303,8 @@ void Preset::normalize(DynamicPrintConfig &config) first_layer_height->value = first_layer_height->get_abs_value(layer_height->value); first_layer_height->percent = false; } + + handle_legacy_sla(config); } std::string Preset::remove_invalid_keys(DynamicPrintConfig &config, const DynamicPrintConfig &default_config) @@ -544,6 +546,9 @@ static std::vector s_Preset_sla_material_options { "exposure_time", "initial_exposure_time", "material_correction", + "material_correction_x", + "material_correction_y", + "material_correction_z", "material_notes", "material_vendor", "default_sla_material_profile", @@ -559,6 +564,9 @@ static std::vector s_Preset_sla_printer_options { "display_orientation", "fast_tilt_time", "slow_tilt_time", "area_fill", "relative_correction", + "relative_correction_x", + "relative_correction_y", + "relative_correction_z", "absolute_correction", "elefant_foot_compensation", "elefant_foot_min_width", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 6315bdc52..14d48368f 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3146,7 +3146,31 @@ void PrintConfigDef::init_sla_params() def->tooltip = L("Printer scaling correction"); def->min = 0; def->mode = comExpert; - def->set_default_value(new ConfigOptionFloats( { 1., 1. } )); + def->set_default_value(new ConfigOptionFloats( { 1., 1.} )); + + def = this->add("relative_correction_x", coFloat); + def->label = L("Printer scaling correction in X axis"); + def->full_label = L("Printer scaling X axis correction"); + def->tooltip = L("Printer scaling correction in X axis"); + def->min = 0; + def->mode = comExpert; + def->set_default_value(new ConfigOptionFloat(1.)); + + def = this->add("relative_correction_y", coFloat); + def->label = L("Printer scaling correction in Y axis"); + def->full_label = L("Printer scaling X axis correction"); + def->tooltip = L("Printer scaling correction in Y axis"); + def->min = 0; + def->mode = comExpert; + def->set_default_value(new ConfigOptionFloat(1.)); + + def = this->add("relative_correction_z", coFloat); + def->label = L("Printer scaling correction in Z axis"); + def->full_label = L("Printer scaling X axis correction"); + def->tooltip = L("Printer scaling correction in Z axis"); + def->min = 0; + def->mode = comExpert; + def->set_default_value(new ConfigOptionFloat(1.)); def = this->add("absolute_correction", coFloat); def->label = L("Printer absolute correction"); @@ -3292,7 +3316,28 @@ void PrintConfigDef::init_sla_params() def->tooltip = L("Correction for expansion"); def->min = 0; def->mode = comExpert; - def->set_default_value(new ConfigOptionFloats( { 1. , 1. } )); + def->set_default_value(new ConfigOptionFloats( { 1., 1., 1. } )); + + def = this->add("material_correction_x", coFloat); + def->full_label = L("Correction for expansion in X axis"); + def->tooltip = L("Correction for expansion in X axis"); + def->min = 0; + def->mode = comExpert; + def->set_default_value(new ConfigOptionFloat(1.)); + + def = this->add("material_correction_y", coFloat); + def->full_label = L("Correction for expansion in Y axis"); + def->tooltip = L("Correction for expansion in Y axis"); + def->min = 0; + def->mode = comExpert; + def->set_default_value(new ConfigOptionFloat(1.)); + + def = this->add("material_correction_z", coFloat); + def->full_label = L("Correction for expansion in Z axis"); + def->tooltip = L("Correction for expansion in Z axis"); + def->min = 0; + def->mode = comExpert; + def->set_default_value(new ConfigOptionFloat(1.)); def = this->add("material_notes", coString); def->label = L("SLA print material notes"); @@ -3749,7 +3794,16 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va opt_key = "printhost_apikey"; } else if (opt_key == "preset_name") { opt_key = "preset_names"; - } + } /*else if (opt_key == "material_correction" || opt_key == "relative_correction") { + ConfigOptionFloats p; + p.deserialize(value); + + if (p.values.size() < 3) { + double firstval = p.values.front(); + p.values.emplace(p.values.begin(), firstval); + value = p.serialize(); + } + }*/ // Ignore the following obsolete configuration keys: static std::set ignore = { @@ -3866,6 +3920,28 @@ void DynamicPrintConfig::normalize_fdm() } } +void handle_legacy_sla(DynamicPrintConfig &config) +{ + for (std::string corr : {"relative_correction", "material_correction"}) { + if (config.has(corr)) { + if (std::string corr_x = corr + "_x"; !config.has(corr_x)) { + auto* opt = config.opt(corr_x, true); + opt->value = config.opt(corr)->values[0]; + } + + if (std::string corr_y = corr + "_y"; !config.has(corr_y)) { + auto* opt = config.opt(corr_y, true); + opt->value = config.opt(corr)->values[0]; + } + + if (std::string corr_z = corr + "_z"; !config.has(corr_z)) { + auto* opt = config.opt(corr_z, true); + opt->value = config.opt(corr)->values[1]; + } + } + } +} + void DynamicPrintConfig::set_num_extruders(unsigned int num_extruders) { const auto &defaults = FullPrintConfig::defaults(); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index d7409d12c..8297f9d2f 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -224,6 +224,8 @@ public: { PrintConfigDef::handle_legacy(opt_key, value); } }; +void handle_legacy_sla(DynamicPrintConfig &config); + class StaticPrintConfig : public StaticConfig { public: @@ -924,6 +926,9 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionFloat, exposure_time)) ((ConfigOptionFloat, initial_exposure_time)) ((ConfigOptionFloats, material_correction)) + ((ConfigOptionFloat, material_correction_x)) + ((ConfigOptionFloat, material_correction_y)) + ((ConfigOptionFloat, material_correction_z)) ) PRINT_CONFIG_CLASS_DEFINE( @@ -940,6 +945,9 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionBool, display_mirror_x)) ((ConfigOptionBool, display_mirror_y)) ((ConfigOptionFloats, relative_correction)) + ((ConfigOptionFloat, relative_correction_x)) + ((ConfigOptionFloat, relative_correction_y)) + ((ConfigOptionFloat, relative_correction_z)) ((ConfigOptionFloat, absolute_correction)) ((ConfigOptionFloat, elefant_foot_compensation)) ((ConfigOptionFloat, elefant_foot_min_width)) diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 43ac958b5..55acd3846 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -807,7 +807,13 @@ bool SLAPrint::invalidate_state_by_config_options(const std::vector steps_full = { "initial_layer_height", "material_correction", + "material_correction_x", + "material_correction_y", + "material_correction_z", "relative_correction", + "relative_correction_x", + "relative_correction_y", + "relative_correction_z", "absolute_correction", "elefant_foot_compensation", "elefant_foot_min_width", @@ -1047,15 +1053,15 @@ Vec3d SLAPrint::relative_correction() const Vec3d corr(1., 1., 1.); if(printer_config().relative_correction.values.size() >= 2) { - corr.x() = printer_config().relative_correction.values[0]; - corr.y() = corr.x(); - corr.z() = printer_config().relative_correction.values[1]; + corr.x() = printer_config().relative_correction_x.value; + corr.y() = printer_config().relative_correction_y.value; + corr.z() = printer_config().relative_correction_z.value; } if(material_config().material_correction.values.size() >= 2) { - corr.x() *= material_config().material_correction.values[0]; - corr.y() = corr.x(); - corr.z() *= material_config().material_correction.values[1]; + corr.x() *= material_config().material_correction_x.value; + corr.y() *= material_config().material_correction_y.value; + corr.z() *= material_config().material_correction_z.value; } return corr; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 038a513d1..6c820cff3 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2479,14 +2479,11 @@ void TabPrinter::build_sla() optgroup = page->new_optgroup(L("Corrections")); line = Line{ m_config->def()->get("relative_correction")->full_label, "" }; -// std::vector axes{ "X", "Y", "Z" }; - std::vector axes{ "XY", "Z" }; - int id = 0; + std::vector axes{ "X", "Y", "Z" }; for (auto& axis : axes) { - auto opt = optgroup->get_option("relative_correction", id); + auto opt = optgroup->get_option(std::string("relative_correction_") + char(std::tolower(axis[0]))); opt.opt.label = axis; line.append_option(opt); - ++id; } optgroup->append_line(line); optgroup->append_single_option_line("absolute_correction"); @@ -4204,21 +4201,16 @@ void TabSLAMaterial::build() optgroup->append_single_option_line("initial_exposure_time"); optgroup = page->new_optgroup(L("Corrections")); - std::vector corrections = {"material_correction"}; -// std::vector axes{ "X", "Y", "Z" }; - std::vector axes{ "XY", "Z" }; - for (auto& opt_key : corrections) { - auto line = Line{ m_config->def()->get(opt_key)->full_label, "" }; - int id = 0; - for (auto& axis : axes) { - auto opt = optgroup->get_option(opt_key, id); - opt.opt.label = axis; - line.append_option(opt); - ++id; - } - optgroup->append_line(line); + auto line = Line{ m_config->def()->get("material_correction")->full_label, "" }; + std::vector axes{ "X", "Y", "Z" }; + for (auto& axis : axes) { + auto opt = optgroup->get_option(std::string("material_correction_") + char(std::tolower(axis[0]))); + opt.opt.label = axis; + line.append_option(opt); } + optgroup->append_line(line); + page = add_options_page(L("Notes"), "note.png"); optgroup = page->new_optgroup(L("Notes"), 0); optgroup->label_width = 0;