diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 9d5d30e01e..e94637f176 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -268,10 +268,6 @@ static GCodeInputData convert(const Slic3r::GCodeProcessorResult& result) } ret.vertices.shrink_to_fit(); - for (size_t i = 0; i < static_cast(Slic3r::PrintEstimatedStatistics::ETimeMode::Count); ++i) { - ret.times[static_cast(convert(static_cast(i)))] = result.print_statistics.modes[i].time; - } - return ret; } @@ -1484,7 +1480,15 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr m_print_statistics = gcode_result.print_statistics; //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -#if !ENABLE_NEW_GCODE_VIEWER +#if ENABLE_NEW_GCODE_VIEWER + PrintEstimatedStatistics::ETimeMode time_mode = convert(m_new_viewer.get_time_mode()); + if (m_new_viewer.get_time_mode() != libvgcode::ETimeMode::Normal) { + const float time = m_print_statistics.modes[static_cast(time_mode)].time; + if (time == 0.0f || + short_time(get_time_dhms(time)) == short_time(get_time_dhms(m_print_statistics.modes[static_cast(PrintEstimatedStatistics::ETimeMode::Normal)].time))) + m_new_viewer.set_time_mode(libvgcode::convert(PrintEstimatedStatistics::ETimeMode::Normal)); + } +#else //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ if (m_time_estimate_mode != PrintEstimatedStatistics::ETimeMode::Normal) { const float time = m_print_statistics.modes[static_cast(m_time_estimate_mode)].time; @@ -1493,7 +1497,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr m_time_estimate_mode = PrintEstimatedStatistics::ETimeMode::Normal; } //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -#endif // !ENABLE_NEW_GCODE_VIEWER +#endif // ENABLE_NEW_GCODE_VIEWER //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ m_conflict_result = gcode_result.conflict_result; @@ -1705,19 +1709,8 @@ void GCodeViewer::render() //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #if ENABLE_NEW_GCODE_VIEWER - if (m_use_new_viewer) { - 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 - libvgcode::Vec3 converted_tool_marker_position = libvgcode::convert(m_sequential_view.current_position); - m_new_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_new_viewer.enable_tool_marker(m_sequential_view.current.last != m_sequential_view.endpoints.last); - m_new_viewer.set_tool_marker_position(converted_tool_marker_position); - m_new_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 - m_new_viewer.render(converted_view_matrix, converted_projetion_matrix); - } + if (m_use_new_viewer) + render_new_toolpaths(); else #endif // ENABLE_NEW_GCODE_VIEWER //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ -3902,6 +3895,151 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool #endif // ENABLE_GCODE_VIEWER_STATISTICS } +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#if ENABLE_NEW_GCODE_VIEWER +void GCodeViewer::render_new_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 + libvgcode::Vec3 converted_tool_marker_position = libvgcode::convert(m_sequential_view.current_position); + m_new_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_new_viewer.enable_tool_marker(m_sequential_view.current.last != m_sequential_view.endpoints.last); + m_new_viewer.set_tool_marker_position(converted_tool_marker_position); + m_new_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 + m_new_viewer.render(converted_view_matrix, converted_projetion_matrix); + +#if ENABLE_NEW_GCODE_VIEWER_DEBUG + Slic3r::GUI::ImGuiWrapper& imgui = *Slic3r::GUI::wxGetApp().imgui(); + imgui.begin(std::string("LibVGCode Viewer Debug"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); + + if (ImGui::BeginTable("Data", 2)) { + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# vertices"); + ImGui::TableSetColumnIndex(1); + imgui.text(std::to_string(m_new_viewer.get_vertices_count())); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# enabled lines"); + ImGui::TableSetColumnIndex(1); + const std::array& enabled_segments_range = m_new_viewer.get_enabled_segments_range(); + imgui.text(std::to_string(m_new_viewer.get_enabled_segments_count()) + " [" + std::to_string(enabled_segments_range[0]) + + "-" + std::to_string(enabled_segments_range[1]) + "]"); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# enabled options"); + ImGui::TableSetColumnIndex(1); + const std::array& enabled_options_range = m_new_viewer.get_enabled_options_range(); + imgui.text(std::to_string(m_new_viewer.get_enabled_options_count()) + " [" + std::to_string(enabled_options_range[0]) + + "-" + std::to_string(enabled_options_range[1]) + "]"); + + ImGui::Separator(); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "layers range"); + ImGui::TableSetColumnIndex(1); + const std::array& layers_range = m_new_viewer.get_layers_range(); + imgui.text(std::to_string(layers_range[0]) + " - " + std::to_string(layers_range[1])); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (current)"); + ImGui::TableSetColumnIndex(1); + const std::array& current_view_range = m_new_viewer.get_view_current_range(); + imgui.text(std::to_string(current_view_range[0]) + " - " + std::to_string(current_view_range[1])); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (global)"); + ImGui::TableSetColumnIndex(1); + const std::array& global_view_range = m_new_viewer.get_view_global_range(); + imgui.text(std::to_string(global_view_range[0]) + " - " + std::to_string(global_view_range[1])); + + auto add_range_property_row = [&imgui](const std::string& label, const std::array& range) { + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, label); + ImGui::TableSetColumnIndex(1); + char buf[64]; + sprintf(buf, "%.3f - %.3f", range[0], range[1]); + imgui.text(buf); + }; + + add_range_property_row("height range", m_new_viewer.get_height_range()); + add_range_property_row("width range", m_new_viewer.get_width_range()); + add_range_property_row("speed range", m_new_viewer.get_speed_range()); + add_range_property_row("fan speed range", m_new_viewer.get_fan_speed_range()); + add_range_property_row("temperature range", m_new_viewer.get_temperature_range()); + add_range_property_row("volumetric rate range", m_new_viewer.get_volumetric_rate_range()); + add_range_property_row("layer time linear range", m_new_viewer.get_layer_time_range(libvgcode::ColorRange::EType::Linear)); + add_range_property_row("layer time logarithmic range", m_new_viewer.get_layer_time_range(libvgcode::ColorRange::EType::Logarithmic)); + + ImGui::EndTable(); + +#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS + ImGui::Separator(); + + if (ImGui::BeginTable("Cog", 2)) { + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Cog marker scale factor"); + ImGui::TableSetColumnIndex(1); + imgui.text(std::to_string(get_cog_marker_scale_factor())); + + ImGui::EndTable(); + } + + ImGui::Separator(); + + if (ImGui::BeginTable("Tool", 2)) { + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker scale factor"); + ImGui::TableSetColumnIndex(1); + imgui.text(std::to_string(m_new_viewer.get_tool_marker_scale_factor())); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker z offset"); + ImGui::TableSetColumnIndex(1); + float tool_z_offset = m_new_viewer.get_tool_marker_offset_z(); + if (imgui.slider_float("##ToolZOffset", &tool_z_offset, 0.0f, 1.0f)) + m_new_viewer.set_tool_marker_offset_z(tool_z_offset); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker color"); + ImGui::TableSetColumnIndex(1); + libvgcode::Color color = m_new_viewer.get_tool_marker_color(); + if (ImGui::ColorPicker3("##ToolColor", color.data())) + m_new_viewer.set_tool_marker_color(color); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker alpha"); + ImGui::TableSetColumnIndex(1); + float tool_alpha = m_new_viewer.get_tool_marker_alpha(); + if (imgui.slider_float("##ToolAlpha", &tool_alpha, 0.25f, 0.75f)) + m_new_viewer.set_tool_marker_alpha(tool_alpha); + + ImGui::EndTable(); + } +#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS + } + + imgui.end(); +#endif // ENABLE_NEW_GCODE_VIEWER_DEBUG +} +#endif // ENABLE_NEW_GCODE_VIEWER +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + void GCodeViewer::render_toolpaths() { const Camera& camera = wxGetApp().plater()->get_camera(); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 9ef29dea22..fa24764f76 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -1120,6 +1120,11 @@ public: private: void load_toolpaths(const GCodeProcessorResult& gcode_result); void load_wipetower_shell(const Print& print); +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#if ENABLE_NEW_GCODE_VIEWER + void render_new_toolpaths(); +#endif // ENABLE_NEW_GCODE_VIEWER +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void render_toolpaths(); void render_shells(); void render_legend(float& legend_height); diff --git a/src/slic3r/GUI/LibVGCode/ColorRange.cpp b/src/slic3r/GUI/LibVGCode/ColorRange.cpp index 8dc94a0cc3..dcbbc29d75 100644 --- a/src/slic3r/GUI/LibVGCode/ColorRange.cpp +++ b/src/slic3r/GUI/LibVGCode/ColorRange.cpp @@ -26,9 +26,6 @@ ColorRange::ColorRange(EType type) void ColorRange::update(float value) { - if (std::abs(value - m_range[0]) > 0.001 && std::abs(value - m_range[1]) > 0.001) - ++m_count; - m_range[0] = std::min(m_range[0], value); m_range[1] = std::max(m_range[1], value); } @@ -36,7 +33,6 @@ void ColorRange::update(float value) void ColorRange::reset() { m_range = { FLT_MAX, -FLT_MAX }; - m_count = 0; } static float step_size(const std::array& range, ColorRange::EType type) @@ -85,17 +81,10 @@ Color ColorRange::get_color_at(float value) const return lerp(Ranges_Colors[color_low_idx], Ranges_Colors[color_high_idx], global_t - static_cast(color_low_idx)); } -unsigned int ColorRange::get_count() const -{ - return m_count; -} - -#if ENABLE_NEW_GCODE_VIEWER_DEBUG const std::array& ColorRange::get_range() const { return m_range; } -#endif // ENABLE_NEW_GCODE_VIEWER_DEBUG } // namespace libvgcode diff --git a/src/slic3r/GUI/LibVGCode/ColorRange.hpp b/src/slic3r/GUI/LibVGCode/ColorRange.hpp index 552508b6a9..8b33ea4453 100644 --- a/src/slic3r/GUI/LibVGCode/ColorRange.hpp +++ b/src/slic3r/GUI/LibVGCode/ColorRange.hpp @@ -14,11 +14,10 @@ namespace libvgcode { -// Alias for GCodeViewer::Extrusion::Range class ColorRange { public: - enum class EType : unsigned char + enum class EType : uint8_t { Linear, Logarithmic, @@ -32,20 +31,17 @@ public: EType get_type() const; Color get_color_at(float value) const; - unsigned int get_count() const; -#if ENABLE_NEW_GCODE_VIEWER_DEBUG const std::array& get_range() const; -#endif // ENABLE_NEW_GCODE_VIEWER_DEBUG private: EType m_type{ EType::Linear }; // [0] = min, [1] = max std::array m_range{ FLT_MAX, -FLT_MAX }; - // updates counter - unsigned int m_count{ 0 }; }; +static constexpr size_t Color_Range_Types_Count = static_cast(ColorRange::EType::COUNT); + } // namespace libvgcode //################################################################################################################################ diff --git a/src/slic3r/GUI/LibVGCode/GCodeInputData.hpp b/src/slic3r/GUI/LibVGCode/GCodeInputData.hpp index 67a63359c1..e973e735c8 100644 --- a/src/slic3r/GUI/LibVGCode/GCodeInputData.hpp +++ b/src/slic3r/GUI/LibVGCode/GCodeInputData.hpp @@ -20,11 +20,6 @@ struct GCodeInputData // List of path vertices // std::vector vertices; - - // - // Total time for each time mode - // - std::array times{ 0.0f, 0.0f }; }; } // namespace libvgcode diff --git a/src/slic3r/GUI/LibVGCode/Layers.cpp b/src/slic3r/GUI/LibVGCode/Layers.cpp index 6940f51bce..24f983fe3e 100644 --- a/src/slic3r/GUI/LibVGCode/Layers.cpp +++ b/src/slic3r/GUI/LibVGCode/Layers.cpp @@ -49,6 +49,7 @@ void Layers::update(const PathVertex& vertex, uint32_t vertex_id) void Layers::reset() { m_items.clear(); + m_view_range.reset(); } bool Layers::empty() const @@ -79,6 +80,21 @@ std::vector Layers::get_times(ETimeMode mode) const return ret; } +const std::array& Layers::get_view_range() const +{ + return m_view_range.get(); +} + +void Layers::set_view_range(const std::array& range) +{ + set_view_range(range[0], range[1]); +} + +void Layers::set_view_range(uint32_t min, uint32_t max) +{ + m_view_range.set(min, max); +} + bool Layers::layer_contains_colorprint_options(uint32_t layer_id) const { return (layer_id < static_cast(m_items.size())) ? m_items[layer_id].contains_colorprint_options : false; diff --git a/src/slic3r/GUI/LibVGCode/Layers.hpp b/src/slic3r/GUI/LibVGCode/Layers.hpp index fca2094b8f..ab91ca8af2 100644 --- a/src/slic3r/GUI/LibVGCode/Layers.hpp +++ b/src/slic3r/GUI/LibVGCode/Layers.hpp @@ -29,6 +29,10 @@ public: float get_time(ETimeMode mode, uint32_t layer_id) const; std::vector get_times(ETimeMode mode) const; + const std::array& get_view_range() const; + void set_view_range(const std::array& range); + void set_view_range(uint32_t min, uint32_t max); + bool layer_contains_colorprint_options(uint32_t layer_id) const; private: @@ -40,6 +44,7 @@ private: }; std::vector m_items; + Range m_view_range; }; } // namespace libvgcode diff --git a/src/slic3r/GUI/LibVGCode/Viewer.cpp b/src/slic3r/GUI/LibVGCode/Viewer.cpp index c4bbe16d1d..713c62cc1e 100644 --- a/src/slic3r/GUI/LibVGCode/Viewer.cpp +++ b/src/slic3r/GUI/LibVGCode/Viewer.cpp @@ -131,6 +131,26 @@ PathVertex Viewer::get_vertex_at(uint32_t id) const return m_impl.get_vertex_at(id); } +size_t Viewer::get_enabled_segments_count() const +{ + return m_impl.get_enabled_segments_count(); +} + +const std::array& Viewer::get_enabled_segments_range() const +{ + return m_impl.get_enabled_segments_range(); +} + +size_t Viewer::get_enabled_options_count() const +{ + return m_impl.get_enabled_options_count(); +} + +const std::array& Viewer::get_enabled_options_range() const +{ + return m_impl.get_enabled_options_range(); +} + uint32_t Viewer::get_extrusion_roles_count() const { return m_impl.get_extrusion_roles_count(); @@ -186,6 +206,41 @@ void Viewer::set_tool_colors(const std::vector& colors) m_impl.set_tool_colors(colors); } +const std::array& Viewer::get_height_range() const +{ + return m_impl.get_height_range(); +} + +const std::array& Viewer::get_width_range() const +{ + return m_impl.get_width_range(); +} + +const std::array& Viewer::get_speed_range() const +{ + return m_impl.get_speed_range(); +} + +const std::array& Viewer::get_fan_speed_range() const +{ + return m_impl.get_fan_speed_range(); +} + +const std::array& Viewer::get_temperature_range() const +{ + return m_impl.get_temperature_range(); +} + +const std::array& Viewer::get_volumetric_rate_range() const +{ + return m_impl.get_volumetric_rate_range(); +} + +std::array Viewer::get_layer_time_range(ColorRange::EType type) const +{ + return m_impl.get_layer_time_range(type); +} + #if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS Vec3 Viewer::get_cog_position() const { @@ -222,6 +277,16 @@ void Viewer::set_tool_marker_position(const Vec3& position) m_impl.set_tool_marker_position(position); } +float Viewer::get_tool_marker_offset_z() const +{ + return m_impl.get_tool_marker_offset_z(); +} + +void Viewer::set_tool_marker_offset_z(float offset_z) +{ + m_impl.set_tool_marker_offset_z(offset_z); +} + float Viewer::get_tool_marker_scale_factor() const { return m_impl.get_tool_marker_scale_factor(); diff --git a/src/slic3r/GUI/LibVGCode/Viewer.hpp b/src/slic3r/GUI/LibVGCode/Viewer.hpp index 32c005dbc7..81279a9cb8 100644 --- a/src/slic3r/GUI/LibVGCode/Viewer.hpp +++ b/src/slic3r/GUI/LibVGCode/Viewer.hpp @@ -62,42 +62,66 @@ public: // Return the count of vertices used to render the toolpaths // uint32_t get_vertices_count() const; + // // Return the vertex pointed by the max value of the view current range // PathVertex get_current_vertex() const; + // // Return the vertex at the given index // PathVertex get_vertex_at(uint32_t id) const; + + // + // Return the count of path segments enabled for rendering + // + size_t get_enabled_segments_count() const; + + const std::array& get_enabled_segments_range() const; + + // + // Return the count of options enabled for rendering + // + size_t get_enabled_options_count() const; + + const std::array& get_enabled_options_range() const; + // // Return the count of detected extrusion roles // uint32_t get_extrusion_roles_count() const; + // // Return the list of detected extrusion roles // std::vector get_extrusion_roles() const; + // // Return the estimated time for the given role and the current time mode // float get_extrusion_role_time(EGCodeExtrusionRole role) const; + // // Return the estimated time for the given role and the given time mode // float get_extrusion_role_time(EGCodeExtrusionRole role, ETimeMode mode) const; + // // Return the estimated time for the travel moves and the current time mode // float get_travels_time() const; + // // Return the estimated time for the travel moves and the given time mode // float get_travels_time(ETimeMode mode) const; + // // Return the list of layers time for the current time mode // std::vector get_layers_times() const; + // // Return the list of layers time for the given time mode // @@ -107,6 +131,14 @@ public: const std::vector& get_tool_colors() const; void set_tool_colors(const std::vector& colors); + const std::array& get_height_range() const; + const std::array& get_width_range() const; + const std::array& get_speed_range() const; + const std::array& get_fan_speed_range() const; + const std::array& get_temperature_range() const; + const std::array& get_volumetric_rate_range() const; + std::array get_layer_time_range(ColorRange::EType type) const; + #if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS // // Returns the position of the center of gravity of the toolpaths. @@ -128,6 +160,9 @@ public: const Vec3& get_tool_marker_position() const; void set_tool_marker_position(const Vec3& position); + float get_tool_marker_offset_z() const; + void set_tool_marker_offset_z(float offset_z); + float get_tool_marker_scale_factor() const; void set_tool_marker_scale_factor(float factor); diff --git a/src/slic3r/GUI/LibVGCode/ViewerImpl.cpp b/src/slic3r/GUI/LibVGCode/ViewerImpl.cpp index b23de9236e..53ed9b00e7 100644 --- a/src/slic3r/GUI/LibVGCode/ViewerImpl.cpp +++ b/src/slic3r/GUI/LibVGCode/ViewerImpl.cpp @@ -16,8 +16,6 @@ //################################################################################################################################ // PrusaSlicer development only -> !!!TO BE REMOVED!!! #if ENABLE_NEW_GCODE_VIEWER -#include "slic3r/GUI/GUI_App.hpp" -#include "slic3r/GUI/ImGuiWrapper.hpp" //################################################################################################################################ #include @@ -445,7 +443,6 @@ void ViewerImpl::init() void ViewerImpl::reset() { m_layers.reset(); - m_layers_range.reset(); m_view_range.reset(); m_extrusion_roles.reset(); m_travels_time = { 0.0f, 0.0f }; @@ -473,18 +470,6 @@ void ViewerImpl::reset() void ViewerImpl::load(GCodeInputData&& gcode_data) { - if (m_settings.time_mode != ETimeMode::Normal) { - bool force_normal_mode = static_cast(m_settings.time_mode) >= gcode_data.times.size(); - if (!force_normal_mode) { - const float normal_time = gcode_data.times[static_cast(ETimeMode::Normal)]; - const float mode_time = gcode_data.times[static_cast(m_settings.time_mode)]; - force_normal_mode = mode_time == 0.0f || - short_time(get_time_dhms(mode_time)) == short_time(get_time_dhms(normal_time)); // TO CHECK -> Is this necessary ? - } - if (force_normal_mode) - m_settings.time_mode = ETimeMode::Normal; - } - m_vertices = std::move(gcode_data.vertices); for (size_t i = 0; i < m_vertices.size(); ++i) { @@ -513,6 +498,9 @@ void ViewerImpl::load(GCodeInputData&& gcode_data) } } + if (!m_layers.empty()) + m_layers.set_view_range(0, static_cast(m_layers.count()) - 1); + // reset segments visibility bitset m_valid_lines_bitset = BitSet<>(m_vertices.size()); m_valid_lines_bitset.setAll(); @@ -648,12 +636,14 @@ void ViewerImpl::update_enabled_entities() m_enabled_segments_count = enabled_segments.size(); m_enabled_options_count = enabled_options.size(); -#if ENABLE_NEW_GCODE_VIEWER_DEBUG - m_enabled_segments_range = (m_enabled_segments_count > 0) ? - std::make_pair((uint32_t)enabled_segments.front(), (uint32_t)enabled_segments.back()) : std::make_pair((uint32_t)0, (uint32_t)0); - m_enabled_options_range = (m_enabled_options_count > 0) ? - std::make_pair((uint32_t)enabled_options.front(), (uint32_t)enabled_options.back()) : std::make_pair((uint32_t)0, (uint32_t)0); -#endif // ENABLE_NEW_GCODE_VIEWER_DEBUG + if (m_enabled_segments_count > 0) + m_enabled_segments_range.set(enabled_segments.front(), enabled_segments.back()); + else + m_enabled_segments_range.reset(); + if (m_enabled_options_count > 0) + m_enabled_options_range.set(enabled_options.front(), enabled_options.back()); + else + m_enabled_options_range.reset(); // update gpu buffer for enabled segments assert(m_enabled_segments_buf_id > 0); @@ -686,7 +676,7 @@ void ViewerImpl::update_colors() { update_color_ranges(); - const uint32_t top_layer_id = m_settings.top_layer_only_view_range ? m_layers_range.get()[1] : 0; + const uint32_t top_layer_id = m_settings.top_layer_only_view_range ? m_layers.get_view_range()[1] : 0; const bool color_top_layer_only = m_view_range.get_global()[1] != m_view_range.get_current()[1]; std::vector colors(m_vertices.size()); for (size_t i = 0; i < m_vertices.size(); i++) { @@ -728,10 +718,6 @@ void ViewerImpl::render(const Mat4x4& view_matrix, const Mat4x4& projection_matr 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 - -#if ENABLE_NEW_GCODE_VIEWER_DEBUG - render_debug_window(); -#endif // ENABLE_NEW_GCODE_VIEWER_DEBUG } EViewType ViewerImpl::get_view_type() const @@ -758,7 +744,7 @@ void ViewerImpl::set_time_mode(ETimeMode mode) const std::array& ViewerImpl::get_layers_range() const { - return m_layers_range.get(); + return m_layers.get_view_range(); } void ViewerImpl::set_layers_range(const std::array& range) @@ -768,7 +754,7 @@ void ViewerImpl::set_layers_range(const std::array& range) void ViewerImpl::set_layers_range(uint32_t min, uint32_t max) { - m_layers_range.set(min, max); + m_layers.set_view_range(min, max); m_settings.update_view_global_range = true; m_settings.update_enabled_entities = true; m_settings.update_colors = true; @@ -906,6 +892,26 @@ PathVertex ViewerImpl::get_vertex_at(size_t id) const return (id < m_vertices.size()) ? m_vertices[id] : PathVertex(); } +size_t ViewerImpl::get_enabled_segments_count() const +{ + return m_enabled_segments_count; +} + +const std::array& ViewerImpl::get_enabled_segments_range() const +{ + return m_enabled_segments_range.get(); +} + +size_t ViewerImpl::get_enabled_options_count() const +{ + return m_enabled_options_count; +} + +const std::array& ViewerImpl::get_enabled_options_range() const +{ + return m_enabled_options_range.get(); +} + std::vector ViewerImpl::get_extrusion_roles() const { return m_extrusion_roles.get_roles(); @@ -962,6 +968,46 @@ void ViewerImpl::set_tool_colors(const std::vector& colors) m_settings.update_colors = true; } +const std::array& ViewerImpl::get_height_range() const +{ + return m_height_range.get_range(); +} + +const std::array& ViewerImpl::get_width_range() const +{ + return m_width_range.get_range(); +} + +const std::array& ViewerImpl::get_speed_range() const +{ + return m_speed_range.get_range(); +} + +const std::array& ViewerImpl::get_fan_speed_range() const +{ + return m_fan_speed_range.get_range(); +} + +const std::array& ViewerImpl::get_temperature_range() const +{ + return m_temperature_range.get_range(); +} + +const std::array& ViewerImpl::get_volumetric_rate_range() const +{ + return m_volumetric_rate_range.get_range(); +} + +std::array ViewerImpl::get_layer_time_range(ColorRange::EType type) const +{ + try { + return m_layer_time_range[static_cast(type)].get_range(); + } + catch (...) { + return { 0.0f, 0.0f }; + } +} + #if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS Vec3 ViewerImpl::get_cog_marker_position() const { @@ -1059,7 +1105,7 @@ static bool is_visible(EMoveType type, const Settings& settings) void ViewerImpl::update_view_global_range() { - const std::array& layers_range = m_layers_range.get(); + const std::array& layers_range = m_layers.get_view_range(); const bool travels_visible = m_settings.options_visibility.at(EOptionType::Travels); auto first_it = m_vertices.begin(); @@ -1404,133 +1450,6 @@ void ViewerImpl::render_tool_marker(const Mat4x4& view_matrix, const Mat4x4& pro } #endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS -#if ENABLE_NEW_GCODE_VIEWER_DEBUG -void ViewerImpl::render_debug_window() -{ - Slic3r::GUI::ImGuiWrapper& imgui = *Slic3r::GUI::wxGetApp().imgui(); - imgui.begin(std::string("LibVGCode Viewer Debug"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); - - if (ImGui::BeginTable("Data", 2)) { - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# vertices"); - ImGui::TableSetColumnIndex(1); - imgui.text(std::to_string(m_vertices.size())); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# enabled lines"); - ImGui::TableSetColumnIndex(1); - imgui.text(std::to_string(m_enabled_segments_count) + " [" + std::to_string(m_enabled_segments_range.first) + "-" + std::to_string(m_enabled_segments_range.second) + "]"); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# enabled options"); - ImGui::TableSetColumnIndex(1); - imgui.text(std::to_string(m_enabled_options_count) + " [" + std::to_string(m_enabled_options_range.first) + "-" + std::to_string(m_enabled_options_range.second) + "]"); - - ImGui::Separator(); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "layers range"); - ImGui::TableSetColumnIndex(1); - const std::array& layers_range = get_layers_range(); - imgui.text(std::to_string(layers_range[0]) + " - " + std::to_string(layers_range[1])); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (current)"); - ImGui::TableSetColumnIndex(1); - const std::array& current_view_range = get_view_current_range(); - imgui.text(std::to_string(current_view_range[0]) + " - " + std::to_string(current_view_range[1])); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (global)"); - ImGui::TableSetColumnIndex(1); - const std::array& global_view_range = get_view_global_range(); - imgui.text(std::to_string(global_view_range[0]) + " - " + std::to_string(global_view_range[1])); - - auto add_range_property_row = [&imgui](const std::string& label, const std::array& range) { - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, label); - ImGui::TableSetColumnIndex(1); - char buf[64]; - sprintf(buf, "%.3f - %.3f", range[0], range[1]); - imgui.text(buf); - }; - - add_range_property_row("height range", m_height_range.get_range()); - add_range_property_row("width range", m_width_range.get_range()); - add_range_property_row("speed range", m_speed_range.get_range()); - add_range_property_row("fan speed range", m_fan_speed_range.get_range()); - add_range_property_row("temperature range", m_temperature_range.get_range()); - add_range_property_row("volumetric rate range", m_volumetric_rate_range.get_range()); - add_range_property_row("layer time linear range", m_layer_time_range[0].get_range()); - add_range_property_row("layer time logarithmic range", m_layer_time_range[1].get_range()); - - ImGui::EndTable(); - -#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - ImGui::Separator(); - - if (ImGui::BeginTable("Cog", 2)) { - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Cog marker scale factor"); - ImGui::TableSetColumnIndex(1); - imgui.text(std::to_string(get_cog_marker_scale_factor())); - - ImGui::EndTable(); - } - - ImGui::Separator(); - - if (ImGui::BeginTable("Tool", 2)) { - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker scale factor"); - ImGui::TableSetColumnIndex(1); - imgui.text(std::to_string(get_tool_marker_scale_factor())); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker z offset"); - ImGui::TableSetColumnIndex(1); - float tool_z_offset = get_tool_marker_offset_z(); - if (imgui.slider_float("##ToolZOffset", &tool_z_offset, 0.0f, 1.0f)) - set_tool_marker_offset_z(tool_z_offset); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker color"); - ImGui::TableSetColumnIndex(1); - Color color = get_tool_marker_color(); - if (ImGui::ColorPicker3("##ToolColor", color.data())) - set_tool_marker_color(color); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker alpha"); - ImGui::TableSetColumnIndex(1); - float tool_alpha = get_tool_marker_alpha(); - if (imgui.slider_float("##ToolAlpha", &tool_alpha, 0.25f, 0.75f)) - set_tool_marker_alpha(tool_alpha); - - ImGui::EndTable(); - } -#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS - } - - imgui.end(); -} -#endif // ENABLE_NEW_GCODE_VIEWER_DEBUG - } // namespace libvgcode //################################################################################################################################ diff --git a/src/slic3r/GUI/LibVGCode/ViewerImpl.hpp b/src/slic3r/GUI/LibVGCode/ViewerImpl.hpp index e214c1017b..a549f3debf 100644 --- a/src/slic3r/GUI/LibVGCode/ViewerImpl.hpp +++ b/src/slic3r/GUI/LibVGCode/ViewerImpl.hpp @@ -98,6 +98,12 @@ public: PathVertex get_current_vertex() const; PathVertex get_vertex_at(size_t id) const; + size_t get_enabled_segments_count() const; + const std::array& get_enabled_segments_range() const; + + size_t get_enabled_options_count() const; + const std::array& get_enabled_options_range() const; + size_t get_extrusion_roles_count() const; std::vector get_extrusion_roles() const; float get_extrusion_role_time(EGCodeExtrusionRole role) const; @@ -112,6 +118,14 @@ public: const std::vector& get_tool_colors() const; void set_tool_colors(const std::vector& colors); + const std::array& get_height_range() const; + const std::array& get_width_range() const; + const std::array& get_speed_range() const; + const std::array& get_fan_speed_range() const; + const std::array& get_temperature_range() const; + const std::array& get_volumetric_rate_range() const; + std::array get_layer_time_range(ColorRange::EType type) const; + #if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS Vec3 get_cog_marker_position() const; @@ -140,7 +154,6 @@ public: private: Settings m_settings; Layers m_layers; - Range m_layers_range; ViewRange m_view_range; ExtrusionRoles m_extrusion_roles; std::array m_travels_time{ 0.0f, 0.0f }; @@ -173,10 +186,8 @@ private: // cpu buffer to store vertices // std::vector m_vertices; -#if ENABLE_NEW_GCODE_VIEWER_DEBUG - std::pair m_enabled_segments_range{ 0, 0 }; - std::pair m_enabled_options_range{ 0, 0 }; -#endif // ENABLE_NEW_GCODE_VIEWER_DEBUG + Range m_enabled_segments_range; + Range m_enabled_options_range; // // Member variables used for toolpaths visibiliity @@ -194,7 +205,7 @@ private: ColorRange m_fan_speed_range; ColorRange m_temperature_range; ColorRange m_volumetric_rate_range; - std::array(ColorRange::EType::COUNT)> m_layer_time_range{ + std::array m_layer_time_range{ ColorRange(ColorRange::EType::Linear), ColorRange(ColorRange::EType::Logarithmic) }; std::vector m_tool_colors; @@ -282,11 +293,6 @@ private: 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 - -#if ENABLE_NEW_GCODE_VIEWER_DEBUG - // Debug - void render_debug_window(); -#endif // ENABLE_NEW_GCODE_VIEWER_DEBUG }; } // namespace libvgcode