diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b1ec4bb48..f5aca49732 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,7 +151,7 @@ set(engine_SRCS # Except main.cpp. src/utils/ToolpathVisualizer.cpp src/utils/VoronoiUtils.cpp src/utils/VoxelUtils.cpp - ) +) add_library(_CuraEngine STATIC ${engine_SRCS} ${engine_PB_SRCS}) #use_threads(_CuraEngine) @@ -162,7 +162,7 @@ target_include_directories(_CuraEngine $ PRIVATE $ # Include Cura.pb.h - ) +) target_compile_definitions(_CuraEngine PUBLIC @@ -180,7 +180,7 @@ target_compile_definitions(_CuraEngine $<$:ASSERT_INSANE_OUTPUT> $<$:USE_CPU_TIME> $<$:DEBUG> - ) +) enable_sanitizers(_CuraEngine) @@ -189,7 +189,7 @@ if (${EXTENSIVE_WARNINGS}) endif () if (ENABLE_ARCUS) - target_link_libraries(_CuraEngine PUBLIC arcus::arcus ) + target_link_libraries(_CuraEngine PUBLIC arcus::arcus) endif () find_package(clipper REQUIRED) @@ -242,7 +242,7 @@ else () SET(CMAKE_RC_COMPILER_INIT windres) SET(CMAKE_RC_COMPILE_OBJECT " -O coff -i -o " - ) + ) endif () add_executable(CuraEngine src/main.cpp ${RES_FILES}) # ..., but don't forget the glitter! if (ENABLE_SENTRY) @@ -293,7 +293,7 @@ if (ENABLE_BENCHMARKS) add_subdirectory(benchmark) if (NOT WIN32) add_subdirectory(stress_benchmark) - endif() + endif () endif () if (ENABLE_TESTING) diff --git a/conanfile.py b/conanfile.py index c183c1a011..e3313e1cbd 100644 --- a/conanfile.py +++ b/conanfile.py @@ -143,6 +143,9 @@ def generate(self): tc.variables["ENABLE_PLUGINS"] = self.options.enable_plugins tc.generate() + if self.settings.arch == "wasm" and self.settings.os == "Emscripten": + self.buildenv.define("EMCC_CFLAGS", "-s ALLOW_MEMORY_GROWTH=1 -s EXPORT_ES6=1 -s EXPORT_NAME='CuraEngine' -s EXPORTED_RUNTIME_METHODS='[\"callMain\", \"FS\"]' -s INVOKE_RUN=0 -s MODULARIZE=1 -s SINGLE_FILE=1 -s ENVIRONMENT=worker -s USE_ES6_IMPORT_META=0") + for dep in self.dependencies.values(): if len(dep.cpp_info.libdirs) > 0: copy(self, "*.dylib", dep.cpp_info.libdirs[0], self.build_folder) diff --git a/include/communication/CommandLine.h b/include/communication/CommandLine.h index ac7c1ccda7..d6ded052d4 100644 --- a/include/communication/CommandLine.h +++ b/include/communication/CommandLine.h @@ -1,5 +1,5 @@ -// Copyright (c) 2018-2022 Ultimaker B.V. -// CuraEngine is released under the terms of the AGPLv3 or higher. +// Copyright (c) 2024 UltiMaker +// CuraEngine is released under the terms of the AGPLv3 or higher #ifndef COMMANDLINE_H #define COMMANDLINE_H @@ -151,6 +151,10 @@ class CommandLine : public Communication void sliceNext() override; private: +#ifdef __EMSCRIPTEN__ + std::string progressHandler; +#endif + /* * \brief The command line arguments that the application was called with. */ diff --git a/src/communication/CommandLine.cpp b/src/communication/CommandLine.cpp index 95359abae4..1ecf3e7a71 100644 --- a/src/communication/CommandLine.cpp +++ b/src/communication/CommandLine.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2022 Ultimaker B.V. +// Copyright (c) 2024 UltiMaker // CuraEngine is released under the terms of the AGPLv3 or higher #include "communication/CommandLine.h" @@ -21,6 +21,10 @@ #include "Slice.h" #include "utils/Matrix4x3D.h" //For the mesh_rotation_matrix setting. +#ifdef __EMSCRIPTEN__ +#include +#endif + namespace cura { @@ -106,6 +110,12 @@ void CommandLine::sendProgress(double progress) const return; } // TODO: Do we want to print a progress bar? We'd need a better solution to not have that progress bar be ruined by any logging. +#ifdef __EMSCRIPTEN__ + // Call progress handler with progress + char js[100]; + std::sprintf(js, "globalThis[\"%s\"](%f)", progressHandler.c_str(), progress); + emscripten_run_script(js); +#endif } void CommandLine::sliceNext() @@ -178,6 +188,15 @@ void CommandLine::sliceNext() force_read_parent = false; force_read_nondefault = false; } +#ifdef __EMSCRIPTEN__ + else if (argument.find("--progress") == 0) + { + // Store progress handler name + argument_index++; + argument = arguments_[argument_index]; + progressHandler = argument; + } +#endif else { spdlog::error("Unknown option: {}", argument);