diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 78a322e3f6..3836c454f3 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -10426,7 +10426,7 @@ std::string GCode::travel_to(const Point& point, ExtrusionRole role, std::string jerk_to_set = initial_layer_travel_jerk; } } else { // ORCA: Handle short-travel acceleration and jerk for outer perimeters (if applicable) - const bool is_short_travel = travel.length() < scale_(EXTRUDER_CONFIG(retraction_minimum_travel)); + const bool is_short_travel = travel.length() < scale_(FILAMENT_CONFIG(retraction_minimum_travel)); if (NOZZLE_CONFIG(default_acceleration) > 0) { if (role == erOverhangPerimeter && is_short_travel) { @@ -10759,7 +10759,7 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li gcode += m_writer.reset_e(); // Orca: check if should + can lift (roughly from SuperSlicer) - RetractLiftEnforceType retract_lift_type = RetractLiftEnforceType(EXTRUDER_CONFIG(retract_lift_enforce)); + RetractLiftEnforceType retract_lift_type = RetractLiftEnforceType(FILAMENT_CONFIG(retract_lift_enforce)); bool needs_lift = toolchange || m_writer.filament()->retraction_length() > 0 diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 13d4efb367..761e89293d 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -906,12 +906,12 @@ std::string GCodeWriter::lazy_lift(LiftType lift_type, bool spiral_vase) double target_lift = 0; { //BBS - int extruder_id = filament()->extruder_id(); - int filament_id = filament()->id(); - double above = this->config.retract_lift_above.get_at(extruder_id); - double below = this->config.retract_lift_below.get_at(extruder_id); + // The filament's column, like Extruder::z_hop(): a filament can override the printer's lift limits. + const int config_index = filament()->config_index(); + double above = this->config.retract_lift_above.get_at(config_index); + double below = this->config.retract_lift_below.get_at(config_index); if (m_pos.z() >= above && (m_pos.z() <= below || below == 0.)) - target_lift = this->config.z_hop.get_at(filament_id); + target_lift = this->config.z_hop.get_at(config_index); } // BBS if (m_lifted == 0 && m_to_lift == 0 && target_lift > 0) { @@ -939,12 +939,12 @@ std::string GCodeWriter::eager_lift(const LiftType type) { double target_lift = 0; { //BBS - int extruder_id = filament()->extruder_id(); - int filament_id = filament()->id(); - double above = this->config.retract_lift_above.get_at(extruder_id); - double below = this->config.retract_lift_below.get_at(extruder_id); + // The filament's column, like Extruder::z_hop(): a filament can override the printer's lift limits. + const int config_index = filament()->config_index(); + double above = this->config.retract_lift_above.get_at(config_index); + double below = this->config.retract_lift_below.get_at(config_index); if (m_pos.z() >= above && (m_pos.z() <= below || below == 0.)) - target_lift = this->config.z_hop.get_at(filament_id); + target_lift = this->config.z_hop.get_at(config_index); } // BBS: spiral lift only safe with known position diff --git a/tests/fff_print/test_gcode.cpp b/tests/fff_print/test_gcode.cpp index 5d1d0b07de..aa9dc14137 100644 --- a/tests/fff_print/test_gcode.cpp +++ b/tests/fff_print/test_gcode.cpp @@ -464,6 +464,64 @@ TEST_CASE("An exported G-code's settings load back as the settings it was sliced CHECK(bundle.project_config.option>("prime_volume_mode")->value == PrimeVolumeMode::pvmFast); } +TEST_CASE("Z hop follows the lift settings of the filament printing", "[GCode]") +{ + // One nozzle, two filaments. Filament 2 overrides one lift setting; filament 1 keeps the printer's default, + // which lifts on every layer. + auto [key, value] = GENERATE(table({ + {"filament_retract_lift_above", "nil,1"}, // only lift Z above 1 mm + {"filament_retract_lift_enforce", "nil,Bottom Only"}, // only lift on the first layer + })); + const int filament = GENERATE(1, 2); + CAPTURE(key, filament); + DynamicPrintConfig config = Test::multifilament_config(2, { + // each filament its own variant column, as in a real preset + {"filament_self_index", "1,2"}, + {"filament_extruder_variant", "Direct Drive Standard;Direct Drive Standard"}, + {"z_hop", "0.6"}, + {key, value}, + {"layer_height", "0.2"}, + {"initial_layer_print_height", "0.2"}, + {"enable_prime_tower", 0}, + }); + Print print; + Model model; + const std::vector> overrides(2, {{"extruder", std::to_string(filament)}}); + // Two objects, so every layer travels between them with a retraction. + Test::init_print({Test::cube(20), Test::cube(20)}, print, model, config, &overrides); + + // The heights of the layers with a move that lifts Z above the layer. + std::set lift_layers; + double layer_z = 0.; + std::istringstream lines(Test::gcode(print)); + std::string line; + const std::regex z_word(R"(\bZ([-0-9.]+))"); + while (std::getline(lines, line)) { + if (line.rfind(";Z:", 0) == 0) { + layer_z = std::stod(line.substr(3)); + continue; + } + // Skip the start G-code, which lifts the nozzle before the first layer. + if (layer_z <= 0. || (line.rfind("G1 ", 0) != 0 && line.rfind("G0 ", 0) != 0)) + continue; + const std::string move = line.substr(0, line.find(';')); + std::smatch match; + if (std::regex_search(move, match, z_word) && std::stod(match[1]) > layer_z + 0.3) + lift_layers.insert(layer_z); + } + + REQUIRE_FALSE(lift_layers.empty()); + const double first = *lift_layers.begin(); + const double last = *lift_layers.rbegin(); + if (filament == 1) { + CHECK(first < 0.2 + EPSILON); + CHECK(last > 1.); + } else if (key == "filament_retract_lift_above") + CHECK(first > 1. - EPSILON); + else + CHECK(last < 0.2 + EPSILON); +} + // A temperature tower re-targets the hotend at every layer. On a multi-tool printer that // command has to name the tool printing the tower: a bare M104 goes to whichever tool the // firmware considers active, which the first-layer M109 right before it already addresses by