Join Precise-Z Sliver Layers to the Prime Tower Layer Below (#17204)

* Join Precise-Z Sliver Layers to the Prime Tower Layer Below

Precise Z height ends each object at its exact top, so another object's
layers can print a few microns above these. Each sliver became its own
wipe tower layer, and a tool change on it was sized for that height: a
0.0009 mm layer asked for a 230 mm ramming band, which grew the tower
past the bed ("Prime tower is partially outside the printable area").
Once sized correctly, G-code export lost step with the tower and threw
"append_tcr was asked to do a toolchange it didn't expect".

A tower layer thinner than half the printer's minimum layer height now
joins the tower layer below: ToolOrdering records the tower layer each
layer prints on and whether it finishes it, the tower plans the joined
tool changes on that layer's z and height, and the G-code neither
advances the tower on a joined layer nor finishes the layer before it.

* Finish a Joined Prime Tower Layer on Its Last Tool Change

The joined layer always finished the tower layer, so a joined layer that
changed no tools asked for a result after the layer below had taken them
all and threw "Wipe tower generation failed". The layer that finishes is
now the last of the group that changes tools, or the last one when none
does, matching how a single layer merges its finish into a tool change.

A joined layer also reset the Type 1 tower's first print, so smooth
timelapse replayed the tower layer's wall and threw the same error.

Layers are now joined below the printer's minimum layer height instead of
half of it: precise Z height can move a layer off by up to a layer height,
and the 0.04-0.08 mm layers left on their own still grew the tower off the
bed.

* Print Joined Prime Tower Purges at the Tower Layer's Z

A joined layer printed its purges at its own nozzle height, up to just
under the minimum layer height above the tower layer, so the beads were
not pressed onto it. The emitter now descends to the tower layer's z for
a joined layer, travelling over the tower first and climbing back after,
the way it already does for a tower compacted below the objects.

Layers sliced at exactly the minimum layer height sum to gaps a hair
under it and were joined to the layer below; an EPSILON margin keeps
them apart.

* Travel Over the Prime Tower Before a Joined Layer Descends

With no change_filament_gcode and no nozzle change, the Type 1 emitter
descended to the joined tower layer's z while the head was still over the
part, then travelled to the tower at that z. It now travels over the tower
first. The tests check that every descent below the object layer happens
over the tower.

(cherry picked from commit 1c9f6f9318)
This commit is contained in:
HanifKoh committed 2026-11-13 19:40:16 +08:00
1 parent 3eb2d3ca35
commit 135f383eb2
7 files changed
+290 -24

No files matched your search

+28 -9
View File
@@ -1166,7 +1166,9 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
// over the tower - which is what the is_finish_first travel above does. Otherwise the nozzle
// is still over the model and this descent would drive it into the print, so defer it to the
// re-descents below, which run after the travel to the tower.
const bool defer_compacted_descend = m_sparse_layers_skipped
// A layer joined to the tower layer below descends to it the same way, by less than a layer.
const bool joined_below_layer = m_layer_joined && !tcr.priming && (current_z - z) > EPSILON;
const bool defer_compacted_descend = (m_sparse_layers_skipped || joined_below_layer)
&& !tcr.priming && !tcr.is_finish_first && (current_z - z) > EPSILON;
if (!is_approx(z, current_z) && !defer_compacted_descend) {
gcode += gcodegen.writer().retract();
@@ -1175,7 +1177,7 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
}
// Tower compacted below the object, so any extrusion emitted without an explicit z has to be
// pulled back down to it first.
const bool compacted_below_object = m_sparse_layers_skipped && z >= 0. && (tcr.print_z - z) > EPSILON;
const bool compacted_below_object = (m_sparse_layers_skipped && z >= 0. && (tcr.print_z - z) > EPSILON) || joined_below_layer;
// Process the end filament gcode.
bool add_change_filament_624 = false;
@@ -1510,6 +1512,14 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
if (position_before_toolchange)
gcodegen.synchronize_toolchange_position(*position_before_toolchange, toolchange_gcode_str);
// A joined layer descends to the tower layer below it. With no macro and no nozzle change
// nothing has moved the head off the part yet, so travel over the tower before that descent.
if (joined_below_layer && !need_travel_after_change_filament_gcode && !is_nozzle_change) {
std::string start_pos_str = gcodegen.travel_to(wipe_tower_point_to_object_point(gcodegen, tool_change_start_pos + plate_origin_2d), erMixed, "Move to start pos");
check_add_eol(start_pos_str);
wipe_next_start_point_str = start_pos_str;
}
if (need_travel_after_change_filament_gcode) {
// move to start_pos for wiping after toolchange
if (!is_used_travel_avoid_perimeter) {
@@ -2102,7 +2112,8 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
ignore_sparse = wipe_tower_layer_is_sparse(m_tool_changes[m_layer_idx]) && m_layer_idx != 0;
if (m_tool_change_idx == 0 && !ignore_sparse)
wipe_tower_z = m_last_wipe_tower_print_z + m_tool_changes[m_layer_idx].front().layer_height;
}
} else if (m_layer_joined)
wipe_tower_z = joined_tower_z();
if (!ignore_sparse) {
gcode += append_tcr2(gcodegen, m_tool_changes[m_layer_idx][m_tool_change_idx++], extruder_id, wipe_tower_z);
@@ -2119,7 +2130,8 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
if (m_sparse_layers_skipped) {
ignore_sparse = wipe_tower_layer_is_sparse(m_tool_changes[m_layer_idx]);
wipe_tower_z = m_compacted_tower_z[m_layer_idx];
}
} else if (m_layer_joined)
wipe_tower_z = joined_tower_z();
if ((m_enable_timelapse_print || m_enable_wrapping_detection) && m_is_first_print) {
gcode += append_tcr(gcodegen, m_tool_changes[m_layer_idx][0], m_tool_changes[m_layer_idx][0].new_tool, wipe_tower_z);
@@ -5175,8 +5187,13 @@ void GCode::process_layers(
const std::pair<coordf_t, std::vector<LayerToPrint>>& layer = layers_to_print[precomputed.index];
const LayerTools& layer_tools = tool_ordering.tools_for_layer(layer.first);
print.set_status(80, Slic3r::format(_(L("Generating G-code: layer %1%")), std::to_string(precomputed.index + 1)));
if (m_wipe_tower && layer_tools.has_wipe_tower)
m_wipe_tower->next_layer();
// A layer that joined the tower layer below continues it.
if (m_wipe_tower && layer_tools.has_wipe_tower) {
if (layer_tools.joins_wipe_tower_layer_below())
m_wipe_tower->join_layer();
else
m_wipe_tower->next_layer();
}
//BBS
check_placeholder_parser_failed();
print.throw_if_canceled();
@@ -7419,7 +7436,8 @@ LayerResult GCode::process_layer(
gcode += insert_timelapse_gcode();
}
if (m_wipe_tower)
// A joined layer continues a tower layer whose first print is already done.
if (m_wipe_tower && ! layer_tools.joins_wipe_tower_layer_below())
m_wipe_tower->set_is_first_print(true);
auto insert_wrapping_detection_gcode = [this, &print, &print_z, &most_used_extruder]() -> std::string {
@@ -7508,7 +7526,8 @@ LayerResult GCode::process_layer(
std::string gcode_toolchange;
if (has_wipe_tower) {
if (!m_wipe_tower->is_empty_wipe_tower_gcode(*this, extruder_id, extruder_id == layer_tools.extruders.back())) {
const bool finish_tower_layer = extruder_id == layer_tools.extruders.back() && layer_tools.wipe_tower_layer_ends;
if (!m_wipe_tower->is_empty_wipe_tower_gcode(*this, extruder_id, finish_tower_layer)) {
if (need_insert_timelapse_gcode_for_traditional && !has_insert_timelapse_gcode
&& !(m_farthest_point_timelapse.enabled && m_farthest_point_timelapse.farthest_is_photo_head)) {
bool should_insert = true;
@@ -7536,7 +7555,7 @@ LayerResult GCode::process_layer(
gcode += insert_wrapping_detection_gcode();
has_insert_wrapping_detection_gcode = true;
}
gcode_toolchange = m_wipe_tower->tool_change(*this, extruder_id, extruder_id == layer_tools.extruders.back());
gcode_toolchange = m_wipe_tower->tool_change(*this, extruder_id, finish_tower_layer);
}
} else {
// Same case-A/case-B split for the non-wipe-tower path. With the subsystem off,