From 175387bd88bdc39569596ca38ad77a7564135c09 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 13 Aug 2018 11:43:28 +0200 Subject: [PATCH] Fix IfcOpenHouse --- .travis.yml | 2 +- src/ifcgeom_schema_agnostic/Serialization.cpp | 4 ++-- src/ifcparse/IfcBaseClass.h | 6 ++++++ src/ifcparse/IfcHierarchyHelper.h | 17 +++++++++++------ src/ifcparse/IfcParse.cpp | 4 ++++ 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8056b9feec..7a5129021a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,7 @@ script: - cd cmake - mkdir build - cd build - - 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 -DBUILD_EXAMPLES=Off -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 .. + - 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 -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 .. - sudo make install - cd ../../test - /usr/bin/python2.7 tests.py diff --git a/src/ifcgeom_schema_agnostic/Serialization.cpp b/src/ifcgeom_schema_agnostic/Serialization.cpp index 79f41a726c..1e618c5f06 100644 --- a/src/ifcgeom_schema_agnostic/Serialization.cpp +++ b/src/ifcgeom_schema_agnostic/Serialization.cpp @@ -12,9 +12,9 @@ namespace IfcGeom { template IfcUtil::IfcBaseClass* execute_based_on_schema(Fn fn1, Fn fn2, const std::string& schema_name, const TopoDS_Shape& shape, T t) { const std::string schema_name_lower = boost::to_lower_copy(schema_name); - if (schema_name == "ifc2x3") { + if (schema_name_lower == "ifc2x3") { return fn1(shape, t); - } else if (schema_name == "ifc4") { + } else if (schema_name_lower == "ifc4") { return fn2(shape, t); } else { throw IfcParse::IfcException("No geometry serialization available for " + schema_name); diff --git a/src/ifcparse/IfcBaseClass.h b/src/ifcparse/IfcBaseClass.h index c60d7ef7ef..d0518e62b1 100644 --- a/src/ifcparse/IfcBaseClass.h +++ b/src/ifcparse/IfcBaseClass.h @@ -52,6 +52,9 @@ namespace IfcUtil { template T* as() { + if (this == 0) { + return static_cast(0); + } return declaration().is(T::Class()) ? static_cast(this) : static_cast(0); @@ -59,6 +62,9 @@ namespace IfcUtil { template const T* as() const { + if (this == 0) { + return static_cast(0); + } return declaration().is(T::Class()) ? static_cast(this) : static_cast(0); diff --git a/src/ifcparse/IfcHierarchyHelper.h b/src/ifcparse/IfcHierarchyHelper.h index 06e36581aa..ccfe52a37f 100644 --- a/src/ifcparse/IfcHierarchyHelper.h +++ b/src/ifcparse/IfcHierarchyHelper.h @@ -39,7 +39,7 @@ #include "../ifcparse/IfcWrite.h" #include "../ifcparse/IfcGlobalId.h" -namespace impl { +namespace { IfcUtil::IfcBaseClass* get_parent_of_relation(IfcUtil::IfcBaseClass* t) { return *t->data().getArgument( t->declaration().as_entity()->attribute_index("RelatingObject") @@ -132,10 +132,10 @@ public: bool found = false; for (typename T::list::it i = li->begin(); i != li->end(); ++i) { T* rel = *i; - if (impl::get_parent_of_relation(rel) == relating_object) { - IfcEntityList::ptr products = impl::get_children_of_relation(rel); + if (get_parent_of_relation(rel) == relating_object) { + IfcEntityList::ptr products = get_children_of_relation(rel); products->push(related_object); - impl::set_children_of_relation(rel, products); + set_children_of_relation(rel, products); found = true; break; } @@ -154,8 +154,13 @@ public: IfcEntityInstanceData* data = new IfcEntityInstanceData(&T::Class()); { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(IfcParse::IfcGlobalId()); data->setArgument(0, attr); } { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(owner_hist); data->setArgument(1, attr); } - { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(relating_object); data->setArgument(4, attr); } - { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(related_objects); data->setArgument(5, attr); } + int relating_index = 4, related_index = 5; + if (T::Class().name() == "IfcRelContainedInSpatialStructure") { + // IfcRelContainedInSpatialStructure has attributes reversed. + std::swap(relating_index, related_index); + } + { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(relating_object); data->setArgument(relating_index, attr); } + { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(related_objects); data->setArgument(related_index, attr); } T* t = (T*)Schema::get_schema().instantiate(data); addEntity(t); diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index a9b7c52337..f8b3a6d25d 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -1079,6 +1079,10 @@ private: template void apply_attribute_(T& t, Argument* attr) const { + if (!attr) { + return; + } + if (attr->type() == IfcUtil::Argument_ENTITY_INSTANCE) { IfcUtil::IfcBaseClass* inst = *attr; t(inst);