From 10d530a57e5db078a38722daa16d85eb4f21a0bb Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 4 May 2020 22:30:38 +0200 Subject: [PATCH 1/4] New Layouts: There 3 mode of a layout of the settings tabpanel : 1. Old mode, as it was always. 2. New mode, when Settings Tabs are hidden on the Plater. Use "cog" icon for the switching to the settings tabs 3. Dlg mode, when Settings Tabs are extracted to the Settings dialog. Use "cog" icon for Show or Focus the Settings Dialog The "Collapse sidebar" toolbar appearance is set in the Preferences. --- src/slic3r/GUI/GLCanvas3D.cpp | 71 ++++------------ src/slic3r/GUI/GLToolbar.cpp | 2 +- src/slic3r/GUI/GUI_App.cpp | 5 +- src/slic3r/GUI/MainFrame.cpp | 143 ++++++++++++++++++++++++-------- src/slic3r/GUI/MainFrame.hpp | 30 ++++++- src/slic3r/GUI/OptionsGroup.cpp | 1 + src/slic3r/GUI/Plater.cpp | 9 +- src/slic3r/GUI/Preferences.cpp | 80 ++++++++++++++++-- src/slic3r/GUI/Preferences.hpp | 1 + 9 files changed, 241 insertions(+), 101 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index e78525d21..cd8ab6694 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4362,6 +4362,9 @@ void GLCanvas3D::update_ui_from_settings() _refresh_if_shown_on_screen(); } #endif + + bool enable_collapse = wxGetApp().app_config->get("show_collapse_button") == "1"; + enable_collapse_toolbar(enable_collapse); } @@ -5062,10 +5065,23 @@ bool GLCanvas3D::_init_main_toolbar() if (!m_main_toolbar.add_separator()) return false; + item.name = "settings"; + item.icon_filename = "cog.svg"; + item.tooltip = _utf8(L("Switch to Settings")); + item.sprite_id = 10; + item.enabling_callback = GLToolbarItem::Default_Enabling_Callback; + item.visibility_callback = [this]() { return wxGetApp().app_config->get("old_settings_layout_mode") != "1"; }; + item.left.action_callback = [this]() { wxGetApp().mainframe->select_tab(); }; + if (!m_main_toolbar.add_item(item)) + return false; + + if (!m_main_toolbar.add_separator()) + return false; + item.name = "layersediting"; item.icon_filename = "layers_white.svg"; item.tooltip = _utf8(L("Variable layer height")); - item.sprite_id = 10; + item.sprite_id = /*10*/11; item.left.toggable = true; item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_LAYERSEDITING)); }; item.visibility_callback = [this]()->bool @@ -5087,7 +5103,7 @@ bool GLCanvas3D::_init_main_toolbar() item.name = "search"; item.icon_filename = "search_.svg"; item.tooltip = _utf8(L("Search")) + " [" + GUI::shortkey_ctrl_prefix() + "F]"; - item.sprite_id = 11; + item.sprite_id = /*11*/12; item.left.render_callback = [this](float left, float right, float, float) { if (m_canvas != nullptr) { @@ -5264,61 +5280,10 @@ bool GLCanvas3D::_init_collapse_toolbar() wxGetApp().plater()->collapse_sidebar(!wxGetApp().plater()->is_sidebar_collapsed()); }; - if (!m_collapse_toolbar.add_item(item)) - return false; - - if (!m_collapse_toolbar.add_separator()) - return false; - - item.name = "print"; - item.icon_filename = "cog.svg"; - item.tooltip = _utf8(L("Switch to Print Settings")) + " [" + GUI::shortkey_ctrl_prefix() + "2]"; - item.sprite_id = 1; - item.left.action_callback = [this]() { wxGetApp().mainframe->select_tab(/*0*/1); }; - - if (!m_collapse_toolbar.add_item(item)) - return false; - - item.name = "filament"; - item.icon_filename = "spool.svg"; - item.tooltip = _utf8(L("Switch to Filament Settings")) + " [" + GUI::shortkey_ctrl_prefix() + "3]"; - item.sprite_id = 2; - item.left.action_callback = [this]() { wxGetApp().mainframe->select_tab(/*1*/2); }; - item.visibility_callback = [this]() { return wxGetApp().plater()->printer_technology() == ptFFF; }; - - if (!m_collapse_toolbar.add_item(item)) - return false; - - item.name = "printer"; - item.icon_filename = "printer.svg"; - item.tooltip = _utf8(L("Switch to Printer Settings")) + " [" + GUI::shortkey_ctrl_prefix() + "4]"; - item.sprite_id = 3; - item.left.action_callback = [this]() { wxGetApp().mainframe->select_tab(/*2*/3); }; - - if (!m_collapse_toolbar.add_item(item)) - return false; - - item.name = "resin"; - item.icon_filename = "resin.svg"; - item.tooltip = _utf8(L("Switch to SLA Material Settings")) + " [" + GUI::shortkey_ctrl_prefix() + "3]"; - item.sprite_id = 4; - item.left.action_callback = [this]() { wxGetApp().mainframe->select_tab(/*1*/2); }; - item.visibility_callback = [this]() { return m_process->current_printer_technology() == ptSLA; }; - - if (!m_collapse_toolbar.add_item(item)) - return false; - - item.name = "sla_printer"; - item.icon_filename = "sla_printer.svg"; - item.tooltip = _utf8(L("Switch to Printer Settings")) + " [" + GUI::shortkey_ctrl_prefix() + "4]"; - item.sprite_id = 5; - item.left.action_callback = [this]() { wxGetApp().mainframe->select_tab(/*2*/3); }; - if (!m_collapse_toolbar.add_item(item)) return false; return true; - } bool GLCanvas3D::_set_current() diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index 0bd087814..88ed1d476 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -252,7 +252,7 @@ bool GLToolbar::is_enabled() const void GLToolbar::set_enabled(bool enable) { - m_enabled = true; + m_enabled = enable;//true; etFIXME } bool GLToolbar::add_item(const GLToolbarItem::Data& data) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 0774f3208..6790c4c8a 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -413,7 +413,8 @@ bool GUI_App::on_init_inner() if (wxImage::FindHandler(wxBITMAP_TYPE_PNG) == nullptr) wxImage::AddHandler(new wxPNGHandler()); mainframe = new MainFrame(); - mainframe->switch_to(true); // hide settings tabs after first Layout + // hide settings tabs after first Layout + mainframe->select_tab(0); sidebar().obj_list()->init_objects(); // propagate model objects to object list // update_mode(); // !!! do that later @@ -602,6 +603,8 @@ void GUI_App::recreate_GUI() MainFrame *old_main_frame = mainframe; mainframe = new MainFrame(); + // hide settings tabs after first Layout + mainframe->select_tab(0); // Propagate model objects to object list. sidebar().obj_list()->init_objects(); SetTopWindow(mainframe); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index d3bd2720e..5d72dcc8b 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -90,10 +90,12 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S // initialize layout auto sizer = new wxBoxSizer(wxVERTICAL); - if (m_plater) + if (m_plater && m_layout != slOld) sizer->Add(m_plater, 1, wxEXPAND); - if (m_tabpanel) + + if (m_tabpanel && m_layout != slDlg) sizer->Add(m_tabpanel, 1, wxEXPAND); + sizer->SetSizeHints(this); SetSizer(sizer); Fit(); @@ -289,12 +291,22 @@ void MainFrame::update_title() void MainFrame::init_tabpanel() { - // wxNB_NOPAGETHEME: Disable Windows Vista theme for the Notebook background. The theme performance is terrible on Windows 10 - // with multiple high resolution displays connected. - m_tabpanel = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME); + m_layout = wxGetApp().app_config->get("old_settings_layout_mode") == "1" ? slOld : + wxGetApp().app_config->get("new_settings_layout_mode") == "1" ? slNew : + wxGetApp().app_config->get("dlg_settings_layout_mode") == "1" ? slDlg : slOld; + + if (m_layout == slDlg) { + m_settings_dialog = new SettingsDialog(); + m_tabpanel = m_settings_dialog->get_tabpanel(); + } + else { + // wxNB_NOPAGETHEME: Disable Windows Vista theme for the Notebook background. The theme performance is terrible on Windows 10 + // with multiple high resolution displays connected. + m_tabpanel = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME); #ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList - m_tabpanel->SetFont(Slic3r::GUI::wxGetApp().normal_font()); + m_tabpanel->SetFont(Slic3r::GUI::wxGetApp().normal_font()); #endif + } m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, [this](wxEvent&) { auto panel = m_tabpanel->GetCurrentPage(); @@ -307,17 +319,22 @@ void MainFrame::init_tabpanel() // On GTK, the wxEVT_NOTEBOOK_PAGE_CHANGED event is triggered // before the MainFrame is fully set up. static_cast(panel)->OnActivate(); + m_last_selected_tab = m_tabpanel->GetSelection(); } else select_tab(0); }); -//! m_plater = new Slic3r::GUI::Plater(m_tabpanel, this); - m_plater = new Plater(this, this); - + if (m_layout == slOld) { + m_plater = new Plater(m_tabpanel, this); + m_tabpanel->AddPage(m_plater, _L("Plater")); + } + else { + m_plater = new Plater(this, this); + if (m_layout == slNew) + m_tabpanel->AddPage(new wxPanel(m_tabpanel), _L("Plater")); // empty panel just for Plater tab + } wxGetApp().plater_ = m_plater; -// m_tabpanel->AddPage(m_plater, _(L("Plater"))); - m_tabpanel->AddPage(new wxPanel(m_tabpanel), _L("Plater")); // empty panel just for Plater tab wxGetApp().obj_list()->create_popup_menus(); @@ -343,13 +360,6 @@ void MainFrame::init_tabpanel() } } -void MainFrame::switch_to(bool plater) -{ - this->m_plater->Show(plater); - this->m_tabpanel->Show(!plater); - this->Layout(); -} - void MainFrame::create_preset_tabs() { wxGetApp().update_label_colours_from_appconfig(); @@ -763,25 +773,21 @@ void MainFrame::init_menubar() // Window menu auto windowMenu = new wxMenu(); { -//! size_t tab_offset = 0; if (m_plater) { append_menu_item(windowMenu, wxID_HIGHEST + 1, _(L("&Plater Tab")) + "\tCtrl+1", _(L("Show the plater")), - [this/*, tab_offset*/](wxCommandEvent&) { select_tab(/*(size_t)(-1)*/0); }, "plater", nullptr, + [this](wxCommandEvent&) { select_tab(0); }, "plater", nullptr, [this]() {return true; }, this); -//! tab_offset += 1; -//! } -//! if (tab_offset > 0) { windowMenu->AppendSeparator(); } append_menu_item(windowMenu, wxID_HIGHEST + 2, _(L("P&rint Settings Tab")) + "\tCtrl+2", _(L("Show the print settings")), - [this/*, tab_offset*/](wxCommandEvent&) { select_tab(/*tab_offset + 0*/1); }, "cog", nullptr, + [this/*, tab_offset*/](wxCommandEvent&) { select_tab(1); }, "cog", nullptr, [this]() {return true; }, this); wxMenuItem* item_material_tab = append_menu_item(windowMenu, wxID_HIGHEST + 3, _(L("&Filament Settings Tab")) + "\tCtrl+3", _(L("Show the filament settings")), - [this/*, tab_offset*/](wxCommandEvent&) { select_tab(/*tab_offset + 1*/2); }, "spool", nullptr, + [this/*, tab_offset*/](wxCommandEvent&) { select_tab(2); }, "spool", nullptr, [this]() {return true; }, this); m_changeable_menu_items.push_back(item_material_tab); wxMenuItem* item_printer_tab = append_menu_item(windowMenu, wxID_HIGHEST + 4, _(L("Print&er Settings Tab")) + "\tCtrl+4", _(L("Show the printer settings")), - [this/*, tab_offset*/](wxCommandEvent&) { select_tab(/*tab_offset + 2*/3); }, "printer", nullptr, + [this/*, tab_offset*/](wxCommandEvent&) { select_tab(3); }, "printer", nullptr, [this]() {return true; }, this); m_changeable_menu_items.push_back(item_printer_tab); if (m_plater) { @@ -1245,17 +1251,25 @@ void MainFrame::load_config(const DynamicPrintConfig& config) #endif } -void MainFrame::select_tab(size_t tab) +void MainFrame::select_tab(size_t tab/* = size_t(-1)*/) { - if (tab == /*(size_t)(-1)*/0) { - if (m_plater && !m_plater->IsShown()) - this->switch_to(true); + if (m_layout == slDlg) { + if (tab==0) + return; + // Show/Activate Settings Dialog + if (m_settings_dialog->IsShown()) + m_settings_dialog->SetFocus(); + else + m_settings_dialog->Show(); } - else { - if (m_plater && m_plater->IsShown()) - switch_to(false); - m_tabpanel->SetSelection(tab); + else if (m_layout == slNew) { + m_plater->Show(tab == 0); + m_tabpanel->Show(tab != 0); + Layout(); } + + // when tab == -1, it means we should to show the last selected tab + m_tabpanel->SetSelection(tab == (size_t)(-1) ? m_last_selected_tab : (m_layout == slDlg && tab != 0) ? tab-1 : tab); } // Set a camera direction, zoom to all objects. @@ -1360,5 +1374,66 @@ std::string MainFrame::get_dir_name(const wxString &full_name) const return boost::filesystem::path(full_name.wx_str()).parent_path().string(); } + +// ---------------------------------------------------------------------------- +// SettingsDialog +// ---------------------------------------------------------------------------- + +SettingsDialog::SettingsDialog() +: DPIDialog(nullptr, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _L("Settings")) +{ + this->SetFont(wxGetApp().normal_font()); + + wxColour bgr_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); + this->SetBackgroundColour(bgr_clr); + + // Load the icon either from the exe, or from the ico file. +#if _WIN32 + { + TCHAR szExeFileName[MAX_PATH]; + GetModuleFileName(nullptr, szExeFileName, MAX_PATH); + SetIcon(wxIcon(szExeFileName, wxBITMAP_TYPE_ICO)); + } +#else + SetIcon(wxIcon(var("PrusaSlicer_128px.png"), wxBITMAP_TYPE_PNG)); +#endif // _WIN32 + + // wxNB_NOPAGETHEME: Disable Windows Vista theme for the Notebook background. The theme performance is terrible on Windows 10 + // with multiple high resolution displays connected. + m_tabpanel = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME); +#ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList + m_tabpanel->SetFont(Slic3r::GUI::wxGetApp().normal_font()); +#endif + + // initialize layout + auto sizer = new wxBoxSizer(wxVERTICAL); + sizer->Add(m_tabpanel, 1, wxEXPAND); + sizer->SetSizeHints(this); + SetSizer(sizer); + Fit(); + + const wxSize min_size = wxSize(85 * em_unit(), 50 * em_unit()); +#ifdef __APPLE__ + // Using SetMinSize() on Mac messes up the window position in some cases + // cf. https://groups.google.com/forum/#!topic/wx-users/yUKPBBfXWO0 + SetSize(min_size); +#else + SetMinSize(min_size); + SetSize(GetMinSize()); +#endif + Layout(); +} + +void SettingsDialog::on_dpi_changed(const wxRect& suggested_rect) +{ + const int& em = em_unit(); + const wxSize& size = wxSize(85 * em, 50 * em); + + SetMinSize(size); + Fit(); + Refresh(); +} + + } // GUI } // Slic3r diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 8fc0ed1f2..536191700 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -43,6 +43,22 @@ struct PresetTab { PrinterTechnology technology; }; +// ---------------------------------------------------------------------------- +// SettingsDialog +// ---------------------------------------------------------------------------- + +class SettingsDialog : public DPIDialog +{ + wxNotebook* m_tabpanel { nullptr }; +public: + SettingsDialog(); + ~SettingsDialog() {} + wxNotebook* get_tabpanel() { return m_tabpanel; } + +protected: + void on_dpi_changed(const wxRect& suggested_rect) override; +}; + class MainFrame : public DPIFrame { bool m_loaded {false}; @@ -57,6 +73,8 @@ class MainFrame : public DPIFrame PrintHostQueueDialog *m_printhost_queue_dlg; + size_t m_last_selected_tab {1}; + std::string get_base_name(const wxString &full_name, const char *extension = nullptr) const; std::string get_dir_name(const wxString &full_name) const; @@ -94,6 +112,12 @@ class MainFrame : public DPIFrame wxFileHistory m_recent_projects; + enum SettingsLayout { + slOld = 0, + slNew, + slDlg, + } m_layout; + protected: virtual void on_dpi_changed(const wxRect &suggested_rect); @@ -109,7 +133,6 @@ public: void update_title(); void init_tabpanel(); - void switch_to(bool plater); void create_preset_tabs(); void add_created_tab(Tab* panel); void init_menubar(); @@ -130,7 +153,9 @@ public: void export_configbundle(); void load_configbundle(wxString file = wxEmptyString); void load_config(const DynamicPrintConfig& config); - void select_tab(size_t tab); + // Select tab in m_tabpanel + // When tab == -1, will be selected last selected tab + void select_tab(size_t tab = size_t(-1)); void select_view(const std::string& direction); // Propagate changed configuration from the Tab to the Plater and save changes to the AppConfig void on_config_changed(DynamicPrintConfig* cfg) const ; @@ -141,6 +166,7 @@ public: Plater* m_plater { nullptr }; wxNotebook* m_tabpanel { nullptr }; + SettingsDialog* m_settings_dialog { nullptr }; wxProgressDialog* m_progress_dialog { nullptr }; std::shared_ptr m_statusbar; diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 83eb6c76f..5b2b5703b 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -105,6 +105,7 @@ void OptionsGroup::add_undo_buttuns_to_sizer(wxSizer* sizer, const t_field& fiel if (!m_show_modified_btns) { field->m_Undo_btn->set_as_hidden(); field->m_Undo_to_sys_btn->set_as_hidden(); + field->m_blinking_bmp->Hide(); return; } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 02baaa17e..a6430e472 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -355,10 +355,10 @@ PresetBitmapComboBox(parent, wxSize(15 * wxGetApp().em_unit(), -1)), if (page_id == wxNOT_FOUND) return; - wxGetApp().tab_panel()->ChangeSelection(page_id); + wxGetApp().tab_panel()->SetSelection(page_id); // Switch to Settings NotePad - wxGetApp().mainframe->switch_to(false); + wxGetApp().mainframe->select_tab(); /* In a case of a multi-material printing, for editing another Filament Preset * it's needed to select this preset for the "Filament settings" Tab @@ -1100,9 +1100,8 @@ void Sidebar::jump_to_option(size_t selected) const Search::Option& opt = p->searcher.get_option(selected); wxGetApp().get_tab(opt.type)->activate_option(opt.opt_key, opt.category); - // Switch to the Settings NotePad, if plater is shown - if (p->plater->IsShown()) - wxGetApp().mainframe->switch_to(false); + // Switch to the Settings NotePad + wxGetApp().mainframe->select_tab(); } ObjectManipulation* Sidebar::obj_manipul() diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index e2bccb1c7..5963a1637 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -117,6 +117,13 @@ void PreferencesDialog::build() m_optgroup_general->append_single_option_line(option); #endif + def.label = L("Show the button for the collapse sidebar"); + def.type = coBool; + def.tooltip = L("If enabled, the button for the collapse sidebar will be appeared in top right corner of the 3D Scene"); + def.set_default_value(new ConfigOptionBool{ app_config->get("show_collapse_button") == "1" }); + option = Option(def, "show_collapse_button"); + m_optgroup_general->append_single_option_line(option); + m_optgroup_camera = std::make_shared(this, _(L("Camera"))); m_optgroup_camera->label_width = 40; m_optgroup_camera->m_on_change = [this](t_config_option_key opt_key, boost::any value) { @@ -157,6 +164,8 @@ void PreferencesDialog::build() create_icon_size_slider(); m_icon_size_sizer->ShowItems(app_config->get("use_custom_toolbar_size") == "1"); + create_settings_mode_widget(); + auto sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(m_optgroup_general->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); sizer->Add(m_optgroup_camera->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); @@ -167,7 +176,7 @@ void PreferencesDialog::build() auto buttons = CreateStdDialogButtonSizer(wxOK | wxCANCEL); wxButton* btn = static_cast(FindWindowById(wxID_OK, this)); btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { accept(); }); - sizer->Add(buttons, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10); + sizer->Add(buttons, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 5); SetSizer(sizer); sizer->SetSizeHints(this); @@ -179,8 +188,33 @@ void PreferencesDialog::accept() warning_catcher(this, wxString::Format(_(L("You need to restart %s to make the changes effective.")), SLIC3R_APP_NAME)); } - auto app_config = get_app_config(); - for (std::map::iterator it = m_values.begin(); it != m_values.end(); ++it) { + bool settings_layout_changed = m_values.find("old_settings_layout_mode") != m_values.end() || + m_values.find("new_settings_layout_mode") != m_values.end() || + m_values.find("dlg_settings_layout_mode") != m_values.end(); + + bool canceled = false; + if (settings_layout_changed) { + // the dialog needs to be destroyed before the call to recreate_gui() + // or sometimes the application crashes into wxDialogBase() destructor + // so we put it into an inner scope + wxMessageDialog dialog(nullptr, + _L("Switching the settings layout mode will trigger application restart.\n" + "You will lose content of the plater.") + "\n\n" + + _L("Do you want to proceed?"), + wxString(SLIC3R_APP_NAME) + " - " + _L("Switching the settings layout mode"), + wxICON_QUESTION | wxOK | wxCANCEL); + + if (dialog.ShowModal() == wxID_CANCEL) + canceled = true; + } + + auto app_config = get_app_config(); + for (std::map::iterator it = m_values.begin(); it != m_values.end(); ++it) + { + if (canceled && (it->first == "old_settings_layout_mode" || + it->first == "new_settings_layout_mode" || + it->first == "dlg_settings_layout_mode" )) + continue; app_config->set(it->first, it->second); } @@ -188,8 +222,12 @@ void PreferencesDialog::accept() EndModal(wxID_OK); - // Nothify the UI to update itself from the ini file. - wxGetApp().update_ui_from_settings(); + if (settings_layout_changed && !canceled) + // recreate application, if settings layout was changed + wxGetApp().recreate_GUI(); + else + // Nothify the UI to update itself from the ini file. + wxGetApp().update_ui_from_settings(); } void PreferencesDialog::on_dpi_changed(const wxRect &suggested_rect) @@ -272,6 +310,38 @@ void PreferencesDialog::create_icon_size_slider() m_optgroup_gui->sizer->Add(m_icon_size_sizer, 0, wxEXPAND | wxALL, em); } +void PreferencesDialog::create_settings_mode_widget() +{ + wxString choices[] = { _L("Old regular layout with tab bar"), + _L("New layout without the tab bar on the platter"), + _L("Settings will be shown in non-modal dialog") }; + + auto app_config = get_app_config(); + int selection = app_config->get("old_settings_layout_mode") == "1" ? 0 : + app_config->get("new_settings_layout_mode") == "1" ? 1 : + app_config->get("dlg_settings_layout_mode") == "1" ? 2 : 0; + + wxWindow* parent = m_optgroup_gui->ctrl_parent(); + + wxRadioBox* box = new wxRadioBox(parent, wxID_ANY, _L("Settings layout mode"), wxDefaultPosition, wxDefaultSize, WXSIZEOF(choices), choices, + 3, wxRA_SPECIFY_ROWS); + box->SetButtonFont(wxGetApp().normal_font()); + box->SetSelection(selection); + + box->Bind(wxEVT_RADIOBOX, [this](wxCommandEvent& e) { + int selection = e.GetSelection(); + + m_values["old_settings_layout_mode"] = boost::any_cast(selection == 0) ? "1" : "0"; + m_values["new_settings_layout_mode"] = boost::any_cast(selection == 1) ? "1" : "0"; + m_values["dlg_settings_layout_mode"] = boost::any_cast(selection == 2) ? "1" : "0"; + }); + + auto sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(box, 1, wxALIGN_CENTER_VERTICAL); + + m_optgroup_gui->sizer->Add(sizer, 0, wxEXPAND | wxALL, em_unit()); +} + } // GUI } // Slic3r \ No newline at end of file diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index 35bf2b8c5..7a6de8377 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -31,6 +31,7 @@ protected: void on_dpi_changed(const wxRect &suggested_rect) override; void layout(); void create_icon_size_slider(); + void create_settings_mode_widget(); }; } // GUI From 43be7a51aa4823d9a32c4bdeb834b0379762ad71 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 5 May 2020 09:35:28 +0200 Subject: [PATCH 2/4] Fixed OSX/Linux build Destroy Settings Dialog when close application --- src/slic3r/GUI/MainFrame.cpp | 6 ++++++ src/slic3r/GUI/MainFrame.hpp | 2 +- src/slic3r/GUI/Preferences.cpp | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 5d72dcc8b..417afdfbd 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -231,6 +231,9 @@ void MainFrame::shutdown() // In addition, there were some crashes due to the Paint events sent to already destructed windows. this->Show(false); + if (m_settings_dialog) + m_settings_dialog->Destroy(); + // Stop the background thread (Windows and Linux). // Disconnect from a 3DConnextion driver (OSX). m_plater->get_mouse3d_controller().shutdown(); @@ -295,6 +298,9 @@ void MainFrame::init_tabpanel() wxGetApp().app_config->get("new_settings_layout_mode") == "1" ? slNew : wxGetApp().app_config->get("dlg_settings_layout_mode") == "1" ? slDlg : slOld; + // From the very beginning the Print settings should be selected + m_last_selected_tab = m_layout == slDlg ? 0 : 1; + if (m_layout == slDlg) { m_settings_dialog = new SettingsDialog(); m_tabpanel = m_settings_dialog->get_tabpanel(); diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 536191700..5c8bd2f86 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -73,7 +73,7 @@ class MainFrame : public DPIFrame PrintHostQueueDialog *m_printhost_queue_dlg; - size_t m_last_selected_tab {1}; + size_t m_last_selected_tab; std::string get_base_name(const wxString &full_name, const char *extension = nullptr) const; std::string get_dir_name(const wxString &full_name) const; diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 5963a1637..f8fa1a233 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -325,7 +325,7 @@ void PreferencesDialog::create_settings_mode_widget() wxRadioBox* box = new wxRadioBox(parent, wxID_ANY, _L("Settings layout mode"), wxDefaultPosition, wxDefaultSize, WXSIZEOF(choices), choices, 3, wxRA_SPECIFY_ROWS); - box->SetButtonFont(wxGetApp().normal_font()); + box->SetFont(wxGetApp().normal_font()); box->SetSelection(selection); box->Bind(wxEVT_RADIOBOX, [this](wxCommandEvent& e) { @@ -339,7 +339,7 @@ void PreferencesDialog::create_settings_mode_widget() auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(box, 1, wxALIGN_CENTER_VERTICAL); - m_optgroup_gui->sizer->Add(sizer, 0, wxEXPAND | wxALL, em_unit()); + m_optgroup_gui->sizer->Add(sizer, 0, wxEXPAND); } From 181203c2c7d2171bba7fccabb1709d88a8ad874e Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 5 May 2020 17:23:58 +0200 Subject: [PATCH 3/4] New layout: 1. PreferencesDialog: When "Cancel" is selected, don't close the PreferencesDialog, just revert layout mode selection 2. For the tooltip of "Switch to Settings" added information about shortcuts 3. Shortcuts for the switching between tabs work from Settings Dialog now 4. Fixed the collapse button show after preference's change --- src/slic3r/GUI/GLCanvas3D.cpp | 16 ++++++++++++++-- src/slic3r/GUI/GLCanvas3D.hpp | 1 + src/slic3r/GUI/MainFrame.cpp | 24 ++++++++++++++++++++---- src/slic3r/GUI/MainFrame.hpp | 3 ++- src/slic3r/GUI/Plater.cpp | 16 +++++++++++++++- src/slic3r/GUI/Preferences.cpp | 32 ++++++++++++++++---------------- src/slic3r/GUI/Preferences.hpp | 1 + 7 files changed, 69 insertions(+), 24 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index cd8ab6694..f94e8f147 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4422,6 +4422,16 @@ void GLCanvas3D::msw_rescale() m_warning_texture.msw_rescale(*this); } +void GLCanvas3D::update_tooltip_for_settings_item_in_main_toolbar() +{ + std::string new_tooltip = _u8L("Switch to Settings") + + "\n" + "[" + GUI::shortkey_ctrl_prefix() + "2] - " + _u8L("Print Settings Tab") + + "\n" + "[" + GUI::shortkey_ctrl_prefix() + "3] - " + (m_process->current_printer_technology() == ptFFF ? _u8L("Filament Settings Tab") : _u8L("Material Settings Tab")) + + "\n" + "[" + GUI::shortkey_ctrl_prefix() + "4] - " + _u8L("Printer Settings Tab") ; + + m_main_toolbar.set_tooltip(get_main_toolbar_item_id("settings"), new_tooltip); +} + bool GLCanvas3D::has_toolpaths_to_export() const { return m_volumes.has_toolpaths_to_export(); @@ -5067,7 +5077,9 @@ bool GLCanvas3D::_init_main_toolbar() item.name = "settings"; item.icon_filename = "cog.svg"; - item.tooltip = _utf8(L("Switch to Settings")); + item.tooltip = _u8L("Switch to Settings") + "\n" + "[" + GUI::shortkey_ctrl_prefix() + "2] - " + _u8L("Print Settings Tab") + + "\n" + "[" + GUI::shortkey_ctrl_prefix() + "3] - " + (m_process->current_printer_technology() == ptFFF ? _u8L("Filament Settings Tab") : _u8L("Material Settings Tab")) + + "\n" + "[" + GUI::shortkey_ctrl_prefix() + "4] - " + _u8L("Printer Settings Tab") ; item.sprite_id = 10; item.enabling_callback = GLToolbarItem::Default_Enabling_Callback; item.visibility_callback = [this]() { return wxGetApp().app_config->get("old_settings_layout_mode") != "1"; }; @@ -5239,7 +5251,7 @@ bool GLCanvas3D::_init_view_toolbar() bool GLCanvas3D::_init_collapse_toolbar() { - if (!m_collapse_toolbar.is_enabled()) + if (!m_collapse_toolbar.is_enabled() && m_collapse_toolbar.get_items_count() > 0) return true; BackgroundTexture::Metadata background_data; diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 15aa8c456..fa1c070a2 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -724,6 +724,7 @@ public: int get_main_toolbar_item_id(const std::string& name) const { return m_main_toolbar.get_item_id(name); } void force_main_toolbar_left_action(int item_id) { m_main_toolbar.force_left_action(item_id, *this); } void force_main_toolbar_right_action(int item_id) { m_main_toolbar.force_right_action(item_id, *this); } + void update_tooltip_for_settings_item_in_main_toolbar(); bool has_toolpaths_to_export() const; void export_toolpaths_to_obj(const char* filename) const; diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 417afdfbd..e603ce341 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -302,7 +302,7 @@ void MainFrame::init_tabpanel() m_last_selected_tab = m_layout == slDlg ? 0 : 1; if (m_layout == slDlg) { - m_settings_dialog = new SettingsDialog(); + m_settings_dialog = new SettingsDialog(this); m_tabpanel = m_settings_dialog->get_tabpanel(); } else { @@ -1260,8 +1260,11 @@ void MainFrame::load_config(const DynamicPrintConfig& config) void MainFrame::select_tab(size_t tab/* = size_t(-1)*/) { if (m_layout == slDlg) { - if (tab==0) + if (tab==0) { + if (m_settings_dialog->IsShown()) + this->SetFocus(); return; + } // Show/Activate Settings Dialog if (m_settings_dialog->IsShown()) m_settings_dialog->SetFocus(); @@ -1385,8 +1388,9 @@ std::string MainFrame::get_dir_name(const wxString &full_name) const // SettingsDialog // ---------------------------------------------------------------------------- -SettingsDialog::SettingsDialog() -: DPIDialog(nullptr, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _L("Settings")) +SettingsDialog::SettingsDialog(MainFrame* mainframe) +: DPIDialog(nullptr, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _L("Settings")), + m_main_frame(mainframe) { this->SetFont(wxGetApp().normal_font()); @@ -1411,6 +1415,18 @@ SettingsDialog::SettingsDialog() m_tabpanel->SetFont(Slic3r::GUI::wxGetApp().normal_font()); #endif + m_tabpanel->Bind(wxEVT_KEY_UP, [this](wxKeyEvent& evt) { + if ((evt.GetModifiers() & wxMOD_CONTROL) != 0) { + switch (evt.GetKeyCode()) { + case '1': { m_main_frame->select_tab(0); break; } + case '2': { m_main_frame->select_tab(1); break; } + case '3': { m_main_frame->select_tab(2); break; } + case '4': { m_main_frame->select_tab(3); break; } + default:break; + } + } + }); + // initialize layout auto sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(m_tabpanel, 1, wxEXPAND); diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 5c8bd2f86..219f68319 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -50,8 +50,9 @@ struct PresetTab { class SettingsDialog : public DPIDialog { wxNotebook* m_tabpanel { nullptr }; + MainFrame* m_main_frame {nullptr }; public: - SettingsDialog(); + SettingsDialog(MainFrame* mainframe); ~SettingsDialog() {} wxNotebook* get_tabpanel() { return m_tabpanel; } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f95e12db0..66afbfa99 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1640,6 +1640,7 @@ struct Plater::priv void reset_all_gizmos(); void update_ui_from_settings(); + void update_main_toolbar_tooltips(); std::shared_ptr statusbar(); std::string get_config(const std::string &key) const; BoundingBoxf bed_shape_bb() const; @@ -2041,7 +2042,11 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) // collapse sidebar according to saved value - sidebar->collapse(wxGetApp().app_config->get("collapsed_sidebar") == "1"); + bool is_collapsed = wxGetApp().app_config->get("collapsed_sidebar") == "1"; + sidebar->collapse(is_collapsed); + // Update an enable of the collapse_toolbar: if sidebar is collapsed, then collapse_toolbar should be visible + if (is_collapsed) + wxGetApp().app_config->set("show_collapse_button", "1"); } Plater::priv::~priv() @@ -2116,6 +2121,13 @@ void Plater::priv::update_ui_from_settings() preview->get_canvas3d()->update_ui_from_settings(); } +// Called after the print technology was changed. +// Update the tooltips for "Switch to Settings" button in maintoolbar +void Plater::priv::update_main_toolbar_tooltips() +{ + view3D->get_canvas3d()->update_tooltip_for_settings_item_in_main_toolbar(); +} + std::shared_ptr Plater::priv::statusbar() { return main_frame->m_statusbar; @@ -5278,6 +5290,8 @@ void Plater::set_printer_technology(PrinterTechnology printer_technology) if (wxGetApp().mainframe) wxGetApp().mainframe->update_menubar(); + + p->update_main_toolbar_tooltips(); } void Plater::changed_object(int obj_idx) diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index f8fa1a233..88c643add 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -188,11 +188,12 @@ void PreferencesDialog::accept() warning_catcher(this, wxString::Format(_(L("You need to restart %s to make the changes effective.")), SLIC3R_APP_NAME)); } + auto app_config = get_app_config(); + bool settings_layout_changed = m_values.find("old_settings_layout_mode") != m_values.end() || m_values.find("new_settings_layout_mode") != m_values.end() || m_values.find("dlg_settings_layout_mode") != m_values.end(); - bool canceled = false; if (settings_layout_changed) { // the dialog needs to be destroyed before the call to recreate_gui() // or sometimes the application crashes into wxDialogBase() destructor @@ -205,24 +206,23 @@ void PreferencesDialog::accept() wxICON_QUESTION | wxOK | wxCANCEL); if (dialog.ShowModal() == wxID_CANCEL) - canceled = true; + { + int selection = app_config->get("old_settings_layout_mode") == "1" ? 0 : + app_config->get("new_settings_layout_mode") == "1" ? 1 : + app_config->get("dlg_settings_layout_mode") == "1" ? 2 : 0; + + m_layout_mode_box->SetSelection(selection); + return; + } } - auto app_config = get_app_config(); for (std::map::iterator it = m_values.begin(); it != m_values.end(); ++it) - { - if (canceled && (it->first == "old_settings_layout_mode" || - it->first == "new_settings_layout_mode" || - it->first == "dlg_settings_layout_mode" )) - continue; app_config->set(it->first, it->second); - } app_config->save(); - EndModal(wxID_OK); - if (settings_layout_changed && !canceled) + if (settings_layout_changed) // recreate application, if settings layout was changed wxGetApp().recreate_GUI(); else @@ -323,12 +323,12 @@ void PreferencesDialog::create_settings_mode_widget() wxWindow* parent = m_optgroup_gui->ctrl_parent(); - wxRadioBox* box = new wxRadioBox(parent, wxID_ANY, _L("Settings layout mode"), wxDefaultPosition, wxDefaultSize, WXSIZEOF(choices), choices, + m_layout_mode_box = new wxRadioBox(parent, wxID_ANY, _L("Settings layout mode"), wxDefaultPosition, wxDefaultSize, WXSIZEOF(choices), choices, 3, wxRA_SPECIFY_ROWS); - box->SetFont(wxGetApp().normal_font()); - box->SetSelection(selection); + m_layout_mode_box->SetFont(wxGetApp().normal_font()); + m_layout_mode_box->SetSelection(selection); - box->Bind(wxEVT_RADIOBOX, [this](wxCommandEvent& e) { + m_layout_mode_box->Bind(wxEVT_RADIOBOX, [this](wxCommandEvent& e) { int selection = e.GetSelection(); m_values["old_settings_layout_mode"] = boost::any_cast(selection == 0) ? "1" : "0"; @@ -337,7 +337,7 @@ void PreferencesDialog::create_settings_mode_widget() }); auto sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(box, 1, wxALIGN_CENTER_VERTICAL); + sizer->Add(m_layout_mode_box, 1, wxALIGN_CENTER_VERTICAL); m_optgroup_gui->sizer->Add(sizer, 0, wxEXPAND); } diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index 7a6de8377..ec35bc2a4 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -19,6 +19,7 @@ class PreferencesDialog : public DPIDialog std::shared_ptr m_optgroup_camera; std::shared_ptr m_optgroup_gui; wxSizer* m_icon_size_sizer; + wxRadioBox* m_layout_mode_box; bool isOSX {false}; public: PreferencesDialog(wxWindow* parent); From 0098aee00295ca34f1ecf20a2248f276d1c33b7b Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 5 May 2020 20:36:00 +0200 Subject: [PATCH 4/4] Fixed OSX build --- src/slic3r/GUI/Preferences.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index ec35bc2a4..738e805b2 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -7,6 +7,8 @@ #include #include +class wxRadioBox; + namespace Slic3r { namespace GUI {