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") {