Fixed unresponsive 3Dconnexion device when switching to preview

This commit is contained in:
Enrico Turri 2020-01-03 11:41:29 +01:00
parent 3fb9fd4e30
commit a4ad0a0925
6 changed files with 26 additions and 18 deletions

View File

@ -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) void Preview::set_enabled(bool enabled)
{ {
m_enabled = enabled; m_enabled = enabled;

View File

@ -116,7 +116,6 @@ public:
void set_as_dirty(); void set_as_dirty();
void set_number_extruders(unsigned int number_extruders); void set_number_extruders(unsigned int number_extruders);
void set_canvas_as_dirty();
void set_enabled(bool enabled); void set_enabled(bool enabled);
void bed_shape_changed(); void bed_shape_changed();
void select_view(const std::string& direction); void select_view(const std::string& direction);

View File

@ -112,7 +112,7 @@ void Mouse3DController::State::append_button(unsigned int id)
bool Mouse3DController::State::process_mouse_wheel() bool Mouse3DController::State::process_mouse_wheel()
{ {
if (m_mouse_wheel_counter == 0) if (m_mouse_wheel_counter.load() == 0)
return false; return false;
else if (!m_rotation.queue.empty()) else if (!m_rotation.queue.empty())
{ {
@ -120,7 +120,7 @@ bool Mouse3DController::State::process_mouse_wheel()
return true; return true;
} }
m_mouse_wheel_counter = 0; m_mouse_wheel_counter.store(0);
return true; return true;
} }
@ -229,8 +229,6 @@ bool Mouse3DController::apply(Camera& camera)
if (!m_initialized) if (!m_initialized)
return false; return false;
std::lock_guard<std::mutex> lock(m_mutex);
// check if the user unplugged the device // check if the user unplugged the device
if (!m_running && is_device_connected()) if (!m_running && is_device_connected())
{ {
@ -393,7 +391,7 @@ void Mouse3DController::render_settings_dialog(unsigned int canvas_width, unsign
bool Mouse3DController::connect_device() 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()) if (is_device_connected())
return false; return false;
@ -694,7 +692,6 @@ void Mouse3DController::run()
collect_input(); collect_input();
} }
} }
void Mouse3DController::collect_input() void Mouse3DController::collect_input()
{ {
DataPacket packet = { 0 }; DataPacket packet = { 0 };
@ -709,8 +706,6 @@ void Mouse3DController::collect_input()
if (!wxGetApp().IsActive()) if (!wxGetApp().IsActive())
return; return;
std::lock_guard<std::mutex> lock(m_mutex);
bool updated = false; bool updated = false;
if (res == 7) if (res == 7)
@ -726,8 +721,11 @@ void Mouse3DController::collect_input()
#endif // ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT #endif // ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT
if (updated) if (updated)
{
wxGetApp().plater()->set_current_canvas_as_dirty();
// ask for an idle event to update 3D scene // ask for an idle event to update 3D scene
wxWakeUpIdle(); wxWakeUpIdle();
}
} }
bool Mouse3DController::handle_packet(const DataPacket& packet) bool Mouse3DController::handle_packet(const DataPacket& packet)

View File

@ -72,7 +72,7 @@ class Mouse3DController
// Mouse3DController::collect_input() through the call to the append_rotation() method // 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_mouse_wheel() through the call to the process_mouse_wheel() method
// GLCanvas3D::on_idle() through the call to the apply() method // GLCanvas3D::on_idle() through the call to the apply() method
unsigned int m_mouse_wheel_counter; std::atomic<unsigned int> m_mouse_wheel_counter;
#if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT #if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT
size_t m_translation_queue_max_size; size_t m_translation_queue_max_size;
@ -128,7 +128,6 @@ class Mouse3DController
bool m_initialized; bool m_initialized;
mutable State m_state; mutable State m_state;
std::mutex m_mutex;
std::thread m_thread; std::thread m_thread;
hid_device* m_device; hid_device* m_device;
std::string m_device_str; std::string m_device_str;
@ -151,7 +150,7 @@ public:
bool is_device_connected() const { return m_device != nullptr; } bool is_device_connected() const { return m_device != nullptr; }
bool is_running() const { return m_running; } bool is_running() const { return m_running; }
bool process_mouse_wheel() { std::lock_guard<std::mutex> lock(m_mutex); return m_state.process_mouse_wheel(); } bool process_mouse_wheel() { return m_state.process_mouse_wheel(); }
bool apply(Camera& camera); bool apply(Camera& camera);

View File

@ -1855,6 +1855,8 @@ struct Plater::priv
bool is_preview_loaded() const { return preview->is_loaded(); } bool is_preview_loaded() const { return preview->is_loaded(); }
bool is_view3D_shown() const { return current_panel == view3D; } bool is_view3D_shown() const { return current_panel == view3D; }
void set_current_canvas_as_dirty();
#if ENABLE_VIEW_TOOLBAR_BACKGROUND_FIX #if ENABLE_VIEW_TOOLBAR_BACKGROUND_FIX
bool init_view_toolbar(); bool init_view_toolbar();
#endif // ENABLE_VIEW_TOOLBAR_BACKGROUND_FIX #endif // ENABLE_VIEW_TOOLBAR_BACKGROUND_FIX
@ -3472,7 +3474,7 @@ void Plater::priv::set_current_panel(wxPanel* panel)
// keeps current gcode preview, if any // keeps current gcode preview, if any
preview->reload_print(true); preview->reload_print(true);
preview->set_canvas_as_dirty(); preview->set_as_dirty();
view_toolbar.select_item("Preview"); view_toolbar.select_item("Preview");
} }
@ -3985,6 +3987,14 @@ bool Plater::priv::complit_init_part_menu()
return true; 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 #if ENABLE_VIEW_TOOLBAR_BACKGROUND_FIX
bool Plater::priv::init_view_toolbar() bool Plater::priv::init_view_toolbar()
#else #else
@ -5368,6 +5378,11 @@ BoundingBoxf Plater::bed_shape_bb() const
return p->bed_shape_bb(); return p->bed_shape_bb();
} }
void Plater::set_current_canvas_as_dirty()
{
p->set_current_canvas_as_dirty();
}
PrinterTechnology Plater::printer_technology() const PrinterTechnology Plater::printer_technology() const
{ {
return p->printer_technology; return p->printer_technology;

View File

@ -240,6 +240,8 @@ public:
GLCanvas3D* canvas3D(); GLCanvas3D* canvas3D();
BoundingBoxf bed_shape_bb() const; BoundingBoxf bed_shape_bb() const;
void set_current_canvas_as_dirty();
PrinterTechnology printer_technology() const; PrinterTechnology printer_technology() const;
void set_printer_technology(PrinterTechnology printer_technology); void set_printer_technology(PrinterTechnology printer_technology);