QoL: improve gcode marker (#11881)

QoL: Improve gcode marker
This commit is contained in:
SoftFever
2026-01-09 11:52:30 +08:00
committed by GitHub
parent 7ac84b1f17
commit 779f4a890d
6 changed files with 71 additions and 7 deletions

View File

@@ -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<float>(m_layer_id), //layer_duration: set later
std::max<unsigned int>(1, m_layer_id) - 1,
internal_only,
m_object_label_id,

View File

@@ -185,6 +185,7 @@ class Print;
float fan_speed{ 0.0f }; // percentage
float temperature{ 0.0f }; // Celsius degrees
std::array<float, static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count)> time{ 0.0f, 0.0f }; // s
float layer_duration{ 0.0f }; // s
unsigned int layer_id{ 0 };
bool internal_only{ false };

View File

@@ -82,6 +82,10 @@ struct PathVertex
// Segment estimated times
//
std::array<float, TIME_MODES_COUNT> times{ 0.0f, 0.0f };
//
// Layer duration in seconds
//
float layer_duration{ 0.0f };
//
// Return true if the segment is an extrusion move

View File

@@ -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<size_t>(v.layer_id));
}
if (!m_layers.empty())
m_layers.set_view_range(0, static_cast<uint32_t>(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<size_t>(v.layer_id));
}
}
void ViewerImpl::set_layers_view_range(Interval::value_type min, Interval::value_type max)

View File

@@ -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();

View File

@@ -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; }
};