Share the prime-tower rule with the slicer instead of copying it

imex_wipe_tower_hull() open-coded "does this plate print a tower?" as one
filament and no forcing reason. normalize_fdm_2, which is what actually
clears enable_prime_tower before slicing, has a second arm the copy omitted,
and reads the mixed-filament flag project-wide where the copy read the
plate. Two cases went wrong in opposite directions.

A ByObject plate with several objects prints no tower and the scene draws
none, yet the copy validated one and could refuse the slice with "the prime
tower overlaps an area reserved for IDEX/IQEX parallel printing" - with
nothing on screen to move.

A plate using one plain slot while some other slot in the project is a blend
does print a tower, because normalize_fdm_2 keeps it for any mixed filament
in the project, and the copy skipped validation entirely, so the tower could
be placed in a carriage zone and sliced.

prime_tower_is_printed() in libslic3r states the rule once, and both the
gate and a test use it. The counts are the ones normalize_fdm_2 is handed:
filament slots as authored, so a mixed slot counts once, and distinct
objects rather than instances. filament_is_mixed is a project option, so it
is passed in rather than read from the print preset.

The test drives every combination the rule looks at and compares the verdict
against normalize_fdm_2 itself, so the two cannot drift again without
failing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Clifford Garwood
2026-09-18 01:41:42 -04:00
co-authored by Claude Opus 5
parent 0e44269c5e
commit b6a2c76e5d
4 changed files with 93 additions and 18 deletions
+19 -18
View File
@@ -1118,27 +1118,28 @@ Polygon PartPlate::imex_wipe_tower_hull() const
return Polygon();
const DynamicPrintConfig& print_cfg = preset_bundle->prints.get_edited_preset().config;
const ConfigOptionBool* enable_opt = print_cfg.option<ConfigOptionBool>("enable_prime_tower");
if (!enable_opt || !enable_opt->value)
// Whether a tower is PRINTED is normalize_fdm_2's rule, shared with the slicer through
// prime_tower_is_printed() rather than re-derived here - re-deriving it is what let this
// validate a tower the slicer had already cancelled. Do not substitute the footprint
// estimate: it reports a tower for a single filament whenever the flush matrix purges
// (SEMM + purge_in_prime_tower, the Klipper default), which hard-blocks a plate with
// nothing drawn on screen to move.
//
// Counts are the ones normalize_fdm_2 is handed: filament slots as authored, so a mixed
// slot counts once, and distinct objects rather than instances. filament_is_mixed is a
// project option, hence read separately.
const auto* mixed_opt = preset_bundle->project_config.option<ConfigOptionBools>("filament_is_mixed");
const bool has_mixed = mixed_opt != nullptr && has_any_mixed_filament(mixed_opt->values);
std::set<int> plate_objects;
for (const auto& pr : obj_to_instance_set)
plate_objects.insert(pr.first);
if (!prime_tower_is_printed(print_cfg, (int) get_extruders(true, /*expand_mixed=*/false).size(),
(int) plate_objects.size(), has_mixed))
return Polygon();
// Approximates normalize_fdm_2(), which is what actually decides whether a tower is
// printed: it clears enable_prime_tower for one filament, or ByObject over several
// objects, unless smooth timelapse or wrapping detection forces one.
//
// Do not substitute the footprint estimate's answer. It reports a tower for a single
// filament whenever the flush matrix purges (SEMM + purge_in_prime_tower, the Klipper
// default), which would hard-block a plate whose tower normalize_fdm_2 already cleared -
// with nothing drawn on screen to move. See test_wipe_tower_estimate.cpp.
auto timelapse_type = print_cfg.option<ConfigOptionEnum<TimelapseType>>("timelapse_type");
bool need_wipe_tower = timelapse_type ? (timelapse_type->value == TimelapseType::tlSmooth) : false;
// enable_wrapping_detection is a PRINT option; read from the printer preset it returns
// nullptr and silently skips validation for a tower the user can see and drag.
if (auto wrapping_opt = print_cfg.option<ConfigOptionBool>("enable_wrapping_detection"))
need_wipe_tower |= wrapping_opt->value;
// The estimate's floor counts what is purged, so a mixed slot counts as its components here.
const int plate_extruder_size = (int) get_extruders(true).size();
if (!need_wipe_tower && plate_extruder_size < 2)
return Polygon();
Vec3d wt_pos, wt_size;
// full_config(), not the print preset: wipe_tower_x/y are project options the estimate