Skip to content

Commit 839b5a2

Browse files
committed
Minor cleanups, 4x1 and 4x2 geom lib, granular schema macros
1 parent 73f7c34 commit 839b5a2

36 files changed

Lines changed: 15573 additions & 2294 deletions

cmake/CMakeLists.txt

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,18 @@ function(files_for_ifc_version IFC_VERSION RESULT_NAME)
453453
)
454454
endfunction()
455455

456+
set(SCHEMA_VERSIONS "2x3" "4" "4x1" "4x2")
457+
456458
if(COMPILE_SCHEMA)
459+
# @todo, this appears to be untested at the moment
460+
457461
find_package(PythonInterp)
458462

459463
IF(NOT PYTHONINTERP_FOUND)
460464
MESSAGE(FATAL_ERROR "A Python interpreter is necessary when COMPILE_SCHEMA is enabled. Disable COMPILE_SCHEMA or fix Python paths to proceed.")
461465
ENDIF()
462466

463-
set(IFC_RELEASE_NOT_USED "2x3" "4")
467+
set(IFC_RELEASE_NOT_USED ${SCHEMA_VERSIONS})
464468

465469
# Install pyparsing if necessary
466470
execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip freeze OUTPUT_VARIABLE PYTHON_PACKAGE_LIST)
@@ -501,13 +505,11 @@ if(COMPILE_SCHEMA)
501505
OUTPUT_VARIABLE COMPILED_SCHEMA_NAME)
502506

503507
# Prevent the schema that had just been compiled from being excluded
504-
if("${COMPILED_SCHEMA_NAME}" STREQUAL "IFC2X3")
505-
list(REMOVE_ITEM IFC_RELEASE_NOT_USED "2x3")
506-
add_definitions(-DUSE_IFC2x3)
507-
elseif("${COMPILED_SCHEMA_NAME}" STREQUAL "IFC4")
508-
list(REMOVE_ITEM IFC_RELEASE_NOT_USED "4")
509-
add_definitions(-DUSE_IFC4)
510-
endif()
508+
foreach(s ${SCHEMA_VERSIONS})
509+
if("${COMPILED_SCHEMA_NAME}" STREQUAL "${s}")
510+
list(REMOVE_ITEM IFC_RELEASE_NOT_USED "${s}")
511+
endif()
512+
endforeach()
511513
endif()
512514

513515
# Boost >= 1.58 requires BOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE to build on some Linux distros.
@@ -517,10 +519,16 @@ endif()
517519

518520
set(IFCOPENSHELL_LIBRARIES IfcParse)
519521
if (BUILD_IFCGEOM)
520-
set(IFCOPENSHELL_LIBRARIES ${IFCOPENSHELL_LIBRARIES} IfcGeom_ifc2x3 IfcGeom_ifc4 IfcGeom IfcGeom_ifc2x3 IfcGeom_ifc4 IfcGeom)
522+
foreach(s ${SCHEMA_VERSIONS})
523+
set(IFCGEOM_SCHEMA_LIBRARIES ${IFCGEOM_SCHEMA_LIBRARIES} IfcGeom_ifc${s})
524+
endforeach()
525+
set(IFCOPENSHELL_LIBRARIES ${IFCOPENSHELL_LIBRARIES} IfcGeom ${IFCGEOM_SCHEMA_LIBRARIES} IfcGeom ${IFCGEOM_SCHEMA_LIBRARIES})
521526
endif()
522527
if (BUILD_CONVERT)
523-
set(IFCOPENSHELL_LIBRARIES ${IFCOPENSHELL_LIBRARIES} Serializers_ifc2x3 Serializers_ifc4 Serializers Serializers_ifc2x3 Serializers_ifc4 Serializers)
528+
foreach(s ${SCHEMA_VERSIONS})
529+
set(SERIALIZER_SCHEMA_LIBRARIES ${SERIALIZER_SCHEMA_LIBRARIES} Serializers_ifc${s})
530+
endforeach()
531+
set(IFCOPENSHELL_LIBRARIES ${IFCOPENSHELL_LIBRARIES} Serializers ${SERIALIZER_SCHEMA_LIBRARIES})
524532
endif()
525533

