From 1820afa3dd15b95f3a33da6964398739a9975832 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Fri, 9 Feb 2024 06:55:39 +0100 Subject: [PATCH 01/42] Include CMake config to make lib3mf into a valid CMake package and changes in the root CMakeLists.txt to accomodate it + Introduction of CPack --- CMakeLists.txt | 18 ++++++++++++++++++ cmake/lib3mfConfig.cmake | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 cmake/lib3mfConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index fe8004a5f..33b881700 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,6 +226,8 @@ endif(WIN32) configure_file(lib3mf.pc.in lib3mf.pc @ONLY) install(FILES ${CMAKE_BINARY_DIR}/lib3mf.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +install(FILES cmake/lib3mfConfig.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/lib3mf) install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" @@ -253,3 +255,19 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${STARTUPPROJECT}) ENDIF() endif() + + +######################################################### +set(CPACK_PACKAGE_NAME "lib3mf") +set(CPACK_PACKAGE_VENDOR "3MF Consortium") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "lib3mf - An implementation of the 3D Manufacturing Format file standard") +set(CPACK_PACKAGE_VERSION "${LIB3MF_VERSION_MAJOR}.${LIB3MF_VERSION_MINOR}.${LIB3MF_VERSION_MICRO}") +set(CPACK_PACKAGE_VERSION_MAJOR "${LIB3MF_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${LIB3MF_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${LIB3MF_VERSION_MICRO}") +set(CPACK_PACKAGE_CONTACT "maintainer@3mf.io") # An actual email id is required here +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "3MF Consortium") +set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}") +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Source") + +include(CPack) diff --git a/cmake/lib3mfConfig.cmake b/cmake/lib3mfConfig.cmake new file mode 100644 index 000000000..4318b8418 --- /dev/null +++ b/cmake/lib3mfConfig.cmake @@ -0,0 +1,41 @@ +# lib3mfConfig.cmake + +# Initial setup for known components and default selection +set(lib3mf_known_components "C" "CDynamic" "Cpp" "CppDynamic") +set(lib3mf_selected_variant "CPPDynamic") # Default variant + +# Check if any known component was specified and select it +foreach(comp ${lib3mf_FIND_COMPONENTS}) + if(comp IN_LIST lib3mf_known_components) + set(lib3mf_selected_variant ${comp}) + break() # Use the first specified known component + endif() +endforeach() + +# Configure paths based on the selected variant +set(lib3mf_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../include/Bindings/${lib3mf_selected_variant}") +set(lib3mf_LIBRARY_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../lib") + +# Adjust library file name based on platform +if(WIN32) + set(lib3mf_LIBRARY "${lib3mf_LIBRARY_DIR}/lib3mf.dll") + set(lib3mf_LIBRARY_IMPORT "${lib3mf_LIBRARY_DIR}/lib3mf.lib") # For importing symbols +elseif(APPLE) + set(lib3mf_LIBRARY "${lib3mf_LIBRARY_DIR}/lib3mf.dylib") +else() # Linux and others + set(lib3mf_LIBRARY "${lib3mf_LIBRARY_DIR}/lib3mf.so") +endif() + +# Define the imported target +add_library(lib3mf::lib3mf SHARED IMPORTED) + +# Set target properties for include directory and library path +set_target_properties(lib3mf::lib3mf PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${lib3mf_INCLUDE_DIR}" + IMPORTED_LOCATION "${lib3mf_LIBRARY}" +) + +if(WIN32) + set_property(TARGET lib3mf PROPERTY IMPORTED_IMPLIB "${lib3mf_LIBRARY_IMPORT}") +endif() + From 95140d8d133e9a6070cd0bff71e43524169ca52a Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Fri, 9 Feb 2024 20:25:44 +0100 Subject: [PATCH 02/42] Update gitignore --- .gitignore | 2 ++ CMakeLists.txt | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a41019361..87ee8d189 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ Include/Model/COM/NMR_COMVersion.h debug .DS_Store .vscode +.idea +cmake-build-* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 33b881700..2b7892340 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,4 +270,5 @@ set(CPACK_DEBIAN_PACKAGE_MAINTAINER "3MF Consortium") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Source") -include(CPack) +######################################################### +include(CPack) \ No newline at end of file From 0a72824db8acfa2cd5dd2a43ca25e513113e3f3e Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Fri, 9 Feb 2024 20:40:02 +0100 Subject: [PATCH 03/42] Comment out unnecessary workflows for easier debugging --- .github/workflows/build.yml | 192 ++++++++++++++++++------------------ 1 file changed, 96 insertions(+), 96 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 96a237c83..f8a328540 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,103 +75,103 @@ jobs: with: name: lib3mf.dylib path: build/lib3mf.dylib - codecoverage-macos: - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - name: Install Prerequisites - run: | - brew install lcov - brew install gcovr - - run: sh cmake/GenerateMake.sh -DBUILD_FOR_CODECOVERAGE=ON - - run: cmake --build . - working-directory: ./build - - run: ./Tests/codecoverage/run_codecoverage.sh - - name: Archive Code Coverage Results - uses: actions/upload-artifact@v2 - with: - name: codecoverage.zip - path: build/codecoverage.zip - - name: Upload code coverage to codecov - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./build/Test_CPP_Bindings_filtered.info - fail_ci_if_error: true # optional (default = false) - verbose: true # optional (default = false) +# codecoverage-macos: +# runs-on: macos-latest +# steps: +# - uses: actions/checkout@v4 +# with: +# submodules: true +# - name: Install Prerequisites +# run: | +# brew install lcov +# brew install gcovr +# - run: sh cmake/GenerateMake.sh -DBUILD_FOR_CODECOVERAGE=ON +# - run: cmake --build . +# working-directory: ./build +# - run: ./Tests/codecoverage/run_codecoverage.sh +# - name: Archive Code Coverage Results +# uses: actions/upload-artifact@v2 +# with: +# name: codecoverage.zip +# path: build/codecoverage.zip +# - name: Upload code coverage to codecov +# uses: codecov/codecov-action@v3 +# with: +# token: ${{ secrets.CODECOV_TOKEN }} +# files: ./build/Test_CPP_Bindings_filtered.info +# fail_ci_if_error: true # optional (default = false) +# verbose: true # optional (default = false) - build-windows-release: - runs-on: windows-2019 - steps: - - uses: actions/checkout@v2 - with: - submodules: true - - run: ./cmake/GenerateVS2019.bat - - run: cmake --build . --config Release - working-directory: ./build - - run: ctest -V - working-directory: ./build - - name: Archive Windows Release binary - uses: actions/upload-artifact@v2 - with: - name: lib3mf.dll - path: build/Release/lib3mf.dll - - name: Archive Windows Release lib - uses: actions/upload-artifact@v2 - with: - name: lib3mf.lib - path: build/Release/lib3mf.lib - build-windows-debug: - runs-on: windows-2019 - steps: - - uses: actions/checkout@v2 - with: - submodules: true - - run: ./cmake/GenerateVS2019.bat - - run: cmake --build . --config Debug - working-directory: ./build - - run: ctest -V - working-directory: ./build - - name: Archive Windows Debug binary - uses: actions/upload-artifact@v2 - with: - name: lib3mf.debug.dll - path: build/Debug/lib3mf.dll - build-windows-32bit: - runs-on: windows-2019 - steps: - - uses: actions/checkout@v2 - with: - submodules: true - - run: ./cmake/GenerateVS2019_32bit.bat - - run: cmake --build . --config Release - working-directory: ./build_32bit - - run: ctest -V - working-directory: ./build_32bit - - name: Archive Windows 32 bit Release binary - uses: actions/upload-artifact@v2 - with: - name: lib3mf_32bit.dll - path: build_32bit/Release/lib3mf.dll - - name: Archive Windows 32 bit Release lib - uses: actions/upload-artifact@v2 - with: - name: lib3mf_32bit.lib - path: build_32bit/Release/lib3mf.lib - build-mingw-w64: - runs-on: windows-2019 - steps: - - run: choco install mingw -y - - uses: actions/checkout@v2 - with: - submodules: true - - run: ./cmake/GenerateMinGW.bat - - run: cmake --build . - working-directory: ./build - - run: ctest -V - working-directory: ./build +# build-windows-release: +# runs-on: windows-2019 +# steps: +# - uses: actions/checkout@v2 +# with: +# submodules: true +# - run: ./cmake/GenerateVS2019.bat +# - run: cmake --build . --config Release +# working-directory: ./build +# - run: ctest -V +# working-directory: ./build +# - name: Archive Windows Release binary +# uses: actions/upload-artifact@v2 +# with: +# name: lib3mf.dll +# path: build/Release/lib3mf.dll +# - name: Archive Windows Release lib +# uses: actions/upload-artifact@v2 +# with: +# name: lib3mf.lib +# path: build/Release/lib3mf.lib +# build-windows-debug: +# runs-on: windows-2019 +# steps: +# - uses: actions/checkout@v2 +# with: +# submodules: true +# - run: ./cmake/GenerateVS2019.bat +# - run: cmake --build . --config Debug +# working-directory: ./build +# - run: ctest -V +# working-directory: ./build +# - name: Archive Windows Debug binary +# uses: actions/upload-artifact@v2 +# with: +# name: lib3mf.debug.dll +# path: build/Debug/lib3mf.dll +# build-windows-32bit: +# runs-on: windows-2019 +# steps: +# - uses: actions/checkout@v2 +# with: +# submodules: true +# - run: ./cmake/GenerateVS2019_32bit.bat +# - run: cmake --build . --config Release +# working-directory: ./build_32bit +# - run: ctest -V +# working-directory: ./build_32bit +# - name: Archive Windows 32 bit Release binary +# uses: actions/upload-artifact@v2 +# with: +# name: lib3mf_32bit.dll +# path: build_32bit/Release/lib3mf.dll +# - name: Archive Windows 32 bit Release lib +# uses: actions/upload-artifact@v2 +# with: +# name: lib3mf_32bit.lib +# path: build_32bit/Release/lib3mf.lib +# build-mingw-w64: +# runs-on: windows-2019 +# steps: +# - run: choco install mingw -y +# - uses: actions/checkout@v2 +# with: +# submodules: true +# - run: ./cmake/GenerateMinGW.bat +# - run: cmake --build . +# working-directory: ./build +# - run: ctest -V +# working-directory: ./build assemble-sdk: runs-on: ubuntu-20.04 needs: [build-windows-release, build-macos, build-linux-ubi8-gcc12] From 0e98a92e12ebb51279b073622ff0dc5e49fa8f7e Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Fri, 9 Feb 2024 20:45:04 +0100 Subject: [PATCH 04/42] . --- .github/workflows/build.yml | 42 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f8a328540..46c47d4ba 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -102,27 +102,27 @@ jobs: # fail_ci_if_error: true # optional (default = false) # verbose: true # optional (default = false) -# build-windows-release: -# runs-on: windows-2019 -# steps: -# - uses: actions/checkout@v2 -# with: -# submodules: true -# - run: ./cmake/GenerateVS2019.bat -# - run: cmake --build . --config Release -# working-directory: ./build -# - run: ctest -V -# working-directory: ./build -# - name: Archive Windows Release binary -# uses: actions/upload-artifact@v2 -# with: -# name: lib3mf.dll -# path: build/Release/lib3mf.dll -# - name: Archive Windows Release lib -# uses: actions/upload-artifact@v2 -# with: -# name: lib3mf.lib -# path: build/Release/lib3mf.lib + build-windows-release: + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - run: ./cmake/GenerateVS2019.bat + - run: cmake --build . --config Release + working-directory: ./build + - run: ctest -V + working-directory: ./build + - name: Archive Windows Release binary + uses: actions/upload-artifact@v2 + with: + name: lib3mf.dll + path: build/Release/lib3mf.dll + - name: Archive Windows Release lib + uses: actions/upload-artifact@v2 + with: + name: lib3mf.lib + path: build/Release/lib3mf.lib # build-windows-debug: # runs-on: windows-2019 # steps: From bfdee90c4133e3d4176a779fd54125853929d7a7 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Fri, 9 Feb 2024 20:46:04 +0100 Subject: [PATCH 05/42] Disable memtest workflow too. Its expensive --- .github/workflows/build.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 46c47d4ba..0b6dbb7c0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,17 +1,17 @@ on: [push, pull_request] name: Build jobs: - build-linux-memtest: - runs-on: ubuntu-20.04 - steps: - - run: sudo apt update - - run: sudo apt install -y valgrind uuid-dev - - uses: actions/checkout@v2 - with: - submodules: true - - run: sh cmake/GenerateMake.sh - - run: cmake --build . --target lib3mf_memcheck - working-directory: ./build +# build-linux-memtest: +# runs-on: ubuntu-20.04 +# steps: +# - run: sudo apt update +# - run: sudo apt install -y valgrind uuid-dev +# - uses: actions/checkout@v2 +# with: +# submodules: true +# - run: sh cmake/GenerateMake.sh +# - run: cmake --build . --target lib3mf_memcheck +# working-directory: ./build build-linux-ubi8-gcc12: runs-on: ubuntu-20.04 From f2e7d586291e44d3e86510c4e1048f964f6012cd Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Fri, 9 Feb 2024 21:13:49 +0100 Subject: [PATCH 06/42] Include CPack generation for all 3 platforms --- .github/workflows/build.yml | 4 ++++ CI/Dockerfile | 3 +++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0b6dbb7c0..92463feba 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,6 +70,8 @@ jobs: working-directory: ./build - run: ctest -V working-directory: ./build + - run: cpack -G ZIP -C Release + working-directory: ./build - name: Archive Mac binary uses: actions/upload-artifact@v2 with: @@ -113,6 +115,8 @@ jobs: working-directory: ./build - run: ctest -V working-directory: ./build + - run: cpack -G ZIP -C Release + working-directory: ./build - name: Archive Windows Release binary uses: actions/upload-artifact@v2 with: diff --git a/CI/Dockerfile b/CI/Dockerfile index 846332f66..e95efa404 100644 --- a/CI/Dockerfile +++ b/CI/Dockerfile @@ -53,6 +53,9 @@ RUN cmake --build . RUN ctest -V . +# Add this line to generate a ZIP package with cpack +RUN cpack -G ZIP -C Release + WORKDIR "/../../" RUN mkdir -p out From b1d8011ab27d9a7baff841800d52b99bbdd1fb51 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Fri, 9 Feb 2024 22:06:22 +0100 Subject: [PATCH 07/42] Included CPack artifact archiving for all 3 platforms (First version) --- .github/workflows/build.yml | 33 +++++++++++++++++++++++++++++++++ CI/Dockerfile | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 92463feba..6e20e7d03 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,12 +52,25 @@ jobs: - run: unzip out.zip working-directory: ./dist + + - name: Extract File Name + run: | + ZIP_FILE=$(ls dist/lib3mf-*.zip) + echo "ARTIFACT_NAME=$(basename ${ZIP_FILE})" >> $GITHUB_ENV + shell: bash + - name: Upload Artifact uses: actions/upload-artifact@v2 with: name: lib3mf.so path: dist/lib3mf.so.2 + - + name: Upload Artifact (CPacked Archive) + uses: actions/upload-artifact@v2 + with: + name: ${{ env.ARTIFACT_NAME }} + path: dist/${{ env.ARTIFACT_NAME }} build-macos: runs-on: macos-latest @@ -72,11 +85,21 @@ jobs: working-directory: ./build - run: cpack -G ZIP -C Release working-directory: ./build + - name: Extract File Name + run: | + ZIP_FILE=$(ls dist/lib3mf-*.zip) + echo "ARTIFACT_NAME=$(basename ${ZIP_FILE})" >> $GITHUB_ENV + shell: bash - name: Archive Mac binary uses: actions/upload-artifact@v2 with: name: lib3mf.dylib path: build/lib3mf.dylib + - name: Upload Artifact (CPacked Archive) + uses: actions/upload-artifact@v2 + with: + name: ${{ env.ARTIFACT_NAME }} + path: build/${{ env.ARTIFACT_NAME }} # codecoverage-macos: # runs-on: macos-latest # steps: @@ -117,6 +140,11 @@ jobs: working-directory: ./build - run: cpack -G ZIP -C Release working-directory: ./build + - name: Extract File Name + run: | + $zipFile = Get-ChildItem dist\lib3mf-*.zip -Name + echo "ARTIFACT_NAME=$zipFile" | Out-File -FilePath $env:GITHUB_ENV -Append + shell: pwsh - name: Archive Windows Release binary uses: actions/upload-artifact@v2 with: @@ -127,6 +155,11 @@ jobs: with: name: lib3mf.lib path: build/Release/lib3mf.lib + - name: Upload Artifact (CPacked Archive) + uses: actions/upload-artifact@v2 + with: + name: ${{ env.ARTIFACT_NAME }} + path: build/${{ env.ARTIFACT_NAME }} # build-windows-debug: # runs-on: windows-2019 # steps: diff --git a/CI/Dockerfile b/CI/Dockerfile index e95efa404..98fe00842 100644 --- a/CI/Dockerfile +++ b/CI/Dockerfile @@ -62,8 +62,9 @@ RUN mkdir -p out RUN cp ./lib3mf-repo/build/lib3mf.so.2 ./out/ -RUN cd out && zip -r ../out.zip . +RUN cp ./lib3mf-repo/build/lib3mf-*-Linux.zip ./out/ +RUN cd out && zip -r ../out.zip . From 7fbe383ec32ca41ace74fa9ed41feb9644f18fc2 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Fri, 9 Feb 2024 22:29:23 +0100 Subject: [PATCH 08/42] Fix erroneous paths in windows and osx. Linux works (but double zipping is an issue). Also symlinks seem to disappear. This will require a change in cmake config script since it requires exact .so file to be referenced instead of lib3mf.so (A problem to worry at a latter time) --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6e20e7d03..0e94ff01f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -87,7 +87,7 @@ jobs: working-directory: ./build - name: Extract File Name run: | - ZIP_FILE=$(ls dist/lib3mf-*.zip) + ZIP_FILE=$(ls build/lib3mf-*.zip) echo "ARTIFACT_NAME=$(basename ${ZIP_FILE})" >> $GITHUB_ENV shell: bash - name: Archive Mac binary @@ -142,7 +142,7 @@ jobs: working-directory: ./build - name: Extract File Name run: | - $zipFile = Get-ChildItem dist\lib3mf-*.zip -Name + $zipFile = Get-ChildItem build\lib3mf-*.zip -Name echo "ARTIFACT_NAME=$zipFile" | Out-File -FilePath $env:GITHUB_ENV -Append shell: pwsh - name: Archive Windows Release binary From 4a3e86b059295885537ceb122053537f89ed6986 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Mon, 12 Feb 2024 13:24:43 +0100 Subject: [PATCH 09/42] Update dll path in CMake script --- cmake/lib3mfConfig.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/lib3mfConfig.cmake b/cmake/lib3mfConfig.cmake index 4318b8418..320d68e86 100644 --- a/cmake/lib3mfConfig.cmake +++ b/cmake/lib3mfConfig.cmake @@ -15,10 +15,11 @@ endforeach() # Configure paths based on the selected variant set(lib3mf_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../include/Bindings/${lib3mf_selected_variant}") set(lib3mf_LIBRARY_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../lib") +set(lib3mf_BINARY_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../bin") # Adjust library file name based on platform if(WIN32) - set(lib3mf_LIBRARY "${lib3mf_LIBRARY_DIR}/lib3mf.dll") + set(lib3mf_LIBRARY "${lib3mf_BINARY_DIR}/lib3mf.dll") set(lib3mf_LIBRARY_IMPORT "${lib3mf_LIBRARY_DIR}/lib3mf.lib") # For importing symbols elseif(APPLE) set(lib3mf_LIBRARY "${lib3mf_LIBRARY_DIR}/lib3mf.dylib") From 455b8805b8c7a4d0cccbbf78411035c85d519386 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Mon, 12 Feb 2024 13:48:42 +0100 Subject: [PATCH 10/42] Include Debian and RPM build too (Testing) --- .github/workflows/build.yml | 42 ++++++++++++++++++++++++++++--------- CI/Dockerfile | 10 +++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0e94ff01f..ec77527bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,24 +53,46 @@ jobs: - run: unzip out.zip working-directory: ./dist - - name: Extract File Name + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: lib3mf.so + path: dist/lib3mf.so.2 + + + - name: Extract File Name (CPacked Archive) run: | ZIP_FILE=$(ls dist/lib3mf-*.zip) - echo "ARTIFACT_NAME=$(basename ${ZIP_FILE})" >> $GITHUB_ENV + echo "ARTIFACT_NAME_ZIP=$(basename ${ZIP_FILE})" >> $GITHUB_ENV shell: bash + - name: Upload Artifact (CPacked Archive) + uses: actions/upload-artifact@v2 + with: + name: ${{ env.ARTIFACT_NAME_ZIP }} + path: dist/${{ env.ARTIFACT_NAME_ZIP }} - - - name: Upload Artifact + - name: Extract File Name (Debian) + run: | + DEB_FILE=$(ls dist/lib3mf-*.deb) + echo "ARTIFACT_NAME_DEB=$(basename ${DEB_FILE})" >> $GITHUB_ENV + shell: bash + - name: Upload Artifact (Debian Archive) uses: actions/upload-artifact@v2 with: - name: lib3mf.so - path: dist/lib3mf.so.2 - - - name: Upload Artifact (CPacked Archive) + name: ${{ env.ARTIFACT_NAME_DEB }} + path: dist/${{ env.ARTIFACT_NAME_DEB }} + + - name: Extract File Name (RPM) + run: | + RPM_FILE=$(ls dist/lib3mf-*.rpm) + echo "ARTIFACT_NAME_RPM=$(basename ${RPM_FILE})" >> $GITHUB_ENV + shell: bash + - name: Upload Artifact (RPM Archive) uses: actions/upload-artifact@v2 with: - name: ${{ env.ARTIFACT_NAME }} - path: dist/${{ env.ARTIFACT_NAME }} + name: ${{ env.ARTIFACT_NAME_RPM }} + path: dist/${{ env.ARTIFACT_NAME_RPM }} + build-macos: runs-on: macos-latest diff --git a/CI/Dockerfile b/CI/Dockerfile index 98fe00842..ee249c365 100644 --- a/CI/Dockerfile +++ b/CI/Dockerfile @@ -56,6 +56,12 @@ RUN ctest -V . # Add this line to generate a ZIP package with cpack RUN cpack -G ZIP -C Release +# Generate a debian package +RUN cpack -G DEB -C Release + +# Generate a RPM package +RUN cpack -G RPM -C Release + WORKDIR "/../../" RUN mkdir -p out @@ -64,6 +70,10 @@ RUN cp ./lib3mf-repo/build/lib3mf.so.2 ./out/ RUN cp ./lib3mf-repo/build/lib3mf-*-Linux.zip ./out/ +RUN cp ./lib3mf-repo/build/lib3mf-*-Linux.deb ./out/ + +RUN cp ./lib3mf-repo/build/lib3mf-*-Linux.rpm ./out/ + RUN cd out && zip -r ../out.zip . From 4c8abba494ce8c0438d3b7f7df166e79bbaccb1b Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Mon, 12 Feb 2024 14:23:38 +0100 Subject: [PATCH 11/42] Install RPM build --- CI/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/CI/Dockerfile b/CI/Dockerfile index ee249c365..efedb0943 100644 --- a/CI/Dockerfile +++ b/CI/Dockerfile @@ -14,6 +14,7 @@ RUN \ tar \ gzip \ zip \ + rpm-build \ ${GCCTOOLSET} \ && microdnf clean all From 829d9b8bb53856ed0a64da38b119f68a35a2b105 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Mon, 19 Feb 2024 14:38:21 +0100 Subject: [PATCH 12/42] Make a variable called CDYNAMIC_SOURCE available for the CDynamic variant --- cmake/lib3mfConfig.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/lib3mfConfig.cmake b/cmake/lib3mfConfig.cmake index 320d68e86..d2059e463 100644 --- a/cmake/lib3mfConfig.cmake +++ b/cmake/lib3mfConfig.cmake @@ -40,3 +40,8 @@ if(WIN32) set_property(TARGET lib3mf PROPERTY IMPORTED_IMPLIB "${lib3mf_LIBRARY_IMPORT}") endif() +# Check if CDynamic variant is selected and set CDYNAMIC_SOURCE variable +if("${lib3mf_selected_variant}" STREQUAL "CDynamic") + # Set CDYNAMIC_SOURCE to the path of the .cc file + set(CDYNAMIC_SOURCE "${CMAKE_CURRENT_LIST_DIR}/../../../include/Bindings/CDynamic/lib3mf_dynamic.cc" PARENT_SCOPE) +endif() From 92bd5bb5dc6d495b99b5704b2c3c0b8b4b49a3c6 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Mon, 19 Feb 2024 15:31:40 +0100 Subject: [PATCH 13/42] Make changes to make LIB3MF_LIBRARY_LOCATION available to source files automatically --- cmake/lib3mfConfig.cmake | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/cmake/lib3mfConfig.cmake b/cmake/lib3mfConfig.cmake index d2059e463..d8f9be0ca 100644 --- a/cmake/lib3mfConfig.cmake +++ b/cmake/lib3mfConfig.cmake @@ -32,16 +32,13 @@ add_library(lib3mf::lib3mf SHARED IMPORTED) # Set target properties for include directory and library path set_target_properties(lib3mf::lib3mf PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${lib3mf_INCLUDE_DIR}" - IMPORTED_LOCATION "${lib3mf_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${lib3mf_INCLUDE_DIR}" + IMPORTED_LOCATION "${lib3mf_LIBRARY}" +) +target_compile_definitions(lib3mf::lib3mf INTERFACE + "LIB3MF_LIBRARY_LOCATION=\"$\"" ) if(WIN32) - set_property(TARGET lib3mf PROPERTY IMPORTED_IMPLIB "${lib3mf_LIBRARY_IMPORT}") -endif() - -# Check if CDynamic variant is selected and set CDYNAMIC_SOURCE variable -if("${lib3mf_selected_variant}" STREQUAL "CDynamic") - # Set CDYNAMIC_SOURCE to the path of the .cc file - set(CDYNAMIC_SOURCE "${CMAKE_CURRENT_LIST_DIR}/../../../include/Bindings/CDynamic/lib3mf_dynamic.cc" PARENT_SCOPE) -endif() + set_property(TARGET lib3mf::lib3mf PROPERTY IMPORTED_IMPLIB "${lib3mf_LIBRARY_IMPORT}") +endif() \ No newline at end of file From 11ff1d5c10fe196a7031a0f02bb5cd4c1e702cc9 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Mon, 19 Feb 2024 15:46:54 +0100 Subject: [PATCH 14/42] Check if artifact is single or double zipped --- SDK/GenerateSDK_github.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SDK/GenerateSDK_github.sh b/SDK/GenerateSDK_github.sh index 6a59330ea..512d83e2f 100644 --- a/SDK/GenerateSDK_github.sh +++ b/SDK/GenerateSDK_github.sh @@ -44,3 +44,8 @@ echo "GITRevision = "`git rev-parse HEAD` >> $VERSIONTXT echo Zip SDK artifacts cd $SDKARTIFACT zip -r ../$OUTFILE ./* || failed "Error zipping SDK" + + +# Test other packages +unzip lib3mf-2.3.0-Linux.zip +ls lib3mf-2.3.0-Linux \ No newline at end of file From fdc824d5c639caeb5d422e320f0c3f63193ac8ec Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Mon, 19 Feb 2024 16:02:52 +0100 Subject: [PATCH 15/42] Test SDK generation again --- SDK/GenerateSDK_github.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SDK/GenerateSDK_github.sh b/SDK/GenerateSDK_github.sh index 512d83e2f..ec59c1125 100644 --- a/SDK/GenerateSDK_github.sh +++ b/SDK/GenerateSDK_github.sh @@ -47,5 +47,6 @@ zip -r ../$OUTFILE ./* || failed "Error zipping SDK" # Test other packages -unzip lib3mf-2.3.0-Linux.zip -ls lib3mf-2.3.0-Linux \ No newline at end of file +unzip build/lib3mf-2.3.0-Linux.zip +ls -al +ls build/ \ No newline at end of file From ac75ddc21aee98c1811bd5ac8f404d476e721c93 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 00:30:43 +0100 Subject: [PATCH 16/42] Testing sdk generation --- SDK/GenerateSDK_github.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SDK/GenerateSDK_github.sh b/SDK/GenerateSDK_github.sh index ec59c1125..fda4b57f1 100644 --- a/SDK/GenerateSDK_github.sh +++ b/SDK/GenerateSDK_github.sh @@ -47,6 +47,7 @@ zip -r ../$OUTFILE ./* || failed "Error zipping SDK" # Test other packages -unzip build/lib3mf-2.3.0-Linux.zip -ls -al -ls build/ \ No newline at end of file +ls -al $LOCATION +#unzip build/lib3mf-2.3.0-Linux.zip +#ls -al +#ls build/ \ No newline at end of file From fb403a885faea06582d0fd0421cd577806fbd7e6 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 01:05:35 +0100 Subject: [PATCH 17/42] Inclue cpacked artifacts to assemble SDK --- .github/workflows/build.yml | 29 ++++++++++++++++++++++++++++- SDK/GenerateSDK_github.sh | 9 +-------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ec77527bf..09be29335 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,6 @@ on: [push, pull_request] +env: + LIB3MF_VERSION: "2.3.0" name: Build jobs: # build-linux-memtest: @@ -248,11 +250,36 @@ jobs: - run: unzip bindings.zip/bindings.zip working-directory: ./build - run: bash SDK/GenerateSDK_github.sh - - name: Archive SDK artifact + - name: Archive SDK artifact (Comprehensive) uses: actions/upload-artifact@v2 with: name: lib3mf_sdk.zip path: build/lib3mf_sdk.zip + - name: Archive SDK artifact (CPack - Linux) + uses: actions/upload-artifact@v2 + with: + name: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.zip + path: build/lib3mf-${{ env.LIB3MF_VERSION }}-Linux.zip + - name: Archive SDK artifact (CPack - Windows) + uses: actions/upload-artifact@v2 + with: + name: lib3mf-${{ env.LIB3MF_VERSION }}-Windows.zip + path: build/lib3mf-${{ env.LIB3MF_VERSION }}-Windows.zip + - name: Archive SDK artifact (CPack - Darwin) + uses: actions/upload-artifact@v2 + with: + name: lib3mf-${{ env.LIB3MF_VERSION }}-Darwin.zip + path: build/lib3mf-${{ env.LIB3MF_VERSION }}-Darwin.zip + - name: Archive SDK artifact (CPack - Debian) + uses: actions/upload-artifact@v2 + with: + name: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb + path: build/lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb + - name: Archive SDK artifact (CPack - RPM) + uses: actions/upload-artifact@v2 + with: + name: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.rpm + path: build/lib3mf-${{ env.LIB3MF_VERSION }}-Linux.rpm deploy-linux: runs-on: ubuntu-20.04 needs: [assemble-sdk] diff --git a/SDK/GenerateSDK_github.sh b/SDK/GenerateSDK_github.sh index fda4b57f1..00a0d6236 100644 --- a/SDK/GenerateSDK_github.sh +++ b/SDK/GenerateSDK_github.sh @@ -43,11 +43,4 @@ echo "GITRevision = "`git rev-parse HEAD` >> $VERSIONTXT echo Zip SDK artifacts cd $SDKARTIFACT -zip -r ../$OUTFILE ./* || failed "Error zipping SDK" - - -# Test other packages -ls -al $LOCATION -#unzip build/lib3mf-2.3.0-Linux.zip -#ls -al -#ls build/ \ No newline at end of file +zip -r ../$OUTFILE ./* || failed "Error zipping SDK" \ No newline at end of file From ad48a1cac73d73e5822c5484999c42a1038fc40c Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 02:03:40 +0100 Subject: [PATCH 18/42] Make necessary changes to ensure that linking does not happen in CDynamic or CppDynamic variants --- cmake/lib3mfConfig.cmake | 52 ++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/cmake/lib3mfConfig.cmake b/cmake/lib3mfConfig.cmake index d8f9be0ca..f2d05358f 100644 --- a/cmake/lib3mfConfig.cmake +++ b/cmake/lib3mfConfig.cmake @@ -2,7 +2,7 @@ # Initial setup for known components and default selection set(lib3mf_known_components "C" "CDynamic" "Cpp" "CppDynamic") -set(lib3mf_selected_variant "CPPDynamic") # Default variant +set(lib3mf_selected_variant "Cpp") # Default variant # Check if any known component was specified and select it foreach(comp ${lib3mf_FIND_COMPONENTS}) @@ -27,18 +27,40 @@ else() # Linux and others set(lib3mf_LIBRARY "${lib3mf_LIBRARY_DIR}/lib3mf.so") endif() -# Define the imported target -add_library(lib3mf::lib3mf SHARED IMPORTED) +# Print the chosen variant +message("***********************************") +message("LIB3MF Chosen Variant : " ${lib3mf_selected_variant}) +message("***********************************") -# Set target properties for include directory and library path -set_target_properties(lib3mf::lib3mf PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${lib3mf_INCLUDE_DIR}" - IMPORTED_LOCATION "${lib3mf_LIBRARY}" -) -target_compile_definitions(lib3mf::lib3mf INTERFACE - "LIB3MF_LIBRARY_LOCATION=\"$\"" -) - -if(WIN32) - set_property(TARGET lib3mf::lib3mf PROPERTY IMPORTED_IMPLIB "${lib3mf_LIBRARY_IMPORT}") -endif() \ No newline at end of file +# Create a special interface for dynamic loading scenarios +if("${lib3mf_selected_variant}" STREQUAL "CppDynamic" OR "${lib3mf_selected_variant}" STREQUAL "CDynamic") + if("${lib3mf_selected_variant}" STREQUAL "CDynamic") + message("*****************************************************************************") + message("") + message(" For CDynamic Variant, an additional source called lib3mf_dynamic.cc ") + message(" is required ") + message(" It is made available using the variable LIB3MF_CDYNAMIC_ADDITIONAL_SOURCE ") + message(" You must append this to your sources ") + message("") + message("*****************************************************************************") + set(LIB3MF_CDYNAMIC_ADDITIONAL_SOURCE "${CMAKE_CURRENT_LIST_DIR}/../../../include/Bindings/CDynamic/lib3mf_dynamic.cc") + endif() + add_library(lib3mfdynamic INTERFACE) + # Now alias lib3mfdynamic to include the namespace + add_library(lib3mf::lib3mf ALIAS lib3mfdynamic) + # Set properties and compile definitions for lib3mfdynamic + target_compile_definitions(lib3mfdynamic INTERFACE + "LIB3MF_LIBRARY_LOCATION=\"${lib3mf_LIBRARY}\"" + ) + target_include_directories(lib3mfdynamic INTERFACE "${lib3mf_INCLUDE_DIR}") +else() + # Define the imported target for static linking + add_library(lib3mf::lib3mf SHARED IMPORTED) + set_target_properties(lib3mf::lib3mf PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${lib3mf_INCLUDE_DIR}" + IMPORTED_LOCATION "${lib3mf_LIBRARY}" + ) + if(WIN32) + set_property(TARGET lib3mf::lib3mf PROPERTY IMPORTED_IMPLIB "${lib3mf_LIBRARY_IMPORT}") + endif() +endif() From 94fafbba20bb07f906dc6246dffb429a4bbe3c9d Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 02:21:09 +0100 Subject: [PATCH 19/42] First steps toward testing cpacked SDK's --- .github/workflows/build.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 09be29335..ac0bc952d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -308,6 +308,17 @@ jobs: cd Examples/Cpp/build cmake --build . ./Example_ExtractInfo ../../Files/Helix.3mf + - name: Download lib3mf cpack (Linux) + uses: actions/download-artifact@v2 + with: + name: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.zip + path: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.zip + - run: ls -Rl . + - name: Unpack the cpacked SDK + run: | + unzip lib3mf-${{ env.LIB3MF_VERSION }}-Linux.zip/lib3mf-${{ env.LIB3MF_VERSION }}-Linux.zip + - run: ls -Rl . + deploy-windows: runs-on: windows-2019 needs: [assemble-sdk] From eeb609edef8c3dadb09afc72b88fb896345b4e5d Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 02:48:48 +0100 Subject: [PATCH 20/42] Including Linux CppDynamic + Cpacked Cmake build --- .github/workflows/build.yml | 7 +- SDK/Examples/CppDynamicNew/CMakeLists.txt | 59 ++++ SDK/Examples/CppDynamicNew/GenerateMake.sh | 7 + SDK/Examples/CppDynamicNew/GenerateVS2015.bat | 10 + SDK/Examples/CppDynamicNew/GenerateVS2017.bat | 10 + SDK/Examples/CppDynamicNew/GenerateVS2019.bat | 10 + .../CppDynamicNew/Source/ExtractInfo.cpp | 271 ++++++++++++++++++ 7 files changed, 373 insertions(+), 1 deletion(-) create mode 100644 SDK/Examples/CppDynamicNew/CMakeLists.txt create mode 100644 SDK/Examples/CppDynamicNew/GenerateMake.sh create mode 100644 SDK/Examples/CppDynamicNew/GenerateVS2015.bat create mode 100644 SDK/Examples/CppDynamicNew/GenerateVS2017.bat create mode 100644 SDK/Examples/CppDynamicNew/GenerateVS2019.bat create mode 100644 SDK/Examples/CppDynamicNew/Source/ExtractInfo.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ac0bc952d..df429572d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -317,7 +317,12 @@ jobs: - name: Unpack the cpacked SDK run: | unzip lib3mf-${{ env.LIB3MF_VERSION }}-Linux.zip/lib3mf-${{ env.LIB3MF_VERSION }}-Linux.zip - - run: ls -Rl . + - name: Build CppDynamicNew + run: | + sh Examples/CppDynamicNew/GenerateMake.sh + cd Examples/CppDynamicNew/build + cmake --build . + ./Example_ExtractInfo ../../Files/Helix.3mf deploy-windows: runs-on: windows-2019 diff --git a/SDK/Examples/CppDynamicNew/CMakeLists.txt b/SDK/Examples/CppDynamicNew/CMakeLists.txt new file mode 100644 index 000000000..848d02afd --- /dev/null +++ b/SDK/Examples/CppDynamicNew/CMakeLists.txt @@ -0,0 +1,59 @@ +#[[++ + +Copyright (C) 2019 3MF Consortium (Original Author) + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.5.0-develop3. + +Abstract: This is an autogenerated CMake Project that demonstrates the + usage of the Dynamic C++ bindings of the 3MF Library + +Interface version: 2.2.0 + + +]] + +cmake_minimum_required(VERSION 3.5) + +project(Example_ExtractInfo) +set(CMAKE_CXX_STANDARD 11) + +# For Linux +set(lib3mf_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Linux/lib/cmake/lib3mf) + +find_package(lib3mf REQUIRED CppDynamic) + +add_executable(Example_ExtractInfo "${CMAKE_CURRENT_SOURCE_DIR}/Source/ExtractInfo.cpp") + +# In case of CDynamic and CppDynamic, the lib3mf::lib3mf is simply an alias to an interface +target_link_libraries(Example_ExtractInfo lib3mf::lib3mf) + +if (${MSVC}) + IF(${CMAKE_VERSION} VERSION_LESS 3.6.3) + MESSAGE ("Note: You need to manually select a StartUp-project in Visual Studio.") + ELSE() + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Example_ExtractInfo) + ENDIF() +endif() + diff --git a/SDK/Examples/CppDynamicNew/GenerateMake.sh b/SDK/Examples/CppDynamicNew/GenerateMake.sh new file mode 100644 index 000000000..16fe9cf2b --- /dev/null +++ b/SDK/Examples/CppDynamicNew/GenerateMake.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +basepath="$(cd "$(dirname "$0")" && pwd)" +builddir="$basepath/build" +mkdir -p $builddir +cd $builddir +cmake .. -G "Unix Makefiles" "$@" \ No newline at end of file diff --git a/SDK/Examples/CppDynamicNew/GenerateVS2015.bat b/SDK/Examples/CppDynamicNew/GenerateVS2015.bat new file mode 100644 index 000000000..e6933cdeb --- /dev/null +++ b/SDK/Examples/CppDynamicNew/GenerateVS2015.bat @@ -0,0 +1,10 @@ +@echo off +set startingDir=%CD% + +set basepath=%~dp0 +set builddir=%basepath%\build +if not exist %builddir% (mkdir %builddir%) +cd %builddir% +cmake -G "Visual Studio 14 2015 Win64" .. %* + +cd %startingDir% diff --git a/SDK/Examples/CppDynamicNew/GenerateVS2017.bat b/SDK/Examples/CppDynamicNew/GenerateVS2017.bat new file mode 100644 index 000000000..4014d2f99 --- /dev/null +++ b/SDK/Examples/CppDynamicNew/GenerateVS2017.bat @@ -0,0 +1,10 @@ +@echo off +set startingDir=%CD% + +set basepath=%~dp0 +set builddir=%basepath%\build +if not exist %builddir% (mkdir %builddir%) +cd %builddir% +cmake -G "Visual Studio 15 2017 Win64" .. %* + +cd %startingDir% diff --git a/SDK/Examples/CppDynamicNew/GenerateVS2019.bat b/SDK/Examples/CppDynamicNew/GenerateVS2019.bat new file mode 100644 index 000000000..efa4f308f --- /dev/null +++ b/SDK/Examples/CppDynamicNew/GenerateVS2019.bat @@ -0,0 +1,10 @@ +@echo off +set startingDir=%CD% + +set basepath=%~dp0 +set builddir=%basepath%\build +if not exist %builddir% (mkdir %builddir%) +cd %builddir% +cmake -G "Visual Studio 16 2019" .. %* + +cd %startingDir% diff --git a/SDK/Examples/CppDynamicNew/Source/ExtractInfo.cpp b/SDK/Examples/CppDynamicNew/Source/ExtractInfo.cpp new file mode 100644 index 000000000..0a96b29f4 --- /dev/null +++ b/SDK/Examples/CppDynamicNew/Source/ExtractInfo.cpp @@ -0,0 +1,271 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL MICROSOFT AND/OR NETFABB BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Abstract: + +ExtractInfo.cpp : 3MF Read Example + +--*/ + +#include +#include +#include + +#include "lib3mf_dynamic.hpp" + +using namespace Lib3MF; + + +void printVersion(PWrapper wrapper) { + Lib3MF_uint32 nMajor, nMinor, nMicro; + wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); + std::cout << "lib3mf version = " << nMajor << "." << nMinor << "." << nMicro; + std::string sReleaseInfo, sBuildInfo; + if (wrapper->GetPrereleaseInformation(sReleaseInfo)) { + std::cout << "-" << sReleaseInfo; + } + if (wrapper->GetBuildInformation(sBuildInfo)) { + std::cout << "+" << sBuildInfo; + } + std::cout << std::endl; +} + +void ShowThumbnailInformation(PModel model) +{ + /* + // TODO: this is not yet implemented in lib3mf + */ +} + + +void ShowMetaDataInformation(PMetaDataGroup metaDataGroup) +{ + Lib3MF_uint32 nMetaDataCount = metaDataGroup->GetMetaDataCount(); + + for (Lib3MF_uint32 iMeta = 0; iMeta < nMetaDataCount; iMeta++) { + + PMetaData metaData = metaDataGroup->GetMetaData(iMeta); + std::string sMetaDataValue = metaData->GetValue(); + std::string sMetaDataName = metaData->GetName(); + std::cout << "Metadatum: " << iMeta << ":" << std::endl; + std::cout << "Name = \"" << sMetaDataName << "\"" << std::endl; + std::cout << "Value = \"" << sMetaDataValue << "\"" << std::endl; + } +} + +void ShowSliceStack(PSliceStack sliceStack, std::string indent) +{ + std::cout << indent << "SliceStackID: " << sliceStack->GetResourceID() << std::endl; + if (sliceStack->GetSliceCount() > 0) { + std::cout << indent << " Slice count: " << sliceStack->GetSliceCount() << std::endl; + } + if (sliceStack->GetSliceRefCount() > 0) { + std::cout << indent << " Slice ref count: " << sliceStack->GetSliceRefCount() << std::endl; + for (Lib3MF_uint64 iSliceRef = 0; iSliceRef < sliceStack->GetSliceRefCount(); iSliceRef++) { + std::cout << indent << " Slice ref : " << sliceStack->GetSliceStackReference(iSliceRef)->GetResourceID() << std::endl; + } + } +} + +void ShowObjectProperties(PObject object) +{ + std::cout << " Name: \"" << object->GetName() << "\"" << std::endl; + std::cout << " PartNumber: \"" << object->GetPartNumber() << "\"" << std::endl; + + switch (object->GetType()) { + case eObjectType::Model: + std::cout << " Object type: model" << std::endl; + break; + case eObjectType::Support: + std::cout << " Object type: support" << std::endl; + break; + case eObjectType::SolidSupport: + std::cout << " Object type: solidsupport" << std::endl; + break; + case eObjectType::Other: + std::cout << " Object type: other" << std::endl; + break; + default: + std::cout << " Object type: invalid" << std::endl; + break; + } + + if (object->HasSlices(false)) { + PSliceStack sliceStack = object->GetSliceStack(); + ShowSliceStack(sliceStack, " "); + } + + if (object->GetMetaDataGroup()->GetMetaDataCount() > 0) { + ShowMetaDataInformation(object->GetMetaDataGroup()); + } +} + +void ShowMeshObjectInformation(PMeshObject meshObject) +{ + std::cout << "mesh object #" << meshObject->GetResourceID() << ": " << std::endl; + + ShowObjectProperties(meshObject); + + Lib3MF_uint64 nVertexCount = meshObject->GetVertexCount(); + Lib3MF_uint64 nTriangleCount = meshObject->GetTriangleCount(); + PBeamLattice beamLattice = meshObject->BeamLattice(); + + // Output data + std::cout << " Vertex count: " << nVertexCount << std::endl; + std::cout << " Triangle count: " << nTriangleCount << std::endl; + + Lib3MF_uint64 nBeamCount = beamLattice->GetBeamCount(); + if (nBeamCount > 0) { + std::cout << " Beam count: " << nBeamCount << std::endl; + Lib3MF_uint32 nRepresentationMesh; + if (beamLattice->GetRepresentation(nRepresentationMesh)) + std::cout << " |_Representation Mesh ID: " << nRepresentationMesh << std::endl; + eLib3MFBeamLatticeClipMode eClipMode; + Lib3MF_uint32 nClippingMesh; + beamLattice->GetClipping(eClipMode, nClippingMesh); + if (eClipMode != eBeamLatticeClipMode::NoClipMode) + std::cout << " |_Clipping Mesh ID: " << nClippingMesh << "(mode=" << (int)eClipMode << ")" << std::endl; + if (beamLattice->GetBeamSetCount() > 0) { + std::cout << " |_BeamSet count: " << beamLattice->GetBeamSetCount() << std::endl; + } + } + +} + +void ShowTransform(sLib3MFTransform transform, std::string indent) { + std::cout << indent << "Transformation: [ " << transform.m_Fields[0][0] << " " << transform.m_Fields[1][0] << " " << transform.m_Fields[2][0] << " " << transform.m_Fields[3][0] << " ]" << std::endl; + std::cout << indent << " [ " << transform.m_Fields[0][1] << " " << transform.m_Fields[1][1] << " " << transform.m_Fields[2][1] << " " << transform.m_Fields[3][1] << " ]" << std::endl; + std::cout << indent << " [ " << transform.m_Fields[0][2] << " " << transform.m_Fields[1][2] << " " << transform.m_Fields[2][2] << " " << transform.m_Fields[3][2] << " ]" << std::endl; +} + +void ShowComponentsObjectInformation(PComponentsObject componentsObject) +{ + std::cout << "components object #" << componentsObject->GetResourceID() << ": " << std::endl; + + ShowObjectProperties(componentsObject); + std::cout << " Component count: " << componentsObject->GetComponentCount() << std::endl; + for (Lib3MF_uint32 nIndex = 0; nIndex < componentsObject->GetComponentCount(); nIndex++) { + PComponent component = componentsObject->GetComponent(nIndex); + + std::cout << " Component " << nIndex << ": Object ID: " << component->GetObjectResourceID() << std::endl; + if (component->HasTransform()) { + ShowTransform(component->GetTransform(), " "); + } + else { + std::cout << " Transformation: none" << std::endl; + } + } +} + + +void ExtractInfoExample(std::string sFileName) { + std::cout << "------------------------------------------------------------------" << std::endl; + std::cout << "3MF Read example" << std::endl; + + std::string libpath = ("."); // TODO: put the location of the Lib3MF-library file here. + auto wrapper = Lib3MF::CWrapper::loadLibrary(LIB3MF_LIBRARY_LOCATION); // TODO: add correct suffix of the library + + printVersion(wrapper); + std::cout << "------------------------------------------------------------------" << std::endl; + + PModel model = wrapper->CreateModel(); + + // Import Model from 3MF File + { + PReader reader = model->QueryReader("3mf"); + // And deactivate the strict mode (default is "false", anyway. This just demonstrates where/how to use it). + reader->SetStrictModeActive(false); + reader->ReadFromFile(sFileName); + + for (Lib3MF_uint32 iWarning = 0; iWarning < reader->GetWarningCount(); iWarning++) { + Lib3MF_uint32 nErrorCode; + std::string sWarningMessage = reader->GetWarning(iWarning, nErrorCode); + std::cout << "Encountered warning #" << nErrorCode << " : " << sWarningMessage << std::endl; + } + } + ShowThumbnailInformation(model); + + ShowMetaDataInformation(model->GetMetaDataGroup()); + + PSliceStackIterator sliceStacks = model->GetSliceStacks(); + while (sliceStacks->MoveNext()) { + PSliceStack sliceStack = sliceStacks->GetCurrentSliceStack(); + ShowSliceStack(sliceStack, ""); + } + + PObjectIterator objectIterator = model->GetObjects(); + while (objectIterator->MoveNext()) { + PObject object = objectIterator->GetCurrentObject(); + if (object->IsMeshObject()) { + ShowMeshObjectInformation(model->GetMeshObjectByID(object->GetResourceID())); + } + else if (object->IsComponentsObject()) { + ShowComponentsObjectInformation(model->GetComponentsObjectByID(object->GetResourceID())); + } + else { + std::cout << "unknown object #" << object->GetResourceID() << ": " << std::endl; + } + } + + + PBuildItemIterator buildItemIterator = model->GetBuildItems(); + while (buildItemIterator->MoveNext()) { + PBuildItem buildItem = buildItemIterator->GetCurrent(); + + std::cout << "Build item (Object #" << buildItem->GetObjectResourceID() << "): " << std::endl; + + if (buildItem->HasObjectTransform()) { + ShowTransform(buildItem->GetObjectTransform(), " "); + } + else { + std::cout << " Transformation: none" << std::endl; + } + std::cout << " Part number: \"" << buildItem->GetPartNumber() << "\"" << std::endl; + if (buildItem->GetMetaDataGroup()->GetMetaDataCount() > 0) { + ShowMetaDataInformation(buildItem->GetMetaDataGroup()); + } + } + + std::cout << "done" << std::endl; +} + + +int main(int argc, char** argv) { + // Parse Arguments + if (argc != 2) { + std::cout << "Usage: " << std::endl; + std::cout << "ExtractInfo.exe model.3mf" << std::endl; + return 0; + } + + try { + ExtractInfoExample(argv[1]); + } + catch (ELib3MFException &e) { + std::cout << e.what() << std::endl; + return e.getErrorCode(); + } + return 0; +} From 0c7e688265085c322f0cde07afb2fcfd21f476ba Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 03:03:53 +0100 Subject: [PATCH 21/42] Include DL also to CppDynamic linking --- SDK/Examples/CppDynamicNew/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDK/Examples/CppDynamicNew/CMakeLists.txt b/SDK/Examples/CppDynamicNew/CMakeLists.txt index 848d02afd..f8e85ce43 100644 --- a/SDK/Examples/CppDynamicNew/CMakeLists.txt +++ b/SDK/Examples/CppDynamicNew/CMakeLists.txt @@ -47,7 +47,7 @@ find_package(lib3mf REQUIRED CppDynamic) add_executable(Example_ExtractInfo "${CMAKE_CURRENT_SOURCE_DIR}/Source/ExtractInfo.cpp") # In case of CDynamic and CppDynamic, the lib3mf::lib3mf is simply an alias to an interface -target_link_libraries(Example_ExtractInfo lib3mf::lib3mf) +target_link_libraries(Example_ExtractInfo lib3mf::lib3mf ${CMAKE_DL_LIBS}) if (${MSVC}) IF(${CMAKE_VERSION} VERSION_LESS 3.6.3) From 181f51f93785d568eab995f51a14b495ce4df1ff Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 03:22:49 +0100 Subject: [PATCH 22/42] Include Cpp variant example for Cpacked Linux package --- .github/workflows/build.yml | 6 + SDK/Examples/CppNew/CMakeLists.txt | 44 ++ SDK/Examples/CppNew/GenerateMake.sh | 7 + SDK/Examples/CppNew/GenerateVS2015.bat | 10 + SDK/Examples/CppNew/GenerateVS2017.bat | 10 + SDK/Examples/CppNew/GenerateVS2019.bat | 10 + SDK/Examples/CppNew/Source/BeamLattice.cpp | 159 +++++++ SDK/Examples/CppNew/Source/ColorCube.cpp | 183 ++++++++ SDK/Examples/CppNew/Source/Components.cpp | 183 ++++++++ SDK/Examples/CppNew/Source/Converter.cpp | 154 +++++++ SDK/Examples/CppNew/Source/Cube.cpp | 140 ++++++ SDK/Examples/CppNew/Source/ExtractInfo.cpp | 269 ++++++++++++ SDK/Examples/CppNew/Source/SecureCube.cpp | 487 +++++++++++++++++++++ SDK/Examples/CppNew/Source/Slice.cpp | 191 ++++++++ SDK/Examples/CppNew/Source/TextureCube.cpp | 205 +++++++++ 15 files changed, 2058 insertions(+) create mode 100644 SDK/Examples/CppNew/CMakeLists.txt create mode 100644 SDK/Examples/CppNew/GenerateMake.sh create mode 100644 SDK/Examples/CppNew/GenerateVS2015.bat create mode 100644 SDK/Examples/CppNew/GenerateVS2017.bat create mode 100644 SDK/Examples/CppNew/GenerateVS2019.bat create mode 100644 SDK/Examples/CppNew/Source/BeamLattice.cpp create mode 100644 SDK/Examples/CppNew/Source/ColorCube.cpp create mode 100644 SDK/Examples/CppNew/Source/Components.cpp create mode 100644 SDK/Examples/CppNew/Source/Converter.cpp create mode 100644 SDK/Examples/CppNew/Source/Cube.cpp create mode 100644 SDK/Examples/CppNew/Source/ExtractInfo.cpp create mode 100644 SDK/Examples/CppNew/Source/SecureCube.cpp create mode 100644 SDK/Examples/CppNew/Source/Slice.cpp create mode 100644 SDK/Examples/CppNew/Source/TextureCube.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index df429572d..4211a187b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -323,6 +323,12 @@ jobs: cd Examples/CppDynamicNew/build cmake --build . ./Example_ExtractInfo ../../Files/Helix.3mf + - name: Build CppNew + run: | + sh Examples/CppNew/GenerateMake.sh + cd Examples/CppNew/build + cmake --build . + ./Example_ExtractInfo ../../Files/Helix.3mf deploy-windows: runs-on: windows-2019 diff --git a/SDK/Examples/CppNew/CMakeLists.txt b/SDK/Examples/CppNew/CMakeLists.txt new file mode 100644 index 000000000..066f9eb1d --- /dev/null +++ b/SDK/Examples/CppNew/CMakeLists.txt @@ -0,0 +1,44 @@ +cmake_minimum_required (VERSION 2.6) +project(Examples) +set(CMAKE_CXX_STANDARD 11) + +# For Linux +set(lib3mf_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Linux/lib/cmake/lib3mf) +find_package(lib3mf REQUIRED Cpp) + +add_definitions(-DTEXTURESPATH="${CMAKE_CURRENT_SOURCE_DIR}/../Files/Textures/") + +add_executable(Example_ColorCube Source/ColorCube.cpp) +target_link_libraries(Example_ColorCube lib3mf::lib3mf) + +add_executable(Example_Components Source/Components.cpp) +target_link_libraries(Example_Components lib3mf::lib3mf) + +add_executable(Example_Converter Source/Converter.cpp) +target_link_libraries(Example_Converter lib3mf::lib3mf) + +add_executable(Example_Cube Source/Cube.cpp) +target_link_libraries(Example_Cube lib3mf::lib3mf) + +add_executable(Example_SecureCube Source/SecureCube.cpp) +target_link_libraries(Example_SecureCube lib3mf::lib3mf) + +add_executable(Example_ExtractInfo Source/ExtractInfo.cpp) +target_link_libraries(Example_ExtractInfo lib3mf::lib3mf) + +add_executable(Example_TextureCube Source/TextureCube.cpp) +target_link_libraries(Example_TextureCube lib3mf::lib3mf) + +add_executable(Example_Slice Source/Slice.cpp) +target_link_libraries(Example_Slice lib3mf::lib3mf) + +add_executable(Example_BeamLattice Source/BeamLattice.cpp) +target_link_libraries(Example_BeamLattice lib3mf::lib3mf) + +if (${MSVC}) + IF(${CMAKE_VERSION} VERSION_LESS 3.6.3) + MESSAGE ("Note: You need to manually select a StartUp-project in Visual Studio.") + ELSE() + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Example_Cube) + ENDIF() +endif() diff --git a/SDK/Examples/CppNew/GenerateMake.sh b/SDK/Examples/CppNew/GenerateMake.sh new file mode 100644 index 000000000..16fe9cf2b --- /dev/null +++ b/SDK/Examples/CppNew/GenerateMake.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +basepath="$(cd "$(dirname "$0")" && pwd)" +builddir="$basepath/build" +mkdir -p $builddir +cd $builddir +cmake .. -G "Unix Makefiles" "$@" \ No newline at end of file diff --git a/SDK/Examples/CppNew/GenerateVS2015.bat b/SDK/Examples/CppNew/GenerateVS2015.bat new file mode 100644 index 000000000..e6933cdeb --- /dev/null +++ b/SDK/Examples/CppNew/GenerateVS2015.bat @@ -0,0 +1,10 @@ +@echo off +set startingDir=%CD% + +set basepath=%~dp0 +set builddir=%basepath%\build +if not exist %builddir% (mkdir %builddir%) +cd %builddir% +cmake -G "Visual Studio 14 2015 Win64" .. %* + +cd %startingDir% diff --git a/SDK/Examples/CppNew/GenerateVS2017.bat b/SDK/Examples/CppNew/GenerateVS2017.bat new file mode 100644 index 000000000..4014d2f99 --- /dev/null +++ b/SDK/Examples/CppNew/GenerateVS2017.bat @@ -0,0 +1,10 @@ +@echo off +set startingDir=%CD% + +set basepath=%~dp0 +set builddir=%basepath%\build +if not exist %builddir% (mkdir %builddir%) +cd %builddir% +cmake -G "Visual Studio 15 2017 Win64" .. %* + +cd %startingDir% diff --git a/SDK/Examples/CppNew/GenerateVS2019.bat b/SDK/Examples/CppNew/GenerateVS2019.bat new file mode 100644 index 000000000..efa4f308f --- /dev/null +++ b/SDK/Examples/CppNew/GenerateVS2019.bat @@ -0,0 +1,10 @@ +@echo off +set startingDir=%CD% + +set basepath=%~dp0 +set builddir=%basepath%\build +if not exist %builddir% (mkdir %builddir%) +cd %builddir% +cmake -G "Visual Studio 16 2019" .. %* + +cd %startingDir% diff --git a/SDK/Examples/CppNew/Source/BeamLattice.cpp b/SDK/Examples/CppNew/Source/BeamLattice.cpp new file mode 100644 index 000000000..c1509cc88 --- /dev/null +++ b/SDK/Examples/CppNew/Source/BeamLattice.cpp @@ -0,0 +1,159 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL MICROSOFT AND/OR NETFABB BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Abstract: + +BeamLattice.cpp : 3MF beamlattice creation example + +--*/ + +#include +#include +#include + +#include "lib3mf_implicit.hpp" + +using namespace Lib3MF; + + +void printVersion(PWrapper wrapper) { + Lib3MF_uint32 nMajor, nMinor, nMicro; + wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); + std::cout << "lib3mf version = " << nMajor << "." << nMinor << "." << nMicro; + std::string sReleaseInfo, sBuildInfo; + if (wrapper->GetPrereleaseInformation(sReleaseInfo)) { + std::cout << "-" << sReleaseInfo; + } + if (wrapper->GetBuildInformation(sBuildInfo)) { + std::cout << "+" << sBuildInfo; + } + std::cout << std::endl; +} + +// Utility functions to create vertices and beams +sLib3MFPosition fnCreateVertex(float x, float y, float z) +{ + sLib3MFPosition result; + result.m_Coordinates[0] = x; + result.m_Coordinates[1] = y; + result.m_Coordinates[2] = z; + return result; +} + +sLib3MFBeam fnCreateBeam(int v0, int v1, double r0, double r1, eLib3MFBeamLatticeCapMode c0, eLib3MFBeamLatticeCapMode c1) +{ + sLib3MFBeam result; + result.m_Indices[0] = v0; + result.m_Indices[1] = v1; + result.m_Radii[0] = r0; + result.m_Radii[1] = r1; + result.m_CapModes[0] = c0; + result.m_CapModes[1] = c1; + return result; +} + + +void BeamLatticeExample() { + PWrapper wrapper = CWrapper::loadLibrary(); + + std::cout << "------------------------------------------------------------------" << std::endl; + std::cout << "3MF Beamlattice example" << std::endl; + printVersion(wrapper); + std::cout << "------------------------------------------------------------------" << std::endl; + + PModel model = wrapper->CreateModel(); + + PMeshObject meshObject = model->AddMeshObject(); + meshObject->SetName("Beamlattice"); + + // Create mesh structure of a cube + std::vector vertices(8); + std::vector triangles(0); + std::vector beams(12); + + float fSizeX = 100.0f; + float fSizeY = 200.0f; + float fSizeZ = 300.0f; + + // Manually create vertices + vertices[0] = fnCreateVertex(0.0f, 0.0f, 0.0f); + vertices[1] = fnCreateVertex(fSizeX, 0.0f, 0.0f); + vertices[2] = fnCreateVertex(fSizeX, fSizeY, 0.0f); + vertices[3] = fnCreateVertex(0.0f, fSizeY, 0.0f); + vertices[4] = fnCreateVertex(0.0f, 0.0f, fSizeZ); + vertices[5] = fnCreateVertex(fSizeX, 0.0f, fSizeZ); + vertices[6] = fnCreateVertex(fSizeX, fSizeY, fSizeZ); + vertices[7] = fnCreateVertex(0.0f, fSizeY, fSizeZ); + + // Manually create beams + double r0 = 1.0; + double r1 = 1.5; + double r2 = 2.0; + double r3 = 2.5; + beams[0] = fnCreateBeam(2, 1, r0, r0, eBeamLatticeCapMode::Butt, eBeamLatticeCapMode::Butt); + beams[1] = fnCreateBeam(0, 3, r0, r1, eBeamLatticeCapMode::Sphere, eBeamLatticeCapMode::Butt); + beams[2] = fnCreateBeam(4, 5, r0, r2, eBeamLatticeCapMode::Sphere, eBeamLatticeCapMode::Butt); + beams[3] = fnCreateBeam(6, 7, r0, r3, eBeamLatticeCapMode::HemiSphere, eBeamLatticeCapMode::Butt); + beams[4] = fnCreateBeam(0, 1, r1, r0, eBeamLatticeCapMode::HemiSphere, eBeamLatticeCapMode::Butt); + beams[5] = fnCreateBeam(5, 4, r1, r1, eBeamLatticeCapMode::Sphere, eBeamLatticeCapMode::HemiSphere); + beams[6] = fnCreateBeam(2, 3, r1, r2, eBeamLatticeCapMode::Sphere, eBeamLatticeCapMode::Sphere); + beams[7] = fnCreateBeam(7, 6, r1, r3, eBeamLatticeCapMode::Butt, eBeamLatticeCapMode::Butt); + beams[8] = fnCreateBeam(1, 2, r2, r2, eBeamLatticeCapMode::Butt, eBeamLatticeCapMode::Butt); + beams[9] = fnCreateBeam(6, 5, r2, r3, eBeamLatticeCapMode::HemiSphere, eBeamLatticeCapMode::Butt); + beams[10] = fnCreateBeam(3, 0, r3, r0, eBeamLatticeCapMode::Butt, eBeamLatticeCapMode::Sphere); + beams[11] = fnCreateBeam(4, 7, r3, r1, eBeamLatticeCapMode::HemiSphere, eBeamLatticeCapMode::HemiSphere); + meshObject->SetGeometry(vertices, triangles); + + // Set beamlattice geometry and metadata + PBeamLattice beamLattice = meshObject->BeamLattice(); + beamLattice->SetBeams(beams); + beamLattice->SetMinLength(0.005); + + PBeamSet set = beamLattice->AddBeamSet(); + set->SetName("Special Beams"); + set->SetIdentifier("bs1"); + std::vector references = { 2,0,5 }; + set->SetReferences(references); + + // Add build item + model->AddBuildItem(meshObject.get(), wrapper->GetIdentityTransform()); + + // Write file + PWriter writer = model->QueryWriter("3mf"); + writer->WriteToFile("beamlattice.3mf"); + + std::cout << "done" << std::endl; +} + +int main() { + try { + BeamLatticeExample(); + } + catch (ELib3MFException &e) { + std::cout << e.what() << std::endl; + return e.getErrorCode(); + } + return 0; +} diff --git a/SDK/Examples/CppNew/Source/ColorCube.cpp b/SDK/Examples/CppNew/Source/ColorCube.cpp new file mode 100644 index 000000000..f1c46baca --- /dev/null +++ b/SDK/Examples/CppNew/Source/ColorCube.cpp @@ -0,0 +1,183 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL MICROSOFT AND/OR NETFABB BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Abstract: + +ColorCube.cpp : 3MF Color Cube creation example + +--*/ + +#include +#include +#include + +#include "lib3mf_implicit.hpp" + +using namespace Lib3MF; + + +void printVersion(PWrapper wrapper) { + Lib3MF_uint32 nMajor, nMinor, nMicro; + wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); + std::cout << "lib3mf version = " << nMajor << "." << nMinor << "." << nMicro; + std::string sReleaseInfo, sBuildInfo; + if (wrapper->GetPrereleaseInformation(sReleaseInfo)) { + std::cout << "-" << sReleaseInfo; + } + if (wrapper->GetBuildInformation(sBuildInfo)) { + std::cout << "+" << sBuildInfo; + } + std::cout << std::endl; +} + +// Utility functions to create vertices and triangles +sLib3MFPosition fnCreateVertex(float x, float y, float z) +{ + sLib3MFPosition result; + result.m_Coordinates[0] = x; + result.m_Coordinates[1] = y; + result.m_Coordinates[2] = z; + return result; +} + +sLib3MFTriangle fnCreateTriangle(int v0, int v1, int v2) +{ + sLib3MFTriangle result; + result.m_Indices[0] = v0; + result.m_Indices[1] = v1; + result.m_Indices[2] = v2; + return result; +} + +sLib3MFTriangleProperties fnCreateTriangleColor(PColorGroup colorGroup, Lib3MF_uint32 colorID1, Lib3MF_uint32 colorID2, Lib3MF_uint32 colorID3) +{ + sLib3MFTriangleProperties sTriangleProperty; + sTriangleProperty.m_ResourceID = colorGroup->GetResourceID(); + sTriangleProperty.m_PropertyIDs[0] = colorID1; + sTriangleProperty.m_PropertyIDs[1] = colorID2; + sTriangleProperty.m_PropertyIDs[2] = colorID3; + return sTriangleProperty; +} + + +void CubeExample() { + PWrapper wrapper = wrapper->loadLibrary(); + + std::cout << "------------------------------------------------------------------" << std::endl; + std::cout << "3MF Color Cube example" << std::endl; + printVersion(wrapper); + std::cout << "------------------------------------------------------------------" << std::endl; + + PModel model = wrapper->CreateModel(); + + PMeshObject meshObject = model->AddMeshObject(); + meshObject->SetName("Colored Box"); + + // Create mesh structure of a cube + std::vector vertices(8); + std::vector triangles(12); + + float fSizeX = 100.0f; + float fSizeY = 200.0f; + float fSizeZ = 300.0f; + + // Manually create vertices + vertices[0] = fnCreateVertex(0.0f, 0.0f, 0.0f); + vertices[1] = fnCreateVertex(fSizeX, 0.0f, 0.0f); + vertices[2] = fnCreateVertex(fSizeX, fSizeY, 0.0f); + vertices[3] = fnCreateVertex(0.0f, fSizeY, 0.0f); + vertices[4] = fnCreateVertex(0.0f, 0.0f, fSizeZ); + vertices[5] = fnCreateVertex(fSizeX, 0.0f, fSizeZ); + vertices[6] = fnCreateVertex(fSizeX, fSizeY, fSizeZ); + vertices[7] = fnCreateVertex(0.0f, fSizeY, fSizeZ); + + // Manually create triangles + triangles[0] = fnCreateTriangle(2, 1, 0); + triangles[1] = fnCreateTriangle(0, 3, 2); + triangles[2] = fnCreateTriangle(4, 5, 6); + triangles[3] = fnCreateTriangle(6, 7, 4); + triangles[4] = fnCreateTriangle(0, 1, 5); + triangles[5] = fnCreateTriangle(5, 4, 0); + triangles[6] = fnCreateTriangle(2, 3, 7); + triangles[7] = fnCreateTriangle(7, 6, 2); + triangles[8] = fnCreateTriangle(1, 2, 6); + triangles[9] = fnCreateTriangle(6, 5, 1); + triangles[10] = fnCreateTriangle(3, 0, 4); + triangles[11] = fnCreateTriangle(4, 7, 3); + + meshObject->SetGeometry(vertices, triangles); + + // define colors + PColorGroup colorGroup = model->AddColorGroup(); + Lib3MF_uint32 idRed = colorGroup->AddColor(wrapper->RGBAToColor(255, 0, 0, 255)); + Lib3MF_uint32 idGreen = colorGroup->AddColor(wrapper->RGBAToColor(0, 255, 0, 255)); + Lib3MF_uint32 idBlue = colorGroup->AddColor(wrapper->RGBAToColor(0, 0, 255, 255)); + Lib3MF_uint32 idOrange = colorGroup->AddColor(wrapper->RGBAToColor(255, 128, 0, 255)); + Lib3MF_uint32 idYellow = colorGroup->AddColor(wrapper->RGBAToColor(255, 255, 0, 255)); + + sLib3MFTriangleProperties sTriangleColorRed = fnCreateTriangleColor(colorGroup, idRed, idRed, idRed); + sLib3MFTriangleProperties sTriangleColorGreen = fnCreateTriangleColor(colorGroup, idGreen, idGreen, idGreen); + sLib3MFTriangleProperties sTriangleColorBlue = fnCreateTriangleColor(colorGroup, idBlue, idBlue, idBlue); + + sLib3MFTriangleProperties sTriangleColor1 = fnCreateTriangleColor(colorGroup, idOrange, idRed, idYellow); + sLib3MFTriangleProperties sTriangleColor2 = fnCreateTriangleColor(colorGroup, idYellow, idGreen, idOrange); + + // One-colored Triangles + meshObject->SetTriangleProperties(0, sTriangleColorRed); + meshObject->SetTriangleProperties(1, sTriangleColorRed); + meshObject->SetTriangleProperties(2, sTriangleColorGreen); + meshObject->SetTriangleProperties(3, sTriangleColorGreen); + meshObject->SetTriangleProperties(4, sTriangleColorBlue); + meshObject->SetTriangleProperties(5, sTriangleColorBlue); + // Gradient-colored Triangles + meshObject->SetTriangleProperties(6, sTriangleColor1); + meshObject->SetTriangleProperties(7, sTriangleColor2); + meshObject->SetTriangleProperties(8, sTriangleColor1); + meshObject->SetTriangleProperties(9, sTriangleColor2); + meshObject->SetTriangleProperties(10, sTriangleColor1); + meshObject->SetTriangleProperties(11, sTriangleColor2); + + // Object Level Property + meshObject->SetObjectLevelProperty(sTriangleColorRed.m_ResourceID, sTriangleColorRed.m_PropertyIDs[0]); + + // Add build item + model->AddBuildItem(meshObject.get(), wrapper->GetIdentityTransform()); + + PWriter writer = model->QueryWriter("3mf"); + writer->WriteToFile("colorcube.3mf"); + + std::cout << "done" << std::endl; +} + +int main() { + try { + CubeExample(); + } + catch (ELib3MFException &e) { + std::cout << e.what() << std::endl; + return e.getErrorCode(); + } + return 0; +} diff --git a/SDK/Examples/CppNew/Source/Components.cpp b/SDK/Examples/CppNew/Source/Components.cpp new file mode 100644 index 000000000..f91499024 --- /dev/null +++ b/SDK/Examples/CppNew/Source/Components.cpp @@ -0,0 +1,183 @@ + +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL MICROSOFT AND/OR NETFABB BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Abstract: + +Components.cpp : 3MF Components example + +--*/ + +#include +#include +#include + +#include "lib3mf_implicit.hpp" + +using namespace Lib3MF; + + +void printVersion(PWrapper wrapper) { + Lib3MF_uint32 nMajor, nMinor, nMicro; + wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); + std::cout << "lib3mf version = " << nMajor << "." << nMinor << "." << nMicro; + std::string sReleaseInfo, sBuildInfo; + if (wrapper->GetPrereleaseInformation(sReleaseInfo)) { + std::cout << "-" << sReleaseInfo; + } + if (wrapper->GetBuildInformation(sBuildInfo)) { + std::cout << "+" << sBuildInfo; + } + std::cout << std::endl; +} + +// Utility functions to create vertices and triangles +sLib3MFPosition fnCreateVertex(float x, float y, float z) +{ + sLib3MFPosition result; + result.m_Coordinates[0] = x; + result.m_Coordinates[1] = y; + result.m_Coordinates[2] = z; + return result; +} + +sLib3MFTriangle fnCreateTriangle(int v0, int v1, int v2) +{ + sLib3MFTriangle result; + result.m_Indices[0] = v0; + result.m_Indices[1] = v1; + result.m_Indices[2] = v2; + return result; +} + +sLib3MFTransform createTranslationMatrix(float x, float y, float z) +{ + sLib3MFTransform mMatrix; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 3; j++) { + mMatrix.m_Fields[i][j] = (i == j) ? 1.0f : 0.0f; + } + } + + mMatrix.m_Fields[3][0] = x; + mMatrix.m_Fields[3][1] = y; + mMatrix.m_Fields[3][2] = z; + + return mMatrix; +} + + +void ComponentsExample() { + PWrapper wrapper = CWrapper::loadLibrary(); + + std::cout << "------------------------------------------------------------------" << std::endl; + std::cout << "3MF Components example" << std::endl; + printVersion(wrapper); + std::cout << "------------------------------------------------------------------" << std::endl; + + PModel model = wrapper->CreateModel(); + + PMeshObject meshObject = model->AddMeshObject(); + meshObject->SetName("Box"); + + // Create mesh structure of a cube + std::vector vertices(8); + std::vector triangles(12); + + float fSizeX = 10.0f; + float fSizeY = 20.0f; + float fSizeZ = 30.0f; + + // Manually create vertices + vertices[0] = fnCreateVertex(0.0f, 0.0f, 0.0f); + vertices[1] = fnCreateVertex(fSizeX, 0.0f, 0.0f); + vertices[2] = fnCreateVertex(fSizeX, fSizeY, 0.0f); + vertices[3] = fnCreateVertex(0.0f, fSizeY, 0.0f); + vertices[4] = fnCreateVertex(0.0f, 0.0f, fSizeZ); + vertices[5] = fnCreateVertex(fSizeX, 0.0f, fSizeZ); + vertices[6] = fnCreateVertex(fSizeX, fSizeY, fSizeZ); + vertices[7] = fnCreateVertex(0.0f, fSizeY, fSizeZ); + + // Manually create triangles + triangles[0] = fnCreateTriangle(2, 1, 0); + triangles[1] = fnCreateTriangle(0, 3, 2); + triangles[2] = fnCreateTriangle(4, 5, 6); + triangles[3] = fnCreateTriangle(6, 7, 4); + triangles[4] = fnCreateTriangle(0, 1, 5); + triangles[5] = fnCreateTriangle(5, 4, 0); + triangles[6] = fnCreateTriangle(2, 3, 7); + triangles[7] = fnCreateTriangle(7, 6, 2); + triangles[8] = fnCreateTriangle(1, 2, 6); + triangles[9] = fnCreateTriangle(6, 5, 1); + triangles[10] = fnCreateTriangle(3, 0, 4); + triangles[11] = fnCreateTriangle(4, 7, 3); + + meshObject->SetGeometry(vertices, triangles); + + // Create Component Object + PComponentsObject componentsObject = model->AddComponentsObject(); + + // Add first component + componentsObject->AddComponent(meshObject.get(), createTranslationMatrix(0.0f, 0.0f, 0.0f)); + + // Add second component + componentsObject->AddComponent(meshObject.get(), createTranslationMatrix(40.0f, 60.0f, 80.0f)); + + // Add third component + componentsObject->AddComponent(meshObject.get(), createTranslationMatrix(120.0f, 30.0f, 70.0f)); + + + // Add componentsobject as build item + model->AddBuildItem(componentsObject.get(), createTranslationMatrix(0.0f, 0.0f, 0.0f)); + + // Add translated componentsobject as build item + model->AddBuildItem(componentsObject.get(), createTranslationMatrix(200.0f, 40.0f, 10.0f)); + + // Add translated meshobject as build item + model->AddBuildItem(meshObject.get(), createTranslationMatrix(-40.0f, 0.0f, 20.0f)); + + // Output scene as STL and 3MF + PWriter _3mfWriter = model->QueryWriter("3mf"); + std::cout << "writing components.3mf..." << std::endl; + _3mfWriter->WriteToFile("components.3mf"); + + PWriter stlWriter = model->QueryWriter("stl"); + std::cout << "writing components.stl..." << std::endl; + stlWriter->WriteToFile("components.stl"); + + std::cout << "done" << std::endl; +} + +int main() { + try { + ComponentsExample(); + } + catch (ELib3MFException &e) { + std::cout << e.what() << std::endl; + return e.getErrorCode(); + } + return 0; +} + diff --git a/SDK/Examples/CppNew/Source/Converter.cpp b/SDK/Examples/CppNew/Source/Converter.cpp new file mode 100644 index 000000000..2fefdbc56 --- /dev/null +++ b/SDK/Examples/CppNew/Source/Converter.cpp @@ -0,0 +1,154 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL MICROSOFT AND/OR NETFABB BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Abstract: + +Converter.cpp : Can convert 3MFs to STL and back + +--*/ + +#include +#include +#include + +#ifndef __GNUC__ +#include +#endif + +#include "lib3mf_implicit.hpp" + +using namespace Lib3MF; + + +void printVersion(PWrapper wrapper) { + Lib3MF_uint32 nMajor, nMinor, nMicro; + wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); + std::cout << "lib3mf version = " << nMajor << "." << nMinor << "." << nMicro; + std::string sReleaseInfo, sBuildInfo; + if (wrapper->GetPrereleaseInformation(sReleaseInfo)) { + std::cout << "-" << sReleaseInfo; + } + if (wrapper->GetBuildInformation(sBuildInfo)) { + std::cout << "+" << sBuildInfo; + } + std::cout << std::endl; +} + +std::string FindExtension(std::string filename) { + // this emulates Windows' PathFindExtension + std::string::size_type idx; + idx = filename.rfind('.'); + + if (idx != std::string::npos) + { + return filename.substr(idx); + } + else + { + return ""; + } +} + + +int convert(std::string sFilename) { + PWrapper wrapper = CWrapper::loadLibrary(); + + std::cout << "------------------------------------------------------------------" << std::endl; + std::cout << "3MF Model Converter" << std::endl; + printVersion(wrapper); + std::cout << "------------------------------------------------------------------" << std::endl; + + // Extract Extension of filename + std::string sReaderName; + std::string sWriterName; + std::string sNewExtension; + std::string sExtension = FindExtension(sFilename); + std::transform(sExtension.begin(), sExtension.end(), sExtension.begin(), ::tolower); + + // Which Reader and Writer classes do we need? + if (sExtension == ".stl") { + sReaderName = "stl"; + sWriterName = "3mf"; + sNewExtension = ".3mf"; + } + if (sExtension == ".3mf") { + sReaderName = "3mf"; + sWriterName = "stl"; + sNewExtension = ".stl"; + } + if (sReaderName.length() == 0) { + std::cout << "unknown input file extension:" << sExtension << std::endl; + return -1; + } + + // Create new filename + std::string sOutputFilename = sFilename; + sOutputFilename.erase(sOutputFilename.length() - sExtension.length()); + sOutputFilename += sNewExtension; + + PModel model = wrapper->CreateModel(); + PReader reader = model->QueryReader(sReaderName); + + // Import Model from File + std::cout << "reading " << sFilename << "..." << std::endl; +#ifndef __GNUC__ + ULONGLONG nStartTicks = GetTickCount64(); +#endif + reader->ReadFromFile(sFilename); +#ifndef __GNUC__ + std::cout << "elapsed time: " << (GetTickCount64() - nStartTicks) << "ms" << std::endl; +#endif + + PWriter writer = model->QueryWriter(sWriterName); + std::cout << "writing " << sOutputFilename << "..." << std::endl; +#ifndef __GNUC__ + nStartTicks = GetTickCount64(); +#endif + writer->WriteToFile(sOutputFilename); +#ifndef __GNUC__ + std::cout << "elapsed time: " << (GetTickCount64() - nStartTicks) << "ms" << std::endl; +#endif + std::cout << "done" << std::endl; + return 0; +} + +int main(int argc, char** argv) { + // Parse Arguments + if (argc != 2) { + std::cout << "Usage: " << std::endl; + std::cout << "Convert 3MF to STL: Converter.exe model.3mf" << std::endl; + std::cout << "Convert STL to 3MF: Converter.exe model.stl" << std::endl; + return 0; + } + + try { + return convert(argv[1]); + } + catch (ELib3MFException &e) { + std::cout << e.what() << std::endl; + return e.getErrorCode(); + } + return 0; +} diff --git a/SDK/Examples/CppNew/Source/Cube.cpp b/SDK/Examples/CppNew/Source/Cube.cpp new file mode 100644 index 000000000..18e99cb51 --- /dev/null +++ b/SDK/Examples/CppNew/Source/Cube.cpp @@ -0,0 +1,140 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL MICROSOFT AND/OR NETFABB BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Abstract: + +Cube.cpp : 3MF Cube creation example + +--*/ + +#include +#include +#include + +#include "lib3mf_implicit.hpp" + +using namespace Lib3MF; + + +void printVersion(PWrapper wrapper) { + Lib3MF_uint32 nMajor, nMinor, nMicro; + wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); + std::cout << "lib3mf version = " << nMajor << "." << nMinor << "." << nMicro; + std::string sReleaseInfo, sBuildInfo; + if (wrapper->GetPrereleaseInformation(sReleaseInfo)) { + std::cout << "-" << sReleaseInfo; + } + if (wrapper->GetBuildInformation(sBuildInfo)) { + std::cout << "+" << sBuildInfo; + } + std::cout << std::endl; +} + +// Utility functions to create vertices and triangles +sLib3MFPosition fnCreateVertex(float x, float y, float z) +{ + sLib3MFPosition result; + result.m_Coordinates[0] = x; + result.m_Coordinates[1] = y; + result.m_Coordinates[2] = z; + return result; +} + +sLib3MFTriangle fnCreateTriangle(int v0, int v1, int v2) +{ + sLib3MFTriangle result; + result.m_Indices[0] = v0; + result.m_Indices[1] = v1; + result.m_Indices[2] = v2; + return result; +} + + +void CubeExample() { + PWrapper wrapper = CWrapper::loadLibrary(); + + std::cout << "------------------------------------------------------------------" << std::endl; + std::cout << "3MF Cube example" << std::endl; + printVersion(wrapper); + std::cout << "------------------------------------------------------------------" << std::endl; + + PModel model = wrapper->CreateModel(); + + PMeshObject meshObject = model->AddMeshObject(); + meshObject->SetName("Box"); + + // Create mesh structure of a cube + std::vector vertices(8); + std::vector triangles(12); + + float fSizeX = 100.0f; + float fSizeY = 200.0f; + float fSizeZ = 300.0f; + + // Manually create vertices + vertices[0] = fnCreateVertex(0.0f, 0.0f, 0.0f); + vertices[1] = fnCreateVertex(fSizeX, 0.0f, 0.0f); + vertices[2] = fnCreateVertex(fSizeX, fSizeY, 0.0f); + vertices[3] = fnCreateVertex(0.0f, fSizeY, 0.0f); + vertices[4] = fnCreateVertex(0.0f, 0.0f, fSizeZ); + vertices[5] = fnCreateVertex(fSizeX, 0.0f, fSizeZ); + vertices[6] = fnCreateVertex(fSizeX, fSizeY, fSizeZ); + vertices[7] = fnCreateVertex(0.0f, fSizeY, fSizeZ); + + // Manually create triangles + triangles[0] = fnCreateTriangle(2, 1, 0); + triangles[1] = fnCreateTriangle(0, 3, 2); + triangles[2] = fnCreateTriangle(4, 5, 6); + triangles[3] = fnCreateTriangle(6, 7, 4); + triangles[4] = fnCreateTriangle(0, 1, 5); + triangles[5] = fnCreateTriangle(5, 4, 0); + triangles[6] = fnCreateTriangle(2, 3, 7); + triangles[7] = fnCreateTriangle(7, 6, 2); + triangles[8] = fnCreateTriangle(1, 2, 6); + triangles[9] = fnCreateTriangle(6, 5, 1); + triangles[10] = fnCreateTriangle(3, 0, 4); + triangles[11] = fnCreateTriangle(4, 7, 3); + + meshObject->SetGeometry(vertices, triangles); + + // Add build item + model->AddBuildItem(meshObject.get(), wrapper->GetIdentityTransform()); + + PWriter writer = model->QueryWriter("3mf"); + writer->WriteToFile("cube.3mf"); + + std::cout << "done" << std::endl; +} + +int main() { + try { + CubeExample(); + } + catch (ELib3MFException &e) { + std::cout << e.what() << std::endl; + return e.getErrorCode(); + } + return 0; +} diff --git a/SDK/Examples/CppNew/Source/ExtractInfo.cpp b/SDK/Examples/CppNew/Source/ExtractInfo.cpp new file mode 100644 index 000000000..661cd30f2 --- /dev/null +++ b/SDK/Examples/CppNew/Source/ExtractInfo.cpp @@ -0,0 +1,269 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL MICROSOFT AND/OR NETFABB BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Abstract: + +ExtractInfo.cpp : 3MF Read Example + +--*/ + +#include +#include +#include + +#include "lib3mf_implicit.hpp" + +using namespace Lib3MF; + + +void printVersion(PWrapper wrapper) { + Lib3MF_uint32 nMajor, nMinor, nMicro; + wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); + std::cout << "lib3mf version = " << nMajor << "." << nMinor << "." << nMicro; + std::string sReleaseInfo, sBuildInfo; + if (wrapper->GetPrereleaseInformation(sReleaseInfo)) { + std::cout << "-" << sReleaseInfo; + } + if (wrapper->GetBuildInformation(sBuildInfo)) { + std::cout << "+" << sBuildInfo; + } + std::cout << std::endl; +} + +void ShowThumbnailInformation(PModel model) +{ + /* + // TODO: this is not yet implemented in Lib3MF + */ +} + + +void ShowMetaDataInformation(PMetaDataGroup metaDataGroup) +{ + Lib3MF_uint32 nMetaDataCount = metaDataGroup->GetMetaDataCount(); + + for (Lib3MF_uint32 iMeta = 0; iMeta < nMetaDataCount; iMeta++) { + + PMetaData metaData = metaDataGroup->GetMetaData(iMeta); + std::string sMetaDataValue = metaData->GetValue(); + std::string sMetaDataName = metaData->GetName(); + std::cout << "Metadatum: " << iMeta << ":" << std::endl; + std::cout << "Name = \"" << sMetaDataName << "\"" << std::endl; + std::cout << "Value = \"" << sMetaDataValue << "\"" << std::endl; + } +} + +void ShowSliceStack(PSliceStack sliceStack, std::string indent) +{ + std::cout << indent << "SliceStackID: " << sliceStack->GetResourceID() << std::endl; + if (sliceStack->GetSliceCount() > 0) { + std::cout << indent << " Slice count: " << sliceStack->GetSliceCount() << std::endl; + } + if (sliceStack->GetSliceRefCount() > 0) { + std::cout << indent << " Slice ref count: " << sliceStack->GetSliceRefCount() << std::endl; + for (Lib3MF_uint64 iSliceRef = 0; iSliceRef < sliceStack->GetSliceRefCount(); iSliceRef++) { + std::cout << indent << " Slice ref : " << sliceStack->GetSliceStackReference(iSliceRef)->GetResourceID() << std::endl; + } + } +} + +void ShowObjectProperties(PObject object) +{ + std::cout << " Name: \"" << object->GetName() << "\"" << std::endl; + std::cout << " PartNumber: \"" << object->GetPartNumber() << "\"" << std::endl; + + switch (object->GetType()) { + case eObjectType::Model: + std::cout << " Object type: model" << std::endl; + break; + case eObjectType::Support: + std::cout << " Object type: support" << std::endl; + break; + case eObjectType::SolidSupport: + std::cout << " Object type: solidsupport" << std::endl; + break; + case eObjectType::Other: + std::cout << " Object type: other" << std::endl; + break; + default: + std::cout << " Object type: invalid" << std::endl; + break; + } + + if (object->HasSlices(false)) { + PSliceStack sliceStack = object->GetSliceStack(); + ShowSliceStack(sliceStack, " "); + } + + if (object->GetMetaDataGroup()->GetMetaDataCount() > 0) { + ShowMetaDataInformation(object->GetMetaDataGroup()); + } +} + +void ShowMeshObjectInformation(PMeshObject meshObject) +{ + std::cout << "mesh object #" << meshObject->GetResourceID() << ": " << std::endl; + + ShowObjectProperties(meshObject); + + Lib3MF_uint64 nVertexCount = meshObject->GetVertexCount(); + Lib3MF_uint64 nTriangleCount = meshObject->GetTriangleCount(); + PBeamLattice beamLattice = meshObject->BeamLattice(); + + // Output data + std::cout << " Vertex count: " << nVertexCount << std::endl; + std::cout << " Triangle count: " << nTriangleCount << std::endl; + + Lib3MF_uint64 nBeamCount = beamLattice->GetBeamCount(); + if (nBeamCount > 0) { + std::cout << " Beam count: " << nBeamCount << std::endl; + Lib3MF_uint32 nRepresentationMesh; + if (beamLattice->GetRepresentation(nRepresentationMesh)) + std::cout << " |_Representation Mesh ID: " << nRepresentationMesh << std::endl; + eLib3MFBeamLatticeClipMode eClipMode; + Lib3MF_uint32 nClippingMesh; + beamLattice->GetClipping(eClipMode, nClippingMesh); + if (eClipMode != eBeamLatticeClipMode::NoClipMode) + std::cout << " |_Clipping Mesh ID: " << nClippingMesh << "(mode=" << (int)eClipMode << ")" << std::endl; + if (beamLattice->GetBeamSetCount() > 0) { + std::cout << " |_BeamSet count: " << beamLattice->GetBeamSetCount() << std::endl; + } + } + +} + +void ShowTransform(sLib3MFTransform transform, std::string indent) { + std::cout << indent << "Transformation: [ " << transform.m_Fields[0][0] << " " << transform.m_Fields[1][0] << " " << transform.m_Fields[2][0] << " " << transform.m_Fields[3][0] << " ]" << std::endl; + std::cout << indent << " [ " << transform.m_Fields[0][1] << " " << transform.m_Fields[1][1] << " " << transform.m_Fields[2][1] << " " << transform.m_Fields[3][1] << " ]" << std::endl; + std::cout << indent << " [ " << transform.m_Fields[0][2] << " " << transform.m_Fields[1][2] << " " << transform.m_Fields[2][2] << " " << transform.m_Fields[3][2] << " ]" << std::endl; +} + +void ShowComponentsObjectInformation(PComponentsObject componentsObject) +{ + std::cout << "components object #" << componentsObject->GetResourceID() << ": " << std::endl; + + ShowObjectProperties(componentsObject); + std::cout << " Component count: " << componentsObject->GetComponentCount() << std::endl; + for (Lib3MF_uint32 nIndex = 0; nIndex < componentsObject->GetComponentCount(); nIndex++) { + PComponent component = componentsObject->GetComponent(nIndex); + + std::cout << " Component " << nIndex << ": Object ID: " << component->GetObjectResourceID() << std::endl; + if (component->HasTransform()) { + ShowTransform(component->GetTransform(), " "); + } + else { + std::cout << " Transformation: none" << std::endl; + } + } +} + + +void ExtractInfoExample(std::string sFileName) { + PWrapper wrapper = CWrapper::loadLibrary(); + + std::cout << "------------------------------------------------------------------" << std::endl; + std::cout << "3MF Read example" << std::endl; + printVersion(wrapper); + std::cout << "------------------------------------------------------------------" << std::endl; + + PModel model = wrapper->CreateModel(); + + // Import Model from 3MF File + { + PReader reader = model->QueryReader("3mf"); + // And deactivate the strict mode (default is "false", anyway. This just demonstrates where/how to use it). + reader->SetStrictModeActive(false); + reader->ReadFromFile(sFileName); + + for (Lib3MF_uint32 iWarning = 0; iWarning < reader->GetWarningCount(); iWarning++) { + Lib3MF_uint32 nErrorCode; + std::string sWarningMessage = reader->GetWarning(iWarning, nErrorCode); + std::cout << "Encountered warning #" << nErrorCode << " : " << sWarningMessage << std::endl; + } + } + ShowThumbnailInformation(model); + + ShowMetaDataInformation(model->GetMetaDataGroup()); + + PSliceStackIterator sliceStacks = model->GetSliceStacks(); + while (sliceStacks->MoveNext()) { + PSliceStack sliceStack = sliceStacks->GetCurrentSliceStack(); + ShowSliceStack(sliceStack, ""); + } + + PObjectIterator objectIterator = model->GetObjects(); + while (objectIterator->MoveNext()) { + PObject object = objectIterator->GetCurrentObject(); + if (object->IsMeshObject()) { + ShowMeshObjectInformation(model->GetMeshObjectByID(object->GetResourceID())); + } + else if (object->IsComponentsObject()) { + ShowComponentsObjectInformation(model->GetComponentsObjectByID(object->GetResourceID())); + } + else { + std::cout << "unknown object #" << object->GetResourceID() << ": " << std::endl; + } + } + + + PBuildItemIterator buildItemIterator = model->GetBuildItems(); + while (buildItemIterator->MoveNext()) { + PBuildItem buildItem = buildItemIterator->GetCurrent(); + + std::cout << "Build item (Object #" << buildItem->GetObjectResourceID() << "): " << std::endl; + + if (buildItem->HasObjectTransform()) { + ShowTransform(buildItem->GetObjectTransform(), " "); + } + else { + std::cout << " Transformation: none" << std::endl; + } + std::cout << " Part number: \"" << buildItem->GetPartNumber() << "\"" << std::endl; + if (buildItem->GetMetaDataGroup()->GetMetaDataCount() > 0) { + ShowMetaDataInformation(buildItem->GetMetaDataGroup()); + } + } + + std::cout << "done" << std::endl; +} + + +int main(int argc, char** argv) { + // Parse Arguments + if (argc != 2) { + std::cout << "Usage: " << std::endl; + std::cout << "ExtractInfo.exe model.3mf" << std::endl; + return 0; + } + + try { + ExtractInfoExample(argv[1]); + } + catch (ELib3MFException &e) { + std::cout << e.what() << std::endl; + return e.getErrorCode(); + } + return 0; +} diff --git a/SDK/Examples/CppNew/Source/SecureCube.cpp b/SDK/Examples/CppNew/Source/SecureCube.cpp new file mode 100644 index 000000000..de966b61f --- /dev/null +++ b/SDK/Examples/CppNew/Source/SecureCube.cpp @@ -0,0 +1,487 @@ +/*++ + +Copyright (C) 2020 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL MICROSOFT AND/OR NETFABB BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Abstract: + +SecureCube.cpp : 3MF encrypted Cube creation and read example. This is a sample +skeleton code provided to guide you to the process of reading and writing a 3MF +file using the Secure Content spec. Encryption and decryption processes are abstracted +so to avoid binding this sample to any particular implementation. If you would like +to check a working version of the process, there's a unit tests available on the 3MF code +base that implements the entire workflow using LibreSSL: EncryptionMethods.cpp +Tip: you could also copy buffers around - file won't be valid but you will be able +to run the entire process. +--*/ + +#include +#include +#include +#include + +#include "lib3mf_implicit.hpp" + +using namespace Lib3MF; + + +namespace SecureContentCallbacks { + // Sample random number generation callback. Do not use this beyond the scope of this example as it is not really a random number generation function. + static void NotRandomBytesAtAll(Lib3MF_uint64 byteData, Lib3MF_uint64 size, Lib3MF_pvoid userData, Lib3MF_uint64 * bytesWritten) { + static Lib3MF_uint8 random = 0; + Lib3MF_uint8 * buffer = (Lib3MF_uint8 *)byteData; + *bytesWritten = size; + while (size > 0) + *(buffer + (--size)) = ++random; + } + + // Structure to hold encryption context for keys + struct KeyWrappingCbData { + CWrapper * wrapper; + }; + + + // Structure to hold encryption context for resources + struct ContentEncryptionCbData { + CWrapper * wrapper; + std::map context; + }; + + // Sample callback to wrap the key of an encryption process + static void WriteKeyWrappingCbSample( + Lib3MF_AccessRight access, + Lib3MF_uint64 inSize, + const Lib3MF_uint8 * inBuffer, + const Lib3MF_uint64 outSize, + Lib3MF_uint64 * outNeeded, + Lib3MF_uint8 * outBuffer, + Lib3MF_pvoid userData, + Lib3MF_uint64 * status) { + + KeyWrappingCbData * cp = (KeyWrappingCbData *)userData; + + // Since we're using CAccessRight constructure, we have to account for + // the use of 'access' by calling Acquire on the CWrapper + CAccessRight accessRight(cp->wrapper, access); + cp->wrapper->Acquire(&accessRight); + + // This is going to be called for each consumer you've registered to + PConsumer consumer = accessRight.GetConsumer(); + std::string consumerId = consumer->GetConsumerID(); + std::cout << "ConsumerID " << consumer->GetConsumerID() << std::endl; + // You can also check for keyid and keyvalue + + // A call could be made to first identify what the output buffer size should be. + // In that case, outSize will be 0 or outBuffer will be null, and the proper size must be placed in outNeeded. + if (nullptr == outBuffer || outSize == 0) { + *outNeeded = inSize; + *status = inSize; + return; + } + + // Query the data about the encryption process to be done + eWrappingAlgorithm algorithm = accessRight.GetWrappingAlgorithm(); + eMgfAlgorithm mask = accessRight.GetMgfAlgorithm(); + eDigestMethod diges = accessRight.GetDigestMethod(); + + // You should deal with the encryption process of the key. + // Use the encryption process to wrap inBuffer (plain) into outBuffer (cipher) using details above. + // Use KeyWrappingCbData to hold any information you'll be needing at this point. + throw std::runtime_error("TODO: Add your encryption wrapping process here"); + //std::copy(inBuffer, inBuffer + outSize, outBuffer); + + // Finally, this function should use status to return the number of bytes needed, + // encrypted - or zero to indicate a failure. + *status = outSize; + } + + // Sample callback to encrypt contents of a resource + static void WriteContentEncryptionCbSample( + Lib3MF_ContentEncryptionParams params, + Lib3MF_uint64 inSize, + const Lib3MF_uint8 * inBuffer, + const Lib3MF_uint64 outSize, + Lib3MF_uint64 * outNeededSize, + Lib3MF_uint8 * outBuffer, + Lib3MF_pvoid userData, + Lib3MF_uint64 * status) { + + ContentEncryptionCbData * cb = (ContentEncryptionCbData *)userData; + + // Since we're using CAccessRight constructure, we have to account for + // the use of 'access' by calling Acquire on the CWrapper + CContentEncryptionParams cd(cb->wrapper, params); + cb->wrapper->Acquire(&cd); + + // A descriptor uniquely identifies the encryption process for a resource + Lib3MF_uint64 descriptor = cd.GetDescriptor(); + + // You can map the descriptor in use as you'll probably keep several + // contexts initialized at same time + auto localDescriptor = cb->context.find(cd.GetDescriptor()); + if (localDescriptor != cb->context.end()) + // Use an existing context + localDescriptor->second++; + else { + // Initialize a new context + + // Retrieve the encryption key, if there is one + std::vector key; + cd.GetKey(key); + + // You can also use keyuuid to look up a key externally + std::string keyUUID = cd.GetKeyUUID(); + + // Retrieve the additional authenticaton data, if it has been used to encrypt + std::vector aad; + cd.GetAdditionalAuthenticationData(aad); + + // TODO: Initialize the encryption context + cb->context[cd.GetDescriptor()] = 0; + } + + // Attention to the order in which params are tested, it matters + if (0 == inSize || nullptr == inBuffer) { + // When input buffer is null or input size is 0, this is a request + // to finalize this encryption process and generating the authentication tag + // TODO: generate proper tag + std::vector tag = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + cd.SetAuthenticationTag(tag); + //add tag verification status here + *status = tag.size(); + } else if (0 == outSize || nullptr == outBuffer) { + // If outSize is zero or outBuffer is null (but inSize and inBuffer are not), + // this is a call to figure out the output buffer size. + // Put the respective value in outNeededSize. + *outNeededSize = inSize; + *status = inSize; + } else { + // Else, perform the encryption process + throw std::runtime_error("TODO: Add your encryption process here"); + //std::copy(inBuffer, inBuffer + outSize, outBuffer); + *status = outSize; + } + //This function should use status to return the number of bytes needed, encrypted + // or verified - or zero to indicate a failure. + } + + static void ReadKeyWrappingCbSample( + Lib3MF_AccessRight access, + Lib3MF_uint64 inSize, + const Lib3MF_uint8 * inBuffer, + const Lib3MF_uint64 outSize, + Lib3MF_uint64 * outNeeded, + Lib3MF_uint8 * outBuffer, + Lib3MF_pvoid userData, + Lib3MF_uint64 * status) { + + // A call could be made to first identify what the output buffer size should be. + // In that case, outSize will be 0 or outBuffer will be null, and the proper size must be placed in outNeeded. + if (nullptr == outBuffer || outSize == 0) { + *outNeeded = inSize; + *status = inSize; + return; + } + + KeyWrappingCbData * cp = (KeyWrappingCbData *)userData; + + // Since we're using CAccessRight constructure, we have to account for + // the use of 'access' by calling Acquire on the CWrapper + CAccessRight accessRight(cp->wrapper, access); + cp->wrapper->Acquire(&accessRight); + + // This is going to be called for each consumer you've registered to + PConsumer consumer = accessRight.GetConsumer(); + std::string consumerId = consumer->GetConsumerID(); + std::cout << "ConsumerID " << consumer->GetConsumerID() << std::endl; + // You can also check for keyid and keyvalue + + // Query the data about the encryption process to be done + eWrappingAlgorithm algorithm = accessRight.GetWrappingAlgorithm(); + eMgfAlgorithm mask = accessRight.GetMgfAlgorithm(); + eDigestMethod diges = accessRight.GetDigestMethod(); + + // You should deal with the encryption process of the key. + // Use the encryption process to wrap inBuffer (cipher) into outBuffer (plain) using details above. + // Use KeyWrappingCbData to hold any information you'll be needing at this point. + throw std::runtime_error("TODO: Add your decryption wrapping process here"); + //std::copy(inBuffer, inBuffer + outSize, outBuffer); + + // Finally, this function should use status to return the number of bytes needed, + // decrypted - or zero to indicate a failure. + *status = outSize; + } + + static void ReadContentEncryptionCbSample( + Lib3MF_ContentEncryptionParams params, + Lib3MF_uint64 inSize, + const Lib3MF_uint8 * inBuffer, + const Lib3MF_uint64 outSize, + Lib3MF_uint64 * outNeededSize, + Lib3MF_uint8 * outBuffer, + Lib3MF_pvoid userData, + Lib3MF_uint64 * status) { + + ContentEncryptionCbData * cb = (ContentEncryptionCbData *)userData; + + // Since we're using CAccessRight constructure, we have to account for + // the use of 'access' by calling Acquire on the CWrapper + CContentEncryptionParams cd(cb->wrapper, params); + cb->wrapper->Acquire(&cd); + + // A descriptor uniquely identifies the encryption process for a resource + Lib3MF_uint64 descriptor = cd.GetDescriptor(); + + // You can map the descriptor in use as you'll probably keep several + // contexts initialized at same time + auto localDescriptor = cb->context.find(cd.GetDescriptor()); + if (localDescriptor != cb->context.end()) + // Use an existing context + localDescriptor->second++; + else { + // Initialize a new context + + // Retrieve the encryption key, if there is one + std::vector key; + cd.GetKey(key); + + // You can also use keyuuid to look up a key externally + std::string keyUUID = cd.GetKeyUUID(); + + // Retrieve the additional authenticaton data, if it has been used to encrypt + std::vector aad; + cd.GetAdditionalAuthenticationData(aad); + + // TODO: Initialize the encryption context + cb->context[cd.GetDescriptor()] = 0; + } + + // Attention to the order in which params are tested, it matters + if (0 == inSize || nullptr == inBuffer) { + // When input buffer is null or input size is 0, this is a request + // to finalize this encryption process and verify the authentication tag + std::vector tag; + cd.GetAuthenticationTag(tag); + // TODO: verify tag + *status = tag.size(); + } else if (0 == outSize || nullptr == outBuffer) { + // If outSize is zero or outBuffer is null (but inSize and inBuffer are not), + // this is a call to figure out the output buffer size. + // Put the respective value in outNeededSize. + *outNeededSize = inSize; + *status = inSize; + return; + } else { + // Else, perform the descryption process + throw std::runtime_error("TODO: Add your encryption process here"); + //std::copy(inBuffer, inBuffer + outSize, outBuffer); + *status = outSize; + } + //This function should use status to return the number of bytes needed, decrypted + // or verified - or zero to indicate a failure. + } +}; + +void printVersion(CWrapper & wrapper) { + Lib3MF_uint32 nMajor, nMinor, nMicro; + wrapper.GetLibraryVersion(nMajor, nMinor, nMicro); + std::cout << "lib3mf version = " << nMajor << "." << nMinor << "." << nMicro; + std::string sReleaseInfo, sBuildInfo; + if (wrapper.GetPrereleaseInformation(sReleaseInfo)) { + std::cout << "-" << sReleaseInfo; + } + if (wrapper.GetBuildInformation(sBuildInfo)) { + std::cout << "+" << sBuildInfo; + } + std::cout << std::endl; +} + +// Utility functions to create vertices and triangles +sLib3MFPosition fnCreateVertex(float x, float y, float z) { + sLib3MFPosition result; + result.m_Coordinates[0] = x; + result.m_Coordinates[1] = y; + result.m_Coordinates[2] = z; + return result; +} + +sLib3MFTriangle fnCreateTriangle(int v0, int v1, int v2) { + sLib3MFTriangle result; + result.m_Indices[0] = v0; + result.m_Indices[1] = v1; + result.m_Indices[2] = v2; + return result; +} + +void WriteSecureContentExample(CWrapper & wrapper) { + + PModel model = wrapper.CreateModel(); + + // After initializing the model, set the random number generation callback + // A default one will be used if you don't, current implementation uses std::mt19937 + model->SetRandomNumberCallback(SecureContentCallbacks::NotRandomBytesAtAll, nullptr); + + PMeshObject meshObject = model->AddMeshObject(); + meshObject->SetName("Box"); + + // Create mesh structure of a cube + std::vector vertices(8); + std::vector triangles(12); + + float fSizeX = 100.0f; + float fSizeY = 200.0f; + float fSizeZ = 300.0f; + + // Manually create vertices + vertices[0] = fnCreateVertex(0.0f, 0.0f, 0.0f); + vertices[1] = fnCreateVertex(fSizeX, 0.0f, 0.0f); + vertices[2] = fnCreateVertex(fSizeX, fSizeY, 0.0f); + vertices[3] = fnCreateVertex(0.0f, fSizeY, 0.0f); + vertices[4] = fnCreateVertex(0.0f, 0.0f, fSizeZ); + vertices[5] = fnCreateVertex(fSizeX, 0.0f, fSizeZ); + vertices[6] = fnCreateVertex(fSizeX, fSizeY, fSizeZ); + vertices[7] = fnCreateVertex(0.0f, fSizeY, fSizeZ); + + // Manually create triangles + triangles[0] = fnCreateTriangle(2, 1, 0); + triangles[1] = fnCreateTriangle(0, 3, 2); + triangles[2] = fnCreateTriangle(4, 5, 6); + triangles[3] = fnCreateTriangle(6, 7, 4); + triangles[4] = fnCreateTriangle(0, 1, 5); + triangles[5] = fnCreateTriangle(5, 4, 0); + triangles[6] = fnCreateTriangle(2, 3, 7); + triangles[7] = fnCreateTriangle(7, 6, 2); + triangles[8] = fnCreateTriangle(1, 2, 6); + triangles[9] = fnCreateTriangle(6, 5, 1); + triangles[10] = fnCreateTriangle(3, 0, 4); + triangles[11] = fnCreateTriangle(4, 7, 3); + + meshObject->SetGeometry(vertices, triangles); + + // Add build item + model->AddBuildItem(meshObject.get(), wrapper.GetIdentityTransform()); + + // Move this mesh out of the root model file into another model + PPackagePart nonRootModel = model->FindOrCreatePackagePart("/3D/securecube.model"); + meshObject->SetPackagePart(nonRootModel.get()); + + // Locate the keystore and setup the resource as a secure content + PKeyStore keystore = model->GetKeyStore(); + + // Add you (client) as consumer of the resource. You'll need to do this + // to be able to have a chance to wrap the content key + // You can set optional public key and an optional key id + PConsumer consumer = keystore->AddConsumer("MyConsumerID", std::string(), std::string()); + + // Add a container for your secured resources. Resources within the same container will have a shared key. + PResourceDataGroup dataGroup = keystore->AddResourceDataGroup(); + + // Add access rights for your consumer into the datagroup + PAccessRight accessRight = dataGroup->AddAccessRight(consumer.get(), eWrappingAlgorithm::RSA_OAEP, eMgfAlgorithm::MGF1_SHA1, eDigestMethod::SHA1); + + // Specify additional authentication data that you could use to further validate your encryption process + std::vector aad = { '3','M','F','C','o','n','s','o','r','t','i','u','m',' ','S','a','m','p','l','e' }; + + // This will effectively add your nonRootModel as a secure content + PResourceData resourceData = keystore->AddResourceData(dataGroup.get(), nonRootModel.get(), eEncryptionAlgorithm::AES256_GCM, eCompression::Deflate, aad); + + // Query the writer and setup the encryption before saving results + PWriter writer = model->QueryWriter("3mf"); + + // Setup Key Wrapping process + SecureContentCallbacks::KeyWrappingCbData keyData; + keyData.wrapper = &wrapper; + writer->AddKeyWrappingCallback(consumer->GetConsumerID(), SecureContentCallbacks::WriteKeyWrappingCbSample, &keyData); + + // Content Encryption process + SecureContentCallbacks::ContentEncryptionCbData contentData; + contentData.wrapper = &wrapper; + writer->SetContentEncryptionCallback(SecureContentCallbacks::WriteContentEncryptionCbSample, &contentData); + + // You'll need to complete the callback code for this call to work properly. + writer->WriteToFile("secureCube.3mf"); + + std::cout << "Writing Done." << std::endl; +} + +void ReadSecureContentExample(CWrapper & wrapper) { + PModel model = wrapper.CreateModel(); + + // After initializing the model, set the random number generation callback + // A default one will be used if you don't, current implementation uses std::mt19937 + model->SetRandomNumberCallback(SecureContentCallbacks::NotRandomBytesAtAll, nullptr); + + // Query the reader and setup the encryption before saving results + PReader reader = model->QueryReader("3mf"); + + // Setup Key Wrapping process + SecureContentCallbacks::KeyWrappingCbData keyData; + keyData.wrapper = &wrapper; + reader->AddKeyWrappingCallback("MyConsumerID", SecureContentCallbacks::ReadKeyWrappingCbSample, &keyData); + + // Content Encryption process + SecureContentCallbacks::ContentEncryptionCbData contentData; + contentData.wrapper = &wrapper; + reader->SetContentEncryptionCallback(SecureContentCallbacks::ReadContentEncryptionCbSample, &contentData); + + // You'll need to complete the callback code for this call to work properly. + reader->ReadFromFile("secureCube.3mf"); + + PKeyStore keystore = model->GetKeyStore(); + + // If you know the part you're interested in, look for its resource data + PPackagePart partPath = model->FindOrCreatePackagePart("/3D/securecube.model"); + PResourceData resourceData = keystore->FindResourceData(partPath.get()); + + // You can retrieve additional authenticated data using in the encryption + // to further verify the consistency of the process. At this time, it is + // already verified. + std::vector aad; + resourceData->GetAdditionalAuthenticationData(aad); + std::cout << "Additional Authenticated Data: "; + for (auto it = aad.begin(); it != aad.end(); ++it) { + std::cout << (char)*it; + } + std::cout << std::endl; + + std::cout << "Reading Done." << std::endl; + +} + +int main() { + PWrapper wrapper = CWrapper::loadLibrary(); + + std::cout << "------------------------------------------------------------------" << std::endl; + std::cout << "3MF SecureContent example" << std::endl; + printVersion(*wrapper); + std::cout << "------------------------------------------------------------------" << std::endl; + + try { + WriteSecureContentExample(*wrapper); + ReadSecureContentExample(*wrapper); + } catch (ELib3MFException &e) { + std::cout << e.what() << std::endl; + return e.getErrorCode(); + } + return 0; +} diff --git a/SDK/Examples/CppNew/Source/Slice.cpp b/SDK/Examples/CppNew/Source/Slice.cpp new file mode 100644 index 000000000..5b8a3828e --- /dev/null +++ b/SDK/Examples/CppNew/Source/Slice.cpp @@ -0,0 +1,191 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL MICROSOFT AND/OR NETFABB BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Abstract: + +Slice.cpp : 3MF slice extension example + +--*/ + +#include +#include +#include +double const_pi() { return std::atan(1) * 4; } +#include + +#include "lib3mf_implicit.hpp" + +using namespace Lib3MF; + + +void printVersion(PWrapper wrapper) { + Lib3MF_uint32 nMajor, nMinor, nMicro; + wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); + std::cout << "lib3mf version = " << nMajor << "." << nMinor << "." << nMicro; + std::string sReleaseInfo, sBuildInfo; + if (wrapper->GetPrereleaseInformation(sReleaseInfo)) { + std::cout << "-" << sReleaseInfo; + } + if (wrapper->GetBuildInformation(sBuildInfo)) { + std::cout << "+" << sBuildInfo; + } + std::cout << std::endl; +} + +// Utility functions to create vertices and beams +sLib3MFPosition fnCreateVertex(float x, float y, float z) +{ + sLib3MFPosition result; + result.m_Coordinates[0] = x; + result.m_Coordinates[1] = y; + result.m_Coordinates[2] = z; + return result; +} + +sLib3MFTriangle fnCreateTriangle(int v0, int v1, int v2) +{ + sLib3MFTriangle result; + result.m_Indices[0] = v0; + result.m_Indices[1] = v1; + result.m_Indices[2] = v2; + return result; +} + + +void SliceExample() { + PWrapper wrapper = CWrapper::loadLibrary(); + + std::cout << "------------------------------------------------------------------" << std::endl; + std::cout << "3MF Slice example" << std::endl; + printVersion(wrapper); + std::cout << "------------------------------------------------------------------" << std::endl; + + PModel model = wrapper->CreateModel(); + + PMeshObject meshObject = model->AddMeshObject(); + meshObject->SetName("Sliced Object [outbox]"); + + // Create mesh structure of a cube + std::vector vertices(8); + std::vector triangles(12); + + float fSizeX = 100.0f; + float fSizeY = 100.0f; + float fSizeZ = 300.0f; + + // Manually create vertices + vertices[0] = fnCreateVertex(-fSizeX, -fSizeY, 0.0f); + vertices[1] = fnCreateVertex(fSizeX, -fSizeY, 0.0f); + vertices[2] = fnCreateVertex(fSizeX, fSizeY, 0.0f); + vertices[3] = fnCreateVertex(-fSizeX, fSizeY, 0.0f); + vertices[4] = fnCreateVertex(-fSizeX, -fSizeY, fSizeZ); + vertices[5] = fnCreateVertex(fSizeX, -fSizeY, fSizeZ); + vertices[6] = fnCreateVertex(fSizeX, fSizeY, fSizeZ); + vertices[7] = fnCreateVertex(-fSizeX, fSizeY, fSizeZ); + + // Manually create triangles + triangles[0] = fnCreateTriangle(2, 1, 0); + triangles[1] = fnCreateTriangle(0, 3, 2); + triangles[2] = fnCreateTriangle(4, 5, 6); + triangles[3] = fnCreateTriangle(6, 7, 4); + triangles[4] = fnCreateTriangle(0, 1, 5); + triangles[5] = fnCreateTriangle(5, 4, 0); + triangles[6] = fnCreateTriangle(2, 3, 7); + triangles[7] = fnCreateTriangle(7, 6, 2); + triangles[8] = fnCreateTriangle(1, 2, 6); + triangles[9] = fnCreateTriangle(6, 5, 1); + triangles[10] = fnCreateTriangle(3, 0, 4); + triangles[11] = fnCreateTriangle(4, 7, 3); + + // Set Geometry + meshObject->SetGeometry(vertices, triangles); + + + PSliceStack sliceStack = model->AddSliceStack(0.0); + + + + + + // Define an ellipse + Lib3MF_uint32 nSliceVertices = 20; + std::vector origSliceVertices(nSliceVertices); + for (Lib3MF_uint32 iSliceVertex = 0; iSliceVertex < nSliceVertices; iSliceVertex++) { + double angle = 2 * (const_pi()* iSliceVertex) / nSliceVertices; + origSliceVertices[iSliceVertex].m_Coordinates[0] = (Lib3MF_single)(fSizeX / 2 * std::cos(angle)); + origSliceVertices[iSliceVertex].m_Coordinates[1] = (Lib3MF_single)(fSizeY *std::sin(angle)); + } + + std::vector polygonIndices(nSliceVertices + 1); + for (Lib3MF_uint32 iPolygonIndex = 0; iPolygonIndex < polygonIndices.size(); iPolygonIndex++) { + polygonIndices[iPolygonIndex] = iPolygonIndex % nSliceVertices; + } + + Lib3MF_uint32 nSlices = 10; + + for (Lib3MF_uint32 iSlice = 0; iSlice < nSlices; iSlice++) { + PSlice slice = sliceStack->AddSlice((iSlice + 1.0)*fSizeZ / nSlices); + + // Rotate the ellpise as we move up z + double angle = 2 * (const_pi()*iSlice) / nSlices; + std::vector sliceVertices(nSliceVertices); + for (Lib3MF_uint32 iSliceVertex = 0; iSliceVertex < nSliceVertices; iSliceVertex++) { + double x = origSliceVertices[iSliceVertex].m_Coordinates[0]; + double y = origSliceVertices[iSliceVertex].m_Coordinates[1]; + sliceVertices[iSliceVertex].m_Coordinates[0] = (Lib3MF_single)(std::cos(angle)*x - std::sin(angle)*y); + sliceVertices[iSliceVertex].m_Coordinates[1] = (Lib3MF_single)(std::sin(angle)*x + std::cos(angle)*y); + } + + slice->SetVertices(sliceVertices); + slice->AddPolygon(polygonIndices); + } + + + // Assign this slice stack to mesh..., the exact geometry of the part + meshObject->AssignSliceStack(sliceStack.get()); + // which is not an exact representation of the sliced geometry + meshObject->SetSlicesMeshResolution(eSlicesMeshResolution::Lowres); + + + // Add build item + model->AddBuildItem(meshObject.get(), wrapper->GetIdentityTransform()); + + // Write file + PWriter writer = model->QueryWriter("3mf"); + writer->WriteToFile("slice.3mf"); + + std::cout << "done" << std::endl; +} + +int main() { + try { + SliceExample(); + } + catch (ELib3MFException &e) { + std::cout << e.what() << std::endl; + return e.getErrorCode(); + } + return 0; +} diff --git a/SDK/Examples/CppNew/Source/TextureCube.cpp b/SDK/Examples/CppNew/Source/TextureCube.cpp new file mode 100644 index 000000000..a8cd51d76 --- /dev/null +++ b/SDK/Examples/CppNew/Source/TextureCube.cpp @@ -0,0 +1,205 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL MICROSOFT AND/OR NETFABB BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Abstract: + +TextureCube.cpp : 3MF Texture Cube creation example. + +--*/ + +#include +#include +#include + +#include "lib3mf_implicit.hpp" + +using namespace Lib3MF; + + +void printVersion(PWrapper wrapper) { + Lib3MF_uint32 nMajor, nMinor, nMicro; + wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); + std::cout << "lib3mf version = " << nMajor << "." << nMinor << "." << nMicro; + std::string sReleaseInfo, sBuildInfo; + if (wrapper->GetPrereleaseInformation(sReleaseInfo)) { + std::cout << "-" << sReleaseInfo; + } + if (wrapper->GetBuildInformation(sBuildInfo)) { + std::cout << "+" << sBuildInfo; + } + std::cout << std::endl; +} + +// Utility functions to create vertices and triangles +sLib3MFPosition fnCreateVertex(float x, float y, float z) +{ + sLib3MFPosition result; + result.m_Coordinates[0] = x; + result.m_Coordinates[1] = y; + result.m_Coordinates[2] = z; + return result; +} + +sLib3MFTriangle fnCreateTriangle(int v0, int v1, int v2) +{ + sLib3MFTriangle result; + result.m_Indices[0] = v0; + result.m_Indices[1] = v1; + result.m_Indices[2] = v2; + return result; +} + +PTexture2DGroup fnLoadModelTexture(PModel model, const std::string sOPCPath, const std::string sFilePath, eLib3MFTextureType eType, eLib3MFTextureTileStyle eTileStyleU, eLib3MFTextureTileStyle eTileStyleV) +{ + std::string sRelationshipType_Texture = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture"; + PAttachment attachment = model->AddAttachment(sOPCPath, sRelationshipType_Texture); + attachment->ReadFromFile(sFilePath); + + PTexture2D texture2D = model->AddTexture2DFromAttachment(attachment.get()); + + texture2D->SetContentType(eType); + texture2D->SetTileStyleUV(eTileStyleU, eTileStyleV); + + PTexture2DGroup textureGroup = model->AddTexture2DGroup(texture2D.get()); + return textureGroup; +} + + +sLib3MFTriangleProperties fnCreateTexture(PTexture2DGroup textureGroup, double u1, double v1, double u2, double v2, double u3, double v3) +{ + sLib3MFTriangleProperties property; + property.m_ResourceID = textureGroup->GetResourceID(); + property.m_PropertyIDs[0] = textureGroup->AddTex2Coord(sLib3MFTex2Coord({ u1, v1 })); + property.m_PropertyIDs[1] = textureGroup->AddTex2Coord(sLib3MFTex2Coord({ u2, v2 })); + property.m_PropertyIDs[2] = textureGroup->AddTex2Coord(sLib3MFTex2Coord({ u3, v3 })); + return property; +} + +void TextureExample() { + PWrapper wrapper = CWrapper::loadLibrary(); + + std::cout << "------------------------------------------------------------------" << std::endl; + std::cout << "3MF Texture Cube example" << std::endl; + printVersion(wrapper); + std::cout << "------------------------------------------------------------------" << std::endl; + + PModel model = wrapper->CreateModel(); + + PMeshObject meshObject = model->AddMeshObject(); + meshObject->SetName("Textured Box"); + + // Create mesh structure of a cube + std::vector vertices(8); + std::vector triangles(12); + + float fSizeX = 100.0f; + float fSizeY = 100.0f; + float fSizeZ = 100.0f; + + // Manually create vertices + vertices[0] = fnCreateVertex(0.0f, 0.0f, 0.0f); + vertices[1] = fnCreateVertex(fSizeX, 0.0f, 0.0f); + vertices[2] = fnCreateVertex(fSizeX, fSizeY, 0.0f); + vertices[3] = fnCreateVertex(0.0f, fSizeY, 0.0f); + vertices[4] = fnCreateVertex(0.0f, 0.0f, fSizeZ); + vertices[5] = fnCreateVertex(fSizeX, 0.0f, fSizeZ); + vertices[6] = fnCreateVertex(fSizeX, fSizeY, fSizeZ); + vertices[7] = fnCreateVertex(0.0f, fSizeY, fSizeZ); + + // Manually create triangles + triangles[0] = fnCreateTriangle(2, 1, 0); + triangles[1] = fnCreateTriangle(0, 3, 2); + triangles[2] = fnCreateTriangle(4, 5, 6); + triangles[3] = fnCreateTriangle(6, 7, 4); + triangles[4] = fnCreateTriangle(0, 1, 5); + triangles[5] = fnCreateTriangle(5, 4, 0); + triangles[6] = fnCreateTriangle(2, 3, 7); + triangles[7] = fnCreateTriangle(7, 6, 2); + triangles[8] = fnCreateTriangle(1, 2, 6); + triangles[9] = fnCreateTriangle(6, 5, 1); + triangles[10] = fnCreateTriangle(3, 0, 4); + triangles[11] = fnCreateTriangle(4, 7, 3); + + meshObject->SetGeometry(vertices, triangles); + + std::string sTextureFolder = TEXTURESPATH; + // add textures to 3mf package + std::cout << "sTextureFolder=\"" << sTextureFolder << "\"\n"; + auto textureGroup1 = fnLoadModelTexture(model, "/3D/Textures/tex1.png", sTextureFolder + "tex1.png", eTextureType::PNG, eTextureTileStyle::Wrap, eTextureTileStyle::Wrap); + auto textureGroup2 = fnLoadModelTexture(model, "/3D/Textures/tex2.png", sTextureFolder + "tex2.png", eTextureType::PNG, eTextureTileStyle::Mirror, eTextureTileStyle::Wrap); + auto textureGroup3 = fnLoadModelTexture(model, "/3D/Textures/tex3.png", sTextureFolder + "tex3.png", eTextureType::PNG, eTextureTileStyle::Wrap, eTextureTileStyle::Mirror); + auto textureGroup4 = fnLoadModelTexture(model, "/3D/Textures/tex4.png", sTextureFolder + "tex4.png", eTextureType::PNG, eTextureTileStyle::Clamp, eTextureTileStyle::Wrap); + auto textureGroup5 = fnLoadModelTexture(model, "/3D/Textures/tex5.png", sTextureFolder + "tex5.png", eTextureType::PNG, eTextureTileStyle::Wrap, eTextureTileStyle::Clamp); + auto textureGroup6 = fnLoadModelTexture(model, "/3D/Textures/tex6.png", sTextureFolder + "tex6.png", eTextureType::PNG, eTextureTileStyle::Clamp, eTextureTileStyle::Mirror); + + // Side 1 + meshObject->SetTriangleProperties(0, fnCreateTexture(textureGroup1, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0)); + meshObject->SetTriangleProperties(1, fnCreateTexture(textureGroup1, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0)); + + // Side 2 + meshObject->SetTriangleProperties(2, fnCreateTexture(textureGroup2, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0)); + meshObject->SetTriangleProperties(3, fnCreateTexture(textureGroup2, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0)); + + // Side 3 + // Go outside of bounds on this side + meshObject->SetTriangleProperties(4, fnCreateTexture(textureGroup3, -1.0, -1.0, 2.0, -1.0, 2.0, 2.0)); + meshObject->SetTriangleProperties(5, fnCreateTexture(textureGroup3, 2.0, 2.0, -1.0, 2.0, -1.0, -1.0)); + + // Side 4 + meshObject->SetTriangleProperties(6, fnCreateTexture(textureGroup4, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0)); + meshObject->SetTriangleProperties(7, fnCreateTexture(textureGroup4, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0)); + + // Side 5 + meshObject->SetTriangleProperties(8, fnCreateTexture(textureGroup5, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0)); + meshObject->SetTriangleProperties(9, fnCreateTexture(textureGroup5, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0)); + + // Side 6 + meshObject->SetTriangleProperties(10, fnCreateTexture(textureGroup6, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0)); + meshObject->SetTriangleProperties(11, fnCreateTexture(textureGroup6, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0)); + + // Object Level Property + meshObject->SetObjectLevelProperty(textureGroup1->GetResourceID(), 1); + + // Add build item + model->AddBuildItem(meshObject.get(), wrapper->GetIdentityTransform()); + + PWriter writer = model->QueryWriter("3mf"); + writer->WriteToFile("texturegroup.3mf"); + + std::cout << "done" << std::endl; +} + +int main() { + try { + TextureExample(); + } + catch (ELib3MFException &e) { + std::cout << e.what() << std::endl; + return e.getErrorCode(); + } + return 0; +} + + From 157d78b93a05360b8e7789659a314da8e21cfb1d Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 03:44:18 +0100 Subject: [PATCH 23/42] Cpp failure is due to a lower CMake version. First version of routines includes also for Windows and Mac OS --- .github/workflows/build.yml | 43 +++++++++++++++++++++++ SDK/Examples/CppDynamicNew/CMakeLists.txt | 14 ++++++-- SDK/Examples/CppNew/CMakeLists.txt | 17 +++++++-- 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4211a187b..f0422c6d5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -354,6 +354,28 @@ jobs: cd Examples/Cpp/build cmake --build . --config Release ./Release/Example_ExtractInfo.exe ../../Files/Helix.3mf + - name: Download lib3mf cpack (Windows) + uses: actions/download-artifact@v2 + with: + name: lib3mf-${{ env.LIB3MF_VERSION }}-Windows.zip + path: lib3mf-${{ env.LIB3MF_VERSION }}-Windows.zip + - run: ls -Rl . + - name: Unpack the cpacked SDK + run: | + unzip lib3mf-${{ env.LIB3MF_VERSION }}-Windows.zip/lib3mf-${{ env.LIB3MF_VERSION }}-Windows.zip + - name: Build CppDynamic (Windows) + run: | + ./Examples/CppDynamic/GenerateVS2019.bat + cd Examples/CppDynamic/build + cmake --build . --config Release + ./Release/Example_ExtractInfo.exe ../../Files/Helix.3mf + - name: Build Cpp (Windows) + run: | + ./Examples/Cpp/GenerateVS2019.bat + cd Examples/Cpp/build + cmake --build . --config Release + ./Release/Example_ExtractInfo.exe ../../Files/Helix.3mf + deploy-macos: runs-on: macos-latest needs: [assemble-sdk] @@ -377,4 +399,25 @@ jobs: sh Examples/Cpp/GenerateMake.sh cd Examples/Cpp/build cmake --build . + ./Example_ExtractInfo ../../Files/Helix.3mf + - name: Download lib3mf cpack (Darwin) + uses: actions/download-artifact@v2 + with: + name: lib3mf-${{ env.LIB3MF_VERSION }}-Darwin.zip + path: lib3mf-${{ env.LIB3MF_VERSION }}-Darwin.zip + - run: ls -Rl . + - name: Unpack the cpacked SDK (Darwin) + run: | + unzip lib3mf-${{ env.LIB3MF_VERSION }}-Darwin.zip/lib3mf-${{ env.LIB3MF_VERSION }}-Darwin.zip + - name: Build CppDynamicNew (Darwin) + run: | + sh Examples/CppDynamicNew/GenerateMake.sh + cd Examples/CppDynamicNew/build + cmake --build . + ./Example_ExtractInfo ../../Files/Helix.3mf + - name: Build CppNew (Darwin) + run: | + sh Examples/CppNew/GenerateMake.sh + cd Examples/CppNew/build + cmake --build . ./Example_ExtractInfo ../../Files/Helix.3mf \ No newline at end of file diff --git a/SDK/Examples/CppDynamicNew/CMakeLists.txt b/SDK/Examples/CppDynamicNew/CMakeLists.txt index f8e85ce43..f2b8994a2 100644 --- a/SDK/Examples/CppDynamicNew/CMakeLists.txt +++ b/SDK/Examples/CppDynamicNew/CMakeLists.txt @@ -39,9 +39,19 @@ cmake_minimum_required(VERSION 3.5) project(Example_ExtractInfo) set(CMAKE_CXX_STANDARD 11) -# For Linux -set(lib3mf_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Linux/lib/cmake/lib3mf) +# Determine the platform and set lib3mf_DIR accordingly +if(WIN32) + # Path for Windows + set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Windows/lib/cmake/lib3mf") +elseif(APPLE) + # Path for macOS (Darwin) + set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Darwin/lib/cmake/lib3mf") +else() + # Assuming the else case is Linux or other Unix-like except macOS + set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Linux/lib/cmake/lib3mf") +endif() +# Find package find_package(lib3mf REQUIRED CppDynamic) add_executable(Example_ExtractInfo "${CMAKE_CURRENT_SOURCE_DIR}/Source/ExtractInfo.cpp") diff --git a/SDK/Examples/CppNew/CMakeLists.txt b/SDK/Examples/CppNew/CMakeLists.txt index 066f9eb1d..b1d655909 100644 --- a/SDK/Examples/CppNew/CMakeLists.txt +++ b/SDK/Examples/CppNew/CMakeLists.txt @@ -1,9 +1,20 @@ -cmake_minimum_required (VERSION 2.6) +cmake_minimum_required (VERSION 3.5) project(Examples) set(CMAKE_CXX_STANDARD 11) -# For Linux -set(lib3mf_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Linux/lib/cmake/lib3mf) +# Determine the platform and set lib3mf_DIR accordingly +if(WIN32) + # Path for Windows + set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Windows/lib/cmake/lib3mf") +elseif(APPLE) + # Path for macOS (Darwin) + set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Darwin/lib/cmake/lib3mf") +else() + # Assuming the else case is Linux or other Unix-like except macOS + set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Linux/lib/cmake/lib3mf") +endif() + +# Find package (lib3mf) find_package(lib3mf REQUIRED Cpp) add_definitions(-DTEXTURESPATH="${CMAKE_CURRENT_SOURCE_DIR}/../Files/Textures/") From f69dc80ad947ce15f64afd292d3130a9ddeb2d0e Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 03:58:29 +0100 Subject: [PATCH 24/42] Remove erroneous ls command from windows deployment --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f0422c6d5..17654bb06 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -359,7 +359,6 @@ jobs: with: name: lib3mf-${{ env.LIB3MF_VERSION }}-Windows.zip path: lib3mf-${{ env.LIB3MF_VERSION }}-Windows.zip - - run: ls -Rl . - name: Unpack the cpacked SDK run: | unzip lib3mf-${{ env.LIB3MF_VERSION }}-Windows.zip/lib3mf-${{ env.LIB3MF_VERSION }}-Windows.zip From 2c3bedf89e3507fb6b032f0e213493112a97da8c Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 04:25:19 +0100 Subject: [PATCH 25/42] First tests for debian package --- .github/workflows/build.yml | 30 ++++++++++++++++-------------- SDK/Examples/CppNew/CMakeLists.txt | 12 +++++++++--- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 17654bb06..cbde93c9f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,6 +3,7 @@ env: LIB3MF_VERSION: "2.3.0" name: Build jobs: + # build-linux-memtest: # runs-on: ubuntu-20.04 # steps: @@ -25,17 +26,14 @@ jobs: submodules: true - run: mkdir -p build - run: zip -r build/bindings.zip Autogenerated/Bindings - - name: Archive bindings uses: actions/upload-artifact@v2 with: name: bindings.zip path: build/bindings.zip - - - name: Set up Docker Buildx + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - - name: Docker Build + - name: Docker Build uses: docker/build-push-action@v5 with: context: . @@ -43,25 +41,20 @@ jobs: platforms: linux/amd64 tags: lib3mf_ubi8:latest load: true - - - name: Docker Extract + - name: Docker Extract uses: shrink/actions-docker-extract@v3.0.0 id: extract with: image: lib3mf_ubi8:latest path: out.zip destination: dist - - run: unzip out.zip working-directory: ./dist - - name: Upload Artifact uses: actions/upload-artifact@v2 with: name: lib3mf.so path: dist/lib3mf.so.2 - - - name: Extract File Name (CPacked Archive) run: | ZIP_FILE=$(ls dist/lib3mf-*.zip) @@ -72,7 +65,6 @@ jobs: with: name: ${{ env.ARTIFACT_NAME_ZIP }} path: dist/${{ env.ARTIFACT_NAME_ZIP }} - - name: Extract File Name (Debian) run: | DEB_FILE=$(ls dist/lib3mf-*.deb) @@ -83,7 +75,6 @@ jobs: with: name: ${{ env.ARTIFACT_NAME_DEB }} path: dist/${{ env.ARTIFACT_NAME_DEB }} - - name: Extract File Name (RPM) run: | RPM_FILE=$(ls dist/lib3mf-*.rpm) @@ -95,7 +86,6 @@ jobs: name: ${{ env.ARTIFACT_NAME_RPM }} path: dist/${{ env.ARTIFACT_NAME_RPM }} - build-macos: runs-on: macos-latest steps: @@ -124,6 +114,7 @@ jobs: with: name: ${{ env.ARTIFACT_NAME }} path: build/${{ env.ARTIFACT_NAME }} + # codecoverage-macos: # runs-on: macos-latest # steps: @@ -184,6 +175,7 @@ jobs: with: name: ${{ env.ARTIFACT_NAME }} path: build/${{ env.ARTIFACT_NAME }} + # build-windows-debug: # runs-on: windows-2019 # steps: @@ -233,6 +225,8 @@ jobs: # working-directory: ./build # - run: ctest -V # working-directory: ./build + + assemble-sdk: runs-on: ubuntu-20.04 needs: [build-windows-release, build-macos, build-linux-ubi8-gcc12] @@ -280,6 +274,8 @@ jobs: with: name: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.rpm path: build/lib3mf-${{ env.LIB3MF_VERSION }}-Linux.rpm + + deploy-linux: runs-on: ubuntu-20.04 needs: [assemble-sdk] @@ -329,6 +325,12 @@ jobs: cd Examples/CppNew/build cmake --build . ./Example_ExtractInfo ../../Files/Helix.3mf + - name: Download lib3mf (Debian Linux) + uses: actions/download-artifact@v2 + with: + name: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb + path: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb + - run: ls -Rl . deploy-windows: runs-on: windows-2019 diff --git a/SDK/Examples/CppNew/CMakeLists.txt b/SDK/Examples/CppNew/CMakeLists.txt index b1d655909..883544f59 100644 --- a/SDK/Examples/CppNew/CMakeLists.txt +++ b/SDK/Examples/CppNew/CMakeLists.txt @@ -10,12 +10,18 @@ elseif(APPLE) # Path for macOS (Darwin) set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Darwin/lib/cmake/lib3mf") else() - # Assuming the else case is Linux or other Unix-like except macOS - set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Linux/lib/cmake/lib3mf") + # Path for Linux (Here we check twice to test for Debian / RPM packages properly) + find_package(lib3mf QUIET COMPONENTS Cpp) + # Check if the package was not found + if(NOT lib3mf_FOUND) + # lib3mf not found, so set lib3mf_DIR to the fallback directory + set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Linux/lib/cmake/lib3mf") + + endif() endif() # Find package (lib3mf) -find_package(lib3mf REQUIRED Cpp) +find_package(lib3mf REQUIRED COMPONENTS Cpp) add_definitions(-DTEXTURESPATH="${CMAKE_CURRENT_SOURCE_DIR}/../Files/Textures/") From e5995a4f033b483f7502f5562a4ce7b7eb3125c5 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 04:47:08 +0100 Subject: [PATCH 26/42] Include examples for debian package too --- .github/workflows/build.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cbde93c9f..deb1aaf5f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -331,6 +331,21 @@ jobs: name: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb path: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb - run: ls -Rl . + - name: Install the debian package + run: | + sudo dpkg -i lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb + - name: Build CppDynamicNew (Debian) + run: | + sh Examples/CppDynamicNew/GenerateMake.sh + cd Examples/CppDynamicNew/build + cmake --build . + ./Example_ExtractInfo ../../Files/Helix.3mf + - name: Build CppNew (Debian) + run: | + sh Examples/CppNew/GenerateMake.sh + cd Examples/CppNew/build + cmake --build . + ./Example_ExtractInfo ../../Files/Helix.3mf deploy-windows: runs-on: windows-2019 From e72519a5af1a506aa0522a1ff7ccb51ad3d2940c Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 05:00:11 +0100 Subject: [PATCH 27/42] Check the path once for debian --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index deb1aaf5f..b470794e5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -330,6 +330,7 @@ jobs: with: name: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb path: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb + - run: pwd - run: ls -Rl . - name: Install the debian package run: | From 287b423b436e38f20d1423f958ce7d5762317369 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 08:25:25 +0100 Subject: [PATCH 28/42] Check if debian is being double zipped --- .github/workflows/build.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b470794e5..aaeeb2f0c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -328,8 +328,11 @@ jobs: - name: Download lib3mf (Debian Linux) uses: actions/download-artifact@v2 with: - name: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb + name: lib3mf-debian.zip path: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb + - name: Unpack the cpacked SDK + run: | + unzip lib3mf-debian.zip - run: pwd - run: ls -Rl . - name: Install the debian package From e6a7489ff3b393ec0f68d9824dd895566342f9c6 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 08:53:52 +0100 Subject: [PATCH 29/42] . --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aaeeb2f0c..4a4525d70 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -328,11 +328,11 @@ jobs: - name: Download lib3mf (Debian Linux) uses: actions/download-artifact@v2 with: - name: lib3mf-debian.zip + name: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb path: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb - name: Unpack the cpacked SDK run: | - unzip lib3mf-debian.zip + unzip lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb.zip - run: pwd - run: ls -Rl . - name: Install the debian package From 8d13609046cdefd535f5d8d4cb52f433400ff948 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 09:35:34 +0100 Subject: [PATCH 30/42] Check the type of debian archive --- .github/workflows/build.yml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4a4525d70..9042d1982 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -280,7 +280,7 @@ jobs: runs-on: ubuntu-20.04 needs: [assemble-sdk] steps: - - run: sudo apt install -y zip unzip + - run: sudo apt install -y zip unzip file - run: pwd - run: ls -Rl . - name: Download lib3mf_sdk artifact @@ -330,26 +330,26 @@ jobs: with: name: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb path: lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb - - name: Unpack the cpacked SDK + - name: Check the file type run: | - unzip lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb.zip + file lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb - run: pwd - run: ls -Rl . - - name: Install the debian package - run: | - sudo dpkg -i lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb - - name: Build CppDynamicNew (Debian) - run: | - sh Examples/CppDynamicNew/GenerateMake.sh - cd Examples/CppDynamicNew/build - cmake --build . - ./Example_ExtractInfo ../../Files/Helix.3mf - - name: Build CppNew (Debian) - run: | - sh Examples/CppNew/GenerateMake.sh - cd Examples/CppNew/build - cmake --build . - ./Example_ExtractInfo ../../Files/Helix.3mf +# - name: Install the debian package +# run: | +# sudo dpkg -i DEBIAN_INTERMEDIATE/lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb +# - name: Build CppDynamicNew (Debian) +# run: | +# sh Examples/CppDynamicNew/GenerateMake.sh +# cd Examples/CppDynamicNew/build +# cmake --build . +# ./Example_ExtractInfo ../../Files/Helix.3mf +# - name: Build CppNew (Debian) +# run: | +# sh Examples/CppNew/GenerateMake.sh +# cd Examples/CppNew/build +# cmake --build . +# ./Example_ExtractInfo ../../Files/Helix.3mf deploy-windows: runs-on: windows-2019 From 7b630848765524e9156ced7298856e03c4e1c987 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 09:49:42 +0100 Subject: [PATCH 31/42] . --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9042d1982..5aa02f0f6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -333,6 +333,7 @@ jobs: - name: Check the file type run: | file lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb + file lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb/lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb - run: pwd - run: ls -Rl . # - name: Install the debian package From d484c51e53e956970bfe047c46b009f3eaca2ff4 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 10:07:35 +0100 Subject: [PATCH 32/42] Debian tests should go through --- .github/workflows/build.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5aa02f0f6..5e2141c9b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -336,21 +336,21 @@ jobs: file lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb/lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb - run: pwd - run: ls -Rl . -# - name: Install the debian package -# run: | -# sudo dpkg -i DEBIAN_INTERMEDIATE/lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb -# - name: Build CppDynamicNew (Debian) -# run: | -# sh Examples/CppDynamicNew/GenerateMake.sh -# cd Examples/CppDynamicNew/build -# cmake --build . -# ./Example_ExtractInfo ../../Files/Helix.3mf -# - name: Build CppNew (Debian) -# run: | -# sh Examples/CppNew/GenerateMake.sh -# cd Examples/CppNew/build -# cmake --build . -# ./Example_ExtractInfo ../../Files/Helix.3mf + - name: Install the debian package + run: | + sudo dpkg -i lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb/lib3mf-${{ env.LIB3MF_VERSION }}-Linux.deb + - name: Build CppDynamicNew (Debian) + run: | + sh Examples/CppDynamicNew/GenerateMake.sh + cd Examples/CppDynamicNew/build + cmake --build . + ./Example_ExtractInfo ../../Files/Helix.3mf + - name: Build CppNew (Debian) + run: | + sh Examples/CppNew/GenerateMake.sh + cd Examples/CppNew/build + cmake --build . + ./Example_ExtractInfo ../../Files/Helix.3mf deploy-windows: runs-on: windows-2019 From a14db58b3eb521f33f693f27020216c62f28b76f Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 10:34:24 +0100 Subject: [PATCH 33/42] Include architecture to debian package --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b7892340..b963f5c31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -265,6 +265,7 @@ set(CPACK_PACKAGE_VERSION "${LIB3MF_VERSION_MAJOR}.${LIB3MF_VERSION_MINOR}.${LIB set(CPACK_PACKAGE_VERSION_MAJOR "${LIB3MF_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${LIB3MF_VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_PATCH "${LIB3MF_VERSION_MICRO}") +set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64") set(CPACK_PACKAGE_CONTACT "maintainer@3mf.io") # An actual email id is required here set(CPACK_DEBIAN_PACKAGE_MAINTAINER "3MF Consortium") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}") From caf7b36b3784f32a2de1d9e1fe466afd2bdca274 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 10:58:41 +0100 Subject: [PATCH 34/42] Calling find_package twice is problematic. So we fix the issue --- SDK/Examples/CppDynamicNew/CMakeLists.txt | 14 +++++++++----- SDK/Examples/CppNew/CMakeLists.txt | 6 ++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/SDK/Examples/CppDynamicNew/CMakeLists.txt b/SDK/Examples/CppDynamicNew/CMakeLists.txt index f2b8994a2..9f5a2ffbf 100644 --- a/SDK/Examples/CppDynamicNew/CMakeLists.txt +++ b/SDK/Examples/CppDynamicNew/CMakeLists.txt @@ -47,13 +47,17 @@ elseif(APPLE) # Path for macOS (Darwin) set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Darwin/lib/cmake/lib3mf") else() - # Assuming the else case is Linux or other Unix-like except macOS - set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Linux/lib/cmake/lib3mf") + # Path for Linux (Here we check twice to test for Debian / RPM packages properly) + find_package(lib3mf QUIET COMPONENTS CppDynamic) + # Check if the package was not found + if(NOT lib3mf_FOUND) + # lib3mf not found, so set lib3mf_DIR to the fallback directory + set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Linux/lib/cmake/lib3mf") + # Find package (lib3mf) + find_package(lib3mf REQUIRED COMPONENTS CppDynamic) + endif() endif() -# Find package -find_package(lib3mf REQUIRED CppDynamic) - add_executable(Example_ExtractInfo "${CMAKE_CURRENT_SOURCE_DIR}/Source/ExtractInfo.cpp") # In case of CDynamic and CppDynamic, the lib3mf::lib3mf is simply an alias to an interface diff --git a/SDK/Examples/CppNew/CMakeLists.txt b/SDK/Examples/CppNew/CMakeLists.txt index 883544f59..65bcff2b9 100644 --- a/SDK/Examples/CppNew/CMakeLists.txt +++ b/SDK/Examples/CppNew/CMakeLists.txt @@ -16,13 +16,11 @@ else() if(NOT lib3mf_FOUND) # lib3mf not found, so set lib3mf_DIR to the fallback directory set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Linux/lib/cmake/lib3mf") - + # Find package (lib3mf) + find_package(lib3mf REQUIRED COMPONENTS Cpp) endif() endif() -# Find package (lib3mf) -find_package(lib3mf REQUIRED COMPONENTS Cpp) - add_definitions(-DTEXTURESPATH="${CMAKE_CURRENT_SOURCE_DIR}/../Files/Textures/") add_executable(Example_ColorCube Source/ColorCube.cpp) From 74f7eeca154181da2eb013d2d8f4d6361dea1a7b Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 11:19:36 +0100 Subject: [PATCH 35/42] Fix a minor mistake in Examples --- SDK/Examples/CppDynamicNew/CMakeLists.txt | 2 ++ SDK/Examples/CppNew/CMakeLists.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/SDK/Examples/CppDynamicNew/CMakeLists.txt b/SDK/Examples/CppDynamicNew/CMakeLists.txt index 9f5a2ffbf..5217d3b8e 100644 --- a/SDK/Examples/CppDynamicNew/CMakeLists.txt +++ b/SDK/Examples/CppDynamicNew/CMakeLists.txt @@ -43,9 +43,11 @@ set(CMAKE_CXX_STANDARD 11) if(WIN32) # Path for Windows set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Windows/lib/cmake/lib3mf") + find_package(lib3mf REQUIRED COMPONENTS CppDynamic) elseif(APPLE) # Path for macOS (Darwin) set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Darwin/lib/cmake/lib3mf") + find_package(lib3mf REQUIRED COMPONENTS CppDynamic) else() # Path for Linux (Here we check twice to test for Debian / RPM packages properly) find_package(lib3mf QUIET COMPONENTS CppDynamic) diff --git a/SDK/Examples/CppNew/CMakeLists.txt b/SDK/Examples/CppNew/CMakeLists.txt index 65bcff2b9..969bde05f 100644 --- a/SDK/Examples/CppNew/CMakeLists.txt +++ b/SDK/Examples/CppNew/CMakeLists.txt @@ -6,9 +6,11 @@ set(CMAKE_CXX_STANDARD 11) if(WIN32) # Path for Windows set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Windows/lib/cmake/lib3mf") + find_package(lib3mf REQUIRED COMPONENTS Cpp) elseif(APPLE) # Path for macOS (Darwin) set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../lib3mf-2.3.0-Darwin/lib/cmake/lib3mf") + find_package(lib3mf REQUIRED COMPONENTS Cpp) else() # Path for Linux (Here we check twice to test for Debian / RPM packages properly) find_package(lib3mf QUIET COMPONENTS Cpp) From 262e9de4e2179a7ed0bae9407416bf3094e4ca4f Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Tue, 20 Feb 2024 11:51:31 +0100 Subject: [PATCH 36/42] Re-enable all blocks of the pipeline. Maintainer email has not been changed yet. It can be done after confirmation. --- .github/workflows/build.yml | 172 ++++++++++++++++++------------------ 1 file changed, 86 insertions(+), 86 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5e2141c9b..f82de92c5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,17 +4,17 @@ env: name: Build jobs: -# build-linux-memtest: -# runs-on: ubuntu-20.04 -# steps: -# - run: sudo apt update -# - run: sudo apt install -y valgrind uuid-dev -# - uses: actions/checkout@v2 -# with: -# submodules: true -# - run: sh cmake/GenerateMake.sh -# - run: cmake --build . --target lib3mf_memcheck -# working-directory: ./build + build-linux-memtest: + runs-on: ubuntu-20.04 + steps: + - run: sudo apt update + - run: sudo apt install -y valgrind uuid-dev + - uses: actions/checkout@v2 + with: + submodules: true + - run: sh cmake/GenerateMake.sh + - run: cmake --build . --target lib3mf_memcheck + working-directory: ./build build-linux-ubi8-gcc12: runs-on: ubuntu-20.04 @@ -115,32 +115,32 @@ jobs: name: ${{ env.ARTIFACT_NAME }} path: build/${{ env.ARTIFACT_NAME }} -# codecoverage-macos: -# runs-on: macos-latest -# steps: -# - uses: actions/checkout@v4 -# with: -# submodules: true -# - name: Install Prerequisites -# run: | -# brew install lcov -# brew install gcovr -# - run: sh cmake/GenerateMake.sh -DBUILD_FOR_CODECOVERAGE=ON -# - run: cmake --build . -# working-directory: ./build -# - run: ./Tests/codecoverage/run_codecoverage.sh -# - name: Archive Code Coverage Results -# uses: actions/upload-artifact@v2 -# with: -# name: codecoverage.zip -# path: build/codecoverage.zip -# - name: Upload code coverage to codecov -# uses: codecov/codecov-action@v3 -# with: -# token: ${{ secrets.CODECOV_TOKEN }} -# files: ./build/Test_CPP_Bindings_filtered.info -# fail_ci_if_error: true # optional (default = false) -# verbose: true # optional (default = false) + codecoverage-macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install Prerequisites + run: | + brew install lcov + brew install gcovr + - run: sh cmake/GenerateMake.sh -DBUILD_FOR_CODECOVERAGE=ON + - run: cmake --build . + working-directory: ./build + - run: ./Tests/codecoverage/run_codecoverage.sh + - name: Archive Code Coverage Results + uses: actions/upload-artifact@v2 + with: + name: codecoverage.zip + path: build/codecoverage.zip + - name: Upload code coverage to codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./build/Test_CPP_Bindings_filtered.info + fail_ci_if_error: true # optional (default = false) + verbose: true # optional (default = false) build-windows-release: runs-on: windows-2019 @@ -176,55 +176,55 @@ jobs: name: ${{ env.ARTIFACT_NAME }} path: build/${{ env.ARTIFACT_NAME }} -# build-windows-debug: -# runs-on: windows-2019 -# steps: -# - uses: actions/checkout@v2 -# with: -# submodules: true -# - run: ./cmake/GenerateVS2019.bat -# - run: cmake --build . --config Debug -# working-directory: ./build -# - run: ctest -V -# working-directory: ./build -# - name: Archive Windows Debug binary -# uses: actions/upload-artifact@v2 -# with: -# name: lib3mf.debug.dll -# path: build/Debug/lib3mf.dll -# build-windows-32bit: -# runs-on: windows-2019 -# steps: -# - uses: actions/checkout@v2 -# with: -# submodules: true -# - run: ./cmake/GenerateVS2019_32bit.bat -# - run: cmake --build . --config Release -# working-directory: ./build_32bit -# - run: ctest -V -# working-directory: ./build_32bit -# - name: Archive Windows 32 bit Release binary -# uses: actions/upload-artifact@v2 -# with: -# name: lib3mf_32bit.dll -# path: build_32bit/Release/lib3mf.dll -# - name: Archive Windows 32 bit Release lib -# uses: actions/upload-artifact@v2 -# with: -# name: lib3mf_32bit.lib -# path: build_32bit/Release/lib3mf.lib -# build-mingw-w64: -# runs-on: windows-2019 -# steps: -# - run: choco install mingw -y -# - uses: actions/checkout@v2 -# with: -# submodules: true -# - run: ./cmake/GenerateMinGW.bat -# - run: cmake --build . -# working-directory: ./build -# - run: ctest -V -# working-directory: ./build + build-windows-debug: + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - run: ./cmake/GenerateVS2019.bat + - run: cmake --build . --config Debug + working-directory: ./build + - run: ctest -V + working-directory: ./build + - name: Archive Windows Debug binary + uses: actions/upload-artifact@v2 + with: + name: lib3mf.debug.dll + path: build/Debug/lib3mf.dll + build-windows-32bit: + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - run: ./cmake/GenerateVS2019_32bit.bat + - run: cmake --build . --config Release + working-directory: ./build_32bit + - run: ctest -V + working-directory: ./build_32bit + - name: Archive Windows 32 bit Release binary + uses: actions/upload-artifact@v2 + with: + name: lib3mf_32bit.dll + path: build_32bit/Release/lib3mf.dll + - name: Archive Windows 32 bit Release lib + uses: actions/upload-artifact@v2 + with: + name: lib3mf_32bit.lib + path: build_32bit/Release/lib3mf.lib + build-mingw-w64: + runs-on: windows-2019 + steps: + - run: choco install mingw -y + - uses: actions/checkout@v2 + with: + submodules: true + - run: ./cmake/GenerateMinGW.bat + - run: cmake --build . + working-directory: ./build + - run: ctest -V + working-directory: ./build assemble-sdk: From 822796fa5cb4674b989ddf4eb043a4c5dad80032 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Mon, 26 Feb 2024 16:32:48 +0530 Subject: [PATCH 37/42] Update maintainer email --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b963f5c31..edb7853c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,6 +131,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/I target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Include) if (USE_INCLUDED_LIBZIP) + # Something goes here to check if submodules exist and initialize the submodules if it does not target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/libzip/Include) if(MSVC) target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_WARNINGS) @@ -266,7 +267,7 @@ set(CPACK_PACKAGE_VERSION_MAJOR "${LIB3MF_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${LIB3MF_VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_PATCH "${LIB3MF_VERSION_MICRO}") set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64") -set(CPACK_PACKAGE_CONTACT "maintainer@3mf.io") # An actual email id is required here +set(CPACK_PACKAGE_CONTACT "lib3mf@3mf.io") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "3MF Consortium") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Source") From ceca3e1e4618440c7639686015ee131adc4c1bae Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Mon, 26 Feb 2024 21:08:14 +0530 Subject: [PATCH 38/42] A preliminary addition to config.cmake to copy libraries. The function name is copy_lib3mf_libraries --- SDK/Examples/CppNew/CMakeLists.txt | 9 +++++++++ cmake/lib3mfConfig.cmake | 26 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/SDK/Examples/CppNew/CMakeLists.txt b/SDK/Examples/CppNew/CMakeLists.txt index 969bde05f..eda3d4662 100644 --- a/SDK/Examples/CppNew/CMakeLists.txt +++ b/SDK/Examples/CppNew/CMakeLists.txt @@ -27,30 +27,39 @@ add_definitions(-DTEXTURESPATH="${CMAKE_CURRENT_SOURCE_DIR}/../Files/Textures/") add_executable(Example_ColorCube Source/ColorCube.cpp) target_link_libraries(Example_ColorCube lib3mf::lib3mf) +copy_lib3mf_libraries(Example_ColorCube) add_executable(Example_Components Source/Components.cpp) target_link_libraries(Example_Components lib3mf::lib3mf) +copy_lib3mf_libraries(Example_Components) add_executable(Example_Converter Source/Converter.cpp) target_link_libraries(Example_Converter lib3mf::lib3mf) +copy_lib3mf_libraries(Example_Converter) add_executable(Example_Cube Source/Cube.cpp) target_link_libraries(Example_Cube lib3mf::lib3mf) +copy_lib3mf_libraries(Example_Cube) add_executable(Example_SecureCube Source/SecureCube.cpp) target_link_libraries(Example_SecureCube lib3mf::lib3mf) +copy_lib3mf_libraries(Example_SecureCube) add_executable(Example_ExtractInfo Source/ExtractInfo.cpp) target_link_libraries(Example_ExtractInfo lib3mf::lib3mf) +copy_lib3mf_libraries(Example_ExtractInfo) add_executable(Example_TextureCube Source/TextureCube.cpp) target_link_libraries(Example_TextureCube lib3mf::lib3mf) +copy_lib3mf_libraries(Example_TextureCube) add_executable(Example_Slice Source/Slice.cpp) target_link_libraries(Example_Slice lib3mf::lib3mf) +copy_lib3mf_libraries(Example_Slice) add_executable(Example_BeamLattice Source/BeamLattice.cpp) target_link_libraries(Example_BeamLattice lib3mf::lib3mf) +copy_lib3mf_libraries(Example_BeamLattice) if (${MSVC}) IF(${CMAKE_VERSION} VERSION_LESS 3.6.3) diff --git a/cmake/lib3mfConfig.cmake b/cmake/lib3mfConfig.cmake index f2d05358f..b33c45fc7 100644 --- a/cmake/lib3mfConfig.cmake +++ b/cmake/lib3mfConfig.cmake @@ -63,4 +63,28 @@ else() if(WIN32) set_property(TARGET lib3mf::lib3mf PROPERTY IMPORTED_IMPLIB "${lib3mf_LIBRARY_IMPORT}") endif() -endif() + + # Define a custom function to handle library copying + function(copy_lib3mf_libraries target) + if(TARGET ${target}) + if(APPLE) + # On macOS, copy .dylib files, preserving symlinks + add_custom_command(TARGET ${target} POST_BUILD + COMMAND sh -c "cp -P '${lib3mf_LIBRARY_DIR}/lib3mf.dylib'* '$'" + COMMENT "Copying all lib3mf library files to target directory on MacOS") + elseif(UNIX) + # On Unix-like systems (excluding macOS), copy .so files, preserving symlinks + add_custom_command(TARGET ${target} POST_BUILD + COMMAND sh -c "cp -P '${lib3mf_LIBRARY_DIR}/lib3mf.so'* '$'" + COMMENT "Copying all lib3mf.so* files to target directory on Linux") + else() + # On Windows, directly copy the .dll file without worrying about symlinks + add_custom_command(TARGET ${target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${lib3mf_LIBRARY}" "$" + COMMENT "Copying lib3mf.dll to target directory on Windows") + endif() + else() + message(WARNING "Target '${target}' not found. lib3mf library was not copied.") + endif() + endfunction() +endif() \ No newline at end of file From 7597c67f25115e3e3e4b126908183512644c296f Mon Sep 17 00:00:00 2001 From: Vijai Kumar S Date: Tue, 26 Mar 2024 20:40:02 +0530 Subject: [PATCH 39/42] Update CMake to remove global warning flags --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index edb7853c8..c3cfbb95c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,10 +46,10 @@ if (${MSVC}) # using Visual Studio C++ # this ensures that the min/max macros of minwindef.h are not used - add_definitions(-DNOMINMAX /W3) + add_definitions(-DNOMINMAX) + + #add_definitions(/W3) - add_definitions(/W3) - # add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS) # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") @@ -273,4 +273,4 @@ set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CM set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Source") ######################################################### -include(CPack) \ No newline at end of file +include(CPack) From f96fc536eb1d83a22d04d40eb27de6c644a8c9d2 Mon Sep 17 00:00:00 2001 From: Vijai Kumar S Date: Wed, 27 Mar 2024 12:56:51 +0530 Subject: [PATCH 40/42] Dynamically choose the library directory based on the type of tool chain --- cmake/lib3mfConfig.cmake | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/cmake/lib3mfConfig.cmake b/cmake/lib3mfConfig.cmake index b33c45fc7..112d8ad07 100644 --- a/cmake/lib3mfConfig.cmake +++ b/cmake/lib3mfConfig.cmake @@ -1,5 +1,14 @@ # lib3mfConfig.cmake +if(VCPKG_TOOLCHAIN) + message("Lib3MF - VCPKG Tool Chain") + set(LIB3MF_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../..") +else() + message("Lib3MF - General CMake Tool Chain") + set(LIB3MF_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../../..") +endif() + + # Initial setup for known components and default selection set(lib3mf_known_components "C" "CDynamic" "Cpp" "CppDynamic") set(lib3mf_selected_variant "Cpp") # Default variant @@ -13,9 +22,9 @@ foreach(comp ${lib3mf_FIND_COMPONENTS}) endforeach() # Configure paths based on the selected variant -set(lib3mf_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../include/Bindings/${lib3mf_selected_variant}") -set(lib3mf_LIBRARY_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../lib") -set(lib3mf_BINARY_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../bin") +set(lib3mf_INCLUDE_DIR "${LIB3MF_ROOT_DIR}/include/Bindings/${lib3mf_selected_variant}") +set(lib3mf_LIBRARY_DIR "${LIB3MF_ROOT_DIR}/lib") +set(lib3mf_BINARY_DIR "${LIB3MF_ROOT_DIR}/bin") # Adjust library file name based on platform if(WIN32) @@ -43,7 +52,7 @@ if("${lib3mf_selected_variant}" STREQUAL "CppDynamic" OR "${lib3mf_selected_vari message(" You must append this to your sources ") message("") message("*****************************************************************************") - set(LIB3MF_CDYNAMIC_ADDITIONAL_SOURCE "${CMAKE_CURRENT_LIST_DIR}/../../../include/Bindings/CDynamic/lib3mf_dynamic.cc") + set(LIB3MF_CDYNAMIC_ADDITIONAL_SOURCE "${LIB3MF_ROOT_DIR}/include/Bindings/CDynamic/lib3mf_dynamic.cc") endif() add_library(lib3mfdynamic INTERFACE) # Now alias lib3mfdynamic to include the namespace @@ -87,4 +96,4 @@ else() message(WARNING "Target '${target}' not found. lib3mf library was not copied.") endif() endfunction() -endif() \ No newline at end of file +endif() From 24f8497c89395d499b3e129874aeb6b3df2dcfbe Mon Sep 17 00:00:00 2001 From: Vijai Kumar S Date: Mon, 13 May 2024 19:41:46 +0530 Subject: [PATCH 41/42] Update build.yml --- .github/workflows/build.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d11787258..19376ab9a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -109,6 +109,11 @@ jobs: with: name: lib3mf.dylib path: build/lib3mf.dylib + - name: Upload Artifact (CPacked Archive) + uses: actions/upload-artifact@v2 + with: + name: ${{ env.ARTIFACT_NAME }} + path: build/${{ env.ARTIFACT_NAME }} build-macos-debug: runs-on: macos-latest @@ -127,12 +132,6 @@ jobs: name: lib3mf.debug.dylib path: build/lib3mf.dylib - - name: Upload Artifact (CPacked Archive) - uses: actions/upload-artifact@v2 - with: - name: ${{ env.ARTIFACT_NAME }} - path: build/${{ env.ARTIFACT_NAME }} - codecoverage-macos: runs-on: macos-latest steps: @@ -467,4 +466,4 @@ jobs: sh Examples/CppNew/GenerateMake.sh cd Examples/CppNew/build cmake --build . - ./Example_ExtractInfo ../../Files/Helix.3mf \ No newline at end of file + ./Example_ExtractInfo ../../Files/Helix.3mf From 96a3e50f181153f230a291e3ed36b872f6116342 Mon Sep 17 00:00:00 2001 From: Vijai Kumar S Date: Mon, 13 May 2024 22:33:59 +0530 Subject: [PATCH 42/42] Update build.yml Update version name --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 19376ab9a..9018af27e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ on: [push, pull_request] env: - LIB3MF_VERSION: "2.3.0" + LIB3MF_VERSION: "2.3.1" name: Build jobs: