time estimation shown in GUI after gcode export

This commit is contained in:
Enrico Turri 2017-12-11 11:11:54 +01:00
parent a0a503e4a8
commit bea9628be0
5 changed files with 23 additions and 55 deletions

View file

@ -441,6 +441,7 @@ sub new {
fil_mm3 => "Used Filament (mm^3)", fil_mm3 => "Used Filament (mm^3)",
fil_g => "Used Filament (g)", fil_g => "Used Filament (g)",
cost => "Cost", cost => "Cost",
time => "Estimated printing time (min)",
); );
while (my $field = shift @info) { while (my $field = shift @info) {
my $label = shift @info; my $label = shift @info;
@ -1540,6 +1541,7 @@ sub on_export_completed {
$self->{"print_info_cost"}->SetLabel(sprintf("%.2f" , $self->{print}->total_cost)); $self->{"print_info_cost"}->SetLabel(sprintf("%.2f" , $self->{print}->total_cost));
$self->{"print_info_fil_g"}->SetLabel(sprintf("%.2f" , $self->{print}->total_weight)); $self->{"print_info_fil_g"}->SetLabel(sprintf("%.2f" , $self->{print}->total_weight));
$self->{"print_info_fil_mm3"}->SetLabel(sprintf("%.2f" , $self->{print}->total_extruded_volume)); $self->{"print_info_fil_mm3"}->SetLabel(sprintf("%.2f" , $self->{print}->total_extruded_volume));
$self->{"print_info_time"}->SetLabel(sprintf("%.2f" , $self->{print}->estimated_print_time));
$self->{"print_info_box_show"}->(1); $self->{"print_info_box_show"}->(1);
# this updates buttons status # this updates buttons status

View file

@ -259,7 +259,6 @@ std::string WipeTowerIntegration::finalize(GCode &gcodegen)
#define EXTRUDER_CONFIG(OPT) m_config.OPT.get_at(m_writer.extruder()->id()) #define EXTRUDER_CONFIG(OPT) m_config.OPT.get_at(m_writer.extruder()->id())
#if ENABLE_TIME_ESTIMATOR
// Helper class for writing to file with/without time estimation // Helper class for writing to file with/without time estimation
class Write class Write
{ {
@ -296,18 +295,12 @@ public:
//std::string Write::s_cache = ""; //std::string Write::s_cache = "";
GCodeTimeEstimator* Write::s_time_estimator = nullptr; GCodeTimeEstimator* Write::s_time_estimator = nullptr;
#endif // ENABLE_TIME_ESTIMATOR
inline void write(FILE *file, const std::string &what) inline void write(FILE *file, const std::string &what)
{ {
#if ENABLE_TIME_ESTIMATOR
Write::write(file, what); Write::write(file, what);
#else
fwrite(what.data(), 1, what.size(), file);
#endif // ENABLE_TIME_ESTIMATOR
} }
#if ENABLE_TIME_ESTIMATOR
inline void write_format(FILE* file, const char* format, ...) inline void write_format(FILE* file, const char* format, ...)
{ {
char buffer[1024]; char buffer[1024];
@ -319,17 +312,11 @@ inline void write_format(FILE* file, const char* format, ...)
if (res >= 0) if (res >= 0)
write(file, buffer); write(file, buffer);
} }
#endif // ENABLE_TIME_ESTIMATOR
inline void writeln(FILE *file, const std::string &what) inline void writeln(FILE *file, const std::string &what)
{ {
if (! what.empty()) { if (! what.empty()) {
#if ENABLE_TIME_ESTIMATOR
write_format(file, "%s\n", what.c_str()); write_format(file, "%s\n", what.c_str());
#else
write(file, what);
fprintf(file, "\n");
#endif // ENABLE_TIME_ESTIMATOR
} }
} }
@ -436,27 +423,14 @@ bool GCode::do_export(Print *print, const char *path)
if (! result) if (! result)
boost::nowide::remove(path_tmp.c_str()); boost::nowide::remove(path_tmp.c_str());
// debug only -> tests time estimator from file
{
GCodeTimeEstimator timeEstimator;
timeEstimator.calculate_time_from_file(path);
float time = timeEstimator.get_time();
std::string timeHMS = timeEstimator.get_time_hms();
std::cout << std::endl << "Time estimated from file:" << std::endl;
std::cout << std::endl << ">>> estimated time: " << timeHMS << " (" << time << " seconds)" << std::endl << std::endl;
}
return result; return result;
} }
bool GCode::_do_export(Print &print, FILE *file) bool GCode::_do_export(Print &print, FILE *file)
{ {
#if ENABLE_TIME_ESTIMATOR
// resets time estimator // resets time estimator
m_time_estimator.reset(); m_time_estimator.reset();
Write::set_time_estimator(&m_time_estimator); Write::set_time_estimator(&m_time_estimator);
#endif // ENABLE_TIME_ESTIMATOR
// How many times will be change_layer() called? // How many times will be change_layer() called?
// change_layer() in turn increments the progress bar status. // change_layer() in turn increments the progress bar status.
@ -780,28 +754,16 @@ bool GCode::_do_export(Print &print, FILE *file)
bbox_prime.offset(0.5f); bbox_prime.offset(0.5f);
// Beep for 500ms, tone 800Hz. Yet better, play some Morse. // Beep for 500ms, tone 800Hz. Yet better, play some Morse.
write(file, this->retract()); write(file, this->retract());
#if ENABLE_TIME_ESTIMATOR write(file, "M300 S800 P500\n");
write_format(file, "M300 S800 P500\n");
#else
fprintf(file, "M300 S800 P500\n");
#endif // ENABLE_TIME_ESTIMATOR
if (bbox_prime.overlap(bbox_print)) { if (bbox_prime.overlap(bbox_print)) {
// Wait for the user to remove the priming extrusions, otherwise they would // Wait for the user to remove the priming extrusions, otherwise they would
// get covered by the print. // get covered by the print.
#if ENABLE_TIME_ESTIMATOR write(file, "M1 Remove priming towers and click button.\n");
write_format(file, "M1 Remove priming towers and click button.\n"); }
#else
fprintf(file, "M1 Remove priming towers and click button.\n");
#endif // ENABLE_TIME_ESTIMATOR
}
else { else {
// Just wait for a bit to let the user check, that the priming succeeded. // Just wait for a bit to let the user check, that the priming succeeded.
//TODO Add a message explaining what the printer is waiting for. This needs a firmware fix. //TODO Add a message explaining what the printer is waiting for. This needs a firmware fix.
#if ENABLE_TIME_ESTIMATOR write(file, "M1 S10\n");
write_format(file, "M1 S10\n");
#else
fprintf(file, "M1 S10\n");
#endif // ENABLE_TIME_ESTIMATOR
} }
} else } else
write(file, WipeTowerIntegration::prime_single_color_print(print, initial_extruder_id, *this)); write(file, WipeTowerIntegration::prime_single_color_print(print, initial_extruder_id, *this));
@ -830,12 +792,16 @@ bool GCode::_do_export(Print &print, FILE *file)
write(file, m_writer.update_progress(m_layer_count, m_layer_count, true)); // 100% write(file, m_writer.update_progress(m_layer_count, m_layer_count, true)); // 100%
write(file, m_writer.postamble()); write(file, m_writer.postamble());
// calculates estimated printing time
m_time_estimator.calculate_time();
// Get filament stats. // Get filament stats.
print.filament_stats.clear(); print.filament_stats.clear();
print.total_used_filament = 0.; print.total_used_filament = 0.;
print.total_extruded_volume = 0.; print.total_extruded_volume = 0.;
print.total_weight = 0.; print.total_weight = 0.;
print.total_cost = 0.; print.total_cost = 0.;
print.estimated_print_time = (double)m_time_estimator.get_time() / 60.0;
for (const Extruder &extruder : m_writer.extruders()) { for (const Extruder &extruder : m_writer.extruders()) {
double used_filament = extruder.used_filament(); double used_filament = extruder.used_filament();
double extruded_volume = extruder.extruded_volume(); double extruded_volume = extruder.extruded_volume();
@ -855,11 +821,7 @@ bool GCode::_do_export(Print &print, FILE *file)
print.total_extruded_volume = print.total_extruded_volume + extruded_volume; print.total_extruded_volume = print.total_extruded_volume + extruded_volume;
} }
fprintf(file, "; total filament cost = %.1lf\n", print.total_cost); fprintf(file, "; total filament cost = %.1lf\n", print.total_cost);
#if ENABLE_TIME_ESTIMATOR
m_time_estimator.calculate_time();
fprintf(file, "; estimated printing time = %s\n", m_time_estimator.get_time_hms()); fprintf(file, "; estimated printing time = %s\n", m_time_estimator.get_time_hms());
#endif // ENABLE_TIME_ESTIMATOR
// Append full config. // Append full config.
fprintf(file, "\n"); fprintf(file, "\n");

View file

@ -1,8 +1,6 @@
#ifndef slic3r_GCode_hpp_ #ifndef slic3r_GCode_hpp_
#define slic3r_GCode_hpp_ #define slic3r_GCode_hpp_
#define ENABLE_TIME_ESTIMATOR 1
#include "libslic3r.h" #include "libslic3r.h"
#include "ExPolygon.hpp" #include "ExPolygon.hpp"
#include "GCodeWriter.hpp" #include "GCodeWriter.hpp"
@ -17,9 +15,7 @@
#include "GCode/SpiralVase.hpp" #include "GCode/SpiralVase.hpp"
#include "GCode/ToolOrdering.hpp" #include "GCode/ToolOrdering.hpp"
#include "GCode/WipeTower.hpp" #include "GCode/WipeTower.hpp"
#if ENABLE_TIME_ESTIMATOR
#include "GCodeTimeEstimator.hpp" #include "GCodeTimeEstimator.hpp"
#endif // ENABLE_TIME_ESTIMATOR
#include "EdgeGrid.hpp" #include "EdgeGrid.hpp"
#include <memory> #include <memory>
@ -272,10 +268,8 @@ protected:
// Index of a last object copy extruded. // Index of a last object copy extruded.
std::pair<const PrintObject*, Point> m_last_obj_copy; std::pair<const PrintObject*, Point> m_last_obj_copy;
#if ENABLE_TIME_ESTIMATOR
// Time estimator // Time estimator
GCodeTimeEstimator m_time_estimator; GCodeTimeEstimator m_time_estimator;
#endif // ENABLE_TIME_ESTIMATOR
std::string _extrude(const ExtrusionPath &path, std::string description = "", double speed = -1); std::string _extrude(const ExtrusionPath &path, std::string description = "", double speed = -1);
void _print_first_layer_extruder_temperatures(FILE *file, Print &print, unsigned int first_printing_extruder_id, bool wait); void _print_first_layer_extruder_temperatures(FILE *file, Print &print, unsigned int first_printing_extruder_id, bool wait);

View file

@ -233,14 +233,14 @@ public:
PrintRegionPtrs regions; PrintRegionPtrs regions;
PlaceholderParser placeholder_parser; PlaceholderParser placeholder_parser;
// TODO: status_cb // TODO: status_cb
double total_used_filament, total_extruded_volume, total_cost, total_weight; double total_used_filament, total_extruded_volume, total_cost, total_weight, estimated_print_time;
std::map<size_t,float> filament_stats; std::map<size_t, float> filament_stats;
PrintState<PrintStep, psCount> state; PrintState<PrintStep, psCount> state;
// ordered collections of extrusion paths to build skirt loops and brim // ordered collections of extrusion paths to build skirt loops and brim
ExtrusionEntityCollection skirt, brim; ExtrusionEntityCollection skirt, brim;
Print() : total_used_filament(0), total_extruded_volume(0) { restart(); } Print() : total_used_filament(0), total_extruded_volume(0), estimated_print_time(0) { restart(); }
~Print() { clear_objects(); } ~Print() { clear_objects(); }
// methods for handling objects // methods for handling objects

View file

@ -273,5 +273,15 @@ Print::total_cost(...)
OUTPUT: OUTPUT:
RETVAL RETVAL
double
Print::estimated_print_time(...)
CODE:
if (items > 1) {
THIS->estimated_print_time = (double)SvNV(ST(1));
}
RETVAL = THIS->estimated_print_time;
OUTPUT:
RETVAL
%} %}
}; };