526534
# IfcParse
@@ -540,15 +548,11 @@ file(GLOB IFCGEOM_H_FILES ../src/ifcgeom/*.h)
540548
file(GLOB IFCGEOM_CPP_FILES ../src/ifcgeom/*.cpp)
541549
set(IFCGEOM_FILES ${IFCGEOM_CPP_FILES} ${IFCGEOM_H_FILES})
542550

543-
add_library(IfcGeom_ifc2x3 STATIC ${IFCGEOM_FILES})
544-
add_library(IfcGeom_ifc4 STATIC ${IFCGEOM_FILES})
545-
546-
set_target_properties(IfcGeom_ifc2x3 PROPERTIES COMPILE_FLAGS "-DIFC_GEOM_EXPORTS -DIfcSchema=Ifc2x3")
547-
# TODO: Detect based on IfcSchema
548-
set_target_properties(IfcGeom_ifc4 PROPERTIES COMPILE_FLAGS "-DIFC_GEOM_EXPORTS -DIfcSchema=Ifc4 -DUSE_IFC4")
549-
550-
TARGET_LINK_LIBRARIES(IfcGeom_ifc2x3 IfcParse ${OPENCASCADE_LIBRARIES})
551-
TARGET_LINK_LIBRARIES(IfcGeom_ifc4 IfcParse ${OPENCASCADE_LIBRARIES})
551+
foreach(s ${SCHEMA_VERSIONS})
552+
add_library(IfcGeom_ifc${s} STATIC ${IFCGEOM_FILES})
553+
set_target_properties(IfcGeom_ifc${s} PROPERTIES COMPILE_FLAGS "-DIFC_GEOM_EXPORTS -DIfcSchema=Ifc${s}")
554+
TARGET_LINK_LIBRARIES(IfcGeom_ifc${s} IfcParse ${OPENCASCADE_LIBRARIES})
555+
endforeach()
552556

553557
# IfcGeom (schema agnostic)
554558
file(GLOB SCHEMA_AGNOSTIC_H_FILES ../src/ifcgeom_schema_agnostic/*.h)
@@ -557,7 +561,7 @@ set(SCHEMA_AGNOSTIC_FILES ${SCHEMA_AGNOSTIC_H_FILES} ${SCHEMA_AGNOSTIC_CPP_FILES
557561

558562
add_library(IfcGeom ${SCHEMA_AGNOSTIC_FILES})
559563
set_target_properties(IfcGeom PROPERTIES COMPILE_FLAGS -DIFC_GEOM_EXPORTS)
560-
TARGET_LINK_LIBRARIES(IfcGeom IfcGeom_ifc2x3 IfcGeom_ifc4)
564+
TARGET_LINK_LIBRARIES(IfcGeom ${IFCGEOM_SCHEMA_LIBRARIES})
561565

562566
endif(BUILD_IFCGEOM)
563567

@@ -571,20 +575,16 @@ file(GLOB SERIALIZERS_S_H_FILES ../src/serializers/schema_dependent/*.h)
571575
file(GLOB SERIALIZERS_S_CPP_FILES ../src/serializers/schema_dependent/*.cpp)
572576
set(SERIALIZERS_S_FILES ${SERIALIZERS_S_H_FILES} ${SERIALIZERS_S_CPP_FILES})
573577

574-
add_library(Serializers_ifc2x3 STATIC ${SERIALIZERS_S_FILES})
575-
add_library(Serializers_ifc4 STATIC ${SERIALIZERS_S_FILES})
576-
577-
set_target_properties(Serializers_ifc2x3 PROPERTIES COMPILE_FLAGS "-DIFC_GEOM_EXPORTS -DIfcSchema=Ifc2x3 ${CONVERT_PRECISION}")
578-
# TODO: Detect based on IfcSchema
579-
set_target_properties(Serializers_ifc4 PROPERTIES COMPILE_FLAGS "-DIFC_GEOM_EXPORTS -DIfcSchema=Ifc4 -DUSE_IFC4 ${CONVERT_PRECISION}")
580-
581-
TARGET_LINK_LIBRARIES(Serializers_ifc2x3 IfcGeom ${OPENCASCADE_LIBRARIES})
582-
TARGET_LINK_LIBRARIES(Serializers_ifc4 IfcGeom ${OPENCASCADE_LIBRARIES})
578+
foreach(s ${SCHEMA_VERSIONS})
579+
add_library(Serializers_ifc${s} STATIC ${SERIALIZERS_S_FILES})
580+
set_target_properties(Serializers_ifc${s} PROPERTIES COMPILE_FLAGS "-DIFC_GEOM_EXPORTS -DIfcSchema=Ifc${s} ${CONVERT_PRECISION}")
581+
TARGET_LINK_LIBRARIES(Serializers_ifc${s} IfcGeom ${OPENCASCADE_LIBRARIES})
582+
endforeach()
583583

584584
add_library(Serializers ${SERIALIZERS_FILES})
585585
set_target_properties(Serializers PROPERTIES COMPILE_FLAGS "-DIFC_GEOM_EXPORTS ${CONVERT_PRECISION}")
586586

587-
TARGET_LINK_LIBRARIES(Serializers Serializers_ifc2x3 Serializers_ifc4)
587+
TARGET_LINK_LIBRARIES(Serializers ${SERIALIZER_SCHEMA_LIBRARIES})
588588

589589
# IfcConvert
590590
file(GLOB IFCCONVERT_CPP_FILES ../src/ifcconvert/*.cpp)
@@ -663,15 +663,15 @@ INSTALL(FILES ${SCHEMA_AGNOSTIC_H_FILES}
663663
DESTINATION ${INCLUDEDIR}/ifcgeom_schema_agnostic
664664
)
665665

666-
INSTALL(TARGETS IfcGeom_ifc2x3 IfcGeom_ifc4 IfcGeom
666+
INSTALL(TARGETS ${IFCGEOM_SCHEMA_LIBRARIES} IfcGeom
667667
ARCHIVE DESTINATION ${LIBDIR}
668668
LIBRARY DESTINATION ${LIBDIR}
669669
RUNTIME DESTINATION ${BINDIR}
670670
)
671671
endif()
672672

673673
if(BUILD_CONVERT)
674-
INSTALL(TARGETS Serializers Serializers_ifc2x3 Serializers_ifc4
674+
INSTALL(TARGETS Serializers ${SERIALIZER_SCHEMA_LIBRARIES}
675675
ARCHIVE DESTINATION ${LIBDIR}
676676
LIBRARY DESTINATION ${LIBDIR}
677677
RUNTIME DESTINATION ${BINDIR}

src/ifcexpressparser/bootstrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ def find_bytype(expr, ty, li = None):
199199
pickle.dump(mapping, f, protocol=0)
200200
201201
import header
202-
import enum_header
203202
import implementation
204203
import schema_class
204+
import definitions
205205
206206
header.Header(mapping).emit()
207-
enum_header.EnumHeader(mapping).emit()
208207
implementation.Implementation(mapping).emit()
209208
schema_class.SchemaClass(mapping).emit()
209+
definitions.Definitions(mapping).emit()
210210
211211
sys.stdout.write(schema.name)
212212
"""%('\n '.join(statements)))
Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,46 @@
1717
# #
1818
###############################################################################
1919

20-
import templates
20+
import operator
21+
22+
import nodes
2123
import codegen
2224

23-
class EnumHeader(codegen.Base):
25+
from collections import defaultdict
26+
27+
class Definitions(codegen.Base):
2428
def __init__(self, mapping):
25-
enumerable_types = sorted(set([name for name, type in mapping.schema.types.items()] + [name for name, type in mapping.schema.entities.items()]))
2629

27-
self.str = templates.enum_header % {
28-
'schema_name_upper' : mapping.schema.name.upper(),
29-
'schema_name' : mapping.schema.name.capitalize(),
30-
'types' : ', '.join(enumerable_types)
31-
}
30+
schema_name = mapping.schema.name
31+
self.schema_name = schema_name_title = schema_name.capitalize()
32+
33+
statements = ['']
3234

33-
self.schema_name = mapping.schema.name.capitalize()
34-
35-
self.file_name = '%senum.h'%self.schema_name
35+
def write_entity(schema_name, name, type):
36+
attribute_names = list(map(lambda t: (t.name, t.optional), type.attributes))
37+
for attr, is_optional in attribute_names:
38+
statements.append("#define SCHEMA_%(name)s_HAS_%(attr)s" % locals())
39+
if is_optional:
40+
statements.append("#define SCHEMA_%(name)s_%(attr)s_IS_OPTIONAL" % locals())
41+
42+
def write(name):
43+
statements.append("#define SCHEMA_HAS_%(name)s" % locals())
44+
fn = None
45+
if mapping.schema.is_entity(name):
46+
fn = write_entity
47+
48+
if fn is not None:
49+
decl = mapping.schema[name]
50+
if isinstance(decl, nodes.TypeDeclaration):
51+
decl = decl.type.type
52+
fn(schema_name, name, decl) is not False
3653

54+
for name in mapping.schema:
55+
write(name)
56+
57+
self.str = "\n".join(statements) + "\n"
3758

59+
self.file_name = '%s-definitions.h' % self.schema_name
60+
3861
def __repr__(self):
3962
return self.str

src/ifcexpressparser/templates.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
#include "../ifcparse/IfcException.h"
3535
#include "../ifcparse/Argument.h"
3636
37-
#include "../ifcparse/%(schema_name)senum.h"
38-
3937
struct %(schema_name)s {
4038
4139
static const IfcParse::schema_definition& get_schema();

src/ifcgeom/IfcGeom.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ if ( it != cache.T.end() ) { e = it->second; return true; }
8080

8181
#define INCLUDE_PARENT_DIR(x) STRINGIFY(../ifcparse/x.h)
8282
#include INCLUDE_PARENT_DIR(IfcSchema)
83+
#undef INCLUDE_PARENT_DIR
84+
#define INCLUDE_PARENT_DIR(x) STRINGIFY(../ifcparse/x-definitions.h)
85+
#include INCLUDE_PARENT_DIR(IfcSchema)
8386

8487
namespace IfcGeom {
8588
class IFC_GEOM_API geometry_exception : public std::exception {
@@ -357,7 +360,7 @@ class IFC_GEOM_API MAKE_TYPE_NAME(Kernel) : public IfcGeom::Kernel {
357360
const SurfaceStyle* get_style(const IfcSchema::IfcMaterial*);
358361

359362
template <typename T> std::pair<IfcSchema::IfcSurfaceStyle*, T*> _get_surface_style(const IfcSchema::IfcStyledItem* si) {
360-
#ifdef USE_IFC4
363+
#ifdef SCHEMA_HAS_IfcStyleAssignmentSelect
361364
IfcEntityList::ptr style_assignments = si->Styles();
362365
for (IfcEntityList::it kt = style_assignments->begin(); kt != style_assignments->end(); ++kt) {
363366
if (!(*kt)->declaration().is(IfcSchema::IfcPresentationStyleAssignment::Class())) {

src/ifcgeom/IfcGeomCurves.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@
7777

7878
#include <TopLoc_Location.hxx>
7979

80-
#ifdef USE_IFC4
80+
#include "../ifcgeom/IfcGeom.h"
81+
82+
#ifdef SCHEMA_HAS_IfcBSplineCurveWithKnots
8183
#include <Geom_BSplineCurve.hxx>
8284
#endif
8385

84-
#include "../ifcgeom/IfcGeom.h"
85-
8686
#define Kernel MAKE_TYPE_NAME(Kernel)
8787

8888
bool IfcGeom::Kernel::convert(const IfcSchema::IfcCircle* l, Handle(Geom_Curve)& curve) {
@@ -143,7 +143,7 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcLine* l, Handle(Geom_Curve)& c
143143
return true;
144144
}
145145

146-
#ifdef USE_IFC4
146+
#ifdef SCHEMA_HAS_IfcBSplineCurveWithKnots
147147
bool IfcGeom::Kernel::convert(const IfcSchema::IfcBSplineCurveWithKnots* l, Handle(Geom_Curve)& curve) {
148148

149149
const bool is_rational = l->declaration().is(IfcSchema::IfcRationalBSplineCurveWithKnots::Class());

0 commit comments

Comments
 (0)