From 5633824f87c47d4c6cc06d7f7b7d3f6a2bfc1ac7 Mon Sep 17 00:00:00 2001 From: supermerill Date: Sun, 8 Nov 2020 23:41:09 +0100 Subject: [PATCH] #395 Z-Lift only on Top & zlift on First layers #642 Z-Lift dist as a range height modifier --- resources/ui_layout/extruder.ui | 5 +++- src/libslic3r/GCode.cpp | 14 +++++++--- src/libslic3r/GCodeWriter.cpp | 5 ++++ src/libslic3r/Preset.cpp | 1 + src/libslic3r/Print.cpp | 3 ++- src/libslic3r/PrintConfig.cpp | 45 +++++++++++++++++++++++++++------ src/libslic3r/PrintConfig.hpp | 25 +++++++++++++++--- src/slic3r/GUI/Tab.cpp | 2 +- 8 files changed, 82 insertions(+), 18 deletions(-) diff --git a/resources/ui_layout/extruder.ui b/resources/ui_layout/extruder.ui index affff5865..d9231e34a 100644 --- a/resources/ui_layout/extruder.ui +++ b/resources/ui_layout/extruder.ui @@ -16,7 +16,10 @@ group:Retraction line:Only lift Z setting:idx:retract_lift_above setting:idx:retract_lift_below - setting:idx:retract_lift_not_last_layer + end_line + line:Lift z enforcement + setting:idx:retract_lift_first_layer + setting:idx:retract_lift_top end_line line:Retraction Speed setting:idx:retract_speed diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 10b6dbd5f..b165e522c 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -4196,10 +4196,16 @@ std::string GCode::retract(bool toolchange) methods even if we performed wipe, since this will ensure the entire retraction length is honored in case wipe path was too short. */ gcode += toolchange ? m_writer.retract_for_toolchange() : m_writer.retract(); - if (toolchange - || !(BOOL_EXTRUDER_CONFIG(retract_lift_not_last_layer) && (this->m_last_extrusion_role == ExtrusionRole::erTopSolidInfill )) - || !m_writer.tool_is_extruder() - ) + bool need_lift = !m_writer.tool_is_extruder() || toolchange || (BOOL_EXTRUDER_CONFIG(retract_lift_first_layer) && m_config.print_retract_lift.value != 0 && this->m_layer_index == 0); + if (!need_lift && m_config.print_retract_lift.value != 0) { + if (EXTRUDER_CONFIG_WITH_DEFAULT(retract_lift_top, "") == "Not on top") + need_lift = (this->m_last_extrusion_role != ExtrusionRole::erTopSolidInfill); + else if (EXTRUDER_CONFIG_WITH_DEFAULT(retract_lift_top, "") == "Only on top") + need_lift = (this->m_last_extrusion_role == ExtrusionRole::erTopSolidInfill); + else + need_lift = true; + } + if (need_lift) if (m_writer.tool()->retract_length() > 0 || m_config.use_firmware_retraction || (!m_writer.tool_is_extruder() && m_writer.tool()->retract_lift() != 0) diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 1cea32fcc..afe04b21a 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -660,6 +660,11 @@ std::string GCodeWriter::lift() target_lift = m_tool->retract_lift(); } + // use the override if set + if (target_lift > 0 && config_region && config_region->print_retract_lift.value >= 0) { + target_lift = config_region->print_retract_lift.value; + } + if (this->extra_lift > 0) { target_lift += this->extra_lift; this->extra_lift = 0; diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 9c101382f..5360f6855 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -559,6 +559,7 @@ const std::vector& Preset::print_options() "print_extrusion_multiplier", "print_retract_length", "print_temperature", + "print_retract_lift", "external_perimeter_cut_corners", "external_perimeter_overlap", "perimeter_bonding", diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 8f9c14ad0..20c37ff74 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -148,7 +148,8 @@ bool Print::invalidate_state_by_config_options(const std::vectormode = comAdvanced; def->set_default_value(new ConfigOptionFloats { 0. }); - def = this->add("retract_lift_not_last_layer", coBools); - def->label = L("Not on top"); - def->full_label = L("Don't retract on top surfaces"); - def->category = OptionCategory::support; - def->tooltip = L("Select this option to not use the z-lift on a top surface."); + def = this->add("retract_lift_first_layer", coBools); + def->label = L("Enforce on first layer"); + def->full_label = L("Enforce lift on first layer"); + def->category = OptionCategory::extruders; + def->tooltip = L("Select this option to enforce z-lift on the first layer."); def->mode = comAdvanced; - def->set_default_value(new ConfigOptionBools { false }); + def->set_default_value(new ConfigOptionBools{ false }); + + def = this->add("retract_lift_top", coStrings); + def->label = L("On surfaces"); + def->full_label = L("Lift only on"); + def->category = OptionCategory::extruders; + def->tooltip = L("Select this option to not use/enforce the z-lift on a top surface."); + def->gui_type = "f_enum_open"; + def->gui_flags = "show_value"; + def->enum_values.push_back(("All surfaces")); + def->enum_values.push_back(("Not on top")); + def->enum_values.push_back(("Only on top")); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionStrings{ "All surfaces" }); + def = this->add("retract_restart_extra", coFloats); def->label = L("Extra length on restart"); @@ -3522,10 +3536,18 @@ void PrintConfigDef::init_fff_params() def = this->add("print_temperature", coInt); def->label = L("Temperature"); def->category = OptionCategory::filament; - def->tooltip = L("Override the temperature of the extruder. Avoid doing too many changes, it won't stop for cooling/heating. 0 to disable."); + def->tooltip = L("Override the temperature of the extruder. Avoid doing too many changes, it won't stop for cooling/heating. 0 to disable. May only works on Height range modifiers."); def->mode = comExpert; def->set_default_value(new ConfigOptionInt(0)); + def = this->add("print_retract_lift", coFloat); + def->label = L("Z-lift override"); + def->category = OptionCategory::filament; + def->tooltip = L("Set the new lift-z value for this override. 0 will disable the z-lift. -& to disable. May only works on Height range modifiers."); + def->sidetext = L("mm"); + def->mode = comExpert; + def->set_default_value(new ConfigOptionFloat(-1)); + def = this->add("thin_perimeters", coBool); def->label = L("Overlapping external perimeter"); def->full_label = L("Overlapping external perimeter"); @@ -3996,7 +4018,8 @@ void PrintConfigDef::init_extruder_option_keys() "retract_lift", "retract_lift_above", "retract_lift_below", - "retract_lift_not_last_layer", + "retract_lift_first_layer", + "retract_lift_top", "retract_speed", "deretract_speed", "retract_before_wipe", @@ -4875,6 +4898,12 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va value = "emit_to_gcode"; else value = "time_estimate_only"; + } else if (opt_key == "retract_lift_not_last_layer") { + opt_key = "retract_lift_top"; + if (value == "1") + value = "Not on top"; + else + value = "All surfaces"; } // Ignore the following obsolete configuration keys: diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 621577e8a..042535d3f 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -135,7 +135,13 @@ enum SLAPillarConnectionMode { slapcmZigZag, slapcmCross, slapcmDynamic -}; +}; + +enum ZLiftTop { + zltAll, + zltTop, + zltNotTop +}; template<> inline const t_config_enum_values& ConfigOptionEnum::get_enum_values() { static t_config_enum_values keys_map; @@ -342,6 +348,15 @@ template<> inline const t_config_enum_values& ConfigOptionEnum inline const t_config_enum_values& ConfigOptionEnum::get_enum_values() { + static const t_config_enum_values keys_map = { + {"everywhere", zltAll}, + {"onlytop", zltTop}, + {"nottop", zltNotTop} + }; + return keys_map; +} + // Defines each and every confiuration option of Slic3r, including the properties of the GUI dialogs. // Does not store the actual values, but defines default values. class PrintConfigDef : public ConfigDef @@ -774,6 +789,7 @@ public: ConfigOptionInt perimeters; ConfigOptionPercent print_extrusion_multiplier; ConfigOptionFloat print_retract_length; + ConfigOptionFloat print_retract_lift; ConfigOptionFloatOrPercent small_perimeter_speed; ConfigOptionFloatOrPercent small_perimeter_min_length; ConfigOptionFloatOrPercent small_perimeter_max_length; @@ -874,6 +890,7 @@ protected: OPT_PTR(perimeters); OPT_PTR(print_extrusion_multiplier); OPT_PTR(print_retract_length); + OPT_PTR(print_retract_lift); OPT_PTR(small_perimeter_speed); OPT_PTR(small_perimeter_min_length); OPT_PTR(small_perimeter_max_length); @@ -1023,7 +1040,8 @@ public: ConfigOptionFloats retract_lift; ConfigOptionFloats retract_lift_above; ConfigOptionFloats retract_lift_below; - ConfigOptionBools retract_lift_not_last_layer; + ConfigOptionBools retract_lift_first_layer; + ConfigOptionStrings retract_lift_top; ConfigOptionFloats retract_restart_extra; ConfigOptionFloats retract_restart_extra_toolchange; ConfigOptionFloats retract_speed; @@ -1128,7 +1146,8 @@ protected: OPT_PTR(retract_lift); OPT_PTR(retract_lift_above); OPT_PTR(retract_lift_below); - OPT_PTR(retract_lift_not_last_layer); + OPT_PTR(retract_lift_first_layer); + OPT_PTR(retract_lift_top); OPT_PTR(retract_restart_extra); OPT_PTR(retract_restart_extra_toolchange); OPT_PTR(retract_speed); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 496b38d6c..3064583c6 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2750,7 +2750,7 @@ void TabPrinter::toggle_options() // retract lift above / below only applies if using retract lift vec.resize(0); - vec = { "retract_lift_above", "retract_lift_below", "retract_lift_not_last_layer" }; + vec = { "retract_lift_above", "retract_lift_below", "retract_lift_first_layer", "retract_lift_top" }; for (auto el : vec) { field = get_field(el, i); if (field)