From e228e72db1b28214a8bd5ba2d4c4bb6250f47958 Mon Sep 17 00:00:00 2001 From: "lane.wei" Date: Wed, 21 Sep 2022 12:09:30 +0800 Subject: [PATCH] Fix serveral issues on Linux environments 1. fix the crash issue in ComboBox 2. fix the network agent directory not correct issue 3. fix the first 3d tab switch failed issue 4. fix the filemenu not correct issue Change-Id: I6a99218c0f7edbd57114ca1d9ff8c5c020d26d94 (cherry picked from commit b5e1b06af42aea9d1413be29dd58150b2ac8d470) --- src/slic3r/GUI/GUI_App.cpp | 8 ++++---- src/slic3r/GUI/MainFrame.cpp | 28 ++++++++++++++-------------- src/slic3r/GUI/Widgets/ComboBox.cpp | 2 +- src/slic3r/Utils/NetworkAgent.cpp | 8 ++++++-- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 838fa4e99..6529bf7f1 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -2228,11 +2228,11 @@ bool GUI_App::on_init_inner() // An ugly solution to GH #5537 in which GUI_App::init_opengl (normally called from events wxEVT_PAINT // and wxEVT_SET_FOCUS before GUI_App::post_init is called) wasn't called before GUI_App::post_init and OpenGL wasn't initialized. -#ifdef __linux__ - if (!m_post_initialized && m_opengl_initialized) { -#else +//#ifdef __linux__ +// if (!m_post_initialized && m_opengl_initialized) { +//#else if (!m_post_initialized) { -#endif +//#endif m_post_initialized = true; #ifdef WIN32 this->mainframe->register_win32_callbacks(); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index e8008aae1..a39ae4879 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -139,7 +139,7 @@ static wxIcon main_frame_icon(GUI_App::EAppMode app_mode) } // BBS -#ifdef __WINDOWS__ +#ifndef __APPLE__ #define BORDERLESS_FRAME_STYLE (wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX) #else #define BORDERLESS_FRAME_STYLE (wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX) @@ -178,7 +178,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_ // Fonts were created by the DPIFrame constructor for the monitor, on which the window opened. wxGetApp().update_fonts(this); -#ifdef __WINDOWS__ +#ifndef __APPLE__ m_topbar = new BBLTopbar(this); #else auto panel_topbar = new wxPanel(this, wxID_ANY); @@ -284,7 +284,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_ //Bind(wxEVT_MENU, [this](wxCommandEvent&) { m_plater->cut_selection_to_clipboard(); }, wxID_HIGHEST + wxID_CUT); Bind(wxEVT_SIZE, [this](wxSizeEvent&) { BOOST_LOG_TRIVIAL(trace) << "mainframe: size changed, is maximized = " << this->IsMaximized(); -#ifdef __WINDOWS__ +#ifndef __APPLE__ if (this->IsMaximized()) { m_topbar->SetWindowSize(); } else { @@ -326,7 +326,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_ // initialize layout m_main_sizer = new wxBoxSizer(wxVERTICAL); wxSizer* sizer = new wxBoxSizer(wxVERTICAL); -#ifdef __WINDOWS__ +#ifndef __APPLE__ sizer->Add(m_topbar, 0, wxEXPAND); #else sizer->Add(panel_topbar, 0, wxEXPAND); @@ -854,7 +854,7 @@ void MainFrame::init_tabpanel() //monitor } -#ifdef __WINDOWS__ +#ifndef __APPLE__ if (sel == tp3DEditor) { m_topbar->EnableUndoRedoItems(); } @@ -1507,7 +1507,7 @@ void MainFrame::on_dpi_changed(const wxRect& suggested_rect) dynamic_cast(m_tabpanel)->Rescale(); #endif -#ifdef __WINDOWS__ +#ifndef __APPLE__ // BBS m_topbar->Rescale(); #endif @@ -1630,7 +1630,7 @@ static wxMenu* generate_help_menu() return true; }); // About -#ifdef __WINDOWS__ +#ifndef __APPLE__ wxString about_title = wxString::Format(_L("&About %s"), SLIC3R_APP_FULL_NAME); append_menu_item(helpMenu, wxID_ANY, about_title, about_title, [](wxCommandEvent&) { Slic3r::GUI::about(); }); @@ -1691,7 +1691,7 @@ void MainFrame::init_menubar_as_editor() [this](){return can_start_new_project(); }, this); // Open Project -#ifdef __WINDOWS__ +#ifndef __APPLE__ append_menu_item(fileMenu, wxID_ANY, _L("Open Project") + dots + "\tCtrl+O", _L("Open a project file"), [this](wxCommandEvent&) { if (m_plater) m_plater->load_project(); }, "menu_open", nullptr, [this](){return can_open_project(); }, this); @@ -1722,7 +1722,7 @@ void MainFrame::init_menubar_as_editor() Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_open_project() && (m_recent_projects.GetCount() > 0)); }, recent_projects_submenu->GetId()); // BBS: close save project -#ifdef __WINDOWS__ +#ifndef __APPLE__ append_menu_item(fileMenu, wxID_ANY, _L("Save Project") + "\tCtrl+S", _L("Save current project to file"), [this](wxCommandEvent&) { if (m_plater) m_plater->save_project(); }, "menu_save", nullptr, [this](){return m_plater != nullptr && can_save(); }, this); @@ -1733,7 +1733,7 @@ void MainFrame::init_menubar_as_editor() #endif -#ifdef __WINDOWS__ +#ifndef __APPLE__ append_menu_item(fileMenu, wxID_ANY, _L("Save Project as") + dots + "\tCtrl+Shift+S", _L("Save current project as"), [this](wxCommandEvent&) { if (m_plater) m_plater->save_project(true); }, "menu_save", nullptr, [this](){return m_plater != nullptr && can_save_as(); }, this); @@ -1748,7 +1748,7 @@ void MainFrame::init_menubar_as_editor() // BBS wxMenu *import_menu = new wxMenu(); -#ifdef __WINDOWS__ +#ifndef __APPLE__ append_menu_item(import_menu, wxID_ANY, _L("Import 3MF/STL/STEP/OBJ/AMF") + dots + "\tCtrl+I", _L("Load a model"), [this](wxCommandEvent&) { if (m_plater) { m_plater->add_model(); @@ -1791,7 +1791,7 @@ void MainFrame::init_menubar_as_editor() fileMenu->AppendSeparator(); -#ifdef __WINDOWS__ +#ifndef __APPLE__ append_menu_item(fileMenu, wxID_EXIT, _L("Quit"), wxString::Format(_L("Quit")), [this](wxCommandEvent&) { Close(false); }, "menu_exit", nullptr); #else @@ -1812,7 +1812,7 @@ void MainFrame::init_menubar_as_editor() wxString hotkey_delete = "Del"; #endif -#ifdef __WINDOWS__ +#ifndef __APPLE__ // BBS undo append_menu_item(editMenu, wxID_ANY, _L("Undo") + "\tCtrl+Z", _L("Undo"), [this](wxCommandEvent&) { m_plater->undo(); }, @@ -2086,7 +2086,7 @@ void MainFrame::init_menubar_as_editor() auto helpMenu = generate_help_menu(); -#ifdef __WINDOWS__ +#ifndef __APPLE__ m_topbar->SetFileMenu(fileMenu); if (editMenu) m_topbar->AddDropDownSubMenu(editMenu, _L("Edit")); diff --git a/src/slic3r/GUI/Widgets/ComboBox.cpp b/src/slic3r/GUI/Widgets/ComboBox.cpp index c15ade211..0b8e27d6f 100644 --- a/src/slic3r/GUI/Widgets/ComboBox.cpp +++ b/src/slic3r/GUI/Widgets/ComboBox.cpp @@ -120,7 +120,7 @@ wxString ComboBox::GetTextLabel() const bool ComboBox::SetFont(wxFont const& font) { - if (GetTextCtrl()->IsShown()) + if (GetTextCtrl() && GetTextCtrl()->IsShown()) return GetTextCtrl()->SetFont(font); else return TextInput::SetFont(font); diff --git a/src/slic3r/Utils/NetworkAgent.cpp b/src/slic3r/Utils/NetworkAgent.cpp index 9620df989..34c535778 100644 --- a/src/slic3r/Utils/NetworkAgent.cpp +++ b/src/slic3r/Utils/NetworkAgent.cpp @@ -111,7 +111,9 @@ int NetworkAgent::initialize_network_module(bool using_backup) { //int ret = -1; std::string library; - auto plugin_folder = boost::filesystem::path(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data()) / "plugins"; + std::string data_dir_str = data_dir(); + boost::filesystem::path data_dir_path(data_dir_str); + auto plugin_folder = data_dir_path / "plugins"; if (using_backup) { plugin_folder = plugin_folder/"backup"; @@ -323,7 +325,9 @@ void* NetworkAgent::get_bambu_source_entry() //int ret = -1; std::string library; - auto plugin_folder = boost::filesystem::path(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data()) / "plugins"; + std::string data_dir_str = data_dir(); + boost::filesystem::path data_dir_path(data_dir_str); + auto plugin_folder = data_dir_path / "plugins"; #if defined(_MSC_VER) || defined(_WIN32) wchar_t lib_wstr[128];