Skip to content

Commit 2f8ff93

Browse files
committed
#1153 work on embedding svgfill in ifcopenshell wrapper
1 parent 872306f commit 2f8ff93

File tree

13 files changed

+197
-9
lines changed

13 files changed

+197
-9
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
[submodule "src/ifcopenshell-python/ifcopenshell/mvd"]
66
path = src/ifcopenshell-python/ifcopenshell/mvd
77
url = https://github.com/opensourceBIM/python-mvdxml/
8+
[submodule "src/svgfill"]
9+
path = src/svgfill
10+
url = https://github.com/IfcOpenShell/svgfill

cmake/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ cmake_minimum_required(VERSION 3.1.3)
2121
set(CMAKE_CXX_STANDARD 14)
2222
set(CMAKE_CXX_STANDARD_REQUIRED ON) # not necessary, but encouraged
2323

24-
project (IfcOpenShell VERSION 0.6.0)
24+
project (IfcOpenShell VERSION 0.7.0)
25+
26+
cmake_policy(SET CMP0048 NEW)
27+
cmake_policy(SET CMP0074 NEW)
28+
cmake_policy(SET CMP0078 OLD)
29+
cmake_policy(SET CMP0086 NEW)
2530

2631
# use extra version to make pre-release using eg semver
2732
set( EXTRA_VERSION "-alpha.3")
@@ -123,6 +128,13 @@ UNIFY_ENVVARS_AND_CACHE(HDF5_LIBRARIES)
123128
UNIFY_ENVVARS_AND_CACHE(BOOST_ROOT)
124129
UNIFY_ENVVARS_AND_CACHE(BOOST_LIBRARYDIR)
125130

131+
UNIFY_ENVVARS_AND_CACHE(CGAL_INCLUDE_DIR)
132+
UNIFY_ENVVARS_AND_CACHE(CGAL_LIBRARY_DIR)
133+
UNIFY_ENVVARS_AND_CACHE(GMP_INCLUDE_DIR)
134+
UNIFY_ENVVARS_AND_CACHE(GMP_LIBRARY_DIR)
135+
UNIFY_ENVVARS_AND_CACHE(MPFR_INCLUDE_DIR)
136+
UNIFY_ENVVARS_AND_CACHE(MPFR_LIBRARY_DIR)
137+
126138
if (GLTF_SUPPORT AND BUILD_CONVERT)
127139
UNIFY_ENVVARS_AND_CACHE(JSON_INCLUDE_DIR)
128140
FIND_FILE(json_hpp "json.hpp" ${JSON_INCLUDE_DIR}/nlohmann)
@@ -779,6 +791,8 @@ IF(BUILD_IFCMAX)
779791
ADD_SUBDIRECTORY(../src/ifcmax ifcmax)
780792
ENDIF()
781793

794+
ADD_SUBDIRECTORY(../src/svgfill svgfill)
795+
782796
# CMake installation targets
783797
INSTALL(FILES ${IFCPARSE_H_FILES}
784798
DESTINATION ${INCLUDEDIR}/ifcparse

src/ifcwrap/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ IF (WIN32 AND NOT PYTHON_DEBUG_LIBRARIES)
5353
ENDIF()
5454

5555
SET_SOURCE_FILES_PROPERTIES(IfcPython.i PROPERTIES CPLUSPLUS ON)
56-
SWIG_ADD_MODULE(ifcopenshell_wrapper python IfcPython.i)
56+
swig_add_library(ifcopenshell_wrapper LANGUAGE python SOURCES IfcPython.i)
5757
if("$ENV{LDFLAGS}" MATCHES ".undefined.suppress")
5858
# On osx there is some state in the python dylib. With `-Wl,undefined,suppress` we can ignore the missing symbols at compile time.
59-
SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${IFCOPENSHELL_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES})
59+
SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${IFCOPENSHELL_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} libsvgfill)
6060
else()
61-
SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${IFCOPENSHELL_LIBRARIES} ${PYTHON_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES})
61+
SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${IFCOPENSHELL_LIBRARIES} ${PYTHON_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} libsvgfill)
6262
endif()
6363
if ((NOT WIN32) AND BUILD_SHARED_LIBS)
6464
SET_INSTALL_RPATHS(${SWIG_MODULE_ifcopenshell_wrapper_REAL_NAME} "${IFCDIRS};${OCC_LIBRARY_DIR}")

