Added option to apply the sequential slider in preview to top layer only or to whole gcode toolpaths

This commit is contained in:
enricoturri1966 2020-10-15 10:25:13 +02:00
parent d7686d7e6a
commit 8580ecacca
9 changed files with 78 additions and 38 deletions
src/slic3r/GUI

View file

@ -13,6 +13,7 @@
#include "Camera.hpp"
#include "I18N.hpp"
#include "GUI_Utils.hpp"
#include "GUI.hpp"
#include "DoubleSlider.hpp"
#include "GLCanvas3D.hpp"
#include "GLToolbar.hpp"
@ -446,7 +447,7 @@ void GCodeViewer::refresh(const GCodeProcessor::Result& gcode_result, const std:
#endif // ENABLE_GCODE_VIEWER_STATISTICS
// update buffers' render paths
refresh_render_paths(/*false,*/ false);
refresh_render_paths(false, false);
log_memory_used("Refreshed G-code extrusion paths, ");
}
@ -536,7 +537,7 @@ void GCodeViewer::update_sequential_view_current(unsigned int first, unsigned in
m_sequential_view.current.last = new_last;
m_sequential_view.last_current = m_sequential_view.current;
refresh_render_paths(/*true,*/ true);
refresh_render_paths(true, true);
if (new_first != first || new_last != last)
wxGetApp().plater()->update_preview_moves_slider();
@ -595,10 +596,10 @@ void GCodeViewer::set_options_visibility_from_flags(unsigned int flags)
void GCodeViewer::set_layers_z_range(const std::array<double, 2>& layers_z_range)
{
/*bool keep_sequential_current_first = layers_z_range[0] >= m_layers_z_range[0];*/
bool keep_sequential_current_first = layers_z_range[0] >= m_layers_z_range[0];
bool keep_sequential_current_last = layers_z_range[1] <= m_layers_z_range[1];
m_layers_z_range = layers_z_range;
refresh_render_paths(/*keep_sequential_current_first,*/ keep_sequential_current_last);
refresh_render_paths(keep_sequential_current_first, keep_sequential_current_last);
wxGetApp().plater()->update_preview_moves_slider();
}
@ -1584,7 +1585,7 @@ void GCodeViewer::load_shells(const Print& print, bool initialized)
}
}
void GCodeViewer::refresh_render_paths(/*bool keep_sequential_current_first,*/ bool keep_sequential_current_last) const
void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const
{
#if ENABLE_GCODE_VIEWER_STATISTICS
auto start_time = std::chrono::high_resolution_clock::now();
@ -1647,9 +1648,11 @@ void GCodeViewer::refresh_render_paths(/*bool keep_sequential_current_first,*/ b
m_statistics.render_paths_size = 0;
#endif // ENABLE_GCODE_VIEWER_STATISTICS
bool top_layer_only = get_app_config()->get("seq_top_layer_only") == "1";
SequentialView::Endpoints global_endpoints = { m_moves_count , 0 };
SequentialView::Endpoints top_layer_endpoints = global_endpoints;
/*if (!keep_sequential_current_first)*/ m_sequential_view.current.first = 0;
if (top_layer_only || !keep_sequential_current_first) m_sequential_view.current.first = 0;
if (!keep_sequential_current_last) m_sequential_view.current.last = m_moves_count;
// first pass: collect visible paths and update sequential view data
@ -1679,21 +1682,23 @@ void GCodeViewer::refresh_render_paths(/*bool keep_sequential_current_first,*/ b
global_endpoints.first = std::min(global_endpoints.first, path.first.s_id);
global_endpoints.last = std::max(global_endpoints.last, path.last.s_id);
if (path.type == EMoveType::Travel) {
if (is_travel_in_z_range(i, m_layers_z_range[1], m_layers_z_range[1])) {
if (top_layer_only) {
if (path.type == EMoveType::Travel) {
if (is_travel_in_z_range(i, m_layers_z_range[1], m_layers_z_range[1])) {
top_layer_endpoints.first = std::min(top_layer_endpoints.first, path.first.s_id);
top_layer_endpoints.last = std::max(top_layer_endpoints.last, path.last.s_id);
}
}
else if (is_in_z_range(path, m_layers_z_range[1], m_layers_z_range[1])) {
top_layer_endpoints.first = std::min(top_layer_endpoints.first, path.first.s_id);
top_layer_endpoints.last = std::max(top_layer_endpoints.last, path.last.s_id);
}
}
else if (is_in_z_range(path, m_layers_z_range[1], m_layers_z_range[1])) {
top_layer_endpoints.first = std::min(top_layer_endpoints.first, path.first.s_id);
top_layer_endpoints.last = std::max(top_layer_endpoints.last, path.last.s_id);
}
}
}
// update current sequential position
m_sequential_view.current.first = /*keep_sequential_current_first ? std::clamp(m_sequential_view.current.first, global_endpoints.first, global_endpoints.last) :*/ global_endpoints.first;
m_sequential_view.current.first = !top_layer_only && keep_sequential_current_first ? std::clamp(m_sequential_view.current.first, global_endpoints.first, global_endpoints.last) : global_endpoints.first;
m_sequential_view.current.last = keep_sequential_current_last ? std::clamp(m_sequential_view.current.last, global_endpoints.first, global_endpoints.last) : global_endpoints.last;
// get the world position from gpu
@ -1741,7 +1746,7 @@ void GCodeViewer::refresh_render_paths(/*bool keep_sequential_current_first,*/ b
switch (path.type)
{
case EMoveType::Extrude: {
if (m_sequential_view.current.last == global_endpoints.last || is_in_z_range(path, m_layers_z_range[1], m_layers_z_range[1]))
if (!top_layer_only || m_sequential_view.current.last == global_endpoints.last || is_in_z_range(path, m_layers_z_range[1], m_layers_z_range[1]))
color = extrusion_color(path);
else
color = { 0.25f, 0.25f, 0.25f };
@ -1749,7 +1754,7 @@ void GCodeViewer::refresh_render_paths(/*bool keep_sequential_current_first,*/ b
break;
}
case EMoveType::Travel: {
if (m_sequential_view.current.last == global_endpoints.last || is_travel_in_z_range(path_id, m_layers_z_range[1], m_layers_z_range[1]))
if (!top_layer_only || m_sequential_view.current.last == global_endpoints.last || is_travel_in_z_range(path_id, m_layers_z_range[1], m_layers_z_range[1]))
color = (m_view_type == EViewType::Feedrate || m_view_type == EViewType::Tool || m_view_type == EViewType::ColorPrint) ? extrusion_color(path) : travel_color(path);
else
color = { 0.25f, 0.25f, 0.25f };
@ -1790,8 +1795,8 @@ void GCodeViewer::refresh_render_paths(/*bool keep_sequential_current_first,*/ b
}
// set sequential data to their final value
m_sequential_view.endpoints = top_layer_endpoints;
m_sequential_view.current.first = /*keep_sequential_current_first ? std::clamp(m_sequential_view.current.first, m_sequential_view.endpoints.first, m_sequential_view.endpoints.last) :*/ m_sequential_view.endpoints.first;
m_sequential_view.endpoints = top_layer_only ? top_layer_endpoints : global_endpoints;
m_sequential_view.current.first = !top_layer_only && keep_sequential_current_first ? std::clamp(m_sequential_view.current.first, m_sequential_view.endpoints.first, m_sequential_view.endpoints.last) : m_sequential_view.endpoints.first;
wxGetApp().plater()->enable_preview_moves_slider(!paths.empty());
@ -2236,7 +2241,7 @@ void GCodeViewer::render_legend() const
visible, times[i], percents[i], max_percent, offsets, [this, role, visible]() {
m_extrusions.role_visibility_flags = visible ? m_extrusions.role_visibility_flags & ~(1 << role) : m_extrusions.role_visibility_flags | (1 << role);
// update buffers' render paths
refresh_render_paths(/*false,*/ false);
refresh_render_paths(false, false);
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
wxGetApp().plater()->update_preview_bottom_toolbar();
}