From eeedeeca13dca5b24b401adbd8bdd66d77c89964 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 6 Oct 2023 16:00:36 +0200 Subject: [PATCH] Fix of #6832, SPE-1956: total toolchanges not counted correctly when wipe tower is disabled --- src/libslic3r/GCode.cpp | 6 ++++-- src/libslic3r/GCode/ToolOrdering.cpp | 16 ++++++++++++++++ src/libslic3r/GCode/ToolOrdering.hpp | 1 + src/slic3r/GUI/Plater.cpp | 3 +-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index ba6e71b7ea8..256b14695f1 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -720,6 +720,7 @@ namespace DoExport { const FullPrintConfig &config, const std::vector &extruders, unsigned int initial_extruder_id, + int total_toolchanges, PrintStatistics &print_statistics, bool export_binary_data, bgcode::binarize::BinaryData &binary_data) @@ -727,7 +728,7 @@ namespace DoExport { std::string filament_stats_string_out; print_statistics.clear(); - print_statistics.total_toolchanges = std::max(0, wipe_tower_data.number_of_toolchanges); + print_statistics.total_toolchanges = total_toolchanges; print_statistics.initial_extruder_id = initial_extruder_id; std::vector filament_types; if (! extruders.empty()) { @@ -1161,7 +1162,7 @@ void GCodeGenerator::_do_export(Print& print, GCodeOutputStream &file, Thumbnail // For the start / end G-code to do the priming and final filament pull in case there is no wipe tower provided. this->placeholder_parser().set("has_wipe_tower", has_wipe_tower); this->placeholder_parser().set("has_single_extruder_multi_material_priming", has_wipe_tower && print.config().single_extruder_multi_material_priming); - this->placeholder_parser().set("total_toolchanges", std::max(0, print.wipe_tower_data().number_of_toolchanges)); // Check for negative toolchanges (single extruder mode) and set to 0 (no tool change). + this->placeholder_parser().set("total_toolchanges", tool_ordering.toolchanges_count()); { BoundingBoxf bbox(print.config().bed_shape.values); assert(bbox.defined); @@ -1389,6 +1390,7 @@ void GCodeGenerator::_do_export(Print& print, GCodeOutputStream &file, Thumbnail this->config(), m_writer.extruders(), initial_extruder_id, + tool_ordering.toolchanges_count(), // Modifies print.m_print_statistics, export_to_binary_gcode, diff --git a/src/libslic3r/GCode/ToolOrdering.cpp b/src/libslic3r/GCode/ToolOrdering.cpp index 6bd092204c5..0876b645f1e 100644 --- a/src/libslic3r/GCode/ToolOrdering.cpp +++ b/src/libslic3r/GCode/ToolOrdering.cpp @@ -836,4 +836,20 @@ void WipingExtrusions::ensure_perimeters_infills_order(const Print& print, const } } + +int ToolOrdering::toolchanges_count() const +{ + std::vector tools_in_order; + for (const LayerTools& lt : m_layer_tools) + tools_in_order.insert(tools_in_order.end(), lt.extruders.begin(), lt.extruders.end()); + assert(std::find(tools_in_order.begin(), tools_in_order.end(), (unsigned int)(-1)) == tools_in_order.end()); + for (size_t i=1; i 1 && tools_in_order.back() == tools_in_order[tools_in_order.size()-2]) + tools_in_order.pop_back(); + return std::max(0, int(tools_in_order.size())-1); // 5 tools = 4 toolchanges +} + } // namespace Slic3r diff --git a/src/libslic3r/GCode/ToolOrdering.hpp b/src/libslic3r/GCode/ToolOrdering.hpp index 3196a7012de..028663660b9 100644 --- a/src/libslic3r/GCode/ToolOrdering.hpp +++ b/src/libslic3r/GCode/ToolOrdering.hpp @@ -165,6 +165,7 @@ class ToolOrdering bool empty() const { return m_layer_tools.empty(); } std::vector& layer_tools() { return m_layer_tools; } bool has_wipe_tower() const { return ! m_layer_tools.empty() && m_first_printing_extruder != (unsigned int)-1 && m_layer_tools.front().wipe_tower_partitions > 0; } + int toolchanges_count() const; private: void initialize_layers(std::vector &zs); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index e0bd80bcfeb..bf53d8c32c2 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1502,8 +1502,7 @@ void Sidebar::update_sliced_info_sizer() p->sliced_info->SetTextAndShow(siEstimatedTime, info_text, new_label); } - // if there is a wipe tower, insert number of toolchanges info into the array: - p->sliced_info->SetTextAndShow(siWTNumbetOfToolchanges, is_wipe_tower ? wxString::Format("%.d", ps.total_toolchanges) : "N/A"); + p->sliced_info->SetTextAndShow(siWTNumbetOfToolchanges, ps.total_toolchanges > 0 ? wxString::Format("%.d", ps.total_toolchanges) : "N/A"); // Hide non-FFF sliced info parameters p->sliced_info->SetTextAndShow(siMateril_unit, "N/A");