diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index ee1a10893b..3b856f6a5a 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -4057,20 +4057,16 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description, double F = speed * 60; // convert mm/sec to mm/min // extrude arc or line - if (m_enable_extrusion_role_markers) - { - if (path.role() != m_last_extrusion_role) - { - m_last_extrusion_role = path.role(); - if (m_enable_extrusion_role_markers) - { - char buf[32]; - sprintf(buf, ";_EXTRUSION_ROLE:%d\n", int(m_last_extrusion_role)); - gcode += buf; - } - } + if (m_enable_extrusion_role_markers) { + if (path.role() != m_last_extrusion_role) { + char buf[32]; + sprintf(buf, ";_EXTRUSION_ROLE:%d\n", int(path.role())); + gcode += buf; + } } + m_last_extrusion_role = path.role(); + // adds processor tags and updates processor tracking data // PrusaMultiMaterial::Writer may generate GCodeProcessor::Height_Tag lines without updating m_last_height // so, if the last role was erWipeTower we force export of GCodeProcessor::Height_Tag lines @@ -4288,6 +4284,11 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description, if (m_enable_cooling_markers) { gcode += ";_EXTRUDE_END\n"; } + + if (path.role() != ExtrusionRole::erGapFill) { + m_last_notgapfill_extrusion_role = path.role(); + } + this->set_last_pos(path.last_point()); return gcode; } @@ -4519,8 +4520,34 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li gcode += toolchange ? m_writer.retract_for_toolchange() : m_writer.retract(); gcode += m_writer.reset_e(); + + // check if should + can lift (roughly from SuperSlicer) + RetractLiftEnforceType retract_lift_type = RetractLiftEnforceType(EXTRUDER_CONFIG(retract_lift_enforce)); + + bool needs_lift = toolchange + || m_writer.extruder()->retraction_length() > 0 + || m_config.use_firmware_retraction; + + bool last_fill_extrusion_role_top_infill = (this->m_last_notgapfill_extrusion_role == ExtrusionRole::erTopSolidInfill || this->m_last_notgapfill_extrusion_role == ExtrusionRole::erIroning); + + // assume we can lift on retraction; conditions left explicit + bool can_lift = true; + + if (retract_lift_type == RetractLiftEnforceType::rletAllSurfaces) { + can_lift = true; + } + else if (this->m_layer_index == 0 && (retract_lift_type == RetractLiftEnforceType::rletBottomOnly || retract_lift_type == RetractLiftEnforceType::rletTopAndBottom)) { + can_lift = true; + } + else if (retract_lift_type == RetractLiftEnforceType::rletTopOnly || retract_lift_type == RetractLiftEnforceType::rletTopAndBottom) { + can_lift = last_fill_extrusion_role_top_infill; + } + else { + can_lift = false; + } + //BBS - if (m_writer.extruder()->retraction_length() > 0 || m_config.use_firmware_retraction) { + if (needs_lift && can_lift) { // BBS: don't do lazy_lift when enable spiral vase size_t extruder_id = m_writer.extruder()->id(); gcode += m_writer.lift(!m_spiral_vase ? lift_type : LiftType::NormalLift); diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index dd1c357267..9baac4d8bd 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -459,6 +459,8 @@ private: //double m_volumetric_speed; // Support for the extrusion role markers. Which marker is active? ExtrusionRole m_last_extrusion_role; + // To ignore gapfill role for retract_lift_enforce + ExtrusionRole m_last_notgapfill_extrusion_role; // Support for G-Code Processor float m_last_height{ 0.0f }; float m_last_layer_z{ 0.0f }; diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index e52b413b4b..2516af7856 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -691,7 +691,10 @@ std::string GCodeWriter::lift(LiftType lift_type) double target_lift = 0; { //BBS - target_lift = this->config.z_hop.get_at(m_extruder->id()); + double above = this->config.retract_lift_above.get_at(m_extruder->id()); + double below = this->config.retract_lift_below.get_at(m_extruder->id()); + if (m_pos(2) >= above && (below == 0 || m_pos(2) <= below)) + target_lift = this->config.z_hop.get_at(m_extruder->id()); } // BBS if (m_lifted == 0 && m_to_lift == 0 && target_lift > 0) { diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 15ef51b309..47703f9298 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -773,7 +773,7 @@ static std::vector s_Preset_filament_options { "fan_max_speed", "enable_overhang_bridge_fan", "overhang_fan_speed", "overhang_fan_threshold", "close_fan_the_first_x_layers", "full_fan_speed_layer", "fan_cooling_layer_time", "slow_down_layer_time", "slow_down_min_speed", "filament_start_gcode", "filament_end_gcode", // Retract overrides - "filament_retraction_length", "filament_z_hop", "filament_z_hop_types", "filament_retraction_speed", "filament_deretraction_speed", "filament_retract_restart_extra", "filament_retraction_minimum_travel", + "filament_retraction_length", "filament_z_hop", "filament_z_hop_types", "filament_retract_lift_above", "filament_retract_lift_below", "filament_retract_lift_enforce", "filament_retraction_speed", "filament_deretraction_speed", "filament_retract_restart_extra", "filament_retraction_minimum_travel", "filament_retract_when_changing_layer", "filament_wipe", "filament_retract_before_wipe", // Profile compatibility "filament_vendor", "compatible_prints", "compatible_prints_condition", "compatible_printers", "compatible_printers_condition", "inherits", @@ -802,7 +802,7 @@ static std::vector s_Preset_printer_options { "silent_mode", // BBS "scan_first_layer", "machine_load_filament_time", "machine_unload_filament_time", "machine_pause_gcode", "template_custom_gcode", - "nozzle_type", "nozzle_hrc","auxiliary_fan", "nozzle_volume","upward_compatible_machine", "z_hop_types", + "nozzle_type", "nozzle_hrc","auxiliary_fan", "nozzle_volume","upward_compatible_machine", "z_hop_types", "retract_lift_enforce", //SoftFever "host_type", "print_host", "printhost_apikey", "print_host_webui", diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 46090dcaee..4cd8484994 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -136,7 +136,10 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "retract_when_changing_layer", "retraction_length", "retract_length_toolchange", - "z_hop", + "z_hop", + "retract_lift_above", + "retract_lift_below", + "retract_lift_enforce", "retract_restart_extra", "retract_restart_extra_toolchange", "retraction_speed", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 451bb09ded..cd9f1c61cb 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -307,6 +307,14 @@ static const t_config_enum_values s_keys_map_ZHopType = { }; CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(ZHopType) +static const t_config_enum_values s_keys_map_RetractLiftEnforceType = { + {"All Surfaces", rletAllSurfaces}, + {"Top Only", rletTopOnly}, + {"Bottom Only", rletBottomOnly}, + {"Top and Bottom", rletTopAndBottom} +}; +CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(RetractLiftEnforceType) + static void assign_printer_technology_to_unknown(t_optiondef_map &options, PrinterTechnology printer_technology) { for (std::pair &kvp : options) @@ -2553,6 +2561,35 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionEnumsGeneric{ ZHopType::zhtNormal }); + def = this->add("retract_lift_above", coFloats); + def->label = L("Only lift Z above"); + def->tooltip = L("If you set this to a positive value, Z lift will only take place above the specified absolute Z."); + def->sidetext = L("mm"); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloats{0.}); + + def = this->add("retract_lift_below", coFloats); + def->label = L("Only lift Z below"); + def->tooltip = L("If you set this to a positive value, Z lift will only take place below the specified absolute Z."); + def->sidetext = L("mm"); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloats{0.}); + + def = this->add("retract_lift_enforce", coEnums); + def->label = L("On surfaces"); + def->tooltip = L("Enforce Z Hop behavior. This setting is impacted by the above settings (Only lift Z above/below)."); + def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); + def->enum_values.push_back("All Surfaces"); + def->enum_values.push_back("Top Only"); + def->enum_values.push_back("Bottom Only"); + def->enum_values.push_back("Top and Bottom"); + def->enum_labels.push_back(L("All Surfaces")); + def->enum_labels.push_back(L("Top Only")); + def->enum_labels.push_back(L("Bottom Only")); + def->enum_labels.push_back(L("Top and Bottom")); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionEnumsGeneric{RetractLiftEnforceType ::rletAllSurfaces}); + def = this->add("retract_restart_extra", coFloats); def->label = L("Extra length on restart"); def->tooltip = L("When the retraction is compensated after the travel move, the extruder will push " @@ -3592,7 +3629,7 @@ void PrintConfigDef::init_fff_params() // Declare retract values for filament profile, overriding the printer's extruder profile. for (const char *opt_key : { // floats - "retraction_length", "z_hop", "z_hop_types", "retraction_speed", "deretraction_speed", "retract_restart_extra", "retraction_minimum_travel", + "retraction_length", "z_hop", "z_hop_types", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed", "retract_restart_extra", "retraction_minimum_travel", // BBS: floats "wipe_distance", // bools @@ -3639,7 +3676,7 @@ void PrintConfigDef::init_extruder_option_keys() // ConfigOptionFloats, ConfigOptionPercents, ConfigOptionBools, ConfigOptionStrings m_extruder_option_keys = { "nozzle_diameter", "min_layer_height", "max_layer_height", "extruder_offset", - "retraction_length", "z_hop", "z_hop_types", "retraction_speed", "deretraction_speed", + "retraction_length", "z_hop", "z_hop_types", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed", "retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance", "retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "extruder_colour", "default_filament_profile" @@ -3648,6 +3685,9 @@ void PrintConfigDef::init_extruder_option_keys() m_extruder_retract_keys = { "deretraction_speed", "retract_before_wipe", + "retract_lift_above", + "retract_lift_below", + "retract_lift_enforce", "retract_restart_extra", "retract_when_changing_layer", "retraction_length", @@ -3665,7 +3705,7 @@ void PrintConfigDef::init_filament_option_keys() { m_filament_option_keys = { "filament_diameter", "min_layer_height", "max_layer_height", - "retraction_length", "z_hop", "z_hop_types", "retraction_speed", "deretraction_speed", + "retraction_length", "z_hop", "z_hop_types", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed", "retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance", "retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "filament_colour", "default_filament_profile"/*,"filament_seam_gap"*/ @@ -3674,6 +3714,9 @@ void PrintConfigDef::init_filament_option_keys() m_filament_retract_keys = { "deretraction_speed", "retract_before_wipe", + "retract_lift_above", + "retract_lift_below", + "retract_lift_enforce", "retract_restart_extra", "retract_when_changing_layer", "retraction_length", diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 5ad5122e50..1360b9c94f 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -218,6 +218,13 @@ enum ZHopType { zhtCount }; +enum RetractLiftEnforceType { + rletAllSurfaces = 0, + rletTopOnly, + rletBottomOnly, + rletTopAndBottom +}; + static std::string bed_type_to_gcode_string(const BedType type) { std::string type_str; @@ -863,6 +870,9 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionFloats, z_hop)) // BBS ((ConfigOptionEnumsGeneric, z_hop_types)) + ((ConfigOptionFloats, retract_lift_above)) + ((ConfigOptionFloats, retract_lift_below)) + ((ConfigOptionEnumsGeneric, retract_lift_enforce)) ((ConfigOptionFloats, retract_restart_extra)) ((ConfigOptionFloats, retract_restart_extra_toolchange)) ((ConfigOptionFloats, retraction_speed)) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index bb9f7fb350..4df00aca75 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2560,7 +2560,10 @@ void TabFilament::add_filament_overrides_page() for (const std::string opt_key : { "filament_retraction_length", "filament_z_hop", - "filament_z_hop_types", + "filament_z_hop_types", + "filament_retract_lift_above", + "filament_retract_lift_below", + "filament_retract_lift_enforce", "filament_retraction_speed", "filament_deretraction_speed", "filament_retract_restart_extra", @@ -2594,7 +2597,10 @@ void TabFilament::update_filament_overrides_page() std::vector opt_keys = { "filament_retraction_length", "filament_z_hop", - "filament_z_hop_types", + "filament_z_hop_types", + "filament_retract_lift_above", + "filament_retract_lift_below", + "filament_retract_lift_enforce", "filament_retraction_speed", "filament_deretraction_speed", "filament_retract_restart_extra", @@ -3507,6 +3513,11 @@ void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/) optgroup->append_single_option_line("wipe_distance", "", extruder_idx); optgroup->append_single_option_line("retract_before_wipe", "", extruder_idx); + optgroup = page->new_optgroup(L("Lift Z Enforcement"), L"param_retraction", -1, true); + optgroup->append_single_option_line("retract_lift_above", "", extruder_idx); + optgroup->append_single_option_line("retract_lift_below", "", extruder_idx); + optgroup->append_single_option_line("retract_lift_enforce", "", extruder_idx); + optgroup = page->new_optgroup(L("Retraction when switching material"), L"param_retraction", -1, true); optgroup->append_single_option_line("retract_length_toolchange", "", extruder_idx); optgroup->append_single_option_line("retract_restart_extra_toolchange", "", extruder_idx); @@ -3707,6 +3718,12 @@ void TabPrinter::toggle_options() for (auto el : vec) toggle_option(el, retraction, i); + // retract lift above / below + enforce only applies if using retract lift + vec.resize(0); + vec = {"retract_lift_above", "retract_lift_below", "retract_lift_enforce"}; + for (auto el : vec) + toggle_option(el, retraction && (m_config->opt_float("z_hop", i) > 0), i); + // some options only apply when not using firmware retraction vec.resize(0); vec = { "retraction_speed", "deretraction_speed", "retract_before_wipe", "retract_restart_extra", "wipe", "wipe_distance" };