From 083df84009b0813483e02ab81b60f033419ac314 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 8 Nov 2022 08:22:16 +0100 Subject: [PATCH 1/7] Removed duplicated code into SceneRaycaster --- src/slic3r/GUI/SceneRaycaster.cpp | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/src/slic3r/GUI/SceneRaycaster.cpp b/src/slic3r/GUI/SceneRaycaster.cpp index 96ae536ca..a92c622c1 100644 --- a/src/slic3r/GUI/SceneRaycaster.cpp +++ b/src/slic3r/GUI/SceneRaycaster.cpp @@ -228,35 +228,6 @@ int SceneRaycaster::base_id(EType type) return -1; } -#if ENABLE_RAYCAST_PICKING_DEBUG -size_t SceneRaycaster::active_beds_count() const -{ - size_t count = 0; - for (const auto& item : m_bed) { - if (item->is_active()) ++count; - } - return count; -} - -size_t SceneRaycaster::active_volumes_count() const -{ - size_t count = 0; - for (const auto& item : m_volumes) { - if (item->is_active()) ++count; - } - return count; -} - -size_t SceneRaycaster::active_gizmos_count() const -{ - size_t count = 0; - for (const auto& item : m_gizmos) { - if (item->is_active()) ++count; - } - return count; -} -#endif // ENABLE_RAYCAST_PICKING_DEBUG - int SceneRaycaster::encode_id(EType type, int id) { return base_id(type) + id; } int SceneRaycaster::decode_id(EType type, int id) { return id - base_id(type); } From 8681770eaacc064737919085e4448c055920b5e6 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 8 Nov 2022 09:05:57 +0100 Subject: [PATCH 2/7] Tech ENABLE_NEW_CAMERA_MOVEMENTS set as default --- src/libslic3r/Technologies.hpp | 2 -- src/slic3r/GUI/GLCanvas3D.cpp | 14 -------------- 2 files changed, 16 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index e390ff209..a3e72cf0c 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -55,8 +55,6 @@ #define ENABLE_RELOAD_FROM_DISK_REWORK (1 && ENABLE_2_5_0_ALPHA1) // Enable editing volumes transformation in world coordinates and instances in local coordinates #define ENABLE_WORLD_COORDINATE (1 && ENABLE_2_5_0_ALPHA1) -// Enable modified camera control using mouse -#define ENABLE_NEW_CAMERA_MOVEMENTS (1 && ENABLE_2_5_0_ALPHA1) // Enable alternative version of file_wildcards() #define ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR (1 && ENABLE_2_5_0_ALPHA1) // Enable processing of gcode G2 and G3 lines diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index a5698f67b..560532e92 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2997,7 +2997,6 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) // set_cursor(Standard); } else if (keyCode == WXK_CONTROL) { -#if ENABLE_NEW_CAMERA_MOVEMENTS #if ENABLE_RAYCAST_PICKING if (m_mouse.dragging && !m_moving) { #else @@ -3008,7 +3007,6 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) m_mouse.drag.move_volume_idx = -1; m_mouse.set_start_position_3D_as_invalid(); } -#endif // ENABLE_NEW_CAMERA_MOVEMENTS m_ctrl_kar_filter.reset_count(); m_dirty = true; } @@ -3515,10 +3513,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_volumes.volumes[volume_idx]->hover = GLVolume::HS_None; // The dragging operation is initiated. m_mouse.drag.move_volume_idx = volume_idx; -#if ENABLE_NEW_CAMERA_MOVEMENTS m_selection.setup_cache(); if (!evt.CmdDown()) -#endif // ENABLE_NEW_CAMERA_MOVEMENTS m_mouse.drag.start_position_3D = m_mouse.scene_position; m_sequential_print_clearance_first_displacement = true; #if !ENABLE_RAYCAST_PICKING @@ -3529,12 +3525,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } } -#if ENABLE_NEW_CAMERA_MOVEMENTS else if (evt.Dragging() && evt.LeftIsDown() && !evt.CmdDown() && m_layers_editing.state == LayersEditing::Unknown && m_mouse.drag.move_volume_idx != -1 && m_mouse.is_start_position_3D_defined()) { -#else - else if (evt.Dragging() && evt.LeftIsDown() && m_layers_editing.state == LayersEditing::Unknown && m_mouse.drag.move_volume_idx != -1) { -#endif // ENABLE_NEW_CAMERA_MOVEMENTS if (!m_mouse.drag.move_requires_threshold) { m_mouse.dragging = true; Vec3d cur_pos = m_mouse.drag.start_position_3D; @@ -3602,18 +3594,12 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } // do not process the dragging if the left mouse was set down in another canvas -#if ENABLE_NEW_CAMERA_MOVEMENTS else if (evt.LeftIsDown()) { // if dragging over blank area with left button, rotate #if ENABLE_RAYCAST_PICKING if (!m_moving) { #endif // ENABLE_RAYCAST_PICKING if ((any_gizmo_active || evt.CmdDown() || m_hover_volume_idxs.empty()) && m_mouse.is_start_position_3D_defined()) { -#else - // if dragging over blank area with left button, rotate - else if (evt.LeftIsDown()) { - if ((any_gizmo_active || m_hover_volume_idxs.empty()) && m_mouse.is_start_position_3D_defined()) { -#endif // ENABLE_NEW_CAMERA_MOVEMENTS const Vec3d rot = (Vec3d(pos.x(), pos.y(), 0.0) - m_mouse.drag.start_position_3D) * (PI * TRACKBALLSIZE / 180.0); if (wxGetApp().app_config->get("use_free_camera") == "1") // Virtual track ball (similar to the 3DConnexion mouse). From 38ecef036a7b9c13aa448e651584f1592f6275cb Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 8 Nov 2022 11:13:48 +0100 Subject: [PATCH 3/7] Measure Gizmo - Fixed unwanted volume displacement when click and dragging outside of an highlighted feature --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 3fa8d8d6f..37df5a31d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -310,6 +310,10 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) return true; } + else + // if the mouse pointer is on any volume, filter out the event to prevent the user to move it + // equivalent tp: return (m_parent.get_first_hover_volume_idx() != -1); + return m_curr_feature.has_value(); // fix: prevent restart gizmo when reselect object // take responsibility for left up From 46e84dfd3576c74e04ecc858cb879764e7f9b673 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 8 Nov 2022 12:02:46 +0100 Subject: [PATCH 4/7] Read from hint database file in binary style --- src/slic3r/GUI/HintNotification.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/HintNotification.cpp b/src/slic3r/GUI/HintNotification.cpp index 2e4a6d263..df955fa93 100644 --- a/src/slic3r/GUI/HintNotification.cpp +++ b/src/slic3r/GUI/HintNotification.cpp @@ -86,7 +86,7 @@ void read_used_binary(std::vector& ids) BOOST_LOG_TRIVIAL(warning) << "Failed to load to hints.cereal. File does not exists. " << path.string(); return; } - boost::nowide::ifstream file(path.string()); + boost::nowide::ifstream file(path.string(), std::ios::binary); cereal::BinaryInputArchive archive(file); HintsCerealData cd; try From 41c6da913df5ed3cad144063334f4288b106e331 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 8 Nov 2022 12:16:58 +0100 Subject: [PATCH 5/7] Measure Gizmo - Release m_measuring content when leaving the gizmo --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 37df5a31d..699d6776f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -405,6 +405,9 @@ void GLGizmoMeasure::on_set_state() restore_scene_raycasters_state(); m_editing_distance = false; m_is_editing_distance_first_frame = true; + m_measuring.reset(); + + int a = 0; } else { m_mode = EMode::BasicSelection; From a09c2695842609ee5c01cbf7dda26b0372e6d702 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 8 Nov 2022 12:15:14 +0100 Subject: [PATCH 6/7] Measurement: make the edge endpoint detection threshold smaller for short edges --- src/libslic3r/Measure.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index fc27f0383..26de9f0a6 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -10,7 +10,6 @@ namespace Measure { constexpr double feature_hover_limit = 0.5; // how close to a feature the mouse must be to highlight it -constexpr double edge_endpoint_limit = 0.5; // how close to an edge endpoint the mouse ... static std::pair get_center_and_radius(const std::vector& border, int start_idx, int end_idx, const Transform3d& trafo) { @@ -467,6 +466,8 @@ std::optional MeasuringImpl::get_feature(size_t face_idx, const MeasurementResult res; SurfaceFeature point_sf(point); + assert(plane.surface_features.empty() || plane.surface_features.back().get_type() == SurfaceFeatureType::Plane); + for (size_t i=0; i MeasuringImpl::get_feature(size_t face_idx, const const SurfaceFeature& f = plane.surface_features[closest_feature_idx]; if (f.get_type() == SurfaceFeatureType::Edge) { // If this is an edge, check if we are not close to the endpoint. If so, - // we will include the endpoint as well. - constexpr double limit_sq = edge_endpoint_limit * edge_endpoint_limit; + // we will include the endpoint as well. Close = 10% of the lenghth of + // the edge, clamped between 0.025 and 0.5 mm. const auto& [sp, ep] = f.get_edge(); + double len_sq = (ep-sp).squaredNorm(); + double limit_sq = std::max(0.025*0.025, std::min(0.5*0.5, 0.1 * 0.1 * len_sq)); + if ((point-sp).squaredNorm() < limit_sq) return std::make_optional(SurfaceFeature(sp)); if ((point-ep).squaredNorm() < limit_sq) From 2ce76e27dd4acf466957452a2afcbbd9a613decb Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 8 Nov 2022 13:08:30 +0100 Subject: [PATCH 7/7] Measure Gizmo - Fixed volume's color blinking when pressing SHIFT key --- src/slic3r/GUI/GLCanvas3D.cpp | 24 ++++++++++++++---------- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 2 -- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 560532e92..91fc0f748 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -6705,6 +6705,10 @@ void GLCanvas3D::_render_selection_sidebar_hints() void GLCanvas3D::_update_volumes_hover_state() { + // skip update if the Gizmo Measure is active + if (m_gizmos.get_current_type() == GLGizmosManager::Measure) + return; + for (GLVolume* v : m_volumes.volumes) { v->hover = GLVolume::HS_None; } @@ -6712,9 +6716,9 @@ void GLCanvas3D::_update_volumes_hover_state() if (m_hover_volume_idxs.empty()) return; - bool ctrl_pressed = wxGetKeyState(WXK_CONTROL); // additive select/deselect - bool shift_pressed = wxGetKeyState(WXK_SHIFT); // select by rectangle - bool alt_pressed = wxGetKeyState(WXK_ALT); // deselect by rectangle + const bool ctrl_pressed = wxGetKeyState(WXK_CONTROL); + const bool shift_pressed = wxGetKeyState(WXK_SHIFT); + const bool alt_pressed = wxGetKeyState(WXK_ALT); if (alt_pressed && (shift_pressed || ctrl_pressed)) { // illegal combinations of keys @@ -6749,22 +6753,22 @@ void GLCanvas3D::_update_volumes_hover_state() if (volume.hover != GLVolume::HS_None) continue; - bool deselect = volume.selected && ((shift_pressed && m_rectangle_selection.is_empty()) || (alt_pressed && !m_rectangle_selection.is_empty())); - bool select = !volume.selected && (m_rectangle_selection.is_empty() || (shift_pressed && !m_rectangle_selection.is_empty())); + const bool deselect = volume.selected && ((shift_pressed && m_rectangle_selection.is_empty()) || (alt_pressed && !m_rectangle_selection.is_empty())); + const bool select = !volume.selected && (m_rectangle_selection.is_empty() || (shift_pressed && !m_rectangle_selection.is_empty())); if (select || deselect) { - bool as_volume = + const bool as_volume = volume.is_modifier && hover_from_single_instance && !ctrl_pressed && ( - (!deselect) || - (deselect && !m_selection.is_single_full_instance() && (volume.object_idx() == m_selection.get_object_idx()) && (volume.instance_idx() == m_selection.get_instance_idx())) + !deselect || + (deselect && !m_selection.is_single_full_instance() && volume.object_idx() == m_selection.get_object_idx() && volume.instance_idx() == m_selection.get_instance_idx()) ); if (as_volume) volume.hover = deselect ? GLVolume::HS_Deselect : GLVolume::HS_Select; else { - int object_idx = volume.object_idx(); - int instance_idx = volume.instance_idx(); + const int object_idx = volume.object_idx(); + const int instance_idx = volume.instance_idx(); for (GLVolume* v : m_volumes.volumes) { if (v->object_idx() == object_idx && v->instance_idx() == instance_idx) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 699d6776f..895304e5a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -406,8 +406,6 @@ void GLGizmoMeasure::on_set_state() m_editing_distance = false; m_is_editing_distance_first_frame = true; m_measuring.reset(); - - int a = 0; } else { m_mode = EMode::BasicSelection;