src/ifcwrap/IfcGeomWrapper.i

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,3 +502,42 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
502502
return IfcGeom::tesselate(schema_name, shp, d);
503503
}
504504
%}
505+
506+
%ignore svgfill::svg_to_line_segments;
507+
%ignore svgfill::line_segments_to_polygons;
508+
509+
%template(svg_line_segments) std::vector<std::array<svgfill::point_2, 2>>;
510+
%template(svg_groups_of_line_segments) std::vector<std::vector<std::array<svgfill::point_2, 2>>>;
511+
%template(svg_point) std::array<double, 2>;
512+
%template(line_segment) std::array<svgfill::point_2, 2>;
513+
%template(svg_polygons) std::vector<svgfill::polygon_2>;
514+
%template(svg_groups_of_polygons) std::vector<std::vector<svgfill::polygon_2>>;
515+
%template(svg_loop) std::vector<std::array<double, 2>>;
516+
%template(svg_loops) std::vector<std::vector<std::array<double, 2>>>;
517+
518+
%naturalvar svgfill::polygon_2::boundary;
519+
%naturalvar svgfill::polygon_2::inner_boundaries;
520+
%naturalvar svgfill::polygon_2::point_inside;
521+
522+
%include "../svgfill/src/svgfill.h"
523+
524+
%inline %{
525+
std::vector<std::vector<svgfill::line_segment_2>> svg_to_line_segments(const std::string& data, const boost::optional<std::string>& class_name) {
526+
std::vector<std::vector<svgfill::line_segment_2>> r;
527+
if (svgfill::svg_to_line_segments(data, class_name, r)) {
528+
return r;
529+
} else {
530+
throw std::runtime_error("Failed to read SVG");
531+
}
532+
}
533+
534+
std::vector<std::vector<svgfill::polygon_2>> line_segments_to_polygons(svgfill::solver s, double eps, const std::vector<std::vector<svgfill::line_segment_2>>& segments) {
535+
std::vector<std::vector<svgfill::polygon_2>> r;
536+
if (svgfill::line_segments_to_polygons(s, eps, segments, r)) {
537+
return r;
538+
} else {
539+
throw std::runtime_error("Failed to read SVG");
540+
}
541+
}
542+
%}
543+

src/ifcwrap/IfcPython.i

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
%}
4949

5050
%include "std_array.i"
51+
%include "std_vector.i"
5152
%include "std_string.i"
5253
%include "exception.i"
5354

@@ -111,6 +112,8 @@
111112
#include "../ifcparse/IfcSchema.h"
112113
#include "../ifcparse/utils.h"
113114

115+
#include "../svgfill/src/svgfill.h"
116+
114117
#include <BRepTools_ShapeSet.hxx>
115118
%}
116119

@@ -155,6 +158,8 @@
155158
#include "../ifcparse/IfcSchema.h"
156159
#include "../ifcparse/utils.h"
157160

161+
#include "../svgfill/src/svgfill.h"
162+
158163
#include <BRepTools_ShapeSet.hxx>
159164
%}
160165

src/svgfill

Submodule svgfill added at 77f2329

win/build-deps.cmd

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ if "%CMAKE_VERSION%" LSS "cmake version 3.11.4" (
116116
goto :ErrorAndPrintUsage
117117
)
118118

119+
:: NOTE Boost < 1.64 doesn't work without tricks if the user has only VS 2017 installed and no earlier versions.
120+
set BOOST_VERSION=1.74.0
121+
:: Version string with underscores instead of dots.
122+
set BOOST_VER=%BOOST_VERSION:.=_%
123+
119124
:: Print build configuration information
120125

121126
call cecho.cmd 0 10 "Script configuration:"
@@ -191,10 +196,6 @@ popd
191196
:: Note all of the dependencies have appropriate label so that user can easily skip something if wanted
192197
:: by modifying this file and using goto.
193198
:Boost
194-
:: NOTE Boost < 1.64 doesn't work without tricks if the user has only VS 2017 installed and no earlier versions.
195-
set BOOST_VERSION=1.74.0
196-
:: Version string with underscores instead of dots.
197-
set BOOST_VER=%BOOST_VERSION:.=_%
198199
:: DEPENDENCY_NAME is used for logging and DEPENDENCY_DIR for saving from some redundant typing
199200
set DEPENDENCY_NAME=Boost %BOOST_VERSION%
200201
set DEPENDENCY_DIR=%DEPS_DIR%\boost_%BOOST_VER%
@@ -428,6 +429,68 @@ IF EXIST "%DEPS_DIR%\swigwin-%SWIG_VERSION%". (
428429
)
429430
IF EXIST "%DEPS_DIR%\swigwin\". robocopy "%DEPS_DIR%\swigwin" "%INSTALL_DIR%\swigwin" /E /IS /MOVE /njh /njs
430431

