Skip to content

Commit a792a7e

Browse files
committed
Two simultaneous IfcGeom implementations
1 parent 5eba7af commit a792a7e

37 files changed

+8929
-8847
lines changed

cmake/CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ if(NOT MSVC)
551551
endif()
552552
endif()
553553

554-
set(IFCOPENSHELL_LIBRARIES IfcParse IfcGeom)
554+
set(IFCOPENSHELL_LIBRARIES IfcParse IfcGeom_ifc2x3 IfcGeom_ifc4)
555555

556556
# IfcParse
557557
file(GLOB IFCPARSE_H_FILES ../src/ifcparse/*.h)
@@ -579,10 +579,18 @@ file(GLOB IFCGEOM_H_FILES ../src/ifcgeom/*.h)
579579
file(GLOB IFCGEOM_CPP_FILES ../src/ifcgeom/*.cpp)
580580
set(IFCGEOM_FILES ${IFCGEOM_CPP_FILES} ${IFCGEOM_H_FILES})
581581

582-
add_library(IfcGeom ${IFCGEOM_FILES})
583-
set_target_properties(IfcGeom PROPERTIES COMPILE_FLAGS -DIFC_GEOM_EXPORTS)
582+
add_library(IfcGeom_ifc2x3 ${IFCGEOM_FILES})
583+
add_library(IfcGeom_ifc4 ${IFCGEOM_FILES})
584584

585-
TARGET_LINK_LIBRARIES(IfcGeom IfcParse ${OPENCASCADE_LIBRARIES})
585+
set_target_properties(IfcGeom_ifc2x3 PROPERTIES COMPILE_FLAGS -DIFC_GEOM_EXPORTS)
586+
set_target_properties(IfcGeom_ifc4 PROPERTIES COMPILE_FLAGS -DIFC_GEOM_EXPORTS)
587+
588+
set_target_properties(IfcGeom_ifc2x3 PROPERTIES COMPILE_FLAGS -DIfcSchema=Ifc2x3)
589+
# TODO: Detect based on IfcSchema
590+
set_target_properties(IfcGeom_ifc4 PROPERTIES COMPILE_FLAGS "-DIfcSchema=Ifc4 -DUSE_IFC4")
591+
592+
TARGET_LINK_LIBRARIES(IfcGeom_ifc2x3 IfcParse ${OPENCASCADE_LIBRARIES})
593+
TARGET_LINK_LIBRARIES(IfcGeom_ifc4 IfcParse ${OPENCASCADE_LIBRARIES})
586594

587595
# IfcConvert
588596
file(GLOB IFCCONVERT_CPP_FILES ../src/ifcconvert/*.cpp)
@@ -632,7 +640,7 @@ INSTALL(FILES ${IFCGEOM_H_FILES}
632640
DESTINATION ${INCLUDEDIR}/ifcgeom
633641
)
634642

635-
INSTALL(TARGETS IfcParse IfcGeom IfcConvert IfcGeomServer
643+
INSTALL(TARGETS IfcParse IfcGeom_ifc2x3 IfcGeom_ifc4 IfcConvert IfcGeomServer
636644
ARCHIVE DESTINATION ${LIBDIR}
637645
LIBRARY DESTINATION ${LIBDIR}
638646
RUNTIME DESTINATION ${BINDIR}

src/ifcexpressparser/implementation.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self, mapping):
2929
schema_entity_statements = []
3030

3131
schema_name = mapping.schema.name.capitalize()
32+
schema_name_upper = mapping.schema.name.upper()
3233

3334
stringify = lambda s: '"%s"'%s
3435
cat = lambda vs: "".join(vs)
@@ -47,6 +48,7 @@ def __init__(self, mapping):
4748
max_id = len(enum.values),
4849
name = name,
4950
schema_name = schema_name,
51+
schema_name_upper = schema_name_upper,
5052
values = catc(map(stringify, enum.values)),
5153
from_string_statements = catnl(templates.enum_from_string_stmt%dict(context,**locals()) for value in enum.values)
5254
)
@@ -73,6 +75,7 @@ def __init__(self, mapping):
7375
templates.const_function,
7476
class_name = name,
7577
schema_name = schema_name,
78+
schema_name_upper = schema_name_upper,
7679
name = 'has%s'%arg['name'],
7780
arguments = '',
7881
return_type = 'bool',
@@ -96,6 +99,7 @@ def find_template(arg):
9699
name = arg['name'],
97100
arguments = '',
98101
schema_name = schema_name,
102+
schema_name_upper = schema_name_upper,
99103
return_type = arg['non_optional_type'],
100104
body = tmpl % {'index': arg['index']-1,
101105
'type' : arg['non_optional_type'].replace('::Value', ''),
@@ -118,6 +122,7 @@ def find_template(arg):
118122
arguments = '%s v'%arg['non_optional_type'],
119123
return_type = 'void',
120124
schema_name = schema_name,
125+
schema_name_upper = schema_name_upper,
121126
body = tmpl % {'index': arg['index']-1,
122127
'type' : arg['non_optional_type'].replace('::Value', '')}
123128
)
@@ -148,10 +153,11 @@ def get_attribute_index(entity, attr_name):
148153
inverse = [templates.const_function % {
149154
'class_name' : name,
150155
'schema_name' : schema_name,
156+
'schema_name_upper' : schema_name_upper,
151157
'name' : i.name,
152158
'arguments' : '',
153159
'return_type' : '::%s::%s::list::ptr' % (schema_name, i.entity),
154-
'body' : templates.get_inverse % {'type': i.entity, 'index':get_attribute_index(i.entity, i.attribute), 'schema_name' : schema_name}
160+
'body' : templates.get_inverse % {'type': i.entity, 'index':get_attribute_index(i.entity, i.attribute), 'schema_name' : schema_name, 'schema_name_upper': schema_name_upper}
155161
} for i in (type.inverse.elements if type.inverse else [])]
156162

157163
superclass = "%s((IfcEntityInstanceData*)0)" % type.supertypes[0] if len(type.supertypes) == 1 else 'IfcUtil::IfcBaseEntity()'
@@ -165,7 +171,8 @@ def get_attribute_index(entity, attr_name):
165171
attributes = nl(catnl(attributes)),
166172
inverse = nl(catnl(inverse)),
167173
superclass = superclass,
168-
schema_name = schema_name
174+
schema_name = schema_name,
175+
schema_name_upper = schema_name_upper
169176
)
170177

171178
selectable_simple_types = sorted(set(sum([b.values for a,b in mapping.schema.selects.items()], [])) & set(map(str, mapping.schema.types.keys())))
@@ -212,7 +219,7 @@ def get_parent_id(s):
212219
simpletype_impl_constructor = templates.simpletype_impl_constructor_templated if mapping.is_templated_list(type) \
213220
else templates.simpletype_impl_constructor
214221

215-
def compose(params, schema_name=schema_name):
222+
def compose(params, schema_name=schema_name, schema_name_upper=schema_name_upper):
216223
class_name, attr_type, superclass, superclass_init, name, tmpl, return_type, args, body = params
217224
underlying_type = mapping.list_instance_type(type)
218225
arguments = ",".join(args)
@@ -229,12 +236,12 @@ def compose(params, schema_name=schema_name):
229236
))))
230237
simple_type_impl.append('')
231238

232-
external_definitions = [("extern entity* %s_%%s_type;" % mapping.schema.name.capitalize()) % n for n in mapping.schema.entities.keys() ] + \
233-
[("extern type_declaration* %s_%%s_type;" % mapping.schema.name.capitalize()) % n for n in mapping.schema.simpletypes.keys()]
239+
external_definitions = [("extern entity* %s_%%s_type;" % schema_name_upper) % n for n in mapping.schema.entities.keys() ] + \
240+
[("extern type_declaration* %s_%%s_type;" % schema_name_upper) % n for n in mapping.schema.simpletypes.keys()]
234241

235242
self.str = templates.implementation % {
236-
'schema_name_upper' : mapping.schema.name.upper(),
237-
'schema_name' : mapping.schema.name.capitalize(),
243+
'schema_name_upper' : schema_name_upper,
244+
'schema_name' : schema_name,
238245
'max_id' : max_id,
239246
'enumeration_functions' : cat(enumeration_functions),
240247
'schema_entity_statements' : catnl(schema_entity_statements),

src/ifcexpressparser/schema_class.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,11 @@ def find_inverse_name_and_index(entity_name, attribute_name):
203203
#endif
204204
""")
205205

206-
statements.append("namespace %s {" % mapping.schema.name)
207-
208-
statements.extend(('const schema_definition& get_schema() {',
206+
statements.extend(('const schema_definition& %s::get_schema() {' % schema_name_title,
209207
'',
210208
' static const schema_definition* s = %(schema_name)s_populate_schema();' % locals(),
211209
' return *s;',
212-
'}','}','',''))
210+
'}','',''))
213211

214212
declarations_by_index.sort()
215213
declarations_by_index_map = dict(("index_in_schema_%s" % j,i) for i,j in enumerate(declarations_by_index))

src/ifcexpressparser/templates.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@
3636
3737
#include "../ifcparse/%(schema_name)senum.h"
3838
39-
#define IfcSchema %(schema_name)s
40-
4139
struct %(schema_name)s {
4240
43-
const IfcParse::schema_definition& get_schema();
41+
static const IfcParse::schema_definition& get_schema();
4442
4543
const char* const Identifier = "%(schema_name_upper)s";
4644
@@ -124,14 +122,14 @@ class IFC_PARSE_API %(name)s : public %(superclass)s {
124122
simpletype_impl_argument = "return data_->getArgument(i);"
125123
simpletype_impl_is_with_supertype = "return v == %(class_name)s_type || %(superclass)s::is(v);"
126124
simpletype_impl_is_without_supertype = "return v == %(class_name)s_type;"
127-
simpletype_impl_type = "return *%(schema_name)s_%(class_name)s_type;"
128-
simpletype_impl_class = "return *%(schema_name)s_%(class_name)s_type;"
125+
simpletype_impl_type = "return *%(schema_name_upper)s_%(class_name)s_type;"
126+
simpletype_impl_class = "return *%(schema_name_upper)s_%(class_name)s_type;"
129127
simpletype_impl_explicit_constructor = "data_ = e;"
130-
simpletype_impl_constructor = "data_ = new IfcEntityInstanceData(%(schema_name)s_%(class_name)s_type); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(v" +"); data_->setArgument(0, attr);}"
131-
simpletype_impl_constructor_templated = "data_ = new IfcEntityInstanceData(%(schema_name)s_%(class_name)s_type); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(v->generalize()); data_->setArgument(0, attr);}"
128+
simpletype_impl_constructor = "data_ = new IfcEntityInstanceData(%(schema_name_upper)s_%(class_name)s_type); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(v" +"); data_->setArgument(0, attr);}"
129+
simpletype_impl_constructor_templated = "data_ = new IfcEntityInstanceData(%(schema_name_upper)s_%(class_name)s_type); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(v->generalize()); data_->setArgument(0, attr);}"
132130
simpletype_impl_cast = "return *data_->getArgument(0);"
133131
simpletype_impl_cast_templated = "IfcEntityList::ptr es = *data_->getArgument(0); return es->as<%(underlying_type)s>();"
134-
simpletype_impl_declaration = "return *%(schema_name)s_%(class_name)s_type;"
132+
simpletype_impl_declaration = "return *%(schema_name_upper)s_%(class_name)s_type;"
135133

136134
select = """%(documentation)s
137135
typedef IfcUtil::IfcBaseClass %(name)s;
@@ -172,10 +170,10 @@ class IFC_PARSE_API %(name)s %(superclass)s{
172170
entity_implementation = """// Function implementations for %(name)s
173171
%(attributes)s
174172
%(inverse)s
175-
const IfcParse::entity& %(schema_name)s::%(name)s::declaration() const { return *%(schema_name)s_%(name)s_type; }
176-
const IfcParse::entity& %(schema_name)s::%(name)s::Class() { return *%(schema_name)s_%(name)s_type; }
177-
%(schema_name)s::%(name)s::%(name)s(IfcEntityInstanceData* e) : %(superclass)s { if (!e) return; if (e->type() != %(schema_name)s_%(name)s_type) throw IfcException("Unable to find find keyword in schema"); data_ = e; }
178-
%(schema_name)s::%(name)s::%(name)s(%(constructor_arguments)s) : %(superclass)s {data_ = new IfcEntityInstanceData(%(schema_name)s_%(name)s_type); %(constructor_implementation)s }
173+
const IfcParse::entity& %(schema_name)s::%(name)s::declaration() const { return *%(schema_name_upper)s_%(name)s_type; }
174+
const IfcParse::entity& %(schema_name)s::%(name)s::Class() { return *%(schema_name_upper)s_%(name)s_type; }
175+
%(schema_name)s::%(name)s::%(name)s(IfcEntityInstanceData* e) : %(superclass)s { if (!e) return; if (e->type() != %(schema_name_upper)s_%(name)s_type) throw IfcException("Unable to find find keyword in schema"); data_ = e; }
176+
%(schema_name)s::%(name)s::%(name)s(%(constructor_arguments)s) : %(superclass)s {data_ = new IfcEntityInstanceData(%(schema_name_upper)s_%(name)s_type); %(constructor_implementation)s }
179177
"""
180178

181179
optional_attribute_description = "/// Whether the optional attribute %s is defined for this %s"
@@ -209,7 +207,7 @@ class IFC_PARSE_API %(name)s %(superclass)s{
209207
get_attr_stmt_array = "IfcEntityList::ptr es = *data_->getArgument(%(index)d); return es->as<%(list_instance_type)s>();"
210208
get_attr_stmt_nested_array = "IfcEntityListList::ptr es = *data_->getArgument(%(index)d); return es->as<%(list_instance_type)s>();"
211209

212-
get_inverse = "return data_->getInverse(%(schema_name)s_%(type)s_type, %(index)d)->as<%(type)s>();"
210+
get_inverse = "return data_->getInverse(%(schema_name_upper)s_%(type)s_type, %(index)d)->as<%(type)s>();"
213211

214212
set_attr_stmt = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(v" +");data_->setArgument(%(index)d,attr);}"
215213
set_attr_stmt_enum = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(IfcWrite::IfcWriteArgument::EnumerationReference(v,%(type)s::ToString(v)));data_->setArgument(%(index)d,attr);}"

src/ifcgeom/IfcGeom.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class IFC_GEOM_API Kernel {
101101
const SurfaceStyle* internalize_surface_style(const std::pair<IfcSchema::IfcSurfaceStyle*, IfcSchema::IfcSurfaceStyleShading*>& shading_style);
102102

103103
// For stopping PlacementRelTo recursion in convert(const IfcSchema::IfcObjectPlacement* l, gp_Trsf& trsf)
104-
IfcSchema::Type::Enum placement_rel_to;
104+
const IfcParse::declaration* placement_rel_to;
105105

106106
public:
107107
Kernel()
@@ -113,7 +113,7 @@ class IFC_GEOM_API Kernel {
113113
, ifc_planeangle_unit(-1.0)
114114
, modelling_precision(0.00001)
115115
, dimensionality(1.)
116-
, placement_rel_to(IfcSchema::Type::UNDEFINED)
116+
, placement_rel_to(0)
117117
{}
118118

119119
Kernel(const Kernel& other) {
@@ -268,7 +268,7 @@ class IFC_GEOM_API Kernel {
268268
#ifdef USE_IFC4
269269
IfcEntityList::ptr style_assignments = si->Styles();
270270
for (IfcEntityList::it kt = style_assignments->begin(); kt != style_assignments->end(); ++kt) {
271-
if (!(*kt)->declaration().is(IfcSchema::Type::IfcPresentationStyleAssignment)) {
271+
if (!(*kt)->declaration().is(IfcSchema::IfcPresentationStyleAssignment::Class())) {
272272
continue;
273273
}
274274
IfcSchema::IfcPresentationStyleAssignment* style_assignment = (IfcSchema::IfcPresentationStyleAssignment*) *kt;
@@ -280,7 +280,7 @@ class IFC_GEOM_API Kernel {
280280
IfcEntityList::ptr styles = style_assignment->Styles();
281281
for (IfcEntityList::it lt = styles->begin(); lt != styles->end(); ++lt) {
282282
IfcUtil::IfcBaseClass* style = *lt;
283-
if (style->declaration().is(IfcSchema::Type::IfcSurfaceStyle)) {
283+
if (style->declaration().is(IfcSchema::IfcSurfaceStyle::Class())) {
284284
IfcSchema::IfcSurfaceStyle* surface_style = (IfcSchema::IfcSurfaceStyle*) style;
285285
if (surface_style->Side() != IfcSchema::IfcSurfaceSide::IfcSurfaceSide_NEGATIVE) {
286286
IfcEntityList::ptr styles_elements = surface_style->Styles();
@@ -322,7 +322,7 @@ class IFC_GEOM_API Kernel {
322322
#endif
323323
}
324324

325-
void set_conversion_placement_rel_to(IfcSchema::Type::Enum type);
325+
void set_conversion_placement_rel_to(const IfcParse::declaration* type);
326326

327327
#include "IfcRegisterGeomHeader.h"
328328

src/ifcgeom/IfcGeomCurves.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcCircle* l, Handle(Geom_Curve)&
9191
}
9292
gp_Trsf trsf;
9393
IfcSchema::IfcAxis2Placement* placement = l->Position();
94-
if (placement->declaration().is(IfcSchema::Type::IfcAxis2Placement3D)) {
94+
if (placement->declaration().is(IfcSchema::IfcAxis2Placement3D::Class())) {
9595
IfcGeom::Kernel::convert((IfcSchema::IfcAxis2Placement3D*)placement,trsf);
9696
} else {
9797
gp_Trsf2d trsf2d;
@@ -116,7 +116,7 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcEllipse* l, Handle(Geom_Curve)
116116
const bool rotated = y > x;
117117
gp_Trsf trsf;
118118
IfcSchema::IfcAxis2Placement* placement = l->Position();
119-
if (placement->declaration().is(IfcSchema::Type::IfcAxis2Placement3D)) {
119+
if (placement->declaration().is(IfcSchema::IfcAxis2Placement3D::Class())) {
120120
convert((IfcSchema::IfcAxis2Placement3D*)placement,trsf);
121121
} else {
122122
gp_Trsf2d trsf2d;
@@ -144,7 +144,7 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcLine* l, Handle(Geom_Curve)& c
144144
#ifdef USE_IFC4
145145
bool IfcGeom::Kernel::convert(const IfcSchema::IfcBSplineCurveWithKnots* l, Handle(Geom_Curve)& curve) {
146146

147-
const bool is_rational = l->declaration().is(IfcSchema::Type::IfcRationalBSplineCurveWithKnots);
147+
const bool is_rational = l->declaration().is(IfcSchema::IfcRationalBSplineCurveWithKnots::Class());
148148

149149
const IfcSchema::IfcCartesianPoint::list::ptr cps = l->ControlPointsList();
150150
const std::vector<int> mults = l->KnotMultiplicities();

src/ifcgeom/IfcGeomElement.h

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,31 +90,29 @@ namespace IfcGeom {
9090
std::string _context;
9191
std::string _unique_id;
9292
Transformation<P> _transformation;
93-
IfcSchema::IfcProduct* product_;
93+
IfcUtil::IfcBaseClass* product_;
9494
std::vector<const IfcGeom::Element<P>*> _parents;
9595
public:
9696

97-
friend bool operator == (const Element<P> & element1, const Element<P> & element2)
98-
{
97+
friend bool operator == (const Element<P> & element1, const Element<P> & element2) {
9998
return element1.id() == element2.id();
10099
}
101100

102101
// Use the id to compare, or the elevation is the elements are IfcBuildingStoreys and the elevation is set
103-
friend bool operator < (const Element<P> & element1, const Element<P> & element2)
104-
{
105-
if (element1.type() == "IfcBuildingStorey" && element2.type() == "IfcBuildingStorey")
106-
{
107-
IfcSchema::IfcBuildingStorey* storey1 = NULL;
108-
IfcSchema::IfcBuildingStorey* storey2 = NULL;
109-
110-
storey1 = (IfcSchema::IfcBuildingStorey*)element1.product();
111-
storey2 = (IfcSchema::IfcBuildingStorey*)element2.product();
112-
113-
if (storey1 != NULL && storey2 != NULL && storey1->hasElevation() && storey2->hasElevation())
114-
{
115-
return storey1->Elevation() < storey2->Elevation();
102+
friend bool operator < (const Element<P> & element1, const Element<P> & element2) {
103+
if (element1.type() == "IfcBuildingStorey" && element2.type() == "IfcBuildingStorey") {
104+
size_t attr_index = product_->declaration().as_entity->attribute_index("Elevation");
105+
Argument* elev_attr1 = storey1->data().getArgument(attr_index);
106+
Argument* elev_attr2 = storey2->data().getArgument(attr_index);
107+
108+
if (!elev_attr1->isNull() && !elev_attr2->isNull()) {
109+
double elev1 = *elev_attr1;
110+
double elev2 = *elev_attr2;
111+
112+
return elev1 < elev2;
116113
}
117114
}
115+
118116
return element1.id() < element2.id();
119117
}
120118

@@ -131,7 +129,7 @@ namespace IfcGeom {
131129
void SetParents(std::vector<const IfcGeom::Element<P>*> newparents) { _parents = newparents; }
132130

133131
Element(const ElementSettings& settings, int id, int parent_id, const std::string& name, const std::string& type,
134-
const std::string& guid, const std::string& context, const gp_Trsf& trsf, IfcSchema::IfcProduct *product)
132+
const std::string& guid, const std::string& context, const gp_Trsf& trsf, IfcUtil::IfcBaseClass* product)
135133
: _id(id), _parent_id(parent_id), _name(name), _type(type), _guid(guid), _context(context), _transformation(settings, trsf)
136134
, product_(product)
137135
{
@@ -169,8 +167,8 @@ namespace IfcGeom {
169167
const Representation::BRep& geometry() const { return *_geometry; }
170168
BRepElement(int id, int parent_id, const std::string& name, const std::string& type, const std::string& guid,
171169
const std::string& context, const gp_Trsf& trsf, const boost::shared_ptr<Representation::BRep>& geometry,
172-
IfcSchema::IfcProduct* product)
173-
: Element<P>(geometry->settings(),id,parent_id,name,type,guid,context,trsf, product)
170+
IfcUtil::IfcBaseClass* product)
171+
: Element<P>(geometry->settings() ,id, parent_id, name, type, guid, context, trsf, product)
174172
, _geometry(geometry)
175173
{}
176174
private:

0 commit comments

Comments
 (0)