From c7c594c302e3e95c40a7dd9ab90b2bd5f8f91537 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 20 Dec 2023 11:37:08 +0100 Subject: [PATCH] New gcode visualization - Refactoring + added missing headers --- src/libvgcode/include/ColorRange.hpp | 2 + src/libvgcode/include/PathVertex.hpp | 9 +- src/libvgcode/include/Types.hpp | 6 +- src/libvgcode/include/Viewer.hpp | 4 +- src/libvgcode/src/CogMarker.cpp | 4 +- src/libvgcode/src/CogMarker.hpp | 4 +- src/libvgcode/src/Settings.hpp | 4 +- src/libvgcode/src/Shaders.hpp | 6 +- src/libvgcode/src/ToolMarker.cpp | 4 +- src/libvgcode/src/ToolMarker.hpp | 4 +- src/libvgcode/src/Viewer.cpp | 4 +- src/libvgcode/src/ViewerImpl.cpp | 20 ++-- src/libvgcode/src/ViewerImpl.hpp | 24 ++--- src/slic3r/GUI/GCodeViewer.cpp | 94 +++++++++---------- src/slic3r/GUI/GCodeViewer.hpp | 48 +++++----- src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp | 60 ++++++------ 16 files changed, 152 insertions(+), 145 deletions(-) diff --git a/src/libvgcode/include/ColorRange.hpp b/src/libvgcode/include/ColorRange.hpp index 4da1e2bcbb..d3dbb17c27 100644 --- a/src/libvgcode/include/ColorRange.hpp +++ b/src/libvgcode/include/ColorRange.hpp @@ -7,6 +7,8 @@ #include "../include/Types.hpp" +#include + namespace libvgcode { // diff --git a/src/libvgcode/include/PathVertex.hpp b/src/libvgcode/include/PathVertex.hpp index 523df501b9..f48384e1f6 100644 --- a/src/libvgcode/include/PathVertex.hpp +++ b/src/libvgcode/include/PathVertex.hpp @@ -7,6 +7,8 @@ #include "Types.hpp" +#include + namespace libvgcode { // @@ -42,9 +44,12 @@ struct PathVertex // Segment volumetric rate // float volumetric_rate{ 0.0f }; -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS + // + // Segment weight + // float weight{ 0.0f }; -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS // // Segment extrusion role // diff --git a/src/libvgcode/include/Types.hpp b/src/libvgcode/include/Types.hpp index bf5fde9685..319811bd75 100644 --- a/src/libvgcode/include/Types.hpp +++ b/src/libvgcode/include/Types.hpp @@ -5,7 +5,7 @@ #ifndef VGCODE_TYPES_HPP #define VGCODE_TYPES_HPP -#define ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS 1 +#define ENABLE_COG_AND_TOOL_MARKERS 0 #include #include @@ -152,10 +152,10 @@ enum class EOptionType : uint8_t ColorChanges, PausePrints, CustomGCodes, -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS CenterOfGravity, ToolMarker, -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS COUNT }; diff --git a/src/libvgcode/include/Viewer.hpp b/src/libvgcode/include/Viewer.hpp index b869b812f1..1856c943cd 100644 --- a/src/libvgcode/include/Viewer.hpp +++ b/src/libvgcode/include/Viewer.hpp @@ -172,7 +172,7 @@ public: float get_wipes_radius() const; void set_wipes_radius(float radius); -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS // // Returns the position of the center of gravity of the toolpaths. // It does not take in account extrusions of type: @@ -204,7 +204,7 @@ public: float get_tool_marker_alpha() const; void set_tool_marker_alpha(float alpha); -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS private: ViewerImpl* m_impl{ nullptr }; diff --git a/src/libvgcode/src/CogMarker.cpp b/src/libvgcode/src/CogMarker.cpp index 772bb77c1c..489a680da8 100644 --- a/src/libvgcode/src/CogMarker.cpp +++ b/src/libvgcode/src/CogMarker.cpp @@ -10,7 +10,7 @@ #include #include -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS namespace libvgcode { @@ -157,4 +157,4 @@ Vec3 CogMarker::get_position() const } // namespace libvgcode -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS diff --git a/src/libvgcode/src/CogMarker.hpp b/src/libvgcode/src/CogMarker.hpp index 1296c42198..38a6d87f12 100644 --- a/src/libvgcode/src/CogMarker.hpp +++ b/src/libvgcode/src/CogMarker.hpp @@ -7,7 +7,7 @@ #include "../include/Types.hpp" -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS namespace libvgcode { @@ -57,6 +57,6 @@ private: } // namespace libvgcode -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS #endif // VGCODE_COGMARKER_HPP \ No newline at end of file diff --git a/src/libvgcode/src/Settings.hpp b/src/libvgcode/src/Settings.hpp index 83c7c34cd0..7fbf2a34a1 100644 --- a/src/libvgcode/src/Settings.hpp +++ b/src/libvgcode/src/Settings.hpp @@ -31,10 +31,10 @@ struct Settings { EOptionType::ColorChanges, false }, { EOptionType::PausePrints, false }, { EOptionType::CustomGCodes, false }, -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS { EOptionType::CenterOfGravity, false }, { EOptionType::ToolMarker, true } -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS } }; std::map extrusion_roles_visibility{ { diff --git a/src/libvgcode/src/Shaders.hpp b/src/libvgcode/src/Shaders.hpp index fdafcdef9a..6aad577f08 100644 --- a/src/libvgcode/src/Shaders.hpp +++ b/src/libvgcode/src/Shaders.hpp @@ -5,7 +5,7 @@ #ifndef VGCODE_SHADERS_HPP #define VGCODE_SHADERS_HPP -// needed for tech ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +// needed for tech ENABLE_COG_AND_TOOL_MARKERS #include "../include/Types.hpp" namespace libvgcode { @@ -203,7 +203,7 @@ static const char* Options_Fragment_Shader = " fragmentColor = vec4(color, 1.0);\n" "}\n"; -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS static const char* Cog_Marker_Vertex_Shader = "#version 150\n" "const vec3 light_top_dir = vec3(-0.4574957, 0.4574957, 0.7624929);\n" @@ -291,7 +291,7 @@ static const char* Tool_Marker_Fragment_Shader = "void main() {\n" " fragment_color = color;\n" "}\n"; -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS } // namespace libvgcode diff --git a/src/libvgcode/src/ToolMarker.cpp b/src/libvgcode/src/ToolMarker.cpp index e9845533f7..59e3ef3c34 100644 --- a/src/libvgcode/src/ToolMarker.cpp +++ b/src/libvgcode/src/ToolMarker.cpp @@ -8,7 +8,7 @@ #include -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS namespace libvgcode { @@ -158,4 +158,4 @@ void ToolMarker::render() } // namespace libvgcode -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS diff --git a/src/libvgcode/src/ToolMarker.hpp b/src/libvgcode/src/ToolMarker.hpp index cacdf25538..b21ef89ba7 100644 --- a/src/libvgcode/src/ToolMarker.hpp +++ b/src/libvgcode/src/ToolMarker.hpp @@ -7,7 +7,7 @@ #include "../include/Types.hpp" -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS #include namespace libvgcode { @@ -55,6 +55,6 @@ private: } // namespace libvgcode -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS #endif // VGCODE_TOOLMARKER_HPP \ No newline at end of file diff --git a/src/libvgcode/src/Viewer.cpp b/src/libvgcode/src/Viewer.cpp index bf7c7bfff1..7c18848379 100644 --- a/src/libvgcode/src/Viewer.cpp +++ b/src/libvgcode/src/Viewer.cpp @@ -357,7 +357,7 @@ void Viewer::set_wipes_radius(float radius) m_impl->set_wipes_radius(radius); } -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS Vec3 Viewer::get_cog_position() const { return m_impl->get_cog_marker_position(); @@ -432,6 +432,6 @@ void Viewer::set_tool_marker_alpha(float alpha) { m_impl->set_tool_marker_alpha(alpha); } -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS } // namespace libvgcode diff --git a/src/libvgcode/src/ViewerImpl.cpp b/src/libvgcode/src/ViewerImpl.cpp index eef9144dd3..bbf030906c 100644 --- a/src/libvgcode/src/ViewerImpl.cpp +++ b/src/libvgcode/src/ViewerImpl.cpp @@ -385,7 +385,7 @@ void ViewerImpl::init() m_option_template.init(16); -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS // cog marker shader m_cog_marker_shader_id = init_shader("cog_marker", Cog_Marker_Vertex_Shader, Cog_Marker_Fragment_Shader); @@ -418,7 +418,7 @@ void ViewerImpl::init() m_uni_tool_marker_color_base != -1); m_tool_marker.init(32, 2.0f, 4.0f, 1.0f, 8.0f); -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS m_initialized = true; } @@ -432,9 +432,9 @@ void ViewerImpl::reset() m_used_extruders_ids.clear(); m_vertices.clear(); m_valid_lines_bitset.clear(); -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS m_cog_marker.reset(); -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS m_enabled_segments_count = 0; m_enabled_options_count = 0; @@ -482,7 +482,7 @@ void ViewerImpl::load(GCodeInputData&& gcode_data) m_used_extruders_ids.emplace_back(v.extruder_id); if (i > 0) { -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS // updates calculation for center of gravity if (v.type == EMoveType::Extrude && v.role != EGCodeExtrusionRole::Skirt && @@ -492,7 +492,7 @@ void ViewerImpl::load(GCodeInputData&& gcode_data) v.role != EGCodeExtrusionRole::Custom) { m_cog_marker.update(0.5f * (v.position + m_vertices[i - 1].position), v.weight); } -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS } } @@ -727,12 +727,12 @@ void ViewerImpl::render(const Mat4x4& view_matrix, const Mat4x4& projection_matr render_segments(view_matrix, projection_matrix, camera_position); render_options(view_matrix, projection_matrix); -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS if (m_settings.options_visibility.at(EOptionType::ToolMarker)) render_tool_marker(view_matrix, projection_matrix); if (m_settings.options_visibility.at(EOptionType::CenterOfGravity)) render_cog_marker(view_matrix, projection_matrix); -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS } void ViewerImpl::set_view_type(EViewType type) @@ -1220,7 +1220,7 @@ void ViewerImpl::render_options(const Mat4x4& view_matrix, const Mat4x4& project glsafe(glActiveTexture(curr_active_texture)); } -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS void ViewerImpl::render_cog_marker(const Mat4x4& view_matrix, const Mat4x4& projection_matrix) { if (m_cog_marker_shader_id == 0) @@ -1299,6 +1299,6 @@ void ViewerImpl::render_tool_marker(const Mat4x4& view_matrix, const Mat4x4& pro glsafe(glUseProgram(curr_shader)); } -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS } // namespace libvgcode diff --git a/src/libvgcode/src/ViewerImpl.hpp b/src/libvgcode/src/ViewerImpl.hpp index 84eace1bd7..a7c38b5f68 100644 --- a/src/libvgcode/src/ViewerImpl.hpp +++ b/src/libvgcode/src/ViewerImpl.hpp @@ -8,10 +8,10 @@ #include "Settings.hpp" #include "SegmentTemplate.hpp" #include "OptionTemplate.hpp" -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS #include "CogMarker.hpp" #include "ToolMarker.hpp" -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS #include "../include/PathVertex.hpp" #include "../include/ColorRange.hpp" #include "Bitset.hpp" @@ -160,7 +160,7 @@ public: float get_wipes_radius() const { return m_wipes_radius; } void set_wipes_radius(float radius); -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS Vec3 get_cog_marker_position() const { return m_cog_marker.get_position(); } float get_cog_marker_scale_factor() const { return m_cog_marker_scale_factor; } @@ -183,7 +183,7 @@ public: float get_tool_marker_alpha() const { return m_tool_marker.get_alpha(); } void set_tool_marker_alpha(float alpha) { m_tool_marker.set_alpha(alpha); } -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS private: Settings m_settings; @@ -212,7 +212,7 @@ private: // OptionTemplate m_option_template; -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS // // The OpenGL element used to represent the center of gravity // @@ -224,7 +224,7 @@ private: // ToolMarker m_tool_marker; float m_tool_marker_scale_factor{ 1.0f }; -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS // // cpu buffer to store vertices @@ -259,10 +259,10 @@ private: // unsigned int m_segments_shader_id{ 0 }; unsigned int m_options_shader_id{ 0 }; -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS unsigned int m_cog_marker_shader_id{ 0 }; unsigned int m_tool_marker_shader_id{ 0 }; -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS // // Cache for OpenGL uniforms id for segments shader @@ -285,7 +285,7 @@ private: int m_uni_options_colors_tex_id{ -1 }; int m_uni_options_segment_index_tex_id{ -1 }; -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS // // Cache for OpenGL uniforms id for cog marker shader // @@ -302,7 +302,7 @@ private: int m_uni_tool_marker_view_matrix{ -1 }; int m_uni_tool_marker_projection_matrix{ -1 }; int m_uni_tool_marker_color_base{ -1 }; -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS // // gpu buffers to store positions @@ -335,10 +335,10 @@ private: void update_heights_widths(); void render_segments(const Mat4x4& view_matrix, const Mat4x4& projection_matrix, const Vec3& camera_position); void render_options(const Mat4x4& view_matrix, const Mat4x4& projection_matrix); -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS void render_cog_marker(const Mat4x4& view_matrix, const Mat4x4& projection_matrix); void render_tool_marker(const Mat4x4& view_matrix, const Mat4x4& projection_matrix); -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS // // Palette used to render extrusion moves by extrusion roles diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index a38e5e5c68..f618ceed2e 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -193,11 +193,11 @@ void GCodeViewer::TBuffer::add_path(const GCodeProcessorResult::MoveVertex& move #endif // !ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS -void GCodeViewer::COG::render() -#else +#if ENABLE_COG_AND_TOOL_MARKERS void GCodeViewer::COG::render(bool fixed_screen_size) -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#else +void GCodeViewer::COG::render() +#endif // ENABLE_COG_AND_TOOL_MARKERS #else void GCodeViewer::COG::render() #endif // ENABLE_NEW_GCODE_VIEWER @@ -206,12 +206,12 @@ void GCodeViewer::COG::render() return; #if ENABLE_NEW_GCODE_VIEWER -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - init(); -#else +#if ENABLE_COG_AND_TOOL_MARKERS fixed_screen_size = true; init(fixed_screen_size); -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#else + init(); +#endif // ENABLE_COG_AND_TOOL_MARKERS #else init(); #endif // ENABLE_NEW_GCODE_VIEWER @@ -227,11 +227,11 @@ void GCodeViewer::COG::render() const Camera& camera = wxGetApp().plater()->get_camera(); Transform3d model_matrix = Geometry::translation_transform(cog()) * Geometry::scale_transform(m_scale_factor); #if ENABLE_NEW_GCODE_VIEWER -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - if (m_fixed_screen_size) { -#else +#if ENABLE_COG_AND_TOOL_MARKERS if (fixed_screen_size) { -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#else + if (m_fixed_screen_size) { +#endif // ENABLE_COG_AND_TOOL_MARKERS #else if (m_fixed_screen_size) { #endif // ENABLE_NEW_GCODE_VIEWER @@ -916,9 +916,9 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, s #if ENABLE_NEW_GCODE_VIEWER void GCodeViewer::SequentialView::render(float legend_height, const libvgcode::Viewer* viewer, uint32_t gcode_id) { -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS if (viewer == nullptr) -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS marker.render(); marker.render_position_window(viewer); #else @@ -1151,7 +1151,7 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const m_viewer.reset_default_extrusion_roles_colors(); m_viewer.load(std::move(data)); -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if !ENABLE_COG_AND_TOOL_MARKERS const size_t vertices_count = m_viewer.get_vertices_count(); m_cog.reset(); for (size_t i = 1; i < vertices_count; ++i) { @@ -1167,7 +1167,7 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const m_cog.add_segment(curr_pos, prev_pos, curr.volumetric_rate / curr.feedrate * (curr_pos - prev_pos).norm()); } } -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // !ENABLE_COG_AND_TOOL_MARKERS const libvgcode::AABox bbox = m_viewer.get_bounding_box(wxGetApp().is_gcode_viewer() ? libvgcode::EBBoxType::Full : libvgcode::EBBoxType::ExtrusionNoCustom); m_paths_bounding_box.min = libvgcode::convert(bbox[0]).cast(); @@ -1492,7 +1492,7 @@ void GCodeViewer::render() #endif // !ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS if (is_legend_shown()) { ImGuiWrapper& imgui = *Slic3r::GUI::wxGetApp().imgui(); const Size cnv_size = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size(); @@ -1525,7 +1525,7 @@ void GCodeViewer::render() imgui.end(); } -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS #endif // ENABLE_NEW_GCODE_VIEWER } @@ -3853,12 +3853,12 @@ void GCodeViewer::render_toolpaths() const Camera& camera = wxGetApp().plater()->get_camera(); libvgcode::Mat4x4 converted_view_matrix = libvgcode::convert(static_cast(camera.get_view_matrix().matrix().cast())); libvgcode::Mat4x4 converted_projetion_matrix = libvgcode::convert(static_cast(camera.get_projection_matrix().matrix().cast())); -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS m_viewer.set_cog_marker_scale_factor(m_cog_marker_fixed_screen_size ? 10.0f * m_cog_marker_size * camera.get_inv_zoom() : m_cog_marker_size); m_viewer.enable_tool_marker(m_viewer.get_view_enabled_range()[1] != m_viewer.get_view_visible_range()[1]); m_viewer.set_tool_marker_position(m_viewer.get_current_vertex().position); m_viewer.set_tool_marker_scale_factor(m_tool_marker_fixed_screen_size ? 10.0f * m_tool_marker_size * camera.get_inv_zoom() : m_tool_marker_size); -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS m_viewer.render(converted_view_matrix, converted_projetion_matrix); #if ENABLE_NEW_GCODE_VIEWER_DEBUG @@ -3949,7 +3949,7 @@ void GCodeViewer::render_toolpaths() ImGui::EndTable(); -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS ImGui::Separator(); if (ImGui::BeginTable("Cog", 2)) { @@ -4001,7 +4001,7 @@ void GCodeViewer::render_toolpaths() ImGui::EndTable(); } -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS } ImGui::Separator(); @@ -5566,7 +5566,9 @@ void GCodeViewer::render_legend(float& legend_height) std::function draw_callback) { #if ENABLE_NEW_GCODE_VIEWER bool active = false; -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS + active = (type == Preview::OptionType::Shells) ? m_shells.visible : m_viewer.is_option_visible(libvgcode::convert(type)); +#else switch (type) { case Preview::OptionType::CenterOfGravity: { active = m_cog.is_visible(); break; } @@ -5574,9 +5576,7 @@ void GCodeViewer::render_legend(float& legend_height) case Preview::OptionType::Shells: { active = m_shells.visible; break; } default: { active = m_viewer.is_option_visible(libvgcode::convert(type)); break; } } -#else - active = (type == Preview::OptionType::Shells) ? m_shells.visible : m_viewer.is_option_visible(libvgcode::convert(type)); -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS #else auto is_flag_set = [](unsigned int flags, unsigned int flag) { return (flags & (1 << flag)) != 0; @@ -5596,28 +5596,28 @@ void GCodeViewer::render_legend(float& legend_height) const libvgcode::Interval& view_visible_range = m_viewer.get_view_visible_range(); const libvgcode::Interval& view_enabled_range = m_viewer.get_view_enabled_range(); bool keep_visible_range = false; -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - switch (type) - { - case Preview::OptionType::CenterOfGravity: { m_cog.set_visible(!active); break; } - case Preview::OptionType::ToolMarker: { m_sequential_view.marker.set_visible(!active); break; } - case Preview::OptionType::Shells: { m_shells.visible = !active; break; } - default: { - m_viewer.toggle_option_visibility(libvgcode::convert(type)); - if (view_visible_range != view_enabled_range) - keep_visible_range = true; - break; - } - } +#if ENABLE_COG_AND_TOOL_MARKERS + if (type == Preview::OptionType::Shells) + m_shells.visible = !active; + else { + m_viewer.toggle_option_visibility(libvgcode::convert(type)); + if (view_visible_range != view_enabled_range) + keep_visible_range = true; + } #else - if (type == Preview::OptionType::Shells) - m_shells.visible = !active; - else { - m_viewer.toggle_option_visibility(libvgcode::convert(type)); - if (view_visible_range != view_enabled_range) - keep_visible_range = true; - } -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS + switch (type) + { + case Preview::OptionType::CenterOfGravity: { m_cog.set_visible(!active); break; } + case Preview::OptionType::ToolMarker: { m_sequential_view.marker.set_visible(!active); break; } + case Preview::OptionType::Shells: { m_shells.visible = !active; break; } + default: { + m_viewer.toggle_option_visibility(libvgcode::convert(type)); + if (view_visible_range != view_enabled_range) + keep_visible_range = true; + break; + } + } +#endif // ENABLE_COG_AND_TOOL_MARKERS std::optional view_visible_range_min; std::optional view_visible_range_max; if (keep_visible_range) { diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 7360e05d01..831ad45e9b 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -14,7 +14,7 @@ #if ENABLE_NEW_GCODE_VIEWER #include "LibVGCode/LibVGCodeWrapper.hpp" -// needed for tech ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +// needed for tech ENABLE_COG_AND_TOOL_MARKERS #include "LibVGCode/include/Types.hpp" #endif // ENABLE_NEW_GCODE_VIEWER @@ -399,10 +399,10 @@ class GCodeViewer GLModel m_model; bool m_visible{ false }; #if ENABLE_NEW_GCODE_VIEWER -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if !ENABLE_COG_AND_TOOL_MARKERS // whether or not to render the model with fixed screen size bool m_fixed_screen_size{ true }; -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // !ENABLE_COG_AND_TOOL_MARKERS #else // whether or not to render the model with fixed screen size bool m_fixed_screen_size{ true }; @@ -413,11 +413,11 @@ class GCodeViewer public: #if ENABLE_NEW_GCODE_VIEWER -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - void render(); -#else - void render(bool fixed_screen_size); -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS + void render(bool fixed_screen_size); +#else + void render(); +#endif // ENABLE_COG_AND_TOOL_MARKERS #else void render(); #endif // ENABLE_NEW_GCODE_VIEWER @@ -447,11 +447,11 @@ class GCodeViewer private: #if ENABLE_NEW_GCODE_VIEWER -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - void init() { -#else +#if ENABLE_COG_AND_TOOL_MARKERS void init(bool fixed_screen_size) { -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#else + void init() { +#endif // ENABLE_COG_AND_TOOL_MARKERS #else void init() { #endif // ENABLE_NEW_GCODE_VIEWER @@ -459,11 +459,11 @@ class GCodeViewer return; #if ENABLE_NEW_GCODE_VIEWER -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - const float radius = m_fixed_screen_size ? 10.0f : 1.0f; -#else +#if ENABLE_COG_AND_TOOL_MARKERS const float radius = fixed_screen_size ? 10.0f : 1.0f; -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#else + const float radius = m_fixed_screen_size ? 10.0f : 1.0f; +#endif // ENABLE_COG_AND_TOOL_MARKERS #else const float radius = m_fixed_screen_size ? 10.0f : 1.0f; #endif // ENABLE_NEW_GCODE_VIEWER @@ -857,13 +857,13 @@ private: Shells m_shells; COG m_cog; #if ENABLE_NEW_GCODE_VIEWER -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS // whether or not to render the cog model with fixed screen size bool m_cog_marker_fixed_screen_size{ true }; float m_cog_marker_size{ 1.0f }; bool m_tool_marker_fixed_screen_size{ false }; float m_tool_marker_size{ 1.0f }; -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS bool m_legend_visible{ true }; bool m_legend_enabled{ true }; #else @@ -919,11 +919,11 @@ public: void reset(); void render(); #if ENABLE_NEW_GCODE_VIEWER -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - void render_cog() { m_cog.render(); } -#else +#if ENABLE_COG_AND_TOOL_MARKERS void render_cog() { m_cog.render(m_cog_marker_fixed_screen_size); } -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#else + void render_cog() { m_cog.render(); } +#endif // ENABLE_COG_AND_TOOL_MARKERS bool has_data() const { return !m_viewer.get_extrusion_roles().empty(); } #else void render_cog() { m_cog.render(); } @@ -1018,10 +1018,10 @@ public: void load_shells(const Print& print); #if ENABLE_NEW_GCODE_VIEWER -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#if ENABLE_COG_AND_TOOL_MARKERS float get_cog_marker_scale_factor() const { return m_viewer.get_cog_marker_scale_factor(); } void set_cog_marker_scale_factor(float factor) { return m_viewer.set_cog_marker_scale_factor(factor); } -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#endif // ENABLE_COG_AND_TOOL_MARKERS #endif // ENABLE_NEW_GCODE_VIEWER private: diff --git a/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp b/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp index f5842e5017..b002296957 100644 --- a/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp +++ b/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp @@ -116,13 +116,13 @@ EOptionType convert(const Slic3r::GUI::Preview::OptionType& type) case Slic3r::GUI::Preview::OptionType::ColorChanges: { return EOptionType::ColorChanges; } case Slic3r::GUI::Preview::OptionType::PausePrints: { return EOptionType::PausePrints; } case Slic3r::GUI::Preview::OptionType::CustomGCodes: { return EOptionType::CustomGCodes; } -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - case Slic3r::GUI::Preview::OptionType::CenterOfGravity: { return EOptionType::COUNT; } - case Slic3r::GUI::Preview::OptionType::ToolMarker: { return EOptionType::COUNT; } -#else +#if ENABLE_COG_AND_TOOL_MARKERS case Slic3r::GUI::Preview::OptionType::CenterOfGravity: { return EOptionType::CenterOfGravity; } case Slic3r::GUI::Preview::OptionType::ToolMarker: { return EOptionType::ToolMarker; } -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#else + case Slic3r::GUI::Preview::OptionType::CenterOfGravity: { return EOptionType::COUNT; } + case Slic3r::GUI::Preview::OptionType::ToolMarker: { return EOptionType::COUNT; } +#endif // ENABLE_COG_AND_TOOL_MARKERS default: { return EOptionType::COUNT; } } } @@ -197,31 +197,31 @@ GCodeInputData convert(const Slic3r::GCodeProcessorResult& result, float travels // to allow libvgcode to properly detect the start/end of a path we need to add a 'phantom' vertex // equal to the current one with the exception of the position, which should match the previous move position, // and the times, which are set to zero -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, curr.fan_speed, - curr.temperature, curr.volumetric_rate(), extrusion_role, curr_type, - static_cast(curr.gcode_id), static_cast(curr.layer_id), - static_cast(curr.extruder_id), static_cast(curr.cp_color_id), { 0.0f, 0.0f } }; -#else +#if ENABLE_COG_AND_TOOL_MARKERS const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, curr.fan_speed, curr.temperature, curr.volumetric_rate(), 0.0f, extrusion_role, curr_type, static_cast(curr.gcode_id), static_cast(curr.layer_id), static_cast(curr.extruder_id), static_cast(curr.cp_color_id), { 0.0f, 0.0f } }; -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#else + const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, curr.fan_speed, + curr.temperature, curr.volumetric_rate(), extrusion_role, curr_type, + static_cast(curr.gcode_id), static_cast(curr.layer_id), + static_cast(curr.extruder_id), static_cast(curr.cp_color_id), { 0.0f, 0.0f } }; +#endif // ENABLE_COG_AND_TOOL_MARKERS ret.vertices.emplace_back(vertex); } } -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.fan_speed, - curr.temperature, curr.volumetric_rate(), extrusion_role, curr_type, static_cast(curr.gcode_id), - static_cast(curr.layer_id), static_cast(curr.extruder_id), static_cast(curr.cp_color_id), curr.time }; -#else +#if ENABLE_COG_AND_TOOL_MARKERS const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.fan_speed, curr.temperature, curr.volumetric_rate(), curr.mm3_per_mm * (curr.position - prev.position).norm(), extrusion_role, curr_type, static_cast(curr.gcode_id), static_cast(curr.layer_id), static_cast(curr.extruder_id), static_cast(curr.cp_color_id), curr.time }; -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#else + const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.fan_speed, + curr.temperature, curr.volumetric_rate(), extrusion_role, curr_type, static_cast(curr.gcode_id), + static_cast(curr.layer_id), static_cast(curr.extruder_id), static_cast(curr.cp_color_id), curr.time }; +#endif // ENABLE_COG_AND_TOOL_MARKERS ret.vertices.emplace_back(vertex); } ret.vertices.shrink_to_fit(); @@ -246,15 +246,15 @@ static void convert_lines_to_vertices(const Slic3r::Lines& lines, const std::vec if (ii == 0) { // add a dummy vertex at the start, to separate the current line from the others const Slic3r::Vec2f a = unscale(line.a).cast(); -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(a.x(), a.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f, - 0.0f, 0.0f, extrusion_role, EMoveType::Noop, 0, static_cast(layer_id), - static_cast(extruder_id), static_cast(color_id), { 0.0f, 0.0f } }; -#else +#if ENABLE_COG_AND_TOOL_MARKERS libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(a.x(), a.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, extrusion_role, EMoveType::Noop, 0, static_cast(layer_id), static_cast(extruder_id), static_cast(color_id), { 0.0f, 0.0f } }; -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#else + libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(a.x(), a.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f, + 0.0f, 0.0f, extrusion_role, EMoveType::Noop, 0, static_cast(layer_id), + static_cast(extruder_id), static_cast(color_id), { 0.0f, 0.0f } }; +#endif // ENABLE_COG_AND_TOOL_MARKERS vertices.emplace_back(vertex); // add the starting vertex of the segment vertex.type = EMoveType::Extrude; @@ -262,15 +262,15 @@ static void convert_lines_to_vertices(const Slic3r::Lines& lines, const std::vec } // add the ending vertex of the segment const Slic3r::Vec2f b = unscale(line.b).cast(); -#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - const libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(b.x(), b.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f, - 0.0f, 0.0f, extrusion_role, EMoveType::Extrude, 0, static_cast(layer_id), - static_cast(extruder_id), static_cast(color_id), { 0.0f, 0.0f } }; -#else +#if ENABLE_COG_AND_TOOL_MARKERS const libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(b.x(), b.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, extrusion_role, EMoveType::Extrude, 0, static_cast(layer_id), static_cast(extruder_id), static_cast(color_id), { 0.0f, 0.0f } }; -#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS +#else + const libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(b.x(), b.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f, + 0.0f, 0.0f, extrusion_role, EMoveType::Extrude, 0, static_cast(layer_id), + static_cast(extruder_id), static_cast(color_id), { 0.0f, 0.0f } }; +#endif // ENABLE_COG_AND_TOOL_MARKERS vertices.emplace_back(vertex); } }