432+
:mpir
433+
set DEPENDENCY_NAME=mpir
434+
set DEPENDENCY_DIR=%DEPS_DIR%\mpir
435+
call :GitCloneAndCheckoutRevision https://github.com/BrianGladman/mpir.git "%DEPENDENCY_DIR%"
436+
IF NOT %ERRORLEVEL%==0 GOTO :Error
437+
cd "%DEPENDENCY_DIR%"
438+
git reset --hard
439+
REM There probably need to be quotes here around the filename
440+
powershell -c "get-content %~dp0patches\mpir.patch | %%{$_ -replace \"sdk\",\"%UCRTVersion%\"} | %%{$_ -replace \"fn\",\"lib_mpir_cxx\"}" | git apply --unidiff-zero
441+
IF NOT %ERRORLEVEL%==0 GOTO :Error
442+
powershell -c "get-content %~dp0patches\mpir.patch | %%{$_ -replace \"sdk\",\"%UCRTVersion%\"} | %%{$_ -replace \"fn\",\"lib_mpir_gc\"}" | git apply --unidiff-zero
443+
IF NOT %ERRORLEVEL%==0 GOTO :Error
444+
if NOT "%USE_STATIC_RUNTIME%"=="FALSE" git apply "%~dp0patches\mpir_runtime.patch" --unidiff-zero
445+
IF NOT %ERRORLEVEL%==0 GOTO :Error
446+
cd msvc
447+
cd vs%VS_VER:~2,2%
448+
call .\msbuild.bat gc LIB %VS_PLATFORM% Release
449+
IF NOT %ERRORLEVEL%==0 GOTO :Error
450+
IF NOT EXIST "%INSTALL_DIR%\mpir". mkdir "%INSTALL_DIR%\mpir"
451+
copy ..\..\lib\%VS_PLATFORM%\Release\* "%INSTALL_DIR%\mpir"
452+
IF NOT %ERRORLEVEL%==0 GOTO :Error
453+
454+
:mpfr
455+
set DEPENDENCY_NAME=mpfr
456+
set DEPENDENCY_DIR=%DEPS_DIR%\mpfr
457+
call :GitCloneAndCheckoutRevision https://github.com/BrianGladman/mpfr.git "%DEPENDENCY_DIR%" 2ebbe10fd029a480cf6e8a64c493afa9f3654251
458+
IF NOT %ERRORLEVEL%==0 GOTO :Error
459+
cd "%DEPENDENCY_DIR%"
460+
git reset --hard
461+
powershell -c "get-content %~dp0patches\mpfr.patch | %%{$_ -replace \"sdk\",\"%UCRTVersion%\"} | %%{$_ -replace \"fn\",\"lib_mpfr\"}" | git apply --unidiff-zero
462+
IF NOT %ERRORLEVEL%==0 GOTO :Error
463+
if NOT "%USE_STATIC_RUNTIME%"=="FALSE" git apply "%~dp0patches\mpfr_runtime.patch" --unidiff-zero
464+
IF NOT %ERRORLEVEL%==0 GOTO :Error
465+
call :BuildSolution "%DEPENDENCY_DIR%\build.vc15\lib_mpfr.sln" %DEBUG_OR_RELEASE% lib_mpfr
466+
REM This command fails because not all msvc projects are patched with the right sdk version
467+
IF NOT EXIST lib\%VS_PLATFORM%\Release\mpfr.lib GOTO :Error
468+
IF NOT EXIST "%INSTALL_DIR%\mpfr". mkdir "%INSTALL_DIR%\mpfr"
469+
copy lib\%VS_PLATFORM%\Release\* "%INSTALL_DIR%\mpfr"
470+
IF NOT %ERRORLEVEL%==0 GOTO :Error
471+
472+
:cgal
473+
set DEPENDENCY_NAME=cgal
474+
set DEPENDENCY_DIR=%DEPS_DIR%\cgal
475+
call :GitCloneAndCheckoutRevision https://github.com/CGAL/cgal.git "%DEPENDENCY_DIR%" v5.2.3
476+
IF NOT %ERRORLEVEL%==0 GOTO :Error
477+
cd "%DEPENDENCY_DIR%"
478+
git reset --hard
479+
git apply "%~dp0patches\cgal_no_zlib.patch"
480+
call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\cgal" ^
481+
-DBOOST_ROOT="%DEPS_DIR%\boost_%BOOST_VER%" ^
482+
-DGMP_INCLUDE_DIR="%INSTALL_DIR%\mpir" ^
483+
-DGMP_LIBRARIES="%INSTALL_DIR%\mpir\mpir.lib" ^
484+
-DMPFR_INCLUDE_DIR="%INSTALL_DIR%\mpfr" ^
485+
-DMPFR_LIBRARIES="%INSTALL_DIR%\mpfr\mpfr.lib" ^
486+
-DBUILD_SHARED_LIBS=On ^
487+
-DBOOST_LIBRARYDIR="%DEPS_DIR%\boost_%BOOST_VER%\stage\vs%VS_VER%-%VS_PLATFORM%\lib"
488+
IF NOT %ERRORLEVEL%==0 GOTO :Error
489+
call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\CGAL.sln" %BUILD_CFG%
490+
IF NOT %ERRORLEVEL%==0 GOTO :Error
491+
call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %BUILD_CFG%
492+
IF NOT %ERRORLEVEL%==0 GOTO :Error
493+
431494
:Successful
432495
echo.
433496
call "%~dp0\utils\cecho.cmd" 0 10 "%PROJECT_NAME% dependencies built."
@@ -504,6 +567,7 @@ if not exist "%~2". (
504567
set RET=%ERRORLEVEL%
505568
) else (
506569
call cecho.cmd 0 13 "%DEPENDENCY_NAME% already cloned. Pulling latest changes."
570+
git reset --hard
507571
pushd %2
508572
call git pull
509573
set RET=0
@@ -520,7 +584,7 @@ if not exist "%~2". (
520584
pushd "%DEPS_DIR%"
521585
call git clone %1 %2
522586
set RET=%ERRORLEVEL%
523-
if not %RET%==0 exit /b %RET%
587+
if not "%RET%"=="0" exit /b %RET%
524588
popd
525589
) else (
526590
call cecho.cmd 0 13 "%DEPENDENCY_NAME% already cloned."

win/patches/cgal_no_zlib.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/Installation/cmake/modules/CGAL_SetupCGAL_ImageIODependencies.cmake b/Installation/cmake/modules/CGAL_SetupCGAL_ImageIODependencies.cmake
2+
index 8ac856d037..742fa8df69 100644
3+
--- a/Installation/cmake/modules/CGAL_SetupCGAL_ImageIODependencies.cmake
4+
+++ b/Installation/cmake/modules/CGAL_SetupCGAL_ImageIODependencies.cmake
5+
@@ -23,7 +23,7 @@ set(CGAL_SetupCGAL_ImageIODependencies_included TRUE)
6+
# Used Modules
7+
# ^^^^^^^^^^^^
8+
# - :module:`FindZLIB`
9+
-find_package( ZLIB )
10+
+# find_package( ZLIB )
11+
12+
define_property(TARGET PROPERTY CGAL_TARGET_USES_ZLIB
13+
BRIEF_DOCS "Tells if the target uses ZLIB as a dependency"

win/patches/mpfr.patch

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--- a/build.vc15/fn/fn.vcxproj
2+
+++ a/build.vc15/fn/fn.vcxproj
3+
@@ -25 +25 @@
4+
- <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
5+
+ <WindowsTargetPlatformVersion>sdk</WindowsTargetPlatformVersion>

win/patches/mpfr_runtime.patch

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
diff --git a/build.vc15/lib_mpfr/lib_mpfr.vcxproj b/build.vc15/lib_mpfr/lib_mpfr.vcxproj
2+
index a3c72e48..85da0bcc 100644
3+
--- a/build.vc15/lib_mpfr/lib_mpfr.vcxproj
4+
+++ b/build.vc15/lib_mpfr/lib_mpfr.vcxproj
5+
@@ -148 +148 @@
6+
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
7+
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
8+
@@ -179 +179 @@
9+
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
10+
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>

0 commit comments

Comments
 (0)