2023-09-17 12:30:17 +02:00
|
|
|
/********************************************************************************
|
2023-09-18 16:13:44 +02:00
|
|
|
* *
|
|
|
|
|
* This file is part of IfcOpenShell. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* Lesser GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
2023-09-17 12:30:17 +02:00
|
|
|
|
2015-09-08 20:40:54 +02:00
|
|
|
#include "IfcSchema.h"
|
2023-09-17 12:30:17 +02:00
|
|
|
|
2026-01-04 10:40:02 +01:00
|
|
|
#include "express.h"
|
2023-09-17 12:30:17 +02:00
|
|
|
|
2023-10-24 11:47:44 +02:00
|
|
|
#include <map>
|
|
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
#ifdef HAS_SCHEMA_2x3
|
|
|
|
|
#include "Ifc2x3.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4
|
|
|
|
|
#include "Ifc4.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x1
|
|
|
|
|
#include "Ifc4x1.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x2
|
|
|
|
|
#include "Ifc4x2.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc1
|
|
|
|
|
#include "Ifc4x3_rc1.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc2
|
|
|
|
|
#include "Ifc4x3_rc2.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc3
|
|
|
|
|
#include "Ifc4x3_rc3.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc4
|
|
|
|
|
#include "Ifc4x3_rc4.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3
|
|
|
|
|
#include "Ifc4x3.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_tc1
|
|
|
|
|
#include "Ifc4x3_tc1.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_add1
|
|
|
|
|
#include "Ifc4x3_add1.h"
|
|
|
|
|
#endif
|
2023-10-18 09:46:29 +02:00
|
|
|
#ifdef HAS_SCHEMA_4x3_add2
|
|
|
|
|
#include "Ifc4x3_add2.h"
|
|
|
|
|
#endif
|
2025-09-29 11:29:35 +02:00
|
|
|
#include "Header_section_schema.h"
|
2015-09-08 20:40:54 +02:00
|
|
|
|
|
|
|
|
bool IfcParse::declaration::is(const std::string& name) const {
|
2023-09-17 12:30:17 +02:00
|
|
|
const std::string* name_ptr = &name;
|
2023-11-06 20:29:00 +01:00
|
|
|
if (std::any_of(name.begin(), name.end(), [](char character) { return std::islower(character); })) {
|
2023-09-17 12:30:17 +02:00
|
|
|
temp_string_() = name;
|
|
|
|
|
boost::to_upper(temp_string_());
|
|
|
|
|
name_ptr = &temp_string_();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (name_upper_ == *name_ptr) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-24 14:16:26 +02:00
|
|
|
if ((this->as_entity() != nullptr) && (this->as_entity()->supertype() != nullptr)) {
|
2023-09-17 12:30:17 +02:00
|
|
|
return this->as_entity()->supertype()->is(name);
|
2023-10-24 12:21:32 +02:00
|
|
|
}
|
2023-10-24 14:16:26 +02:00
|
|
|
if (this->as_type_declaration() != nullptr) {
|
2023-11-06 20:29:00 +01:00
|
|
|
const IfcParse::named_type* named_type = this->as_type_declaration()->declared_type()->as_named_type();
|
|
|
|
|
if (named_type != nullptr) {
|
|
|
|
|
return named_type->is(name);
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2017-12-13 13:58:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IfcParse::declaration::is(const IfcParse::declaration& decl) const {
|
2023-09-17 12:30:17 +02:00
|
|
|
if (this == &decl) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-12-13 13:58:58 +01:00
|
|
|
|
2026-01-04 10:40:02 +01:00
|
|
|
if (decl.as_select_type() != nullptr) {
|
|
|
|
|
const auto& li = decl.as_select_type()->select_list();
|
|
|
|
|
for (const auto* selected_decl : li) {
|
|
|
|
|
if (is(*selected_decl)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-24 14:16:26 +02:00
|
|
|
if ((this->as_entity() != nullptr) && (this->as_entity()->supertype() != nullptr)) {
|
2023-09-17 12:30:17 +02:00
|
|
|
return this->as_entity()->supertype()->is(decl);
|
2023-10-24 12:21:32 +02:00
|
|
|
}
|
2023-10-24 14:16:26 +02:00
|
|
|
if (this->as_type_declaration() != nullptr) {
|
2023-11-06 20:29:00 +01:00
|
|
|
const IfcParse::named_type* named_type = this->as_type_declaration()->declared_type()->as_named_type();
|
|
|
|
|
if (named_type != nullptr) {
|
|
|
|
|
return named_type->is(decl);
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-13 13:58:58 +01:00
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
return false;
|
2015-09-08 20:40:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IfcParse::named_type::is(const std::string& name) const {
|
2023-09-17 12:30:17 +02:00
|
|
|
return declared_type()->is(name);
|
2015-09-08 20:40:54 +02:00
|
|
|
}
|
|
|
|
|
|
2017-12-13 13:58:58 +01:00
|
|
|
bool IfcParse::named_type::is(const IfcParse::declaration& decl) const {
|
2023-09-17 12:30:17 +02:00
|
|
|
return declared_type()->is(decl);
|
2017-12-12 10:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-27 16:20:35 +02:00
|
|
|
IfcParse::entity::~entity() {
|
2023-10-24 16:11:26 +02:00
|
|
|
for (const auto* attribute : attributes_) {
|
2023-09-17 12:30:17 +02:00
|
|
|
delete attribute;
|
|
|
|
|
}
|
2023-10-24 16:11:26 +02:00
|
|
|
for (const auto* inverse_attribute : inverse_attributes_) {
|
2023-09-17 12:30:17 +02:00
|
|
|
delete inverse_attribute;
|
|
|
|
|
}
|
2022-04-27 16:20:35 +02:00
|
|
|
}
|
2017-12-12 10:33:24 +01:00
|
|
|
static std::map<std::string, const IfcParse::schema_definition*> schemas;
|
|
|
|
|
|
2026-01-04 10:40:02 +01:00
|
|
|
IfcParse::schema_definition::schema_definition(const std::string& name, const std::vector<const declaration*>& declarations)
|
|
|
|
|
: name_(name)
|
|
|
|
|
, declarations_(declarations)
|
|
|
|
|
{
|
2023-09-17 12:30:17 +02:00
|
|
|
std::sort(declarations_.begin(), declarations_.end(), declaration_by_index_sort());
|
|
|
|
|
for (std::vector<const declaration*>::iterator it = declarations_.begin(); it != declarations_.end(); ++it) {
|
|
|
|
|
(**it).schema_ = this;
|
|
|
|
|
|
2023-10-24 14:16:26 +02:00
|
|
|
if ((**it).as_type_declaration() != nullptr) {
|
2023-09-17 12:30:17 +02:00
|
|
|
type_declarations_.push_back((**it).as_type_declaration());
|
|
|
|
|
}
|
2023-10-24 14:16:26 +02:00
|
|
|
if ((**it).as_select_type() != nullptr) {
|
2023-09-17 12:30:17 +02:00
|
|
|
select_types_.push_back((**it).as_select_type());
|
|
|
|
|
}
|
2023-10-24 14:16:26 +02:00
|
|
|
if ((**it).as_enumeration_type() != nullptr) {
|
2023-09-17 12:30:17 +02:00
|
|
|
enumeration_types_.push_back((**it).as_enumeration_type());
|
|
|
|
|
}
|
2023-10-24 14:16:26 +02:00
|
|
|
if ((**it).as_entity() != nullptr) {
|
2023-09-17 12:30:17 +02:00
|
|
|
entities_.push_back((**it).as_entity());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
schemas[name_] = this;
|
2017-12-12 10:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IfcParse::schema_definition::~schema_definition() {
|
2023-09-17 12:30:17 +02:00
|
|
|
for (std::vector<const declaration*>::const_iterator it = declarations_.begin(); it != declarations_.end(); ++it) {
|
|
|
|
|
delete *it;
|
|
|
|
|
}
|
2020-09-08 14:37:50 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-06 20:29:00 +01:00
|
|
|
void IfcParse::register_schema(schema_definition* schema) {
|
|
|
|
|
schemas.insert({boost::to_upper_copy(schema->name()), schema});
|
2020-09-08 14:37:50 +02:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 16:38:55 +01:00
|
|
|
const IfcParse::schema_definition* IfcParse::schema_by_name(const std::string& name) {
|
2023-09-17 12:30:17 +02:00
|
|
|
// TODO: initialize automatically somehow
|
2025-09-29 11:29:35 +02:00
|
|
|
Header_section_schema::get_schema();
|
2021-05-11 22:29:16 +02:00
|
|
|
#ifdef HAS_SCHEMA_2x3
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc2x3::get_schema();
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4::get_schema();
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x1
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x1::get_schema();
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x2
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x2::get_schema();
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc1
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3_rc1::get_schema();
|
2021-05-11 22:29:16 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc2
|
2023-09-17 12:30:17 +02: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
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3_rc3::get_schema();
|
2021-07-03 21:42:37 -07:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc4
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3_rc4::get_schema();
|
2021-07-03 21:42:37 -07:00
|
|
|
#endif
|
2022-07-17 21:13:46 +02:00
|
|
|
#ifdef HAS_SCHEMA_4x3
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3::get_schema();
|
2022-07-17 21:13:46 +02:00
|
|
|
#endif
|
2022-11-23 13:23:49 +01:00
|
|
|
#ifdef HAS_SCHEMA_4x3_tc1
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3_tc1::get_schema();
|
2022-11-23 13:23:49 +01:00
|
|
|
#endif
|
2022-11-21 09:43:13 +01:00
|
|
|
#ifdef HAS_SCHEMA_4x3_add1
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3_add1::get_schema();
|
2022-11-21 09:43:13 +01:00
|
|
|
#endif
|
2023-10-18 09:46:29 +02:00
|
|
|
#ifdef HAS_SCHEMA_4x3_add2
|
|
|
|
|
Ifc4x3_add2::get_schema();
|
|
|
|
|
#endif
|
2017-12-21 14:14:04 +01:00
|
|
|
|
2023-11-06 20:29:00 +01:00
|
|
|
std::map<std::string, const IfcParse::schema_definition*>::const_iterator iter = schemas.find(boost::to_upper_copy(name));
|
|
|
|
|
if (iter == schemas.end()) {
|
2023-09-17 12:30:17 +02:00
|
|
|
throw IfcParse::IfcException("No schema named " + name);
|
|
|
|
|
}
|
2023-11-06 20:29:00 +01:00
|
|
|
return iter->second;
|
2019-06-26 13:50:46 +02:00
|
|
|
}
|
2021-12-02 11:05:36 +01:00
|
|
|
|
|
|
|
|
std::vector<std::string> IfcParse::schema_names() {
|
2023-09-17 12:30:17 +02:00
|
|
|
// 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;
|
2021-12-02 11:05:36 +01:00
|
|
|
}
|
2022-04-27 16:20:35 +02:00
|
|
|
|
|
|
|
|
void IfcParse::clear_schemas() {
|
|
|
|
|
#ifdef HAS_SCHEMA_2x3
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc2x3::clear_schema();
|
2022-04-27 16:20:35 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4::clear_schema();
|
2022-04-27 16:20:35 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x1
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x1::clear_schema();
|
2022-04-27 16:20:35 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x2
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x2::clear_schema();
|
2022-04-27 16:20:35 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc1
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3_rc1::clear_schema();
|
2022-04-27 16:20:35 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc2
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3_rc2::clear_schema();
|
2022-04-27 16:20:35 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc3
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3_rc3::clear_schema();
|
2022-04-27 16:20:35 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_rc4
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3_rc4::clear_schema();
|
2022-04-27 16:20:35 +02:00
|
|
|
#endif
|
2022-07-17 21:13:46 +02:00
|
|
|
#ifdef HAS_SCHEMA_4x3
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3::clear_schema();
|
2022-07-17 21:13:46 +02:00
|
|
|
#endif
|
2022-11-23 13:23:49 +01:00
|
|
|
#ifdef HAS_SCHEMA_4x3_tc1
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3_tc1::clear_schema();
|
2022-11-23 13:23:49 +01:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAS_SCHEMA_4x3_add1
|
2023-09-17 12:30:17 +02:00
|
|
|
Ifc4x3_add1::clear_schema();
|
2022-11-23 13:23:49 +01:00
|
|
|
#endif
|
2023-10-18 09:46:29 +02:00
|
|
|
#ifdef HAS_SCHEMA_4x3_add2
|
|
|
|
|
Ifc4x3_add2::clear_schema();
|
|
|
|
|
#endif
|
2025-09-29 11:29:35 +02:00
|
|
|
Header_section_schema::clear_schema();
|
2022-04-27 16:20:35 +02:00
|
|
|
|
2025-10-03 14:18:50 +02:00
|
|
|
// Schemas are owned by their respective modules in a unique_ptr, so just clear the map
|
|
|
|
|
schemas.clear();
|
2022-04-27 16:20:35 +02:00
|
|
|
}
|