diff --git a/docs/HLSD/prime-tower-sparse-layers.md b/docs/HLSD/prime-tower-sparse-layers.md index 5175c4239e..1b20cc7af8 100644 --- a/docs/HLSD/prime-tower-sparse-layers.md +++ b/docs/HLSD/prime-tower-sparse-layers.md @@ -111,11 +111,14 @@ compacted z for the same reason. Reaching down is only safe if nothing tall stands near the tower. `Print.hpp` carries the clearance rule: a keep-out zone grown from the tower's footprint by the spiral z-hop envelope, and a per-object limit on how high an object may rise -near it, tiered by the nozzle cone, the head body, the rod and the lid. The same -rule serves the precise check on real extrusions, the pre-slice estimate that -feeds the plater, and the outlines the plater draws while an object is dragged, -so that the ring the user sees touches the object's outline exactly when the -check trips. +near it, tiered by the nozzle cone, the head body, the rod and the lid. The +precise check applies all four to the real extrusions, measuring an object's +rise from the tower as printed by then. Before slicing that height is unknown, +so the pre-slice estimate that feeds the plater, and the outlines the plater +draws while an object is dragged, measure the rise from the plate and apply only +the nozzle cone and the head body. An object away from the toolhead, which only +the rod or the lid can reach, is left to the precise check. The ring the user +sees touches the object's outline exactly when the pre-slice check trips. ## Merging sparse layers diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 0c0100db9b..b9b5daad2f 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1407,6 +1407,7 @@ CompactedTowerClearance compacted_wipe_tower_clearance(const PrintConfig &config const Polygons inst_near_nozzle = offset(inst_hull, float(scale_(compacted_tower_half_clearance(MAX_OUTER_NOZZLE_DIAMETER))), jtRound, scale_(0.1)); const bool near_nozzle = ! intersection(zone.grown_nozzle, inst_near_nozzle).empty(); result.near_body = false; + result.near_nozzle = near_nozzle; if (! object_is_short) { const Polygons inst_near_body = offset(inst_hull, float(scale_(compacted_tower_half_clearance(zone.body_radius))), jtRound, scale_(0.1)); result.near_body = ! intersection(zone.grown_body, inst_near_body).empty(); @@ -1506,15 +1507,17 @@ static Polygon estimated_wipe_tower_footprint(const Print &print) return footprint; } -// Pre-slice counterpart of validate_compacted_wipe_tower_clearance(). It applies the very same -// clearance rule, but to an estimated tower footprint instead of the real tool-change extrusions, -// which is what lets it run from Print::validate() before anything has been sliced. Reporting through -// polygons / height_polygons rather than by throwing is what puts the collision area and the height -// limit plane on the plater, exactly the way sequential printing does it. +// Pre-slice counterpart of validate_compacted_wipe_tower_clearance(). It applies the same clearance +// rule to the objects near the toolhead, but to an estimated tower footprint instead of the real +// tool-change extrusions, which is what lets it run from Print::validate() before anything has been +// sliced. Reporting through polygons / height_polygons rather than by throwing is what puts the +// collision area and the height limit plane on the plater, exactly the way sequential printing does it. StringObjectException Print::compacted_wipe_tower_clearance_valid(const Print &print, Polygons *polygons, std::vector> *height_polygons) { const PrintConfig &config = print.config(); - if (! wipe_tower_sparse_layers_skipped(config) || config.print_sequence != PrintSequence::ByLayer || ! print.has_wipe_tower()) + // Orca: when only the support could change filaments, whether there is a tower at all is left to + // validate_compacted_wipe_tower_clearance(), once slicing has told. + if (! wipe_tower_sparse_layers_skipped(config) || config.print_sequence != PrintSequence::ByLayer || ! print.wipe_tower_certain_before_slicing()) return {}; const CompactedTowerZone zone = compacted_wipe_tower_zone(config, estimated_wipe_tower_footprint(print)); @@ -1531,14 +1534,16 @@ StringObjectException Print::compacted_wipe_tower_clearance_valid(const Print &p if (inst_hull.points.empty()) continue; const CompactedTowerClearance clearance = compacted_wipe_tower_clearance(config, zone, inst_hull, object_top); - body_tier_used = body_tier_used || compacted_tower_body_tier(clearance); - // Every tier the precise check applies is applied here too, otherwise an object standing - // within the toolhead radius would pass here and then be rejected mid-slice, which is the - // one outcome this check exists to prevent. The compacted tower base is unknown before - // slicing, so the rise is measured from the plate rather than from the tower top; that - // overstates it by the tower's own height and makes this check err strict, never lax. - if (object_top <= clearance.allowed_rise + EPSILON) + // Orca: away from the toolhead only the rod and the lid limit an object, and whether it reaches + // them depends on how far the compacted tower has grown by each tool change, which only slicing + // tells. Measured from the plate, any object taller than the lid clearance was refused wherever + // it stood. validate_compacted_wipe_tower_clearance() judges those against the real tower. + if (! clearance.near_nozzle && ! clearance.near_body) continue; + // Orca: closer, the rise is measured from the plate, the tower base being unknown before slicing, + // which errs strict. Next to the nozzle an object may not rise at all, and within the toolhead + // radius it is taller than nozzle_height, the most it may rise there, so either way it is refused. + body_tier_used = body_tier_used || compacted_tower_body_tier(clearance); // Height-limit and too-close cases share one user-facing message: both mean the layout // violates the "No sparse layers" clearance rule, and the remedies are the same. @@ -2052,6 +2057,93 @@ std::string Print::slicing_errors_message(const SlicingErrors &errors) const return message; } +// Orca: the layering a prime tower needs, all objects sharing their layers over the height they have in common. +StringObjectException Print::validate_wipe_tower_layering() const +{ + if (m_objects.size() < 2) + return {}; + const bool has_custom_layering = std::any_of(m_objects.begin(), m_objects.end(), + [](const PrintObject *object) { return object->model_object()->has_custom_layering(); }); + std::vector> layer_height_profiles(m_objects.size()); + auto layer_height_profile = [this, &layer_height_profiles](const size_t print_object_idx) -> const std::vector& { + std::vector &profile = layer_height_profiles[print_object_idx]; + if (profile.empty()) + PrintObject::update_layer_height_profile(*m_objects[print_object_idx]->model_object(), m_objects[print_object_idx]->slicing_parameters(), profile); + return profile; + }; + + const SlicingParameters &slicing_params0 = m_objects.front()->slicing_parameters(); + size_t tallest_object_idx = 0; + for (size_t i = 1; i < m_objects.size(); ++ i) { + const PrintObject *object = m_objects[i]; + const SlicingParameters &slicing_params = object->slicing_parameters(); + if (std::abs(slicing_params.first_print_layer_height - slicing_params0.first_print_layer_height) > EPSILON || + std::abs(slicing_params.layer_height - slicing_params0.layer_height ) > EPSILON) + return {L("A prime tower requires that all objects have the same layer height."), object, "initial_layer_print_height"}; + if (slicing_params.raft_layers() != slicing_params0.raft_layers()) + return {L("A prime tower requires that all objects are printed over the same number of raft layers."), object, "raft_layers"}; + // BBS: support gap can be multiple of object layer height, remove _L() +#if 0 + if (slicing_params0.gap_object_support != slicing_params.gap_object_support || + slicing_params0.gap_support_object != slicing_params.gap_support_object) + return {L("The prime tower is only supported for multiple objects if they are printed with the same support_top_z_distance."), object}; +#endif + if (!equal_layering(slicing_params, slicing_params0)) + return { L("A prime tower requires that all objects are sliced with the same layer height."), object }; + if (has_custom_layering) { + auto &lh = layer_height_profile(i); + auto &lh_tallest = layer_height_profile(tallest_object_idx); + if (*(lh.end() - 2) > *(lh_tallest.end() - 2)) + tallest_object_idx = i; + } + } + + // BBS: remove obsolete logics and _L() + if (has_custom_layering) { + std::vector> layer_z_series; + layer_z_series.assign(m_objects.size(), std::vector()); + + for (size_t idx_object = 0; idx_object < m_objects.size(); ++idx_object) { + layer_z_series[idx_object] = generate_object_layers(m_objects[idx_object]->slicing_parameters(), layer_height_profile(idx_object), m_objects[idx_object]->config().precise_z_height.value); + } + + for (size_t idx_object = 0; idx_object < m_objects.size(); ++idx_object) { + if (idx_object == tallest_object_idx) continue; + // Check that the layer height profiles are equal. This will happen when one object is + // a copy of another, or when a layer height modifier is used the same way on both objects. + // The latter case might create a floating point inaccuracy mismatch, so compare + // element-wise using an epsilon check. + size_t i = 0; + const coordf_t eps = 0.5 * EPSILON; // layers closer than EPSILON will be merged later. Let's make + // this check a bit more sensitive to make sure we never consider two different layers as one. + while (i < layer_height_profiles[idx_object].size() && i < layer_height_profiles[tallest_object_idx].size()) { + // BBS: remove the break condition, because a variable layer height object and a new object will not be checked when slicing + //if (i % 2 == 0 && layer_height_profiles[tallest_object_idx][i] > layer_height_profiles[idx_object][layer_height_profiles[idx_object].size() - 2]) + // break; + if (std::abs(layer_height_profiles[idx_object][i] - layer_height_profiles[tallest_object_idx][i]) > eps) + return {L("The prime tower is only supported if all objects have the same variable layer height.")}; + ++i; + } + } + } + return {}; +} + +// Orca: a tower is printed only on a tool change. When the parts themselves use one filament, the only +// tool changes can come from support printed with another filament, and only slicing tells whether +// there is any support at all. +bool Print::wipe_tower_certain_before_slicing() const +{ + if (! this->has_wipe_tower()) + return false; + if ((m_config.enable_wrapping_detection.value && m_config.wrapping_exclude_area.values.size() > 2) || this->enable_timelapse_print()) + return true; + std::vector extruders = this->object_extruders(); + this->append_tool_change_extruders(extruders); + sort_remove_duplicates(extruders); + return extruders.size() > 1; +} + StringObjectException Print::validate(std::vector *warnings, Polygons* collison_polygons, std::vector>* height_polygons) const { auto add_warning = [warnings](StringObjectException w) { @@ -2518,11 +2610,6 @@ StringObjectException Print::validate(std::vector *warnin } } - // Some of the objects has variable layer height applied by painting or by a table. - bool has_custom_layering = std::find_if(m_objects.begin(), m_objects.end(), - [](const PrintObject *object) { return object->model_object()->has_custom_layering(); }) - != m_objects.end(); - // Custom layering is not allowed for tree supports as of now. for (size_t print_object_idx = 0; print_object_idx < m_objects.size(); ++ print_object_idx) if (const PrintObject &print_object = *m_objects[print_object_idx]; @@ -2599,62 +2686,11 @@ StringObjectException Print::validate(std::vector *warnin } #endif - if (m_objects.size() > 1) { - const SlicingParameters &slicing_params0 = m_objects.front()->slicing_parameters(); - size_t tallest_object_idx = 0; - for (size_t i = 1; i < m_objects.size(); ++ i) { - const PrintObject *object = m_objects[i]; - const SlicingParameters &slicing_params = object->slicing_parameters(); - if (std::abs(slicing_params.first_print_layer_height - slicing_params0.first_print_layer_height) > EPSILON || - std::abs(slicing_params.layer_height - slicing_params0.layer_height ) > EPSILON) - return {L("A prime tower requires that all objects have the same layer height."), object, "initial_layer_print_height"}; - if (slicing_params.raft_layers() != slicing_params0.raft_layers()) - return {L("A prime tower requires that all objects are printed over the same number of raft layers."), object, "raft_layers"}; - // BBS: support gap can be multiple of object layer height, remove _L() -#if 0 - if (slicing_params0.gap_object_support != slicing_params.gap_object_support || - slicing_params0.gap_support_object != slicing_params.gap_support_object) - return {L("The prime tower is only supported for multiple objects if they are printed with the same support_top_z_distance."), object}; -#endif - if (!equal_layering(slicing_params, slicing_params0)) - return { L("A prime tower requires that all objects are sliced with the same layer height."), object }; - if (has_custom_layering) { - auto &lh = layer_height_profile(i); - auto &lh_tallest = layer_height_profile(tallest_object_idx); - if (*(lh.end() - 2) > *(lh_tallest.end() - 2)) - tallest_object_idx = i; - } - } - - // BBS: remove obsolete logics and _L() - if (has_custom_layering) { - std::vector> layer_z_series; - layer_z_series.assign(m_objects.size(), std::vector()); - - for (size_t idx_object = 0; idx_object < m_objects.size(); ++idx_object) { - layer_z_series[idx_object] = generate_object_layers(m_objects[idx_object]->slicing_parameters(), layer_height_profiles[idx_object], m_objects[idx_object]->config().precise_z_height.value); - } - - for (size_t idx_object = 0; idx_object < m_objects.size(); ++idx_object) { - if (idx_object == tallest_object_idx) continue; - // Check that the layer height profiles are equal. This will happen when one object is - // a copy of another, or when a layer height modifier is used the same way on both objects. - // The latter case might create a floating point inaccuracy mismatch, so compare - // element-wise using an epsilon check. - size_t i = 0; - const coordf_t eps = 0.5 * EPSILON; // layers closer than EPSILON will be merged later. Let's make - // this check a bit more sensitive to make sure we never consider two different layers as one. - while (i < layer_height_profiles[idx_object].size() && i < layer_height_profiles[tallest_object_idx].size()) { - // BBS: remove the break condition, because a variable layer height object and a new object will not be checked when slicing - //if (i % 2 == 0 && layer_height_profiles[tallest_object_idx][i] > layer_height_profiles[idx_object][layer_height_profiles[idx_object].size() - 2]) - // break; - if (std::abs(layer_height_profiles[idx_object][i] - layer_height_profiles[tallest_object_idx][i]) > eps) - return {L("The prime tower is only supported if all objects have the same variable layer height.")}; - ++i; - } - } - } - } + // Orca: the objects only have to share their layers when the tower is printed. When that depends on + // the support slicing generates, _make_wipe_tower() checks it once the tool changes are known. + if (m_objects.size() > 1 && (this->has_belt_purge_tower() || this->wipe_tower_certain_before_slicing())) + if (StringObjectException error = this->validate_wipe_tower_layering(); ! error.string.empty()) + return error; } { @@ -3719,6 +3755,9 @@ void Print::process(long long *time_cost_with_cache, bool use_cache) m_wipe_tower_data.clear(); m_tool_ordering.clear(); + // Orca: _make_wipe_tower() sets it up only for a tower it generates, so none is left from an earlier + // slicing of the plate, nor uninitialized when the plate turns out to change no filament. + m_fake_wipe_tower = FakeWipeTower(); if (this->has_belt_purge_tower() && this->config().print_sequence != PrintSequence::ByObject) { this->_plan_belt_purge(); } @@ -4056,7 +4095,8 @@ void Print::process(long long *time_cost_with_cache, bool use_cache) using Clock = std::chrono::high_resolution_clock; auto startTime = Clock::now(); std::optional wipe_tower_opt = {}; - if (this->has_wipe_tower()) { + // Orca: only a tower that is printed can collide with the objects. + if (this->has_wipe_tower() && m_wipe_tower_data.tool_ordering.has_wipe_tower()) { m_fake_wipe_tower.set_pos({m_config.wipe_tower_x.get_at(m_plate_index), m_config.wipe_tower_y.get_at(m_plate_index)}); wipe_tower_opt = std::make_optional(&m_fake_wipe_tower); } @@ -5365,6 +5405,12 @@ void Print::_make_wipe_tower() // Don't generate any wipe tower. return; + // Orca: validate() leaves the layering unchecked when only the support could change filaments, since + // it cannot know before slicing whether there is any support. Now that there are tool changes, check it. + if (! this->wipe_tower_certain_before_slicing()) + if (StringObjectException error = this->validate_wipe_tower_layering(); ! error.string.empty()) + throw Slic3r::SlicingError(error.string, error.object ? error.object->id().id : 0); + // Check whether there are any layers in m_tool_ordering, which are marked with has_wipe_tower, // they print neither object, nor support. Each such layer needs a virtual support layer // counterpart in m_objects.front() so that GCode::collect_layers_to_print picks it up and the diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 85b3a28b30..38627daeea 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -1188,6 +1188,12 @@ public: // Wipe tower support. bool has_wipe_tower() const; + // Orca: has_wipe_tower() only says the prime tower is enabled for a plate that may change filaments. + // This says the plate prints a tower whatever slicing finds; when false, whether it does depends on + // the support that slicing generates. + bool wipe_tower_certain_before_slicing() const; + // Orca: the layering a prime tower needs, all objects sharing their layers. Empty if they do. + StringObjectException validate_wipe_tower_layering() const; // Belt purge prism (belt-mode replacement for the wipe tower). bool has_belt_purge_tower() const; const WipeTowerData& wipe_tower_data(size_t filaments_cnt = 0) const; @@ -1668,6 +1674,8 @@ struct CompactedTowerClearance double far_clearance; // The object sits within the toolhead radius, so the head body limits it rather than the rod. bool near_body; + // The object sits within the nozzle cone, so it may not rise above the tower at all. + bool near_nozzle; // Horizontal clearance this particular object has to keep from the tower: the full toolhead // radius once it rises past the nozzle cone, the bare cone while it stays below. It is what the // error message quotes and what the plater grows the object outline by. diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 927f820f03..2f5bdad07d 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -6444,8 +6444,8 @@ void GLCanvas3D::update_compacted_wipe_tower_clearance() // the moment that object goes over its limit - which is what makes the pair worth drawing at all. // The tier is per object, so a short object gets the narrow nozzle outline rather than the wide // body one it is not subject to; without that, a 3 mm object parked beside the tower would be drawn - // deep inside the keep-out ring while passing the check. Only the instances that already exceed - // allowed_rise also get a height limit plane. + // deep inside the keep-out ring while passing the check. Only the instances the validation refuses, + // next to the nozzle or within the toolhead radius, also get a height limit plane. Polygons outlines; std::vector> height_polygons; bool body_tier_used = false; @@ -6460,15 +6460,17 @@ void GLCanvas3D::update_compacted_wipe_tower_clearance() continue; // Same tiers and the same rise measured from the plate as - // Print::compacted_wipe_tower_clearance_valid(), so that the preview and the validation - // that follows it never contradict each other. + // Print::compacted_wipe_tower_clearance_valid(), so that the preview shows a height limit on + // the very objects the validation that follows refuses. Orca: like it, the preview leaves an + // object away from the toolhead to the check after slicing, which measures its rise from the + // tower as printed, so such an object gets no height limit plane. const double object_top = model_object->get_instance_max_z(i); const CompactedTowerClearance clearance = compacted_wipe_tower_clearance(config, zone, inst_hull, object_top); body_tier_used = body_tier_used || compacted_tower_body_tier(clearance); const Polygon outline = compacted_wipe_tower_offender_outline(inst_hull, clearance.body_clearance); outlines.emplace_back(outline); - if (object_top <= clearance.allowed_rise + EPSILON) + if (! clearance.near_nozzle && ! clearance.near_body) continue; height_polygons.emplace_back(outline, float(clearance.allowed_rise)); } diff --git a/tests/fff_print/test_print.cpp b/tests/fff_print/test_print.cpp index 3832ec3cae..ab2a9d802c 100644 --- a/tests/fff_print/test_print.cpp +++ b/tests/fff_print/test_print.cpp @@ -9,6 +9,7 @@ #endif #include +#include #include #include #include @@ -2883,6 +2884,62 @@ TEST_CASE("Changing G-code precision invalidates only G-code export", "[Print][R namespace { +// A plate printed by layer with the prime tower on and both filaments loaded. The tower stands in a corner +// of the 200 mm bed, far from where the objects are placed. +DynamicPrintConfig prime_tower_config(std::initializer_list extra = {}) +{ + DynamicPrintConfig config = multifilament_config(2, { + { "enable_prime_tower", 1 }, + { "printable_area", "0x0,200x0,200x200,0x200" }, + { "wipe_tower_x", 160 }, + { "wipe_tower_y", 160 }, + { "prime_tower_width", 20 }, + { "layer_height", 0.2 }, + { "initial_layer_print_height", 0.2 }, + { "skirt_loops", 0 }, + { "brim_type", "no_brim" }, + { "layer_change_gcode", "G92 E0\n" }, // validate() relative-E reset + }); + config.set_deserialize_strict(extra); + return config; +} + +// Support on filament 1 with its interface on filament 2, for the objects that need any. +const std::initializer_list support_interface_on_filament_2 = { + { "enable_support", 1 }, + { "support_type", "normal(auto)" }, + { "support_threshold_angle", 30 }, + { "support_filament", 1 }, + { "support_interface_filament", 2 }, +}; + +ModelObject *add_object(Model &model, TriangleMesh &&mesh, double x, double y) +{ + ModelObject *object = model.add_object(); + object->add_volume(std::move(mesh)); + object->add_instance()->set_offset(Vec3d(x, y, 0.)); + object->ensure_on_bed(); + return object; +} + +// Slices the lower half of a 20 mm cube at 0.1 mm, so that it shares none of its layers there with an +// object sliced at 0.2 mm. +void slice_lower_half_finer(ModelObject &object) +{ + DynamicPrintConfig range; + range.set_key_value("layer_height", new ConfigOptionFloat(0.1)); + object.layer_config_ranges[{ 0., 10. }].assign_config(std::move(range)); +} + +void print_upper_part_with_filament_2(ModelObject &object, double from_z, double to_z) +{ + DynamicPrintConfig range; + range.set_key_value("extruder", new ConfigOptionInt(2)); + // Every layer range must carry a layer_height (see layer_height_profile_from_ranges). + range.set_key_value("layer_height", new ConfigOptionFloat(0.2)); + object.layer_config_ranges[{ from_z, to_z }].assign_config(std::move(range)); +} + // The slicing parameters of an object printed with one filament, on a printer whose first extruder // allows layers up to 0.32 mm and the second one up to 0.28 mm. The layers are 0.2 mm, within both. SlicingParameters slicing_parameters_on_filament(unsigned int filament) @@ -2906,6 +2963,98 @@ SlicingParameters slicing_parameters_on_filament(unsigned int filament) } // namespace +// The parts use one filament and only their support would use the other, so the plate changes filaments +// only if slicing generates support. Without any, no tower is printed, and the objects need not share +// their layers. +TEST_CASE("A plate is sliced with objects that do not share their layers when no support changes filaments", "[Print][PrimeTower]") +{ + Model model; + slice_lower_half_finer(*add_object(model, cube(20), 20., 20.)); + add_object(model, cube(20), 60., 20.); + Print print; + print.apply(model, prime_tower_config(support_interface_on_filament_2)); + + CHECK(print.validate().string.empty()); + REQUIRE_NOTHROW(print.process()); + CHECK(print.wipe_tower_data().tool_changes.empty()); +} + +TEST_CASE("Objects that do not share their layers are refused once their support changes filaments", "[Print][PrimeTower]") +{ + Model model; + slice_lower_half_finer(*add_object(model, cube(20), 20., 20.)); + TriangleMesh overhang = mesh(TestMesh::overhang); + overhang.scale(2.f); + add_object(model, std::move(overhang), 60., 20.); + Print print; + print.apply(model, prime_tower_config(support_interface_on_filament_2)); + + // Before slicing it is not known whether the overhang gets support. + CHECK(print.validate().string.empty()); + REQUIRE_THROWS_WITH(print.process(), Catch::Matchers::ContainsSubstring("prime tower")); +} + +TEST_CASE("Objects that do not share their layers are refused before slicing when their parts use two filaments", "[Print][PrimeTower]") +{ + Model model; + slice_lower_half_finer(*add_object(model, cube(20), 20., 20.)); + add_object(model, cube(20), 60., 20.)->config.set_key_value("extruder", new ConfigOptionInt(2)); + Print print; + print.apply(model, prime_tower_config()); + + CHECK_THAT(print.validate().string, Catch::Matchers::ContainsSubstring("prime tower")); +} + +// "No sparse layers" refuses an object that rises too far above the compacted tower. Away from the +// toolhead that limit is the lid clearance above the tower, which slicing alone tells how tall it is. +TEST_CASE("No sparse layers lets an object away from the tower rise past the lid clearance when the tower keeps up", "[Print][PrimeTower]") +{ + Model model; + // A tool change on every layer, so the compacted tower is as tall as the objects. + add_object(model, make_cube(20., 20., 40.), 20., 20.); + add_object(model, make_cube(20., 20., 40.), 60., 20.)->config.set_key_value("extruder", new ConfigOptionInt(2)); + Print print; + print.apply(model, prime_tower_config({ + { "wipe_tower_no_sparse_layers", 1 }, + { "extruder_clearance_height_to_lid", 20 }, + { "extruder_clearance_height_to_rod", 20 }, + })); + + CHECK(print.validate().string.empty()); + REQUIRE_NOTHROW(print.process()); + CHECK_FALSE(print.wipe_tower_data().tool_changes.empty()); +} + +TEST_CASE("No sparse layers still refuses an object that rises past the lid clearance above the tower", "[Print][PrimeTower]") +{ + Model model; + // The filament only changes from 30 mm up, by when the compacted tower is still a few layers tall. + print_upper_part_with_filament_2(*add_object(model, make_cube(20., 20., 40.), 20., 20.), 30., 40.); + Print print; + print.apply(model, prime_tower_config({ + { "wipe_tower_no_sparse_layers", 1 }, + { "extruder_clearance_height_to_lid", 20 }, + { "extruder_clearance_height_to_rod", 20 }, + })); + + CHECK(print.validate().string.empty()); + REQUIRE_THROWS_WITH(print.process(), Catch::Matchers::ContainsSubstring("No sparse layers")); +} + +// Within the toolhead radius of the tower the head body limits an object to nozzle_height, however tall the tower +// grows, so validate() refuses it before slicing. +TEST_CASE("No sparse layers refuses before slicing an object that rises within the toolhead radius of the tower", "[Print][PrimeTower]") +{ + Model model; + // 10 mm from the tower in X and in Y, within the 40 mm toolhead radius, and taller than the 2.5 mm nozzle cone. + add_object(model, make_cube(10., 10., 10.), 140., 140.); + add_object(model, make_cube(20., 20., 10.), 20., 20.)->config.set_key_value("extruder", new ConfigOptionInt(2)); + Print print; + print.apply(model, prime_tower_config({ { "wipe_tower_no_sparse_layers", 1 } })); + + CHECK_THAT(print.validate().string, Catch::Matchers::ContainsSubstring("No sparse layers")); +} + TEST_CASE("An object takes the layer height limits of the extruder of its own filament", "[Print]") { CHECK_THAT(slicing_parameters_on_filament(1).max_layer_height, Catch::Matchers::WithinAbs(0.32, EPSILON));