diff --git a/.gitmodules b/.gitmodules index 9833ed4832..fa9dff4101 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,3 +5,6 @@ [submodule "src/ifcopenshell-python/ifcopenshell/mvd"] path = src/ifcopenshell-python/ifcopenshell/mvd url = https://github.com/opensourceBIM/python-mvdxml/ +[submodule "src/svgfill"] + path = src/svgfill + url = https://github.com/IfcOpenShell/svgfill diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 8fbc049495..d032ebc434 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -21,7 +21,12 @@ cmake_minimum_required(VERSION 3.1.3) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) # not necessary, but encouraged -project (IfcOpenShell VERSION 0.6.0) +project (IfcOpenShell VERSION 0.7.0) + +cmake_policy(SET CMP0048 NEW) +cmake_policy(SET CMP0074 NEW) +cmake_policy(SET CMP0078 OLD) +cmake_policy(SET CMP0086 NEW) # use extra version to make pre-release using eg semver set( EXTRA_VERSION "-alpha.3") @@ -123,6 +128,13 @@ UNIFY_ENVVARS_AND_CACHE(HDF5_LIBRARIES) UNIFY_ENVVARS_AND_CACHE(BOOST_ROOT) UNIFY_ENVVARS_AND_CACHE(BOOST_LIBRARYDIR) +UNIFY_ENVVARS_AND_CACHE(CGAL_INCLUDE_DIR) +UNIFY_ENVVARS_AND_CACHE(CGAL_LIBRARY_DIR) +UNIFY_ENVVARS_AND_CACHE(GMP_INCLUDE_DIR) +UNIFY_ENVVARS_AND_CACHE(GMP_LIBRARY_DIR) +UNIFY_ENVVARS_AND_CACHE(MPFR_INCLUDE_DIR) +UNIFY_ENVVARS_AND_CACHE(MPFR_LIBRARY_DIR) + if (GLTF_SUPPORT AND BUILD_CONVERT) UNIFY_ENVVARS_AND_CACHE(JSON_INCLUDE_DIR) FIND_FILE(json_hpp "json.hpp" ${JSON_INCLUDE_DIR}/nlohmann) @@ -779,6 +791,8 @@ IF(BUILD_IFCMAX) ADD_SUBDIRECTORY(../src/ifcmax ifcmax) ENDIF() +ADD_SUBDIRECTORY(../src/svgfill svgfill) + # CMake installation targets INSTALL(FILES ${IFCPARSE_H_FILES} DESTINATION ${INCLUDEDIR}/ifcparse diff --git a/src/ifcwrap/CMakeLists.txt b/src/ifcwrap/CMakeLists.txt index 25455fb444..317c4c1c97 100644 --- a/src/ifcwrap/CMakeLists.txt +++ b/src/ifcwrap/CMakeLists.txt @@ -53,12 +53,12 @@ IF (WIN32 AND NOT PYTHON_DEBUG_LIBRARIES) ENDIF() SET_SOURCE_FILES_PROPERTIES(IfcPython.i PROPERTIES CPLUSPLUS ON) -SWIG_ADD_MODULE(ifcopenshell_wrapper python IfcPython.i) +swig_add_library(ifcopenshell_wrapper LANGUAGE python SOURCES IfcPython.i) if("$ENV{LDFLAGS}" MATCHES ".undefined.suppress") # On osx there is some state in the python dylib. With `-Wl,undefined,suppress` we can ignore the missing symbols at compile time. -SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${IFCOPENSHELL_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES}) +SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${IFCOPENSHELL_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} libsvgfill) else() -SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${IFCOPENSHELL_LIBRARIES} ${PYTHON_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES}) +SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${IFCOPENSHELL_LIBRARIES} ${PYTHON_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} libsvgfill) endif() if ((NOT WIN32) AND BUILD_SHARED_LIBS) SET_INSTALL_RPATHS(${SWIG_MODULE_ifcopenshell_wrapper_REAL_NAME} "${IFCDIRS};${OCC_LIBRARY_DIR}") diff --git a/src/ifcwrap/IfcGeomWrapper.i b/src/ifcwrap/IfcGeomWrapper.i index 1ef249fbe2..83853e1543 100644 --- a/src/ifcwrap/IfcGeomWrapper.i +++ b/src/ifcwrap/IfcGeomWrapper.i @@ -502,3 +502,42 @@ struct ShapeRTTI : public boost::static_visitor return IfcGeom::tesselate(schema_name, shp, d); } %} + +%ignore svgfill::svg_to_line_segments; +%ignore svgfill::line_segments_to_polygons; + +%template(svg_line_segments) std::vector>; +%template(svg_groups_of_line_segments) std::vector>>; +%template(svg_point) std::array; +%template(line_segment) std::array; +%template(svg_polygons) std::vector; +%template(svg_groups_of_polygons) std::vector>; +%template(svg_loop) std::vector>; +%template(svg_loops) std::vector>>; + +%naturalvar svgfill::polygon_2::boundary; +%naturalvar svgfill::polygon_2::inner_boundaries; +%naturalvar svgfill::polygon_2::point_inside; + +%include "../svgfill/src/svgfill.h" + +%inline %{ + std::vector> svg_to_line_segments(const std::string& data, const boost::optional& class_name) { + std::vector> r; + if (svgfill::svg_to_line_segments(data, class_name, r)) { + return r; + } else { + throw std::runtime_error("Failed to read SVG"); + } + } + + std::vector> line_segments_to_polygons(svgfill::solver s, double eps, const std::vector>& segments) { + std::vector> r; + if (svgfill::line_segments_to_polygons(s, eps, segments, r)) { + return r; + } else { + throw std::runtime_error("Failed to read SVG"); + } + } +%} + diff --git a/src/ifcwrap/IfcPython.i b/src/ifcwrap/IfcPython.i index 510e6b276d..7af36d71e1 100644 --- a/src/ifcwrap/IfcPython.i +++ b/src/ifcwrap/IfcPython.i @@ -48,6 +48,7 @@ %} %include "std_array.i" +%include "std_vector.i" %include "std_string.i" %include "exception.i" @@ -111,6 +112,8 @@ #include "../ifcparse/IfcSchema.h" #include "../ifcparse/utils.h" + #include "../svgfill/src/svgfill.h" + #include %} @@ -155,6 +158,8 @@ #include "../ifcparse/IfcSchema.h" #include "../ifcparse/utils.h" + #include "../svgfill/src/svgfill.h" + #include %} diff --git a/src/svgfill b/src/svgfill new file mode 160000 index 0000000000..77f2329351 --- /dev/null +++ b/src/svgfill @@ -0,0 +1 @@ +Subproject commit 77f23293510fdf5216ea17801299c1f4dc0a8820 diff --git a/win/build-deps.cmd b/win/build-deps.cmd index cd574f49bc..d4872933c2 100644 --- a/win/build-deps.cmd +++ b/win/build-deps.cmd @@ -116,6 +116,11 @@ if "%CMAKE_VERSION%" LSS "cmake version 3.11.4" ( goto :ErrorAndPrintUsage ) +:: NOTE Boost < 1.64 doesn't work without tricks if the user has only VS 2017 installed and no earlier versions. +set BOOST_VERSION=1.74.0 +:: Version string with underscores instead of dots. +set BOOST_VER=%BOOST_VERSION:.=_% + :: Print build configuration information call cecho.cmd 0 10 "Script configuration:" @@ -191,10 +196,6 @@ popd :: Note all of the dependencies have appropriate label so that user can easily skip something if wanted :: by modifying this file and using goto. :Boost -:: NOTE Boost < 1.64 doesn't work without tricks if the user has only VS 2017 installed and no earlier versions. -set BOOST_VERSION=1.74.0 -:: Version string with underscores instead of dots. -set BOOST_VER=%BOOST_VERSION:.=_% :: DEPENDENCY_NAME is used for logging and DEPENDENCY_DIR for saving from some redundant typing set DEPENDENCY_NAME=Boost %BOOST_VERSION% set DEPENDENCY_DIR=%DEPS_DIR%\boost_%BOOST_VER% @@ -428,6 +429,68 @@ IF EXIST "%DEPS_DIR%\swigwin-%SWIG_VERSION%". ( ) IF EXIST "%DEPS_DIR%\swigwin\". robocopy "%DEPS_DIR%\swigwin" "%INSTALL_DIR%\swigwin" /E /IS /MOVE /njh /njs +:mpir +set DEPENDENCY_NAME=mpir +set DEPENDENCY_DIR=%DEPS_DIR%\mpir +call :GitCloneAndCheckoutRevision https://github.com/BrianGladman/mpir.git "%DEPENDENCY_DIR%" +IF NOT %ERRORLEVEL%==0 GOTO :Error +cd "%DEPENDENCY_DIR%" +git reset --hard +REM There probably need to be quotes here around the filename +powershell -c "get-content %~dp0patches\mpir.patch | %%{$_ -replace \"sdk\",\"%UCRTVersion%\"} | %%{$_ -replace \"fn\",\"lib_mpir_cxx\"}" | git apply --unidiff-zero +IF NOT %ERRORLEVEL%==0 GOTO :Error +powershell -c "get-content %~dp0patches\mpir.patch | %%{$_ -replace \"sdk\",\"%UCRTVersion%\"} | %%{$_ -replace \"fn\",\"lib_mpir_gc\"}" | git apply --unidiff-zero +IF NOT %ERRORLEVEL%==0 GOTO :Error +if NOT "%USE_STATIC_RUNTIME%"=="FALSE" git apply "%~dp0patches\mpir_runtime.patch" --unidiff-zero +IF NOT %ERRORLEVEL%==0 GOTO :Error +cd msvc +cd vs%VS_VER:~2,2% +call .\msbuild.bat gc LIB %VS_PLATFORM% Release +IF NOT %ERRORLEVEL%==0 GOTO :Error +IF NOT EXIST "%INSTALL_DIR%\mpir". mkdir "%INSTALL_DIR%\mpir" +copy ..\..\lib\%VS_PLATFORM%\Release\* "%INSTALL_DIR%\mpir" +IF NOT %ERRORLEVEL%==0 GOTO :Error + +:mpfr +set DEPENDENCY_NAME=mpfr +set DEPENDENCY_DIR=%DEPS_DIR%\mpfr +call :GitCloneAndCheckoutRevision https://github.com/BrianGladman/mpfr.git "%DEPENDENCY_DIR%" 2ebbe10fd029a480cf6e8a64c493afa9f3654251 +IF NOT %ERRORLEVEL%==0 GOTO :Error +cd "%DEPENDENCY_DIR%" +git reset --hard +powershell -c "get-content %~dp0patches\mpfr.patch | %%{$_ -replace \"sdk\",\"%UCRTVersion%\"} | %%{$_ -replace \"fn\",\"lib_mpfr\"}" | git apply --unidiff-zero +IF NOT %ERRORLEVEL%==0 GOTO :Error +if NOT "%USE_STATIC_RUNTIME%"=="FALSE" git apply "%~dp0patches\mpfr_runtime.patch" --unidiff-zero +IF NOT %ERRORLEVEL%==0 GOTO :Error +call :BuildSolution "%DEPENDENCY_DIR%\build.vc15\lib_mpfr.sln" %DEBUG_OR_RELEASE% lib_mpfr +REM This command fails because not all msvc projects are patched with the right sdk version +IF NOT EXIST lib\%VS_PLATFORM%\Release\mpfr.lib GOTO :Error +IF NOT EXIST "%INSTALL_DIR%\mpfr". mkdir "%INSTALL_DIR%\mpfr" +copy lib\%VS_PLATFORM%\Release\* "%INSTALL_DIR%\mpfr" +IF NOT %ERRORLEVEL%==0 GOTO :Error + +:cgal +set DEPENDENCY_NAME=cgal +set DEPENDENCY_DIR=%DEPS_DIR%\cgal +call :GitCloneAndCheckoutRevision https://github.com/CGAL/cgal.git "%DEPENDENCY_DIR%" v5.2.3 +IF NOT %ERRORLEVEL%==0 GOTO :Error +cd "%DEPENDENCY_DIR%" +git reset --hard +git apply "%~dp0patches\cgal_no_zlib.patch" +call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\cgal" ^ + -DBOOST_ROOT="%DEPS_DIR%\boost_%BOOST_VER%" ^ + -DGMP_INCLUDE_DIR="%INSTALL_DIR%\mpir" ^ + -DGMP_LIBRARIES="%INSTALL_DIR%\mpir\mpir.lib" ^ + -DMPFR_INCLUDE_DIR="%INSTALL_DIR%\mpfr" ^ + -DMPFR_LIBRARIES="%INSTALL_DIR%\mpfr\mpfr.lib" ^ + -DBUILD_SHARED_LIBS=On ^ + -DBOOST_LIBRARYDIR="%DEPS_DIR%\boost_%BOOST_VER%\stage\vs%VS_VER%-%VS_PLATFORM%\lib" +IF NOT %ERRORLEVEL%==0 GOTO :Error +call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\CGAL.sln" %BUILD_CFG% +IF NOT %ERRORLEVEL%==0 GOTO :Error +call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %BUILD_CFG% +IF NOT %ERRORLEVEL%==0 GOTO :Error + :Successful echo. call "%~dp0\utils\cecho.cmd" 0 10 "%PROJECT_NAME% dependencies built." @@ -504,6 +567,7 @@ if not exist "%~2". ( set RET=%ERRORLEVEL% ) else ( call cecho.cmd 0 13 "%DEPENDENCY_NAME% already cloned. Pulling latest changes." + git reset --hard pushd %2 call git pull set RET=0 @@ -520,7 +584,7 @@ if not exist "%~2". ( pushd "%DEPS_DIR%" call git clone %1 %2 set RET=%ERRORLEVEL% - if not %RET%==0 exit /b %RET% + if not "%RET%"=="0" exit /b %RET% popd ) else ( call cecho.cmd 0 13 "%DEPENDENCY_NAME% already cloned." diff --git a/win/patches/cgal_no_zlib.patch b/win/patches/cgal_no_zlib.patch new file mode 100644 index 0000000000..1b24a17e19 --- /dev/null +++ b/win/patches/cgal_no_zlib.patch @@ -0,0 +1,13 @@ +diff --git a/Installation/cmake/modules/CGAL_SetupCGAL_ImageIODependencies.cmake b/Installation/cmake/modules/CGAL_SetupCGAL_ImageIODependencies.cmake +index 8ac856d037..742fa8df69 100644 +--- a/Installation/cmake/modules/CGAL_SetupCGAL_ImageIODependencies.cmake ++++ b/Installation/cmake/modules/CGAL_SetupCGAL_ImageIODependencies.cmake +@@ -23,7 +23,7 @@ set(CGAL_SetupCGAL_ImageIODependencies_included TRUE) + # Used Modules + # ^^^^^^^^^^^^ + # - :module:`FindZLIB` +-find_package( ZLIB ) ++# find_package( ZLIB ) + + define_property(TARGET PROPERTY CGAL_TARGET_USES_ZLIB + BRIEF_DOCS "Tells if the target uses ZLIB as a dependency" diff --git a/win/patches/mpfr.patch b/win/patches/mpfr.patch new file mode 100644 index 0000000000..676fad4be7 --- /dev/null +++ b/win/patches/mpfr.patch @@ -0,0 +1,5 @@ +--- a/build.vc15/fn/fn.vcxproj ++++ a/build.vc15/fn/fn.vcxproj +@@ -25 +25 @@ +- 10.0.17134.0 ++ sdk diff --git a/win/patches/mpfr_runtime.patch b/win/patches/mpfr_runtime.patch new file mode 100644 index 0000000000..0152fba603 --- /dev/null +++ b/win/patches/mpfr_runtime.patch @@ -0,0 +1,10 @@ +diff --git a/build.vc15/lib_mpfr/lib_mpfr.vcxproj b/build.vc15/lib_mpfr/lib_mpfr.vcxproj +index a3c72e48..85da0bcc 100644 +--- a/build.vc15/lib_mpfr/lib_mpfr.vcxproj ++++ b/build.vc15/lib_mpfr/lib_mpfr.vcxproj +@@ -148 +148 @@ +- MultiThreaded ++ MultiThreadedDLL +@@ -179 +179 @@ +- MultiThreaded ++ MultiThreadedDLL diff --git a/win/patches/mpir.patch b/win/patches/mpir.patch new file mode 100644 index 0000000000..0bbb105617 --- /dev/null +++ b/win/patches/mpir.patch @@ -0,0 +1,7 @@ +diff --git a/msvc/vs17/fn/fn.vcxproj b/msvc/vs17/fn/fn.vcxproj +index d8d87f8f..e543adc8 100644 +--- a/msvc/vs17/fn/fn.vcxproj ++++ b/msvc/vs17/fn/fn.vcxproj +@@ -25 +25 @@ +- 10.0.17134.0 ++ sdk diff --git a/win/patches/mpir_runtime.patch b/win/patches/mpir_runtime.patch new file mode 100644 index 0000000000..abb5f0bc86 --- /dev/null +++ b/win/patches/mpir_runtime.patch @@ -0,0 +1,13 @@ +diff --git a/msvc/mpir_release_lib.props b/msvc/mpir_release_lib.props +index d46f9649..832c6937 100644 +--- a/msvc/mpir_release_lib.props ++++ b/msvc/mpir_release_lib.props +@@ -9,7 +9,7 @@ + + + $(IntDir)du\m\my\%(RelativeDir) +- MultiThreaded ++ MultiThreadedDLL + $(TargetDir)$(TargetName).pdb + + diff --git a/win/run-cmake.bat b/win/run-cmake.bat index 41617e964c..e682d22327 100755 --- a/win/run-cmake.bat +++ b/win/run-cmake.bat @@ -102,6 +102,13 @@ set SWIG_DIR=%INSTALL_DIR%\swigwin set PATH=%PATH%;%SWIG_DIR%;%PYTHONHOME% set JSON_INCLUDE_DIR=%INSTALL_DIR%\json +set CGAL_INCLUDE_DIR=%INSTALL_DIR%\cgal\include +set CGAL_LIBRARY_DIR=%INSTALL_DIR%\cgal\lib +set GMP_INCLUDE_DIR=%INSTALL_DIR%\mpir +set GMP_LIBRARY_DIR=%INSTALL_DIR%\mpir +set MPFR_INCLUDE_DIR=%INSTALL_DIR%\mpfr +set MPFR_LIBRARY_DIR=%INSTALL_DIR%\mpfr + echo. call cecho.cmd 0 10 "Script configuration:" echo Generator = %GENERATOR% @@ -127,6 +134,13 @@ echo PYTHON_EXECUTABLE = %PYTHON_EXECUTABLE% echo SWIG_DIR = %SWIG_DIR% echo JSON_INCLUDE_DIR = %JSON_INCLUDE_DIR% echo. +echo CGAL_INCLUDE_DIR = %CGAL_INCLUDE_DIR% +echo CGAL_LIBRARY_DIR = %CGAL_LIBRARY_DIR% +echo GMP_INCLUDE_DIR = %GMP_INCLUDE_DIR% +echo GMP_LIBRARY_DIR = %GMP_LIBRARY_DIR% +echo MPFR_INCLUDE_DIR = %MPFR_INCLUDE_DIR% +echo MPFR_LIBRARY_DIR = %MPFR_LIBRARY_DIR% +echo. echo CMAKE_INSTALL_PREFIX = %CMAKE_INSTALL_PREFIX% echo.