From a4ad0a0925bbe52d2a1f69510664a69251caac53 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 3 Jan 2020 11:41:29 +0100 Subject: [PATCH] Fixed unresponsive 3Dconnexion device when switching to preview --- src/slic3r/GUI/GUI_Preview.cpp | 5 ----- src/slic3r/GUI/GUI_Preview.hpp | 1 - src/slic3r/GUI/Mouse3DController.cpp | 14 ++++++-------- src/slic3r/GUI/Mouse3DController.hpp | 5 ++--- src/slic3r/GUI/Plater.cpp | 17 ++++++++++++++++- src/slic3r/GUI/Plater.hpp | 2 ++ 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 2eb316be0..1a4d12d31 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -341,11 +341,6 @@ void Preview::set_number_extruders(unsigned int number_extruders) } } -void Preview::set_canvas_as_dirty() -{ - m_canvas->set_as_dirty(); -} - void Preview::set_enabled(bool enabled) { m_enabled = enabled; diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index b0dac4223..92ec15b22 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -116,7 +116,6 @@ public: void set_as_dirty(); void set_number_extruders(unsigned int number_extruders); - void set_canvas_as_dirty(); void set_enabled(bool enabled); void bed_shape_changed(); void select_view(const std::string& direction); diff --git a/src/slic3r/GUI/Mouse3DController.cpp b/src/slic3r/GUI/Mouse3DController.cpp index 20eaa3d91..e91b6175f 100644 --- a/src/slic3r/GUI/Mouse3DController.cpp +++ b/src/slic3r/GUI/Mouse3DController.cpp @@ -112,7 +112,7 @@ void Mouse3DController::State::append_button(unsigned int id) bool Mouse3DController::State::process_mouse_wheel() { - if (m_mouse_wheel_counter == 0) + if (m_mouse_wheel_counter.load() == 0) return false; else if (!m_rotation.queue.empty()) { @@ -120,7 +120,7 @@ bool Mouse3DController::State::process_mouse_wheel() return true; } - m_mouse_wheel_counter = 0; + m_mouse_wheel_counter.store(0); return true; } @@ -229,8 +229,6 @@ bool Mouse3DController::apply(Camera& camera) if (!m_initialized) return false; - std::lock_guard lock(m_mutex); - // check if the user unplugged the device if (!m_running && is_device_connected()) { @@ -393,7 +391,7 @@ void Mouse3DController::render_settings_dialog(unsigned int canvas_width, unsign bool Mouse3DController::connect_device() { - static const long long DETECTION_TIME_MS = 2000; // seconds + static const long long DETECTION_TIME_MS = 2000; // two seconds if (is_device_connected()) return false; @@ -694,7 +692,6 @@ void Mouse3DController::run() collect_input(); } } - void Mouse3DController::collect_input() { DataPacket packet = { 0 }; @@ -709,8 +706,6 @@ void Mouse3DController::collect_input() if (!wxGetApp().IsActive()) return; - std::lock_guard lock(m_mutex); - bool updated = false; if (res == 7) @@ -726,8 +721,11 @@ void Mouse3DController::collect_input() #endif // ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT if (updated) + { + wxGetApp().plater()->set_current_canvas_as_dirty(); // ask for an idle event to update 3D scene wxWakeUpIdle(); + } } bool Mouse3DController::handle_packet(const DataPacket& packet) diff --git a/src/slic3r/GUI/Mouse3DController.hpp b/src/slic3r/GUI/Mouse3DController.hpp index 543c44e77..9e5161ee7 100644 --- a/src/slic3r/GUI/Mouse3DController.hpp +++ b/src/slic3r/GUI/Mouse3DController.hpp @@ -72,7 +72,7 @@ class Mouse3DController // Mouse3DController::collect_input() through the call to the append_rotation() method // GLCanvas3D::on_mouse_wheel() through the call to the process_mouse_wheel() method // GLCanvas3D::on_idle() through the call to the apply() method - unsigned int m_mouse_wheel_counter; + std::atomic m_mouse_wheel_counter; #if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT size_t m_translation_queue_max_size; @@ -128,7 +128,6 @@ class Mouse3DController bool m_initialized; mutable State m_state; - std::mutex m_mutex; std::thread m_thread; hid_device* m_device; std::string m_device_str; @@ -151,7 +150,7 @@ public: bool is_device_connected() const { return m_device != nullptr; } bool is_running() const { return m_running; } - bool process_mouse_wheel() { std::lock_guard lock(m_mutex); return m_state.process_mouse_wheel(); } + bool process_mouse_wheel() { return m_state.process_mouse_wheel(); } bool apply(Camera& camera); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 8051b73ec..b0fb3f0e6 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1855,6 +1855,8 @@ struct Plater::priv bool is_preview_loaded() const { return preview->is_loaded(); } bool is_view3D_shown() const { return current_panel == view3D; } + void set_current_canvas_as_dirty(); + #if ENABLE_VIEW_TOOLBAR_BACKGROUND_FIX bool init_view_toolbar(); #endif // ENABLE_VIEW_TOOLBAR_BACKGROUND_FIX @@ -3472,7 +3474,7 @@ void Plater::priv::set_current_panel(wxPanel* panel) // keeps current gcode preview, if any preview->reload_print(true); - preview->set_canvas_as_dirty(); + preview->set_as_dirty(); view_toolbar.select_item("Preview"); } @@ -3985,6 +3987,14 @@ bool Plater::priv::complit_init_part_menu() return true; } +void Plater::priv::set_current_canvas_as_dirty() +{ + if (current_panel == view3D) + view3D->set_as_dirty(); + else if (current_panel == preview) + preview->set_as_dirty(); +} + #if ENABLE_VIEW_TOOLBAR_BACKGROUND_FIX bool Plater::priv::init_view_toolbar() #else @@ -5368,6 +5378,11 @@ BoundingBoxf Plater::bed_shape_bb() const return p->bed_shape_bb(); } +void Plater::set_current_canvas_as_dirty() +{ + p->set_current_canvas_as_dirty(); +} + PrinterTechnology Plater::printer_technology() const { return p->printer_technology; diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index d9a9af376..479397705 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -240,6 +240,8 @@ public: GLCanvas3D* canvas3D(); BoundingBoxf bed_shape_bb() const; + void set_current_canvas_as_dirty(); + PrinterTechnology printer_technology() const; void set_printer_technology(PrinterTechnology printer_technology);