SPE-1739: Fixed calculation of gcode preview sequential slider endpoints

This commit is contained in:
enricoturri1966 2023-05-30 08:51:01 +02:00
parent cc71436aef
commit 578921257d
4 changed files with 18 additions and 9 deletions

View File

@ -901,6 +901,7 @@ namespace DoExport {
silent_time_estimator_enabled = (config.gcode_flavor == gcfMarlinLegacy || config.gcode_flavor == gcfMarlinFirmware) silent_time_estimator_enabled = (config.gcode_flavor == gcfMarlinLegacy || config.gcode_flavor == gcfMarlinFirmware)
&& config.silent_mode; && config.silent_mode;
processor.reset(); processor.reset();
processor.initialize_result_moves();
processor.apply_config(config); processor.apply_config(config);
processor.enable_stealth_time_estimator(silent_time_estimator_enabled); processor.enable_stealth_time_estimator(silent_time_estimator_enabled);
} }

View File

@ -1071,8 +1071,7 @@ void GCodeProcessor::process_file(const std::string& filename, std::function<voi
// process gcode // process gcode
m_result.filename = filename; m_result.filename = filename;
m_result.id = ++s_result_id; m_result.id = ++s_result_id;
// 1st move must be a dummy move initialize_result_moves();
m_result.moves.emplace_back(GCodeProcessorResult::MoveVertex());
size_t parse_line_callback_cntr = 10000; size_t parse_line_callback_cntr = 10000;
m_parser.parse_file(filename, [this, cancel_callback, &parse_line_callback_cntr](GCodeReader& reader, const GCodeReader::GCodeLine& line) { m_parser.parse_file(filename, [this, cancel_callback, &parse_line_callback_cntr](GCodeReader& reader, const GCodeReader::GCodeLine& line) {
if (-- parse_line_callback_cntr == 0) { if (-- parse_line_callback_cntr == 0) {
@ -1099,8 +1098,6 @@ void GCodeProcessor::initialize(const std::string& filename)
// process gcode // process gcode
m_result.filename = filename; m_result.filename = filename;
m_result.id = ++s_result_id; m_result.id = ++s_result_id;
// 1st move must be a dummy move
m_result.moves.emplace_back(GCodeProcessorResult::MoveVertex());
} }
void GCodeProcessor::process_buffer(const std::string &buffer) void GCodeProcessor::process_buffer(const std::string &buffer)

View File

@ -639,6 +639,11 @@ namespace Slic3r {
// Streaming interface, for processing G-codes just generated by PrusaSlicer in a pipelined fashion. // Streaming interface, for processing G-codes just generated by PrusaSlicer in a pipelined fashion.
void initialize(const std::string& filename); void initialize(const std::string& filename);
void initialize_result_moves() {
// 1st move must be a dummy move
assert(m_result.moves.empty());
m_result.moves.emplace_back(GCodeProcessorResult::MoveVertex());
}
void process_buffer(const std::string& buffer); void process_buffer(const std::string& buffer);
void finalize(bool post_process); void finalize(bool post_process);

View File

@ -2150,6 +2150,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
// layers zs / roles / extruder ids -> extract from result // layers zs / roles / extruder ids -> extract from result
size_t last_travel_s_id = 0; size_t last_travel_s_id = 0;
size_t first_travel_s_id = 0;
seams_count = 0; seams_count = 0;
for (size_t i = 0; i < m_moves_count; ++i) { for (size_t i = 0; i < m_moves_count; ++i) {
const GCodeProcessorResult::MoveVertex& move = gcode_result.moves[i]; const GCodeProcessorResult::MoveVertex& move = gcode_result.moves[i];
@ -2163,8 +2164,10 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
// layers zs // layers zs
const double* const last_z = m_layers.empty() ? nullptr : &m_layers.get_zs().back(); const double* const last_z = m_layers.empty() ? nullptr : &m_layers.get_zs().back();
const double z = static_cast<double>(move.position.z()); const double z = static_cast<double>(move.position.z());
if (last_z == nullptr || z < *last_z - EPSILON || *last_z + EPSILON < z) if (last_z == nullptr || z < *last_z - EPSILON || *last_z + EPSILON < z) {
m_layers.append(z, { last_travel_s_id, move_id }); const size_t start_it = (m_layers.empty() && first_travel_s_id != 0) ? first_travel_s_id : last_travel_s_id;
m_layers.append(z, { start_it, move_id });
}
else else
m_layers.get_ranges().back().last = move_id; m_layers.get_ranges().back().last = move_id;
} }
@ -2177,7 +2180,8 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
else if (move.type == EMoveType::Travel) { else if (move.type == EMoveType::Travel) {
if (move_id - last_travel_s_id > 1 && !m_layers.empty()) if (move_id - last_travel_s_id > 1 && !m_layers.empty())
m_layers.get_ranges().back().last = move_id; m_layers.get_ranges().back().last = move_id;
else if (m_layers.empty() && first_travel_s_id == 0)
first_travel_s_id = move_id;
last_travel_s_id = move_id; last_travel_s_id = move_id;
} }
} }
@ -2433,8 +2437,10 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
for (size_t i = 0; i < buffer.paths.size(); ++i) { for (size_t i = 0; i < buffer.paths.size(); ++i) {
const Path& path = buffer.paths[i]; const Path& path = buffer.paths[i];
if (path.type == EMoveType::Travel) { if (path.type == EMoveType::Travel) {
if (!is_travel_in_layers_range(i, m_layers_z_range[0], m_layers_z_range[1])) if (path.sub_paths.front().first.s_id > m_layers_z_range[0]) {
continue; if (!is_travel_in_layers_range(i, m_layers_z_range[0], m_layers_z_range[1]))
continue;
}
} }
else if (!is_in_layers_range(path, m_layers_z_range[0], m_layers_z_range[1])) else if (!is_in_layers_range(path, m_layers_z_range[0], m_layers_z_range[1]))
continue; continue;