From 08c69057516dfb90a83ec17099c545748855dbc8 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 1 Oct 2018 15:09:31 +0200 Subject: [PATCH] Moved functions and variables (for fonts and labels color) to GUI_App + corrected Sidebar layouts + deleted get_preset_bundle + actions with tabs_list moved to GUI_App --- src/slic3r.cpp | 4 +- src/slic3r/AppController.cpp | 9 +- src/slic3r/GUI/ButtonsDescription.cpp | 13 +- src/slic3r/GUI/Field.cpp | 3 +- src/slic3r/GUI/FirmwareDialog.cpp | 3 +- src/slic3r/GUI/GLCanvas3D.cpp | 3 +- src/slic3r/GUI/GUI.cpp | 217 +++++--------------------- src/slic3r/GUI/GUI.hpp | 25 +-- src/slic3r/GUI/GUI_App.cpp | 117 ++++++++++++-- src/slic3r/GUI/GUI_App.hpp | 30 ++++ src/slic3r/GUI/GUI_ObjectParts.cpp | 14 +- src/slic3r/GUI/MainFrame.cpp | 2 +- src/slic3r/GUI/OptionsGroup.hpp | 3 +- src/slic3r/GUI/Plater.cpp | 53 ++++--- src/slic3r/GUI/Tab.cpp | 18 +-- src/slic3r/GUI/Tab.hpp | 6 +- src/slic3r/Utils/PresetUpdater.cpp | 8 +- 17 files changed, 252 insertions(+), 276 deletions(-) diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 4cd833e2f7..296d994147 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -12,6 +12,7 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; #endif /* WIN32 */ +#include "libslic3r/libslic3r_version.h.in" #include "Config.hpp" #include "Geometry.hpp" #include "Model.hpp" @@ -73,7 +74,8 @@ int main(int argc, char **argv) // Path from the Slic3r binary to its resources. path_resources /= (path_to_binary.stem().string() == "slic3r-gui") ? // Running from the build directory: - "../../resources" : +// "../../resources" : // ? #ys_FIXME + "../../../resources" : // ! #ys_FIXME // Running from an installation directory: #ifdef __APPLE__ // The application is packed in the .dmg archive as 'Slic3r.app/Contents/MacOS/Slic3r' diff --git a/src/slic3r/AppController.cpp b/src/slic3r/AppController.cpp index 2bb79cec1a..0d6d07c28d 100644 --- a/src/slic3r/AppController.cpp +++ b/src/slic3r/AppController.cpp @@ -17,6 +17,7 @@ #include #include #include +#include "GUI/GUI_App.hpp" namespace Slic3r { @@ -41,9 +42,9 @@ bool AppControllerGui::is_main_thread() const return m_pri_data->ui_thread == std::this_thread::get_id(); } -namespace GUI { -PresetBundle* get_preset_bundle(); -} +// namespace GUI { +// PresetBundle* get_preset_bundle(); +// } static const PrintObjectStep STEP_SLICE = posSlice; static const PrintObjectStep STEP_PERIMETERS = posPerimeters; @@ -142,7 +143,7 @@ void PrintController::slice_to_png() using Pointf3 = Vec3d; auto ctl = GUI::get_appctl(); - auto presetbundle = GUI::get_preset_bundle(); + auto presetbundle = GUI::wxGetApp().preset_bundle; assert(presetbundle); diff --git a/src/slic3r/GUI/ButtonsDescription.cpp b/src/slic3r/GUI/ButtonsDescription.cpp index 5739fc90e3..8018382169 100644 --- a/src/slic3r/GUI/ButtonsDescription.cpp +++ b/src/slic3r/GUI/ButtonsDescription.cpp @@ -5,6 +5,7 @@ #include #include "GUI.hpp" +#include "GUI_App.hpp" namespace Slic3r { namespace GUI { @@ -36,8 +37,8 @@ ButtonsDescription::ButtonsDescription(wxWindow* parent, t_icon_descriptions* ic // Text color description auto sys_label = new wxStaticText(this, wxID_ANY, _(L("Value is the same as the system value"))); - sys_label->SetForegroundColour(get_label_clr_sys()); - auto sys_colour = new wxColourPickerCtrl(this, wxID_ANY, get_label_clr_sys()); + sys_label->SetForegroundColour(wxGetApp().get_label_clr_sys()); + auto sys_colour = new wxColourPickerCtrl(this, wxID_ANY, wxGetApp().get_label_clr_sys()); sys_colour->Bind(wxEVT_COLOURPICKER_CHANGED, ([sys_colour, sys_label](wxCommandEvent e) { sys_label->SetForegroundColour(sys_colour->GetColour()); @@ -53,8 +54,8 @@ ButtonsDescription::ButtonsDescription(wxWindow* parent, t_icon_descriptions* ic grid_sizer->Add(sys_label, -1, wxALIGN_CENTRE_VERTICAL | wxEXPAND); auto mod_label = new wxStaticText(this, wxID_ANY, _(L("Value was changed and is not equal to the system value or the last saved preset"))); - mod_label->SetForegroundColour(get_label_clr_modified()); - auto mod_colour = new wxColourPickerCtrl(this, wxID_ANY, get_label_clr_modified()); + mod_label->SetForegroundColour(wxGetApp().get_label_clr_modified()); + auto mod_colour = new wxColourPickerCtrl(this, wxID_ANY, wxGetApp().get_label_clr_modified()); mod_colour->Bind(wxEVT_COLOURPICKER_CHANGED, ([mod_colour, mod_label](wxCommandEvent e) { mod_label->SetForegroundColour(mod_colour->GetColour()); @@ -70,8 +71,8 @@ ButtonsDescription::ButtonsDescription(wxWindow* parent, t_icon_descriptions* ic wxButton* btn = static_cast(FindWindowById(wxID_OK, this)); btn->Bind(wxEVT_BUTTON, [sys_colour, mod_colour, this](wxCommandEvent&) { - set_label_clr_sys(sys_colour->GetColour()); - set_label_clr_modified(mod_colour->GetColour()); + wxGetApp().set_label_clr_sys(sys_colour->GetColour()); + wxGetApp().set_label_clr_modified(mod_colour->GetColour()); EndModal(wxID_OK); }); diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index f143e8bc6a..02fc9b8b6c 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -7,6 +7,7 @@ #include #include "PrintConfig.hpp" #include +#include "GUI_App.hpp" namespace Slic3r { namespace GUI { @@ -707,7 +708,7 @@ void StaticText::BUILD() wxString legend(static_cast(m_opt.default_value)->value); auto temp = new wxStaticText(m_parent, wxID_ANY, legend, wxDefaultPosition, size); - temp->SetFont(bold_font()); + temp->SetFont(wxGetApp().bold_font()); // // recast as a wxWindow to fit the calling convention window = dynamic_cast(temp); diff --git a/src/slic3r/GUI/FirmwareDialog.cpp b/src/slic3r/GUI/FirmwareDialog.cpp index d5ac64d900..b836b8e65e 100644 --- a/src/slic3r/GUI/FirmwareDialog.cpp +++ b/src/slic3r/GUI/FirmwareDialog.cpp @@ -35,6 +35,7 @@ #include #include #include +#include "GUI_App.hpp" namespace fs = boost::filesystem; @@ -213,7 +214,7 @@ void FirmwareDialog::priv::flashing_start(unsigned tasks) modal_response = wxID_NONE; txt_stdout->Clear(); set_txt_status(label_status_flashing); - txt_status->SetForegroundColour(GUI::get_label_clr_modified()); + txt_status->SetForegroundColour(GUI::wxGetApp().get_label_clr_modified()); port_picker->Disable(); btn_rescan->Disable(); hex_picker->Disable(); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 5e4e71881e..89f092017e 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -10,6 +10,7 @@ #include "../../libslic3r/ClipperUtils.hpp" #include "../../libslic3r/PrintConfig.hpp" #include "../../libslic3r/GCode/PreviewData.hpp" +#include "GUI_App.hpp" #include @@ -424,7 +425,7 @@ GLCanvas3D::Bed::EType GLCanvas3D::Bed::_detect_type() const { EType type = Custom; - const PresetBundle* bundle = get_preset_bundle(); + auto bundle = wxGetApp().preset_bundle; if (bundle != nullptr) { const Preset* curr = &bundle->printers.get_selected_preset(); diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index ca79becf7d..1a4fbb833b 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -125,18 +125,12 @@ wxPanel *g_wxPlater = nullptr; AppConfig *g_AppConfig = nullptr; PresetBundle *g_PresetBundle= nullptr; PresetUpdater *g_PresetUpdater = nullptr; -wxColour g_color_label_modified; -wxColour g_color_label_sys; -wxColour g_color_label_default; // #ys_FIXME_for_delete std::vector g_tabs_list; wxLocale* g_wxLocale {nullptr}; -wxFont g_small_font; -wxFont g_bold_font; - std::vector > m_optgroups; double m_brim_width = 0.0; size_t m_label_width = 100; @@ -154,53 +148,13 @@ bool g_show_manifold_warning_icon = false; PreviewIface* g_preview = nullptr; -static void init_label_colours() -{ - auto luma = get_colour_approx_luma(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - if (luma >= 128) { - g_color_label_modified = wxColour(252, 77, 1); - g_color_label_sys = wxColour(26, 132, 57); - } else { - g_color_label_modified = wxColour(253, 111, 40); - g_color_label_sys = wxColour(115, 220, 103); - } - g_color_label_default = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); -} - -void update_label_colours_from_appconfig() -{ - if (g_AppConfig->has("label_clr_sys")){ - auto str = g_AppConfig->get("label_clr_sys"); - if (str != "") - g_color_label_sys = wxColour(str); - } - - if (g_AppConfig->has("label_clr_modified")){ - auto str = g_AppConfig->get("label_clr_modified"); - if (str != "") - g_color_label_modified = wxColour(str); - } -} - -static void init_fonts() -{ - g_small_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); - g_bold_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Bold(); -#ifdef __WXMAC__ - g_small_font.SetPointSize(11); - g_bold_font.SetPointSize(13); -#endif /*__WXMAC__*/ -} - -static std::string libslic3r_translate_callback(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)).utf8_str().data(); } +// static std::string libslic3r_translate_callback(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)).utf8_str().data(); } void set_wxapp(wxApp *app) { g_wxApp = app; // Let the libslic3r know the callback, which will translate messages on demand. - Slic3r::I18N::set_translate_callback(libslic3r_translate_callback); - init_label_colours(); - init_fonts(); +// Slic3r::I18N::set_translate_callback(libslic3r_translate_callback); } void set_main_frame(wxFrame *main_frame) @@ -269,8 +223,8 @@ void set_objects_from_perl( wxWindow* parent, g_buttons.push_back(btn_send_gcode); // Update font style for buttons - for (auto btn : g_buttons) - btn->SetFont(bold_font()); +// for (auto btn : g_buttons) +// btn->SetFont(bold_font()); g_manifold_warning_icon = manifold_warning_icon; } @@ -298,26 +252,6 @@ void set_objects_list_sizer(wxBoxSizer *objects_list_sizer){ g_object_list_sizer = objects_list_sizer; } -std::vector& get_tabs_list() -{ - return g_tabs_list; -} - -bool checked_tab(Tab* tab) -{ - bool ret = true; - if (find(g_tabs_list.begin(), g_tabs_list.end(), tab) == g_tabs_list.end()) - ret = false; - return ret; -} - -void delete_tab_from_list(Tab* tab) -{ - std::vector::iterator itr = find(g_tabs_list.begin(), g_tabs_list.end(), tab); - if (itr != g_tabs_list.end()) - g_tabs_list.erase(itr); -} - bool select_language(wxArrayString & names, wxArrayLong & identifiers) { @@ -423,31 +357,32 @@ void get_installed_languages(wxArrayString & names, } } -enum ConfigMenuIDs { - ConfigMenuWizard, - ConfigMenuSnapshots, - ConfigMenuTakeSnapshot, - ConfigMenuUpdate, - ConfigMenuPreferences, - ConfigMenuModeSimple, - ConfigMenuModeExpert, - ConfigMenuLanguage, - ConfigMenuFlashFirmware, - ConfigMenuCnt, -}; +// enum ConfigMenuIDs { +// ConfigMenuWizard, +// ConfigMenuSnapshots, +// ConfigMenuTakeSnapshot, +// ConfigMenuUpdate, +// ConfigMenuPreferences, +// ConfigMenuModeSimple, +// ConfigMenuModeExpert, +// ConfigMenuLanguage, +// ConfigMenuFlashFirmware, +// ConfigMenuCnt, +// }; // #ys_FIXME_for_delete -ConfigMenuIDs get_view_mode() -{ - if (!g_AppConfig->has("view_mode")) - return ConfigMenuModeSimple; - - const auto mode = g_AppConfig->get("view_mode"); - return mode == "expert" ? ConfigMenuModeExpert : ConfigMenuModeSimple; -} +// ConfigMenuIDs get_view_mode() +// { +// if (!g_AppConfig->has("view_mode")) +// return ConfigMenuModeSimple; +// +// const auto mode = g_AppConfig->get("view_mode"); +// return mode == "expert" ? ConfigMenuModeExpert : ConfigMenuModeSimple; +// } static wxString dots("…", wxConvUTF8); // #ys_FIXME_for_delete +/* void add_config_menu(wxMenuBar *menu, int event_preferences_changed, int event_language_change) { auto local_menu = new wxMenu(); @@ -551,7 +486,7 @@ void add_menus(wxMenuBar *menu, int event_preferences_changed, int event_languag { add_config_menu(menu, event_preferences_changed, event_language_change); } - +*/ void open_model(wxWindow *parent, wxArrayString& input_files){ auto dialog = new wxFileDialog(parent /*? parent : GetTopWindow()*/, _(L("Choose one or more files (STL/OBJ/AMF/3MF/PRUSA):")), @@ -569,6 +504,7 @@ void open_model(wxWindow *parent, wxArrayString& input_files){ // This is called when closing the application, when loading a config file or when starting the config wizard // to notify the user whether he is aware that some preset changes will be lost. // #ys_FIXME_for_delete +/* bool check_unsaved_changes() { std::string dirty; @@ -588,7 +524,7 @@ bool check_unsaved_changes() wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT); return dialog->ShowModal() == wxID_YES; } - +*/ bool config_wizard_startup(bool app_config_exists) { if (! app_config_exists || g_PresetBundle->printers.size() <= 1) { @@ -610,7 +546,7 @@ bool config_wizard_startup(bool app_config_exists) void config_wizard(int reason) { // Exit wizard if there are unsaved changes and the user cancels the action. - if (! check_unsaved_changes()) + if (! wxGetApp().check_unsaved_changes()) return; try { @@ -622,7 +558,7 @@ void config_wizard(int reason) } // Load the currently selected preset into the GUI, update the preset selection box. - load_current_presets(); + wxGetApp().load_current_presets(); } void open_preferences_dialog(int event_preferences) @@ -631,6 +567,8 @@ void open_preferences_dialog(int event_preferences) dlg->ShowModal(); } +// #ys_FIXME_for_delete +/* void create_preset_tabs(int event_value_change, int event_presets_changed) { update_label_colours_from_appconfig(); @@ -639,7 +577,7 @@ void create_preset_tabs(int event_value_change, int event_presets_changed) add_created_tab(new TabSLAMaterial (g_wxTabPanel), event_value_change, event_presets_changed); add_created_tab(new TabPrinter (g_wxTabPanel), event_value_change, event_presets_changed); } - +*/ std::vector preset_tabs = { { "print", nullptr, ptFFF }, { "filament", nullptr, ptFFF }, @@ -790,37 +728,6 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt int i = 0;//no reason, just experiment } } -// #ys_FIXME_for_delete -void add_created_tab(Tab* panel, int event_value_change, int event_presets_changed) -{ - panel->create_preset_tab(g_PresetBundle); - - // Load the currently selected preset into the GUI, update the preset selection box. - panel->load_current_preset(); - - panel->set_event_value_change(wxEventType(event_value_change)); - panel->set_event_presets_changed(wxEventType(event_presets_changed)); - - const wxString& tab_name = panel->GetName(); - bool add_panel = true; - - auto it = std::find_if( preset_tabs.begin(), preset_tabs.end(), - [tab_name](PresetTab& tab){return tab.name == tab_name; }); - if (it != preset_tabs.end()) { - it->panel = panel; - add_panel = it->technology == g_PresetBundle->printers.get_edited_preset().printer_technology(); - } - - if (add_panel) - g_wxTabPanel->AddPage(panel, panel->title()); -} - -void load_current_presets() -{ - for (Tab *tab : g_tabs_list) { - tab->load_current_preset(); - } -} void show_error(wxWindow* parent, const wxString& message) { ErrorDialog msg(parent, message); @@ -860,60 +767,6 @@ wxApp* get_app(){ return g_wxApp; } -PresetBundle* get_preset_bundle() -{ - return g_PresetBundle; -} - -const wxColour& get_label_clr_modified() { - return g_color_label_modified; -} - -const wxColour& get_label_clr_sys() { - return g_color_label_sys; -} - -void set_label_clr_modified(const wxColour& clr) { - g_color_label_modified = clr; - auto clr_str = wxString::Format(wxT("#%02X%02X%02X"), clr.Red(), clr.Green(), clr.Blue()); - std::string str = clr_str.ToStdString(); - g_AppConfig->set("label_clr_modified", str); - g_AppConfig->save(); -} - -void set_label_clr_sys(const wxColour& clr) { - g_color_label_sys = clr; - auto clr_str = wxString::Format(wxT("#%02X%02X%02X"), clr.Red(), clr.Green(), clr.Blue()); - std::string str = clr_str.ToStdString(); - g_AppConfig->set("label_clr_sys", str); - g_AppConfig->save(); -} - -const wxFont& small_font(){ - return g_small_font; -} - -const wxFont& bold_font(){ - return g_bold_font; -} - -const wxColour& get_label_clr_default() { - return g_color_label_default; -} - -unsigned get_colour_approx_luma(const wxColour &colour) -{ - double r = colour.Red(); - double g = colour.Green(); - double b = colour.Blue(); - - return std::round(std::sqrt( - r * r * .241 + - g * g * .691 + - b * b * .068 - )); -} - wxWindow* get_right_panel(){ return g_right_panel; } @@ -1199,7 +1052,7 @@ void update_mode() { wxWindowUpdateLocker noUpdates(g_right_panel->GetParent()); - ConfigMenuIDs mode = get_view_mode(); + ConfigMenuIDs mode = wxGetApp().get_view_mode(); g_object_list_sizer->Show(mode == ConfigMenuModeExpert); show_info_sizer(mode == ConfigMenuModeExpert); @@ -1216,7 +1069,7 @@ void update_mode() } bool is_expert_mode(){ - return get_view_mode() == ConfigMenuModeExpert; + return wxGetApp().get_view_mode() == ConfigMenuModeExpert; } ConfigOptionsGroup* get_optgroup(size_t i) diff --git a/src/slic3r/GUI/GUI.hpp b/src/slic3r/GUI/GUI.hpp index 3ef662222d..83f9542486 100644 --- a/src/slic3r/GUI/GUI.hpp +++ b/src/slic3r/GUI/GUI.hpp @@ -127,26 +127,14 @@ void set_objects_list_sizer(wxBoxSizer *objects_list_sizer); AppConfig* get_app_config(); wxApp* get_app(); -PresetBundle* get_preset_bundle(); wxFrame* get_main_frame(); ProgressStatusBar* get_progress_status_bar(); -wxNotebook * get_tab_panel(); wxNotebook* get_tab_panel(); AppControllerPtr get_appctl(); void set_cli_appctl(); void set_gui_appctl(); -const wxColour& get_label_clr_modified(); -const wxColour& get_label_clr_sys(); -const wxColour& get_label_clr_default(); -unsigned get_colour_approx_luma(const wxColour &colour); -void set_label_clr_modified(const wxColour& clr); -void set_label_clr_sys(const wxColour& clr); - -const wxFont& small_font(); -const wxFont& bold_font(); - void open_model(wxWindow *parent, wxArrayString& input_files); wxWindow* get_right_panel(); @@ -159,7 +147,7 @@ extern void add_menus(wxMenuBar *menu, int event_preferences_changed, int event_ // This is called when closing the application, when loading a config file or when starting the config wizard // to notify the user whether he is aware that some preset changes will be lost. -extern bool check_unsaved_changes(); +// extern bool check_unsaved_changes(); // Checks if configuration wizard needs to run, calls config_wizard if so. // Returns whether the Wizard ran. @@ -173,19 +161,16 @@ extern void config_wizard(int run_reason); extern void open_preferences_dialog(int event_preferences); // Create a new preset tab (print, filament and printer), -void create_preset_tabs(int event_value_change, int event_presets_changed); +// void create_preset_tabs(int event_value_change, int event_presets_changed); TabIface* get_preset_tab_iface(char *name); PreviewIface* create_preview_iface(wxNotebook* notebook, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data); // add it at the end of the tab panel. -void add_created_tab(Tab* panel, int event_value_change, int event_presets_changed); +// void add_created_tab(Tab* panel, int event_value_change, int event_presets_changed); // Change option value in config void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index = 0); -// Update UI / Tabs to reflect changes in the currently loaded presets -void load_current_presets(); - void show_error(wxWindow* parent, const wxString& message); void show_error_id(int id, const std::string& message); // For Perl void show_info(wxWindow* parent, const wxString& message, const wxString& title); @@ -209,10 +194,6 @@ void update_mode(); void show_info_sizer(const bool show); -std::vector& get_tabs_list(); -bool checked_tab(Tab* tab); -void delete_tab_from_list(Tab* tab); - // Creates a wxCheckListBoxComboPopup inside the given wxComboCtrl, filled with the given text and items. // Items are all initialized to the given value. // Items must be separated by '|', for example "Item1|Item2|Item3", and so on. diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 6aeea4a74b..6bca605686 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -25,10 +25,13 @@ #include "FirmwareDialog.hpp" #include "Preferences.hpp" #include "Tab.hpp" +#include namespace Slic3r { namespace GUI { +static std::string libslic3r_translate_callback(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)).utf8_str().data(); } + IMPLEMENT_APP(GUI_App) bool GUI_App::OnInit() { @@ -42,13 +45,12 @@ bool GUI_App::OnInit() // Windows : "C:\Users\username\AppData\Roaming\Slic3r" or "C:\Documents and Settings\username\Application Data\Slic3r" // Mac : "~/Library/Application Support/Slic3r" if (data_dir().empty()) - Slic3r::set_data_dir(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data()); - // set_wxapp(this); // #ys_FIXME + set_data_dir(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data()); app_config = new AppConfig(); - // set_app_config(app_config);// #ys_FIXME + set_app_config(app_config); preset_bundle = new PresetBundle(); - set_preset_bundle(preset_bundle); // #ys_FIXME + set_preset_bundle(preset_bundle); // just checking for existence of Slic3r::data_dir is not enough : it may be an empty directory // supplied as argument to --datadir; in that case we should still run the wizard @@ -62,11 +64,11 @@ bool GUI_App::OnInit() app_conf_exists = app_config->exists(); // load settings if (app_conf_exists) app_config->load(); - app_config->set("version", "Slic3r_VERSION"/*Slic3r::VERSION*/); + app_config->set("version", SLIC3R_VERSION); app_config->save(); -// preset_updater = new PresetUpdater(); -// set_preset_updater(preset_updater); // #ys_FIXME + preset_updater = new PresetUpdater(); + set_preset_updater(preset_updater); load_language(); @@ -80,8 +82,14 @@ bool GUI_App::OnInit() // show_error(undef, $@); // } + // Let the libslic3r know the callback, which will translate messages on demand. + Slic3r::I18N::set_translate_callback(libslic3r_translate_callback); + // initialize label colors and fonts + init_label_colours(); + init_fonts(); + // application frame - // print STDERR "Creating main frame...\n"; + std::cerr << "Creating main frame..." << std::endl; // wxImage::FindHandlerType(wxBITMAP_TYPE_PNG) || wxImage::AddHandler(new wxPNGHandler()); mainframe = new Slic3r::GUI::MainFrame(no_plater, false); @@ -157,9 +165,77 @@ bool GUI_App::OnInit() return true; } +unsigned GUI_App::get_colour_approx_luma(const wxColour &colour) +{ + double r = colour.Red(); + double g = colour.Green(); + double b = colour.Blue(); + + return std::round(std::sqrt( + r * r * .241 + + g * g * .691 + + b * b * .068 + )); +} + +void GUI_App::init_label_colours() +{ + auto luma = get_colour_approx_luma(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + if (luma >= 128) { + m_color_label_modified = wxColour(252, 77, 1); + m_color_label_sys = wxColour(26, 132, 57); + } + else { + m_color_label_modified = wxColour(253, 111, 40); + m_color_label_sys = wxColour(115, 220, 103); + } + m_color_label_default = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); +} + +void GUI_App::update_label_colours_from_appconfig() +{ + if (app_config->has("label_clr_sys")){ + auto str = app_config->get("label_clr_sys"); + if (str != "") + m_color_label_sys = wxColour(str); + } + + if (app_config->has("label_clr_modified")){ + auto str = app_config->get("label_clr_modified"); + if (str != "") + m_color_label_modified = wxColour(str); + } +} + +void GUI_App::init_fonts() +{ + m_small_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + m_bold_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Bold(); +#ifdef __WXMAC__ + m_small_font.SetPointSize(11); + m_bold_font.SetPointSize(13); +#endif /*__WXMAC__*/ +} + +void GUI_App::set_label_clr_modified(const wxColour& clr) { + m_color_label_modified = clr; + auto clr_str = wxString::Format(wxT("#%02X%02X%02X"), clr.Red(), clr.Green(), clr.Blue()); + std::string str = clr_str.ToStdString(); + app_config->set("label_clr_modified", str); + app_config->save(); +} + +void GUI_App::set_label_clr_sys(const wxColour& clr) { + m_color_label_sys = clr; + auto clr_str = wxString::Format(wxT("#%02X%02X%02X"), clr.Red(), clr.Green(), clr.Blue()); + std::string str = clr_str.ToStdString(); + app_config->set("label_clr_sys", str); + app_config->save(); +} + void GUI_App::recreate_GUI() { -// print STDERR "recreate_GUI\n"; + std::cerr << "recreate_GUI" << std::endl; auto topwindow = GetTopWindow(); mainframe = new Slic3r::GUI::MainFrame(no_plater,false); @@ -478,6 +554,29 @@ bool GUI_App::check_unsaved_changes() return dialog->ShowModal() == wxID_YES; } +bool GUI_App::checked_tab(Tab* tab) +{ + bool ret = true; + if (find(tabs_list.begin(), tabs_list.end(), tab) == tabs_list.end()) + ret = false; + return ret; +} + +void GUI_App::delete_tab_from_list(Tab* tab) +{ + std::vector::iterator itr = find(tabs_list.begin(), tabs_list.end(), tab); + if (itr != tabs_list.end()) + tabs_list.erase(itr); +} + +// Update UI / Tabs to reflect changes in the currently loaded presets +void GUI_App::load_current_presets() +{ + for (Tab *tab : tabs_list) { + tab->load_current_preset(); + } +} + wxNotebook* GUI_App::tab_panel() const { return mainframe->m_tabpanel; diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 99c3d2c1ef..a6e2cdc7a9 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -8,6 +8,8 @@ // #include "GUI.hpp" #include +#include +#include #include #include @@ -50,10 +52,35 @@ class GUI_App : public wxApp // callbacks registered to run during idle event. std::stack> m_cb{}; + wxColour m_color_label_modified; + wxColour m_color_label_sys; + wxColour m_color_label_default; + + wxFont m_small_font; + wxFont m_bold_font; + + // #ys_FIXME +// std::vector g_tabs_list; +// wxLocale* g_wxLocale{ nullptr }; + public: bool OnInit() override; GUI_App() : wxApp() {} + unsigned get_colour_approx_luma(const wxColour &colour); + void init_label_colours(); + void update_label_colours_from_appconfig(); + void init_fonts(); + void set_label_clr_modified(const wxColour& clr); + void set_label_clr_sys(const wxColour& clr); + + const wxColour& get_label_clr_modified(){ return m_color_label_modified; } + const wxColour& get_label_clr_sys() { return m_color_label_sys; } + const wxColour& get_label_clr_default() { return m_color_label_default; } + + const wxFont& small_font() { return m_small_font; } + const wxFont& bold_font() { return m_bold_font; } + void recreate_GUI(); void system_info(); void open_model(wxWindow *parent, wxArrayString& input_files); @@ -82,7 +109,10 @@ public: ConfigMenuIDs get_view_mode(); void add_config_menu(wxMenuBar *menu); bool check_unsaved_changes(); + bool checked_tab(Tab* tab); + void delete_tab_from_list(Tab* tab); // Tab* get_tab(const std::string& name); + void load_current_presets(); AppConfig* app_config{ nullptr }; PresetBundle* preset_bundle{ nullptr }; diff --git a/src/slic3r/GUI/GUI_ObjectParts.cpp b/src/slic3r/GUI/GUI_ObjectParts.cpp index bcc3282b88..d27494617a 100644 --- a/src/slic3r/GUI/GUI_ObjectParts.cpp +++ b/src/slic3r/GUI/GUI_ObjectParts.cpp @@ -365,13 +365,13 @@ wxBoxSizer* create_edit_object_buttons(wxWindow* win) } m_sizer_part_buttons->Show(false); - btn_load_part->SetFont(Slic3r::GUI::small_font()); - btn_load_modifier->SetFont(Slic3r::GUI::small_font()); - btn_load_lambda_modifier->SetFont(Slic3r::GUI::small_font()); - btn_delete->SetFont(Slic3r::GUI::small_font()); - btn_split->SetFont(Slic3r::GUI::small_font()); - m_btn_move_up->SetFont(Slic3r::GUI::small_font()); - m_btn_move_down->SetFont(Slic3r::GUI::small_font()); + btn_load_part->SetFont(wxGetApp().small_font()); + btn_load_modifier->SetFont(wxGetApp().small_font()); + btn_load_lambda_modifier->SetFont(wxGetApp().small_font()); + btn_delete->SetFont(wxGetApp().small_font()); + btn_split->SetFont(wxGetApp().small_font()); + m_btn_move_up->SetFont(wxGetApp().small_font()); + m_btn_move_down->SetFont(wxGetApp().small_font()); sizer->Add(m_sizer_object_buttons, 0, wxEXPAND | wxLEFT, 20); sizer->Add(m_sizer_part_buttons, 0, wxEXPAND | wxLEFT, 20); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index ee90cf297f..1aba0f7c7f 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -276,7 +276,7 @@ Tab* MainFrame::get_preset_tab(const std::string& name) void MainFrame::create_preset_tabs() { -// update_label_colours_from_appconfig(); + wxGetApp().update_label_colours_from_appconfig(); add_created_tab(new TabPrint(m_tabpanel)); add_created_tab(new TabFilament(m_tabpanel)); add_created_tab(new TabSLAMaterial(m_tabpanel)); diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index 4941e54539..3e196f70c8 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -14,6 +14,7 @@ #include "libslic3r/libslic3r.h" #include "Field.hpp" +#include "GUI_App.hpp" // Translate the ifdef #ifdef __WXOSX__ @@ -163,7 +164,7 @@ public: staticbox(title!=""), m_flag(flag), extra_column(extra_clmn){ if (staticbox) { stb = new wxStaticBox(_parent, wxID_ANY, title); - stb->SetFont(bold_font()); + stb->SetFont(wxGetApp().bold_font()); } sizer = (staticbox ? new wxStaticBoxSizer(stb, wxVERTICAL) : new wxBoxSizer(wxVERTICAL)); auto num_columns = 1U; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index e48ae031b4..1652a059cb 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -81,7 +81,7 @@ private: ObjectInfo::ObjectInfo(wxWindow *parent) : wxStaticBoxSizer(new wxStaticBox(parent, wxID_ANY, _(L("Info"))), wxVERTICAL) { - // GetStaticBox()->SetFont(GUI::bold_font()); // XXX: ? + GetStaticBox()->SetFont(wxGetApp().bold_font()); auto *grid_sizer = new wxFlexGridSizer(4, 5, 5); grid_sizer->SetFlexibleDirection(wxHORIZONTAL); @@ -90,9 +90,9 @@ ObjectInfo::ObjectInfo(wxWindow *parent) : auto init_info_label = [parent, grid_sizer](wxStaticText **info_label, wxString text_label) { auto *text = new wxStaticText(parent, wxID_ANY, text_label); - text->SetFont(GUI::small_font()); + text->SetFont(wxGetApp().small_font()); *info_label = new wxStaticText(parent, wxID_ANY, ""); - (*info_label)->SetFont(GUI::small_font()); + (*info_label)->SetFont(wxGetApp().small_font()); grid_sizer->Add(text, 0); grid_sizer->Add(*info_label, 0); }; @@ -103,9 +103,9 @@ ObjectInfo::ObjectInfo(wxWindow *parent) : init_info_label(&info_materials, _(L("Materials"))); auto *info_manifold_text = new wxStaticText(parent, wxID_ANY, _(L("Manifold"))); - info_manifold_text->SetFont(GUI::small_font()); + info_manifold_text->SetFont(wxGetApp().small_font()); info_manifold = new wxStaticText(parent, wxID_ANY, ""); - info_manifold->SetFont(GUI::small_font()); + info_manifold->SetFont(wxGetApp().small_font()); wxBitmap bitmap(GUI::from_u8(Slic3r::var("error.png")), wxBITMAP_TYPE_PNG); manifold_warning_icon = new wxStaticBitmap(parent, wxID_ANY, bitmap); auto *sizer_manifold = new wxBoxSizer(wxHORIZONTAL); @@ -134,18 +134,17 @@ private: SlicedInfo::SlicedInfo(wxWindow *parent) : wxStaticBoxSizer(new wxStaticBox(parent, wxID_ANY, _(L("Sliced Info"))), wxVERTICAL) { - // GetStaticBox()->SetFont(GUI::bold_font()); // XXX: ? + GetStaticBox()->SetFont(wxGetApp().bold_font()); auto *grid_sizer = new wxFlexGridSizer(2, 5, 5); grid_sizer->SetFlexibleDirection(wxHORIZONTAL); grid_sizer->AddGrowableCol(1, 1); - grid_sizer->AddGrowableCol(3, 1); auto init_info_label = [parent, grid_sizer](wxStaticText *&info_label, wxString text_label) { auto *text = new wxStaticText(parent, wxID_ANY, text_label); - text->SetFont(GUI::small_font()); + text->SetFont(wxGetApp().small_font()); info_label = new wxStaticText(parent, wxID_ANY, "N/A"); - info_label->SetFont(GUI::small_font()); + info_label->SetFont(wxGetApp().small_font()); grid_sizer->Add(text, 0); grid_sizer->Add(info_label, 0); }; @@ -231,7 +230,6 @@ Sidebar::Sidebar(wxWindow *parent) : wxPanel(parent), p(new priv) { p->scrolled = new wxScrolledWindow(this); - p->scrolled->SetScrollbars(0, 1, 1, 1); // XXX // The preset chooser p->sizer_presets = new wxFlexGridSizer(4, 2, 1, 2); @@ -240,10 +238,10 @@ Sidebar::Sidebar(wxWindow *parent) p->sizer_filaments = new wxBoxSizer(wxVERTICAL); auto init_combo = [this](PresetComboBox **combo, wxString label, Preset::Type preset_type, bool filament) { - auto *text = new wxStaticText(this, wxID_ANY, label); - text->SetFont(GUI::small_font()); + auto *text = new wxStaticText(p->scrolled, wxID_ANY, label); + text->SetFont(wxGetApp().small_font()); // combo = new wxBitmapComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY); - *combo = new PresetComboBox(this, preset_type); + *combo = new PresetComboBox(p->scrolled, preset_type); auto *sizer_presets = this->p->sizer_presets; auto *sizer_filaments = this->p->sizer_filaments; @@ -262,13 +260,15 @@ Sidebar::Sidebar(wxWindow *parent) init_combo(&p->combo_sla_material, _(L("SLA material")), Preset::TYPE_SLA_MATERIAL, false); init_combo(&p->combo_printer, _(L("Printer")), Preset::TYPE_PRINTER, false); + p->sizer_presets->Layout(); + // Frequently changed parameters p->sizer_params = new wxBoxSizer(wxVERTICAL); - // GUI::add_frequently_changed_parameters(this, p->sizer_params, p->sizer_presets); + GUI::add_frequently_changed_parameters(p->scrolled, p->sizer_params, p->sizer_presets); // Buttons in the scrolled area wxBitmap arrow_up(GUI::from_u8(Slic3r::var("brick_go.png")), wxBITMAP_TYPE_PNG); - p->btn_send_gcode = new wxButton(this, wxID_ANY, _(L("Send to printer"))); + p->btn_send_gcode = new wxButton(p->scrolled, wxID_ANY, _(L("Send to printer"))); p->btn_send_gcode->SetBitmap(arrow_up); p->btn_send_gcode->Hide(); auto *btns_sizer_scrolled = new wxBoxSizer(wxHORIZONTAL); @@ -276,32 +276,37 @@ Sidebar::Sidebar(wxWindow *parent) btns_sizer_scrolled->Add(p->btn_send_gcode); // Info boxes - p->object_info = new ObjectInfo(this); - p->sliced_info = new SlicedInfo(this); + p->object_info = new ObjectInfo(p->scrolled); + p->sliced_info = new SlicedInfo(p->scrolled); // Sizer in the scrolled area auto *scrolled_sizer = new wxBoxSizer(wxVERTICAL); + scrolled_sizer->SetMinSize(320, -1); + p->scrolled->SetSizer(scrolled_sizer); + p->scrolled->SetScrollbars(0, 1, 1, 1); std::cerr << "scrolled_sizer: " << scrolled_sizer << std::endl; scrolled_sizer->Add(p->sizer_presets, 0, wxEXPAND | wxLEFT, 2); - scrolled_sizer->Add(p->object_info, 1, wxEXPAND); + scrolled_sizer->Add(p->sizer_params, 1, wxEXPAND); + scrolled_sizer->Add(p->object_info, 0, wxEXPAND | wxTOP | wxLEFT, 20); scrolled_sizer->Add(btns_sizer_scrolled, 0, wxEXPAND, 0); - scrolled_sizer->Add(p->sliced_info, 0, wxEXPAND); + scrolled_sizer->Add(p->sliced_info, 0, wxEXPAND | wxTOP | wxLEFT, 20); // Buttons underneath the scrolled area p->btn_export_gcode = new wxButton(this, wxID_ANY, _(L("Export G-code…"))); + p->btn_export_gcode->SetFont(wxGetApp().bold_font()); p->btn_reslice = new wxButton(this, wxID_ANY, _(L("Slice now"))); + p->btn_reslice->SetFont(wxGetApp().bold_font()); auto *btns_sizer = new wxBoxSizer(wxVERTICAL); std::cerr << "btns_sizer: " << btns_sizer << std::endl; - btns_sizer->Add(p->btn_reslice); - btns_sizer->Add(p->btn_export_gcode); + btns_sizer->Add(p->btn_reslice, 0, wxEXPAND | wxTOP, 5); + btns_sizer->Add(p->btn_export_gcode, 0, wxEXPAND | wxTOP, 5); auto *sizer = new wxBoxSizer(wxVERTICAL); std::cerr << "sizer: " << sizer << std::endl; - sizer->Add(scrolled_sizer); - sizer->Add(btns_sizer); + sizer->Add(p->scrolled, 1, wxEXPAND | wxTOP, 5); + sizer->Add(btns_sizer, 0, wxEXPAND | wxLEFT, 20); SetSizer(sizer); - SetMinSize(wxSize(320, -1)); } Sidebar::~Sidebar() {} diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index def9ea5b55..e4a1f5933b 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -99,7 +99,7 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) "or click this button."))); // Determine the theme color of OS (dark or light) - auto luma = get_colour_approx_luma(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + auto luma = wxGetApp().get_colour_approx_luma(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); // Bitmaps to be shown on the "Revert to system" aka "Lock to system" button next to each input field. m_bmp_value_lock .LoadFile(from_u8(var("sys_lock.png")), wxBITMAP_TYPE_PNG); m_bmp_value_unlock .LoadFile(from_u8(var(luma >= 128 ? "sys_unlock.png" : "sys_unlock_grey.png")), wxBITMAP_TYPE_PNG); @@ -122,18 +122,18 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) auto dlg = new ButtonsDescription(this, &m_icon_descriptions); if (dlg->ShowModal() == wxID_OK){ // Colors for ui "decoration" - for (Tab *tab : get_tabs_list()){ - tab->m_sys_label_clr = get_label_clr_sys(); - tab->m_modified_label_clr = get_label_clr_modified(); + for (Tab *tab : wxGetApp().tabs_list){ + tab->m_sys_label_clr = wxGetApp().get_label_clr_sys(); + tab->m_modified_label_clr = wxGetApp().get_label_clr_modified(); tab->update_labels_colour(); } } })); // Colors for ui "decoration" - m_sys_label_clr = get_label_clr_sys(); - m_modified_label_clr = get_label_clr_modified(); - m_default_text_clr = get_label_clr_default(); + m_sys_label_clr = wxGetApp().get_label_clr_sys(); + m_modified_label_clr = wxGetApp().get_label_clr_modified(); + m_default_text_clr = wxGetApp().get_label_clr_default(); m_hsizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(m_hsizer, 0, wxBOTTOM, 3); @@ -1484,7 +1484,7 @@ void TabPrinter::build_fff() Line line{ _(L("Bed shape")), "" }; line.widget = [this](wxWindow* parent){ auto btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); - btn->SetFont(Slic3r::GUI::small_font()); + btn->SetFont(wxGetApp().small_font()); btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("printer_empty.png")), wxBITMAP_TYPE_PNG)); auto sizer = new wxBoxSizer(wxHORIZONTAL); @@ -2183,7 +2183,7 @@ void Tab::load_current_preset() // (not sure this is true anymore now that update_dirty is idempotent) wxTheApp->CallAfter([this]{ // checking out if this Tab exists till this moment - if (!checked_tab(this)) + if (!wxGetApp().checked_tab(this)) return; update_tab_ui(); diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index e4e37d4eb8..afdf2008b2 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -57,7 +57,7 @@ public: { Create(m_parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); m_vsizer = new wxBoxSizer(wxVERTICAL); - m_item_color = &get_label_clr_default(); + m_item_color = &wxGetApp().get_label_clr_default(); SetSizer(m_vsizer); } ~Page(){} @@ -201,10 +201,10 @@ public: Tab(wxNotebook* parent, const wxString& title, const char* name) : m_parent(parent), m_title(title), m_name(name) { Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL, name); - get_tabs_list().push_back(this); + wxGetApp().tabs_list.push_back(this); } ~Tab(){ - delete_tab_from_list(this); + wxGetApp().delete_tab_from_list(this); } wxWindow* parent() const { return m_parent; } diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index 617afb68db..026e340da5 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -570,10 +570,10 @@ bool PresetUpdater::config_update() const BOOST_LOG_TRIVIAL(info) << "User wants to re-configure..."; p->perform_updates(std::move(updates)); GUI::ConfigWizard wizard(nullptr, GUI::ConfigWizard::RR_DATA_INCOMPAT); - if (! wizard.run(GUI::get_preset_bundle(), this)) { + if (! wizard.run(GUI::wxGetApp().preset_bundle, this)) { return false; } - GUI::load_current_presets(); + GUI::wxGetApp().load_current_presets(); } else { BOOST_LOG_TRIVIAL(info) << "User wants to exit Slic3r, bye..."; return false; @@ -603,8 +603,8 @@ bool PresetUpdater::config_update() const // Reload global configuration auto *app_config = GUI::wxGetApp().app_config; - GUI::get_preset_bundle()->load_presets(*app_config); - GUI::load_current_presets(); + GUI::wxGetApp().preset_bundle->load_presets(*app_config); + GUI::wxGetApp().load_current_presets(); } else { BOOST_LOG_TRIVIAL(info) << "User refused the update"; }