Skip to content

Commit

Permalink
Fix of #6832, SPE-1956: total toolchanges not counted correctly when …
Browse files Browse the repository at this point in the history
…wipe tower is disabled
  • Loading branch information
lukasmatena committed Nov 2, 2023
1 parent aa0bc74 commit eeedeec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,14 +720,15 @@ namespace DoExport {
const FullPrintConfig &config,
const std::vector<Extruder> &extruders,
unsigned int initial_extruder_id,
int total_toolchanges,
PrintStatistics &print_statistics,
bool export_binary_data,
bgcode::binarize::BinaryData &binary_data)
{
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<std::string> filament_types;
if (! extruders.empty()) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions src/libslic3r/GCode/ToolOrdering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,4 +836,20 @@ void WipingExtrusions::ensure_perimeters_infills_order(const Print& print, const
}
}


int ToolOrdering::toolchanges_count() const
{
std::vector<unsigned int> 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<tools_in_order.size(); ++i)
if (tools_in_order[i] == tools_in_order[i-1])
tools_in_order[i-1] = (unsigned int)(-1);
tools_in_order.erase(std::remove(tools_in_order.begin(), tools_in_order.end(), (unsigned int)(-1)), tools_in_order.end());
if (tools_in_order.size() > 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
1 change: 1 addition & 0 deletions src/libslic3r/GCode/ToolOrdering.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class ToolOrdering
bool empty() const { return m_layer_tools.empty(); }
std::vector<LayerTools>& 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<coordf_t> &zs);
Expand Down
3 changes: 1 addition & 2 deletions src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit eeedeec

Please sign in to comment.