From 7b0e35e70d8cc63343d4ca9b57769e870728a977 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 16 Apr 2020 15:59:36 +0200 Subject: [PATCH] GCodeViewer -> Selection of extrusions view type --- src/slic3r/GUI/GCodeViewer.cpp | 36 ++++++++++++++++++++++++++++------ src/slic3r/GUI/GCodeViewer.hpp | 25 +++++++++++++++++++++++ src/slic3r/GUI/GLCanvas3D.cpp | 5 +++++ src/slic3r/GUI/GLCanvas3D.hpp | 1 + src/slic3r/GUI/GUI_Preview.cpp | 7 +++++++ 5 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index a554ecb8ba..d6fc7fd8ef 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -354,6 +354,35 @@ void GCodeViewer::load_shells(const Print& print, bool initialized) void GCodeViewer::render_toolpaths() const { + auto extrusion_color = [this](const Path& path) { + std::array color; + switch (m_view_type) + { + case EViewType::FeatureType: + { + unsigned int color_id = static_cast(path.role); + if (color_id >= erCount) + color_id = 0; + + color = m_extrusion_role_colors[color_id]; + break; + } + case EViewType::Height: + case EViewType::Width: + case EViewType::Feedrate: + case EViewType::FanSpeed: + case EViewType::VolumetricRate: + case EViewType::Tool: + case EViewType::ColorPrint: + default: + { + color = { 1.0f, 1.0f, 1.0f, 1.0f }; + break; + } + } + return color; + }; + auto set_color = [](GLint current_program_id, const std::array& color) { if (current_program_id > 0) { GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1; @@ -427,12 +456,7 @@ void GCodeViewer::render_toolpaths() const { for (const Path& path : buffer.paths) { - unsigned int color_id = static_cast(path.role); - if (color_id >= erCount) - color_id = 0; - - set_color(current_program_id, m_extrusion_role_colors[color_id]); - + set_color(current_program_id, extrusion_color(path)); glsafe(::glDrawElements(GL_LINE_STRIP, GLsizei(path.last - path.first + 1), GL_UNSIGNED_INT, (const void*)(path.first * sizeof(GLuint)))); } break; diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index e44fb01800..9bc644c4eb 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -62,6 +62,21 @@ class GCodeViewer Shader shader; }; +public: + enum class EViewType : unsigned char + { + FeatureType, + Height, + Width, + Feedrate, + FanSpeed, + VolumetricRate, + Tool, + ColorPrint, + Count + }; + +private: VBuffer m_vertices; std::vector m_buffers{ static_cast(GCodeProcessor::EMoveType::Extrude) }; @@ -71,6 +86,8 @@ class GCodeViewer std::array, erCount> m_extrusion_role_colors; + EViewType m_view_type{ EViewType::FeatureType }; + public: GCodeViewer() = default; ~GCodeViewer() { reset(); } @@ -86,6 +103,14 @@ public: const std::vector& get_layers_zs() const { return m_layers_zs; }; + EViewType get_view_type() const { return m_view_type; } + void set_view_type(EViewType type) { + if (type == EViewType::Count) + type = EViewType::FeatureType; + + m_view_type = type; + } + bool is_toolpath_visible(GCodeProcessor::EMoveType type) const; void set_toolpath_visible(GCodeProcessor::EMoveType type, bool visible); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index c7c3eaaf59..9f3c9653c5 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2323,6 +2323,11 @@ void GLCanvas3D::set_toolpath_visible(GCodeProcessor::EMoveType type, bool visib m_gcode_viewer.set_toolpath_visible(type, visible); } +void GLCanvas3D::set_toolpath_view_type(GCodeViewer::EViewType type) +{ + m_gcode_viewer.set_view_type(type); +} + void GLCanvas3D::set_shells_visible(bool visible) { m_gcode_viewer.set_shells_visible(visible); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 7033f05a0b..246a298fe4 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -642,6 +642,7 @@ public: #if ENABLE_GCODE_VIEWER const std::vector& get_layers_zs() const; void set_toolpath_visible(GCodeProcessor::EMoveType type, bool visible); + void set_toolpath_view_type(GCodeViewer::EViewType type); void set_shells_visible(bool visible); #else std::vector get_current_print_zs(bool active_only) const; diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 0c4f655c58..f2a56e8a20 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -602,10 +602,17 @@ void Preview::on_choice_view_type(wxCommandEvent& evt) { m_preferred_color_mode = (m_choice_view_type->GetStringSelection() == L("Tool")) ? "tool" : "feature"; int selection = m_choice_view_type->GetCurrentSelection(); +#if ENABLE_GCODE_VIEWER + if (0 <= selection && selection < static_cast(GCodeViewer::EViewType::Count)) + m_canvas->set_toolpath_view_type(static_cast(selection)); + + refresh_print(); +#else if ((0 <= selection) && (selection < (int)GCodePreviewData::Extrusion::Num_View_Types)) m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)selection; reload_print(); +#endif // ENABLE_GCODE_VIEWER } void Preview::on_combochecklist_features(wxCommandEvent& evt)