From 87a996d0d592a4d972922fc157d54d422aabbd6c Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 11 Jun 2021 10:32:54 +0200 Subject: [PATCH] Code refactoring to avoid a call of update_ui_from_settings() every time when switching between "3D-View" and "Preview" --- src/slic3r/GUI/GUI_App.cpp | 4 ++-- src/slic3r/GUI/GUI_App.hpp | 2 +- src/slic3r/GUI/MainFrame.cpp | 4 ++-- src/slic3r/GUI/MainFrame.hpp | 2 +- src/slic3r/GUI/Plater.cpp | 20 +++++++++++++------- src/slic3r/GUI/Plater.hpp | 2 +- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index d6520335b..052a782a7 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1254,10 +1254,10 @@ void fatal_error(wxWindow* parent) // Called after the Preferences dialog is closed and the program settings are saved. // Update the UI based on the current preferences. -void GUI_App::update_ui_from_settings(bool apply_free_camera_correction) +void GUI_App::update_ui_from_settings() { update_label_colours(); - mainframe->update_ui_from_settings(apply_free_camera_correction); + mainframe->update_ui_from_settings(); } void GUI_App::persist_window_geometry(wxTopLevelWindow *window, bool default_maximized) diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 2613c51b1..5027dc1ff 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -199,7 +199,7 @@ public: static bool catch_error(std::function cb, const std::string& err); void persist_window_geometry(wxTopLevelWindow *window, bool default_maximized = false); - void update_ui_from_settings(bool apply_free_camera_correction = true); + void update_ui_from_settings(); bool switch_language(); bool load_language(wxString language, bool initial); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 5a9e5d43a..ba3221b83 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -1887,7 +1887,7 @@ void MainFrame::add_to_recent_projects(const wxString& filename) // // Called after the Preferences dialog is closed and the program settings are saved. // Update the UI based on the current preferences. -void MainFrame::update_ui_from_settings(bool apply_free_camera_correction) +void MainFrame::update_ui_from_settings() { // const bool bp_on = wxGetApp().app_config->get("background_processing") == "1"; // m_menu_item_reslice_now->Enable(!bp_on); @@ -1896,7 +1896,7 @@ void MainFrame::update_ui_from_settings(bool apply_free_camera_correction) // m_plater->sidebar().Layout(); if (m_plater) - m_plater->update_ui_from_settings(apply_free_camera_correction); + m_plater->update_ui_from_settings(); for (auto tab: wxGetApp().tabs_list) tab->update_ui_from_settings(); } diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 307cdf1ae..55fde8a53 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -162,7 +162,7 @@ public: void init_menubar_as_gcodeviewer(); void update_menubar(); - void update_ui_from_settings(bool apply_free_camera_correction = true); + void update_ui_from_settings(); bool is_loaded() const { return m_loaded; } bool is_last_input_file() const { return !m_qs_last_input_file.IsEmpty(); } bool is_dlg_layout() const { return m_layout == ESettingsLayout::Dlg; } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 2e07d75c1..40a5a2af0 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1586,7 +1586,8 @@ struct Plater::priv void reset_gcode_toolpaths(); void reset_all_gizmos(); - void update_ui_from_settings(bool apply_free_camera_correction = true); + void apply_free_camera_correction(bool apply = true); + void update_ui_from_settings(); void update_main_toolbar_tooltips(); std::shared_ptr statusbar(); std::string get_config(const std::string &key) const; @@ -2064,6 +2065,13 @@ void Plater::priv::select_view(const std::string& direction) preview->select_view(direction); } +void Plater::priv::apply_free_camera_correction(bool apply/* = true*/) +{ + camera.set_type(wxGetApp().app_config->get("use_perspective_camera")); + if (apply && wxGetApp().app_config->get("use_free_camera") != "1") + camera.recover_from_free_camera(); +} + void Plater::priv::select_view_3D(const std::string& name) { if (name == "3D") @@ -2071,7 +2079,7 @@ void Plater::priv::select_view_3D(const std::string& name) else if (name == "Preview") set_current_panel(preview); - wxGetApp().update_ui_from_settings(false); + apply_free_camera_correction(false); } void Plater::priv::select_next_view_3D() @@ -2103,11 +2111,9 @@ void Plater::priv::reset_all_gizmos() // Called after the Preferences dialog is closed and the program settings are saved. // Update the UI based on the current preferences. -void Plater::priv::update_ui_from_settings(bool apply_free_camera_correction) +void Plater::priv::update_ui_from_settings() { - camera.set_type(wxGetApp().app_config->get("use_perspective_camera")); - if (apply_free_camera_correction && wxGetApp().app_config->get("use_free_camera") != "1") - camera.recover_from_free_camera(); + apply_free_camera_correction(); view3D->get_canvas3d()->update_ui_from_settings(); preview->get_canvas3d()->update_ui_from_settings(); @@ -4942,7 +4948,7 @@ void Plater::update() { p->update(); } void Plater::stop_jobs() { p->m_ui_jobs.stop_all(); } -void Plater::update_ui_from_settings(bool apply_free_camera_correction) { p->update_ui_from_settings(apply_free_camera_correction); } +void Plater::update_ui_from_settings() { p->update_ui_from_settings(); } void Plater::select_view(const std::string& direction) { p->select_view(direction); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 9fc424e83..21d3c6046 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -186,7 +186,7 @@ public: // Called after the Preferences dialog is closed and the program settings are saved. // Update the UI based on the current preferences. - void update_ui_from_settings(bool apply_free_camera_correction = true); + void update_ui_from_settings(); void select_all(); void deselect_all();