From 3682cbe45f583e540b2a57a08715ec6c8b9b4ea9 Mon Sep 17 00:00:00 2001 From: "jiangkai.zhao" Date: Mon, 17 Feb 2025 20:14:00 +0800 Subject: [PATCH] Fix: modify the rules of get_wall_filament_for_all_layer jira: none Change-Id: I6e8655105470dc3eef291d4b6ac1c4447092b21a (cherry picked from commit 81ad7bdde0db5c7bc22951843c2c226496d7b2c0) --- src/libslic3r/GCode/WipeTower.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 7d2e3e709e..520d00dc85 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -3613,15 +3613,30 @@ int WipeTower::get_wall_filament_for_all_layer() { std::map category_counts; std::map filament_counts; + int current_tool = m_current_tool; for (const auto &layer : m_plan) { + if (layer.tool_changes.empty()){ + filament_counts[current_tool]++; + category_counts[get_filament_category(current_tool)]++; + continue; + } + std::unordered_set used_tools; + std::unordered_set used_category; for (size_t i = 0; i < layer.tool_changes.size(); ++i) { if (i == 0) { filament_counts[layer.tool_changes[i].old_tool]++; category_counts[get_filament_category(layer.tool_changes[i].old_tool)]++; + used_tools.insert(layer.tool_changes[i].old_tool); + used_category.insert(get_filament_category(layer.tool_changes[i].old_tool)); } - filament_counts[layer.tool_changes[i].new_tool]++; - category_counts[get_filament_category(layer.tool_changes[i].new_tool)]++; + if (!used_category.count(get_filament_category(layer.tool_changes[i].new_tool))) + category_counts[get_filament_category(layer.tool_changes[i].new_tool)]++; + if (!used_tools.count(layer.tool_changes[i].new_tool)) + filament_counts[layer.tool_changes[i].new_tool]++; + used_tools.insert(layer.tool_changes[i].new_tool); + used_category.insert(get_filament_category(layer.tool_changes[i].new_tool)); } + current_tool = layer.tool_changes.empty()?current_tool:layer.tool_changes.back().new_tool; } // std::vector> category_counts_vec;