Code refactoring to avoid a call of update_ui_from_settings() every time when switching between "3D-View" and "Preview"

This commit is contained in:
YuSanka 2021-06-11 10:32:54 +02:00
parent 69b9beaec0
commit 87a996d0d5
6 changed files with 20 additions and 14 deletions

View file

@ -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)

View file

@ -199,7 +199,7 @@ public:
static bool catch_error(std::function<void()> 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);

View file

@ -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();
}

View file

@ -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; }

View file

@ -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<ProgressStatusBar> 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); }

View file

@ -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();