Skip to content

Commit c563c0d

Browse files
committed
ifcopsh08 compatibility
1 parent 9ea0388 commit c563c0d

File tree

3 files changed

+97
-14
lines changed

3 files changed

+97
-14
lines changed

.github/workflows/build_win.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ jobs:
9292
"-DPython_EXECUTABLE=C:\Users\tkrij\miniconda3\python.exe" `
9393
"-DBOOST_ROOT=$base/_deps/boost_1_86_0" `
9494
"-DBOOST_LIBRARYDIR=$base/_deps/boost_1_86_0/stage/vs2019-x64/lib" `
95+
"-DGMP_LIBRARY_DIR=$base/_deps-vs2019-x64-installed/mpir" `
96+
"-DMPFR_LIBRARY_DIR=$base/_deps-vs2019-x64-installed/mpfr" `
9597
"-DSWIG_EXECUTABLE=$base/_deps-vs2019-x64-installed/swigwin/swig.exe"
9698
cmake --build . --target install --config Release
9799

CMakeLists.txt

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,10 @@ if (IFC_SUPPORT)
169169
add_definitions("-DIFCOPENSHELL_05")
170170
set(SWIG_DEFINES ${SWIG_DEFINES} -DIFCOPENSHELL_05)
171171
else()
172-
file(GLOB geomlibfiles ${IFC_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}IfcGeom_*)
173-
foreach(file ${geomlibfiles})
174-
get_filename_component(file_we ${file} NAME_WE)
175-
string(REPLACE "${CMAKE_SHARED_LIBRARY_PREFIX}IfcGeom_ifc" "" schema_name ${file_we})
176-
list(APPEND SCHEMA_VERSIONS ${schema_name})
177-
endforeach()
178-
179172
if(${ifcopenshell_major_version} STREQUAL "0.7" OR
180-
${ifcopenshell_major_version} STREQUAL "0.8")
173+
${ifcopenshell_major_version} STREQUAL "0.8")
181174

182-
if(${ifcopenshell_major_version} STREQUAL "0.8")
175+
if(${ifcopenshell_major_version} STREQUAL "0.8")
183176
add_definitions("-DIFCOPENSHELL_08")
184177
else()
185178
add_definitions("-DIFCOPENSHELL_07")
@@ -199,9 +192,49 @@ if (IFC_SUPPORT)
199192
endif()
200193
endif()
201194

195+
if (${ifcopenshell_major_version} STREQUAL "0.8")
196+
file(GLOB geomlibfiles ${IFC_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}geometry_mapping_*)
197+
foreach(file ${geomlibfiles})
198+
get_filename_component(file_we ${file} NAME_WE)
199+
string(REPLACE "${CMAKE_SHARED_LIBRARY_PREFIX}geometry_mapping_ifc" "" schema_name ${file_we})
200+
list(APPEND SCHEMA_VERSIONS ${schema_name})
201+
endforeach()
202+
file(GLOB geomlibfiles ${IFC_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}geometry_kernel_*)
203+
foreach(file ${geomlibfiles})
204+
get_filename_component(file_we ${file} NAME_WE)
205+
string(REPLACE "${CMAKE_SHARED_LIBRARY_PREFIX}" "" file_we_wp ${file_we})
206+
if ("${file_we_wp}" STREQUAL "geometry_kernel_cgal")
207+
find_library(libGMP NAMES gmp mpir PATHS ${GMP_LIBRARY_DIR} NO_DEFAULT_PATH)
208+
find_library(libMPFR NAMES mpfr PATHS ${MPFR_LIBRARY_DIR} NO_DEFAULT_PATH)
209+
if(NOT libGMP)
210+
message(FATAL_ERROR "Unable to find GMP library files, aborting")
211+
endif()
212+
if(NOT libMPFR)
213+
message(FATAL_ERROR "Unable to find MPFR library files, aborting")
214+
endif()
215+
216+
list(APPEND CGAL_LIBRARIES "${libMPFR}")
217+
list(APPEND CGAL_LIBRARIES "${libGMP}")
218+
endif()
219+
list(APPEND IFC_LIBRARY_NAMES "${file_we_wp}")
220+
endforeach()
221+
else()
222+
file(GLOB geomlibfiles ${IFC_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}IfcGeom_*)
223+
foreach(file ${geomlibfiles})
224+
get_filename_component(file_we ${file} NAME_WE)
225+
string(REPLACE "${CMAKE_SHARED_LIBRARY_PREFIX}IfcGeom_ifc" "" schema_name ${file_we})
226+
list(APPEND SCHEMA_VERSIONS ${schema_name})
227+
endforeach()
228+
endif()
229+
202230
list(APPEND IFC_LIBRARY_NAMES IfcGeom)
203231
foreach(schema_name ${SCHEMA_VERSIONS})
204-
list(APPEND IFC_LIBRARY_NAMES IfcGeom_ifc${schema_name})
232+
message(STATUS "Detected schema ifc${schema_name}")
233+
if (${ifcopenshell_major_version} STREQUAL "0.8")
234+
list(APPEND IFC_LIBRARY_NAMES geometry_mapping_ifc${schema_name})
235+
else()
236+
list(APPEND IFC_LIBRARY_NAMES IfcGeom_ifc${schema_name})
237+
endif()
205238
endforeach()
206239
list(APPEND IFC_LIBRARY_NAMES IfcParse)
207240
endif()
@@ -213,6 +246,7 @@ endif()
213246

214247
foreach(libname ${IFC_LIBRARY_NAMES})
215248
unset(lib CACHE)
249+
message("Looking for ${libname} in ${IFC_LIBRARY_DIR}")
216250
find_library(lib NAMES "${libname}" PATHS "${IFC_LIBRARY_DIR}" NO_DEFAULT_PATH)
217251
if (lib)
218252
list(APPEND IFC_LIBRARIES "${lib}")
@@ -276,7 +310,7 @@ ENDIF()
276310
set(LIBVOXELIZER_HEADER_FILES progress_writer.h dim3.h sweep.h shift.h collapse.h edge_detect.h fill_gaps.h offset.h polyfill.h resample.h storage.h writer.h factory.h processor.h volume.h voxelizer.h traversal.h memoized_traversal.h lru_cache.h util.h json_logger.h)
277311
set(LIBVOXELIZER_SOURCE_FILES tribox3.cpp polyfill.cpp progress_writer.cpp storage.cpp factory.cpp json_logger.cpp)
278312
add_library(libvoxel STATIC ${LIBVOXELIZER_HEADER_FILES} ${LIBVOXELIZER_SOURCE_FILES})
279-
target_link_libraries(libvoxel ${IFC_LIBRARIES} ${ICU_LIBRARIES} ${Boost_LIBRARIES} ${BCRYPT_LIBRARIES} ${OCC_LIBRARIES} ${LIB_RT} ${dl} ${CMAKE_THREAD_LIBS_INIT} ${WS2_LIBRARIES})
313+
target_link_libraries(libvoxel ${IFC_LIBRARIES} ${ICU_LIBRARIES} ${Boost_LIBRARIES} ${BCRYPT_LIBRARIES} ${OCC_LIBRARIES} ${CGAL_LIBRARIES} ${LIB_RT} ${dl} ${CMAKE_THREAD_LIBS_INIT} ${WS2_LIBRARIES})
280314

281315
set(LIBVOXEC_HEADER_FILES voxelfile.h voxec.h)
282316
set(LIBVOXEC_SOURCE_FILES voxec.cpp)

voxec.h

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,18 @@ class op_create_geometry : public voxel_operation {
580580
}
581581

582582
if (filtered_non_empty) {
583+
#ifdef IFCOPENSHELL_08
584+
const auto& m = elem->transformation().data()->ccomponents();
585+
gp_Trsf tr;
586+
tr.SetValues(
587+
m(0, 0), m(0, 1), m(0, 2), m(0, 3),
588+
m(1, 0), m(1, 1), m(1, 2), m(1, 3),
589+
m(2, 0), m(2, 1), m(2, 2), m(2, 3)
590+
);
591+
compound.Move(tr);
592+
#else
583593
compound.Move(elem->transformation().data());
584-
594+
#endif
585595
BRepMesh_IncrementalMesh(compound, 0.001);
586596
geometries->push_back(std::make_pair(std::pair<void*, int>(ifc_file, elem->id()), compound));
587597
}
@@ -1288,7 +1298,11 @@ class op_export_elements : public voxel_operation {
12881298
}
12891299
}
12901300
if (include) {
1301+
#ifdef IFCOPENSHELL_08
1302+
std::string guid = (std::string)((IfcUtil::IfcBaseEntity*)((IfcParse::IfcFile*)iden.first)->instance_by_id(iden.second))->get("GlobalId");
1303+
#else
12911304
std::string guid = *((IfcUtil::IfcBaseEntity*)((IfcParse::IfcFile*)iden.first)->instance_by_id(iden.second))->get("GlobalId");
1305+
#endif
12921306
if (n++) {
12931307
json << ",\n";
12941308
}
@@ -2077,17 +2091,30 @@ namespace {
20772091
if (idx == -1) {
20782092
throw std::runtime_error(inst->declaration().name() + " has no attribute " + p.first);
20792093
}
2094+
#ifdef IFCOPENSHELL_08
2095+
auto attr = inst->as<IfcUtil::IfcBaseEntity>()->data().get_attribute_value(idx);
2096+
if (attr.isNull()) {
2097+
#else
20802098
auto attr = inst->data().getArgument(idx);
20812099
if (!attr || attr->isNull()) {
2100+
#endif
20822101
return false;
20832102
}
2084-
if (attr->type() == IfcUtil::Argument_DOUBLE) {
2103+
if (attr.type() == IfcUtil::Argument_DOUBLE) {
20852104
auto op = p.second.at(0);
20862105
auto v = p.second.substr(1);
20872106
auto attr_type = inst->declaration().attribute_by_index(idx);
2107+
#ifdef IFCOPENSHELL_08
2108+
double d0 = attr;
2109+
#else
20882110
double d0 = *attr;
2111+
#endif
20892112
if (attr_type->type_of_attribute()->is("IfcLengthMeasure")) {
2113+
#ifdef IFCOPENSHELL_08
2114+
d0 *= inst->file_->getUnit("LENGTHUNIT").second;
2115+
#else
20902116
d0 *= inst->data().file->getUnit("LENGTHUNIT").second;
2117+
#endif
20912118
}
20922119
auto d1 = boost::lexical_cast<double>(v);
20932120
if (op == '<') {
@@ -2136,13 +2163,21 @@ namespace {
21362163
if (rels) {
21372164
for (auto& rel : *rels) {
21382165
if (rel->declaration().is("IfcRelDefinesByProperties")) {
2166+
#ifdef IFCOPENSHELL_08
2167+
IfcUtil::IfcBaseClass* pset = ((IfcUtil::IfcBaseEntity*)rel)->get("RelatingPropertyDefinition");
2168+
if (pset->declaration().is("IfcPropertySet")) {
2169+
instance_list_t::ptr props = ((IfcUtil::IfcBaseEntity*)pset)->get("HasProperties");
2170+
for (auto& prop : *props) {
2171+
if (prop->declaration().is("IfcPropertySingleValue")) {
2172+
auto name = (std::string) ((IfcUtil::IfcBaseEntity*)prop)->get("Name");
2173+
#else
21392174
IfcUtil::IfcBaseClass* pset = *((IfcUtil::IfcBaseEntity*)rel)->get("RelatingPropertyDefinition");
21402175
if (pset->declaration().is("IfcPropertySet")) {
21412176
instance_list_t::ptr props = *((IfcUtil::IfcBaseEntity*)pset)->get("HasProperties");
21422177
for (auto& prop : *props) {
21432178
if (prop->declaration().is("IfcPropertySingleValue")) {
21442179
auto name = (std::string) *((IfcUtil::IfcBaseEntity*)prop)->get("Name");
2145-
2180+
#endif
21462181
/*
21472182
// In the voxelfile grammer we can also have keywords starting with an alpha character
21482183
// so for the string comparison we need to trim off any others.
@@ -2157,10 +2192,17 @@ namespace {
21572192

21582193
if (name == p.first) {
21592194
has_match = true;
2195+
#ifdef IFCOPENSHELL_08
2196+
IfcUtil::IfcBaseClass* val = ((IfcUtil::IfcBaseEntity*)prop)->get("NominalValue");
2197+
auto val_attr = val->data().get_attribute_value(0);
2198+
if (val_attr.type() == IfcUtil::Argument_BOOL) {
2199+
auto v_ifc = (bool)val_attr;
2200+
#else
21602201
IfcUtil::IfcBaseClass* val = *((IfcUtil::IfcBaseEntity*)prop)->get("NominalValue");
21612202
auto val_attr = val->data().getArgument(0);
21622203
if (val_attr->type() == IfcUtil::Argument_BOOL) {
21632204
auto v_ifc = (bool)*val_attr;
2205+
#endif
21642206
int v_filter = 0;
21652207
try {
21662208
v_filter = boost::get<int>(p.second);
@@ -2171,8 +2213,13 @@ namespace {
21712213
if (!match) {
21722214
return false;
21732215
}
2216+
#ifdef IFCOPENSHELL_08
2217+
} else if (val_attr.type() == IfcUtil::Argument_STRING) {
2218+
auto v_ifc = (std::string)val_attr;
2219+
#else
21742220
} else if (val_attr->type() == IfcUtil::Argument_STRING) {
21752221
auto v_ifc = (std::string)*val_attr;
2222+
#endif
21762223
std::string v_filter;
21772224
try {
21782225
v_filter = boost::get<std::string>(p.second);

0 commit comments

Comments
 (0)