From eeedeeca13dca5b24b401adbd8bdd66d77c89964 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 6 Oct 2023 16:00:36 +0200 Subject: [PATCH 1/4] 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 ba6e71b7ea..256b14695f 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 6bd092204c..0876b645f1 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 3196a7012d..028663660b 100644 --- a/src/libslic3r/GCode/ToolOrdering.hpp +++ b/src/libslic3r/GCode/ToolOrdering.hpp @@ -165,6 +165,7 @@ public: 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 e0bd80bcfe..bf53d8c32c 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"); From 8760748cd25bb0c7dc52947a125ad2b1af542a0e Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 10 Oct 2023 14:17:31 +0200 Subject: [PATCH 2/4] Wipe tower: remove the toolchange index from the final purge, it is not a toolchange and the indexing does not match total number of toolchanges, which is misleading --- src/libslic3r/GCode/WipeTower.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 464d0fe755..a899f2f2be 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -793,12 +793,13 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) .set_initial_tool(m_current_tool) .set_y_shift(m_y_shift + (tool!=(unsigned int)(-1) && (m_current_shape == SHAPE_REVERSED) ? m_layer_info->depth - m_layer_info->toolchanges_depth(): 0.f)) .append(";--------------------\n" - "; CP TOOLCHANGE START\n") - .comment_with_value(" toolchange #", m_num_tool_changes + 1); // the number is zero-based + "; CP TOOLCHANGE START\n"); - if (tool != (unsigned)(-1)) + if (tool != (unsigned)(-1)) { + writer.comment_with_value(" toolchange #", m_num_tool_changes + 1); // the number is zero-based writer.append(std::string("; material : " + (m_current_tool < m_filpar.size() ? m_filpar[m_current_tool].material : "(NONE)") + " -> " + m_filpar[tool].material + "\n").c_str()) .append(";--------------------\n"); + } writer.speed_override_backup(); writer.speed_override(100); From 4b4c208ed2aa82d4ad6346331a72fd14f3da7dae Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 1 Nov 2023 14:59:38 +0100 Subject: [PATCH 3/4] Fix an infinite loop when slicing after wipe tower is disabled --- src/libslic3r/Print.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 7e5e5fecdf..3d555bdbce 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -474,7 +474,9 @@ struct WipeTowerData used_filament.clear(); number_of_toolchanges = -1; depth = 0.f; + z_and_depth_pairs.clear(); brim_width = 0.f; + height = 0.f; width = 0.f; first_layer_height = 0.f; cone_angle = 0.f; From 97714d6f8f0a3bd5e2a5c8f9c941640fc80cfa40 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 2 Nov 2023 09:59:49 +0100 Subject: [PATCH 4/4] Fix part of SPE-1956: Toolchanges count incorrect when wipe tower is disabled --- src/libslic3r/GCode/ToolOrdering.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libslic3r/GCode/ToolOrdering.cpp b/src/libslic3r/GCode/ToolOrdering.cpp index 0876b645f1..2eba21de8c 100644 --- a/src/libslic3r/GCode/ToolOrdering.cpp +++ b/src/libslic3r/GCode/ToolOrdering.cpp @@ -479,6 +479,9 @@ void ToolOrdering::fill_wipe_tower_partitions(const PrintConfig &config, coordf_ bool ToolOrdering::insert_wipe_tower_extruder() { + if (!m_print_config_ptr->wipe_tower) + return false; + // In case that wipe_tower_extruder is set to non-zero, we must make sure that the extruder will be in the list. bool changed = false; if (m_print_config_ptr->wipe_tower_extruder != 0) {