From 5c29f868c304c15fe9b7b2e96a092c857b2f287b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 9 Jan 2024 13:14:14 +0100 Subject: [PATCH] New gcode visualization integration - Fixed toolpaths reset --- src/libvgcode/include/ColorRange.hpp | 4 ++-- src/libvgcode/include/Viewer.hpp | 24 ++++++++++++++++++++---- src/libvgcode/src/ColorRange.cpp | 2 +- src/libvgcode/src/ViewerImpl.cpp | 2 ++ src/libvgcode/src/ViewerImpl.hpp | 2 +- src/slic3r/GUI/GCodeViewer.cpp | 2 -- src/slic3r/GUI/GLCanvas3D.cpp | 6 +++--- src/slic3r/GUI/Plater.cpp | 3 +++ 8 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/libvgcode/include/ColorRange.hpp b/src/libvgcode/include/ColorRange.hpp index d3dbb17c27..4afa2b0cf0 100644 --- a/src/libvgcode/include/ColorRange.hpp +++ b/src/libvgcode/include/ColorRange.hpp @@ -12,7 +12,7 @@ namespace libvgcode { // -// Helper class to interpolate between colors defined in Ranges_Colors palette. +// Helper class to interpolate between colors defined in RANGES_COLORS palette. // Interpolation can be done linearly or logarithmically. // Usage: // 1) Define an instance of ColorRange of the desired interpolation type @@ -64,7 +64,7 @@ public: float get_step_size() const; std::vector get_values() const; - static const ColorRange Dummy_Color_Range; + static const ColorRange DUMMY_COLOR_RANGE; private: EColorRangeType m_type{ EColorRangeType::Linear }; diff --git a/src/libvgcode/include/Viewer.hpp b/src/libvgcode/include/Viewer.hpp index e2f3214d56..f280afd245 100644 --- a/src/libvgcode/include/Viewer.hpp +++ b/src/libvgcode/include/Viewer.hpp @@ -27,19 +27,26 @@ public: // // Initialize the viewer. // This method must be called after a valid OpenGL context has been already created - // and before to call any other method of the viewer. + // and before calling any other method of the viewer. // void init(); // // Release the resources used by the viewer. // This method must be called before releasing the OpenGL context if the viewer - // destructor is called after releasing the OpenGL context. + // goes out of scope after releasing the OpenGL context. // void shutdown(); + // + // Reset the contents of the viewer. + // Automatically called by load() method. + // void reset(); + // + // Setup the viewer content from the given data. + // void load(GCodeInputData&& gcode_data); // - // Render the toolpaths according to the current settings, + // Render the toolpaths according to the current settings and // using the given camera matrices. // void render(const Mat4x4& view_matrix, const Mat4x4& projection_matrix); @@ -92,7 +99,7 @@ public: size_t get_vertices_count() const; // - // Return the vertex pointed by the max value of the view current range + // Return the vertex pointed by the max value of the view visible range // const PathVertex& get_current_vertex() const; @@ -101,6 +108,9 @@ public: // const PathVertex& get_vertex_at(size_t id) const; + // + // Return the color used to render the given vertex with the current settings. + // Color get_vertex_color(const PathVertex& vertex) const; // @@ -108,6 +118,9 @@ public: // size_t get_enabled_segments_count() const; + // + // Return the Interval containing the enabled segments + // const Interval& get_enabled_segments_range() const; // @@ -115,6 +128,9 @@ public: // size_t get_enabled_options_count() const; + // + // Return the Interval containing the enabled options + // const Interval& get_enabled_options_range() const; // diff --git a/src/libvgcode/src/ColorRange.cpp b/src/libvgcode/src/ColorRange.cpp index c13592c690..ca115befa7 100644 --- a/src/libvgcode/src/ColorRange.cpp +++ b/src/libvgcode/src/ColorRange.cpp @@ -10,7 +10,7 @@ namespace libvgcode { -const ColorRange ColorRange::Dummy_Color_Range = ColorRange(); +const ColorRange ColorRange::DUMMY_COLOR_RANGE = ColorRange(); ColorRange::ColorRange(EColorRangeType type) : m_type(type) diff --git a/src/libvgcode/src/ViewerImpl.cpp b/src/libvgcode/src/ViewerImpl.cpp index 228c81aeb1..1250010000 100644 --- a/src/libvgcode/src/ViewerImpl.cpp +++ b/src/libvgcode/src/ViewerImpl.cpp @@ -463,6 +463,8 @@ void ViewerImpl::load(GCodeInputData&& gcode_data) if (gcode_data.vertices.empty()) return; + reset(); + m_loading = true; m_vertices = std::move(gcode_data.vertices); diff --git a/src/libvgcode/src/ViewerImpl.hpp b/src/libvgcode/src/ViewerImpl.hpp index 4f0458fe96..1d15c45033 100644 --- a/src/libvgcode/src/ViewerImpl.hpp +++ b/src/libvgcode/src/ViewerImpl.hpp @@ -155,7 +155,7 @@ public: const ColorRange& get_volumetric_rate_range() const { return m_volumetric_rate_range; } const ColorRange& get_layer_time_range(EColorRangeType type) const { return (static_cast(type) < m_layer_time_range.size()) ? - m_layer_time_range[static_cast(type)] : ColorRange::Dummy_Color_Range; + m_layer_time_range[static_cast(type)] : ColorRange::DUMMY_COLOR_RANGE; } float get_travels_radius() const { return m_travels_radius; } diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 5b33eb40ec..4bbc90bb65 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -1290,8 +1290,6 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print & p #if ENABLE_NEW_GCODE_VIEWER void GCodeViewer::load_as_preview(libvgcode::GCodeInputData&& data, const std::vector& str_tool_colors) { - m_viewer.reset(); - if (!str_tool_colors.empty()) { std::vector tool_colors; decode_colors(str_tool_colors, tool_colors); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 5549f071b6..e9aaee3e93 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2743,9 +2743,6 @@ void GLCanvas3D::load_preview(const std::vector& str_tool_colors, c _set_current(); - // Release OpenGL data before generating new data. - this->reset_volumes(); - #if ENABLE_NEW_GCODE_VIEWER libvgcode::GCodeInputData data = libvgcode::convert(*print, str_tool_colors, color_print_values, static_cast(wxGetApp().extruders_edited_cnt())); @@ -2756,6 +2753,9 @@ void GLCanvas3D::load_preview(const std::vector& str_tool_colors, c m_gcode_viewer.set_view_type(libvgcode::EViewType::FeatureType); m_gcode_viewer.load_as_preview(std::move(data), str_tool_colors); #else + // Release OpenGL data before generating new data. + this->reset_volumes(); + const BuildVolume& build_volume = m_bed.build_volume(); _load_print_toolpaths(build_volume); _load_wipe_tower_toolpaths(build_volume, str_tool_colors); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 22fe36d6e6..ca365d4619 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -6233,6 +6233,9 @@ void Plater::on_config_change(const DynamicPrintConfig &config) p->reset_gcode_toolpaths(); p->view3D->get_canvas3d()->reset_sequential_print_clearance(); p->view3D->get_canvas3d()->set_sla_view_type(GLCanvas3D::ESLAViewType::Original); +#if ENABLE_NEW_GCODE_VIEWER + p->preview->get_canvas3d()->reset_volumes(); +#endif // ENABLE_NEW_GCODE_VIEWER } else if (opt_key == "bed_shape" || opt_key == "bed_custom_texture" || opt_key == "bed_custom_model") { bed_shape_changed = true;