From a0a0b0d25399b4b037e736ae98ec83dfc8969c02 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 7 Nov 2022 09:58:25 +0100 Subject: [PATCH] Measuring - Keep showing dimensioning after scaling --- src/libslic3r/Measure.hpp | 11 +++++++++++ src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 21 ++++++++++++--------- src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 1 + 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/Measure.hpp b/src/libslic3r/Measure.hpp index d1a0e3866..6d6dca14f 100644 --- a/src/libslic3r/Measure.hpp +++ b/src/libslic3r/Measure.hpp @@ -150,6 +150,17 @@ struct MeasurementResult { bool has_any_data() const { return angle.has_value() || distance_infinite.has_value() || distance_strict.has_value() || distance_xyz.has_value(); } + + void transform(const Transform3d& trafo) { + if (angle.has_value()) + angle->transform(trafo); + if (distance_infinite.has_value()) + distance_infinite->transform(trafo); + if (distance_strict.has_value()) + distance_strict->transform(trafo); + if (distance_xyz.has_value()) + distance_xyz = trafo * *distance_xyz; + } }; // Returns distance/angle between two SurfaceFeatures. diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 858b4e5ce..04e4957d6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -303,14 +303,7 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) if (m_selected_features != selected_features_old && m_selected_features.second.feature.has_value()) { m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); // transform to world coordinates - if (m_measurement_result.angle.has_value()) - m_measurement_result.angle->transform(m_volume_matrix); - if (m_measurement_result.distance_infinite.has_value()) - m_measurement_result.distance_infinite->transform(m_volume_matrix); - if (m_measurement_result.distance_strict.has_value()) - m_measurement_result.distance_strict->transform(m_volume_matrix); - if (m_measurement_result.distance_xyz.has_value()) - m_measurement_result.distance_xyz = TransformHelper::model_to_world(*m_measurement_result.distance_xyz, m_volume_matrix); + m_measurement_result.transform(m_volume_matrix); } return true; @@ -357,7 +350,14 @@ void GLGizmoMeasure::data_changed() m_last_inv_zoom = 0.0f; m_last_plane_idx = -1; - m_selected_features.reset(); + if (m_pending_scale) { + m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get()); + // transform to world coordinates + m_measurement_result.transform(m_volume_matrix); + m_pending_scale = false; + } + else + m_selected_features.reset(); m_selection_raycasters.clear(); m_editing_distance = false; m_is_editing_distance_first_frame = true; @@ -1007,6 +1007,9 @@ void GLGizmoMeasure::render_dimensioning() selection.scale(ratio * Vec3d::Ones(), type); wxGetApp().plater()->canvas3D()->do_scale(""); // avoid storing another snapshot wxGetApp().obj_manipul()->set_dirty(); + + // update measure on next call to data_changed() + m_pending_scale = true; }; auto action_exit = [this]() { m_editing_distance = false; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index 7d20ca26a..4426457ff 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -116,6 +116,7 @@ class GLGizmoMeasure : public GLGizmoBase KeyAutoRepeatFilter m_ctrl_kar_filter; SelectedFeatures m_selected_features; + bool m_pending_scale{ false }; bool m_editing_distance{ false }; bool m_is_editing_distance_first_frame{ true };