Skip to content

Commit

Permalink
Retract on top layer option. (#6188)
Browse files Browse the repository at this point in the history
Co-authored-by: SoftFever <[email protected]>
  • Loading branch information
vovodroid and SoftFever authored Nov 23, 2024
1 parent 717fe35 commit ca35ba4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5981,7 +5981,7 @@ std::string GCode::travel_to(const Point& point, ExtrusionRole role, std::string
m_wipe.reset_path();*/

Point last_post_before_retract = this->last_pos();
gcode += this->retract(false, false, lift_type);
gcode += this->retract(false, false, lift_type, role);
// When "Wipe while retracting" is enabled, then extruder moves to another position, and travel from this position can cross perimeters.
// Because of it, it is necessary to call avoid crossing perimeters again with new starting point after calling retraction()
// FIXME Lukas H.: Try to predict if this second calling of avoid crossing perimeters will be needed or not. It could save computations.
Expand Down Expand Up @@ -6183,7 +6183,7 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftTyp
return true;
}

std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType lift_type)
std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType lift_type, ExtrusionRole role)
{
std::string gcode;

Expand All @@ -6201,7 +6201,8 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li
(the extruder might be already retracted fully or partially). We call these
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 (role != erTopSolidInfill || EXTRUDER_CONFIG(retract_on_top_layer))
gcode += toolchange ? m_writer.retract_for_toolchange() : m_writer.retract();

gcode += m_writer.reset_e();
// Orca: check if should + can lift (roughly from SuperSlicer)
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class GCode {

std::string travel_to(const Point& point, ExtrusionRole role, std::string comment, double z = DBL_MAX);
bool needs_retraction(const Polyline& travel, ExtrusionRole role, LiftType& lift_type);
std::string retract(bool toolchange = false, bool is_last_retraction = false, LiftType lift_type = LiftType::NormalLift);
std::string retract(bool toolchange = false, bool is_last_retraction = false, LiftType lift_type = LiftType::NormalLift, ExtrusionRole role = erNone);
std::string unretract() { return m_writer.unlift() + m_writer.unretract(); }
std::string set_extruder(unsigned int extruder_id, double print_z, bool by_object=false);
bool is_BBL_Printer();
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
"retraction_minimum_travel",
"retract_before_wipe",
"retract_when_changing_layer",
"retract_on_top_layer",
"retraction_length",
"retract_length_toolchange",
"z_hop",
Expand Down
14 changes: 11 additions & 3 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3711,6 +3711,12 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionBools { false });

def = this->add("retract_on_top_layer", coBools);
def->label = L("Retract on top layer");
def->tooltip = L("Force a retraction on top layer. Disabling could prevent clog on very slow patterns with small movements, like Hilbert curve");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionBools { true });

def = this->add("retraction_length", coFloats);
def->label = L("Length");
def->full_label = L("Retraction Length");
Expand Down Expand Up @@ -5371,7 +5377,7 @@ void PrintConfigDef::init_fff_params()
// BBS: floats
"wipe_distance",
// bools
"retract_when_changing_layer", "wipe",
"retract_when_changing_layer", "retract_on_top_layer", "wipe",
// percents
"retract_before_wipe",
"long_retractions_when_cut",
Expand Down Expand Up @@ -5423,7 +5429,7 @@ void PrintConfigDef::init_extruder_option_keys()
"nozzle_diameter", "min_layer_height", "max_layer_height", "extruder_offset",
"retraction_length", "z_hop", "z_hop_types", "travel_slope", "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",
"retract_when_changing_layer", "retract_on_top_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "extruder_colour",
"default_filament_profile","retraction_distances_when_cut","long_retractions_when_cut"
};

Expand All @@ -5436,6 +5442,7 @@ void PrintConfigDef::init_extruder_option_keys()
"retract_lift_enforce",
"retract_restart_extra",
"retract_when_changing_layer",
"retract_on_top_layer",
"retraction_distances_when_cut",
"retraction_length",
"retraction_minimum_travel",
Expand All @@ -5455,7 +5462,7 @@ void PrintConfigDef::init_filament_option_keys()
"filament_diameter", "min_layer_height", "max_layer_height",
"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",
"retract_when_changing_layer", "retract_on_top_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "filament_colour",
"default_filament_profile","retraction_distances_when_cut","long_retractions_when_cut"/*,"filament_seam_gap"*/
};

Expand All @@ -5468,6 +5475,7 @@ void PrintConfigDef::init_filament_option_keys()
"retract_lift_enforce",
"retract_restart_extra",
"retract_when_changing_layer",
"retract_on_top_layer",
"retraction_distances_when_cut",
"retraction_length",
"retraction_minimum_travel",
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE(
((ConfigOptionFloat, resolution))
((ConfigOptionFloats, retraction_minimum_travel))
((ConfigOptionBools, retract_when_changing_layer))
((ConfigOptionBools, retract_on_top_layer))
((ConfigOptionFloat, skirt_distance))
((ConfigOptionInt, skirt_height))
((ConfigOptionInt, skirt_loops))
Expand Down
3 changes: 2 additions & 1 deletion src/slic3r/GUI/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4322,6 +4322,7 @@ if (is_marlin_flavor)
optgroup->append_single_option_line("deretraction_speed", "", extruder_idx);
optgroup->append_single_option_line("retraction_minimum_travel", "", extruder_idx);
optgroup->append_single_option_line("retract_when_changing_layer", "", extruder_idx);
optgroup->append_single_option_line("retract_on_top_layer", "", extruder_idx);
optgroup->append_single_option_line("wipe", "", extruder_idx);
optgroup->append_single_option_line("wipe_distance", "", extruder_idx);
optgroup->append_single_option_line("retract_before_wipe", "", extruder_idx);
Expand Down Expand Up @@ -4538,7 +4539,7 @@ void TabPrinter::toggle_options()
// user can customize other retraction options if retraction is enabled
//BBS
bool retraction = have_retract_length || use_firmware_retraction;
std::vector<std::string> vec = { "z_hop", "retract_when_changing_layer" };
std::vector<std::string> vec = {"z_hop", "retract_when_changing_layer", "retract_on_top_layer"};
for (auto el : vec)
toggle_option(el, retraction, i);

Expand Down

0 comments on commit ca35ba4

Please sign in to comment.