From 0923bcec3481129e2073446e7c1877deb51d7ee6 Mon Sep 17 00:00:00 2001
From: Vojtech Bubnik <bubnikv@gmail.com>
Date: Tue, 23 Apr 2019 11:02:57 +0200
Subject: [PATCH 1/4] Added explicit linkage of pthreads library (needed on
 raspberry PI)

---
 CMakeLists.txt     | 4 ++++
 src/CMakeLists.txt | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f869be44..3e59090e3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -139,6 +139,10 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
         # Workaround for an old CMake, which does not understand CMAKE_CXX_STANDARD.
         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
     endif()
+
+    # Boost on Raspberry-Pi does not link to pthreads.
+    set(THREADS_PREFER_PTHREAD_FLAG ON)
+    find_package(Threads REQUIRED)
 endif()
 
 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 45d6f8196..136fe9af7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -88,7 +88,8 @@ elseif (MSVC)
     # Manifest is provided through slic3r.rc, don't generate your own.
     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
 else ()
-    target_link_libraries(slic3r ${CMAKE_DL_LIBS} -lstdc++)
+    # Boost on Raspberry-Pi does not link to pthreads explicitely.
+    target_link_libraries(slic3r ${CMAKE_DL_LIBS} -lstdc++ Threads::Threads)
 endif ()
 
 # Add the Slic3r GUI library, libcurl, OpenGL and GLU libraries.

From 31d377d09f0a987519acba069bec9c01eb11204f Mon Sep 17 00:00:00 2001
From: Vojtech Bubnik <bubnikv@gmail.com>
Date: Tue, 23 Apr 2019 12:35:26 +0200
Subject: [PATCH 2/4] Some refactoring and documentation, modified Windows
 dependencies to compile against patched wxWidgets

---
 deps/deps-windows.cmake                   |  8 ++++--
 src/slic3r/GUI/GUI_ObjectManipulation.cpp | 34 ++++++-----------------
 src/slic3r/GUI/OptionsGroup.hpp           |  2 ++
 3 files changed, 16 insertions(+), 28 deletions(-)

diff --git a/deps/deps-windows.cmake b/deps/deps-windows.cmake
index 0806c2388..b3b31e5f3 100644
--- a/deps/deps-windows.cmake
+++ b/deps/deps-windows.cmake
@@ -210,10 +210,12 @@ endif ()
 
 ExternalProject_Add(dep_wxwidgets
     EXCLUDE_FROM_ALL 1
-    URL "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.tar.bz2"
-    URL_HASH SHA256=c925dfe17e8f8b09eb7ea9bfdcfcc13696a3e14e92750effd839f5e10726159e
+    GIT_REPOSITORY "https://github.com/prusa3d/wxWidgets"
+    GIT_TAG v3.1.1-patched
+#    URL "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.tar.bz2"
+#    URL_HASH SHA256=c925dfe17e8f8b09eb7ea9bfdcfcc13696a3e14e92750effd839f5e10726159e
     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 ""
     BUILD_COMMAND cd build\\msw && nmake /f makefile.vc BUILD=release SHARED=0 UNICODE=1 USE_GUI=1 "${DEP_WXWIDGETS_TARGET}"
     INSTALL_COMMAND "${CMAKE_COMMAND}" -E copy_directory include "${DESTDIR}\\usr\\local\\include"
diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp
index df54f16d4..f9284a19b 100644
--- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp
+++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp
@@ -508,31 +508,15 @@ void ObjectManipulation::on_fill_empty_value(const std::string& opt_key)
     std::copy(opt_key.begin(), opt_key.end() - 2, std::back_inserter(param));
 
     double value = 0.0;
-
-    if (param == "position") {
-        int axis = opt_key.back() == 'x' ? 0 :
-            opt_key.back() == 'y' ? 1 : 2;
-
-        value = m_cache.position(axis);
-    }
-    else if (param == "rotation") {
-        int axis = opt_key.back() == 'x' ? 0 :
-            opt_key.back() == 'y' ? 1 : 2;
-
-        value = m_cache.rotation(axis);
-    }
-    else if (param == "scale") {
-        int axis = opt_key.back() == 'x' ? 0 :
-            opt_key.back() == 'y' ? 1 : 2;
-
-        value = m_cache.scale(axis);
-    }
-    else if (param == "size") {
-        int axis = opt_key.back() == 'x' ? 0 :
-            opt_key.back() == 'y' ? 1 : 2;
-
-        value = m_cache.size(axis);
-    }
+	auto opt_key_to_axis = [&opt_key]() { return opt_key.back() == 'x' ? 0 : opt_key.back() == 'y' ? 1 : 2; };
+    if (param == "position")
+        value = m_cache.position(opt_key_to_axis());
+    else if (param == "rotation")
+		value = m_cache.rotation(opt_key_to_axis());
+    else if (param == "scale")
+		value = m_cache.scale(opt_key_to_axis());
+    else if (param == "size")
+		value = m_cache.size(opt_key_to_axis());
 
     m_og->set_value(opt_key, double_to_string(value));
 }
diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp
index dbe1ea1a2..e4ada3692 100644
--- a/src/slic3r/GUI/OptionsGroup.hpp
+++ b/src/slic3r/GUI/OptionsGroup.hpp
@@ -86,6 +86,8 @@ public:
     wxSizer*		sizer {nullptr};
     column_t		extra_column {nullptr};
     t_change		m_on_change { nullptr };
+	// To be called when the field loses focus, to assign a new initial value to the field.
+	// Used by the relative position / rotation / scale manipulation fields of the Object Manipulation UI.
     t_kill_focus    m_fill_empty_value { nullptr };
     t_kill_focus    m_set_focus { nullptr };
 	std::function<DynamicPrintConfig()>	m_get_initial_config{ nullptr };

From 2088abdc31d7a0fa89ea306af6d75f883dcb514e Mon Sep 17 00:00:00 2001
From: Vojtech Kral <vojtech@kral.hk>
Date: Tue, 23 Apr 2019 14:18:07 +0200
Subject: [PATCH 3/4] Build: Don't add slic3r dir when SLIC3R_GUI is off #1050

---
 src/CMakeLists.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 136fe9af7..0dc1facb2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -56,9 +56,10 @@ if (SLIC3R_GUI)
     endif()
 
     include(${wxWidgets_USE_FILE})
+
+    add_subdirectory(slic3r)
 endif()
 
-add_subdirectory(slic3r)
 
 # Create a slic3r executable
 # Process mainfests for various platforms.

From e9d629f248f6c015440ab3ca17f02d8022d0850e Mon Sep 17 00:00:00 2001
From: Vojtech Kral <vojtech@kral.hk>
Date: Tue, 23 Apr 2019 14:56:53 +0200
Subject: [PATCH 4/4] Build: Don't add imgui dir when SLIC3R_GUI is off

---
 src/CMakeLists.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0dc1facb2..f5099c8bb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -12,7 +12,6 @@ add_subdirectory(poly2tri)
 add_subdirectory(qhull)
 add_subdirectory(Shiny)
 add_subdirectory(semver)
-add_subdirectory(imgui)
 
 # Adding libnest2d project for bin packing...
 set(LIBNEST2D_UNITTESTS ON CACHE BOOL "Force generating unittests for libnest2d")
@@ -24,6 +23,8 @@ include_directories(${LIBDIR}/qhull/src)
 add_subdirectory(libslic3r)
 
 if (SLIC3R_GUI)
+    add_subdirectory(imgui)
+
     if(WIN32)
         message(STATUS "WXWIN environment set to: $ENV{WXWIN}")
     elseif(UNIX)