Use the printing filament's retraction lift settings (#16965)

On a single-extruder printer with several filaments, every filament used filament 1's "Only lift Z above", "Only lift Z below", "On surfaces" and "Travel distance threshold" values, so a filament's own overrides of these settings were ignored. All four are now read for the filament that is printing.

Fixes #16185
This commit is contained in:
Gazi Faysal Jubayer authored and GitHub committed 2026-10-30 14:16:22 -05:00
1 parent 52c50e626e
commit 98b539c3e6
3 files changed
+70 -12

No files matched your search

+58
View File
@@ -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<ConfigOptionEnum<PrimeVolumeMode>>("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<std::string, std::string>({
{"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<std::vector<ConfigBase::SetDeserializeItem>> 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<double> 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