diff --git a/src/ifcparse/IfcFile.h b/src/ifcparse/IfcFile.h index 1b77265c13..69a3945840 100644 --- a/src/ifcparse/IfcFile.h +++ b/src/ifcparse/IfcFile.h @@ -133,9 +133,9 @@ public: std::pair getUnit(IfcSchema::IfcUnitEnum::IfcUnitEnum); - const schema_definition* schema() const { return schema_; } + const IfcParse::schema_definition* schema() const { return schema_; } - void write_hdf5(const std::string&, const Hdf5Settings&); + void write_hdf5(const std::string&, const IfcParse::Hdf5Settings&); }; } diff --git a/src/ifcparse/IfcLateBoundEntity.cpp b/src/ifcparse/IfcLateBoundEntity.cpp index d3af738c91..3e41c6af9b 100644 --- a/src/ifcparse/IfcLateBoundEntity.cpp +++ b/src/ifcparse/IfcLateBoundEntity.cpp @@ -280,3 +280,8 @@ std::vector IfcParse::IfcLateBoundEntity::getInverseAttributeNames( std::copy(values.begin(), values.end(), std::back_inserter(return_value)); return return_value; } + +const IfcParse::declaration& IfcParse::IfcLateBoundEntity::declaration() const { + // TODO: Bound instances to a file and use according schema + return *get_schema().declaration_by_name(_type); +} \ No newline at end of file diff --git a/src/ifcparse/IfcLateBoundEntity.h b/src/ifcparse/IfcLateBoundEntity.h index 0fc3cc8728..acfe75fc56 100644 --- a/src/ifcparse/IfcLateBoundEntity.h +++ b/src/ifcparse/IfcLateBoundEntity.h @@ -87,14 +87,7 @@ namespace IfcParse { const IfcAbstractEntity& data() const { return *data_; } IfcAbstractEntity& data() { return *data_; } - virtual const IfcParse::declaration& declaration() const { - if (data().file) { - throw; - // data().file-> - } else { - throw; - } - } + const IfcParse::declaration& IfcParse::IfcLateBoundEntity::declaration() const; }; } diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 30da978ee8..5fede461fb 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -922,9 +922,7 @@ IfcFile::IfcFile(bool create_latebound_entities) , tokens(0) , MaxId(0) { - if (!create_latebound_entities) { - schema_ = &get_schema(); - } + schema_ = &get_schema(); setDefaultHeaderValues(); } diff --git a/src/ifcparse/IfcSchema.h b/src/ifcparse/IfcSchema.h index 504ce8366f..20c7a6b9a3 100644 --- a/src/ifcparse/IfcSchema.h +++ b/src/ifcparse/IfcSchema.h @@ -25,6 +25,10 @@ #include #include +#include + +#include "../ifcparse/IfcException.h" + #ifdef USE_IFC4 #include "../ifcparse/Ifc4enum.h" #else @@ -360,7 +364,22 @@ namespace IfcParse { class declaration_by_name_cmp : public std::binary_function { public: bool operator()(const declaration* decl, const std::string& name) { - return decl->name() < name; + // TODO: Efficiency? + return boost::to_lower_copy(decl->name()) < boost::to_lower_copy(name); + } + }; + + class declaration_by_enum_cmp : public std::binary_function { + public: + bool operator()(const declaration* decl, IfcSchema::Type::Enum name) { + return decl->type() < name; + } + }; + + class declaration_by_enum_sort : public std::binary_function { + public: + bool operator()(const declaration* a, const declaration* b) { + return a->type() < b->type(); } }; @@ -370,12 +389,13 @@ namespace IfcParse { , declarations_(declarations) , built_in_(built_in) { + std::sort(declarations_.begin(), declarations_.end(), declaration_by_enum_sort()); for (std::vector::const_iterator it = declarations_.begin(); it != declarations_.end(); ++it) { if ((**it).as_type_declaration()) type_declarations_.push_back((**it).as_type_declaration()); if ((**it).as_select_type()) select_types_.push_back((**it).as_select_type()); if ((**it).as_enumeration_type()) enumeration_types_.push_back((**it).as_enumeration_type()); if ((**it).as_entity()) entities_.push_back((**it).as_entity()); - } + } } ~schema_definition() { @@ -386,8 +406,8 @@ namespace IfcParse { const declaration* declaration_by_name(const std::string& name) const { std::vector::const_iterator it = std::lower_bound(declarations_.begin(), declarations_.end(), name, declaration_by_name_cmp()); - if (it == declarations_.end() || (**it).name() != name) { - throw; + if (it == declarations_.end() || boost::to_lower_copy((**it).name()) != boost::to_lower_copy(name)) { + throw IfcParse::IfcException("Entity with '" + name + "' not found"); } else { return *it; } @@ -395,7 +415,7 @@ namespace IfcParse { const declaration* declaration_by_name(IfcSchema::Type::Enum name) const { if (!built_in_) throw; - return declaration_by_name(IfcSchema::Type::ToString(name)); + return declarations_[name]; } const std::vector& declarations() const { return declarations_; } diff --git a/src/ifcwrap/IfcGeomWrapper.i b/src/ifcwrap/IfcGeomWrapper.i index 84a435b69e..606374d8da 100644 --- a/src/ifcwrap/IfcGeomWrapper.i +++ b/src/ifcwrap/IfcGeomWrapper.i @@ -236,7 +236,7 @@ struct ShapeRTTI : public boost::static_visitor %inline %{ boost::variant*, IfcGeom::Representation::Representation*> create_shape(IfcGeom::IteratorSettings& settings, IfcParse::IfcLateBoundEntity* instance, IfcParse::IfcLateBoundEntity* representation = 0) { - IfcParse::IfcFile* file = instance->entity->file; + IfcParse::IfcFile* file = instance->data().file; IfcSchema::IfcProject::list::ptr projects = file->entitiesByType(); if (projects->size() != 1) { throw IfcParse::IfcException("Not a single IfcProject instance"); @@ -248,9 +248,9 @@ struct ShapeRTTI : public boost::static_visitor kernel.setValue(IfcGeom::Kernel::GV_DIMENSIONALITY, (settings.include_curves() ? (settings.exclude_solids_and_surfaces() ? -1. : 0.) : +1.)); std::pair length_unit = kernel.initializeUnits(project->UnitsInContext()); - if (instance->is(IfcSchema::Type::IfcProduct)) { + if (instance->declaration().is(IfcSchema::Type::IfcProduct)) { if (representation) { - if (!representation->is(IfcSchema::Type::IfcRepresentation)) { + if (!representation->declaration().is(IfcSchema::Type::IfcRepresentation)) { throw IfcParse::IfcException("Supplied representation not of type IfcRepresentation"); } } @@ -323,11 +323,11 @@ struct ShapeRTTI : public boost::static_visitor } IfcSchema::IfcRepresentationContext* ctx = ifc_representation->ContextOfItems(); - if (!ctx->is(IfcSchema::Type::IfcGeometricRepresentationContext)) { + if (!ctx->declaration().is(IfcSchema::Type::IfcGeometricRepresentationContext)) { throw IfcParse::IfcException("Context not of type IfcGeometricRepresentationContext"); } IfcSchema::IfcGeometricRepresentationContext* context = (IfcSchema::IfcGeometricRepresentationContext*) ctx; - if (context->is(IfcSchema::Type::IfcGeometricRepresentationSubContext)) { + if (context->declaration().is(IfcSchema::Type::IfcGeometricRepresentationSubContext)) { IfcSchema::IfcGeometricRepresentationSubContext* subcontext = (IfcSchema::IfcGeometricRepresentationSubContext*) context; context = subcontext->ParentContext(); } @@ -360,11 +360,11 @@ struct ShapeRTTI : public boost::static_visitor } } else { if (!representation) { - if (instance->is(IfcSchema::Type::IfcRepresentationItem) || instance->is(IfcSchema::Type::IfcRepresentation)) { + if (instance->declaration().is(IfcSchema::Type::IfcRepresentationItem) || instance->declaration().is(IfcSchema::Type::IfcRepresentation)) { IfcGeom::IfcRepresentationShapeItems shapes; if (kernel.convert_shapes(instance, shapes)) { IfcGeom::ElementSettings element_settings(settings, kernel.getValue(IfcGeom::Kernel::GV_LENGTH_UNIT), IfcSchema::Type::ToString(instance->type())); - IfcGeom::Representation::BRep brep(element_settings, instance->entity->id(), shapes); + IfcGeom::Representation::BRep brep(element_settings, instance->data().id(), shapes); try { if (settings.use_brep_data()) { return new IfcGeom::Representation::Serialization(brep); diff --git a/src/ifcwrap/IfcPython.i b/src/ifcwrap/IfcPython.i index ef42830a14..576701f1f8 100644 --- a/src/ifcwrap/IfcPython.i +++ b/src/ifcwrap/IfcPython.i @@ -70,6 +70,8 @@ #include "../ifcparse/IfcFile.h" #include "../ifcparse/IfcLateBoundEntity.h" + #include "../ifcparse/IfcSchema.h" + #include "../ifcparse/Hdf5Settings.h" #ifdef USE_IFC4 #include "../ifcparse/Ifc4-latebound.h"