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@b070bcfaff

Co-authored-by: lhx <luohaoxuan@snapmaker.com>
This commit is contained in:
Ian Bassiandlhx committed 2026-11-30 14:27:08 -03:00
1 parent 2be8e9e955
commit f564ce39c4
2 files changed
+53 -3

No files matched your search

+6 -3
View File
@@ -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();
+47
View File
@@ -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);
}