mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-16 00:35:53 +08:00
Merge branch 'master' of https://github.com/prusa3d/PrusaSlicer into et_trafo_matrix
This commit is contained in:
commit
c592367fd2
@ -43,6 +43,14 @@ set(SLIC3R_GTK "2" CACHE STRING "GTK version to use with wxWidgets on Linux")
|
|||||||
|
|
||||||
set(IS_CROSS_COMPILE FALSE)
|
set(IS_CROSS_COMPILE FALSE)
|
||||||
|
|
||||||
|
if (SLIC3R_STATIC)
|
||||||
|
# Prefer config scripts over find modules. This is helpful when building with
|
||||||
|
# the static dependencies. Many libraries have their own export scripts
|
||||||
|
# while having a Find<PkgName> module in standard cmake installation.
|
||||||
|
# (e.g. CURL)
|
||||||
|
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
|
||||||
|
endif ()
|
||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
set(CMAKE_FIND_FRAMEWORK LAST)
|
set(CMAKE_FIND_FRAMEWORK LAST)
|
||||||
set(CMAKE_FIND_APPBUNDLE LAST)
|
set(CMAKE_FIND_APPBUNDLE LAST)
|
||||||
@ -438,23 +446,6 @@ else()
|
|||||||
target_link_libraries(libcurl INTERFACE crypt32)
|
target_link_libraries(libcurl INTERFACE crypt32)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (SLIC3R_STATIC AND NOT SLIC3R_STATIC_EXCLUDE_CURL)
|
|
||||||
if (NOT APPLE)
|
|
||||||
# libcurl is always linked dynamically to the system libcurl on OSX.
|
|
||||||
# On other systems, libcurl is linked statically if SLIC3R_STATIC is set.
|
|
||||||
target_compile_definitions(libcurl INTERFACE CURL_STATICLIB)
|
|
||||||
endif()
|
|
||||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
||||||
# As of now, our build system produces a statically linked libcurl,
|
|
||||||
# which links the OpenSSL library dynamically.
|
|
||||||
find_package(OpenSSL REQUIRED)
|
|
||||||
message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
|
|
||||||
message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
|
|
||||||
target_include_directories(libcurl INTERFACE ${OPENSSL_INCLUDE_DIR})
|
|
||||||
target_link_libraries(libcurl INTERFACE ${OPENSSL_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
## OPTIONAL packages
|
## OPTIONAL packages
|
||||||
|
|
||||||
# Find eigen3 or use bundled version
|
# Find eigen3 or use bundled version
|
||||||
@ -472,6 +463,14 @@ include_directories(BEFORE SYSTEM ${EIGEN3_INCLUDE_DIR})
|
|||||||
|
|
||||||
find_package(EXPAT REQUIRED)
|
find_package(EXPAT REQUIRED)
|
||||||
|
|
||||||
|
add_library(libexpat INTERFACE)
|
||||||
|
|
||||||
|
if (TARGET EXPAT::EXPAT )
|
||||||
|
target_link_libraries(libexpat INTERFACE EXPAT::EXPAT)
|
||||||
|
elseif(TARGET expat::expat)
|
||||||
|
target_link_libraries(libexpat INTERFACE expat::expat)
|
||||||
|
endif ()
|
||||||
|
|
||||||
find_package(PNG REQUIRED)
|
find_package(PNG REQUIRED)
|
||||||
|
|
||||||
set(OpenGL_GL_PREFERENCE "LEGACY")
|
set(OpenGL_GL_PREFERENCE "LEGACY")
|
||||||
|
4
deps/Boost/Boost.cmake
vendored
4
deps/Boost/Boost.cmake
vendored
@ -75,7 +75,9 @@ file(TO_NATIVE_PATH ${DESTDIR}/usr/local/ _prefix)
|
|||||||
set(_boost_flags "")
|
set(_boost_flags "")
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
set(_boost_flags "cflags=-fPIC;cxxflags=-fPIC")
|
set(_boost_flags "cflags=-fPIC;cxxflags=-fPIC")
|
||||||
elseif(APPLE)
|
endif ()
|
||||||
|
|
||||||
|
if(APPLE)
|
||||||
set(_boost_flags
|
set(_boost_flags
|
||||||
"cflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
|
"cflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
|
||||||
"cxxflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
|
"cxxflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
|
||||||
|
9
deps/CMakeLists.txt
vendored
9
deps/CMakeLists.txt
vendored
@ -179,7 +179,12 @@ include(CGAL/CGAL.cmake)
|
|||||||
include(NLopt/NLopt.cmake)
|
include(NLopt/NLopt.cmake)
|
||||||
|
|
||||||
include(OpenSSL/OpenSSL.cmake)
|
include(OpenSSL/OpenSSL.cmake)
|
||||||
include(CURL/CURL.cmake)
|
|
||||||
|
set(CURL_PKG "")
|
||||||
|
if (NOT CURL_FOUND)
|
||||||
|
include(CURL/CURL.cmake)
|
||||||
|
set(CURL_PKG dep_CURL)
|
||||||
|
endif ()
|
||||||
|
|
||||||
include(JPEG/JPEG.cmake)
|
include(JPEG/JPEG.cmake)
|
||||||
include(TIFF/TIFF.cmake)
|
include(TIFF/TIFF.cmake)
|
||||||
@ -188,7 +193,7 @@ include(wxWidgets/wxWidgets.cmake)
|
|||||||
set(_dep_list
|
set(_dep_list
|
||||||
dep_Boost
|
dep_Boost
|
||||||
dep_TBB
|
dep_TBB
|
||||||
dep_CURL
|
${CURL_PKG}
|
||||||
dep_wxWidgets
|
dep_wxWidgets
|
||||||
dep_Cereal
|
dep_Cereal
|
||||||
dep_NLopt
|
dep_NLopt
|
||||||
|
14
deps/CURL/CURL.cmake
vendored
14
deps/CURL/CURL.cmake
vendored
@ -48,11 +48,13 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|||||||
)
|
)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (BUILD_SHARED_LIBS)
|
set(_patch_command "")
|
||||||
set(_curl_static OFF)
|
if (UNIX AND NOT APPLE)
|
||||||
else()
|
# On non-apple UNIX platforms, finding the location of OpenSSL certificates is necessary at runtime, as there is no standard location usable across platforms.
|
||||||
set(_curl_static ON)
|
# The OPENSSL_CERT_OVERRIDE flag is understood by PrusaSlicer and will trigger the search of certificates at initial application launch.
|
||||||
endif()
|
# Then ask the user for consent about the correctness of the found location.
|
||||||
|
set (_patch_command echo set_target_properties(CURL::libcurl PROPERTIES INTERFACE_COMPILE_DEFINITIONS OPENSSL_CERT_OVERRIDE) >> CMake/curl-config.cmake.in)
|
||||||
|
endif ()
|
||||||
|
|
||||||
prusaslicer_add_cmake_project(CURL
|
prusaslicer_add_cmake_project(CURL
|
||||||
# GIT_REPOSITORY https://github.com/curl/curl.git
|
# GIT_REPOSITORY https://github.com/curl/curl.git
|
||||||
@ -62,10 +64,10 @@ prusaslicer_add_cmake_project(CURL
|
|||||||
DEPENDS ${ZLIB_PKG}
|
DEPENDS ${ZLIB_PKG}
|
||||||
# PATCH_COMMAND ${GIT_EXECUTABLE} checkout -f -- . && git clean -df &&
|
# PATCH_COMMAND ${GIT_EXECUTABLE} checkout -f -- . && git clean -df &&
|
||||||
# ${GIT_EXECUTABLE} apply --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/curl-mods.patch
|
# ${GIT_EXECUTABLE} apply --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/curl-mods.patch
|
||||||
|
PATCH_COMMAND "${_patch_command}"
|
||||||
CMAKE_ARGS
|
CMAKE_ARGS
|
||||||
-DBUILD_TESTING:BOOL=OFF
|
-DBUILD_TESTING:BOOL=OFF
|
||||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||||
-DCURL_STATICLIB=${_curl_static}
|
|
||||||
${_curl_platform_flags}
|
${_curl_platform_flags}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
5
deps/deps-macos.cmake
vendored
5
deps/deps-macos.cmake
vendored
@ -15,6 +15,11 @@ set(DEP_CMAKE_OPTS
|
|||||||
|
|
||||||
include("deps-unix-common.cmake")
|
include("deps-unix-common.cmake")
|
||||||
|
|
||||||
|
find_package(CURL QUIET)
|
||||||
|
if (NOT CURL_FOUND)
|
||||||
|
message(WARNING "No CURL dev package found in system, building static library. Mac SDK should include CURL from at least version 10.12. Check your SDK installation.")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
|
||||||
# ExternalProject_Add(dep_boost
|
# ExternalProject_Add(dep_boost
|
||||||
# EXCLUDE_FROM_ALL 1
|
# EXCLUDE_FROM_ALL 1
|
||||||
|
@ -970,10 +970,7 @@ renamed_from = "Creality ENDER-3 BLTouch"
|
|||||||
printer_model = ENDER3BLTOUCH
|
printer_model = ENDER3BLTOUCH
|
||||||
|
|
||||||
[printer:Creality Ender-3 Pro]
|
[printer:Creality Ender-3 Pro]
|
||||||
inherits = *common*; *pauseprint*
|
inherits = Creality Ender-3; *pauseprint*
|
||||||
renamed_from = "Creality Ender-3 Pro"
|
|
||||||
bed_shape = 5x0,215x0,215x220,5x220
|
|
||||||
max_print_height = 250
|
|
||||||
printer_model = ENDER3PRO
|
printer_model = ENDER3PRO
|
||||||
printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3PRO\nPRINTER_HAS_BOWDEN
|
printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3PRO\nPRINTER_HAS_BOWDEN
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ if (SLIC3R_GUI)
|
|||||||
string(REGEX MATCH "wxexpat" WX_EXPAT_BUILTIN ${wxWidgets_LIBRARIES})
|
string(REGEX MATCH "wxexpat" WX_EXPAT_BUILTIN ${wxWidgets_LIBRARIES})
|
||||||
if (EXPAT_FOUND AND NOT WX_EXPAT_BUILTIN)
|
if (EXPAT_FOUND AND NOT WX_EXPAT_BUILTIN)
|
||||||
list(FILTER wxWidgets_LIBRARIES EXCLUDE REGEX expat)
|
list(FILTER wxWidgets_LIBRARIES EXCLUDE REGEX expat)
|
||||||
list(APPEND wxWidgets_LIBRARIES EXPAT::EXPAT)
|
list(APPEND wxWidgets_LIBRARIES libexpat)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# This is an issue in the new wxWidgets cmake build, doesn't deal with librt
|
# This is an issue in the new wxWidgets cmake build, doesn't deal with librt
|
||||||
|
@ -372,7 +372,7 @@ target_link_libraries(libslic3r
|
|||||||
boost_libs
|
boost_libs
|
||||||
clipper
|
clipper
|
||||||
nowide
|
nowide
|
||||||
EXPAT::EXPAT
|
libexpat
|
||||||
glu-libtess
|
glu-libtess
|
||||||
qhull
|
qhull
|
||||||
semver
|
semver
|
||||||
|
@ -129,9 +129,10 @@ GroundingLocation Layer::getBestGroundingLocation
|
|||||||
if (contour.size() > 2) {
|
if (contour.size() > 2) {
|
||||||
Point prev = contour.points.back();
|
Point prev = contour.points.back();
|
||||||
for (const Point &p2 : contour.points) {
|
for (const Point &p2 : contour.points) {
|
||||||
if (double d = Line::distance_to_squared(unsupported_location, prev, p2); d < d2) {
|
Point closest_point;
|
||||||
|
if (double d = line_alg::distance_to_squared(Line{prev, p2}, unsupported_location, &closest_point); d < d2) {
|
||||||
d2 = d;
|
d2 = d;
|
||||||
node_location = Geometry::foot_pt({ prev, p2 }, unsupported_location).cast<coord_t>();
|
node_location = closest_point;
|
||||||
}
|
}
|
||||||
prev = p2;
|
prev = p2;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <vector>
|
||||||
|
#include <limits>
|
||||||
|
#include <cstdlib> // adds size_t (without std::)
|
||||||
|
|
||||||
template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
|
template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
|
||||||
class MutablePriorityQueue
|
class MutablePriorityQueue
|
||||||
@ -21,7 +24,7 @@ public:
|
|||||||
MutablePriorityQueue& operator=(MutablePriorityQueue &&) = default;
|
MutablePriorityQueue& operator=(MutablePriorityQueue &&) = default;
|
||||||
|
|
||||||
// This class modifies the outside data through the m_index_setter
|
// This class modifies the outside data through the m_index_setter
|
||||||
// and thus it should not be copied. The semantics are similar to std::unique_ptr
|
// and thus it should not be copied. The semantics is similar to std::unique_ptr
|
||||||
MutablePriorityQueue(const MutablePriorityQueue &) = delete;
|
MutablePriorityQueue(const MutablePriorityQueue &) = delete;
|
||||||
MutablePriorityQueue& operator=(const MutablePriorityQueue &) = delete;
|
MutablePriorityQueue& operator=(const MutablePriorityQueue &) = delete;
|
||||||
|
|
||||||
@ -38,6 +41,7 @@ public:
|
|||||||
bool empty() const { return m_heap.empty(); }
|
bool empty() const { return m_heap.empty(); }
|
||||||
T& operator[](std::size_t idx) noexcept { return m_heap[idx]; }
|
T& operator[](std::size_t idx) noexcept { return m_heap[idx]; }
|
||||||
const T& operator[](std::size_t idx) const noexcept { return m_heap[idx]; }
|
const T& operator[](std::size_t idx) const noexcept { return m_heap[idx]; }
|
||||||
|
static constexpr size_t invalid_id() { return std::numeric_limits<size_t>::max(); }
|
||||||
|
|
||||||
using iterator = typename std::vector<T>::iterator;
|
using iterator = typename std::vector<T>::iterator;
|
||||||
using const_iterator = typename std::vector<T>::const_iterator;
|
using const_iterator = typename std::vector<T>::const_iterator;
|
||||||
@ -66,14 +70,10 @@ MutablePriorityQueue<T, IndexSetter, LessPredicate, ResetIndexWhenRemoved> make_
|
|||||||
template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexWhenRemoved>
|
template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexWhenRemoved>
|
||||||
inline void MutablePriorityQueue<T, LessPredicate, IndexSetter, ResetIndexWhenRemoved>::clear()
|
inline void MutablePriorityQueue<T, LessPredicate, IndexSetter, ResetIndexWhenRemoved>::clear()
|
||||||
{
|
{
|
||||||
#ifdef NDEBUG
|
if constexpr (ResetIndexWhenRemoved) {
|
||||||
// Only mark as removed from the queue in release mode, if configured so.
|
|
||||||
if (ResetIndexWhenRemoved)
|
|
||||||
#endif /* NDEBUG */
|
|
||||||
{
|
|
||||||
for (size_t idx = 0; idx < m_heap.size(); ++ idx)
|
for (size_t idx = 0; idx < m_heap.size(); ++ idx)
|
||||||
// Mark as removed from the queue.
|
// Mark as removed from the queue.
|
||||||
m_index_setter(m_heap[idx], std::numeric_limits<size_t>::max());
|
m_index_setter(m_heap[idx], this->invalid_id());
|
||||||
}
|
}
|
||||||
m_heap.clear();
|
m_heap.clear();
|
||||||
}
|
}
|
||||||
@ -100,13 +100,9 @@ template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexW
|
|||||||
inline void MutablePriorityQueue<T, LessPredicate, IndexSetter, ResetIndexWhenRemoved>::pop()
|
inline void MutablePriorityQueue<T, LessPredicate, IndexSetter, ResetIndexWhenRemoved>::pop()
|
||||||
{
|
{
|
||||||
assert(! m_heap.empty());
|
assert(! m_heap.empty());
|
||||||
#ifdef NDEBUG
|
if constexpr (ResetIndexWhenRemoved) {
|
||||||
// Only mark as removed from the queue in release mode, if configured so.
|
|
||||||
if (ResetIndexWhenRemoved)
|
|
||||||
#endif /* NDEBUG */
|
|
||||||
{
|
|
||||||
// Mark as removed from the queue.
|
// Mark as removed from the queue.
|
||||||
m_index_setter(m_heap.front(), std::numeric_limits<size_t>::max());
|
m_index_setter(m_heap.front(), this->invalid_id());
|
||||||
}
|
}
|
||||||
if (m_heap.size() > 1) {
|
if (m_heap.size() > 1) {
|
||||||
m_heap.front() = m_heap.back();
|
m_heap.front() = m_heap.back();
|
||||||
@ -121,13 +117,10 @@ template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexW
|
|||||||
inline void MutablePriorityQueue<T, LessPredicate, IndexSetter, ResetIndexWhenRemoved>::remove(size_t idx)
|
inline void MutablePriorityQueue<T, LessPredicate, IndexSetter, ResetIndexWhenRemoved>::remove(size_t idx)
|
||||||
{
|
{
|
||||||
assert(idx < m_heap.size());
|
assert(idx < m_heap.size());
|
||||||
#ifdef NDEBUG
|
|
||||||
// Only mark as removed from the queue in release mode, if configured so.
|
// Only mark as removed from the queue in release mode, if configured so.
|
||||||
if (ResetIndexWhenRemoved)
|
if constexpr (ResetIndexWhenRemoved) {
|
||||||
#endif /* NDEBUG */
|
|
||||||
{
|
|
||||||
// Mark as removed from the queue.
|
// Mark as removed from the queue.
|
||||||
m_index_setter(m_heap[idx], std::numeric_limits<size_t>::max());
|
m_index_setter(m_heap[idx], this->invalid_id());
|
||||||
}
|
}
|
||||||
if (idx + 1 == m_heap.size()) {
|
if (idx + 1 == m_heap.size()) {
|
||||||
m_heap.pop_back();
|
m_heap.pop_back();
|
||||||
@ -274,6 +267,14 @@ public:
|
|||||||
{}
|
{}
|
||||||
~MutableSkipHeapPriorityQueue() { clear(); }
|
~MutableSkipHeapPriorityQueue() { clear(); }
|
||||||
|
|
||||||
|
MutableSkipHeapPriorityQueue(MutableSkipHeapPriorityQueue &&) = default;
|
||||||
|
MutableSkipHeapPriorityQueue &operator=(MutableSkipHeapPriorityQueue &&) = default;
|
||||||
|
|
||||||
|
// This class modifies the outside data through the m_index_setter
|
||||||
|
// and thus it should not be copied. The semantics is similar to std::unique_ptr
|
||||||
|
MutableSkipHeapPriorityQueue(const MutableSkipHeapPriorityQueue &) = delete;
|
||||||
|
MutableSkipHeapPriorityQueue &operator=(const MutableSkipHeapPriorityQueue &) = delete;
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
// Reserve one unused element per miniheap.
|
// Reserve one unused element per miniheap.
|
||||||
void reserve(size_t cnt) { m_heap.reserve(cnt + ((cnt + (address::block_size - 1)) / (address::block_size - 1))); }
|
void reserve(size_t cnt) { m_heap.reserve(cnt + ((cnt + (address::block_size - 1)) / (address::block_size - 1))); }
|
||||||
@ -285,9 +286,12 @@ public:
|
|||||||
void update(size_t idx) { assert(! address::is_padding(idx)); T item = m_heap[idx]; remove(idx); push(item); }
|
void update(size_t idx) { assert(! address::is_padding(idx)); T item = m_heap[idx]; remove(idx); push(item); }
|
||||||
// There is one padding element storead at each miniheap, thus lower the number of elements by the number of miniheaps.
|
// There is one padding element storead at each miniheap, thus lower the number of elements by the number of miniheaps.
|
||||||
size_t size() const noexcept { return m_heap.size() - (m_heap.size() + address::block_size - 1) / address::block_size; }
|
size_t size() const noexcept { return m_heap.size() - (m_heap.size() + address::block_size - 1) / address::block_size; }
|
||||||
|
// Number of heap elements including padding. heap_size() >= size().
|
||||||
|
size_t heap_size() const noexcept { return m_heap.size(); }
|
||||||
bool empty() const { return m_heap.empty(); }
|
bool empty() const { return m_heap.empty(); }
|
||||||
T& operator[](std::size_t idx) noexcept { assert(! address::is_padding(idx)); return m_heap[idx]; }
|
T& operator[](std::size_t idx) noexcept { assert(! address::is_padding(idx)); return m_heap[idx]; }
|
||||||
const T& operator[](std::size_t idx) const noexcept { assert(! address::is_padding(idx)); return m_heap[idx]; }
|
const T& operator[](std::size_t idx) const noexcept { assert(! address::is_padding(idx)); return m_heap[idx]; }
|
||||||
|
static constexpr size_t invalid_id() { return std::numeric_limits<size_t>::max(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void update_heap_up(size_t top, size_t bottom);
|
void update_heap_up(size_t top, size_t bottom);
|
||||||
@ -317,15 +321,11 @@ MutableSkipHeapPriorityQueue<T, IndexSetter, LessPredicate, BlockSize, ResetInde
|
|||||||
template<class T, class LessPredicate, class IndexSetter, std::size_t blocking, const bool ResetIndexWhenRemoved>
|
template<class T, class LessPredicate, class IndexSetter, std::size_t blocking, const bool ResetIndexWhenRemoved>
|
||||||
inline void MutableSkipHeapPriorityQueue<T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved>::clear()
|
inline void MutableSkipHeapPriorityQueue<T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved>::clear()
|
||||||
{
|
{
|
||||||
#ifdef NDEBUG
|
if constexpr (ResetIndexWhenRemoved) {
|
||||||
// Only mark as removed from the queue in release mode, if configured so.
|
|
||||||
if (ResetIndexWhenRemoved)
|
|
||||||
#endif /* NDEBUG */
|
|
||||||
{
|
|
||||||
for (size_t idx = 0; idx < m_heap.size(); ++ idx)
|
for (size_t idx = 0; idx < m_heap.size(); ++ idx)
|
||||||
// Mark as removed from the queue.
|
// Mark as removed from the queue.
|
||||||
if (! address::is_padding(idx))
|
if (! address::is_padding(idx))
|
||||||
m_index_setter(m_heap[idx], std::numeric_limits<size_t>::max());
|
m_index_setter(m_heap[idx], this->invalid_id());
|
||||||
}
|
}
|
||||||
m_heap.clear();
|
m_heap.clear();
|
||||||
}
|
}
|
||||||
@ -356,13 +356,9 @@ template<class T, class LessPredicate, class IndexSetter, std::size_t blocking,
|
|||||||
inline void MutableSkipHeapPriorityQueue<T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved>::pop()
|
inline void MutableSkipHeapPriorityQueue<T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved>::pop()
|
||||||
{
|
{
|
||||||
assert(! m_heap.empty());
|
assert(! m_heap.empty());
|
||||||
#ifdef NDEBUG
|
if constexpr (ResetIndexWhenRemoved) {
|
||||||
// Only mark as removed from the queue in release mode, if configured so.
|
|
||||||
if (ResetIndexWhenRemoved)
|
|
||||||
#endif /* NDEBUG */
|
|
||||||
{
|
|
||||||
// Mark as removed from the queue.
|
// Mark as removed from the queue.
|
||||||
m_index_setter(m_heap[1], std::numeric_limits<size_t>::max());
|
m_index_setter(m_heap[1], this->invalid_id());
|
||||||
}
|
}
|
||||||
// Zero'th element is padding, thus non-empty queue must have at least two elements.
|
// Zero'th element is padding, thus non-empty queue must have at least two elements.
|
||||||
if (m_heap.size() > 2) {
|
if (m_heap.size() > 2) {
|
||||||
@ -379,13 +375,9 @@ inline void MutableSkipHeapPriorityQueue<T, LessPredicate, IndexSetter, blocking
|
|||||||
{
|
{
|
||||||
assert(idx < m_heap.size());
|
assert(idx < m_heap.size());
|
||||||
assert(! address::is_padding(idx));
|
assert(! address::is_padding(idx));
|
||||||
#ifdef NDEBUG
|
if constexpr (ResetIndexWhenRemoved) {
|
||||||
// Only mark as removed from the queue in release mode, if configured so.
|
|
||||||
if (ResetIndexWhenRemoved)
|
|
||||||
#endif /* NDEBUG */
|
|
||||||
{
|
|
||||||
// Mark as removed from the queue.
|
// Mark as removed from the queue.
|
||||||
m_index_setter(m_heap[idx], std::numeric_limits<size_t>::max());
|
m_index_setter(m_heap[idx], this->invalid_id());
|
||||||
}
|
}
|
||||||
if (idx + 1 == m_heap.size()) {
|
if (idx + 1 == m_heap.size()) {
|
||||||
this->pop_back();
|
this->pop_back();
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "GCode.hpp"
|
#include "GCode.hpp"
|
||||||
#include "GCode/WipeTower.hpp"
|
#include "GCode/WipeTower.hpp"
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
#include "BuildVolume.hpp"
|
||||||
|
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
|
||||||
@ -387,7 +388,7 @@ bool Print::sequential_print_horizontal_clearance_valid(const Print& print, Poly
|
|||||||
Geometry::assemble_transform({ 0.0, 0.0, model_instance0->get_offset().z() }, model_instance0->get_rotation(), model_instance0->get_scaling_factor(), model_instance0->get_mirror())),
|
Geometry::assemble_transform({ 0.0, 0.0, model_instance0->get_offset().z() }, model_instance0->get_rotation(), model_instance0->get_scaling_factor(), model_instance0->get_mirror())),
|
||||||
// Shrink the extruder_clearance_radius a tiny bit, so that if the object arrangement algorithm placed the objects
|
// Shrink the extruder_clearance_radius a tiny bit, so that if the object arrangement algorithm placed the objects
|
||||||
// exactly by satisfying the extruder_clearance_radius, this test will not trigger collision.
|
// exactly by satisfying the extruder_clearance_radius, this test will not trigger collision.
|
||||||
float(scale_(0.5 * print.config().extruder_clearance_radius.value - EPSILON)),
|
float(scale_(0.5 * print.config().extruder_clearance_radius.value - BuildVolume::BedEpsilon)),
|
||||||
jtRound, scale_(0.1)).front());
|
jtRound, scale_(0.1)).front());
|
||||||
}
|
}
|
||||||
// Make a copy, so it may be rotated for instances.
|
// Make a copy, so it may be rotated for instances.
|
||||||
|
@ -195,7 +195,15 @@ std::vector<std::pair<size_t, bool>> chain_segments_greedy_constrained_reversals
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize a heap of end points sorted by the lowest distance to the next valid point of a path.
|
// Initialize a heap of end points sorted by the lowest distance to the next valid point of a path.
|
||||||
auto queue = make_mutable_priority_queue<EndPoint*, false>(
|
auto queue = make_mutable_priority_queue<EndPoint*,
|
||||||
|
#ifndef NDEBUG
|
||||||
|
// In debug mode, reset indices when removing an item from the queue for debugging purposes.
|
||||||
|
true
|
||||||
|
#else // NDEBUG
|
||||||
|
// In release mode, don't reset indices when removing an item from the queue.
|
||||||
|
false
|
||||||
|
#endif // NDEBUG
|
||||||
|
>(
|
||||||
[](EndPoint *ep, size_t idx){ ep->heap_idx = idx; },
|
[](EndPoint *ep, size_t idx){ ep->heap_idx = idx; },
|
||||||
[](EndPoint *l, EndPoint *r){ return l->distance_out < r->distance_out; });
|
[](EndPoint *l, EndPoint *r){ return l->distance_out < r->distance_out; });
|
||||||
queue.reserve(end_points.size() * 2 - 1);
|
queue.reserve(end_points.size() * 2 - 1);
|
||||||
@ -213,7 +221,7 @@ std::vector<std::pair<size_t, bool>> chain_segments_greedy_constrained_reversals
|
|||||||
assert(ep.chain_id == 0);
|
assert(ep.chain_id == 0);
|
||||||
} else {
|
} else {
|
||||||
// End point is NOT on the heap, therefore it is part of the output path.
|
// End point is NOT on the heap, therefore it is part of the output path.
|
||||||
assert(ep.heap_idx == std::numeric_limits<size_t>::max());
|
assert(ep.heap_idx == queue.invalid_id());
|
||||||
assert(ep.chain_id != 0);
|
assert(ep.chain_id != 0);
|
||||||
if (&ep == first_point) {
|
if (&ep == first_point) {
|
||||||
assert(ep.edge_out == nullptr);
|
assert(ep.edge_out == nullptr);
|
||||||
@ -222,7 +230,7 @@ std::vector<std::pair<size_t, bool>> chain_segments_greedy_constrained_reversals
|
|||||||
// Detect loops.
|
// Detect loops.
|
||||||
for (EndPoint *pt = &ep; pt != nullptr;) {
|
for (EndPoint *pt = &ep; pt != nullptr;) {
|
||||||
// Out of queue. It is a final point.
|
// Out of queue. It is a final point.
|
||||||
assert(pt->heap_idx == std::numeric_limits<size_t>::max());
|
assert(pt->heap_idx == queue.invalid_id());
|
||||||
EndPoint *pt_other = &end_points[(pt - &end_points.front()) ^ 1];
|
EndPoint *pt_other = &end_points[(pt - &end_points.front()) ^ 1];
|
||||||
if (pt_other->heap_idx < queue.size())
|
if (pt_other->heap_idx < queue.size())
|
||||||
// The other side of this segment is undecided yet.
|
// The other side of this segment is undecided yet.
|
||||||
|
@ -87,6 +87,8 @@
|
|||||||
#define ENABLE_USED_FILAMENT_POST_PROCESS (1 && ENABLE_2_5_0_ALPHA1)
|
#define ENABLE_USED_FILAMENT_POST_PROCESS (1 && ENABLE_2_5_0_ALPHA1)
|
||||||
// Enable gizmo grabbers to share common models
|
// Enable gizmo grabbers to share common models
|
||||||
#define ENABLE_GIZMO_GRABBER_REFACTOR (1 && ENABLE_2_5_0_ALPHA1)
|
#define ENABLE_GIZMO_GRABBER_REFACTOR (1 && ENABLE_2_5_0_ALPHA1)
|
||||||
|
// Disable association to 3mf and stl files if the application is run on Windows 8 or later
|
||||||
|
#define ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER (1 && ENABLE_2_5_0_ALPHA1)
|
||||||
|
|
||||||
|
|
||||||
#endif // _prusaslicer_technologies_h_
|
#endif // _prusaslicer_technologies_h_
|
||||||
|
@ -292,10 +292,6 @@ if (SLIC3R_STATIC)
|
|||||||
target_compile_definitions(libslic3r_gui PUBLIC -DwxDEBUG_LEVEL=0)
|
target_compile_definitions(libslic3r_gui PUBLIC -DwxDEBUG_LEVEL=0)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (SLIC3R_STATIC AND NOT SLIC3R_STATIC_EXCLUDE_CURL AND UNIX AND NOT APPLE)
|
|
||||||
target_compile_definitions(libslic3r_gui PRIVATE OPENSSL_CERT_OVERRIDE)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
|
if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
|
||||||
add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE)
|
add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE)
|
||||||
endif ()
|
endif ()
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -386,14 +386,14 @@ void GCodeViewer::SequentialView::Marker::render()
|
|||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCodeViewer::SequentialView::GCodeWindow::load_gcode(const std::string& filename, std::vector<size_t> &&lines_ends)
|
void GCodeViewer::SequentialView::GCodeWindow::load_gcode(const std::string& filename, const std::vector<size_t>& lines_ends)
|
||||||
{
|
{
|
||||||
assert(! m_file.is_open());
|
assert(! m_file.is_open());
|
||||||
if (m_file.is_open())
|
if (m_file.is_open())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_filename = filename;
|
m_filename = filename;
|
||||||
m_lines_ends = std::move(lines_ends);
|
m_lines_ends = lines_ends;
|
||||||
|
|
||||||
m_selected_line_id = 0;
|
m_selected_line_id = 0;
|
||||||
m_last_lines_size = 0;
|
m_last_lines_size = 0;
|
||||||
@ -771,9 +771,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr
|
|||||||
// release gpu memory, if used
|
// release gpu memory, if used
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
m_sequential_view.gcode_window.load_gcode(gcode_result.filename,
|
m_sequential_view.gcode_window.load_gcode(gcode_result.filename, gcode_result.lines_ends);
|
||||||
// Stealing out lines_ends should be safe because this gcode_result is processed only once (see the 1st if in this function).
|
|
||||||
std::move(const_cast<std::vector<size_t>&>(gcode_result.lines_ends)));
|
|
||||||
|
|
||||||
if (wxGetApp().is_gcode_viewer())
|
if (wxGetApp().is_gcode_viewer())
|
||||||
m_custom_gcode_per_print_z = gcode_result.custom_gcode_per_print_z;
|
m_custom_gcode_per_print_z = gcode_result.custom_gcode_per_print_z;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -7434,12 +7434,13 @@ bool GLCanvas3D::_is_any_volume_outside() const
|
|||||||
void GLCanvas3D::_update_selection_from_hover()
|
void GLCanvas3D::_update_selection_from_hover()
|
||||||
{
|
{
|
||||||
bool ctrl_pressed = wxGetKeyState(WXK_CONTROL);
|
bool ctrl_pressed = wxGetKeyState(WXK_CONTROL);
|
||||||
|
bool selection_changed = false;
|
||||||
|
|
||||||
if (m_hover_volume_idxs.empty()) {
|
if (m_hover_volume_idxs.empty()) {
|
||||||
if (!ctrl_pressed && m_rectangle_selection.get_state() == GLSelectionRectangle::EState::Select)
|
if (!ctrl_pressed && m_rectangle_selection.get_state() == GLSelectionRectangle::EState::Select) {
|
||||||
|
selection_changed = ! m_selection.is_empty();
|
||||||
m_selection.remove_all();
|
m_selection.remove_all();
|
||||||
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLSelectionRectangle::EState state = m_rectangle_selection.get_state();
|
GLSelectionRectangle::EState state = m_rectangle_selection.get_state();
|
||||||
@ -7452,7 +7453,6 @@ void GLCanvas3D::_update_selection_from_hover()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool selection_changed = false;
|
|
||||||
#if ENABLE_NEW_RECTANGLE_SELECTION
|
#if ENABLE_NEW_RECTANGLE_SELECTION
|
||||||
if (!m_rectangle_selection.is_empty()) {
|
if (!m_rectangle_selection.is_empty()) {
|
||||||
#endif // ENABLE_NEW_RECTANGLE_SELECTION
|
#endif // ENABLE_NEW_RECTANGLE_SELECTION
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -147,7 +147,7 @@ void GLGizmoSimplify::add_simplify_suggestion_notification(
|
|||||||
for (size_t object_id : big_ids) {
|
for (size_t object_id : big_ids) {
|
||||||
std::string t = GUI::format(_L(
|
std::string t = GUI::format(_L(
|
||||||
"Processing model '%1%' with more than 1M triangles "
|
"Processing model '%1%' with more than 1M triangles "
|
||||||
"could be slow. It is highly recommend to reduce "
|
"could be slow. It is highly recommended to reduce "
|
||||||
"amount of triangles."), objects[object_id]->name);
|
"amount of triangles."), objects[object_id]->name);
|
||||||
std::string hypertext = _u8L("Simplify model");
|
std::string hypertext = _u8L("Simplify model");
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -141,7 +141,7 @@ static bool check_internet_connection_win()
|
|||||||
{
|
{
|
||||||
bool internet = true; // return true if COM object creation fails.
|
bool internet = true; // return true if COM object creation fails.
|
||||||
|
|
||||||
if (CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) == S_OK) {
|
if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) {
|
||||||
{
|
{
|
||||||
CComPtr<INetworkListManager> pNLM;
|
CComPtr<INetworkListManager> pNLM;
|
||||||
if (pNLM.CoCreateInstance(CLSID_NetworkListManager) == S_OK) {
|
if (pNLM.CoCreateInstance(CLSID_NetworkListManager) == S_OK) {
|
||||||
|
@ -1,449 +1,449 @@
|
|||||||
#ifdef HAS_WIN10SDK
|
#ifdef HAS_WIN10SDK
|
||||||
|
|
||||||
#ifndef NOMINMAX
|
#ifndef NOMINMAX
|
||||||
# define NOMINMAX
|
# define NOMINMAX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Windows Runtime
|
// Windows Runtime
|
||||||
#include <roapi.h>
|
#include <roapi.h>
|
||||||
// for ComPtr
|
// for ComPtr
|
||||||
#include <wrl/client.h>
|
#include <wrl/client.h>
|
||||||
|
|
||||||
// from C:/Program Files (x86)/Windows Kits/10/Include/10.0.17134.0/
|
// from C:/Program Files (x86)/Windows Kits/10/Include/10.0.17134.0/
|
||||||
#include <winrt/robuffer.h>
|
#include <winrt/robuffer.h>
|
||||||
#include <winrt/windows.storage.provider.h>
|
#include <winrt/windows.storage.provider.h>
|
||||||
#include <winrt/windows.graphics.printing3d.h>
|
#include <winrt/windows.graphics.printing3d.h>
|
||||||
|
|
||||||
#include "FixModelByWin10.hpp"
|
#include "FixModelByWin10.hpp"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/nowide/convert.hpp>
|
#include <boost/nowide/convert.hpp>
|
||||||
#include <boost/nowide/cstdio.hpp>
|
#include <boost/nowide/cstdio.hpp>
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
#include "libslic3r/Model.hpp"
|
#include "libslic3r/Model.hpp"
|
||||||
#include "libslic3r/Print.hpp"
|
#include "libslic3r/Print.hpp"
|
||||||
#include "libslic3r/PresetBundle.hpp"
|
#include "libslic3r/PresetBundle.hpp"
|
||||||
#include "libslic3r/Format/3mf.hpp"
|
#include "libslic3r/Format/3mf.hpp"
|
||||||
#include "../GUI/GUI.hpp"
|
#include "../GUI/GUI.hpp"
|
||||||
#include "../GUI/I18N.hpp"
|
#include "../GUI/I18N.hpp"
|
||||||
#include "../GUI/MsgDialog.hpp"
|
#include "../GUI/MsgDialog.hpp"
|
||||||
|
|
||||||
#include <wx/msgdlg.h>
|
#include <wx/msgdlg.h>
|
||||||
#include <wx/progdlg.h>
|
#include <wx/progdlg.h>
|
||||||
|
|
||||||
extern "C"{
|
extern "C"{
|
||||||
// from rapi.h
|
// from rapi.h
|
||||||
typedef HRESULT (__stdcall* FunctionRoInitialize)(int);
|
typedef HRESULT (__stdcall* FunctionRoInitialize)(int);
|
||||||
typedef HRESULT (__stdcall* FunctionRoUninitialize)();
|
typedef HRESULT (__stdcall* FunctionRoUninitialize)();
|
||||||
typedef HRESULT (__stdcall* FunctionRoActivateInstance)(HSTRING activatableClassId, IInspectable **instance);
|
typedef HRESULT (__stdcall* FunctionRoActivateInstance)(HSTRING activatableClassId, IInspectable **instance);
|
||||||
typedef HRESULT (__stdcall* FunctionRoGetActivationFactory)(HSTRING activatableClassId, REFIID iid, void **factory);
|
typedef HRESULT (__stdcall* FunctionRoGetActivationFactory)(HSTRING activatableClassId, REFIID iid, void **factory);
|
||||||
// from winstring.h
|
// from winstring.h
|
||||||
typedef HRESULT (__stdcall* FunctionWindowsCreateString)(LPCWSTR sourceString, UINT32 length, HSTRING *string);
|
typedef HRESULT (__stdcall* FunctionWindowsCreateString)(LPCWSTR sourceString, UINT32 length, HSTRING *string);
|
||||||
typedef HRESULT (__stdcall* FunctionWindowsDelteString)(HSTRING string);
|
typedef HRESULT (__stdcall* FunctionWindowsDelteString)(HSTRING string);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
HMODULE s_hRuntimeObjectLibrary = nullptr;
|
HMODULE s_hRuntimeObjectLibrary = nullptr;
|
||||||
FunctionRoInitialize s_RoInitialize = nullptr;
|
FunctionRoInitialize s_RoInitialize = nullptr;
|
||||||
FunctionRoUninitialize s_RoUninitialize = nullptr;
|
FunctionRoUninitialize s_RoUninitialize = nullptr;
|
||||||
FunctionRoActivateInstance s_RoActivateInstance = nullptr;
|
FunctionRoActivateInstance s_RoActivateInstance = nullptr;
|
||||||
FunctionRoGetActivationFactory s_RoGetActivationFactory = nullptr;
|
FunctionRoGetActivationFactory s_RoGetActivationFactory = nullptr;
|
||||||
FunctionWindowsCreateString s_WindowsCreateString = nullptr;
|
FunctionWindowsCreateString s_WindowsCreateString = nullptr;
|
||||||
FunctionWindowsDelteString s_WindowsDeleteString = nullptr;
|
FunctionWindowsDelteString s_WindowsDeleteString = nullptr;
|
||||||
|
|
||||||
bool winrt_load_runtime_object_library()
|
bool winrt_load_runtime_object_library()
|
||||||
{
|
{
|
||||||
if (s_hRuntimeObjectLibrary == nullptr)
|
if (s_hRuntimeObjectLibrary == nullptr)
|
||||||
s_hRuntimeObjectLibrary = LoadLibrary(L"ComBase.dll");
|
s_hRuntimeObjectLibrary = LoadLibrary(L"ComBase.dll");
|
||||||
if (s_hRuntimeObjectLibrary != nullptr) {
|
if (s_hRuntimeObjectLibrary != nullptr) {
|
||||||
s_RoInitialize = (FunctionRoInitialize) GetProcAddress(s_hRuntimeObjectLibrary, "RoInitialize");
|
s_RoInitialize = (FunctionRoInitialize) GetProcAddress(s_hRuntimeObjectLibrary, "RoInitialize");
|
||||||
s_RoUninitialize = (FunctionRoUninitialize) GetProcAddress(s_hRuntimeObjectLibrary, "RoUninitialize");
|
s_RoUninitialize = (FunctionRoUninitialize) GetProcAddress(s_hRuntimeObjectLibrary, "RoUninitialize");
|
||||||
s_RoActivateInstance = (FunctionRoActivateInstance) GetProcAddress(s_hRuntimeObjectLibrary, "RoActivateInstance");
|
s_RoActivateInstance = (FunctionRoActivateInstance) GetProcAddress(s_hRuntimeObjectLibrary, "RoActivateInstance");
|
||||||
s_RoGetActivationFactory = (FunctionRoGetActivationFactory) GetProcAddress(s_hRuntimeObjectLibrary, "RoGetActivationFactory");
|
s_RoGetActivationFactory = (FunctionRoGetActivationFactory) GetProcAddress(s_hRuntimeObjectLibrary, "RoGetActivationFactory");
|
||||||
s_WindowsCreateString = (FunctionWindowsCreateString) GetProcAddress(s_hRuntimeObjectLibrary, "WindowsCreateString");
|
s_WindowsCreateString = (FunctionWindowsCreateString) GetProcAddress(s_hRuntimeObjectLibrary, "WindowsCreateString");
|
||||||
s_WindowsDeleteString = (FunctionWindowsDelteString) GetProcAddress(s_hRuntimeObjectLibrary, "WindowsDeleteString");
|
s_WindowsDeleteString = (FunctionWindowsDelteString) GetProcAddress(s_hRuntimeObjectLibrary, "WindowsDeleteString");
|
||||||
}
|
}
|
||||||
return s_RoInitialize && s_RoUninitialize && s_RoActivateInstance && s_WindowsCreateString && s_WindowsDeleteString;
|
return s_RoInitialize && s_RoUninitialize && s_RoActivateInstance && s_WindowsCreateString && s_WindowsDeleteString;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT winrt_activate_instance(const std::wstring &class_name, IInspectable **pinst)
|
static HRESULT winrt_activate_instance(const std::wstring &class_name, IInspectable **pinst)
|
||||||
{
|
{
|
||||||
HSTRING hClassName;
|
HSTRING hClassName;
|
||||||
HRESULT hr = (*s_WindowsCreateString)(class_name.c_str(), class_name.size(), &hClassName);
|
HRESULT hr = (*s_WindowsCreateString)(class_name.c_str(), class_name.size(), &hClassName);
|
||||||
if (S_OK != hr)
|
if (S_OK != hr)
|
||||||
return hr;
|
return hr;
|
||||||
hr = (*s_RoActivateInstance)(hClassName, pinst);
|
hr = (*s_RoActivateInstance)(hClassName, pinst);
|
||||||
(*s_WindowsDeleteString)(hClassName);
|
(*s_WindowsDeleteString)(hClassName);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename TYPE>
|
template<typename TYPE>
|
||||||
static HRESULT winrt_activate_instance(const std::wstring &class_name, TYPE **pinst)
|
static HRESULT winrt_activate_instance(const std::wstring &class_name, TYPE **pinst)
|
||||||
{
|
{
|
||||||
IInspectable *pinspectable = nullptr;
|
IInspectable *pinspectable = nullptr;
|
||||||
HRESULT hr = winrt_activate_instance(class_name, &pinspectable);
|
HRESULT hr = winrt_activate_instance(class_name, &pinspectable);
|
||||||
if (S_OK != hr)
|
if (S_OK != hr)
|
||||||
return hr;
|
return hr;
|
||||||
hr = pinspectable->QueryInterface(__uuidof(TYPE), (void**)pinst);
|
hr = pinspectable->QueryInterface(__uuidof(TYPE), (void**)pinst);
|
||||||
pinspectable->Release();
|
pinspectable->Release();
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT winrt_get_activation_factory(const std::wstring &class_name, REFIID iid, void **pinst)
|
static HRESULT winrt_get_activation_factory(const std::wstring &class_name, REFIID iid, void **pinst)
|
||||||
{
|
{
|
||||||
HSTRING hClassName;
|
HSTRING hClassName;
|
||||||
HRESULT hr = (*s_WindowsCreateString)(class_name.c_str(), class_name.size(), &hClassName);
|
HRESULT hr = (*s_WindowsCreateString)(class_name.c_str(), class_name.size(), &hClassName);
|
||||||
if (S_OK != hr)
|
if (S_OK != hr)
|
||||||
return hr;
|
return hr;
|
||||||
hr = (*s_RoGetActivationFactory)(hClassName, iid, pinst);
|
hr = (*s_RoGetActivationFactory)(hClassName, iid, pinst);
|
||||||
(*s_WindowsDeleteString)(hClassName);
|
(*s_WindowsDeleteString)(hClassName);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename TYPE>
|
template<typename TYPE>
|
||||||
static HRESULT winrt_get_activation_factory(const std::wstring &class_name, TYPE **pinst)
|
static HRESULT winrt_get_activation_factory(const std::wstring &class_name, TYPE **pinst)
|
||||||
{
|
{
|
||||||
return winrt_get_activation_factory(class_name, __uuidof(TYPE), reinterpret_cast<void**>(pinst));
|
return winrt_get_activation_factory(class_name, __uuidof(TYPE), reinterpret_cast<void**>(pinst));
|
||||||
}
|
}
|
||||||
|
|
||||||
// To be called often to test whether to cancel the operation.
|
// To be called often to test whether to cancel the operation.
|
||||||
typedef std::function<void ()> ThrowOnCancelFn;
|
typedef std::function<void ()> ThrowOnCancelFn;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static AsyncStatus winrt_async_await(const Microsoft::WRL::ComPtr<T> &asyncAction, ThrowOnCancelFn throw_on_cancel, int blocking_tick_ms = 100)
|
static AsyncStatus winrt_async_await(const Microsoft::WRL::ComPtr<T> &asyncAction, ThrowOnCancelFn throw_on_cancel, int blocking_tick_ms = 100)
|
||||||
{
|
{
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncInfo> asyncInfo;
|
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncInfo> asyncInfo;
|
||||||
asyncAction.As(&asyncInfo);
|
asyncAction.As(&asyncInfo);
|
||||||
AsyncStatus status;
|
AsyncStatus status;
|
||||||
// Ugly blocking loop until the RepairAsync call finishes.
|
// Ugly blocking loop until the RepairAsync call finishes.
|
||||||
//FIXME replace with a callback.
|
//FIXME replace with a callback.
|
||||||
// https://social.msdn.microsoft.com/Forums/en-US/a5038fb4-b7b7-4504-969d-c102faa389fb/trying-to-block-an-async-operation-and-wait-for-a-particular-time?forum=vclanguage
|
// https://social.msdn.microsoft.com/Forums/en-US/a5038fb4-b7b7-4504-969d-c102faa389fb/trying-to-block-an-async-operation-and-wait-for-a-particular-time?forum=vclanguage
|
||||||
for (;;) {
|
for (;;) {
|
||||||
asyncInfo->get_Status(&status);
|
asyncInfo->get_Status(&status);
|
||||||
if (status != AsyncStatus::Started)
|
if (status != AsyncStatus::Started)
|
||||||
return status;
|
return status;
|
||||||
throw_on_cancel();
|
throw_on_cancel();
|
||||||
::Sleep(blocking_tick_ms);
|
::Sleep(blocking_tick_ms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT winrt_open_file_stream(
|
static HRESULT winrt_open_file_stream(
|
||||||
const std::wstring &path,
|
const std::wstring &path,
|
||||||
ABI::Windows::Storage::FileAccessMode mode,
|
ABI::Windows::Storage::FileAccessMode mode,
|
||||||
ABI::Windows::Storage::Streams::IRandomAccessStream **fileStream,
|
ABI::Windows::Storage::Streams::IRandomAccessStream **fileStream,
|
||||||
ThrowOnCancelFn throw_on_cancel)
|
ThrowOnCancelFn throw_on_cancel)
|
||||||
{
|
{
|
||||||
// Get the file factory.
|
// Get the file factory.
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Storage::IStorageFileStatics> fileFactory;
|
Microsoft::WRL::ComPtr<ABI::Windows::Storage::IStorageFileStatics> fileFactory;
|
||||||
HRESULT hr = winrt_get_activation_factory(L"Windows.Storage.StorageFile", fileFactory.GetAddressOf());
|
HRESULT hr = winrt_get_activation_factory(L"Windows.Storage.StorageFile", fileFactory.GetAddressOf());
|
||||||
if (FAILED(hr)) return hr;
|
if (FAILED(hr)) return hr;
|
||||||
|
|
||||||
// Open the file asynchronously.
|
// Open the file asynchronously.
|
||||||
HSTRING hstr_path;
|
HSTRING hstr_path;
|
||||||
hr = (*s_WindowsCreateString)(path.c_str(), path.size(), &hstr_path);
|
hr = (*s_WindowsCreateString)(path.c_str(), path.size(), &hstr_path);
|
||||||
if (FAILED(hr)) return hr;
|
if (FAILED(hr)) return hr;
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::Storage::StorageFile*>> fileOpenAsync;
|
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::Storage::StorageFile*>> fileOpenAsync;
|
||||||
hr = fileFactory->GetFileFromPathAsync(hstr_path, fileOpenAsync.GetAddressOf());
|
hr = fileFactory->GetFileFromPathAsync(hstr_path, fileOpenAsync.GetAddressOf());
|
||||||
if (FAILED(hr)) return hr;
|
if (FAILED(hr)) return hr;
|
||||||
(*s_WindowsDeleteString)(hstr_path);
|
(*s_WindowsDeleteString)(hstr_path);
|
||||||
|
|
||||||
// Wait until the file gets open, get the actual file.
|
// Wait until the file gets open, get the actual file.
|
||||||
AsyncStatus status = winrt_async_await(fileOpenAsync, throw_on_cancel);
|
AsyncStatus status = winrt_async_await(fileOpenAsync, throw_on_cancel);
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Storage::IStorageFile> storageFile;
|
Microsoft::WRL::ComPtr<ABI::Windows::Storage::IStorageFile> storageFile;
|
||||||
if (status == AsyncStatus::Completed) {
|
if (status == AsyncStatus::Completed) {
|
||||||
hr = fileOpenAsync->GetResults(storageFile.GetAddressOf());
|
hr = fileOpenAsync->GetResults(storageFile.GetAddressOf());
|
||||||
} else {
|
} else {
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncInfo> asyncInfo;
|
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncInfo> asyncInfo;
|
||||||
hr = fileOpenAsync.As(&asyncInfo);
|
hr = fileOpenAsync.As(&asyncInfo);
|
||||||
if (FAILED(hr)) return hr;
|
if (FAILED(hr)) return hr;
|
||||||
HRESULT err;
|
HRESULT err;
|
||||||
hr = asyncInfo->get_ErrorCode(&err);
|
hr = asyncInfo->get_ErrorCode(&err);
|
||||||
return FAILED(hr) ? hr : err;
|
return FAILED(hr) ? hr : err;
|
||||||
}
|
}
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::Storage::Streams::IRandomAccessStream*>> fileStreamAsync;
|
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::Storage::Streams::IRandomAccessStream*>> fileStreamAsync;
|
||||||
hr = storageFile->OpenAsync(mode, fileStreamAsync.GetAddressOf());
|
hr = storageFile->OpenAsync(mode, fileStreamAsync.GetAddressOf());
|
||||||
if (FAILED(hr)) return hr;
|
if (FAILED(hr)) return hr;
|
||||||
|
|
||||||
status = winrt_async_await(fileStreamAsync, throw_on_cancel);
|
status = winrt_async_await(fileStreamAsync, throw_on_cancel);
|
||||||
if (status == AsyncStatus::Completed) {
|
if (status == AsyncStatus::Completed) {
|
||||||
hr = fileStreamAsync->GetResults(fileStream);
|
hr = fileStreamAsync->GetResults(fileStream);
|
||||||
} else {
|
} else {
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncInfo> asyncInfo;
|
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncInfo> asyncInfo;
|
||||||
hr = fileStreamAsync.As(&asyncInfo);
|
hr = fileStreamAsync.As(&asyncInfo);
|
||||||
if (FAILED(hr)) return hr;
|
if (FAILED(hr)) return hr;
|
||||||
HRESULT err;
|
HRESULT err;
|
||||||
hr = asyncInfo->get_ErrorCode(&err);
|
hr = asyncInfo->get_ErrorCode(&err);
|
||||||
if (!FAILED(hr))
|
if (!FAILED(hr))
|
||||||
hr = err;
|
hr = err;
|
||||||
}
|
}
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_windows10()
|
bool is_windows10()
|
||||||
{
|
{
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
LONG lRes = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey);
|
LONG lRes = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey);
|
||||||
if (lRes == ERROR_SUCCESS) {
|
if (lRes == ERROR_SUCCESS) {
|
||||||
WCHAR szBuffer[512];
|
WCHAR szBuffer[512];
|
||||||
DWORD dwBufferSize = sizeof(szBuffer);
|
DWORD dwBufferSize = sizeof(szBuffer);
|
||||||
lRes = RegQueryValueExW(hKey, L"ProductName", 0, nullptr, (LPBYTE)szBuffer, &dwBufferSize);
|
lRes = RegQueryValueExW(hKey, L"ProductName", 0, nullptr, (LPBYTE)szBuffer, &dwBufferSize);
|
||||||
if (lRes == ERROR_SUCCESS)
|
if (lRes == ERROR_SUCCESS)
|
||||||
return wcsncmp(szBuffer, L"Windows 10", 10) == 0;
|
return wcsncmp(szBuffer, L"Windows 10", 10) == 0;
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Progress function, to be called regularly to update the progress.
|
// Progress function, to be called regularly to update the progress.
|
||||||
typedef std::function<void (const char * /* message */, unsigned /* progress */)> ProgressFn;
|
typedef std::function<void (const char * /* message */, unsigned /* progress */)> ProgressFn;
|
||||||
|
|
||||||
void fix_model_by_win10_sdk(const std::string &path_src, const std::string &path_dst, ProgressFn on_progress, ThrowOnCancelFn throw_on_cancel)
|
void fix_model_by_win10_sdk(const std::string &path_src, const std::string &path_dst, ProgressFn on_progress, ThrowOnCancelFn throw_on_cancel)
|
||||||
{
|
{
|
||||||
if (! is_windows10())
|
if (! is_windows10())
|
||||||
throw Slic3r::RuntimeError("fix_model_by_win10_sdk called on non Windows 10 system");
|
throw Slic3r::RuntimeError("fix_model_by_win10_sdk called on non Windows 10 system");
|
||||||
|
|
||||||
if (! winrt_load_runtime_object_library())
|
if (! winrt_load_runtime_object_library())
|
||||||
throw Slic3r::RuntimeError("Failed to initialize the WinRT library.");
|
throw Slic3r::RuntimeError("Failed to initialize the WinRT library.");
|
||||||
|
|
||||||
HRESULT hr = (*s_RoInitialize)(RO_INIT_MULTITHREADED);
|
HRESULT hr = (*s_RoInitialize)(RO_INIT_MULTITHREADED);
|
||||||
{
|
{
|
||||||
on_progress(L("Exporting source model"), 20);
|
on_progress(L("Exporting source model"), 20);
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IRandomAccessStream> fileStream;
|
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IRandomAccessStream> fileStream;
|
||||||
hr = winrt_open_file_stream(boost::nowide::widen(path_src), ABI::Windows::Storage::FileAccessMode::FileAccessMode_Read, fileStream.GetAddressOf(), throw_on_cancel);
|
hr = winrt_open_file_stream(boost::nowide::widen(path_src), ABI::Windows::Storage::FileAccessMode::FileAccessMode_Read, fileStream.GetAddressOf(), throw_on_cancel);
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Printing3D::IPrinting3D3MFPackage> printing3d3mfpackage;
|
Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Printing3D::IPrinting3D3MFPackage> printing3d3mfpackage;
|
||||||
hr = winrt_activate_instance(L"Windows.Graphics.Printing3D.Printing3D3MFPackage", printing3d3mfpackage.GetAddressOf());
|
hr = winrt_activate_instance(L"Windows.Graphics.Printing3D.Printing3D3MFPackage", printing3d3mfpackage.GetAddressOf());
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::Graphics::Printing3D::Printing3DModel*>> modelAsync;
|
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::Graphics::Printing3D::Printing3DModel*>> modelAsync;
|
||||||
hr = printing3d3mfpackage->LoadModelFromPackageAsync(fileStream.Get(), modelAsync.GetAddressOf());
|
hr = printing3d3mfpackage->LoadModelFromPackageAsync(fileStream.Get(), modelAsync.GetAddressOf());
|
||||||
|
|
||||||
AsyncStatus status = winrt_async_await(modelAsync, throw_on_cancel);
|
AsyncStatus status = winrt_async_await(modelAsync, throw_on_cancel);
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Printing3D::IPrinting3DModel> model;
|
Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Printing3D::IPrinting3DModel> model;
|
||||||
if (status == AsyncStatus::Completed)
|
if (status == AsyncStatus::Completed)
|
||||||
hr = modelAsync->GetResults(model.GetAddressOf());
|
hr = modelAsync->GetResults(model.GetAddressOf());
|
||||||
else
|
else
|
||||||
throw Slic3r::RuntimeError(L("Failed loading the input model."));
|
throw Slic3r::RuntimeError(L("Failed loading the input model."));
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IVector<ABI::Windows::Graphics::Printing3D::Printing3DMesh*>> meshes;
|
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IVector<ABI::Windows::Graphics::Printing3D::Printing3DMesh*>> meshes;
|
||||||
hr = model->get_Meshes(meshes.GetAddressOf());
|
hr = model->get_Meshes(meshes.GetAddressOf());
|
||||||
unsigned num_meshes = 0;
|
unsigned num_meshes = 0;
|
||||||
hr = meshes->get_Size(&num_meshes);
|
hr = meshes->get_Size(&num_meshes);
|
||||||
|
|
||||||
on_progress(L("Repairing model by the Netfabb service"), 40);
|
on_progress(L("Repairing model by the Netfabb service"), 40);
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncAction> repairAsync;
|
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncAction> repairAsync;
|
||||||
hr = model->RepairAsync(repairAsync.GetAddressOf());
|
hr = model->RepairAsync(repairAsync.GetAddressOf());
|
||||||
status = winrt_async_await(repairAsync, throw_on_cancel);
|
status = winrt_async_await(repairAsync, throw_on_cancel);
|
||||||
if (status != AsyncStatus::Completed)
|
if (status != AsyncStatus::Completed)
|
||||||
throw Slic3r::RuntimeError(L("Mesh repair failed."));
|
throw Slic3r::RuntimeError(L("Mesh repair failed."));
|
||||||
repairAsync->GetResults();
|
repairAsync->GetResults();
|
||||||
|
|
||||||
on_progress(L("Loading repaired model"), 60);
|
on_progress(L("Loading repaired model"), 60);
|
||||||
|
|
||||||
// Verify the number of meshes returned after the repair action.
|
// Verify the number of meshes returned after the repair action.
|
||||||
meshes.Reset();
|
meshes.Reset();
|
||||||
hr = model->get_Meshes(meshes.GetAddressOf());
|
hr = model->get_Meshes(meshes.GetAddressOf());
|
||||||
hr = meshes->get_Size(&num_meshes);
|
hr = meshes->get_Size(&num_meshes);
|
||||||
|
|
||||||
// Save model to this class' Printing3D3MFPackage.
|
// Save model to this class' Printing3D3MFPackage.
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncAction> saveToPackageAsync;
|
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncAction> saveToPackageAsync;
|
||||||
hr = printing3d3mfpackage->SaveModelToPackageAsync(model.Get(), saveToPackageAsync.GetAddressOf());
|
hr = printing3d3mfpackage->SaveModelToPackageAsync(model.Get(), saveToPackageAsync.GetAddressOf());
|
||||||
status = winrt_async_await(saveToPackageAsync, throw_on_cancel);
|
status = winrt_async_await(saveToPackageAsync, throw_on_cancel);
|
||||||
if (status != AsyncStatus::Completed)
|
if (status != AsyncStatus::Completed)
|
||||||
throw Slic3r::RuntimeError(L("Saving mesh into the 3MF container failed."));
|
throw Slic3r::RuntimeError(L("Saving mesh into the 3MF container failed."));
|
||||||
hr = saveToPackageAsync->GetResults();
|
hr = saveToPackageAsync->GetResults();
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::Storage::Streams::IRandomAccessStream*>> generatorStreamAsync;
|
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::Storage::Streams::IRandomAccessStream*>> generatorStreamAsync;
|
||||||
hr = printing3d3mfpackage->SaveAsync(generatorStreamAsync.GetAddressOf());
|
hr = printing3d3mfpackage->SaveAsync(generatorStreamAsync.GetAddressOf());
|
||||||
status = winrt_async_await(generatorStreamAsync, throw_on_cancel);
|
status = winrt_async_await(generatorStreamAsync, throw_on_cancel);
|
||||||
if (status != AsyncStatus::Completed)
|
if (status != AsyncStatus::Completed)
|
||||||
throw Slic3r::RuntimeError(L("Saving mesh into the 3MF container failed."));
|
throw Slic3r::RuntimeError(L("Saving mesh into the 3MF container failed."));
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IRandomAccessStream> generatorStream;
|
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IRandomAccessStream> generatorStream;
|
||||||
hr = generatorStreamAsync->GetResults(generatorStream.GetAddressOf());
|
hr = generatorStreamAsync->GetResults(generatorStream.GetAddressOf());
|
||||||
|
|
||||||
// Go to the beginning of the stream.
|
// Go to the beginning of the stream.
|
||||||
generatorStream->Seek(0);
|
generatorStream->Seek(0);
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IInputStream> inputStream;
|
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IInputStream> inputStream;
|
||||||
hr = generatorStream.As(&inputStream);
|
hr = generatorStream.As(&inputStream);
|
||||||
|
|
||||||
// Get the buffer factory.
|
// Get the buffer factory.
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBufferFactory> bufferFactory;
|
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBufferFactory> bufferFactory;
|
||||||
hr = winrt_get_activation_factory(L"Windows.Storage.Streams.Buffer", bufferFactory.GetAddressOf());
|
hr = winrt_get_activation_factory(L"Windows.Storage.Streams.Buffer", bufferFactory.GetAddressOf());
|
||||||
|
|
||||||
// Open the destination file.
|
// Open the destination file.
|
||||||
FILE *fout = boost::nowide::fopen(path_dst.c_str(), "wb");
|
FILE *fout = boost::nowide::fopen(path_dst.c_str(), "wb");
|
||||||
try {
|
try {
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBuffer> buffer;
|
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBuffer> buffer;
|
||||||
byte *buffer_ptr;
|
byte *buffer_ptr;
|
||||||
bufferFactory->Create(65536 * 2048, buffer.GetAddressOf());
|
bufferFactory->Create(65536 * 2048, buffer.GetAddressOf());
|
||||||
{
|
{
|
||||||
Microsoft::WRL::ComPtr<Windows::Storage::Streams::IBufferByteAccess> bufferByteAccess;
|
Microsoft::WRL::ComPtr<Windows::Storage::Streams::IBufferByteAccess> bufferByteAccess;
|
||||||
buffer.As(&bufferByteAccess);
|
buffer.As(&bufferByteAccess);
|
||||||
hr = bufferByteAccess->Buffer(&buffer_ptr);
|
hr = bufferByteAccess->Buffer(&buffer_ptr);
|
||||||
}
|
}
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
hr = buffer->get_Length(&length);
|
hr = buffer->get_Length(&length);
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperationWithProgress<ABI::Windows::Storage::Streams::IBuffer*, UINT32>> asyncRead;
|
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperationWithProgress<ABI::Windows::Storage::Streams::IBuffer*, UINT32>> asyncRead;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
hr = inputStream->ReadAsync(buffer.Get(), 65536 * 2048, ABI::Windows::Storage::Streams::InputStreamOptions_ReadAhead, asyncRead.GetAddressOf());
|
hr = inputStream->ReadAsync(buffer.Get(), 65536 * 2048, ABI::Windows::Storage::Streams::InputStreamOptions_ReadAhead, asyncRead.GetAddressOf());
|
||||||
status = winrt_async_await(asyncRead, throw_on_cancel);
|
status = winrt_async_await(asyncRead, throw_on_cancel);
|
||||||
if (status != AsyncStatus::Completed)
|
if (status != AsyncStatus::Completed)
|
||||||
throw Slic3r::RuntimeError(L("Saving mesh into the 3MF container failed."));
|
throw Slic3r::RuntimeError(L("Saving mesh into the 3MF container failed."));
|
||||||
hr = buffer->get_Length(&length);
|
hr = buffer->get_Length(&length);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
break;
|
break;
|
||||||
fwrite(buffer_ptr, length, 1, fout);
|
fwrite(buffer_ptr, length, 1, fout);
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
// Here all the COM objects will be released through the ComPtr destructors.
|
// Here all the COM objects will be released through the ComPtr destructors.
|
||||||
}
|
}
|
||||||
(*s_RoUninitialize)();
|
(*s_RoUninitialize)();
|
||||||
}
|
}
|
||||||
|
|
||||||
class RepairCanceledException : public std::exception {
|
class RepairCanceledException : public std::exception {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() { return "Model repair has been canceled"; }
|
const char* what() const throw() { return "Model repair has been canceled"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// returt FALSE, if fixing was canceled
|
// returt FALSE, if fixing was canceled
|
||||||
// fix_result is empty, if fixing finished successfully
|
// fix_result is empty, if fixing finished successfully
|
||||||
// fix_result containes a message if fixing failed
|
// fix_result containes a message if fixing failed
|
||||||
bool fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx, wxProgressDialog& progress_dialog, const wxString& msg_header, std::string& fix_result)
|
bool fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx, wxProgressDialog& progress_dialog, const wxString& msg_header, std::string& fix_result)
|
||||||
{
|
{
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
std::condition_variable condition;
|
std::condition_variable condition;
|
||||||
std::unique_lock<std::mutex> lock(mutex);
|
std::unique_lock<std::mutex> lock(mutex);
|
||||||
struct Progress {
|
struct Progress {
|
||||||
std::string message;
|
std::string message;
|
||||||
int percent = 0;
|
int percent = 0;
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
} progress;
|
} progress;
|
||||||
std::atomic<bool> canceled = false;
|
std::atomic<bool> canceled = false;
|
||||||
std::atomic<bool> finished = false;
|
std::atomic<bool> finished = false;
|
||||||
|
|
||||||
std::vector<ModelVolume*> volumes;
|
std::vector<ModelVolume*> volumes;
|
||||||
if (volume_idx == -1)
|
if (volume_idx == -1)
|
||||||
volumes = model_object.volumes;
|
volumes = model_object.volumes;
|
||||||
else
|
else
|
||||||
volumes.emplace_back(model_object.volumes[volume_idx]);
|
volumes.emplace_back(model_object.volumes[volume_idx]);
|
||||||
|
|
||||||
// Executing the calculation in a background thread, so that the COM context could be created with its own threading model.
|
// 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).
|
// (It seems like wxWidgets initialize the COM contex as single threaded and we need a multi-threaded context).
|
||||||
bool success = false;
|
bool success = false;
|
||||||
size_t ivolume = 0;
|
size_t ivolume = 0;
|
||||||
auto on_progress = [&mutex, &condition, &ivolume, &volumes, &progress](const char *msg, unsigned prcnt) {
|
auto on_progress = [&mutex, &condition, &ivolume, &volumes, &progress](const char *msg, unsigned prcnt) {
|
||||||
std::lock_guard<std::mutex> lk(mutex);
|
std::lock_guard<std::mutex> lk(mutex);
|
||||||
progress.message = msg;
|
progress.message = msg;
|
||||||
progress.percent = (int)floor((float(prcnt) + float(ivolume) * 100.f) / float(volumes.size()));
|
progress.percent = (int)floor((float(prcnt) + float(ivolume) * 100.f) / float(volumes.size()));
|
||||||
progress.updated = true;
|
progress.updated = true;
|
||||||
condition.notify_all();
|
condition.notify_all();
|
||||||
};
|
};
|
||||||
auto worker_thread = boost::thread([&model_object, &volumes, &ivolume, on_progress, &success, &canceled, &finished]() {
|
auto worker_thread = boost::thread([&model_object, &volumes, &ivolume, on_progress, &success, &canceled, &finished]() {
|
||||||
try {
|
try {
|
||||||
std::vector<TriangleMesh> meshes_repaired;
|
std::vector<TriangleMesh> meshes_repaired;
|
||||||
meshes_repaired.reserve(volumes.size());
|
meshes_repaired.reserve(volumes.size());
|
||||||
for (; ivolume < volumes.size(); ++ ivolume) {
|
for (; ivolume < volumes.size(); ++ ivolume) {
|
||||||
on_progress(L("Exporting source model"), 0);
|
on_progress(L("Exporting source model"), 0);
|
||||||
boost::filesystem::path path_src = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
|
boost::filesystem::path path_src = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
|
||||||
path_src += ".3mf";
|
path_src += ".3mf";
|
||||||
Model model;
|
Model model;
|
||||||
ModelObject *mo = model.add_object();
|
ModelObject *mo = model.add_object();
|
||||||
mo->add_volume(*volumes[ivolume]);
|
mo->add_volume(*volumes[ivolume]);
|
||||||
|
|
||||||
// We are about to save a 3mf, fix it by netfabb and load the fixed 3mf back.
|
// We are about to save a 3mf, fix it by netfabb and load the fixed 3mf back.
|
||||||
// store_3mf currently bakes the volume transformation into the mesh itself.
|
// store_3mf currently bakes the volume transformation into the mesh itself.
|
||||||
// If we then loaded the repaired 3mf and pushed the mesh into the original ModelVolume
|
// If we then loaded the repaired 3mf and pushed the mesh into the original ModelVolume
|
||||||
// (which remembers the matrix the whole time), the transformation would be used twice.
|
// (which remembers the matrix the whole time), the transformation would be used twice.
|
||||||
// We will therefore set the volume transform on the dummy ModelVolume to identity.
|
// We will therefore set the volume transform on the dummy ModelVolume to identity.
|
||||||
mo->volumes.back()->set_transformation(Geometry::Transformation());
|
mo->volumes.back()->set_transformation(Geometry::Transformation());
|
||||||
|
|
||||||
mo->add_instance();
|
mo->add_instance();
|
||||||
if (!Slic3r::store_3mf(path_src.string().c_str(), &model, nullptr, false, nullptr, false)) {
|
if (!Slic3r::store_3mf(path_src.string().c_str(), &model, nullptr, false, nullptr, false)) {
|
||||||
boost::filesystem::remove(path_src);
|
boost::filesystem::remove(path_src);
|
||||||
throw Slic3r::RuntimeError(L("Export of a temporary 3mf file failed"));
|
throw Slic3r::RuntimeError(L("Export of a temporary 3mf file failed"));
|
||||||
}
|
}
|
||||||
model.clear_objects();
|
model.clear_objects();
|
||||||
model.clear_materials();
|
model.clear_materials();
|
||||||
boost::filesystem::path path_dst = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
|
boost::filesystem::path path_dst = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
|
||||||
path_dst += ".3mf";
|
path_dst += ".3mf";
|
||||||
fix_model_by_win10_sdk(path_src.string().c_str(), path_dst.string(), on_progress,
|
fix_model_by_win10_sdk(path_src.string().c_str(), path_dst.string(), on_progress,
|
||||||
[&canceled]() { if (canceled) throw RepairCanceledException(); });
|
[&canceled]() { if (canceled) throw RepairCanceledException(); });
|
||||||
boost::filesystem::remove(path_src);
|
boost::filesystem::remove(path_src);
|
||||||
// PresetBundle bundle;
|
// PresetBundle bundle;
|
||||||
on_progress(L("Loading repaired model"), 80);
|
on_progress(L("Loading repaired model"), 80);
|
||||||
DynamicPrintConfig config;
|
DynamicPrintConfig config;
|
||||||
ConfigSubstitutionContext config_substitutions{ ForwardCompatibilitySubstitutionRule::EnableSilent };
|
ConfigSubstitutionContext config_substitutions{ ForwardCompatibilitySubstitutionRule::EnableSilent };
|
||||||
bool loaded = Slic3r::load_3mf(path_dst.string().c_str(), config, config_substitutions, &model, false);
|
bool loaded = Slic3r::load_3mf(path_dst.string().c_str(), config, config_substitutions, &model, false);
|
||||||
boost::filesystem::remove(path_dst);
|
boost::filesystem::remove(path_dst);
|
||||||
if (! loaded)
|
if (! loaded)
|
||||||
throw Slic3r::RuntimeError(L("Import of the repaired 3mf file failed"));
|
throw Slic3r::RuntimeError(L("Import of the repaired 3mf file failed"));
|
||||||
if (model.objects.size() == 0)
|
if (model.objects.size() == 0)
|
||||||
throw Slic3r::RuntimeError(L("Repaired 3MF file does not contain any object"));
|
throw Slic3r::RuntimeError(L("Repaired 3MF file does not contain any object"));
|
||||||
if (model.objects.size() > 1)
|
if (model.objects.size() > 1)
|
||||||
throw Slic3r::RuntimeError(L("Repaired 3MF file contains more than one object"));
|
throw Slic3r::RuntimeError(L("Repaired 3MF file contains more than one object"));
|
||||||
if (model.objects.front()->volumes.size() == 0)
|
if (model.objects.front()->volumes.size() == 0)
|
||||||
throw Slic3r::RuntimeError(L("Repaired 3MF file does not contain any volume"));
|
throw Slic3r::RuntimeError(L("Repaired 3MF file does not contain any volume"));
|
||||||
if (model.objects.front()->volumes.size() > 1)
|
if (model.objects.front()->volumes.size() > 1)
|
||||||
throw Slic3r::RuntimeError(L("Repaired 3MF file contains more than one volume"));
|
throw Slic3r::RuntimeError(L("Repaired 3MF file contains more than one volume"));
|
||||||
meshes_repaired.emplace_back(std::move(model.objects.front()->volumes.front()->mesh()));
|
meshes_repaired.emplace_back(std::move(model.objects.front()->volumes.front()->mesh()));
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < volumes.size(); ++ i) {
|
for (size_t i = 0; i < volumes.size(); ++ i) {
|
||||||
volumes[i]->set_mesh(std::move(meshes_repaired[i]));
|
volumes[i]->set_mesh(std::move(meshes_repaired[i]));
|
||||||
volumes[i]->calculate_convex_hull();
|
volumes[i]->calculate_convex_hull();
|
||||||
volumes[i]->set_new_unique_id();
|
volumes[i]->set_new_unique_id();
|
||||||
}
|
}
|
||||||
model_object.invalidate_bounding_box();
|
model_object.invalidate_bounding_box();
|
||||||
-- ivolume;
|
-- ivolume;
|
||||||
on_progress(L("Model repair finished"), 100);
|
on_progress(L("Model repair finished"), 100);
|
||||||
success = true;
|
success = true;
|
||||||
finished = true;
|
finished = true;
|
||||||
} catch (RepairCanceledException & /* ex */) {
|
} catch (RepairCanceledException & /* ex */) {
|
||||||
canceled = true;
|
canceled = true;
|
||||||
finished = true;
|
finished = true;
|
||||||
on_progress(L("Model repair canceled"), 100);
|
on_progress(L("Model repair canceled"), 100);
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
success = false;
|
success = false;
|
||||||
finished = true;
|
finished = true;
|
||||||
on_progress(ex.what(), 100);
|
on_progress(ex.what(), 100);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
while (! finished) {
|
while (! finished) {
|
||||||
condition.wait_for(lock, std::chrono::milliseconds(250), [&progress]{ return progress.updated; });
|
condition.wait_for(lock, std::chrono::milliseconds(250), [&progress]{ return progress.updated; });
|
||||||
// decrease progress.percent value to avoid closing of the progress dialog
|
// decrease progress.percent value to avoid closing of the progress dialog
|
||||||
if (!progress_dialog.Update(progress.percent-1, msg_header + _(progress.message)))
|
if (!progress_dialog.Update(progress.percent-1, msg_header + _(progress.message)))
|
||||||
canceled = true;
|
canceled = true;
|
||||||
else
|
else
|
||||||
progress_dialog.Fit();
|
progress_dialog.Fit();
|
||||||
progress.updated = false;
|
progress.updated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canceled) {
|
if (canceled) {
|
||||||
// Nothing to show.
|
// Nothing to show.
|
||||||
} else if (success) {
|
} else if (success) {
|
||||||
fix_result = "";
|
fix_result = "";
|
||||||
} else {
|
} else {
|
||||||
fix_result = progress.message;
|
fix_result = progress.message;
|
||||||
}
|
}
|
||||||
worker_thread.join();
|
worker_thread.join();
|
||||||
return !canceled;
|
return !canceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Slic3r
|
} // namespace Slic3r
|
||||||
|
|
||||||
#endif /* HAS_WIN10SDK */
|
#endif /* HAS_WIN10SDK */
|
||||||
|
@ -181,7 +181,7 @@ Http::priv::~priv()
|
|||||||
|
|
||||||
bool Http::priv::ca_file_supported(::CURL *curl)
|
bool Http::priv::ca_file_supported(::CURL *curl)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#if defined(_WIN32) || defined(__APPLE__)
|
||||||
bool res = false;
|
bool res = false;
|
||||||
#else
|
#else
|
||||||
bool res = true;
|
bool res = true;
|
||||||
@ -194,6 +194,7 @@ bool Http::priv::ca_file_supported(::CURL *curl)
|
|||||||
if (::curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &tls) == CURLE_OK) {
|
if (::curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &tls) == CURLE_OK) {
|
||||||
if (tls->backend == CURLSSLBACKEND_SCHANNEL || tls->backend == CURLSSLBACKEND_DARWINSSL) {
|
if (tls->backend == CURLSSLBACKEND_SCHANNEL || tls->backend == CURLSSLBACKEND_DARWINSSL) {
|
||||||
// With Windows and OS X native SSL support, cert files cannot be set
|
// With Windows and OS X native SSL support, cert files cannot be set
|
||||||
|
// DK: OSX is now not building CURL and links system one, thus we do not know which backend is installed. Still, false will be returned since the ifdef at the begining if this function.
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,18 +54,9 @@ TEST_CASE("astar algorithm test over 3D point grid", "[AStar]") {
|
|||||||
|
|
||||||
auto pgrid = point_grid(ex_seq, vol, {0.1f, 0.1f, 0.1f});
|
auto pgrid = point_grid(ex_seq, vol, {0.1f, 0.1f, 0.1f});
|
||||||
|
|
||||||
size_t target = pgrid.point_count() - 1;
|
|
||||||
|
|
||||||
std::cout << "Tracing route to " << pgrid.get_coord(target).transpose() << std::endl;
|
|
||||||
PointGridTracer pgt{pgrid, pgrid.point_count() - 1};
|
PointGridTracer pgt{pgrid, pgrid.point_count() - 1};
|
||||||
std::vector<size_t> out;
|
std::vector<size_t> out;
|
||||||
bool found = astar::search_route(pgt, size_t(0), std::back_inserter(out));
|
bool found = astar::search_route(pgt, size_t(0), std::back_inserter(out));
|
||||||
|
|
||||||
std::cout << "Route taken: ";
|
|
||||||
for (size_t i : out) {
|
|
||||||
std::cout << "(" << pgrid.get_coord(i).transpose() << ") ";
|
|
||||||
}
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
REQUIRE(found);
|
REQUIRE(found);
|
||||||
}
|
}
|
||||||
|
@ -325,9 +325,9 @@ static void recreate_object_from_rasters(const std::string &objname, float lh) {
|
|||||||
double disp_w = 120.96;
|
double disp_w = 120.96;
|
||||||
double disp_h = 68.04;
|
double disp_h = 68.04;
|
||||||
|
|
||||||
#ifndef NDEBUG
|
//#ifndef NDEBUG
|
||||||
size_t cntr = 0;
|
// size_t cntr = 0;
|
||||||
#endif
|
//#endif
|
||||||
for (ExPolygons &layer : layers) {
|
for (ExPolygons &layer : layers) {
|
||||||
auto rst = create_raster(res, disp_w, disp_h);
|
auto rst = create_raster(res, disp_w, disp_h);
|
||||||
|
|
||||||
@ -335,11 +335,11 @@ static void recreate_object_from_rasters(const std::string &objname, float lh) {
|
|||||||
rst.draw(island);
|
rst.draw(island);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
//#ifndef NDEBUG
|
||||||
std::fstream out(objname + std::to_string(cntr) + ".png", std::ios::out);
|
// std::fstream out(objname + std::to_string(cntr) + ".png", std::ios::out);
|
||||||
out << rst.encode(sla::PNGRasterEncoder{});
|
// out << rst.encode(sla::PNGRasterEncoder{});
|
||||||
out.close();
|
// out.close();
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
ExPolygons layer_ = sla::raster_to_polygons(rst);
|
ExPolygons layer_ = sla::raster_to_polygons(rst);
|
||||||
// float delta = scaled(std::min(rst.pixel_dimensions().h_mm,
|
// float delta = scaled(std::min(rst.pixel_dimensions().h_mm,
|
||||||
@ -347,19 +347,19 @@ static void recreate_object_from_rasters(const std::string &objname, float lh) {
|
|||||||
|
|
||||||
// layer_ = expolygons_simplify(layer_, delta);
|
// layer_ = expolygons_simplify(layer_, delta);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
//#ifndef NDEBUG
|
||||||
SVG svg(objname + std::to_string(cntr) + ".svg", BoundingBox(Point{0, 0}, Point{scaled(disp_w), scaled(disp_h)}));
|
// SVG svg(objname + std::to_string(cntr) + ".svg", BoundingBox(Point{0, 0}, Point{scaled(disp_w), scaled(disp_h)}));
|
||||||
svg.draw(layer_);
|
// svg.draw(layer_);
|
||||||
svg.draw(layer, "green");
|
// svg.draw(layer, "green");
|
||||||
svg.Close();
|
// svg.Close();
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
double layera = 0., layera_ = 0.;
|
double layera = 0., layera_ = 0.;
|
||||||
for (auto &p : layer) layera += p.area();
|
for (auto &p : layer) layera += p.area();
|
||||||
for (auto &p : layer_) layera_ += p.area();
|
for (auto &p : layer_) layera_ += p.area();
|
||||||
#ifndef NDEBUG
|
//#ifndef NDEBUG
|
||||||
std::cout << cntr++ << std::endl;
|
// std::cout << cntr++ << std::endl;
|
||||||
#endif
|
//#endif
|
||||||
double diff = std::abs(layera_ - layera);
|
double diff = std::abs(layera_ - layera);
|
||||||
REQUIRE((diff <= 0.1 * layera || diff < scaled<double>(1.) * scaled<double>(1.)));
|
REQUIRE((diff <= 0.1 * layera || diff < scaled<double>(1.) * scaled<double>(1.)));
|
||||||
|
|
||||||
|
@ -346,25 +346,36 @@ TEST_CASE("Mutable priority queue - first pop", "[MutableSkipHeapPriorityQueue]"
|
|||||||
size_t id;
|
size_t id;
|
||||||
float val;
|
float val;
|
||||||
};
|
};
|
||||||
size_t count = 50000;
|
static constexpr const size_t count = 50000;
|
||||||
std::vector<size_t> idxs(count, {0});
|
std::vector<size_t> idxs(count, {0});
|
||||||
std::vector<bool> dels(count, false);
|
|
||||||
auto q = make_miniheap_mutable_priority_queue<MyValue, 16, true>(
|
auto q = make_miniheap_mutable_priority_queue<MyValue, 16, true>(
|
||||||
[&](MyValue &v, size_t idx) {
|
[&idxs](MyValue &v, size_t idx) { idxs[v.id] = idx; },
|
||||||
idxs[v.id] = idx;
|
|
||||||
},
|
|
||||||
[](MyValue &l, MyValue &r) { return l.val < r.val; });
|
[](MyValue &l, MyValue &r) { return l.val < r.val; });
|
||||||
q.reserve(count);
|
using QueueType = decltype(q);
|
||||||
for (size_t id = 0; id < count; id++) {
|
THEN("Skip queue has 0th element unused, 1st element is the top of the queue.") {
|
||||||
MyValue mv{ id, rand() / 100.f };
|
CHECK(QueueType::address::is_padding(0));
|
||||||
q.push(mv);
|
CHECK(!QueueType::address::is_padding(1));
|
||||||
|
}
|
||||||
|
q.reserve(count);
|
||||||
|
for (size_t id = 0; id < count; ++ id)
|
||||||
|
q.push({ id, rand() / 100.f });
|
||||||
|
MyValue v = q.top(); // copy
|
||||||
|
THEN("Element at the top of the queue has a valid ID.") {
|
||||||
|
CHECK(v.id >= 0);
|
||||||
|
CHECK(v.id < count);
|
||||||
|
}
|
||||||
|
THEN("Element at the top of the queue has its position stored in idxs.") {
|
||||||
|
CHECK(idxs[v.id] == 1);
|
||||||
}
|
}
|
||||||
MyValue it = q.top(); // copy
|
|
||||||
q.pop();
|
q.pop();
|
||||||
// is valid id (no initial value default value)
|
THEN("Element removed from the queue has its position in idxs reset to invalid.") {
|
||||||
CHECK(it.id != 0);
|
CHECK(idxs[v.id] == q.invalid_id());
|
||||||
// is first item in queue valid value
|
}
|
||||||
CHECK(idxs[0] != std::numeric_limits<size_t>::max());
|
THEN("Element was removed from the queue, new top of the queue has its index set correctly.") {
|
||||||
|
CHECK(q.top().id >= 0);
|
||||||
|
CHECK(q.top().id < count);
|
||||||
|
CHECK(idxs[q.top().id] == 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Mutable priority queue complex", "[MutableSkipHeapPriorityQueue]")
|
TEST_CASE("Mutable priority queue complex", "[MutableSkipHeapPriorityQueue]")
|
||||||
@ -382,23 +393,23 @@ TEST_CASE("Mutable priority queue complex", "[MutableSkipHeapPriorityQueue]")
|
|||||||
q.reserve(count);
|
q.reserve(count);
|
||||||
|
|
||||||
auto rand_val = [&]()->float { return (rand() % 53) / 10.f; };
|
auto rand_val = [&]()->float { return (rand() % 53) / 10.f; };
|
||||||
size_t ord = 0;
|
for (size_t id = 0; id < count; ++ id)
|
||||||
for (size_t id = 0; id < count; id++) {
|
q.push({ id, rand_val() });
|
||||||
MyValue mv;
|
|
||||||
mv.id = ord++;
|
|
||||||
mv.val = rand_val();
|
|
||||||
q.push(mv);
|
|
||||||
}
|
|
||||||
auto check = [&]()->bool{
|
auto check = [&]()->bool{
|
||||||
for (size_t i = 0; i < idxs.size(); ++i) {
|
for (size_t i = 0; i < idxs.size(); ++i) {
|
||||||
if (dels[i]) continue;
|
if (dels[i]) {
|
||||||
size_t qid = idxs[i];
|
if (idxs[i] != q.invalid_id())
|
||||||
if (qid > 3*count) {
|
return false; // ERROR
|
||||||
return false;
|
} else {
|
||||||
}
|
size_t qid = idxs[i];
|
||||||
MyValue &mv = q[qid];
|
if (qid >= q.heap_size()) {
|
||||||
if (mv.id != i) {
|
return false; // ERROR
|
||||||
return false; // ERROR
|
}
|
||||||
|
MyValue &mv = q[qid];
|
||||||
|
if (mv.id != i) {
|
||||||
|
return false; // ERROR
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -406,6 +417,7 @@ TEST_CASE("Mutable priority queue complex", "[MutableSkipHeapPriorityQueue]")
|
|||||||
|
|
||||||
CHECK(check()); // initial check
|
CHECK(check()); // initial check
|
||||||
|
|
||||||
|
// Generate an element ID of an elmenet, which was not yet deleted, thus it is still valid.
|
||||||
auto get_valid_id = [&]()->int {
|
auto get_valid_id = [&]()->int {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
do {
|
do {
|
||||||
@ -413,23 +425,28 @@ TEST_CASE("Mutable priority queue complex", "[MutableSkipHeapPriorityQueue]")
|
|||||||
} while (dels[id]);
|
} while (dels[id]);
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Remove first 100 elements from the queue of 5000 elements, cross-validate indices.
|
||||||
|
// Re-enter every 20th element back to the queue.
|
||||||
for (size_t i = 0; i < 100; i++) {
|
for (size_t i = 0; i < 100; i++) {
|
||||||
MyValue it = q.top(); // copy
|
MyValue v = q.top(); // copy
|
||||||
q.pop();
|
q.pop();
|
||||||
dels[it.id] = true;
|
dels[v.id] = true;
|
||||||
CHECK(check());
|
CHECK(check());
|
||||||
if (i % 20 == 0) {
|
if (i % 20 == 0) {
|
||||||
it.val = rand_val();
|
v.val = rand_val();
|
||||||
q.push(it);
|
q.push(v);
|
||||||
dels[it.id] = false;
|
dels[v.id] = false;
|
||||||
CHECK(check());
|
CHECK(check());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Remove some valid element from the queue.
|
||||||
int id = get_valid_id();
|
int id = get_valid_id();
|
||||||
|
CHECK(idxs[id] != q.invalid_id());
|
||||||
q.remove(idxs[id]);
|
q.remove(idxs[id]);
|
||||||
dels[id] = true;
|
dels[id] = true;
|
||||||
CHECK(check());
|
CHECK(check());
|
||||||
|
// and change 5 random elements and reorder them in the queue.
|
||||||
for (size_t j = 0; j < 5; j++) {
|
for (size_t j = 0; j < 5; j++) {
|
||||||
int id = get_valid_id();
|
int id = get_valid_id();
|
||||||
size_t qid = idxs[id];
|
size_t qid = idxs[id];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user