From 5a8d1ffdbaed72a2f4b9ee79316f93be070fc1e0 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 30 May 2018 12:08:03 +0200 Subject: Prototype for exporting estimated remaining time into gcode for default and silent mode --- xs/src/libslic3r/GCode.cpp | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'xs/src/libslic3r/GCode.cpp') diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index b581b3e76..28c15e2fd 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -374,6 +374,9 @@ void GCode::do_export(Print *print, const char *path, GCodePreviewData *preview_ throw std::runtime_error(std::string("G-code export to ") + path + " failed\nIs the disk full?\n"); } fclose(file); + + GCodeTimeEstimator::post_process_elapsed_times(path_tmp, m_default_time_estimator.get_time(), m_silent_time_estimator.get_time()); + if (! this->m_placeholder_parser_failed_templates.empty()) { // G-code export proceeded, but some of the PlaceholderParser substitutions failed. std::string msg = std::string("G-code export to ") + path + " failed due to invalid custom G-code sections:\n\n"; @@ -403,9 +406,11 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) { PROFILE_FUNC(); - // resets time estimator - m_time_estimator.reset(); - m_time_estimator.set_dialect(print.config.gcode_flavor); + // resets time estimators + m_default_time_estimator.reset(); + m_default_time_estimator.set_dialect(print.config.gcode_flavor); + m_silent_time_estimator.reset(); + m_silent_time_estimator.set_dialect(print.config.gcode_flavor); // resets analyzer m_analyzer.reset(); @@ -596,6 +601,10 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) _writeln(file, buf); } + // before start gcode time estimation + _write(file, m_default_time_estimator.get_elapsed_time_string().c_str()); + _write(file, m_silent_time_estimator.get_elapsed_time_string().c_str()); + // Write the custom start G-code _writeln(file, start_gcode); // Process filament-specific gcode in extruder order. @@ -800,13 +809,17 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) for (const std::string &end_gcode : print.config.end_filament_gcode.values) _writeln(file, this->placeholder_parser_process("end_filament_gcode", end_gcode, (unsigned int)(&end_gcode - &print.config.end_filament_gcode.values.front()), &config)); } + // before end gcode time estimation + _write(file, m_default_time_estimator.get_elapsed_time_string().c_str()); + _write(file, m_silent_time_estimator.get_elapsed_time_string().c_str()); _writeln(file, this->placeholder_parser_process("end_gcode", print.config.end_gcode, m_writer.extruder()->id(), &config)); } _write(file, m_writer.update_progress(m_layer_count, m_layer_count, true)); // 100% _write(file, m_writer.postamble()); // calculates estimated printing time - m_time_estimator.calculate_time(); + m_default_time_estimator.calculate_time(); + m_silent_time_estimator.calculate_time(); // Get filament stats. print.filament_stats.clear(); @@ -814,7 +827,8 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) print.total_extruded_volume = 0.; print.total_weight = 0.; print.total_cost = 0.; - print.estimated_print_time = m_time_estimator.get_time_hms(); + print.estimated_default_print_time = m_default_time_estimator.get_time_dhms(); + print.estimated_silent_print_time = m_silent_time_estimator.get_time_dhms(); for (const Extruder &extruder : m_writer.extruders()) { double used_filament = extruder.used_filament(); double extruded_volume = extruder.extruded_volume(); @@ -834,7 +848,8 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) print.total_extruded_volume = print.total_extruded_volume + extruded_volume; } _write_format(file, "; total filament cost = %.1lf\n", print.total_cost); - _write_format(file, "; estimated printing time = %s\n", m_time_estimator.get_time_hms().c_str()); + _write_format(file, "; estimated printing time (default mode) = %s\n", m_default_time_estimator.get_time_dhms().c_str()); + _write_format(file, "; estimated printing time (silent mode) = %s\n", m_silent_time_estimator.get_time_dhms().c_str()); // Append full config. _write(file, "\n"); @@ -1399,8 +1414,12 @@ void GCode::process_layer( if (m_pressure_equalizer) gcode = m_pressure_equalizer->process(gcode.c_str(), false); // printf("G-code after filter:\n%s\n", out.c_str()); - + _write(file, gcode); + + // after layer time estimation + _write(file, m_default_time_estimator.get_elapsed_time_string().c_str()); + _write(file, m_silent_time_estimator.get_elapsed_time_string().c_str()); } void GCode::apply_print_config(const PrintConfig &print_config) @@ -2059,7 +2078,8 @@ void GCode::_write(FILE* file, const char *what) // writes string to file fwrite(gcode, 1, ::strlen(gcode), file); // updates time estimator and gcode lines vector - m_time_estimator.add_gcode_block(gcode); + m_default_time_estimator.add_gcode_block(gcode); + m_silent_time_estimator.add_gcode_block(gcode); } } -- cgit v1.2.3