From 1fb400a091747c142befe32ca4d8430f2d06b7f0 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 2 Oct 2020 08:32:44 +0200 Subject: [PATCH 1/2] use wxYield on mac to show the splashscreen --- src/slic3r/GUI/GUI_App.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 23f79c65f..409ca0a15 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -696,6 +696,7 @@ bool GUI_App::on_init_inner() // create splash screen with updated bmp scrn = new SplashScreen(bmp.IsOk() ? bmp : create_scaled_bitmap("prusa_slicer_logo", nullptr, 400), wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_TIMEOUT, 4000, splashscreen_pos, is_decorated); + wxYield(); scrn->SetText(_L("Loading configuration...")); } From 48f775decb0e1609ef4ab356f6a558666db2bfc0 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 2 Oct 2020 22:27:20 +0200 Subject: [PATCH 2/2] A part of code related to loads after App::OnInit() call is moved from PrusaSlicer.cpp to GUI_App.cpp Splash Screen under OSX requires a call of wxYeild() for update. But wxYield() furthers a case, when CallAfter() in CLI::run() was called at the wrong time, before some of the GUI was created. So, there is workaround: Parameters needed for later loads are encapsulated to GUI_App::AFTER_INIT_LOADS structure and are used in GUI_App::AFTER_INIT_LOADS::on_loads which is called just ones after wxEVT_IDLE --- src/PrusaSlicer.cpp | 7 ++++++ src/slic3r/GUI/GUI_App.cpp | 47 +++++++++++++++++++++++++++++++++++++- src/slic3r/GUI/GUI_App.hpp | 30 ++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/PrusaSlicer.cpp b/src/PrusaSlicer.cpp index d79196cfa..6110a3cc7 100644 --- a/src/PrusaSlicer.cpp +++ b/src/PrusaSlicer.cpp @@ -577,6 +577,12 @@ int CLI::run(int argc, char **argv) // gui->autosave = m_config.opt_string("autosave"); GUI::GUI_App::SetInstance(gui); +#if ENABLE_GCODE_VIEWER + gui->m_after_init_loads.set_params(load_configs, m_extra_config, m_input_files, start_as_gcodeviewer); +#else + gui->m_after_init_loads.set_params(load_configs, m_extra_config, m_input_files); +#endif // ENABLE_GCODE_VIEWER +/* #if ENABLE_GCODE_VIEWER gui->CallAfter([gui, this, &load_configs, start_as_gcodeviewer] { #else @@ -614,6 +620,7 @@ int CLI::run(int argc, char **argv) } #endif // ENABLE_GCODE_VIEWER }); +*/ int result = wxEntry(argc, argv); return result; #else /* SLIC3R_GUI */ diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 409ca0a15..9a32a76b6 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -123,6 +123,10 @@ public: memDC.SelectObject(wxNullBitmap); set_bitmap(bitmap); +#ifdef __WXOSX__ + // without this code splash screen wouldn't be updated under OSX + wxYield(); +#endif } } @@ -531,6 +535,41 @@ static void generic_exception_handle() } } +void GUI_App::AFTER_INIT_LOADS::on_loads(GUI_App* gui) +{ + if (!gui->initialized()) + return; + +#if ENABLE_GCODE_VIEWER + if (m_start_as_gcodeviewer) { + if (!m_input_files.empty()) + gui->plater()->load_gcode(wxString::FromUTF8(m_input_files[0].c_str())); + } + else { +#endif // ENABLE_GCODE_VIEWER_AS +#if 0 + // Load the cummulative config over the currently active profiles. + //FIXME if multiple configs are loaded, only the last one will have an effect. + // We need to decide what to do about loading of separate presets (just print preset, just filament preset etc). + // As of now only the full configs are supported here. + if (!m_print_config.empty()) + gui->mainframe->load_config(m_print_config); +#endif + if (!m_load_configs.empty()) + // Load the last config to give it a name at the UI. The name of the preset may be later + // changed by loading an AMF or 3MF. + //FIXME this is not strictly correct, as one may pass a print/filament/printer profile here instead of a full config. + gui->mainframe->load_config_file(m_load_configs.back()); + // If loading a 3MF file, the config is loaded from the last one. + if (!m_input_files.empty()) + gui->plater()->load_files(m_input_files, true, true); + if (!m_extra_config.empty()) + gui->mainframe->load_config(m_extra_config); +#if ENABLE_GCODE_VIEWER + } +#endif // ENABLE_GCODE_VIEWER + } + IMPLEMENT_APP(GUI_App) #if ENABLE_GCODE_VIEWER @@ -696,7 +735,6 @@ bool GUI_App::on_init_inner() // create splash screen with updated bmp scrn = new SplashScreen(bmp.IsOk() ? bmp : create_scaled_bitmap("prusa_slicer_logo", nullptr, 400), wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_TIMEOUT, 4000, splashscreen_pos, is_decorated); - wxYield(); scrn->SetText(_L("Loading configuration...")); } @@ -785,6 +823,13 @@ bool GUI_App::on_init_inner() this->obj_manipul()->update_if_dirty(); + static bool update_gui_after_init = true; + if (update_gui_after_init) + { + update_gui_after_init = false; + m_after_init_loads.on_loads(this); + } + // Preset updating & Configwizard are done after the above initializations, // and after MainFrame is created & shown. // The extra CallAfter() is needed because of Mac, where this is the only way diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 9bf470a42..68c9b2efd 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -140,6 +140,35 @@ private: std::string m_instance_hash_string; size_t m_instance_hash_int; + // parameters needed for the after OnInit() loads + struct AFTER_INIT_LOADS + { + std::vector m_load_configs; + DynamicPrintConfig m_extra_config; + std::vector m_input_files; +#if ENABLE_GCODE_VIEWER + bool m_start_as_gcodeviewer; +#endif // ENABLE_GCODE_VIEWER + + void set_params( + const std::vector& load_configs, + const DynamicPrintConfig& extra_config, + const std::vector& input_files, +#if ENABLE_GCODE_VIEWER + bool start_as_gcodeviewer +#endif // ENABLE_GCODE_VIEWER + ) { + m_load_configs = load_configs; + m_extra_config = extra_config; + m_input_files = input_files; +#if ENABLE_GCODE_VIEWER + m_start_as_gcodeviewer = start_as_gcodeviewer; +#endif // ENABLE_GCODE_VIEWER + } + + void on_loads(GUI_App* gui); + }; + public: bool OnInit() override; bool initialized() const { return m_initialized; } @@ -236,6 +265,7 @@ public: PresetUpdater* preset_updater{ nullptr }; MainFrame* mainframe{ nullptr }; Plater* plater_{ nullptr }; + AFTER_INIT_LOADS m_after_init_loads; PresetUpdater* get_preset_updater() { return preset_updater; }