diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 3d1234cbfc..64c5ce953d 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -59,4 +59,13 @@ // Enable not applying volume transformation during 3mf and amf loading, but keeping it as a ModelVolume member #define ENABLE_KEEP_LOADED_VOLUME_TRANSFORM_AS_STAND_ALONE (1 && ENABLE_2_2_0_ALPHA1) + +//================== +// 2.2.0.beta1 techs +//================== +#define ENABLE_2_2_0_BETA1 1 + +// Enable using Y axis of 3Dconnexion devices as zoom +#define ENABLE_3DCONNEXION_Y_AS_ZOOM (1 && ENABLE_2_2_0_BETA1) + #endif // _technologies_h_ diff --git a/src/slic3r/GUI/AppConfig.cpp b/src/slic3r/GUI/AppConfig.cpp index 7055822513..eb0a7fca69 100644 --- a/src/slic3r/GUI/AppConfig.cpp +++ b/src/slic3r/GUI/AppConfig.cpp @@ -271,7 +271,11 @@ void AppConfig::set_recent_projects(const std::vector& recent_proje } } +#if ENABLE_3DCONNEXION_Y_AS_ZOOM +void AppConfig::set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone, double zoom_speed) +#else void AppConfig::set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone) +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM { std::string key = std::string("mouse_device:") + name; auto it = m_storage.find(key); @@ -283,6 +287,9 @@ void AppConfig::set_mouse_device(const std::string& name, double translation_spe it->second["translation_deadzone"] = std::to_string(translation_deadzone); it->second["rotation_speed"] = std::to_string(rotation_speed); it->second["rotation_deadzone"] = std::to_string(rotation_deadzone); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + it->second["zoom_speed"] = std::to_string(zoom_speed); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM } bool AppConfig::get_mouse_device_translation_speed(const std::string& name, double& speed) @@ -345,6 +352,23 @@ bool AppConfig::get_mouse_device_rotation_deadzone(const std::string& name, floa return true; } +#if ENABLE_3DCONNEXION_Y_AS_ZOOM +bool AppConfig::get_mouse_device_zoom_speed(const std::string& name, double& speed) +{ + std::string key = std::string("mouse_device:") + name; + auto it = m_storage.find(key); + if (it == m_storage.end()) + return false; + + auto it_val = it->second.find("zoom_speed"); + if (it_val == it->second.end()) + return false; + + speed = (float)::atof(it_val->second.c_str()); + return true; +} +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM + void AppConfig::update_config_dir(const std::string &dir) { this->set("recent", "config_directory", dir); diff --git a/src/slic3r/GUI/AppConfig.hpp b/src/slic3r/GUI/AppConfig.hpp index 3553704506..b432367b66 100644 --- a/src/slic3r/GUI/AppConfig.hpp +++ b/src/slic3r/GUI/AppConfig.hpp @@ -131,11 +131,18 @@ public: std::vector get_recent_projects() const; void set_recent_projects(const std::vector& recent_projects); - void set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone); - bool get_mouse_device_translation_speed(const std::string& name, double& speed); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + void set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone, double zoom_speed); +#else + void set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM + bool get_mouse_device_translation_speed(const std::string& name, double& speed); bool get_mouse_device_translation_deadzone(const std::string& name, double& deadzone); bool get_mouse_device_rotation_speed(const std::string& name, float& speed); bool get_mouse_device_rotation_deadzone(const std::string& name, float& deadzone); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + bool get_mouse_device_zoom_speed(const std::string& name, double& speed); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM static const std::string SECTION_FILAMENTS; static const std::string SECTION_MATERIALS; diff --git a/src/slic3r/GUI/Mouse3DController.cpp b/src/slic3r/GUI/Mouse3DController.cpp index e91b6175f8..707a1d143a 100644 --- a/src/slic3r/GUI/Mouse3DController.cpp +++ b/src/slic3r/GUI/Mouse3DController.cpp @@ -57,13 +57,19 @@ const double Mouse3DController::State::DefaultTranslationScale = 2.5; const double Mouse3DController::State::MaxTranslationDeadzone = 0.2; const double Mouse3DController::State::DefaultTranslationDeadzone = 0.5 * Mouse3DController::State::MaxTranslationDeadzone; const float Mouse3DController::State::DefaultRotationScale = 1.0f; -const float Mouse3DController::State::MaxRotationDeadzone = (float)Mouse3DController::State::MaxTranslationDeadzone; +const float Mouse3DController::State::MaxRotationDeadzone = 0.2f; const float Mouse3DController::State::DefaultRotationDeadzone = 0.5f * Mouse3DController::State::MaxRotationDeadzone; +#if ENABLE_3DCONNEXION_Y_AS_ZOOM +const double Mouse3DController::State::DefaultZoomScale = 0.1; +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM Mouse3DController::State::State() : m_buttons_enabled(false) , m_translation_params(DefaultTranslationScale, DefaultTranslationDeadzone) , m_rotation_params(DefaultRotationScale, DefaultRotationDeadzone) +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + , m_zoom_params(DefaultZoomScale, 0.0) +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM , m_mouse_wheel_counter(0) #if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT , m_translation_queue_max_size(0) @@ -149,7 +155,13 @@ bool Mouse3DController::State::apply(Camera& camera) if (has_translation()) { const Vec3d& translation = m_translation.queue.front(); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + camera.set_target(camera.get_target() + m_translation_params.scale * (translation(0) * camera.get_dir_right() + translation(2) * camera.get_dir_up())); + if (translation(1) != 0.0) + camera.update_zoom(m_zoom_params.scale * translation(1) / std::abs(translation(1))); +#else camera.set_target(camera.get_target() + m_translation_params.scale * (translation(0) * camera.get_dir_right() + translation(1) * camera.get_dir_forward() + translation(2) * camera.get_dir_up())); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM m_translation.queue.pop(); ret = true; } @@ -309,20 +321,30 @@ void Mouse3DController::render_settings_dialog(unsigned int canvas_width, unsign ImGui::PopStyleColor(); float translation_scale = (float)m_state.get_translation_scale() / State::DefaultTranslationScale; - if (imgui.slider_float(_(L("Translation")) + "##1", &translation_scale, 0.5f, 5.0f, "%.1f")) + if (imgui.slider_float(_(L("Translation")) + "##1", &translation_scale, 0.2f, 5.0f, "%.1f")) m_state.set_translation_scale(State::DefaultTranslationScale * (double)translation_scale); float rotation_scale = m_state.get_rotation_scale() / State::DefaultRotationScale; - if (imgui.slider_float(_(L("Rotation")) + "##1", &rotation_scale, 0.5f, 5.0f, "%.1f")) + if (imgui.slider_float(_(L("Rotation")) + "##1", &rotation_scale, 0.2f, 5.0f, "%.1f")) m_state.set_rotation_scale(State::DefaultRotationScale * rotation_scale); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + float zoom_scale = m_state.get_zoom_scale() / State::DefaultZoomScale; + if (imgui.slider_float(_(L("Zoom")), &zoom_scale, 0.2f, 5.0f, "%.1f")) + m_state.set_zoom_scale(State::DefaultZoomScale * zoom_scale); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM + ImGui::Separator(); ImGui::PushStyleColor(ImGuiCol_Text, color); imgui.text(_(L("Deadzone:"))); ImGui::PopStyleColor(); float translation_deadzone = (float)m_state.get_translation_deadzone(); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + if (imgui.slider_float(_(L("Translation")) + "/" + _(L("Zoom")), &translation_deadzone, 0.0f, (float)State::MaxTranslationDeadzone, "%.2f")) +#else if (imgui.slider_float(_(L("Translation")) + "##2", &translation_deadzone, 0.0f, (float)State::MaxTranslationDeadzone, "%.2f")) +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM m_state.set_translation_deadzone((double)translation_deadzone); float rotation_deadzone = m_state.get_rotation_deadzone(); @@ -629,15 +651,24 @@ bool Mouse3DController::connect_device() float rotation_speed = 1.0; double translation_deadzone = State::DefaultTranslationDeadzone; float rotation_deadzone = State::DefaultRotationDeadzone; +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + double zoom_speed = 1.0; +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM wxGetApp().app_config->get_mouse_device_translation_speed(m_device_str, translation_speed); wxGetApp().app_config->get_mouse_device_translation_deadzone(m_device_str, translation_deadzone); wxGetApp().app_config->get_mouse_device_rotation_speed(m_device_str, rotation_speed); wxGetApp().app_config->get_mouse_device_rotation_deadzone(m_device_str, rotation_deadzone); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + wxGetApp().app_config->get_mouse_device_zoom_speed(m_device_str, zoom_speed); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM // clamp to valid values - m_state.set_translation_scale(State::DefaultTranslationScale * std::max(0.5, std::min(2.0, translation_speed))); - m_state.set_translation_deadzone(std::max(0.0, std::min(State::MaxTranslationDeadzone, translation_deadzone))); - m_state.set_rotation_scale(State::DefaultRotationScale * std::max(0.5f, std::min(2.0f, rotation_speed))); - m_state.set_rotation_deadzone(std::max(0.0f, std::min(State::MaxRotationDeadzone, rotation_deadzone))); + m_state.set_translation_scale(State::DefaultTranslationScale * std::clamp(translation_speed, 0.2, 5.0)); + m_state.set_translation_deadzone(std::clamp(translation_deadzone, 0.0, State::MaxTranslationDeadzone)); + m_state.set_rotation_scale(State::DefaultRotationScale * std::clamp(rotation_speed, 0.2f, 5.0f)); + m_state.set_rotation_deadzone(std::clamp(rotation_deadzone, 0.0f, State::MaxRotationDeadzone)); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + m_state.set_zoom_scale(State::DefaultZoomScale * std::clamp(zoom_speed, 0.2, 5.0)); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM } #if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT else @@ -663,8 +694,13 @@ void Mouse3DController::disconnect_device() m_thread.join(); // Store current device parameters into the config +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + wxGetApp().app_config->set_mouse_device(m_device_str, m_state.get_translation_scale() / State::DefaultTranslationScale, m_state.get_translation_deadzone(), + m_state.get_rotation_scale() / State::DefaultRotationScale, m_state.get_rotation_deadzone(), m_state.get_zoom_scale() / State::DefaultZoomScale); +#else wxGetApp().app_config->set_mouse_device(m_device_str, m_state.get_translation_scale() / State::DefaultTranslationScale, m_state.get_translation_deadzone(), m_state.get_rotation_scale() / State::DefaultRotationScale, m_state.get_rotation_deadzone()); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM wxGetApp().app_config->save(); // Close the 3Dconnexion device diff --git a/src/slic3r/GUI/Mouse3DController.hpp b/src/slic3r/GUI/Mouse3DController.hpp index 9e5161ee7d..3598d7df7a 100644 --- a/src/slic3r/GUI/Mouse3DController.hpp +++ b/src/slic3r/GUI/Mouse3DController.hpp @@ -33,6 +33,9 @@ class Mouse3DController static const float DefaultRotationScale; static const float MaxRotationDeadzone; static const float DefaultRotationDeadzone; +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + static const double DefaultZoomScale; +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM private: template @@ -64,6 +67,9 @@ class Mouse3DController CustomParameters m_translation_params; CustomParameters m_rotation_params; +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + CustomParameters m_zoom_params; +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM // When the 3Dconnexion driver is running the system gets, by default, mouse wheel events when rotations around the X axis are detected. // We want to filter these out because we are getting the data directly from the device, bypassing the driver, and those mouse wheel events interfere @@ -99,6 +105,11 @@ class Mouse3DController float get_rotation_scale() const { return m_rotation_params.scale; } void set_rotation_scale(float scale) { m_rotation_params.scale = scale; } +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + double get_zoom_scale() const { return m_zoom_params.scale; } + void set_zoom_scale(double scale) { m_zoom_params.scale = scale; } +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM + double get_translation_deadzone() const { return m_translation_params.deadzone; } void set_translation_deadzone(double deadzone) { m_translation_params.deadzone = deadzone; }