Serialized camera type and fixed Mac build

This commit is contained in:
Enrico Turri 2019-06-20 10:02:52 +02:00
parent 6af69667a3
commit b7f67369c9
5 changed files with 39 additions and 10 deletions

View file

@ -73,6 +73,9 @@ void AppConfig::set_defaults()
if (get("custom_toolbar_size").empty())
set("custom_toolbar_size", "100");
if (get("camera_type").empty())
set("camera_type", "1");
// Remove legacy window positions/sizes
erase("", "main_frame_maximized");
erase("", "main_frame_pos");

View file

@ -2,9 +2,8 @@
#include "Camera.hpp"
#include "3DScene.hpp"
#if ENABLE_CAMERA_STATISTICS
#include "GUI_App.hpp"
#endif // ENABLE_CAMERA_STATISTICS
#include "AppConfig.hpp"
#include <GL/glew.h>
@ -44,23 +43,44 @@ std::string Camera::get_type_as_string() const
{
switch (m_type)
{
default:
case Unknown:
return "unknown";
case Perspective:
return "perspective";
default:
case Ortho:
return "orthographic";
};
}
void Camera::set_type(EType type)
{
if (m_type != type)
{
m_type = type;
wxGetApp().app_config->set("camera_type", std::to_string(m_type));
wxGetApp().app_config->save();
}
}
void Camera::set_type(const std::string& type)
{
if (!type.empty() && (type != "1"))
{
unsigned char type_id = atoi(type.c_str());
if (((unsigned char)Ortho < type_id) && (type_id < (unsigned char)Num_types))
set_type((Camera::EType)type_id);
}
}
void Camera::select_next_type()
{
unsigned char next = (unsigned char)m_type + 1;
if (next == (unsigned char)Num_types)
next = 1;
m_type = (EType)next;
set_type((EType)next);
}
void Camera::set_target(const Vec3d& target)

View file

@ -16,8 +16,8 @@ struct Camera
enum EType : unsigned char
{
Unknown,
Perspective,
Ortho,
Perspective,
Num_types
};
@ -45,7 +45,8 @@ public:
EType get_type() const { return m_type; }
std::string get_type_as_string() const;
void set_type(EType type) { m_type = type; }
void set_type(EType type);
void set_type(const std::string& type);
void select_next_type();
const Vec3d& get_target() const { return m_target; }
@ -56,6 +57,9 @@ public:
double get_zoom() const { return m_zoom; }
void set_zoom(double zoom, const BoundingBoxf3& max_box, int canvas_w, int canvas_h);
#if ENABLE_RETINA_GL
void set_zoom(double zoom) { m_zoom = zoom; }
#endif // ENABLE_RETINA_GL
const BoundingBoxf3& get_scene_box() const { return m_scene_box; }
void set_scene_box(const BoundingBoxf3& box) { m_scene_box = box; }

View file

@ -1593,8 +1593,8 @@ void GLCanvas3D::render()
if (m_camera.requires_zoom_to_bed)
{
zoom_to_bed();
// const Size& cnv_size = get_canvas_size();
// _resize((unsigned int)cnv_size.get_width(), (unsigned int)cnv_size.get_height());
const Size& cnv_size = get_canvas_size();
_resize((unsigned int)cnv_size.get_width(), (unsigned int)cnv_size.get_height());
m_camera.requires_zoom_to_bed = false;
}
@ -3304,8 +3304,7 @@ void GLCanvas3D::update_ui_from_settings()
if (new_scaling != orig_scaling) {
BOOST_LOG_TRIVIAL(debug) << "GLCanvas3D: Scaling factor: " << new_scaling;
m_camera.zoom /= orig_scaling;
m_camera.zoom *= new_scaling;
m_camera.set_zoom(m_camera.get_zoom() * new_scaling / orig_scaling);
_refresh_if_shown_on_screen();
}
#endif

View file

@ -1772,6 +1772,9 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
q->Layout();
set_current_panel(view3D);
// updates camera type from .ini file
camera.set_type(get_config("camera_type"));
}
void Plater::priv::update(bool force_full_scene_refresh)