Prototype for exporting estimated remaining time into gcode for default and silent mode

This commit is contained in:
Enrico Turri 2018-05-30 12:08:03 +02:00
parent e4aff5b08a
commit 5a8d1ffdba
7 changed files with 377 additions and 126 deletions

View file

@ -17,6 +17,12 @@ namespace Slic3r {
class GCodeTimeEstimator
{
public:
enum EMode : unsigned char
{
Default,
Silent
};
enum EUnits : unsigned char
{
Millimeters,
@ -135,6 +141,10 @@ namespace Slic3r {
FeedrateProfile feedrate;
Trapezoid trapezoid;
bool st_synchronized;
Block();
// Returns the length of the move covered by this block, in mm
float move_length() const;
@ -188,18 +198,29 @@ namespace Slic3r {
#endif // ENABLE_MOVE_STATS
private:
EMode _mode;
GCodeReader _parser;
State _state;
Feedrates _curr;
Feedrates _prev;
BlocksList _blocks;
float _time; // s
#if ENABLE_MOVE_STATS
MovesStatsMap _moves_stats;
#endif // ENABLE_MOVE_STATS
public:
GCodeTimeEstimator();
explicit GCodeTimeEstimator(EMode mode);
// Adds the given gcode line
void add_gcode_line(const std::string& gcode_line);
void add_gcode_block(const char *ptr);
void add_gcode_block(const std::string &str) { this->add_gcode_block(str.c_str()); }
// Calculates the time estimate from the gcode lines added using add_gcode_line() or add_gcode_block()
void calculate_time();
// Calculates the time estimate from the given gcode in string format
void calculate_time_from_text(const std::string& gcode);
@ -210,14 +231,12 @@ namespace Slic3r {
// Calculates the time estimate from the gcode contained in given list of gcode lines
void calculate_time_from_lines(const std::vector<std::string>& gcode_lines);
// Adds the given gcode line
void add_gcode_line(const std::string& gcode_line);
// Calculates the time estimate from the gcode lines added using add_gcode_line() or add_gcode_block()
// and returns it in a formatted string
std::string get_elapsed_time_string();
void add_gcode_block(const char *ptr);
void add_gcode_block(const std::string &str) { this->add_gcode_block(str.c_str()); }
// Calculates the time estimate from the gcode lines added using add_gcode_line()
void calculate_time();
// Converts elapsed time lines, contained in the gcode saved with the given filename, into remaining time commands
static bool post_process_elapsed_times(const std::string& filename, float default_time, float silent_time);
// Set current position on the given axis with the given value
void set_axis_position(EAxis axis, float position);
@ -275,13 +294,19 @@ namespace Slic3r {
// Returns the estimated time, in seconds
float get_time() const;
// Returns the estimated time, in format HHh MMm SSs
std::string get_time_hms() const;
// Returns the estimated time, in format DDd HHh MMm SSs
std::string get_time_dhms() const;
private:
void _reset();
void _reset_time();
void _reset_blocks();
void _set_default_as_default();
void _set_default_as_silent();
void _set_blocks_st_synchronize(bool state);
// Calculates the time estimate
void _calculate_time();
@ -353,6 +378,9 @@ namespace Slic3r {
void _recalculate_trapezoids();
// Returns the given time is seconds in format DDd HHh MMm SSs
static std::string _get_time_dhms(float time_in_secs);
#if ENABLE_MOVE_STATS
void _log_moves_stats() const;
#endif // ENABLE_MOVE_STATS