From 91fdb67cd726f280948ffdced65333f6c6625383 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 7 Jan 2021 09:57:37 +0100 Subject: [PATCH] Refactoring of GCodeViewer initialization --- src/slic3r/GUI/GCodeViewer.cpp | 88 +++++++++++++++------------------- src/slic3r/GUI/GCodeViewer.hpp | 8 ++-- 2 files changed, 42 insertions(+), 54 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 097511565..1ae184447 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -306,10 +306,47 @@ const std::vector GCodeViewer::Range_Colors {{ { 0.581f, 0.149f, 0.087f } // reddish }}; +GCodeViewer::GCodeViewer() +{ + // initializes non opengl data of TBuffers + 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; + break; + } + case EMoveType::Wipe: + case EMoveType::Extrude: + { + buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle; + buffer.vertices.format = VBuffer::EFormat::PositionNormal3; + break; + } + case EMoveType::Travel: + { + buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line; + buffer.vertices.format = VBuffer::EFormat::PositionNormal1; + break; + } + } + } + + set_toolpath_move_type_visible(EMoveType::Extrude, true); +// m_sequential_view.skip_invisible_moves = 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; @@ -460,9 +497,6 @@ void GCodeViewer::update_shells_color_by_extruder(const DynamicPrintConfig* conf void GCodeViewer::reset() { - m_initialized = false; - m_gl_data_initialized = false; - m_moves_count = 0; for (TBuffer& buffer : m_buffers) { buffer.reset(); @@ -955,50 +989,6 @@ void GCodeViewer::export_toolpaths_to_obj(const char* filename) const fclose(fp); } -void GCodeViewer::init() -{ - if (m_initialized) - return; - - // initializes non opengl data of TBuffers - 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; - break; - } - case EMoveType::Wipe: - case EMoveType::Extrude: - { - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle; - buffer.vertices.format = VBuffer::EFormat::PositionNormal3; - break; - } - case EMoveType::Travel: - { - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line; - buffer.vertices.format = VBuffer::EFormat::PositionNormal1; - break; - } - } - } - - set_toolpath_move_type_visible(EMoveType::Extrude, true); -// m_sequential_view.skip_invisible_moves = true; - - 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 31092e30d..a929fcc6b 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -195,7 +195,7 @@ class GCodeViewer std::string shader; std::vector paths; - // std::set seems to perform singificantly better, at least on Windows. + // std::set seems to perform significantly better, at least on Windows. // std::unordered_set render_paths; std::set render_paths; bool visible{ false }; @@ -228,7 +228,7 @@ class GCodeViewer { case ERenderPrimitiveType::Point: { return 0; } case ERenderPrimitiveType::Line: { return 1; } - case ERenderPrimitiveType::Triangle: { return 36; } // 1 vertex of 13th triangle + case ERenderPrimitiveType::Triangle: { return 36; } // 1st vertex of 13th triangle default: { return 0; } } } @@ -461,7 +461,6 @@ public: }; private: - bool m_initialized{ false }; mutable bool m_gl_data_initialized{ false }; unsigned int m_last_result_id{ 0 }; size_t m_moves_count{ 0 }; @@ -490,7 +489,7 @@ private: GCodeProcessor::Result::SettingsIds m_settings_ids; public: - GCodeViewer() = default; + GCodeViewer(); ~GCodeViewer() { reset(); } // extract rendering data from the given parameters @@ -536,7 +535,6 @@ 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;