From b467e5c2476e7ea01ca8456836b5ad30c211822a Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 26 Sep 2023 10:48:20 +0200 Subject: [PATCH] SPE-1923: Fixed wrong x of tool position when z offset is applied --- src/libslic3r/GCode/GCodeProcessor.cpp | 4 ++++ src/libslic3r/GCode/GCodeProcessor.hpp | 1 + src/slic3r/GUI/GCodeViewer.cpp | 9 ++++++--- src/slic3r/GUI/GCodeViewer.hpp | 13 +++++++++---- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 791efaf835..5fbaa8f036 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -457,6 +457,7 @@ void GCodeProcessorResult::reset() { moves = std::vector(); bed_shape = Pointfs(); max_print_height = 0.0f; + z_offset = 0.0f; settings_ids.reset(); extruders_count = 0; backtrace_enabled = false; @@ -476,6 +477,7 @@ void GCodeProcessorResult::reset() { lines_ends.clear(); bed_shape = Pointfs(); max_print_height = 0.0f; + z_offset = 0.0f; settings_ids.reset(); extruders_count = 0; backtrace_enabled = false; @@ -1304,6 +1306,8 @@ void GCodeProcessor::process_buffer(const std::string &buffer) void GCodeProcessor::finalize(bool perform_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 3829f2fc28..a055eaa347 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -157,6 +157,7 @@ namespace Slic3r { std::vector> lines_ends; Pointfs bed_shape; float max_print_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 e226e27b5f..f23c10faea 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -307,8 +307,8 @@ void GCodeViewer::SequentialView::Marker::init() void GCodeViewer::SequentialView::Marker::set_world_position(const Vec3f& position) { m_world_position = position; - m_world_transform = (Geometry::translation_transform((position + m_z_offset * Vec3f::UnitZ()).cast()) * - Geometry::translation_transform(m_model.get_bounding_box().size().z() * Vec3d::UnitZ()) * Geometry::rotation_transform({ M_PI, 0.0, 0.0 })).cast(); + m_world_transform = (Geometry::translation_transform((position + m_model_z_offset * Vec3f::UnitZ()).cast()) * + Geometry::translation_transform(m_model.get_bounding_box().size().z() * Vec3d::UnitZ()) * Geometry::rotation_transform({ M_PI, 0.0, 0.0 })).cast(); } void GCodeViewer::SequentialView::Marker::render() @@ -351,7 +351,7 @@ void GCodeViewer::SequentialView::Marker::render() imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Tool position") + ":"); ImGui::SameLine(); char buf[1024]; - const Vec3f position = m_world_position + m_world_offset; + const Vec3f position = m_world_position + m_world_offset + m_z_offset * Vec3f::UnitZ(); sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", position.x(), position.y(), position.z()); imgui.text(std::string(buf)); @@ -841,6 +841,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr m_custom_gcode_per_print_z = gcode_result.custom_gcode_per_print_z; m_max_print_height = gcode_result.max_print_height; + m_z_offset = gcode_result.z_offset; load_toolpaths(gcode_result); load_wipetower_shell(print); @@ -1000,6 +1001,7 @@ void GCodeViewer::reset() m_paths_bounding_box.reset(); m_max_bounding_box.reset(); m_max_print_height = 0.0f; + m_z_offset = 0.0f; m_tool_colors = std::vector(); m_extruders_count = 0; m_extruder_ids = std::vector(); @@ -1042,6 +1044,7 @@ void GCodeViewer::render() 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); + m_sequential_view.marker.set_z_offset(m_z_offset); m_sequential_view.render(legend_height); } } diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index c1e9ae874e..56e72f38ff 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -656,11 +656,14 @@ public: GLModel m_model; Vec3f m_world_position; Transform3f m_world_transform; - // for seams, the position of the marker is on the last endpoint of the toolpath containing it - // the offset is used to show the correct value of tool position in the "ToolPosition" window - // see implementation of render() method + // For seams, the position of the marker is on the last endpoint of the toolpath containing it. + // This 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 }; + // z offset of the print + float m_z_offset{ 0.0f }; + // z offset of the model + float m_model_z_offset{ 0.5f }; bool m_visible{ true }; public: @@ -670,6 +673,7 @@ public: void set_world_position(const Vec3f& position); void set_world_offset(const Vec3f& offset) { m_world_offset = offset; } + void set_z_offset(float z_offset) { m_z_offset = z_offset; } bool is_visible() const { return m_visible; } void set_visible(bool visible) { m_visible = visible; } @@ -773,6 +777,7 @@ private: // bounding box of toolpaths + marker tools + shells BoundingBoxf3 m_max_bounding_box; float m_max_print_height{ 0.0f }; + float m_z_offset{ 0.0f }; std::vector m_tool_colors; Layers m_layers; std::array m_layers_z_range;