From f364b956fcfacfb23badd77f5899ff9c42e1d2d2 Mon Sep 17 00:00:00 2001 From: Bryan Smith Date: Mon, 4 Feb 2019 18:55:06 -0500 Subject: [PATCH 1/2] Add [total_toolchanges] placeholder for filename and custom gcode sections. --- src/libslic3r/GCode.cpp | 8 ++++++++ src/libslic3r/Print.cpp | 3 ++- src/libslic3r/Print.hpp | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index c42669de0..6dc63c249 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -726,6 +726,12 @@ void GCode::_do_export(Print &print, FILE *file) _writeln(file, GCodeTimeEstimator::Silent_First_M73_Output_Placeholder_Tag); } + //Hold total number of print toolchanges + int m_total_toolchanges = 1; + m_total_toolchanges = print.wipe_tower_data().number_of_toolchanges; + //Check for negative toolchanges (probably single extruder mode) and set to 1. + m_total_toolchanges = (print.wipe_tower_data().number_of_toolchanges < 0) ? 1 : print.wipe_tower_data().number_of_toolchanges; + // Prepare the helper object for replacing placeholders in custom G-code and output filename. m_placeholder_parser = print.placeholder_parser(); m_placeholder_parser.update_timestamp(); @@ -788,6 +794,7 @@ void GCode::_do_export(Print &print, FILE *file) // For the start / end G-code to do the priming and final filament pull in case there is no wipe tower provided. m_placeholder_parser.set("has_wipe_tower", has_wipe_tower); m_placeholder_parser.set("has_single_extruder_multi_material_priming", has_wipe_tower && print.config().single_extruder_multi_material_priming); + m_placeholder_parser.set("total_toolchanges", m_total_toolchanges); std::string start_gcode = this->placeholder_parser_process("start_gcode", print.config().start_gcode.value, initial_extruder_id); // Set bed temperature if the start G-code does not contain any bed temp control G-codes. this->_print_first_layer_bed_temperature(file, print, start_gcode, initial_extruder_id, true); @@ -1057,6 +1064,7 @@ void GCode::_do_export(Print &print, FILE *file) print.m_print_statistics.clear(); print.m_print_statistics.estimated_normal_print_time = m_normal_time_estimator.get_time_dhms(); print.m_print_statistics.estimated_silent_print_time = m_silent_time_estimator_enabled ? m_silent_time_estimator.get_time_dhms() : "N/A"; + print.m_print_statistics.total_toolchanges = m_total_toolchanges; std::vector extruders = m_writer.extruders(); if (! extruders.empty()) { std::pair out_filament_used_mm ("; filament used [mm] = ", 0); diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index f9129f15a..69b4d8129 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1956,6 +1956,7 @@ DynamicConfig PrintStatistics::config() const config.set_key_value("used_filament", new ConfigOptionFloat (this->total_used_filament / 1000.)); config.set_key_value("extruded_volume", new ConfigOptionFloat (this->total_extruded_volume)); config.set_key_value("total_cost", new ConfigOptionFloat (this->total_cost)); + config.set_key_value("total_toolchanges", new ConfigOptionInt(this->total_toolchanges)); config.set_key_value("total_weight", new ConfigOptionFloat (this->total_weight)); config.set_key_value("total_wipe_tower_cost", new ConfigOptionFloat (this->total_wipe_tower_cost)); config.set_key_value("total_wipe_tower_filament", new ConfigOptionFloat (this->total_wipe_tower_filament)); @@ -1968,7 +1969,7 @@ DynamicConfig PrintStatistics::placeholders() for (const std::string &key : { "print_time", "normal_print_time", "silent_print_time", "used_filament", "extruded_volume", "total_cost", "total_weight", - "total_wipe_tower_cost", "total_wipe_tower_filament"}) + "total_toolchanges", "total_wipe_tower_cost", "total_wipe_tower_filament"}) config.set_key_value(key, new ConfigOptionString(std::string("{") + key + "}")); return config; } diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 53d6d692d..2326366a0 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -241,6 +241,7 @@ struct PrintStatistics double total_used_filament; double total_extruded_volume; double total_cost; + int total_toolchanges; double total_weight; double total_wipe_tower_cost; double total_wipe_tower_filament; @@ -259,6 +260,7 @@ struct PrintStatistics total_used_filament = 0.; total_extruded_volume = 0.; total_cost = 0.; + total_toolchanges = 0; total_weight = 0.; total_wipe_tower_cost = 0.; total_wipe_tower_filament = 0.; From 0ea6f895c5edcd1da1e7a5c6baaecf74f9b9890c Mon Sep 17 00:00:00 2001 From: Bryan Smith Date: Mon, 4 Feb 2019 20:52:38 -0500 Subject: [PATCH 2/2] Write the total toolchanges statistic to the end of the GCODE file like the other statistics. --- src/libslic3r/GCode.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 6dc63c249..00a4e801a 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1114,6 +1114,7 @@ void GCode::_do_export(Print &print, FILE *file) } _write_format(file, "; total filament used [g] = %.1lf\n", print.m_print_statistics.total_weight); _write_format(file, "; total filament cost = %.1lf\n", print.m_print_statistics.total_cost); + _write_format(file, "; total toolchanges = %i\n", print.m_print_statistics.total_toolchanges); _write_format(file, "; estimated printing time (normal mode) = %s\n", m_normal_time_estimator.get_time_dhms().c_str()); if (m_silent_time_estimator_enabled) _write_format(file, "; estimated printing time (silent mode) = %s\n", m_silent_time_estimator.get_time_dhms().c_str());