From f216154cdf930ba21c1e35d34295d252d796a7f4 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Tue, 9 Jul 2024 10:16:13 +0200 Subject: [PATCH] Restore the check to used extruders to create prime tower This check was removed while working on the smaller prime tower, to rely only on the max_print_height_second_to_last_extruder variable. However, this one can be miscalculated in some conditions because it is done very early. We then use storage.getExtrudersUsed() again to check the actual extruders use. This may leave some edge cases where a ghost prime tower could appear, but they should now be very limited. CURA-12026 --- include/PrimeTower/PrimeTowerNormal.h | 5 ++++- src/PrimeTower/PrimeTower.cpp | 22 +++++++++++++++------- src/PrimeTower/PrimeTowerNormal.cpp | 12 ++++-------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/PrimeTower/PrimeTowerNormal.h b/include/PrimeTower/PrimeTowerNormal.h index 5235774252..009ca24599 100644 --- a/include/PrimeTower/PrimeTowerNormal.h +++ b/include/PrimeTower/PrimeTowerNormal.h @@ -18,8 +18,11 @@ namespace cura */ class PrimeTowerNormal : public PrimeTower { +private: + const std::vector used_extruders_; + public: - PrimeTowerNormal(); + PrimeTowerNormal(const std::vector& used_extruders); virtual ExtruderPrime getExtruderPrime( const std::vector& extruder_is_used_on_this_layer, diff --git a/src/PrimeTower/PrimeTower.cpp b/src/PrimeTower/PrimeTower.cpp index 31699c5412..074d1f501a 100644 --- a/src/PrimeTower/PrimeTower.cpp +++ b/src/PrimeTower/PrimeTower.cpp @@ -306,20 +306,28 @@ void PrimeTower::processExtrudersUse(LayerVector>& extr PrimeTower* PrimeTower::createPrimeTower(SliceDataStorage& storage) { PrimeTower* prime_tower = nullptr; - const Scene& scene = Application::getInstance().current_slice_->scene; + const Settings& settings = Application::getInstance().current_slice_->scene.current_mesh_group->settings; const size_t raft_total_extra_layers = Raft::getTotalExtraLayers(); + const std::vector extruders_used = storage.getExtrudersUsed(); + + std::vector used_extruders_nrs; + for (size_t extruder_nr = 0; extruder_nr < extruders_used.size(); extruder_nr++) + { + if (extruders_used[extruder_nr]) + { + used_extruders_nrs.push_back(extruder_nr); + } + } - if (scene.extruders.size() > 1 && scene.current_mesh_group->settings.get("prime_tower_enable") - && scene.current_mesh_group->settings.get("prime_tower_min_volume") > 10 && scene.current_mesh_group->settings.get("prime_tower_size") > 10 - && storage.max_print_height_second_to_last_extruder >= -static_cast(raft_total_extra_layers)) + if (used_extruders_nrs.size() > 1 && settings.get("prime_tower_enable") && settings.get("prime_tower_min_volume") > 10 + && settings.get("prime_tower_size") > 10 && storage.max_print_height_second_to_last_extruder >= -static_cast(raft_total_extra_layers)) { - const Settings& mesh_group_settings = scene.current_mesh_group->settings; - const PrimeTowerMode method = mesh_group_settings.get("prime_tower_mode"); + const PrimeTowerMode method = settings.get("prime_tower_mode"); switch (method) { case PrimeTowerMode::NORMAL: - prime_tower = new PrimeTowerNormal(); + prime_tower = new PrimeTowerNormal(used_extruders_nrs); break; case PrimeTowerMode::INTERLEAVED: prime_tower = new PrimeTowerInterleaved(); diff --git a/src/PrimeTower/PrimeTowerNormal.cpp b/src/PrimeTower/PrimeTowerNormal.cpp index eb99669423..1ce002eaf8 100644 --- a/src/PrimeTower/PrimeTowerNormal.cpp +++ b/src/PrimeTower/PrimeTowerNormal.cpp @@ -12,8 +12,9 @@ namespace cura { -PrimeTowerNormal::PrimeTowerNormal() +PrimeTowerNormal::PrimeTowerNormal(const std::vector& used_extruders) : PrimeTower() + , used_extruders_(used_extruders) { } @@ -45,13 +46,8 @@ std::map> PrimeTowerNorma const coord_t tower_radius = mesh_group_settings.get("prime_tower_size") / 2; std::map> toolpaths; - // First make a basic list of used extruders numbers - std::vector extruder_order; - extruder_order.reserve(scene.extruders.size()); - for (const ExtruderTrain& extruder : scene.extruders) - { - extruder_order.push_back(extruder.extruder_nr_); - } + // First take all the used extruders numbers, unsorted + std::vector extruder_order = used_extruders_; // Then sort from high adhesion to low adhesion. This will give us the outside to inside extruder processing order. std::sort(