From 36bedfdebfa1c82535c469b251c397b88c260ce9 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 15 Oct 2020 12:42:58 +0200 Subject: [PATCH] #4719 - Fixed toolpaths generation when background process is on --- src/slic3r/GUI/GCodeViewer.cpp | 99 ++++++++++++++++++---------------- src/slic3r/GUI/GCodeViewer.hpp | 4 +- src/slic3r/GUI/GLCanvas3D.cpp | 7 --- 3 files changed, 54 insertions(+), 56 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 6a5221c32..df77c3440 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -288,55 +288,10 @@ const std::vector GCodeViewer::Range_Colors {{ { 0.581f, 0.149f, 0.087f } // reddish }}; -bool GCodeViewer::init() -{ - for (size_t i = 0; i < m_buffers.size(); ++i) { - TBuffer& buffer = m_buffers[i]; - switch (buffer_type(i)) - { - default: { break; } - case EMoveType::Tool_change: - case EMoveType::Color_change: - case EMoveType::Pause_Print: - case EMoveType::Custom_GCode: - case EMoveType::Retract: - case EMoveType::Unretract: - { - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Point; - buffer.vertices.format = VBuffer::EFormat::Position; - buffer.shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; - break; - } - case EMoveType::Extrude: - { - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle; - buffer.vertices.format = VBuffer::EFormat::PositionNormal3; - buffer.shader = "gouraud_light"; - break; - } - case EMoveType::Travel: - { - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line; - buffer.vertices.format = VBuffer::EFormat::PositionNormal1; - buffer.shader = "toolpaths_lines"; - break; - } - } - } - - set_toolpath_move_type_visible(EMoveType::Extrude, true); - m_sequential_view.marker.init(); - m_sequential_view.skip_invisible_moves = true; - - std::array point_sizes; - ::glGetIntegerv(GL_ALIASED_POINT_SIZE_RANGE, point_sizes.data()); - m_detected_point_sizes = { static_cast(point_sizes[0]), static_cast(point_sizes[1]) }; - - return true; -} - void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print& print, bool initialized) { + init(); + // avoid processing if called with the same gcode_result if (m_last_result_id == gcode_result.id) return; @@ -898,6 +853,56 @@ void GCodeViewer::export_toolpaths_to_obj(const char* filename) const fclose(fp); } +void GCodeViewer::init() +{ + if (m_initialized) + return; + + for (size_t i = 0; i < m_buffers.size(); ++i) { + TBuffer& buffer = m_buffers[i]; + switch (buffer_type(i)) + { + default: { break; } + case EMoveType::Tool_change: + case EMoveType::Color_change: + case EMoveType::Pause_Print: + case EMoveType::Custom_GCode: + case EMoveType::Retract: + case EMoveType::Unretract: + { + buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Point; + buffer.vertices.format = VBuffer::EFormat::Position; + buffer.shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; + break; + } + case EMoveType::Extrude: + { + buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle; + buffer.vertices.format = VBuffer::EFormat::PositionNormal3; + buffer.shader = "gouraud_light"; + break; + } + case EMoveType::Travel: + { + buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line; + buffer.vertices.format = VBuffer::EFormat::PositionNormal1; + buffer.shader = "toolpaths_lines"; + break; + } + } + } + + set_toolpath_move_type_visible(EMoveType::Extrude, true); + m_sequential_view.marker.init(); + m_sequential_view.skip_invisible_moves = true; + + std::array point_sizes; + ::glGetIntegerv(GL_ALIASED_POINT_SIZE_RANGE, point_sizes.data()); + m_detected_point_sizes = { static_cast(point_sizes[0]), static_cast(point_sizes[1]) }; + + m_initialized = true; +} + void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result) { #if ENABLE_GCODE_VIEWER_STATISTICS diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index c9fcabac3..4ae5cf2dd 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -387,6 +387,7 @@ public: }; private: + bool m_initialized{ false }; unsigned int m_last_result_id{ 0 }; size_t m_moves_count{ 0 }; mutable std::vector m_buffers{ static_cast(EMoveType::Extrude) }; @@ -415,8 +416,6 @@ public: GCodeViewer() = default; ~GCodeViewer() { reset(); } - bool init(); - // extract rendering data from the given parameters void load(const GCodeProcessor::Result& gcode_result, const Print& print, bool initialized); // recalculate ranges in dependence of what is visible and sets tool/print colors @@ -456,6 +455,7 @@ public: void export_toolpaths_to_obj(const char* filename) const; private: + void init(); void load_toolpaths(const GCodeProcessor::Result& gcode_result); void load_shells(const Print& print, bool initialized); void refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const; diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index c2717761f..dd80e15b5 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1580,13 +1580,6 @@ bool GLCanvas3D::init() if (m_main_toolbar.is_enabled()) m_layers_editing.init(); -#if ENABLE_GCODE_VIEWER - if (!m_main_toolbar.is_enabled()) { - if (!m_gcode_viewer.init()) - return false; - } -#endif // ENABLE_GCODE_VIEWER - // on linux the gl context is not valid until the canvas is not shown on screen // we defer the geometry finalization of volumes until the first call to render() m_volumes.finalize_geometry(true);