Skip to content

Commit 5e0da97

Browse files
authored
ifcparse refactoring (IfcOpenShell#190)
Unify attribute containers, provide latebound attribute access on IfcBaseEntity, more basic tests on Travis
1 parent 9a43658 commit 5e0da97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+9223
-9411
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ script:
5151
- cd cmake
5252
- mkdir build-ifc2x3 build-ifc4
5353
- cd build-ifc2x3
54-
- cmake -DCOLLADA_SUPPORT=True -DOPENCOLLADA_INCLUDE_DIR=/usr/local/include/opencollada -DOPENCOLLADA_LIBRARY_DIR=/usr/local/lib/opencollada -DPCRE_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu -DUSE_IFC4=False -DBUILD_IFCPYTHON=True -DUNICODE_SUPPORT=True -DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu ..
54+
- cmake -DCOLLADA_SUPPORT=True -DOPENCOLLADA_INCLUDE_DIR=/usr/local/include/opencollada -DOPENCOLLADA_LIBRARY_DIR=/usr/local/lib/opencollada -DPCRE_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu -DUSE_IFC4=False -DBUILD_IFCPYTHON=True -DUNICODE_SUPPORT=True -DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu -DPYTHON_LIBRARY=/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so -DPYTHON_INCLUDE_DIR=/usr/include/python2.7 -DPYTHON_EXECUTABLE=/usr/bin/python2.7 ..
5555
- make -j
56+
- sudo make install
5657
- ./examples/IfcOpenHouse
5758
- ./examples/IfcAdvancedHouse
5859
- test -f IfcOpenHouse.ifc
5960
- test -f IfcAdvancedHouse.ifc
60-
- cd ../build-ifc4
61-
- cmake -DCOLLADA_SUPPORT=True -DOPENCOLLADA_INCLUDE_DIR=/usr/local/include/opencollada -DOPENCOLLADA_LIBRARY_DIR=/usr/local/lib/opencollada -DPCRE_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu -DUSE_IFC4=True -DBUILD_IFCPYTHON=True -DUNICODE_SUPPORT=True -DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu ..
61+
- cd ../../test
62+
- /usr/bin/python2.7 tests.py
63+
- cd ../cmake/build-ifc4
64+
- cmake -DCOLLADA_SUPPORT=True -DOPENCOLLADA_INCLUDE_DIR=/usr/local/include/opencollada -DOPENCOLLADA_LIBRARY_DIR=/usr/local/lib/opencollada -DPCRE_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu -DUSE_IFC4=True -DBUILD_IFCPYTHON=True -DUNICODE_SUPPORT=True -DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu -DPYTHON_LIBRARY=/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so -DPYTHON_INCLUDE_DIR=/usr/include/python2.7 -DPYTHON_EXECUTABLE=/usr/bin/python2.7 ..
6265
- make -j
6366
- ./examples/IfcOpenHouse
6467
- ./examples/IfcAdvancedHouse

src/examples/IfcAdvancedHouse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include "../ifcparse/Ifc2x3.h"
4545
#endif
4646

47-
#include "../ifcparse/IfcUtil.h"
47+
#include "../ifcparse/IfcBaseClass.h"
4848
#include "../ifcparse/IfcHierarchyHelper.h"
4949
#include "../ifcgeom/IfcGeom.h"
5050

src/examples/IfcOpenHouse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include "../ifcparse/Ifc2x3.h"
3838
#endif
3939

40-
#include "../ifcparse/IfcUtil.h"
40+
#include "../ifcparse/IfcBaseClass.h"
4141
#include "../ifcparse/IfcHierarchyHelper.h"
4242
#include "../ifcgeom/IfcGeom.h"
4343

src/ifcexpressparser/implementation.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def get_attribute_index(entity, attr_name):
144144
'body' : templates.get_inverse % {'type': i.entity, 'index':get_attribute_index(i.entity, i.attribute)}
145145
} for i in (type.inverse.elements if type.inverse else [])]
146146

