Fixed crash when moving horizontal slider thumb in preview with no toolpath active

This commit is contained in:
enricoturri1966 2020-10-07 13:38:21 +02:00
parent 9e0e597284
commit 2ecd78b0d5
5 changed files with 25 additions and 6 deletions

View file

@ -1689,6 +1689,8 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
break;
}
unsigned int render_paths_count = 0;
// second pass: filter paths by sequential data and collect them by color
for (const auto& [buffer, index_buffer_id, path_id] : paths) {
const Path& path = buffer->paths[path_id];
@ -1711,6 +1713,7 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
it->color = color;
it->path_id = path_id;
it->index_buffer_id = index_buffer_id;
++render_paths_count;
}
unsigned int segments_count = std::min(m_sequential_view.current.last, path.last.s_id) - std::max(m_sequential_view.current.first, path.first.s_id) + 1;
@ -1733,6 +1736,8 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
it->offsets.push_back(static_cast<size_t>((path.first.i_id + delta_1st) * sizeof(unsigned int)));
}
wxGetApp().plater()->enable_preview_moves_slider(render_paths_count > 0);
#if ENABLE_GCODE_VIEWER_STATISTICS
for (const TBuffer& buffer : m_buffers) {
m_statistics.render_paths_size += SLIC3R_STDVEC_MEMSIZE(buffer.render_paths, RenderPath);

View file

@ -1162,8 +1162,7 @@ void Preview::update_moves_slider()
std::vector<double> values(view.endpoints.last - view.endpoints.first + 1);
unsigned int count = 0;
for (unsigned int i = view.endpoints.first; i <= view.endpoints.last; ++i)
{
for (unsigned int i = view.endpoints.first; i <= view.endpoints.last; ++i) {
values[count++] = static_cast<double>(i + 1);
}
@ -1171,6 +1170,12 @@ void Preview::update_moves_slider()
m_moves_slider->SetMaxValue(view.endpoints.last - view.endpoints.first);
m_moves_slider->SetSelectionSpan(view.current.first - view.endpoints.first, view.current.last - view.endpoints.first);
}
void Preview::enable_moves_slider(bool enable)
{
if (m_moves_slider != nullptr)
m_moves_slider->Enable(enable);
}
#else
void Preview::update_double_slider_from_canvas(wxKeyEvent & event)
{

View file

@ -194,6 +194,7 @@ Preview(wxWindow* parent, Model* model, DynamicPrintConfig* config,
#if ENABLE_GCODE_VIEWER
void update_bottom_toolbar();
void update_moves_slider();
void enable_moves_slider(bool enable);
void hide_layers_slider();
#endif // ENABLE_GCODE_VIEWER

View file

@ -1612,9 +1612,8 @@ struct Plater::priv
#if ENABLE_GCODE_VIEWER
void update_preview_bottom_toolbar();
void update_preview_moves_slider();
#endif // ENABLE_GCODE_VIEWER
void enable_preview_moves_slider(bool enable);
#if ENABLE_GCODE_VIEWER
void reset_gcode_toolpaths();
#endif // ENABLE_GCODE_VIEWER
@ -4105,9 +4104,12 @@ void Plater::priv::update_preview_moves_slider()
{
preview->update_moves_slider();
}
#endif // ENABLE_GCODE_VIEWER
#if ENABLE_GCODE_VIEWER
void Plater::priv::enable_preview_moves_slider(bool enable)
{
preview->enable_moves_slider(enable);
}
void Plater::priv::reset_gcode_toolpaths()
{
preview->get_canvas3d()->reset_gcode_toolpaths();
@ -5898,6 +5900,11 @@ void Plater::update_preview_moves_slider()
p->update_preview_moves_slider();
}
void Plater::enable_preview_moves_slider(bool enable)
{
p->enable_preview_moves_slider(enable);
}
void Plater::reset_gcode_toolpaths()
{
p->reset_gcode_toolpaths();

View file

@ -316,6 +316,7 @@ public:
#if ENABLE_GCODE_VIEWER
void update_preview_bottom_toolbar();
void update_preview_moves_slider();
void enable_preview_moves_slider(bool enable);
void reset_gcode_toolpaths();
void reset_last_loaded_gcode() { m_last_loaded_gcode = ""; }