mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-25 23:54:00 -06:00
GCodeViewer -> Added estimated printing times for move types
This commit is contained in:
parent
602a9bc75f
commit
f7164db68e
5 changed files with 195 additions and 87 deletions
|
@ -705,27 +705,6 @@ namespace Slic3r {
|
|||
}
|
||||
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
// free functions called by GCode::do_export()
|
||||
namespace DoExport {
|
||||
static void update_print_stats_estimated_times(
|
||||
const GCodeProcessor& processor,
|
||||
const bool silent_time_estimator_enabled,
|
||||
PrintStatistics& print_statistics)
|
||||
{
|
||||
print_statistics.estimated_normal_print_time = processor.get_time_dhm(GCodeProcessor::ETimeMode::Normal);
|
||||
print_statistics.estimated_normal_custom_gcode_print_times = processor.get_custom_gcode_times(GCodeProcessor::ETimeMode::Normal, true);
|
||||
if (silent_time_estimator_enabled) {
|
||||
print_statistics.estimated_silent_print_time = processor.get_time_dhm(GCodeProcessor::ETimeMode::Stealth);
|
||||
print_statistics.estimated_silent_custom_gcode_print_times = processor.get_custom_gcode_times(GCodeProcessor::ETimeMode::Stealth, true);
|
||||
}
|
||||
else {
|
||||
print_statistics.estimated_silent_print_time = "N/A";
|
||||
print_statistics.estimated_silent_custom_gcode_print_times.clear();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace DoExport
|
||||
|
||||
void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* result, ThumbnailsGeneratorCallback thumbnail_cb)
|
||||
#else
|
||||
void GCode::do_export(Print* print, const char* path, GCodePreviewData* preview_data, ThumbnailsGeneratorCallback thumbnail_cb)
|
||||
|
@ -787,11 +766,12 @@ void GCode::do_export(Print* print, const char* path, GCodePreviewData* preview_
|
|||
}
|
||||
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
print->m_print_statistics.clear_time_estimates();
|
||||
m_processor.process_file(path_tmp);
|
||||
if (result != nullptr)
|
||||
if (result != nullptr) {
|
||||
*result = std::move(m_processor.extract_result());
|
||||
|
||||
DoExport::update_print_stats_estimated_times(m_processor, m_silent_time_estimator_enabled, print->m_print_statistics);
|
||||
m_processor.update_print_stats_estimated_times(print->m_print_statistics);
|
||||
}
|
||||
#endif // ENABLE_GCODE_VIEWER
|
||||
|
||||
GCodeTimeEstimator::PostProcessData normal_data = m_normal_time_estimator.get_post_process_data();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "libslic3r/libslic3r.h"
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "libslic3r/Print.hpp"
|
||||
#include "GCodeProcessor.hpp"
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
@ -161,6 +162,7 @@ void GCodeProcessor::TimeMachine::reset()
|
|||
prev.reset();
|
||||
gcode_time.reset();
|
||||
blocks = std::vector<TimeBlock>();
|
||||
std::fill(moves_time.begin(), moves_time.end(), 0.0f);
|
||||
}
|
||||
|
||||
void GCodeProcessor::TimeMachine::simulate_st_synchronize(float additional_time)
|
||||
|
@ -264,9 +266,11 @@ void GCodeProcessor::TimeMachine::calculate_time(size_t keep_last_n_blocks)
|
|||
size_t n_blocks_process = blocks.size() - keep_last_n_blocks;
|
||||
// m_g1_times.reserve(m_g1_times.size() + n_blocks_process);
|
||||
for (size_t i = 0; i < n_blocks_process; ++i) {
|
||||
float block_time = blocks[i].time();
|
||||
const TimeBlock& block = blocks[i];
|
||||
float block_time = block.time();
|
||||
time += block_time;
|
||||
gcode_time.cache += block_time;
|
||||
moves_time[static_cast<size_t>(block.move_type)] += block_time;
|
||||
|
||||
// if (block.g1_line_id >= 0)
|
||||
// m_g1_times.emplace_back(block.g1_line_id, time);
|
||||
|
@ -388,12 +392,31 @@ void GCodeProcessor::process_file(const std::string& filename)
|
|||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
}
|
||||
|
||||
void GCodeProcessor::update_print_stats_estimated_times(PrintStatistics& print_statistics)
|
||||
{
|
||||
print_statistics.estimated_normal_print_time = get_time(GCodeProcessor::ETimeMode::Normal);
|
||||
print_statistics.estimated_normal_custom_gcode_print_times = get_custom_gcode_times(GCodeProcessor::ETimeMode::Normal, true);
|
||||
print_statistics.estimated_normal_moves_times = get_moves_time(GCodeProcessor::ETimeMode::Normal);
|
||||
if (m_time_processor.machines[static_cast<size_t>(GCodeProcessor::ETimeMode::Stealth)].enabled) {
|
||||
print_statistics.estimated_silent_print_time = get_time(GCodeProcessor::ETimeMode::Stealth);
|
||||
print_statistics.estimated_silent_custom_gcode_print_times = get_custom_gcode_times(GCodeProcessor::ETimeMode::Stealth, true);
|
||||
print_statistics.estimated_silent_moves_times = get_moves_time(GCodeProcessor::ETimeMode::Stealth);
|
||||
}
|
||||
else {
|
||||
print_statistics.estimated_silent_print_time = 0.0f;
|
||||
print_statistics.estimated_silent_custom_gcode_print_times.clear();
|
||||
print_statistics.estimated_silent_moves_times.clear();
|
||||
}
|
||||
}
|
||||
|
||||
float GCodeProcessor::get_time(ETimeMode mode) const
|
||||
{
|
||||
return (mode < ETimeMode::Count) ? m_time_processor.machines[static_cast<size_t>(mode)].time : 0.0f;
|
||||
}
|
||||
|
||||
std::string GCodeProcessor::get_time_dhm(ETimeMode mode) const
|
||||
{
|
||||
std::string ret = "N/A";
|
||||
if (mode < ETimeMode::Count)
|
||||
ret = short_time(get_time_dhms(m_time_processor.machines[static_cast<size_t>(mode)].time));
|
||||
return ret;
|
||||
return (mode < ETimeMode::Count) ? short_time(get_time_dhms(m_time_processor.machines[static_cast<size_t>(mode)].time)) : std::string("N/A");
|
||||
}
|
||||
|
||||
std::vector<std::pair<CustomGCode::Type, std::pair<float, float>>> GCodeProcessor::get_custom_gcode_times(ETimeMode mode, bool include_remaining) const
|
||||
|
@ -411,6 +434,19 @@ std::vector<std::pair<CustomGCode::Type, std::pair<float, float>>> GCodeProcesso
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::vector<std::pair<GCodeProcessor::EMoveType, float>> GCodeProcessor::get_moves_time(ETimeMode mode) const
|
||||
{
|
||||
std::vector<std::pair<EMoveType, float>> ret;
|
||||
if (mode < ETimeMode::Count) {
|
||||
for (size_t i = 0; i < m_time_processor.machines[static_cast<size_t>(mode)].moves_time.size(); ++i) {
|
||||
float time = m_time_processor.machines[static_cast<size_t>(mode)].moves_time[i];
|
||||
if (time > 0.0f)
|
||||
ret.push_back({ static_cast<EMoveType>(i), time });
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void GCodeProcessor::process_gcode_line(const GCodeReader::GCodeLine& line)
|
||||
{
|
||||
/* std::cout << line.raw() << std::endl; */
|
||||
|
@ -668,6 +704,8 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
|
|||
if (max_abs_delta == 0.0f)
|
||||
return;
|
||||
|
||||
EMoveType type = move_type(delta_pos);
|
||||
|
||||
// time estimate section
|
||||
auto move_length = [](const AxisCoords& delta_pos) {
|
||||
float sq_xyz_length = sqr(delta_pos[X]) + sqr(delta_pos[Y]) + sqr(delta_pos[Z]);
|
||||
|
@ -696,6 +734,7 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
|
|||
minimum_feedrate(static_cast<ETimeMode>(i), m_feedrate);
|
||||
|
||||
TimeBlock block;
|
||||
block.move_type = type;
|
||||
block.distance = distance;
|
||||
|
||||
// calculates block cruise feedrate
|
||||
|
@ -827,7 +866,7 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
|
|||
}
|
||||
|
||||
// store move
|
||||
store_move_vertex(move_type(delta_pos));
|
||||
store_move_vertex(type);
|
||||
}
|
||||
|
||||
void GCodeProcessor::process_G10(const GCodeReader::GCodeLine& line)
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
struct PrintStatistics;
|
||||
|
||||
class GCodeProcessor
|
||||
{
|
||||
public:
|
||||
|
@ -57,6 +59,20 @@ namespace Slic3r {
|
|||
};
|
||||
|
||||
public:
|
||||
enum class EMoveType : unsigned char
|
||||
{
|
||||
Noop,
|
||||
Retract,
|
||||
Unretract,
|
||||
Tool_change,
|
||||
Color_change,
|
||||
Pause_Print,
|
||||
Custom_GCode,
|
||||
Travel,
|
||||
Extrude,
|
||||
Count
|
||||
};
|
||||
|
||||
struct FeedrateProfile
|
||||
{
|
||||
float entry{ 0.0f }; // mm/s
|
||||
|
@ -84,6 +100,7 @@ namespace Slic3r {
|
|||
bool nominal_length{ false };
|
||||
};
|
||||
|
||||
EMoveType move_type{ EMoveType::Noop };
|
||||
float distance{ 0.0f }; // mm
|
||||
float acceleration{ 0.0f }; // mm/s^2
|
||||
float max_entry_speed{ 0.0f }; // mm/s
|
||||
|
@ -135,6 +152,7 @@ namespace Slic3r {
|
|||
State prev;
|
||||
CustomGCodeTime gcode_time;
|
||||
std::vector<TimeBlock> blocks;
|
||||
std::array<float, static_cast<size_t>(EMoveType::Count)> moves_time;
|
||||
|
||||
void reset();
|
||||
|
||||
|
@ -169,20 +187,6 @@ namespace Slic3r {
|
|||
};
|
||||
|
||||
public:
|
||||
enum class EMoveType : unsigned char
|
||||
{
|
||||
Noop,
|
||||
Retract,
|
||||
Unretract,
|
||||
Tool_change,
|
||||
Color_change,
|
||||
Pause_Print,
|
||||
Custom_GCode,
|
||||
Travel,
|
||||
Extrude,
|
||||
Count
|
||||
};
|
||||
|
||||
struct MoveVertex
|
||||
{
|
||||
EMoveType type{ EMoveType::Noop };
|
||||
|
@ -255,9 +259,13 @@ namespace Slic3r {
|
|||
// Process the gcode contained in the file with the given filename
|
||||
void process_file(const std::string& filename);
|
||||
|
||||
void update_print_stats_estimated_times(PrintStatistics& print_statistics);
|
||||
float get_time(ETimeMode mode) const;
|
||||
std::string get_time_dhm(ETimeMode mode) const;
|
||||
std::vector<std::pair<CustomGCode::Type, std::pair<float, float>>> get_custom_gcode_times(ETimeMode mode, bool include_remaining) const;
|
||||
|
||||
std::vector<std::pair<EMoveType, float>> get_moves_time(ETimeMode mode) const;
|
||||
|
||||
private:
|
||||
void process_gcode_line(const GCodeReader::GCodeLine& line);
|
||||
|
||||
|
|
|
@ -304,14 +304,16 @@ struct PrintStatistics
|
|||
{
|
||||
PrintStatistics() { clear(); }
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
std::string estimated_normal_print_time;
|
||||
std::string estimated_silent_print_time;
|
||||
float estimated_normal_print_time;
|
||||
float estimated_silent_print_time;
|
||||
std::string estimated_normal_print_time_str;
|
||||
std::string estimated_silent_print_time_str;
|
||||
std::vector<std::pair<CustomGCode::Type, std::pair<float, float>>> estimated_normal_custom_gcode_print_times;
|
||||
std::vector<std::pair<CustomGCode::Type, std::pair<float, float>>> estimated_silent_custom_gcode_print_times;
|
||||
std::vector<std::pair<CustomGCode::Type, std::pair<std::string, std::string>>> estimated_normal_custom_gcode_print_times_str;
|
||||
std::vector<std::pair<CustomGCode::Type, std::pair<std::string, std::string>>> estimated_silent_custom_gcode_print_times_str;
|
||||
std::vector<std::pair<GCodeProcessor::EMoveType, float>> estimated_normal_moves_times;
|
||||
std::vector<std::pair<GCodeProcessor::EMoveType, float>> estimated_silent_moves_times;
|
||||
#else
|
||||
std::string estimated_normal_print_time;
|
||||
std::string estimated_silent_print_time;
|
||||
|
@ -336,6 +338,8 @@ struct PrintStatistics
|
|||
|
||||
void clear() {
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
estimated_normal_print_time_str.clear();
|
||||
estimated_silent_print_time_str.clear();
|
||||
estimated_normal_custom_gcode_print_times_str.clear();
|
||||
estimated_silent_custom_gcode_print_times_str.clear();
|
||||
#else
|
||||
|
@ -353,6 +357,17 @@ struct PrintStatistics
|
|||
total_wipe_tower_filament = 0.;
|
||||
filament_stats.clear();
|
||||
}
|
||||
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
void clear_time_estimates() {
|
||||
estimated_normal_print_time = 0.0f;
|
||||
estimated_silent_print_time = 0.0f;
|
||||
estimated_normal_custom_gcode_print_times.clear();
|
||||
estimated_silent_custom_gcode_print_times.clear();
|
||||
estimated_normal_moves_times.clear();
|
||||
estimated_silent_moves_times.clear();
|
||||
}
|
||||
#endif //ENABLE_GCODE_VIEWER
|
||||
};
|
||||
|
||||
typedef std::vector<PrintObject*> PrintObjectPtrs;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue