diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index e94637f176..b825a4e465 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -59,6 +59,12 @@ static Vec3 convert(const Slic3r::Vec3f& v) return { v.x(), v.y(), v.z() }; } +// mapping from libvgcode::Vec3 to Slic3r::Vec3f +static Slic3r::Vec3f convert(const Vec3& v) +{ + return { v[0], v[1], v[2] }; +} + // mapping from Slic3r::Matrix4f to libvgcode::Mat4x4 static Mat4x4 convert(const Slic3r::Matrix4f& m) { @@ -70,13 +76,14 @@ static Mat4x4 convert(const Slic3r::Matrix4f& m) // mapping from libvgcode::Color to Slic3r::ColorRGBA static Slic3r::ColorRGBA convert(const Color& c) { - return { c[0], c[1], c[2], 1.0f }; + static const float inv_255 = 1.0f / 255.0f; + return { c[0] * inv_255, c[1] * inv_255, c[2] * inv_255, 1.0f }; } // mapping from Slic3r::ColorRGBA to libvgcode::Color static Color convert(const Slic3r::ColorRGBA& c) { - return { c.r(), c.g(), c.b() }; + return { static_cast(c.r() * 255.0f), static_cast(c.g() * 255.0f), static_cast(c.b() * 255.0f) }; } // mapping from libvgcode::EGCodeExtrusionRole to Slic3r::GCodeExtrusionRole @@ -180,21 +187,12 @@ static GCodeInputData convert(const Slic3r::GCodeProcessorResult& result) const std::vector& moves = result.moves; GCodeInputData ret; ret.vertices.reserve(2 * moves.size()); - // Seam moves have no correspondence in the gcode, - // there are no gcode lines associated to them, - // but are added at the end of a loop, by the gcode processor, to be able to visualize them. - // To properly associate the other moves to the gcode lines, we need to keep track - // of them and modify the vertices' move_id accordingly. - uint32_t seams_count = 0; for (size_t i = 1; i < moves.size(); ++i) { const Slic3r::GCodeProcessorResult::MoveVertex& curr = moves[i]; const Slic3r::GCodeProcessorResult::MoveVertex& prev = moves[i - 1]; const EMoveType curr_type = convert(curr.type); const EGCodeExtrusionRole curr_role = convert(curr.extrusion_role); - if (curr_type == EMoveType::Seam) - ++seams_count; - EGCodeExtrusionRole extrusion_role; if (curr_type == EMoveType::Travel) { // for travel moves set the extrusion role @@ -239,29 +237,28 @@ static GCodeInputData convert(const Slic3r::GCodeProcessorResult& result) // 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(i) - seams_count, static_cast(curr.layer_id), - static_cast(curr.extruder_id), static_cast(curr.cp_color_id), { 0.0f, 0.0f } }; + 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 - 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(i) - seams_count, static_cast(curr.layer_id), - static_cast(curr.extruder_id), static_cast(curr.cp_color_id), { 0.0f, 0.0f } }; + 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 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(i) - seams_count, static_cast(curr.layer_id), - static_cast(curr.extruder_id), static_cast(curr.cp_color_id), curr.time }; + 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 - 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(i) - seams_count, static_cast(curr.layer_id), + 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 ret.vertices.emplace_back(vertex); @@ -728,7 +725,7 @@ void GCodeViewer::SequentialView::Marker::render_position_window(const libvgcode ImGui::SameLine(); libvgcode::PathVertex vertex = viewer->get_current_vertex(); if (vertex.type == libvgcode::EMoveType::Seam) - vertex = viewer->get_vertex_at(viewer->get_view_current_range()[1] - 1); + vertex = viewer->get_vertex_at(viewer->get_view_visible_range()[1] - 1); char buf[1024]; sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", vertex.position[0], vertex.position[1], vertex.position[2]); @@ -1141,33 +1138,41 @@ 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) +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 (viewer == nullptr) #endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS #else -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void GCodeViewer::SequentialView::render(float legend_height) { - //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #endif // ENABLE_NEW_GCODE_VIEWER //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ marker.render(); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #if ENABLE_NEW_GCODE_VIEWER marker.render_position_window(viewer); #endif // ENABLE_NEW_GCODE_VIEWER -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ float bottom = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height(); if (wxGetApp().is_editor()) bottom -= wxGetApp().plater()->get_view_toolbar().get_height(); +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#if ENABLE_NEW_GCODE_VIEWER + gcode_window.render(legend_height, bottom, gcode_id); +#else +//@@@@@@@@@@@@@@@@@@@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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ const std::array(GCodeExtrusionRole::Count)> GCodeViewer::Extrusion_Role_Colors{ { { 0.90f, 0.70f, 0.70f, 1.0f }, // GCodeExtrusionRole::None { 1.00f, 0.90f, 0.30f, 1.0f }, // GCodeExtrusionRole::Perimeter @@ -1246,27 +1251,27 @@ const std::vector GCodeViewer::Range_Colors{ { const ColorRGBA GCodeViewer::Wipe_Color = ColorRGBA::YELLOW(); const ColorRGBA GCodeViewer::Neutral_Color = ColorRGBA::DARK_GRAY(); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #endif // !ENABLE_NEW_GCODE_VIEWER -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GCodeViewer::GCodeViewer() { -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #endif // !ENABLE_NEW_GCODE_VIEWER -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ } void GCodeViewer::init() @@ -1719,13 +1724,22 @@ void GCodeViewer::render() float legend_height = 0.0f; if (!m_layers.empty()) { render_legend(legend_height); +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#if ENABLE_NEW_GCODE_VIEWER + if (m_new_viewer.get_view_enabled_range()[1] != m_new_viewer.get_view_visible_range()[1]) { + m_sequential_view.marker.set_world_position(libvgcode::convert(m_new_viewer.get_current_vertex().position)); +#else +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ if (m_sequential_view.current.last != m_sequential_view.endpoints.last) { m_sequential_view.marker.set_world_position(m_sequential_view.current_position); m_sequential_view.marker.set_world_offset(m_sequential_view.current_offset); +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#endif // ENABLE_NEW_GCODE_VIEWER +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ m_sequential_view.marker.set_z_offset(m_z_offset); //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #if ENABLE_NEW_GCODE_VIEWER - m_sequential_view.render(legend_height, m_use_new_viewer ? &m_new_viewer : nullptr); + m_sequential_view.render(legend_height, m_use_new_viewer ? &m_new_viewer : nullptr, m_new_viewer.get_current_vertex().gcode_id); #else //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ m_sequential_view.render(legend_height); @@ -1743,7 +1757,9 @@ void GCodeViewer::render() #if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS if (m_use_new_viewer) { ImGuiWrapper& imgui = *Slic3r::GUI::wxGetApp().imgui(); - imgui.begin(std::string("LibVGCode Viewer Controller"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); + const Size cnv_size = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size(); + imgui.set_next_window_pos(static_cast(cnv_size.get_width()), static_cast(cnv_size.get_height()), ImGuiCond_Always, 1.0f, 1.0f); + imgui.begin(std::string("LibVGCode Viewer Controller"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize); imgui.checkbox("Cog marker fixed screen size", m_cog_marker_fixed_screen_size); if (ImGui::BeginTable("Cog", 2)) { @@ -1785,10 +1801,7 @@ void GCodeViewer::update_sequential_view_current(unsigned int first, unsigned in { //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #if ENABLE_NEW_GCODE_VIEWER - m_new_viewer.set_view_current_range(static_cast(first), static_cast(last)); - m_sequential_view.current.first = first; - m_sequential_view.current.last = last; - m_sequential_view.last_current = m_sequential_view.current; + m_new_viewer.set_view_visible_range(static_cast(first), static_cast(last)); #else //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ auto is_visible = [this](unsigned int id) { @@ -2426,22 +2439,28 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) m_cog.reset(); +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#if !ENABLE_NEW_GCODE_VIEWER +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ m_sequential_view.gcode_ids.clear(); for (size_t i = 0; i < gcode_result.moves.size(); ++i) { const GCodeProcessorResult::MoveVertex& move = gcode_result.moves[i]; if (move.type != EMoveType::Seam) m_sequential_view.gcode_ids.push_back(move.gcode_id); } +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#endif // !ENABLE_NEW_GCODE_VIEWER +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #if ENABLE_NEW_GCODE_VIEWER bool account_for_volumetric_rate = m_new_viewer.get_view_type() == libvgcode::EViewType::VolumetricFlowRate; #else -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@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.size()); std::vector indices(m_buffers.size()); @@ -3913,7 +3932,9 @@ void GCodeViewer::render_new_toolpaths() #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); + const Size cnv_size = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size(); + imgui.set_next_window_pos(static_cast(cnv_size.get_width()), 0.0f, ImGuiCond_Always, 1.0f, 0.0f); + imgui.begin(std::string("LibVGCode Viewer Debug"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize); if (ImGui::BeginTable("Data", 2)) { @@ -3950,17 +3971,30 @@ void GCodeViewer::render_new_toolpaths() ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (current)"); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (full)"); 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])); + const std::array& full_view_range = m_new_viewer.get_view_full_range(); + imgui.text(std::to_string(full_view_range[0]) + " - " + std::to_string(full_view_range[1]) + " | " + + std::to_string(m_new_viewer.get_vertex_at(full_view_range[0]).gcode_id) + " - " + + std::to_string(m_new_viewer.get_vertex_at(full_view_range[1]).gcode_id)); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (global)"); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (enabled)"); 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])); + const std::array& enabled_view_range = m_new_viewer.get_view_enabled_range(); + imgui.text(std::to_string(enabled_view_range[0]) + " - " + std::to_string(enabled_view_range[1]) + " | " + + std::to_string(m_new_viewer.get_vertex_at(enabled_view_range[0]).gcode_id) + " - " + + std::to_string(m_new_viewer.get_vertex_at(enabled_view_range[1]).gcode_id)); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (visible)"); + ImGui::TableSetColumnIndex(1); + const std::array& visible_view_range = m_new_viewer.get_view_visible_range(); + imgui.text(std::to_string(visible_view_range[0]) + " - " + std::to_string(visible_view_range[1]) + " | " + + std::to_string(m_new_viewer.get_vertex_at(visible_view_range[0]).gcode_id) + " - " + + std::to_string(m_new_viewer.get_vertex_at(visible_view_range[1]).gcode_id)); auto add_range_property_row = [&imgui](const std::string& label, const std::array& range) { ImGui::TableNextRow(); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index fa24764f76..3ea469ae98 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -835,11 +835,17 @@ public: Vec3f current_offset{ Vec3f::Zero() }; Marker marker; GCodeWindow gcode_window; +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#if !ENABLE_NEW_GCODE_VIEWER +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ std::vector gcode_ids; +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#endif // !ENABLE_NEW_GCODE_VIEWER +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #if ENABLE_NEW_GCODE_VIEWER - void render(float legend_height, const libvgcode::Viewer* viewer); + void render(float legend_height, const libvgcode::Viewer* viewer, uint32_t gcode_id); #else //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void render(float legend_height); @@ -848,9 +854,9 @@ public: //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ }; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ EViewType m_last_view_type{ EViewType::Count }; -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #endif // !ENABLE_NEW_GCODE_VIEWER -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ size_t m_moves_count{ 0 }; std::vector m_buffers{ static_cast(EMoveType::Extrude) }; // bounding box of toolpaths @@ -1055,14 +1061,23 @@ public: const SequentialView& get_sequential_view() const { return m_sequential_view; } void update_sequential_view_current(unsigned int first, unsigned int last); +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#if ENABLE_NEW_GCODE_VIEWER + const std::array& get_gcode_view_full_range() const { return m_new_viewer.get_view_full_range(); } + const std::array& get_gcode_view_enabled_range() const { return m_new_viewer.get_view_enabled_range(); } + const std::array& get_gcode_view_visible_range() const { return m_new_viewer.get_view_visible_range(); } + libvgcode::PathVertex get_gcode_vertex_at(size_t id) const { return m_new_viewer.get_vertex_at(id); } +#endif // ENABLE_NEW_GCODE_VIEWER +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + bool is_contained_in_bed() const { return m_contained_in_bed; } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #if ENABLE_NEW_GCODE_VIEWER void set_view_type(libvgcode::EViewType type) { m_new_viewer.set_view_type(type); } libvgcode::EViewType get_view_type() const { return m_new_viewer.get_view_type(); } #else -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ EViewType get_view_type() const { return m_view_type; } void set_view_type(EViewType type) { if (type == EViewType::Count) @@ -1070,20 +1085,20 @@ public: m_view_type = type; } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #endif // ENABLE_NEW_GCODE_VIEWER -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ bool is_toolpath_move_type_visible(EMoveType type) const; void set_toolpath_move_type_visible(EMoveType type, bool visible); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #if !ENABLE_NEW_GCODE_VIEWER -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ unsigned int get_toolpath_role_visibility_flags() const { return m_extrusions.role_visibility_flags; } void set_toolpath_role_visibility_flags(unsigned int flags) { m_extrusions.role_visibility_flags = flags; } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #endif // !ENABLE_NEW_GCODE_VIEWER -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ unsigned int get_options_visibility_flags() const; void set_options_visibility_from_flags(unsigned int flags); void set_layers_z_range(const std::array& layers_z_range); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 9e81a40817..6649ddca56 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -736,9 +736,11 @@ public: const GCodeViewer::SequentialView& get_gcode_sequential_view() const { return m_gcode_viewer.get_sequential_view(); } //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #if ENABLE_NEW_GCODE_VIEWER - void update_gcode_sequential_view_current(unsigned int first, unsigned int last) { - m_gcode_viewer.update_sequential_view_current(first, last); - } + void update_gcode_sequential_view_current(unsigned int first, unsigned int last) { m_gcode_viewer.update_sequential_view_current(first, last); } + const std::array& get_gcode_view_full_range() const { return m_gcode_viewer.get_gcode_view_full_range(); } + const std::array& get_gcode_view_enabled_range() const { return m_gcode_viewer.get_gcode_view_enabled_range(); } + const std::array& get_gcode_view_visible_range() const { return m_gcode_viewer.get_gcode_view_visible_range(); } + libvgcode::PathVertex get_gcode_vertex_at(size_t id) const { return m_gcode_viewer.get_gcode_vertex_at(id); } #else //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void update_gcode_sequential_view_current(unsigned int first, unsigned int last) { m_gcode_viewer.update_sequential_view_current(first, last); } diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 49eb08599c..b267137c9f 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -713,6 +713,40 @@ void Preview::update_layers_slider_from_canvas(wxKeyEvent& event) void Preview::update_moves_slider() { +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#if ENABLE_NEW_GCODE_VIEWER + const std::array& range = m_canvas->get_gcode_view_enabled_range(); + uint32_t last_gcode_id = m_canvas->get_gcode_vertex_at(static_cast(range[0])).gcode_id; + + const size_t range_size = static_cast(range[1] - range[0] + 1); + std::vector values; + values.reserve(range_size); + std::vector alternate_values; + alternate_values.reserve(range_size); + + for (uint32_t i = range[0]; i <= range[1]; ++i) { + const uint32_t gcode_id = m_canvas->get_gcode_vertex_at(static_cast(i)).gcode_id; + if (i > range[0]) { + // skip consecutive moves with same gcode id (resulting from processing G2 and G3 lines) + if (last_gcode_id == gcode_id) { + values.back() = static_cast(i + 1); + alternate_values.back() = static_cast(gcode_id); + continue; + } + else + last_gcode_id = gcode_id; + } + + values.emplace_back(static_cast(i + 1)); + alternate_values.emplace_back(static_cast(gcode_id)); + } + + m_moves_slider->SetSliderValues(values); + m_moves_slider->SetSliderAlternateValues(alternate_values); + m_moves_slider->SetMaxValue(int(values.size()) - 1); + m_moves_slider->SetSelectionSpan(values.front() - 1 - range[0], values.back() - 1 - range[0]); +#else +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ const GCodeViewer::SequentialView& view = m_canvas->get_gcode_sequential_view(); // this should not be needed, but it is here to try to prevent rambling crashes on Mac Asan if (view.endpoints.last < view.endpoints.first) @@ -746,6 +780,9 @@ void Preview::update_moves_slider() m_moves_slider->SetSliderAlternateValues(alternate_values); m_moves_slider->SetMaxValue(int(values.size()) - 1); m_moves_slider->SetSelectionSpan(values.front() - 1 - view.endpoints.first, values.back() - 1 - view.endpoints.first); +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#endif // ENABLE_NEW_GCODE_VIEWER +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ } void Preview::enable_moves_slider(bool enable) diff --git a/src/slic3r/GUI/LibVGCode/PathVertex.hpp b/src/slic3r/GUI/LibVGCode/PathVertex.hpp index b75be822ca..7cc8038bd1 100644 --- a/src/slic3r/GUI/LibVGCode/PathVertex.hpp +++ b/src/slic3r/GUI/LibVGCode/PathVertex.hpp @@ -28,7 +28,7 @@ struct PathVertex #endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS EGCodeExtrusionRole role{ EGCodeExtrusionRole::None }; EMoveType type{ EMoveType::Noop }; - uint32_t move_id{ 0 }; + uint32_t gcode_id{ 0 }; uint32_t layer_id{ 0 }; uint8_t extruder_id{ 0 }; uint8_t color_id{ 0 }; diff --git a/src/slic3r/GUI/LibVGCode/Range.cpp b/src/slic3r/GUI/LibVGCode/Range.cpp index 31f76c310c..2236ecb9fd 100644 --- a/src/slic3r/GUI/LibVGCode/Range.cpp +++ b/src/slic3r/GUI/LibVGCode/Range.cpp @@ -23,6 +23,11 @@ const std::array& Range::get() const return m_range; } +void Range::set(const Range& other) +{ + m_range = other.m_range; +} + void Range::set(const std::array& range) { set(range[0], range[1]); @@ -36,6 +41,26 @@ void Range::set(uint32_t min, uint32_t max) m_range[1] = max; } +uint32_t Range::get_min() const +{ + return m_range[0]; +} + +void Range::set_min(uint32_t min) +{ + set(min, m_range[1]); +} + +uint32_t Range::get_max() const +{ + return m_range[1]; +} + +void Range::set_max(uint32_t max) +{ + set(m_range[0], max); +} + void Range::clamp(Range& other) { other.m_range[0] = std::clamp(other.m_range[0], m_range[0], m_range[1]); diff --git a/src/slic3r/GUI/LibVGCode/Range.hpp b/src/slic3r/GUI/LibVGCode/Range.hpp index e9c4472475..973d443c46 100644 --- a/src/slic3r/GUI/LibVGCode/Range.hpp +++ b/src/slic3r/GUI/LibVGCode/Range.hpp @@ -19,8 +19,16 @@ class Range { public: const std::array& get() const; + void set(const Range& other); void set(const std::array& range); void set(uint32_t min, uint32_t max); + + uint32_t get_min() const; + void set_min(uint32_t min); + + uint32_t get_max() const; + void set_max(uint32_t max); + // clamp the given range to stay inside this range void clamp(Range& other); void reset(); diff --git a/src/slic3r/GUI/LibVGCode/Settings.hpp b/src/slic3r/GUI/LibVGCode/Settings.hpp index 5612cadbad..bbf2723b45 100644 --- a/src/slic3r/GUI/LibVGCode/Settings.hpp +++ b/src/slic3r/GUI/LibVGCode/Settings.hpp @@ -18,7 +18,7 @@ namespace libvgcode { struct Settings { - bool update_view_global_range{ true }; + bool update_view_full_range{ true }; bool update_enabled_entities{ true }; bool update_colors{ true }; EViewType view_type{ EViewType::FeatureType }; diff --git a/src/slic3r/GUI/LibVGCode/Types.cpp b/src/slic3r/GUI/LibVGCode/Types.cpp index a08de1fad1..ea4c34bc6f 100644 --- a/src/slic3r/GUI/LibVGCode/Types.cpp +++ b/src/slic3r/GUI/LibVGCode/Types.cpp @@ -34,12 +34,17 @@ EOptionType type_to_option(EMoveType type) } } +static uint8_t lerp(uint8_t f1, uint8_t f2, float t) +{ + const float one_minus_t = 1.0f - t; + return static_cast(one_minus_t * static_cast(f1) + t * static_cast(f2)); +} + +// It will be possible to replace this with std::lerp when using c++20 Color lerp(const Color& c1, const Color& c2, float t) { - // It will be possible to replace this with std::lerp when using c++20 t = std::clamp(t, 0.0f, 1.0f); - const float one_minus_t = 1.0f - t; - return { one_minus_t * c1[0] + t * c2[0], one_minus_t * c1[1] + t * c2[1], one_minus_t * c1[2] + t * c2[2] }; + return { lerp(c1[0], c2[0], t), lerp(c1[1], c2[1], t), lerp(c1[2], c2[2], t) }; } } // namespace libvgcode diff --git a/src/slic3r/GUI/LibVGCode/Types.hpp b/src/slic3r/GUI/LibVGCode/Types.hpp index 61cb5c1fe8..0931b1fd53 100644 --- a/src/slic3r/GUI/LibVGCode/Types.hpp +++ b/src/slic3r/GUI/LibVGCode/Types.hpp @@ -23,6 +23,9 @@ static constexpr float Default_Wipe_Radius = 0.05f; // // Vector in 3 dimensions +// [0] -> x +// [1] -> y +// [2] -> z // Used for positions, displacements and so on. // using Vec3 = std::array; @@ -37,12 +40,12 @@ using Vec3 = std::array; using Mat4x4 = std::array; // +// RGB color // [0] -> red // [1] -> green // [2] -> blue -// Values should belong to the range [0..1] // -using Color = std::array; +using Color = std::array; // // View types @@ -142,8 +145,8 @@ static constexpr size_t Time_Modes_Count = static_cast(ETimeMode::COUNT) // // Predefined colors // -static const Color Dummy_Color{ 0.25f, 0.25f, 0.25f }; -static const Color Wipe_Color{ 1.0f, 1.0f, 0.0f }; +static const Color Dummy_Color{ 64, 64, 64 }; +static const Color Wipe_Color { 255, 255, 255 }; // // Palette used to render moves by ranges @@ -151,17 +154,17 @@ static const Color Wipe_Color{ 1.0f, 1.0f, 0.0f }; // LayerTimeLinear, LayerTimeLogarithmic // static const std::vector Ranges_Colors{ { - { 0.043f, 0.173f, 0.478f }, // bluish - { 0.075f, 0.349f, 0.522f }, - { 0.110f, 0.533f, 0.569f }, - { 0.016f, 0.839f, 0.059f }, - { 0.667f, 0.949f, 0.000f }, - { 0.988f, 0.975f, 0.012f }, - { 0.961f, 0.808f, 0.039f }, - { 0.890f, 0.533f, 0.125f }, - { 0.820f, 0.408f, 0.188f }, - { 0.761f, 0.322f, 0.235f }, - { 0.581f, 0.149f, 0.087f } // reddish + { 11, 44, 122 }, // bluish + { 19, 89, 133 }, + { 28, 136, 145 }, + { 4, 214, 15 }, + { 170, 242, 0 }, + { 252, 249, 3 }, + { 245, 206, 10 }, + { 227, 136, 32 }, + { 209, 104, 48 }, + { 194, 82, 60 }, + { 148, 38, 22 } // reddish } }; // @@ -169,21 +172,21 @@ static const std::vector Ranges_Colors{ { // EViewType: FeatureType // static const std::vector Extrusion_Roles_Colors{ { - { 0.90f, 0.70f, 0.70f }, // None - { 1.00f, 0.90f, 0.30f }, // Perimeter - { 1.00f, 0.49f, 0.22f }, // ExternalPerimeter - { 0.12f, 0.12f, 1.00f }, // OverhangPerimeter - { 0.69f, 0.19f, 0.16f }, // InternalInfill - { 0.59f, 0.33f, 0.80f }, // SolidInfill - { 0.94f, 0.25f, 0.25f }, // TopSolidInfill - { 1.00f, 0.55f, 0.41f }, // Ironing - { 0.30f, 0.50f, 0.73f }, // BridgeInfill - { 1.00f, 1.00f, 1.00f }, // GapFill - { 0.00f, 0.53f, 0.43f }, // Skirt - { 0.00f, 1.00f, 0.00f }, // SupportMaterial - { 0.00f, 0.50f, 0.00f }, // SupportMaterialInterface - { 0.70f, 0.89f, 0.67f }, // WipeTower - { 0.37f, 0.82f, 0.58f }, // Custom + { 230, 179, 179 }, // None + { 255, 230, 77 }, // Perimeter + { 255, 125, 56 }, // ExternalPerimeter + { 31, 31, 255 }, // OverhangPerimeter + { 176, 48, 41 }, // InternalInfill + { 150, 84, 204 }, // SolidInfill + { 240, 64, 64 }, // TopSolidInfill + { 255, 140, 105 }, // Ironing + { 77, 128, 186 }, // BridgeInfill + { 255, 255, 255 }, // GapFill + { 0, 135, 110 }, // Skirt + { 0, 255, 0 }, // SupportMaterial + { 0, 128, 0 }, // SupportMaterialInterface + { 179, 227, 171 }, // WipeTower + { 94, 209, 148 } // Custom } }; // @@ -192,22 +195,22 @@ static const std::vector Extrusion_Roles_Colors{ { // LayerTimeLinear, LayerTimeLogarithmic // static const std::vector Travels_Colors{ { - { 0.219f, 0.282f, 0.609f }, // Move - { 0.112f, 0.422f, 0.103f }, // Extrude - { 0.505f, 0.064f, 0.028f } // Retract + { 56, 72, 155 }, // Move + { 29, 108, 26 }, // Extrude + { 129, 16, 7 } // Retract } }; // // Palette used to render options // static const std::map Options_Colors{ { - { EMoveType::Retract, { 0.803f, 0.135f, 0.839f } }, - { EMoveType::Unretract, { 0.287f, 0.679f, 0.810f } }, - { EMoveType::Seam, { 0.900f, 0.900f, 0.900f } }, - { EMoveType::ToolChange, { 0.758f, 0.744f, 0.389f } }, - { EMoveType::ColorChange, { 0.856f, 0.582f, 0.546f } }, - { EMoveType::PausePrint, { 0.322f, 0.942f, 0.512f } }, - { EMoveType::CustomGCode, { 0.886f, 0.825f, 0.262f } } + { EMoveType::Retract, { 205, 34, 214 } }, + { EMoveType::Unretract, { 73, 173, 207 } }, + { EMoveType::Seam, { 230, 230, 230 } }, + { EMoveType::ToolChange, { 193, 190, 99 } }, + { EMoveType::ColorChange, { 218, 148, 139 } }, + { EMoveType::PausePrint, { 82, 240, 131 } }, + { EMoveType::CustomGCode, { 226, 210, 67 } } } }; // diff --git a/src/slic3r/GUI/LibVGCode/ViewRange.cpp b/src/slic3r/GUI/LibVGCode/ViewRange.cpp index 1f4837cd01..78adb42f3e 100644 --- a/src/slic3r/GUI/LibVGCode/ViewRange.cpp +++ b/src/slic3r/GUI/LibVGCode/ViewRange.cpp @@ -16,59 +16,92 @@ namespace libvgcode { -const std::array& ViewRange::get_current() const +const std::array& ViewRange::get_full() const { - return m_current.get(); + return m_full.get(); } -void ViewRange::set_current(const Range& other) +void ViewRange::set_full(const Range& other) { - set_current(other.get()); + set_full(other.get()); } -void ViewRange::set_current(const std::array& range) +void ViewRange::set_full(const std::array& range) { - set_current(range[0], range[1]); + set_full(range[0], range[1]); } -void ViewRange::set_current(uint32_t min, uint32_t max) +void ViewRange::set_full(uint32_t min, uint32_t max) { - m_current.set(min, max); - // force the current range to stay inside the modified global range - m_global.clamp(m_current); + // is the full range being extended ? + const bool new_max = max > m_full.get_max(); + m_full.set(min, max); + // force the enabled range to stay inside the modified full range + m_full.clamp(m_enabled); + // force the visible range to stay inside the modified enabled range + m_enabled.clamp(m_visible); + if (new_max) { + // force the enabled range to fill the extended full range + m_enabled.set_max(max); + // force the visible range to fill the extended enabled range + m_visible.set_max(max); + } } -const std::array& ViewRange::get_global() const +const std::array& ViewRange::get_enabled() const { - return m_global.get(); + return m_enabled.get(); } -void ViewRange::set_global(const Range& other) +void ViewRange::set_enabled(const Range& other) { - set_global(other.get()); + set_enabled(other.get()); } -void ViewRange::set_global(const std::array& range) +void ViewRange::set_enabled(const std::array& range) { - set_global(range[0], range[1]); + set_enabled(range[0], range[1]); } -void ViewRange::set_global(uint32_t min, uint32_t max) +void ViewRange::set_enabled(uint32_t min, uint32_t max) { - // is the global range being extended ? - const bool new_max = max > m_global.get()[1]; - m_global.set(min, max); - // force the current range to stay inside the modified global range - m_global.clamp(m_current); + // is the enabled range being extended ? + const bool new_max = max > m_enabled.get_max(); + m_enabled.set(min, max); + // force the visible range to stay inside the modified enabled range + m_enabled.clamp(m_visible); if (new_max) - // force the current range to fill the extended global range - m_current.set(m_current.get()[0], max); + // force the visible range to fill the extended enabled range + m_visible.set_max(max); +} + +const std::array& ViewRange::get_visible() const +{ + return m_visible.get(); +} + +void ViewRange::set_visible(const Range& other) +{ + set_visible(other.get()); +} + +void ViewRange::set_visible(const std::array& range) +{ + set_visible(range[0], range[1]); +} + +void ViewRange::set_visible(uint32_t min, uint32_t max) +{ + m_visible.set(min, max); + // force the visible range to stay inside the enabled range + m_enabled.clamp(m_visible); } void ViewRange::reset() { - m_current.reset(); - m_global.reset(); + m_full.reset(); + m_enabled.reset(); + m_visible.reset(); } } // namespace libvgcode diff --git a/src/slic3r/GUI/LibVGCode/ViewRange.hpp b/src/slic3r/GUI/LibVGCode/ViewRange.hpp index 912c688813..2603c82a12 100644 --- a/src/slic3r/GUI/LibVGCode/ViewRange.hpp +++ b/src/slic3r/GUI/LibVGCode/ViewRange.hpp @@ -17,21 +17,43 @@ namespace libvgcode { class ViewRange { public: - const std::array& get_current() const; - void set_current(const Range& other); - void set_current(const std::array& range); - void set_current(uint32_t min, uint32_t max); + const std::array& get_full() const; + void set_full(const Range& other); + void set_full(const std::array& range); + void set_full(uint32_t min, uint32_t max); - const std::array& get_global() const; - void set_global(const Range& other); - void set_global(const std::array& range); - void set_global(uint32_t min, uint32_t max); + const std::array& get_enabled() const; + void set_enabled(const Range& other); + void set_enabled(const std::array& range); + void set_enabled(uint32_t min, uint32_t max); + + const std::array& get_visible() const; + void set_visible(const Range& other); + void set_visible(const std::array& range); + void set_visible(uint32_t min, uint32_t max); void reset(); private: - Range m_current; - Range m_global; + // + // Full range + // The range of moves that could potentially be visible. + // It is usually equal to the enabled range, unless Settings::top_layer_only_view_range is set to true. + // + Range m_full; + + // + // Enabled range + // The range of moves that are enabled for visualization. + // It is usually equal to the full range, unless Settings::top_layer_only_view_range is set to true. + // + Range m_enabled; + + // + // Visible range + // The range of moves that are currently rendered. + // + Range m_visible; }; } // namespace libvgcode diff --git a/src/slic3r/GUI/LibVGCode/Viewer.cpp b/src/slic3r/GUI/LibVGCode/Viewer.cpp index 713c62cc1e..a6cf4f229c 100644 --- a/src/slic3r/GUI/LibVGCode/Viewer.cpp +++ b/src/slic3r/GUI/LibVGCode/Viewer.cpp @@ -101,19 +101,24 @@ void Viewer::toggle_extrusion_role_visibility(EGCodeExtrusionRole role) m_impl.toggle_extrusion_role_visibility(role); } -const std::array& Viewer::get_view_current_range() const +const std::array& Viewer::get_view_full_range() const { - return m_impl.get_view_current_range(); + return m_impl.get_view_full_range(); } -const std::array& Viewer::get_view_global_range() const +const std::array& Viewer::get_view_enabled_range() const { - return m_impl.get_view_global_range(); + return m_impl.get_view_enabled_range(); } -void Viewer::set_view_current_range(uint32_t min, uint32_t max) +const std::array& Viewer::get_view_visible_range() const { - m_impl.set_view_current_range(min, max); + return m_impl.get_view_visible_range(); +} + +void Viewer::set_view_visible_range(uint32_t min, uint32_t max) +{ + m_impl.set_view_visible_range(min, max); } uint32_t Viewer::get_vertices_count() const diff --git a/src/slic3r/GUI/LibVGCode/Viewer.hpp b/src/slic3r/GUI/LibVGCode/Viewer.hpp index 81279a9cb8..bacc79ea3d 100644 --- a/src/slic3r/GUI/LibVGCode/Viewer.hpp +++ b/src/slic3r/GUI/LibVGCode/Viewer.hpp @@ -50,13 +50,15 @@ public: bool is_extrusion_role_visible(EGCodeExtrusionRole role) const; void toggle_extrusion_role_visibility(EGCodeExtrusionRole role); - const std::array& get_view_current_range() const; - const std::array& get_view_global_range() const; + const std::array& get_view_full_range() const; + const std::array& get_view_enabled_range() const; + const std::array& get_view_visible_range() const; + // // min must be smaller than max - // values are clamped to the view global range + // values are clamped to the current view global range // - void set_view_current_range(uint32_t min, uint32_t max); + void set_view_visible_range(uint32_t min, uint32_t max); // // Return the count of vertices used to render the toolpaths diff --git a/src/slic3r/GUI/LibVGCode/ViewerImpl.cpp b/src/slic3r/GUI/LibVGCode/ViewerImpl.cpp index 1e7513b871..d6f2950788 100644 --- a/src/slic3r/GUI/LibVGCode/ViewerImpl.cpp +++ b/src/slic3r/GUI/LibVGCode/ViewerImpl.cpp @@ -583,7 +583,7 @@ void ViewerImpl::load(GCodeInputData&& gcode_data) if (!m_layers.empty()) set_layers_range(0, static_cast(m_layers.count() - 1)); - update_view_global_range(); + m_settings.update_colors = true; } @@ -591,13 +591,13 @@ void ViewerImpl::update_enabled_entities() { std::vector enabled_segments; std::vector enabled_options; - std::array range = m_view_range.get_current(); + std::array range = m_view_range.get_visible(); // when top layer only visualization is enabled, we need to render // all the toolpaths in the other layers as grayed, so extend the range // to contain them if (m_settings.top_layer_only_view_range) - range[0] = m_view_range.get_global()[0]; + range[0] = m_view_range.get_full()[0]; // to show the options at the current tool marker position we need to extend the range by one extra step if (m_vertices[range[1]].is_option() && range[1] < static_cast(m_vertices.size()) - 1) @@ -665,11 +665,11 @@ void ViewerImpl::update_enabled_entities() } static float encode_color(const Color& color) { - const int r = (int)(255.0f * color[0]); - const int g = (int)(255.0f * color[1]); - const int b = (int)(255.0f * color[2]); + const int r = static_cast(color[0]); + const int g = static_cast(color[1]); + const int b = static_cast(color[2]); const int i_color = r << 16 | g << 8 | b; - return float(i_color); + return static_cast(i_color); } void ViewerImpl::update_colors() @@ -677,7 +677,7 @@ void ViewerImpl::update_colors() update_color_ranges(); 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]; + const bool color_top_layer_only = m_view_range.get_full()[1] != m_view_range.get_visible()[1]; std::vector colors(m_vertices.size()); for (size_t i = 0; i < m_vertices.size(); i++) { colors[i] = (color_top_layer_only && m_vertices[i].layer_id < top_layer_id) ? encode_color(Dummy_Color) : encode_color(select_color(m_vertices[i])); @@ -692,9 +692,9 @@ void ViewerImpl::update_colors() void ViewerImpl::render(const Mat4x4& view_matrix, const Mat4x4& projection_matrix) { - if (m_settings.update_view_global_range) { - update_view_global_range(); - m_settings.update_view_global_range = false; + if (m_settings.update_view_full_range) { + update_view_full_range(); + m_settings.update_view_full_range = false; } if (m_settings.update_enabled_entities) { @@ -755,7 +755,9 @@ void ViewerImpl::set_layers_range(const std::array& range) void ViewerImpl::set_layers_range(uint32_t min, uint32_t max) { m_layers.set_view_range(min, max); - m_settings.update_view_global_range = true; + // force immediate update of the full range + update_view_full_range(); + m_settings.update_view_full_range = false; m_settings.update_enabled_entities = true; m_settings.update_colors = true; } @@ -786,7 +788,7 @@ void ViewerImpl::toggle_option_visibility(EOptionType type) try { bool& value = m_settings.options_visibility.at(type); value = !value; - m_settings.update_view_global_range = true; + m_settings.update_view_full_range = true; m_settings.update_enabled_entities = true; m_settings.update_colors = true; } @@ -810,7 +812,7 @@ void ViewerImpl::toggle_extrusion_role_visibility(EGCodeExtrusionRole role) try { bool& value = m_settings.extrusion_roles_visibility.at(role); value = !value; - m_settings.update_view_global_range = true; + m_settings.update_view_full_range = true; m_settings.update_enabled_entities = true; m_settings.update_colors = true; } @@ -819,57 +821,29 @@ void ViewerImpl::toggle_extrusion_role_visibility(EGCodeExtrusionRole role) } } -const std::array& ViewerImpl::get_view_current_range() const +const std::array& ViewerImpl::get_view_full_range() const { - return m_view_range.get_current(); + return m_view_range.get_full(); } -const std::array& ViewerImpl::get_view_global_range() const +const std::array& ViewerImpl::get_view_enabled_range() const { - return m_view_range.get_global(); + return m_view_range.get_enabled(); } -void ViewerImpl::set_view_current_range(uint32_t min, uint32_t max) +const std::array& ViewerImpl::get_view_visible_range() const { - uint32_t min_id = 0; - for (size_t i = 0; i < m_vertices.size(); ++i) { - if (m_vertices[i].move_id < min) - min_id = static_cast(i); - else - break; - } - ++min_id; + return m_view_range.get_visible(); +} - uint32_t max_id = min_id; - if (max > min) { - for (size_t i = static_cast(min_id); i < m_vertices.size(); ++i) { - if (m_vertices[i].move_id < max) - max_id = static_cast(i); - else - break; - } - ++max_id; - } +void ViewerImpl::set_view_visible_range(uint32_t min, uint32_t max) +{ + // force update of the full range, to avoid clamping the visible range with full old values + // when calling m_view_range.set_visible() + update_view_full_range(); + m_settings.update_view_full_range = false; - // adjust the max id to take in account the 'phantom' vertices - if (max_id < static_cast(m_vertices.size() - 1) && - m_vertices[max_id + 1].type == m_vertices[max_id].type && - m_vertices[max_id + 1].move_id == m_vertices[max_id].move_id) - ++max_id; - - // we show the seams when the endpoint of a closed path is reached, so we need to increase the max id by one - if (max_id < static_cast(m_vertices.size() - 1) && m_vertices[max_id + 1].type == EMoveType::Seam) - ++max_id; - - Range new_range; - new_range.set(min_id, max_id); - - // force update of global range, if required, to avoid clamping the current range with global old values - // when calling set_current_range() - update_view_global_range(); - m_settings.update_view_global_range = false; - - m_view_range.set_current(new_range); + m_view_range.set_visible(min, max); m_settings.update_enabled_entities = true; m_settings.update_colors = true; } @@ -881,7 +855,7 @@ size_t ViewerImpl::get_vertices_count() const PathVertex ViewerImpl::get_current_vertex() const { - return m_vertices[m_view_range.get_current()[1]]; + return m_vertices[m_view_range.get_visible()[1]]; } PathVertex ViewerImpl::get_vertex_at(size_t id) const @@ -1101,7 +1075,7 @@ static bool is_visible(const PathVertex& v, const Settings& settings) } } -void ViewerImpl::update_view_global_range() +void ViewerImpl::update_view_full_range() { const std::array& layers_range = m_layers.get_view_range(); const bool travels_visible = m_settings.options_visibility.at(EOptionType::Travels); @@ -1113,7 +1087,7 @@ void ViewerImpl::update_view_global_range() } if (first_it == m_vertices.end()) - m_view_range.set_global(0, 0); + m_view_range.set_full(Range()); else { if (travels_visible) { // if the global range starts with a travel move, extend it to the travel start @@ -1154,7 +1128,22 @@ void ViewerImpl::update_view_global_range() } } - m_view_range.set_global(std::distance(m_vertices.begin(), first_it), std::distance(m_vertices.begin(), last_it)); + m_view_range.set_full(std::distance(m_vertices.begin(), first_it), std::distance(m_vertices.begin(), last_it)); + + if (m_settings.top_layer_only_view_range) { + const std::array& full_range = m_view_range.get_full(); + auto top_first_it = m_vertices.begin() + full_range[0]; + bool shortened = false; + while (top_first_it != m_vertices.end() && (top_first_it->layer_id < layers_range[1] || !is_visible(*top_first_it, m_settings))) { + ++top_first_it; + shortened = true; + } + if (shortened) + --top_first_it; + m_view_range.set_enabled(std::distance(m_vertices.begin(), top_first_it), full_range[1]); + } + else + m_view_range.set_enabled(m_view_range.get_full()); } } diff --git a/src/slic3r/GUI/LibVGCode/ViewerImpl.hpp b/src/slic3r/GUI/LibVGCode/ViewerImpl.hpp index a549f3debf..6f3bc796ee 100644 --- a/src/slic3r/GUI/LibVGCode/ViewerImpl.hpp +++ b/src/slic3r/GUI/LibVGCode/ViewerImpl.hpp @@ -90,9 +90,10 @@ public: bool is_extrusion_role_visible(EGCodeExtrusionRole role) const; void toggle_extrusion_role_visibility(EGCodeExtrusionRole role); - const std::array& get_view_current_range() const; - const std::array& get_view_global_range() const; - void set_view_current_range(uint32_t min, uint32_t max); + const std::array& get_view_full_range() const; + const std::array& get_view_enabled_range() const; + const std::array& get_view_visible_range() const; + void set_view_visible_range(uint32_t min, uint32_t max); size_t get_vertices_count() const; PathVertex get_current_vertex() const; @@ -284,7 +285,7 @@ private: unsigned int m_enabled_options_buf_id{ 0 }; unsigned int m_enabled_options_tex_id{ 0 }; - void update_view_global_range(); + void update_view_full_range(); void update_color_ranges(); Color select_color(const PathVertex& v) const; void render_segments(const Mat4x4& view_matrix, const Mat4x4& projection_matrix, const Vec3& camera_position);