From ed8430bc9b593d0635a93166184552d2fbc7bdd5 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Fri, 10 May 2019 14:43:35 +0200 Subject: [PATCH] Application will pick translation dictionaries based on the system default language on first start of Slic3r. Updated help menu (removed reference to the upstream manual) Fixed some OpenGL assert due to glOrtho being called with zero Z span. --- src/slic3r/GUI/ConfigWizard.cpp | 2 +- src/slic3r/GUI/GLCanvas3D.cpp | 3 +- src/slic3r/GUI/GUI.cpp | 1 - src/slic3r/GUI/GUI_App.cpp | 52 +++++++++++++++++++++------------ src/slic3r/GUI/GUI_App.hpp | 12 ++++---- src/slic3r/GUI/MainFrame.cpp | 8 ++--- 6 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index 09d0ec085..5850ea4e7 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -1062,7 +1062,7 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese // Public ConfigWizard::ConfigWizard(wxWindow *parent, RunReason reason) - : DPIDialog(parent, wxID_ANY, _(name().ToStdString()), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) + : DPIDialog(parent, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _(name().ToStdString()), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) , p(new priv(this)) { this->SetFont(wxGetApp().normal_font()); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 36581369c..5efdde4d7 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3612,7 +3612,8 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h) } // FIXME: calculate a tighter value for depth will improve z-fighting - float depth = 5.0f * (float)bbox.max_size(); + // Set at least some minimum depth in case the bounding box is empty to avoid an OpenGL driver error. + float depth = std::max(1.f, 5.0f * (float)bbox.max_size()); m_camera.apply_ortho_projection(-w2, w2, -h2, h2, -depth, depth); break; diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index e54802770..9a641c7c0 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -104,7 +104,6 @@ const std::string& shortkey_alt_prefix() bool config_wizard_startup(bool app_config_exists) { if (!app_config_exists || wxGetApp().preset_bundle->printers.size() <= 1) { - wxGetApp().switch_language(); config_wizard(ConfigWizard::RR_DATA_EMPTY); return true; } else if (get_app_config()->legacy_datadir()) { diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 9390c8c5d..c08856ffc 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -579,33 +579,47 @@ bool GUI_App::select_language() return false; } -// load language saved at application config +// Load gettext translation files and activate them at the start of the application, +// based on the "translation_language" key stored in the application config. bool GUI_App::load_language() { wxString language = wxEmptyString; if (app_config->has("translation_language")) language = app_config->get("translation_language"); - if (language.IsEmpty()) - return false; - - const auto langs = get_installed_languages(); - for (const wxLanguageInfo *info : langs) - { - if (info->CanonicalName == language) - { - m_wxLocale = new wxLocale; - m_wxLocale->Init(info->Language); - m_wxLocale->AddCatalogLookupPathPrefix(from_u8(localization_dir())); - m_wxLocale->AddCatalog("Slic3rPE"); - //FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only. - wxSetlocale(LC_NUMERIC, "C"); - Preset::update_suffix_modified(); - m_imgui->set_language(into_u8(info->CanonicalName)); - return true; + if (language.IsEmpty()) { + int lang = wxLocale::GetSystemLanguage(); + if (lang != wxLANGUAGE_UNKNOWN) { + const wxLanguageInfo *info = wxLocale::GetLanguageInfo(lang); + if (info != nullptr) + language = info->CanonicalName; } } - return false; + + const wxLanguageInfo *info = nullptr; + if (! language.IsEmpty()) { + const auto langs = get_installed_languages(); + for (const wxLanguageInfo *this_info : langs) + if (this_info->CanonicalName == language) { + info = this_info; + break; + } + } + + m_wxLocale = new wxLocale; + if (info == nullptr) { + m_wxLocale->Init(wxLANGUAGE_DEFAULT); + m_imgui->set_language("en"); + } else { + m_wxLocale->Init(info->Language); + m_wxLocale->AddCatalogLookupPathPrefix(from_u8(localization_dir())); + m_wxLocale->AddCatalog("Slic3rPE"); + m_imgui->set_language(into_u8(info->CanonicalName)); + } + //FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only. + wxSetlocale(LC_NUMERIC, "C"); + Preset::update_suffix_modified(); + return true; } // save language at application config diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 1f3ba9071..0ac5e1d42 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -19,7 +19,7 @@ class wxMenuItem; class wxMenuBar; class wxTopLevelWindow; class wxNotebook; -class wxLanguageInfo; +struct wxLanguageInfo; namespace Slic3r { class AppConfig; @@ -126,10 +126,9 @@ public: void update_ui_from_settings(); bool switch_language(); - bool select_language(); + // Load gettext translation files and activate them at the start of the application, + // based on the "translation_language" key stored in the application config. bool load_language(); - void save_language(); - std::vector get_installed_languages(); Tab* get_tab(Preset::Type type); ConfigOptionMode get_mode(); @@ -177,8 +176,11 @@ private: void window_pos_save(wxTopLevelWindow* window, const std::string &name); void window_pos_restore(wxTopLevelWindow* window, const std::string &name, bool default_maximized = false); void window_pos_sanitize(wxTopLevelWindow* window); + bool select_language(); + void save_language(); + std::vector get_installed_languages(); #ifdef __WXMSW__ - void associate_3mf_files(); + void associate_3mf_files(); #endif // __WXMSW__ }; DECLARE_APP(GUI_App) diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 3439449b9..38ffada87 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -554,10 +554,10 @@ void MainFrame::init_menubar() //# $versioncheck->Enable(wxTheApp->have_version_check); append_menu_item(helpMenu, wxID_ANY, wxString::Format(_(L("%s &Website")), SLIC3R_APP_NAME), wxString::Format(_(L("Open the %s website in your browser")), SLIC3R_APP_NAME), - [this](wxCommandEvent&) { wxLaunchDefaultBrowser("http://slic3r.org/"); }); - append_menu_item(helpMenu, wxID_ANY, wxString::Format(_(L("%s &Manual")), SLIC3R_APP_NAME), - wxString::Format(_(L("Open the %s manual in your browser")), SLIC3R_APP_NAME), - [this](wxCommandEvent&) { wxLaunchDefaultBrowser("http://manual.slic3r.org/"); }); + [this](wxCommandEvent&) { wxLaunchDefaultBrowser("https://www.prusa3d.com/slic3r-prusa-edition/"); }); +// append_menu_item(helpMenu, wxID_ANY, wxString::Format(_(L("%s &Manual")), SLIC3R_APP_NAME), +// wxString::Format(_(L("Open the %s manual in your browser")), SLIC3R_APP_NAME), +// [this](wxCommandEvent&) { wxLaunchDefaultBrowser("http://manual.slic3r.org/"); }); helpMenu->AppendSeparator(); append_menu_item(helpMenu, wxID_ANY, _(L("System &Info")), _(L("Show system information")), [this](wxCommandEvent&) { wxGetApp().system_info(); });