From c8d875bee1e0192c2bb55f878b18733408e19e80 Mon Sep 17 00:00:00 2001 From: enricoturri1966 <enricoturri@seznam.cz> Date: Tue, 27 Oct 2020 14:01:42 +0100 Subject: [PATCH] #4987 - Fixed camera switches back to non-Perspective camera after slice --- src/slic3r/GUI/Camera.cpp | 18 +++++------------- src/slic3r/GUI/Camera.hpp | 21 ++++++++++++--------- src/slic3r/GUI/Plater.cpp | 1 + 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/slic3r/GUI/Camera.cpp b/src/slic3r/GUI/Camera.cpp index 3bd22590f..1e589f1a1 100644 --- a/src/slic3r/GUI/Camera.cpp +++ b/src/slic3r/GUI/Camera.cpp @@ -32,15 +32,6 @@ double Camera::MaxFovDeg = 60.0; Camera::Camera() : requires_zoom_to_bed(false) - , m_type(Perspective) - , m_target(Vec3d::Zero()) - , m_zenit(45.0f) - , m_zoom(1.0) - , m_distance(DefaultDistance) - , m_gui_scale(1.0) - , m_view_matrix(Transform3d::Identity()) - , m_view_rotation(1., 0., 0., 0.) - , m_projection_matrix(Transform3d::Identity()) { set_default_orientation(); } @@ -58,11 +49,12 @@ std::string Camera::get_type_as_string() const void Camera::set_type(EType type) { - if (m_type != type) - { + if (m_type != type) { m_type = type; - wxGetApp().app_config->set("use_perspective_camera", (m_type == Perspective) ? "1" : "0"); - wxGetApp().app_config->save(); + if (m_update_config_on_type_change_enabled) { + wxGetApp().app_config->set("use_perspective_camera", (m_type == Perspective) ? "1" : "0"); + wxGetApp().app_config->save(); + } } } diff --git a/src/slic3r/GUI/Camera.hpp b/src/slic3r/GUI/Camera.hpp index 6e4256235..99b6f05d4 100644 --- a/src/slic3r/GUI/Camera.hpp +++ b/src/slic3r/GUI/Camera.hpp @@ -29,19 +29,20 @@ struct Camera bool requires_zoom_to_bed; private: - EType m_type; - Vec3d m_target; - float m_zenit; - double m_zoom; + EType m_type{ Perspective }; + bool m_update_config_on_type_change_enabled{ false }; + Vec3d m_target{ Vec3d::Zero() }; + float m_zenit{ 45.0f }; + double m_zoom{ 1.0 }; // Distance between camera position and camera target measured along the camera Z axis - mutable double m_distance; - mutable double m_gui_scale; + mutable double m_distance{ DefaultDistance }; + mutable double m_gui_scale{ 1.0 }; mutable std::array<int, 4> m_viewport; - mutable Transform3d m_view_matrix; + mutable Transform3d m_view_matrix{ Transform3d::Identity() }; // We are calculating the rotation part of the m_view_matrix from m_view_rotation. - mutable Eigen::Quaterniond m_view_rotation; - mutable Transform3d m_projection_matrix; + mutable Eigen::Quaterniond m_view_rotation{ 1.0, 0.0, 0.0, 0.0 }; + mutable Transform3d m_projection_matrix{ Transform3d::Identity() }; mutable std::pair<double, double> m_frustrum_zs; BoundingBoxf3 m_scene_box; @@ -56,6 +57,8 @@ public: void set_type(const std::string& type); void select_next_type(); + void enable_update_config_on_type_change(bool enable) { m_update_config_on_type_change_enabled = enable; } + const Vec3d& get_target() const { return m_target; } void set_target(const Vec3d& target); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 80071c972..24f8e5ed6 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2003,6 +2003,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) #endif // ENABLE_GCODE_VIEWER // updates camera type from .ini file + camera.enable_update_config_on_type_change(true); camera.set_type(get_config("use_perspective_camera")); // Load the 3DConnexion device database.