From f564ce39c4bf8bfa16aa91f69ef513b24b5a67aa Mon Sep 17 00:00:00 2001 From: Ian Bassi Date: Tue, 17 Nov 2026 22:02:19 -0300 Subject: [PATCH] Finish the retraction after a wipe on Hilbert curve surfaces A wipe retracts only part of the length and leaves the rest, including retract_after_wipe, to the regular retraction that follows. On the first layer with Hilbert curve bottom surfaces, and on Hilbert curve top surfaces, that retraction is skipped, so the rest was silently dropped. Always finish the retraction once a wipe has started it. Ported from Snapmaker/OrcaSlicer@b070bcfaffcf93aaa04dff8fe97da3ee8dbd68bb Co-authored-by: lhx --- src/libslic3r/GCode.cpp | 9 ++++--- tests/fff_print/test_wipe.cpp | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index fa85557b6e..3e4c26d36a 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -10967,7 +10967,8 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li return gcode; // wipe (if it's enabled for this extruder and we have a stored wipe path and no-zero wipe distance) - if (FILAMENT_CONFIG(wipe) && m_wipe.has_path() && scale_(FILAMENT_CONFIG(wipe_distance)) > SCALED_EPSILON) { + const bool wiped = FILAMENT_CONFIG(wipe) && m_wipe.has_path() && scale_(FILAMENT_CONFIG(wipe_distance)) > SCALED_EPSILON; + if (wiped) { Wipe::RetractionValues wipeRetractions = m_wipe.calculateWipeRetractionLengths(*this, toolchange); gcode += toolchange ? m_writer.retract_for_toolchange(true, wipeRetractions.retraction_length_before_wipe) : m_writer.retract(true, wipeRetractions.retraction_length_before_wipe); @@ -10981,8 +10982,10 @@ 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. */ - if ((!this->on_first_layer() || this->config().bottom_surface_pattern != InfillPattern::ipHilbertCurve) && - (role != erTopSolidInfill || this->config().top_surface_pattern != InfillPattern::ipHilbertCurve)) + // Hilbert curve surfaces skip the retraction, but not the rest of one a wipe has started. + if (wiped || + ((!this->on_first_layer() || this->config().bottom_surface_pattern != InfillPattern::ipHilbertCurve) && + (role != erTopSolidInfill || this->config().top_surface_pattern != InfillPattern::ipHilbertCurve))) gcode += toolchange ? m_writer.retract_for_toolchange() : m_writer.retract(); gcode += m_writer.reset_e(); diff --git a/tests/fff_print/test_wipe.cpp b/tests/fff_print/test_wipe.cpp index df49d56771..fe5cb43d74 100644 --- a/tests/fff_print/test_wipe.cpp +++ b/tests/fff_print/test_wipe.cpp @@ -797,3 +797,50 @@ TEST_CASE("Inward wipe remains valid after wipe on loops moves the nozzle", "[Wi } REQUIRE(start_changed); } + +TEST_CASE("A wipe retracts the full length on a first layer with Hilbert curve bottom surfaces", "[Wipe][RetractionSplit][Regression]") +{ + DynamicPrintConfig config = wipe_config("classic", false); + config.set_deserialize_strict({ + {"gcode_flavor", "marlin2"}, + {"use_relative_e_distances", "1"}, + {"bottom_surface_pattern", "hilbertcurve"}, + {"retraction_minimum_travel", "0"}, + {"retraction_length", "0.8"}, + {"retract_before_wipe", "0%"}, + {"retract_after_wipe", "50%"}, + {"retraction_speed", "25.5"}, + {"role_based_wipe_speed", "0"}, + {"wipe_speed", "100"}, + {"wipe_distance", "2"}, + }); + // Two cubes, so each layer travels between them and retracts with a wipe. + const std::string output = slice({make_cube(10., 10., 1.), make_cube(10., 10., 1.)}, config); + const auto &start_tag = GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Wipe_Start); + bool wipe_seen = false; + double retracted = 0.; + size_t wipes = 0; + size_t first_layer_wipes = 0; + GCodeReader parser; + parser.apply_config(config); + parser.parse_buffer(output, [&](GCodeReader &self, const GCodeReader::GCodeLine &line) { + if (line.comment().find(start_tag) == 0) { + wipe_seen = true; + } else if (line.retracting(self)) { + retracted -= line.dist_E(self); + } else if (line.extruding(self) && line.dist_XY(self) > EPSILON) { + if (wipe_seen) { + CAPTURE(self.z()); + // The 50% left for after the wipe counts too. + CHECK_THAT(retracted, Catch::Matchers::WithinAbs(0.8, 0.0001)); + ++wipes; + if (self.z() < 0.2 + EPSILON) + ++first_layer_wipes; + } + retracted = 0.; + wipe_seen = false; + } + }); + REQUIRE(first_layer_wipes > 0); + REQUIRE(wipes > first_layer_wipes); +}