Fix: wxWidgets 3.0 back-compat

Fix #1599
This commit is contained in:
Vojtech Kral 2019-01-07 19:17:10 +01:00
parent 5aec48418a
commit cde0aa4443
9 changed files with 40 additions and 15 deletions

View File

@ -25,6 +25,7 @@ endif()
option(SLIC3R_STATIC "Compile Slic3r with static libraries (Boost, TBB, glew)" ${SLIC3R_STATIC_INITIAL}) option(SLIC3R_STATIC "Compile Slic3r with static libraries (Boost, TBB, glew)" ${SLIC3R_STATIC_INITIAL})
option(SLIC3R_GUI "Compile Slic3r with GUI components (OpenGL, wxWidgets)" 1) option(SLIC3R_GUI "Compile Slic3r with GUI components (OpenGL, wxWidgets)" 1)
option(SLIC3R_FHS "Assume Slic3r is to be installed in a FHS directory structure" 0) option(SLIC3R_FHS "Assume Slic3r is to be installed in a FHS directory structure" 0)
option(SLIC3R_WX_STABLE "Build against wxWidgets stable (3.0) as oppsed to dev (3.1) on Linux" 0)
option(SLIC3R_PROFILE "Compile Slic3r with an invasive Shiny profiler" 0) option(SLIC3R_PROFILE "Compile Slic3r with an invasive Shiny profiler" 0)
option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1) option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1)
option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1) option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1)

1
deps/CMakeLists.txt vendored
View File

@ -33,6 +33,7 @@ endif ()
set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir" CACHE PATH "Destination directory") set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir" CACHE PATH "Destination directory")
option(DEP_DEBUG "Build debug variants (only applicable on Windows)" ON) option(DEP_DEBUG "Build debug variants (only applicable on Windows)" ON)
option(DEP_WX_STABLE "Build against wxWidgets stable 3.0 as opposed to default 3.1 (Linux only)" OFF)
message(STATUS "Slic3r deps DESTDIR: ${DESTDIR}") message(STATUS "Slic3r deps DESTDIR: ${DESTDIR}")
message(STATUS "Slic3r deps debug build: ${DEP_DEBUG}") message(STATUS "Slic3r deps debug build: ${DEP_DEBUG}")

12
deps/deps-linux.cmake vendored
View File

