Skip to content

Commit 7390faa

Browse files
committed
Adapt XML serializer for changes in IFC4 decomposition and property set types
1 parent b7d4eb6 commit 7390faa

3 files changed

Lines changed: 37 additions & 12 deletions

File tree

src/ifcconvert/XmlSerializer.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ typename V::list::ptr get_related(T* t, F f, G g) {
119119
typename V::list::ptr acc(new typename V::list);
120120
for (typename U::list::it it = li->begin(); it != li->end(); ++it) {
121121
U* u = *it;
122-
acc->push((*u.*g)());
122+
acc->push((*u.*g)()->as<V>());
123123
}
124124
return acc;
125125
}
@@ -142,9 +142,15 @@ void descend(IfcProduct* product, ptree& tree) {
142142
}
143143
}
144144

145+
#ifdef USE_IFC2x3
145146
IfcObjectDefinition::list::ptr structures = get_related
146147
<IfcProduct, IfcRelDecomposes, IfcObjectDefinition>
147148
(product, &IfcProduct::IsDecomposedBy, &IfcRelDecomposes::RelatedObjects);
149+
#else
150+
IfcObjectDefinition::list::ptr structures = get_related
151+
<IfcProduct, IfcRelAggregates, IfcObjectDefinition>
152+
(product, &IfcProduct::IsDecomposedBy, &IfcRelAggregates::RelatedObjects);
153+
#endif
148154

149155
for (IfcObjectDefinition::list::it it = structures->begin(); it != structures->end(); ++it) {
150156
IfcObjectDefinition* ob = *it;
@@ -172,9 +178,15 @@ template <>
172178
void descend(IfcProject* project, ptree& tree) {
173179
ptree& child = format_entity_instance(project, tree);
174180

181+
#ifdef USE_IFC2x3
175182
IfcObjectDefinition::list::ptr structures = get_related
176183
<IfcProject, IfcRelDecomposes, IfcObjectDefinition>
177184
(project, &IfcProject::IsDecomposedBy, &IfcRelDecomposes::RelatedObjects);
185+
#else
186+
IfcObjectDefinition::list::ptr structures = get_related
187+
<IfcProject, IfcRelAggregates, IfcObjectDefinition>
188+
(project, &IfcProduct::IsDecomposedBy, &IfcRelAggregates::RelatedObjects);
189+
#endif
178190

179191
for (IfcObjectDefinition::list::it it = structures->begin(); it != structures->end(); ++it) {
180192
IfcObjectDefinition* ob = *it;

src/ifcparse/IfcUtil.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@
2525
#include "IfcUtil.h"
2626

2727
void IfcEntityList::push(IfcUtil::IfcBaseClass* l) {
28-
if ( l ) ls.push_back(l);
28+
if (l) {
29+
ls.push_back(l);
30+
}
2931
}
3032
void IfcEntityList::push(const IfcEntityList::ptr& l) {
31-
for( it i = l->begin(); i != l->end(); ++i ) {
32-
if ( *i ) ls.push_back(*i);
33+
if (l) {
34+
for( it i = l->begin(); i != l->end(); ++i ) {
35+
if ( *i ) ls.push_back(*i);
36+
}
3337
}
3438
}
3539
unsigned int IfcEntityList::size() const { return (unsigned int) ls.size(); }

src/ifcparse/IfcUtil.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ namespace IfcUtil {
8080
virtual IfcSchema::Type::Enum getArgumentEntity(unsigned int i) const = 0;
8181
virtual Argument* getArgument(unsigned int i) const = 0;
8282
virtual const char* getArgumentName(unsigned int i) const = 0;
83+
84+
template <class T>
85+
typename T* as() {
86+
return is(T::Class())
87+
? static_cast<T*>(this)
88+
: static_cast<T*>(0);
89+
}
8390
};
8491

8592
class IfcBaseEntity : public IfcBaseClass {
@@ -127,8 +134,8 @@ class IfcTemplatedEntityList {
127134
public:
128135
typedef SHARED_PTR< IfcTemplatedEntityList<T> > ptr;
129136
typedef typename std::vector<T*>::const_iterator it;
130-
void push(T* t) {if (t) ls.push_back(t);}
131-
void push(ptr t) { for ( typename T::list::it it = t->begin(); it != t->end(); ++it ) push(*it); }
137+
void push(T* t) { if (t) { ls.push_back(t); } }
138+
void push(ptr t) { if (t) { for ( typename T::list::it it = t->begin(); it != t->end(); ++it ) push(*it); } }
132139
it begin() { return ls.begin(); }
133140
it end() { return ls.end(); }
134141
unsigned int size() const { return (unsigned int) ls.size(); }
@@ -162,15 +169,17 @@ class IfcEntityListList {
162169
typedef SHARED_PTR< IfcEntityListList > ptr;
163170
typedef std::vector< std::vector<IfcUtil::IfcBaseClass*> >::const_iterator outer_it;
164171
typedef std::vector<IfcUtil::IfcBaseClass*>::const_iterator inner_it;
165-
void push(const std::vector<IfcUtil::IfcBaseClass*>& l) {
172+
void push(const std::vector<IfcUtil::IfcBaseClass*>& l) {
166173
ls.push_back(l);
167174
}
168175
void push(const IfcEntityList::ptr& l) {
169-
std::vector<IfcUtil::IfcBaseClass*> li;
170-
for (std::vector<IfcUtil::IfcBaseClass*>::const_iterator jt = l->begin(); jt != l->end(); ++jt) {
171-
li.push_back(*jt);
172-
}
173-
push(li);
176+
if (l) {
177+
std::vector<IfcUtil::IfcBaseClass*> li;
178+
for (std::vector<IfcUtil::IfcBaseClass*>::const_iterator jt = l->begin(); jt != l->end(); ++jt) {
179+
li.push_back(*jt);
180+
}
181+
push(li);
182+
}
174183
}
175184
outer_it begin() const { return ls.begin(); }
176185
outer_it end() const { return ls.end(); }

0 commit comments

Comments
 (0)