From 779f4a890d4bb71519b2989a3b1074ab72c63498 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Fri, 9 Jan 2026 11:52:30 +0800 Subject: [PATCH] QoL: improve gcode marker (#11881) QoL: Improve gcode marker --- src/libslic3r/GCode/GCodeProcessor.cpp | 1 + src/libslic3r/GCode/GCodeProcessor.hpp | 1 + src/libvgcode/include/PathVertex.hpp | 4 ++ src/libvgcode/src/ViewerImpl.cpp | 9 ++++ src/slic3r/GUI/GCodeViewer.cpp | 61 +++++++++++++++++++++++--- src/slic3r/GUI/GCodeViewer.hpp | 2 +- 6 files changed, 71 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index d94f20112f..6332cadb4a 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -5412,6 +5412,7 @@ void GCodeProcessor::store_move_vertex(EMoveType type, EMovePathType path_type, m_fan_speed, m_extruder_temps[filament_id], { 0.0f, 0.0f }, // time + static_cast(m_layer_id), //layer_duration: set later std::max(1, m_layer_id) - 1, internal_only, m_object_label_id, diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index b17f7d0933..126efbc5cb 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -185,6 +185,7 @@ class Print; float fan_speed{ 0.0f }; // percentage float temperature{ 0.0f }; // Celsius degrees std::array(PrintEstimatedStatistics::ETimeMode::Count)> time{ 0.0f, 0.0f }; // s + float layer_duration{ 0.0f }; // s unsigned int layer_id{ 0 }; bool internal_only{ false }; diff --git a/src/libvgcode/include/PathVertex.hpp b/src/libvgcode/include/PathVertex.hpp index d2c39ce40d..d5101d9318 100644 --- a/src/libvgcode/include/PathVertex.hpp +++ b/src/libvgcode/include/PathVertex.hpp @@ -82,6 +82,10 @@ struct PathVertex // Segment estimated times // std::array times{ 0.0f, 0.0f }; + // + // Layer duration in seconds + // + float layer_duration{ 0.0f }; // // Return true if the segment is an extrusion move diff --git a/src/libvgcode/src/ViewerImpl.cpp b/src/libvgcode/src/ViewerImpl.cpp index a9b6b7ae81..51a3079be1 100644 --- a/src/libvgcode/src/ViewerImpl.cpp +++ b/src/libvgcode/src/ViewerImpl.cpp @@ -1034,6 +1034,11 @@ void ViewerImpl::load(GCodeInputData&& gcode_data) } } + // Populate layer_duration for each vertex from the accumulated layer times + for (PathVertex& v : m_vertices) { + v.layer_duration = m_layers.get_layer_time(m_settings.time_mode, static_cast(v.layer_id)); + } + if (!m_layers.empty()) m_layers.set_view_range(0, static_cast(m_layers.count()) - 1); @@ -1306,6 +1311,10 @@ void ViewerImpl::set_time_mode(ETimeMode mode) { m_settings.time_mode = mode; m_settings.update_colors = true; + // Update layer_duration for all vertices based on the new time mode + for (PathVertex& v : m_vertices) { + v.layer_duration = m_layers.get_layer_time(mode, static_cast(v.layer_id)); + } } void ViewerImpl::set_layers_view_range(Interval::value_type min, Interval::value_type max) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 0774d06324..f2eaba0bb9 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -290,7 +290,7 @@ static std::string to_string(libvgcode::EGCodeExtrusionRole role) } } -void GCodeViewer::SequentialView::Marker::render_position_window(const libvgcode::Viewer* viewer, int canvas_width, int canvas_height) +void GCodeViewer::SequentialView::Marker::render_position_window(const libvgcode::Viewer* viewer, int canvas_width, int canvas_height, const libvgcode::EViewType& view_type) { static float last_window_width = 0.0f; static size_t last_text_length = 0; @@ -307,8 +307,8 @@ void GCodeViewer::SequentialView::Marker::render_position_window(const libvgcode ImGui::SetNextWindowBgAlpha(0.8f); imgui.begin(std::string("ToolPosition"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove); ImGui::AlignTextToFramePadding(); - ImGuiWrapper::text_colored(ImGuiWrapper::COL_ORCA, _u8L("Position") + ":"); - ImGui::SameLine(); + // ImGuiWrapper::text_colored(ImGuiWrapper::COL_ORCA, _u8L("Position") + ":"); + // ImGui::SameLine(); libvgcode::PathVertex vertex = viewer->get_current_vertex(); size_t vertex_id = viewer->get_current_vertex_id(); if (vertex.type == libvgcode::EMoveType::Seam) { @@ -317,9 +317,58 @@ void GCodeViewer::SequentialView::Marker::render_position_window(const libvgcode } char buf[1024]; - sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", vertex.position[0], vertex.position[1], vertex.position[2]); - ImGuiWrapper::text(std::string(buf)); + sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f Speed: %.0f ", vertex.position[0], vertex.position[1], vertex.position[2], vertex.feedrate); + switch (view_type) { + case libvgcode::EViewType::Height: { + sprintf(buf, "%s %s%.2f", buf, _u8L("Height: ").c_str(), vertex.height); + break; + } + case libvgcode::EViewType::Width: { + sprintf(buf, "%s %s%.2f", buf, _u8L("Width: ").c_str(), vertex.width); + break; + } + case libvgcode::EViewType::VolumetricFlowRate: { + sprintf(buf, "%s %s%.2f", buf, _u8L("Flow: ").c_str(), vertex.volumetric_rate()); + break; + } + case libvgcode::EViewType::FanSpeed: { + sprintf(buf, "%s %s%.0f", buf, _u8L("Fan: ").c_str(), vertex.fan_speed); + break; + } + case libvgcode::EViewType::Temperature: { + sprintf(buf, "%s %s%.0f", buf, _u8L("Temperature: ").c_str(), vertex.temperature); + break; + } + case libvgcode::EViewType::LayerTimeLinear: + case libvgcode::EViewType::LayerTimeLogarithmic: { + sprintf(buf, "%s %s%.1f", buf, _u8L("Layer Time: ").c_str(), vertex.layer_duration); + break; + } + case libvgcode::EViewType::Tool: { + sprintf(buf, "%s %s%d", buf, _u8L("Tool: ").c_str(), vertex.extruder_id + 1); + break; + } + case libvgcode::EViewType::ColorPrint: { + sprintf(buf, "%s %s%d", buf, _u8L("Color: ").c_str(), vertex.color_id + 1); + break; + } + case libvgcode::EViewType::ActualVolumetricFlowRate: { + sprintf(buf, "%s %s%.2f", buf, _u8L("Actual Flow: ").c_str(), vertex.actual_volumetric_rate()); + break; + } + case libvgcode::EViewType::ActualSpeed: { + sprintf(buf, "%s %s%.1f", buf, _u8L("Actual Speed: ").c_str(), vertex.actual_feedrate); + break; + } + default: + break; + } + ImGuiWrapper::text(std::string(buf)); + if (view_type == libvgcode::EViewType::FeatureType) { + ImGui::SameLine(); + ImGuiWrapper::text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, to_string(vertex.role).c_str()); + } ImGui::SameLine(); if (imgui.image_button(properties_shown ? ImGui::HorizontalHide : ImGui::HorizontalShow, properties_shown ? _u8L("Hide properties") : _u8L("Show properties"))) { properties_shown = !properties_shown; @@ -723,7 +772,7 @@ void GCodeViewer::SequentialView::render(const bool has_render_path, float legen if (has_render_path && m_show_marker) { // marker.set_world_offset(current_offset); marker.render(canvas_width, canvas_height, view_type); - marker.render_position_window(viewer, canvas_width, canvas_height); + marker.render_position_window(viewer, canvas_width, canvas_height, view_type); } //float bottom = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height(); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index ba4f3702db..dc928b822a 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -103,7 +103,7 @@ public: void set_visible(bool visible) { m_visible = visible; } void render(int canvas_width, int canvas_height, const libvgcode::EViewType& view_type); - void render_position_window(const libvgcode::Viewer* viewer, int canvas_width, int canvas_height); + void render_position_window(const libvgcode::Viewer* viewer, int canvas_width, int canvas_height, const libvgcode::EViewType& view_type); void on_change_color_mode(bool is_dark) { m_is_dark = is_dark; } };