Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/xs
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2018-06-04 22:22:42 +0300
committerbubnikv <bubnikv@gmail.com>2018-06-04 22:22:42 +0300
commitd05d3cb652de8dfc156b62e940aaf8a7422dee20 (patch)
tree9e1494633529575381fc0a230325a4d9220593cb /xs
parente65fac5e8484b7737f90948d40dfd05a49a35969 (diff)
Initial working implementation of the "Fix by Netfabb" function.
Diffstat (limited to 'xs')
-rw-r--r--xs/CMakeLists.txt7
-rw-r--r--xs/src/slic3r/Utils/FixModelByWin10.cpp72
-rw-r--r--xs/src/slic3r/Utils/FixModelByWin10.hpp12
-rw-r--r--xs/xsp/GUI.xsp7
4 files changed, 87 insertions, 11 deletions
diff --git a/xs/CMakeLists.txt b/xs/CMakeLists.txt
index 64f4b9274..866374584 100644
--- a/xs/CMakeLists.txt
+++ b/xs/CMakeLists.txt
@@ -27,6 +27,13 @@ if(WIN32)
# BOOST_ALL_NO_LIB: Avoid the automatic linking of Boost libraries on Windows. Rather rely on explicit linking.
add_definitions(-D_USE_MATH_DEFINES -D_WIN32 -DBOOST_ALL_NO_LIB)
# -D_ITERATOR_DEBUG_LEVEL)
+ if(WIN10SDK_PATH)
+ message("Building with Win10 Netfabb STL fixing service support")
+ add_definitions(-DHAS_WIN10SDK)
+ include_directories("${WIN10SDK_PATH}/Include")
+ else()
+ message("Building without Win10 Netfabb STL fixing service support")
+ endif()
endif()
add_definitions(-DwxUSE_UNICODE -D_UNICODE -DUNICODE)
diff --git a/xs/src/slic3r/Utils/FixModelByWin10.cpp b/xs/src/slic3r/Utils/FixModelByWin10.cpp
index e4b1952a4..27a79f84e 100644
--- a/xs/src/slic3r/Utils/FixModelByWin10.cpp
+++ b/xs/src/slic3r/Utils/FixModelByWin10.cpp
@@ -1,10 +1,15 @@
#ifdef HAS_WIN10SDK
+#ifndef NOMINMAX
+# define NOMINMAX
+#endif
+
#include "FixModelByWin10.hpp"
#include <roapi.h>
#include <string>
#include <cstdint>
+#include <thread>
// for ComPtr
#include <wrl/client.h>
// from C:/Program Files (x86)/Windows Kits/10/Include/10.0.17134.0/
@@ -12,6 +17,18 @@
#include <winrt/windows.storage.provider.h>
#include <winrt/windows.graphics.printing3d.h>
+#include <boost/filesystem.hpp>
+#include <boost/nowide/convert.hpp>
+#include <boost/nowide/cstdio.hpp>
+
+#include "libslic3r/Model.hpp"
+#include "libslic3r/Print.hpp"
+#include "libslic3r/Format/3mf.hpp"
+#include "../GUI/GUI.hpp"
+#include "../GUI/PresetBundle.hpp"
+
+#include <wx/progdlg.h>
+
extern "C"{
// from rapi.h
typedef HRESULT (__stdcall* FunctionRoInitialize)(int);
@@ -23,6 +40,8 @@ extern "C"{
typedef HRESULT (__stdcall* FunctionWindowsDelteString)(HSTRING string);
}
+namespace Slic3r {
+
HMODULE s_hRuntimeObjectLibrary = nullptr;
FunctionRoInitialize s_RoInitialize = nullptr;
FunctionRoUninitialize s_RoUninitialize = nullptr;
@@ -178,13 +197,13 @@ bool fix_model_by_win10_sdk(const std::string &path_src, const std::string &path
if (! winrt_load_runtime_object_library()) {
printf("Failed to initialize the WinRT library. This should not happen on Windows 10. Exiting.\n");
- return -1;
+ return false;
}
- (*s_RoInitialize)(RO_INIT_MULTITHREADED);
+ HRESULT hr = (*s_RoInitialize)(RO_INIT_MULTITHREADED);
{
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IRandomAccessStream> fileStream;
- HRESULT hr = winrt_open_file_stream(L"D:\\3dprint\\bug.3mf", ABI::Windows::Storage::FileAccessMode::FileAccessMode_Read, fileStream.GetAddressOf());
+ hr = winrt_open_file_stream(boost::nowide::widen(path_src), ABI::Windows::Storage::FileAccessMode::FileAccessMode_Read, fileStream.GetAddressOf());
Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Printing3D::IPrinting3D3MFPackage> printing3d3mfpackage;
hr = winrt_activate_instance(L"Windows.Graphics.Printing3D.Printing3D3MFPackage", printing3d3mfpackage.GetAddressOf());
@@ -198,7 +217,7 @@ bool fix_model_by_win10_sdk(const std::string &path_src, const std::string &path
hr = modelAsync->GetResults(model.GetAddressOf());
} else {
printf("Failed loading the input model. Exiting.\n");
- return -1;
+ return false;
}
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IVector<ABI::Windows::Graphics::Printing3D::Printing3DMesh*>> meshes;
@@ -211,7 +230,7 @@ bool fix_model_by_win10_sdk(const std::string &path_src, const std::string &path
status = winrt_async_await(repairAsync);
if (status != AsyncStatus::Completed) {
printf("Mesh repair failed. Exiting.\n");
- return -1;
+ return false;
}
printf("Mesh repair finished successfully.\n");
repairAsync->GetResults();
@@ -227,7 +246,7 @@ bool fix_model_by_win10_sdk(const std::string &path_src, const std::string &path
status = winrt_async_await(saveToPackageAsync);
if (status != AsyncStatus::Completed) {
printf("Saving mesh into the 3MF container failed. Exiting.\n");
- return -1;
+ return false;
}
hr = saveToPackageAsync->GetResults();
@@ -236,7 +255,7 @@ bool fix_model_by_win10_sdk(const std::string &path_src, const std::string &path
status = winrt_async_await(generatorStreamAsync);
if (status != AsyncStatus::Completed) {
printf("Saving mesh into the 3MF container failed. Exiting.\n");
- return -1;
+ return false;
}
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IRandomAccessStream> generatorStream;
hr = generatorStreamAsync->GetResults(generatorStream.GetAddressOf());
@@ -251,7 +270,7 @@ bool fix_model_by_win10_sdk(const std::string &path_src, const std::string &path
hr = winrt_get_activation_factory(L"Windows.Storage.Streams.Buffer", bufferFactory.GetAddressOf());
// Open the destination file.
- FILE *fout = ::fopen("D:\\3dprint\\bug-repaired.3mf", "wb");
+ FILE *fout = boost::nowide::fopen(path_dst.c_str(), "wb");
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBuffer> buffer;
byte *buffer_ptr;
@@ -270,7 +289,7 @@ bool fix_model_by_win10_sdk(const std::string &path_src, const std::string &path
status = winrt_async_await(asyncRead);
if (status != AsyncStatus::Completed) {
printf("Saving mesh into the 3MF container failed. Exiting.\n");
- return -1;
+ return false;
}
hr = buffer->get_Length(&length);
if (length == 0)
@@ -281,7 +300,40 @@ bool fix_model_by_win10_sdk(const std::string &path_src, const std::string &path
// Here all the COM objects will be released through the ComPtr destructors.
}
(*s_RoUninitialize)();
- return 0;
+ return true;
}
+void fix_model_by_win10_sdk_gui(const ModelObject &model_object, const Print &print, Model &result)
+{
+ enum { PROGRESS_RANGE = 1000 };
+ wxProgressDialog progress_dialog(
+ _(L("Model fixing")),
+ _(L("Exporting model...")),
+ PROGRESS_RANGE, nullptr, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
+ progress_dialog.Pulse();
+
+ // Executing the calculation in a background thread, so that the COM context could be created with its own threading model.
+ // (It seems like wxWidgets initialize the COM contex as single threaded and we need a multi-threaded context).
+ auto worker = std::thread([&model_object, &print, &result, &progress_dialog](){
+ boost::filesystem::path path_src = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
+ path_src += ".3mf";
+ Model model;
+ model.add_object(model_object);
+ bool res = Slic3r::store_3mf(path_src.string().c_str(), &model, const_cast<Print*>(&print), false);
+ model.clear_objects();
+ model.clear_materials();
+
+ boost::filesystem::path path_dst = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
+ path_dst += ".3mf";
+ res = fix_model_by_win10_sdk(path_src.string().c_str(), path_dst.string());
+ boost::filesystem::remove(path_src);
+ PresetBundle bundle;
+ res = Slic3r::load_3mf(path_dst.string().c_str(), &bundle, &result);
+ boost::filesystem::remove(path_dst);
+ });
+ worker.join();
+}
+
+} // namespace Slic3r
+
#endif /* HAS_WIN10SDK */
diff --git a/xs/src/slic3r/Utils/FixModelByWin10.hpp b/xs/src/slic3r/Utils/FixModelByWin10.hpp
index 268b614ef..299c9b75b 100644
--- a/xs/src/slic3r/Utils/FixModelByWin10.hpp
+++ b/xs/src/slic3r/Utils/FixModelByWin10.hpp
@@ -3,16 +3,26 @@
#include <string>
+namespace Slic3r {
+
+class Model;
+class ModelObject;
+class Print;
+
#ifdef HAS_WIN10SDK
extern bool is_windows10();
extern bool fix_model_by_win10_sdk(const std::string &path_src, const std::string &path_dst);
+extern void fix_model_by_win10_sdk_gui(const ModelObject &model_object, const Print &print, Model &result);
#else /* HAS_WIN10SDK */
inline bool is_windows10() { return false; }
inline bool fix_model_by_win10_sdk(const std::string &, const std::string &) { return false; }
+inline void fix_model_by_win10_sdk_gui(const ModelObject &, const Print &, Model &) {}
+
+#endif /* HAS_WIN10SDK */
-#endif /* HAS_WIN10SDK *
+} // namespace Slic3r
#endif /* slic3r_GUI_Utils_FixModelByWin10_hpp_ */
diff --git a/xs/xsp/GUI.xsp b/xs/xsp/GUI.xsp
index 897e63693..1d860d284 100644
--- a/xs/xsp/GUI.xsp
+++ b/xs/xsp/GUI.xsp
@@ -4,6 +4,7 @@
#include <xsinit.h>
#include "slic3r/GUI/GUI.hpp"
#include "slic3r/Utils/ASCIIFolding.hpp"
+#include "slic3r/Utils/FixModelByWin10.hpp"
#include "slic3r/Utils/Serial.hpp"
%}
@@ -28,6 +29,9 @@ bool debugged()
void break_to_debugger()
%code{% Slic3r::GUI::break_to_debugger(); %};
+bool is_windows10()
+ %code{% RETVAL=Slic3r::is_windows10(); %};
+
void set_wxapp(SV *ui)
%code%{ Slic3r::GUI::set_wxapp((wxApp*)wxPli_sv_2_object(aTHX_ ui, "Wx::App")); %};
@@ -98,3 +102,6 @@ int get_export_option(SV *ui)
void desktop_open_datadir_folder()
%code%{ Slic3r::GUI::desktop_open_datadir_folder(); %};
+
+void fix_model_by_win10_sdk_gui(ModelObject *model_object_src, Print *print, Model *model_dst)
+ %code%{ Slic3r::fix_model_by_win10_sdk_gui(*model_object_src, *print, *model_dst); %};