147-
superclass = "%s((IfcAbstractEntity*)0)" % type.supertypes[0] if len(type.supertypes) == 1 else 'IfcUtil::IfcBaseEntity()'
147+
superclass = "%s((IfcEntityInstanceData*)0)" % type.supertypes[0] if len(type.supertypes) == 1 else 'IfcUtil::IfcBaseEntity()'
148148

149149
write(
150150
templates.entity_implementation,
@@ -209,15 +209,15 @@ def compose(params):
209209
return tmpl % locals()
210210

211211
simple_type_impl.append(templates.simpletype_impl_comment % {'name': class_name})
212-
simple_type_impl.extend(map(compose, map(lambda x: (class_name, attr_type, superclass, "(IfcAbstractEntity*)0")+x, (
213-
('getArgumentType', templates.const_function, 'IfcUtil::ArgumentType', ('unsigned int i',), templates.simpletype_impl_argument_type ),
214-
('getArgument', templates.const_function, 'Argument*', ('unsigned int i',), templates.simpletype_impl_argument ),
215-
('is', templates.const_function, 'bool', ('Type::Enum v',), simpletype_impl_is ),
216-
('type', templates.const_function, 'Type::Enum', (), templates.simpletype_impl_type ),
217-
('Class', templates.function, 'Type::Enum', (), templates.simpletype_impl_class ),
218-
('', constructor, '', ('IfcAbstractEntity* e',), templates.simpletype_impl_explicit_constructor),
219-
('', constructor, '', ("%s v" % type_str,), simpletype_impl_constructor ),
220-
('', templates.cast_function, type_str, (), simpletype_impl_cast )
212+
simple_type_impl.extend(map(compose, map(lambda x: (class_name, attr_type, superclass, "(IfcEntityInstanceData*)0")+x, (
213+
('getArgumentType', templates.const_function, 'IfcUtil::ArgumentType', ('unsigned int i',), templates.simpletype_impl_argument_type ),
214+
('getArgument', templates.const_function, 'Argument*', ('unsigned int i',), templates.simpletype_impl_argument ),
215+
('is', templates.const_function, 'bool', ('Type::Enum v',), simpletype_impl_is ),
216+
('type', templates.const_function, 'Type::Enum', (), templates.simpletype_impl_type ),
217+
('Class', templates.function, 'Type::Enum', (), templates.simpletype_impl_class ),
218+
('', constructor, '', ('IfcEntityInstanceData* e',), templates.simpletype_impl_explicit_constructor),
219+
('', constructor, '', ("%s v" % type_str,), simpletype_impl_constructor ),
220+
('', templates.cast_function, type_str, (), simpletype_impl_cast )
221221
))))
222222
simple_type_impl.append('')
223223

src/ifcexpressparser/templates.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
2929
#include "../ifcparse/ifc_parse_api.h"
3030
31-
#include "../ifcparse/IfcUtil.h"
31+
#include "../ifcparse/IfcEntityList.h"
32+
#include "../ifcparse/IfcBaseClass.h"
3233
#include "../ifcparse/IfcException.h"
34+
#include "../ifcparse/Argument.h"
35+
3336
#include "../ifcparse/%(schema_name)senum.h"
3437
3538
#define IfcSchema %(schema_name)s
@@ -45,7 +48,7 @@
4548
4649
%(class_definitions)s
4750
void InitStringMap();
48-
IfcUtil::IfcBaseClass* SchemaEntity(IfcAbstractEntity* e = 0);
51+
IfcUtil::IfcBaseClass* SchemaEntity(IfcEntityInstanceData* e = 0);
4952
}
5053
5154
#endif
@@ -57,6 +60,7 @@
5760
5861
#include "../ifcparse/ifc_parse_api.h"
5962
63+
#include <string>
6064
#include <boost/optional.hpp>
6165
6266
#define IfcSchema %(schema_name)s
@@ -85,9 +89,8 @@
8589
#define IfcSchema %(schema_name)s
8690
8791
#include "../ifcparse/ifc_parse_api.h"
88-
#include "../ifcparse/IfcUtil.h"
92+
#include "../ifcparse/IfcBaseClass.h"
8993
#include "../ifcparse/IfcEntityDescriptor.h"
90-
#include "../ifcparse/IfcWritableEntity.h"
9194
9295
namespace %(schema_name)s {
9396
namespace Type {
@@ -101,7 +104,7 @@
101104
IFC_PARSE_API std::pair<const char*, int> GetEnumerationIndex(Enum t, const std::string& a);
102105
IFC_PARSE_API std::pair<Enum, unsigned> GetInverseAttribute(Enum t, const std::string& a);
103106
IFC_PARSE_API std::set<std::string> GetInverseAttributeNames(Enum t);
104-
IFC_PARSE_API void PopulateDerivedFields(IfcWrite::IfcWritableEntity* e);
107+
IFC_PARSE_API void PopulateDerivedFields(IfcEntityInstanceData* e);
105108
}}
106109
107110
#endif
@@ -111,15 +114,14 @@
111114
#include "../ifcparse/%(schema_name)s.h"
112115
#include "../ifcparse/IfcException.h"
113116
#include "../ifcparse/IfcWrite.h"
114-
#include "../ifcparse/IfcWritableEntity.h"
115117
116118
#include <map>
117119
118120
using namespace %(schema_name)s;
119121
using namespace IfcParse;
120122
using namespace IfcWrite;
121123
122-
IfcUtil::IfcBaseClass* %(schema_name)s::SchemaEntity(IfcAbstractEntity* e) {
124+
IfcUtil::IfcBaseClass* %(schema_name)s::SchemaEntity(IfcEntityInstanceData* e) {
123125
switch(e->type()) {
124126
%(schema_entity_statements)s
125127
default: throw IfcException("Unable to find find keyword in schema"); break;
@@ -172,8 +174,7 @@
172174
#include "../ifcparse/%(schema_name)s-latebound.h"
173175
#include "../ifcparse/IfcException.h"
174176
#include "../ifcparse/IfcWrite.h"
175-
#include "../ifcparse/IfcWritableEntity.h"
176-
#include "../ifcparse/IfcUtil.h"
177+
#include "../ifcparse/IfcBaseClass.h"
177178
#include "../ifcparse/IfcEntityDescriptor.h"
178179
179180
using namespace %(schema_name)s;
@@ -320,12 +321,14 @@
320321
return return_value;
321322
}
322323
323-
void Type::PopulateDerivedFields(IfcWrite::IfcWritableEntity* e) {
324+
void Type::PopulateDerivedFields(IfcEntityInstanceData* e) {
324325
if (derived_map.empty()) ::InitDerivedMap();
325326
std::map<Type::Enum, std::set<int> >::const_iterator i = derived_map.find(e->type());
326327
if (i != derived_map.end()) {
327328
for (std::set<int>::const_iterator it = i->second.begin(); it != i->second.end(); ++it) {
328-
e->setArgumentDerived(*it);
329+
IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();
330+
attr->set(IfcWrite::IfcWriteArgument::Derived());
331+
e->setArgument(*it, attr);
329332
}
330333
}
331334
}
@@ -355,7 +358,7 @@ class IFC_PARSE_API %(name)s : public %(superclass)s {
355358
bool is(Type::Enum v) const;
356359
Type::Enum type() const;
357360
static Type::Enum Class();
358-
explicit %(name)s (IfcAbstractEntity* e);
361+
explicit %(name)s (IfcEntityInstanceData* e);
359362
%(name)s (%(type)s v);
360363
operator %(type)s() const;
361364
};
@@ -369,8 +372,8 @@ class IFC_PARSE_API %(name)s : public %(superclass)s {
369372
simpletype_impl_type = "return Type::%(class_name)s;"
370373
simpletype_impl_class = "return Type::%(class_name)s;"
371374
simpletype_impl_explicit_constructor = "entity = e;"
372-
simpletype_impl_constructor = "IfcWritableEntity* e = new IfcWritableEntity(Type::%(class_name)s); e->setArgument(0, v); entity = e;"
373-
simpletype_impl_constructor_templated = "IfcWritableEntity* e = new IfcWritableEntity(Type::%(class_name)s); e->setArgument(0, v->generalize()); entity = e;"
375+
simpletype_impl_constructor = "entity = new IfcEntityInstanceData(Class()); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(v" +"); entity->setArgument(0, attr);}"
376+
simpletype_impl_constructor_templated = "entity = new IfcEntityInstanceData(Class()); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(v->generalize()); entity->setArgument(0, attr);}"
374377
simpletype_impl_cast = "return *entity->getArgument(0);"
375378
simpletype_impl_cast_templated = "IfcEntityList::ptr es = *entity->getArgument(0); return es->as<%(underlying_type)s>();"
376379

@@ -397,7 +400,7 @@ class IFC_PARSE_API %(name)s %(superclass)s{
397400
%(inverse)s bool is(Type::Enum v) const;
398401
Type::Enum type() const;
399402
static Type::Enum Class();
400-
%(name)s (IfcAbstractEntity* e);
403+
%(name)s (IfcEntityInstanceData* e);
401404
%(name)s (%(constructor_arguments)s);
402405
typedef IfcTemplatedEntityList< %(name)s > list;
403406
};
@@ -420,8 +423,8 @@ class IFC_PARSE_API %(name)s %(superclass)s{
420423
%(attributes)s%(inverse)sbool %(name)s::is(Type::Enum v) const { return v == Type::%(name)s%(parent_type_test)s; }
421424
Type::Enum %(name)s::type() const { return Type::%(name)s; }
422425
Type::Enum %(name)s::Class() { return Type::%(name)s; }
423-
%(name)s::%(name)s(IfcAbstractEntity* e) : %(superclass)s { if (!e) return; if (!e->is(Type::%(name)s)) throw IfcException("Unable to find find keyword in schema"); entity = e; }
424-
%(name)s::%(name)s(%(constructor_arguments)s) : %(superclass)s { IfcWritableEntity* e = new IfcWritableEntity(Class());%(constructor_implementation)s entity = e; EntityBuffer::Add(this); }
426+
%(name)s::%(name)s(IfcEntityInstanceData* e) : %(superclass)s { if (!e) return; if (e->type() != Type::%(name)s) throw IfcException("Unable to find find keyword in schema"); entity = e; }
427+
%(name)s::%(name)s(%(constructor_arguments)s) : %(superclass)s {entity = new IfcEntityInstanceData(Class()); %(constructor_implementation)s }
425428
"""
426429

427430
optional_attribute_description = "/// Whether the optional attribute %s is defined for this %s"
@@ -457,15 +460,16 @@ class IFC_PARSE_API %(name)s %(superclass)s{
457460

458461
get_inverse = "return entity->getInverse(Type::%(type)s, %(index)d)->as<%(type)s>();"
459462

460-
set_attr_stmt = "if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(%(index)d,v);"
461-
set_attr_stmt_enum = "if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(%(index)d,v,%(type)s::ToString(v));"
462-
set_attr_stmt_array = "if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(%(index)d,v->generalize());"
463+
set_attr_stmt = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(v" +");entity->setArgument(%(index)d,attr);}"
464+
set_attr_stmt_enum = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(IfcWrite::IfcWriteArgument::EnumerationReference(v,%(type)s::ToString(v)));entity->setArgument(%(index)d,attr);}"
465+
set_attr_stmt_array = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(v->generalize()" +");entity->setArgument(%(index)d,attr);}"
466+
467+
constructor_stmt = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((%(name)s)" +");entity->setArgument(%(index)d,attr);}"
468+
constructor_stmt_enum = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((IfcWrite::IfcWriteArgument::EnumerationReference(%(name)s,%(type)s::ToString(%(name)s)))" +");entity->setArgument(%(index)d,attr);}"
469+
constructor_stmt_array = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((%(name)s)->generalize()" +");entity->setArgument(%(index)d,attr);}"
470+
constructor_stmt_derived = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(IfcWrite::IfcWriteArgument::Derived()" +");entity->setArgument(%(index)d,attr);}"
463471

464-
constructor_stmt = " e->setArgument(%(index)d,(%(name)s));"
465-
constructor_stmt_enum = " e->setArgument(%(index)d,%(name)s,%(type)s::ToString(%(name)s));"
466-
constructor_stmt_array = " e->setArgument(%(index)d,(%(name)s)->generalize());"
467-
constructor_stmt_optional = " if (%(name)s) {%(stmt)s } else { e->setArgument(%(index)d); }"
468-
constructor_stmt_derived = " e->setArgumentDerived(%(index)d);"
472+
constructor_stmt_optional = " if (%(name)s) {%(stmt)s } else { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(boost::none); entity->setArgument(%(index)d, attr); }"
469473

470474
inverse_implementation = " inverse_map[Type::%(type)s].insert(std::make_pair(\"%(name)s\", std::make_pair(Type::%(related_type)s, %(index)d)));"
471475

src/ifcgeom/IfcGeom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ inline static bool ALMOST_THE_SAME(const T& a, const T& b, double tolerance=ALMO
4747
#include <BOPAlgo_Operation.hxx>
4848

4949
#include "../ifcparse/IfcParse.h"
50-
#include "../ifcparse/IfcUtil.h"
50+
#include "../ifcparse/IfcBaseClass.h"
5151

5252
#include "../ifcgeom/IfcGeomElement.h"
5353
#include "../ifcgeom/IfcGeomRepresentation.h"

src/ifcgeom/IfcGeomFilter.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#define IFCGEOMFILTER_H
2525

2626
#include "IfcGeom.h"
27-
#include "../ifcparse/IfcWritableEntity.h"
2827

2928
#include <boost/function.hpp>
3029
#include <boost/regex.hpp>
@@ -144,7 +143,7 @@ namespace IfcGeom
144143
{
145144
#ifndef NDEBUG
146145
for (arg_map_t::const_iterator it = args.begin(); it != args.end(); ++it) {
147-
IfcWrite::IfcWritableEntity dummy(it->first);
146+
IfcEntityInstanceData dummy(it->first);
148147
IfcUtil::IfcBaseClass* base = IfcSchema::SchemaEntity(&dummy);
149148
assert(it->second < base->getArgumentCount() && "Argument index out of bounds");
150149
assert(base->getArgumentType(it->second) == IfcUtil::Argument_STRING && "Argument type not string");
@@ -186,7 +185,7 @@ namespace IfcGeom
186185
}
187186

188187
for (arg_map_t::const_iterator it = args.begin(); it != args.end(); ++it) {
189-
IfcWrite::IfcWritableEntity dummy(it->first);
188+
IfcEntityInstanceData dummy(it->first);
190189
IfcUtil::IfcBaseClass* base = IfcSchema::SchemaEntity(&dummy);
191190
try {
192191
ss << " " << IfcSchema::Type::ToString(it->first) << "." << base->getArgumentName(it->second);

src/ifcgeom/IfcGeomIteratorSettings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "ifc_geom_api.h"
2424
#include "../ifcparse/IfcException.h"
25-
#include "../ifcparse/IfcUtil.h"
25+
#include "../ifcparse/IfcBaseClass.h"
2626

2727
namespace IfcGeom
2828
{

src/ifcgeom/IfcRegister.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <gp_Trsf.hxx>
3939
#include <gp_Trsf2d.hxx>
4040

41-
#include "../ifcparse/IfcUtil.h"
41+
#include "../ifcparse/IfcBaseClass.h"
4242
#include "../ifcparse/IfcParse.h"
4343

4444
SHAPES(IfcShellBasedSurfaceModel);

src/ifcopenshell-python/ifcopenshell/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def open(fn=None):
6060

6161

6262
def create_entity(type,*args,**kwargs):
63-
e = entity_instance(ifcopenshell_wrapper.entity_instance(type))
63+
e = entity_instance(type)
6464
attrs = list(enumerate(args)) + \
6565
[(e.wrapped_data.get_argument_index(name), arg) for name, arg in kwargs.items()]
6666
for idx, arg in attrs: e[idx] = arg

0 commit comments

Comments
 (0)