2015-09-08 20:40:54 +02:00
|
|
|
#include "IfcSchema.h"
|
2020-09-08 14:37:50 +02:00
|
|
|
#include "../ifcparse/IfcBaseClass.h"
|
2015-09-08 20:40:54 +02:00
|
|
|
|
2017-12-12 10:33:24 +01:00
|
|
|
#include <map>
|
|
|
|
|
|
2015-09-08 20:40:54 +02:00
|
|
|
bool IfcParse::declaration::is(const std::string& name) const {
|
2017-12-31 12:20:13 +01:00
|
|
|
if (name_lower_ == boost::to_lower_copy(name)) return true;
|
2015-09-08 20:40:54 +02:00
|
|
|
|
|
|
|
|
if (this->as_entity()) {
|
|
|
|
|
return this->as_entity()->is(name);
|
2017-12-13 13:58:58 +01:00
|
|
|
} else if (this->as_type_declaration()) {
|
|
|
|
|
const IfcParse::named_type* nt = this->as_type_declaration()->declared_type()->as_named_type();
|
|
|
|
|
if (nt) return nt->is(name);
|
2015-09-08 20:40:54 +02:00
|
|
|
}
|
2017-12-13 13:58:58 +01:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IfcParse::declaration::is(const IfcParse::declaration& decl) const {
|
|
|
|
|
if (this == &decl) return true;
|
|
|
|
|
|
|
|
|
|
if (this->as_entity()) {
|
|
|
|
|
return this->as_entity()->is(decl);
|
|
|
|
|
} else if (this->as_type_declaration()) {
|
|
|
|
|
const IfcParse::named_type* nt = this->as_type_declaration()->declared_type()->as_named_type();
|
|
|
|
|
if (nt) return nt->is(decl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2015-09-08 20:40:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IfcParse::named_type::is(const std::string& name) const {
|
|
|
|
|
return declared_type()->is(name);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-13 13:58:58 +01:00
|
|
|
bool IfcParse::named_type::is(const IfcParse::declaration& decl) const {
|
|
|
|
|
return declared_type()->is(decl);
|
2017-12-12 10:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::map<std::string, const IfcParse::schema_definition*> schemas;
|
|
|
|
|
|
2017-12-13 13:58:58 +01:00
|
|
|
IfcParse::schema_definition::schema_definition(const std::string& name, const std::vector<const declaration*>& declarations, instance_factory* factory)
|
2017-12-12 10:33:24 +01:00
|
|
|
: name_(name)
|
|
|
|
|
, declarations_(declarations)
|
2017-12-13 13:16:49 +01:00
|
|
|
, factory_(factory)
|
2017-12-12 10:33:24 +01:00
|
|
|
{
|
2017-12-13 13:16:49 +01:00
|
|
|
std::sort(declarations_.begin(), declarations_.end(), declaration_by_index_sort());
|
2017-12-22 13:51:11 +01:00
|
|
|
for (std::vector<const declaration*>::iterator it = declarations_.begin(); it != declarations_.end(); ++it) {
|
|
|
|
|
(**it).schema_ = this;
|
|
|
|
|
|
2017-12-12 10:33:24 +01:00
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
schemas[name_] = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IfcParse::schema_definition::~schema_definition() {
|
|
|
|
|
schemas.erase(name_);
|
|
|
|
|
for (std::vector<const declaration*>::const_iterator it = declarations_.begin(); it != declarations_.end(); ++it) {
|
|
|
|
|
delete *it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-08 14:37:50 +02:00
|
|
|
IfcUtil::IfcBaseClass* IfcParse::schema_definition::instantiate(IfcEntityInstanceData * data) const {
|
|
|
|
|
if (factory_) {
|
|
|
|
|
return (*factory_)(data);
|
|
|
|
|
} else {
|
|
|
|
|
return new IfcUtil::IfcLateBoundEntity(data->type(), data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IfcParse::register_schema(schema_definition* s) {
|
2022-01-07 12:49:28 +01:00
|
|
|
schemas.insert({ boost::to_upper_copy(s->name()), s });
|
2020-09-08 14:37:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-11 22:29:16 +02:00
|
|
|
#ifdef HAS_SCHEMA_2x3
|
2017-12-21 14:14:04 +01:00
|
|
|
#include "../ifcparse/Ifc2x3.h"
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4
|
2017-12-21 14:14:04 +01:00
|
|
|
#include "../ifcparse/Ifc4.h"
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x1
|
2019-06-26 13:50:46 +02:00
|
|
|
#include "../ifcparse/Ifc4x1.h"
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x2
|
2019-06-19 08:54:21 +02:00
|
|
|
#include "../ifcparse/Ifc4x2.h"
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc1
|
2020-06-15 12:48:30 +02:00
|
|
|
#include "../ifcparse/Ifc4x3_rc1.h"
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc2
|
2021-02-14 17:21:34 +01:00
|
|
|
#include "../ifcparse/Ifc4x3_rc2.h"
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
2021-07-03 21:42:37 -07:00
|
|
|
#ifdef HAS_SCHEMA_4x3_rc3
|
|
|
|
|
#include "../ifcparse/Ifc4x3_rc3.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc4
|
|
|
|
|
#include "../ifcparse/Ifc4x3_rc4.h"
|
|
|
|
|
#endif
|
2017-12-21 14:14:04 +01:00
|
|
|
|
2017-12-20 16:38:55 +01:00
|
|
|
const IfcParse::schema_definition* IfcParse::schema_by_name(const std::string& name) {
|
2017-12-21 14:14:04 +01:00
|
|
|
// TODO: initialize automatically somehow
|
2021-05-11 22:29:16 +02:00
|
|
|
#ifdef HAS_SCHEMA_2x3
|
2017-12-21 14:14:04 +01:00
|
|
|
Ifc2x3::get_schema();
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4
|
2017-12-21 14:14:04 +01:00
|
|
|
Ifc4::get_schema();
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x1
|
2019-06-26 13:50:46 +02:00
|
|
|
Ifc4x1::get_schema();
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x2
|
2019-06-26 13:50:46 +02:00
|
|
|
Ifc4x2::get_schema();
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc1
|
2020-06-15 12:48:30 +02:00
|
|
|
Ifc4x3_rc1::get_schema();
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc2
|
2021-02-14 17:21:34 +01:00
|
|
|
Ifc4x3_rc2::get_schema();
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
2021-07-03 21:42:37 -07:00
|
|
|
#ifdef HAS_SCHEMA_4x3_rc3
|
|
|
|
|
Ifc4x3_rc3::get_schema();
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc4
|
|
|
|
|
Ifc4x3_rc4::get_schema();
|
|
|
|
|
#endif
|
2017-12-21 14:14:04 +01:00
|
|
|
|
2021-02-14 17:39:15 +01:00
|
|
|
std::map<std::string, const IfcParse::schema_definition*>::const_iterator it = schemas.find(boost::to_upper_copy(name));
|
2017-12-12 10:33:24 +01:00
|
|
|
if (it == schemas.end()) {
|
|
|
|
|
throw IfcParse::IfcException("No schema named " + name);
|
|
|
|
|
}
|
|
|
|
|
return it->second;
|
2019-06-26 13:50:46 +02:00
|
|
|
}
|
2021-12-02 11:05:36 +01:00
|
|
|
|
|
|
|
|
std::vector<std::string> IfcParse::schema_names() {
|
|
|
|
|
// Load schema modules
|
|
|
|
|
try {
|
|
|
|
|
IfcParse::schema_by_name("IFC2X3");
|
|
|
|
|
} catch (IfcParse::IfcException&) {}
|
|
|
|
|
|
|
|
|
|
// Populate vector with map keys
|
|
|
|
|
std::vector<std::string> return_value;
|
|
|
|
|
for (auto& pair : schemas) {
|
|
|
|
|
return_value.push_back(pair.first);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
|
}
|