@ -88,10 +88,18 @@ ExternalProject_Add(dep_libcurl
INSTALL_COMMAND make install "DESTDIR=${DESTDIR}" INSTALL_COMMAND make install "DESTDIR=${DESTDIR}"
) )
if (DEP_WX_STABLE)
set(DEP_WX_URL "https://github.com/wxWidgets/wxWidgets/releases/download/v3.0.4/wxWidgets-3.0.4.tar.bz2")
set(DEP_WX_HASH "SHA256=96157f988d261b7368e5340afa1a0cad943768f35929c22841f62c25b17bf7f0")
else ()
set(DEP_WX_URL "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.tar.bz2")
set(DEP_WX_HASH "SHA256=c925dfe17e8f8b09eb7ea9bfdcfcc13696a3e14e92750effd839f5e10726159e")
endif()
ExternalProject_Add(dep_wxwidgets ExternalProject_Add(dep_wxwidgets
EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_ALL 1
URL "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.tar.bz2" URL "${DEP_WX_URL}"
URL_HASH SHA256=c925dfe17e8f8b09eb7ea9bfdcfcc13696a3e14e92750effd839f5e10726159e URL_HASH "${DEP_WX_HASH}"
BUILD_IN_SOURCE 1 BUILD_IN_SOURCE 1
PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/wxwidgets-pngprefix.h" src/png/pngprefix.h PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/wxwidgets-pngprefix.h" src/png/pngprefix.h
CONFIGURE_COMMAND ./configure CONFIGURE_COMMAND ./configure

View File

@ -7,7 +7,7 @@ CMake installer can be downloaded from [the official website](https://cmake.org/
Building with newer versions of MSVS (2015, 2017) may work too as reported by some of our users. Building with newer versions of MSVS (2015, 2017) may work too as reported by some of our users.
_Note:_ Thanks to **@supermerill** for testing and inspiration on this guide. _Note:_ Thanks to [**@supermerill**](https://github.com/supermerill) for testing and inspiration on this guide.
### Dependencies ### Dependencies

View File

@ -59,7 +59,19 @@ if (SLIC3R_GUI)
endif() endif()
endif() endif()
find_package(wxWidgets REQUIRED COMPONENTS base core adv html gl) if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
if (SLIC3R_WX_STABLE)
find_package(wxWidgets 3.0 REQUIRED COMPONENTS base core adv html gl)
else ()
find_package(wxWidgets 3.1 QUIET COMPONENTS base core adv html gl)
if (NOT wxWidgets_FOUND)
message(FATAL_ERROR "\nCould not find wxWidgets 3.1.\nHint: On Linux you can set -DSLIC3R_WX_STABLE=1 to use wxWidgets 3.0")
endif ()
endif ()
else ()
find_package(wxWidgets 3.1 REQUIRED COMPONENTS base core adv html gl)
endif ()
include(${wxWidgets_USE_FILE}) include(${wxWidgets_USE_FILE})
endif() endif()

View File

@ -36,7 +36,7 @@ bool GLTexture::load_from_file(const std::string& filename, bool generate_mipmap
// Load a PNG with an alpha channel. // Load a PNG with an alpha channel.
wxImage image; wxImage image;
if (!image.LoadFile(wxString::FromUTF8(filename), wxBITMAP_TYPE_PNG)) if (!image.LoadFile(wxString::FromUTF8(filename.c_str()), wxBITMAP_TYPE_PNG))
{ {
reset(); reset();
return false; return false;

View File

@ -234,7 +234,7 @@ void show_error(wxWindow* parent, const wxString& message)
void show_error_id(int id, const std::string& message) void show_error_id(int id, const std::string& message)
{ {
auto *parent = id != 0 ? wxWindow::FindWindowById(id) : nullptr; auto *parent = id != 0 ? wxWindow::FindWindowById(id) : nullptr;
show_error(parent, wxString::FromUTF8(message.data())); show_error(parent, from_u8(message));
} }
void show_info(wxWindow* parent, const wxString& message, const wxString& title) void show_info(wxWindow* parent, const wxString& message, const wxString& title)
@ -324,7 +324,7 @@ wxString from_path(const boost::filesystem::path &path)
#ifdef _WIN32 #ifdef _WIN32
return wxString(path.string<std::wstring>()); return wxString(path.string<std::wstring>());
#else #else
return wxString::FromUTF8(path.string<std::string>()); return from_u8(path.string<std::string>());
#endif #endif
} }
@ -405,7 +405,7 @@ void desktop_open_datadir_folder()
const auto path = data_dir(); const auto path = data_dir();
#ifdef _WIN32 #ifdef _WIN32
const auto widepath = wxString::FromUTF8(path.data()); const wxString widepath = from_u8(path);
const wchar_t *argv[] = { L"explorer", widepath.GetData(), nullptr }; const wchar_t *argv[] = { L"explorer", widepath.GetData(), nullptr };
::wxExecute(const_cast<wchar_t**>(argv), wxEXEC_ASYNC, nullptr); ::wxExecute(const_cast<wchar_t**>(argv), wxEXEC_ASYNC, nullptr);
#elif __APPLE__ #elif __APPLE__

View File

@ -67,7 +67,7 @@ wxString file_wildcards(FileType file_type, const std::string &custom_extension)
out += std::string(";*") + custom_extension; out += std::string(";*") + custom_extension;
} }
} }
return wxString::FromUTF8(out.c_str()); return from_u8(out);
} }
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(); }
@ -464,7 +464,7 @@ bool GUI_App::select_language( wxArrayString & names,
{ {
m_wxLocale = new wxLocale; m_wxLocale = new wxLocale;
m_wxLocale->Init(identifiers[index]); m_wxLocale->Init(identifiers[index]);
m_wxLocale->AddCatalogLookupPathPrefix(wxString::FromUTF8(localization_dir())); m_wxLocale->AddCatalogLookupPathPrefix(from_u8(localization_dir()));
m_wxLocale->AddCatalog(/*GetAppName()*/"Slic3rPE"); m_wxLocale->AddCatalog(/*GetAppName()*/"Slic3rPE");
//FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only. //FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only.
wxSetlocale(LC_NUMERIC, "C"); wxSetlocale(LC_NUMERIC, "C");
@ -492,7 +492,7 @@ bool GUI_App::load_language()
{ {
m_wxLocale = new wxLocale; m_wxLocale = new wxLocale;
m_wxLocale->Init(identifiers[i]); m_wxLocale->Init(identifiers[i]);
m_wxLocale->AddCatalogLookupPathPrefix(wxString::FromUTF8(localization_dir())); m_wxLocale->AddCatalogLookupPathPrefix(from_u8(localization_dir()));
m_wxLocale->AddCatalog(/*GetAppName()*/"Slic3rPE"); m_wxLocale->AddCatalog(/*GetAppName()*/"Slic3rPE");
//FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only. //FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only.
wxSetlocale(LC_NUMERIC, "C"); wxSetlocale(LC_NUMERIC, "C");
@ -520,7 +520,7 @@ void GUI_App::get_installed_languages(wxArrayString & names, wxArrayLong & ident
names.Clear(); names.Clear();
identifiers.Clear(); identifiers.Clear();
wxDir dir(wxString::FromUTF8(localization_dir())); wxDir dir(from_u8(localization_dir()));
wxString filename; wxString filename;
const wxLanguageInfo * langinfo; const wxLanguageInfo * langinfo;
wxString name = wxLocale::GetLanguageName(wxLANGUAGE_DEFAULT); wxString name = wxLocale::GetLanguageName(wxLANGUAGE_DEFAULT);

View File

@ -9,9 +9,12 @@
#include <wx/numformatter.h> #include <wx/numformatter.h>
#include "BitmapCache.hpp" #include "BitmapCache.hpp"
#include "GUI.hpp"
#include "GUI_App.hpp" #include "GUI_App.hpp"
#include "GUI_ObjectList.hpp" #include "GUI_ObjectList.hpp"
using Slic3r::GUI::from_u8;
wxDEFINE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent); wxDEFINE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);
wxDEFINE_EVENT(wxCUSTOMEVT_LAST_VOLUME_IS_DELETED, wxCommandEvent); wxDEFINE_EVENT(wxCUSTOMEVT_LAST_VOLUME_IS_DELETED, wxCommandEvent);
@ -37,7 +40,7 @@ wxMenuItem* append_menu_item(wxMenu* menu, int id, const wxString& string, const
wxMenuItem* append_menu_item(wxMenu* menu, int id, const wxString& string, const wxString& description, wxMenuItem* append_menu_item(wxMenu* menu, int id, const wxString& string, const wxString& description,
std::function<void(wxCommandEvent& event)> cb, const std::string& icon, wxEvtHandler* event_handler) std::function<void(wxCommandEvent& event)> cb, const std::string& icon, wxEvtHandler* event_handler)
{ {
const wxBitmap& bmp = !icon.empty() ? wxBitmap(wxString::FromUTF8(Slic3r::var(icon)), wxBITMAP_TYPE_PNG) : wxNullBitmap; const wxBitmap& bmp = !icon.empty() ? wxBitmap(from_u8(Slic3r::var(icon)), wxBITMAP_TYPE_PNG) : wxNullBitmap;
return append_menu_item(menu, id, string, description, cb, bmp, event_handler); return append_menu_item(menu, id, string, description, cb, bmp, event_handler);
} }
@ -48,7 +51,7 @@ wxMenuItem* append_submenu(wxMenu* menu, wxMenu* sub_menu, int id, const wxStrin
wxMenuItem* item = new wxMenuItem(menu, id, string, description); wxMenuItem* item = new wxMenuItem(menu, id, string, description);
if (!icon.empty()) if (!icon.empty())
item->SetBitmap(wxBitmap(wxString::FromUTF8(Slic3r::var(icon)), wxBITMAP_TYPE_PNG)); item->SetBitmap(wxBitmap(from_u8(Slic3r::var(icon)), wxBITMAP_TYPE_PNG));
item->SetSubMenu(sub_menu); item->SetSubMenu(sub_menu);
menu->Append(item); menu->Append(item);