From 9359aa860713463ab0a4c598a4d35df5d47aff1c Mon Sep 17 00:00:00 2001 From: Andrew Sun Date: Sat, 20 Sep 2025 13:48:20 -0400 Subject: [PATCH] Fix nozzle marker position --- src/libslic3r/GCode/GCodeProcessor.cpp | 2 ++ src/libslic3r/GCode/GCodeProcessor.hpp | 1 + src/slic3r/GUI/GCodeViewer.cpp | 6 +++++- src/slic3r/GUI/GCodeViewer.hpp | 4 +++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index b9db43b3b6..36da3764c1 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -1326,6 +1326,8 @@ void GCodeProcessor::process_buffer(const std::string &buffer) void GCodeProcessor::finalize(bool post_process) { + m_result.z_offset = m_z_offset; + // update width/height of wipe moves for (GCodeProcessorResult::MoveVertex& move : m_result.moves) { if (move.type == EMoveType::Wipe) { diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 0dbf14d919..d682762169 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -202,6 +202,7 @@ class Print; int timelapse_warning_code {0}; bool support_traditional_timelapse{true}; float printable_height; + float z_offset; SettingsIds settings_ids; size_t extruders_count; bool backtrace_enabled; diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 142df0555e..8fbf2ef657 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -856,7 +856,6 @@ void GCodeViewer::SequentialView::GCodeWindow::stop_mapping_file() void GCodeViewer::SequentialView::render(const bool has_render_path, float legend_height, const libvgcode::Viewer* viewer, uint32_t gcode_id, int canvas_width, int canvas_height, int right_margin, const libvgcode::EViewType& view_type) { if (has_render_path && m_show_marker) { - // marker.set_world_position(current_position); // marker.set_world_offset(current_offset); marker.render(canvas_width, canvas_height, view_type); @@ -1205,6 +1204,7 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const m_custom_gcode_per_print_z = gcode_result.custom_gcode_per_print_z; m_max_print_height = gcode_result.printable_height; + m_z_offset = gcode_result.z_offset; //BBS: add mutex for protection of gcode result // if (m_layers.empty()) { @@ -1363,6 +1363,7 @@ void GCodeViewer::reset() m_paths_bounding_box = BoundingBoxf3(); m_max_bounding_box = BoundingBoxf3(); m_max_print_height = 0.0f; + m_z_offset = 0.0f; m_extruders_count = 0; // TODO // m_extruder_ids = std::vector(); // TODO m_filament_diameters = std::vector(); @@ -1403,6 +1404,9 @@ void GCodeViewer::render(int canvas_width, int canvas_height, int right_margin) auto current = m_viewer.get_view_visible_range(); // TODO: verify auto endpoints = m_viewer.get_view_full_range(); m_sequential_view.m_show_marker = m_sequential_view.m_show_marker || (current.back() != endpoints.back() && !m_no_render_path); + const libvgcode::PathVertex& curr_vertex = m_viewer.get_current_vertex(); + m_sequential_view.marker.set_world_position(libvgcode::convert(curr_vertex.position)); + m_sequential_view.marker.set_z_offset(m_z_offset + 0.5f); // BBS fixed buttom margin. m_moves_slider.pos_y m_sequential_view.render(!m_no_render_path, legend_height, &m_viewer, m_viewer.get_current_vertex().gcode_id, canvas_width, canvas_height - bottom_margin * m_scale, right_margin * m_scale, m_viewer.get_view_type()); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 978177491f..bf164e3f5e 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -76,7 +76,7 @@ public: // the offset is used to show the correct value of tool position in the "ToolPosition" window // see implementation of render() method Vec3f m_world_offset; - float m_z_offset{ 0.5f }; + float m_z_offset{ 0.0f }; // z offset of the model float m_model_z_offset{ 0.5f }; GCodeProcessorResult::MoveVertex m_curr_move; @@ -97,6 +97,7 @@ public: void set_world_position(const Vec3f& position) { m_world_position = position; } void set_world_offset(const Vec3f& offset) { m_world_offset = offset; } + void set_z_offset(float z_offset) { m_z_offset = z_offset; } #if ENABLE_ACTUAL_SPEED_DEBUG void set_actual_speed_y_range(const std::pair& y_range) { @@ -187,6 +188,7 @@ private: //BBS: add shell bounding box BoundingBoxf3 m_shell_bounding_box; float m_max_print_height{ 0.0f }; + float m_z_offset{ 0.0f }; ConfigOptionMode m_user_mode; bool m_fold = {false};