diff options
Diffstat (limited to 'src/slic3r/GUI/GUI_App.hpp')
-rw-r--r-- | src/slic3r/GUI/GUI_App.hpp | 117 |
1 files changed, 106 insertions, 11 deletions
diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index d02a60ba9..8aceb7a69 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -3,15 +3,16 @@ #include <memory> #include <string> -#include "libslic3r/PrintConfig.hpp" -#include "MainFrame.hpp" #include "ImGuiWrapper.hpp" #include "ConfigWizard.hpp" +#include "OpenGLManager.hpp" +#include "libslic3r/Preset.hpp" #include <wx/app.h> #include <wx/colour.h> #include <wx/font.h> #include <wx/string.h> +#include <wx/snglinst.h> #include <mutex> #include <stack> @@ -23,15 +24,29 @@ class wxNotebook; struct wxLanguageInfo; namespace Slic3r { + class AppConfig; class PresetBundle; class PresetUpdater; class ModelObject; class PrintHostJobQueue; - +class Model; namespace GUI{ + class RemovableDriveManager; +class OtherInstanceMessageHandler; +class MainFrame; +class Sidebar; +class ObjectManipulation; +class ObjectSettings; +class ObjectList; +class ObjectLayers; +class Plater; +struct GUI_InitParams; + + + enum FileType { FT_STL, @@ -74,10 +89,29 @@ class ConfigWizard; static wxString dots("…", wxConvUTF8); +// Does our wxWidgets version support markup? +// https://github.com/prusa3d/PrusaSlicer/issues/4282#issuecomment-634676371 +#if wxUSE_MARKUP && wxCHECK_VERSION(3, 1, 1) + #define SUPPORTS_MARKUP +#endif + class GUI_App : public wxApp { +public: + enum class EAppMode : unsigned char + { + Editor, + GCodeViewer + }; + +private: bool m_initialized { false }; - bool app_conf_exists{ false }; + bool m_app_conf_exists{ false }; + EAppMode m_app_mode{ EAppMode::Editor }; + bool m_is_recreating_gui{ false }; +#ifdef __linux__ + bool m_opengl_initialized{ false }; +#endif wxColour m_color_label_modified; wxColour m_color_label_sys; @@ -86,8 +120,9 @@ class GUI_App : public wxApp wxFont m_small_font; wxFont m_bold_font; wxFont m_normal_font; + wxFont m_code_font; - int m_em_unit; // width of a "m"-symbol in pixels for current system font + int m_em_unit; // width of a "m"-symbol in pixels for current system font // Note: for 100% Scale m_em_unit = 10 -> it's a good enough coefficient for a size setting of controls std::unique_ptr<wxLocale> m_wxLocale; @@ -96,19 +131,38 @@ class GUI_App : public wxApp // Best translation language, provided by Windows or OSX, owned by wxWidgets. const wxLanguageInfo *m_language_info_best = nullptr; - std::unique_ptr<RemovableDriveManager> m_removable_drive_manager; + OpenGLManager m_opengl_mgr; + + std::unique_ptr<RemovableDriveManager> m_removable_drive_manager; std::unique_ptr<ImGuiWrapper> m_imgui; std::unique_ptr<PrintHostJobQueue> m_printhost_job_queue; ConfigWizard* m_wizard; // Managed by wxWindow tree + std::unique_ptr <OtherInstanceMessageHandler> m_other_instance_message_handler; + std::unique_ptr <wxSingleInstanceChecker> m_single_instance_checker; + std::string m_instance_hash_string; + size_t m_instance_hash_int; public: bool OnInit() override; bool initialized() const { return m_initialized; } - GUI_App(); + explicit GUI_App(EAppMode mode = EAppMode::Editor); ~GUI_App() override; + EAppMode get_app_mode() const { return m_app_mode; } + bool is_editor() const { return m_app_mode == EAppMode::Editor; } + bool is_gcode_viewer() const { return m_app_mode == EAppMode::GCodeViewer; } + bool is_recreating_gui() const { return m_is_recreating_gui; } + + // To be called after the GUI is fully built up. + // Process command line parameters cached in this->init_params, + // load configs, STLs etc. + void post_init(); + static std::string get_gl_info(bool format_as_html, bool extensions); + wxGLContext* init_glcontext(wxGLCanvas& canvas); + bool init_opengl(); + static unsigned get_colour_approx_luma(const wxColour &colour); static bool dark_mode(); void init_label_colours(); @@ -125,18 +179,24 @@ public: const wxFont& small_font() { return m_small_font; } const wxFont& bold_font() { return m_bold_font; } const wxFont& normal_font() { return m_normal_font; } + const wxFont& code_font() { return m_code_font; } int em_unit() const { return m_em_unit; } + wxSize get_min_size() const; float toolbar_icon_scale(const bool is_limited = false) const; + void set_auto_toolbar_icon_scale(float scale) const; + void check_printer_presets(); - void recreate_GUI(); + void recreate_GUI(const wxString& message); void system_info(); void keyboard_shortcuts(); void load_project(wxWindow *parent, wxString& input_file) const; void import_model(wxWindow *parent, wxArrayString& input_files) const; + void load_gcode(wxWindow* parent, wxString& input_file) const; + 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(); + void update_ui_from_settings(bool apply_free_camera_correction = true); bool switch_language(); bool load_language(wxString language, bool initial); @@ -148,16 +208,19 @@ public: void add_config_menu(wxMenuBar *menu); bool check_unsaved_changes(const wxString &header = wxString()); + bool check_print_host_queue(); bool checked_tab(Tab* tab); - void load_current_presets(); + void load_current_presets(bool check_printer_presets = true); wxString current_language_code() const { return m_wxLocale->GetCanonicalName(); } // Translate the language code to a code, for which Prusa Research maintains translations. Defaults to "en_US". wxString current_language_code_safe() const; + bool is_localized() const { return m_wxLocale->GetLocale() != "English"; } virtual bool OnExceptionInMainLoop() override; #ifdef __APPLE__ + void OSXStoreOpenFiles(const wxArrayString &files) override; // wxWidgets override to get an event on open files. void MacOpenFiles(const wxArrayString &fileNames) override; #endif /* __APPLE */ @@ -170,12 +233,18 @@ public: Plater* plater(); Model& model(); + + // Parameters extracted from the command line to be passed to GUI after initialization. + const GUI_InitParams* init_params { nullptr }; + AppConfig* app_config{ nullptr }; PresetBundle* preset_bundle{ nullptr }; PresetUpdater* preset_updater{ nullptr }; MainFrame* mainframe{ nullptr }; Plater* plater_{ nullptr }; + PresetUpdater* get_preset_updater() { return preset_updater; } + wxNotebook* tab_panel() const ; int extruders_cnt() const; int extruders_edited_cnt() const; @@ -183,6 +252,13 @@ public: std::vector<Tab *> tabs_list; RemovableDriveManager* removable_drive_manager() { return m_removable_drive_manager.get(); } + OtherInstanceMessageHandler* other_instance_message_handler() { return m_other_instance_message_handler.get(); } + wxSingleInstanceChecker* single_instance_checker() {return m_single_instance_checker.get();} + + void init_single_instance_checker(const std::string &name, const std::string &path); + void set_instance_hash (const size_t hash) { m_instance_hash_int = hash; m_instance_hash_string = std::to_string(hash); } + std::string get_instance_hash_string () { return m_instance_hash_string; } + size_t get_instance_hash_int () { return m_instance_hash_int; } ImGuiWrapper* imgui() { return m_imgui.get(); } @@ -196,8 +272,23 @@ public: void gcode_thumbnails_debug(); #endif // ENABLE_THUMBNAIL_GENERATOR_DEBUG + GLShaderProgram* get_shader(const std::string& shader_name) { return m_opengl_mgr.get_shader(shader_name); } + GLShaderProgram* get_current_shader() { return m_opengl_mgr.get_current_shader(); } + + bool is_gl_version_greater_or_equal_to(unsigned int major, unsigned int minor) const { return m_opengl_mgr.get_gl_info().is_version_greater_or_equal_to(major, minor); } + bool is_glsl_version_greater_or_equal_to(unsigned int major, unsigned int minor) const { return m_opengl_mgr.get_gl_info().is_glsl_version_greater_or_equal_to(major, minor); } + +#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN +#ifdef __WXMSW__ + void associate_3mf_files(); + void associate_stl_files(); + void associate_gcode_files(); +#endif // __WXMSW__ +#endif // ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN + private: bool on_init_inner(); + void init_app_config(); 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); @@ -206,13 +297,17 @@ private: bool config_wizard_startup(); void check_updates(const bool verbose); +#if !ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN #ifdef __WXMSW__ void associate_3mf_files(); + void associate_gcode_files(); #endif // __WXMSW__ +#endif // !ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN }; + DECLARE_APP(GUI_App) } // GUI -} //Slic3r +} // Slic3r #endif // slic3r_GUI_App_hpp_ |