From 99b70ef82f9063b74efce15da252d827dcd827b8 Mon Sep 17 00:00:00 2001 From: Ian Bassi Date: Wed, 18 Nov 2026 09:09:45 -0300 Subject: [PATCH] Wipe toward the Type1 prime tower on every plate After a toolchange on the Type1 prime tower, the wipe path was built in plate coordinates while the nozzle position includes the plate origin. On every plate but the first, the wipe that ends the toolchange headed toward the first plate instead of along the tower. The Type2 tower and the nozzle change path already add the plate origin. Found through Snapmaker/OrcaSlicer@407dc6f68e99957890630fb4b196e962d5d750a4, which adds the plate origin to the same wipe in the fork's version of the Type2 path. Co-authored-by: fire2wind <1229725087@qq.com> --- src/libslic3r/GCode.cpp | 2 +- tests/fff_print/test_wipe_tower.cpp | 46 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 3e4c26d36a..baa927090f 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1660,7 +1660,7 @@ static std::vector get_path_of_change_filament(const Print& print) // Prepare a future wipe. gcodegen.m_wipe.reset_path(); for (const Vec2f &wipe_pt : tcr.wipe_path) - gcodegen.m_wipe.path.points.emplace_back(wipe_tower_point_to_object_point(gcodegen, transform_wt_pt(wipe_pt))); + gcodegen.m_wipe.path.points.emplace_back(wipe_tower_point_to_object_point(gcodegen, transform_wt_pt(wipe_pt) + plate_origin_2d)); gcode += gcodegen.retract(false, false, auto_lift_type, true); } diff --git a/tests/fff_print/test_wipe_tower.cpp b/tests/fff_print/test_wipe_tower.cpp index 0f3d9b1b6a..d6202d409e 100644 --- a/tests/fff_print/test_wipe_tower.cpp +++ b/tests/fff_print/test_wipe_tower.cpp @@ -290,6 +290,52 @@ TEST_CASE("Tower consumption is classified separately for each printer kind", "[ } } +// The points of the first wipe after each prime tower region, in G-code coordinates. +static std::vector wipes_after_tower(const std::string &gcode) +{ + const std::string &tower_start = GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Wipe_Tower_Start); + const std::string &tower_end = GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Wipe_Tower_End); + const std::string &wipe_start = GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Wipe_Start); + const std::string &wipe_end = GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Wipe_End); + std::vector points; + for (size_t pos = gcode.find(tower_end); pos != std::string::npos; pos = gcode.find(tower_end, pos + 1)) { + const size_t start = gcode.find(wipe_start, pos); + const size_t end = gcode.find(wipe_end, start); + if (start == std::string::npos || end == std::string::npos || gcode.find(tower_start, pos) < start) + continue; + GCodeReader reader; + reader.parse_buffer(gcode.substr(start, end - start), [&points](GCodeReader &, const GCodeReader::GCodeLine &line) { + if (line.has_x() && line.has_y()) + points.emplace_back(double(line.x()), double(line.y())); + }); + } + return points; +} + +TEST_CASE("A Type1 tower wipes the same way after a toolchange on every plate", "[WipeTower][Regression]") +{ + DynamicPrintConfig config = wipe_tower_toolchange_config("marlin"); + config.set_deserialize_strict({ { "wipe_tower_type", "type1" }, { "wipe", "1" }, { "wipe_distance", "2" } }); + auto tower_wipes = [&config](const Vec3d &plate_origin) { + Print print; + Model model; + init_print({ cube(10) }, print, model, config); + print.apply(model, config); + // The tower position is relative to the plate, so its G-code is the same on every plate. + print.set_plate_origin(plate_origin); + return wipes_after_tower(gcode(print)); + }; + const std::vector first_plate = tower_wipes(Vec3d::Zero()); + const std::vector other_plate = tower_wipes(Vec3d(300., 300., 0.)); + REQUIRE_FALSE(first_plate.empty()); + REQUIRE(other_plate.size() == first_plate.size()); + for (size_t i = 0; i < first_plate.size(); ++i) { + CAPTURE(i); + CHECK_THAT(other_plate[i].x(), Catch::Matchers::WithinAbs(first_plate[i].x(), 0.01)); + CHECK_THAT(other_plate[i].y(), Catch::Matchers::WithinAbs(first_plate[i].y(), 0.01)); + } +} + TEST_CASE("The wipe tower's toolchange planner flush follows the gcode flavor", "[WipeTower]") { SECTION("klipper") {