2017-06-05 17:26:58 +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/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef IFCBASECLASS_H
|
|
|
|
|
#define IFCBASECLASS_H
|
|
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
#include "Argument.h"
|
2017-06-05 17:26:58 +02:00
|
|
|
#include "ifc_parse_api.h"
|
2023-09-17 12:30:17 +02:00
|
|
|
#include "IfcEntityInstanceData.h"
|
|
|
|
|
#include "IfcSchema.h"
|
|
|
|
|
#include "utils.h"
|
2017-06-05 17:26:58 +02:00
|
|
|
|
2021-09-11 12:59:48 +02:00
|
|
|
#include <atomic>
|
2026-06-04 22:23:19 +01:00
|
|
|
#include <cstdint>
|
2023-09-17 12:30:17 +02:00
|
|
|
#include <boost/shared_ptr.hpp>
|
2021-09-11 12:59:48 +02:00
|
|
|
|
2021-07-29 14:54:51 +02:00
|
|
|
class aggregate_of_instance;
|
2017-06-05 17:26:58 +02:00
|
|
|
|
2024-08-23 20:29:07 +02:00
|
|
|
namespace IfcParse {
|
|
|
|
|
class IfcFile;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-05 17:26:58 +02:00
|
|
|
namespace IfcUtil {
|
|
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
class IFC_PARSE_API IfcBaseInterface {
|
|
|
|
|
protected:
|
|
|
|
|
static bool is_null(const IfcBaseInterface* not_this) {
|
2023-10-24 14:16:26 +02:00
|
|
|
return not_this == nullptr;
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
std::enable_if_t<!std::is_same<IfcBaseClass, T>::value && !std::is_same<IfcBaseEntity, T>::value && !std::is_same<IfcBaseType, T>::value> raise_error_on_concrete_class() const {
|
|
|
|
|
throw IfcParse::IfcException("Instance of type " + this->declaration().name() + " cannot be cast to " + T::Class().name());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
std::enable_if_t<std::is_same<IfcBaseClass, T>::value || std::is_same<IfcBaseEntity, T>::value || std::is_same<IfcBaseType, T>::value> raise_error_on_concrete_class() const {
|
|
|
|
|
throw IfcParse::IfcException("Instance of type " + this->declaration().name() + " cannot be cast to base class");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual const IfcEntityInstanceData& data() const = 0;
|
|
|
|
|
virtual IfcEntityInstanceData& data() = 0;
|
|
|
|
|
virtual const IfcParse::declaration& declaration() const = 0;
|
2024-08-23 20:29:07 +02:00
|
|
|
virtual ~IfcBaseInterface() {}
|
2023-09-17 12:30:17 +02:00
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
T* as(bool do_throw = false) {
|
|
|
|
|
// @todo: do not allow this to be null in the first place
|
|
|
|
|
if (is_null(this)) {
|
|
|
|
|
return static_cast<T*>(0);
|
|
|
|
|
}
|
2023-11-06 20:29:00 +01:00
|
|
|
auto type = dynamic_cast<T*>(this);
|
|
|
|
|
if (do_throw && !type) {
|
2023-09-17 12:30:17 +02:00
|
|
|
raise_error_on_concrete_class<T>();
|
|
|
|
|
}
|
2023-11-06 20:29:00 +01:00
|
|
|
return type;
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
const T* as(bool do_throw = false) const {
|
|
|
|
|
if (is_null(this)) {
|
|
|
|
|
return static_cast<const T*>(0);
|
|
|
|
|
}
|
2023-11-06 20:29:00 +01:00
|
|
|
auto type = dynamic_cast<const T*>(this);
|
|
|
|
|
if (do_throw && !type) {
|
2023-09-17 12:30:17 +02:00
|
|
|
raise_error_on_concrete_class<T>();
|
|
|
|
|
}
|
2023-11-06 20:29:00 +01:00
|
|
|
return type;
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class IFC_PARSE_API IfcBaseClass : public virtual IfcBaseInterface {
|
2024-08-23 20:29:07 +02:00
|
|
|
protected:
|
2023-09-17 12:30:17 +02:00
|
|
|
static std::atomic_uint32_t counter_;
|
|
|
|
|
|
2024-08-23 20:29:07 +02:00
|
|
|
uint32_t identity_;
|
|
|
|
|
public:
|
|
|
|
|
uint32_t id_;
|
|
|
|
|
IfcParse::IfcFile* file_;
|
|
|
|
|
protected:
|
|
|
|
|
IfcEntityInstanceData data_;
|
|
|
|
|
|
|
|
|
|
public:
|
2025-03-09 21:20:16 +01:00
|
|
|
IfcBaseClass(IfcEntityInstanceData&& data);
|
2024-08-23 20:29:07 +02:00
|
|
|
|
|
|
|
|
const IfcEntityInstanceData& data() const { return data_; }
|
|
|
|
|
IfcEntityInstanceData& data() { return data_; }
|
2023-09-17 12:30:17 +02:00
|
|
|
|
|
|
|
|
virtual const IfcParse::declaration& declaration() const = 0;
|
|
|
|
|
|
2024-05-12 16:57:34 +02:00
|
|
|
template <typename T>
|
2025-08-26 10:19:47 +02:00
|
|
|
typename std::enable_if<
|
|
|
|
|
(!(std::is_pointer<T>::value && std::is_base_of<IfcUtil::IfcBaseClass, typename std::remove_pointer<T>::type>::value) || std::is_same_v<IfcUtil::IfcBaseClass, std::remove_pointer_t<T>>),
|
|
|
|
|
void>::type
|
|
|
|
|
set_attribute_value(size_t i, const T& t);
|
2024-05-12 16:57:34 +02:00
|
|
|
|
2024-08-23 20:29:07 +02:00
|
|
|
template <typename T>
|
2025-08-26 10:19:47 +02:00
|
|
|
typename std::enable_if<
|
|
|
|
|
(!(std::is_pointer<T>::value&& std::is_base_of<IfcUtil::IfcBaseClass, typename std::remove_pointer<T>::type>::value) || std::is_same_v<IfcUtil::IfcBaseClass, std::remove_pointer_t<T>>),
|
|
|
|
|
void>::type
|
|
|
|
|
set_attribute_value(const std::string& name, const T& t);
|
|
|
|
|
|
|
|
|
|
void set_attribute_value(size_t i, IfcUtil::IfcBaseClass* p);
|
|
|
|
|
void set_attribute_value(const std::string& name, IfcUtil::IfcBaseClass* p);
|
2024-08-23 20:29:07 +02:00
|
|
|
|
|
|
|
|
void unset_attribute_value(size_t i);
|
2024-05-12 16:57:34 +02:00
|
|
|
|
2025-02-21 16:12:16 +01:00
|
|
|
AttributeValue get_attribute_value(size_t index) const;
|
|
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
uint32_t identity() const { return identity_; }
|
2024-08-23 20:29:07 +02:00
|
|
|
|
|
|
|
|
uint32_t id() const { return id_; }
|
|
|
|
|
|
|
|
|
|
void toString(std::ostream&, bool upper = false) const;
|
2025-01-30 13:04:14 +01:00
|
|
|
|
|
|
|
|
typedef aggregate_of_instance list;
|
2023-09-17 12:30:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class IFC_PARSE_API IfcBaseEntity : public IfcBaseClass {
|
|
|
|
|
public:
|
2024-10-07 20:41:34 +02:00
|
|
|
IfcBaseEntity(IfcEntityInstanceData&& data);
|
2024-08-23 20:29:07 +02:00
|
|
|
|
|
|
|
|
IfcBaseEntity(size_t n)
|
2025-02-21 16:12:16 +01:00
|
|
|
: IfcBaseClass(IfcEntityInstanceData(in_memory_attribute_storage(n)))
|
2024-08-23 20:29:07 +02:00
|
|
|
{}
|
2023-09-17 12:30:17 +02:00
|
|
|
|
2024-11-28 12:57:08 +01:00
|
|
|
virtual const IfcParse::declaration& declaration() const = 0;
|
2023-09-17 12:30:17 +02:00
|
|
|
|
2024-08-23 20:29:07 +02:00
|
|
|
AttributeValue get(const std::string& name) const;
|
2023-09-17 12:30:17 +02:00
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
T get_value(const std::string& name) const;
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
T get_value(const std::string& name, const T& default_value) const;
|
|
|
|
|
|
2023-11-06 20:29:00 +01:00
|
|
|
boost::shared_ptr<aggregate_of_instance> get_inverse(const std::string& name) const;
|
2024-08-23 20:29:07 +02:00
|
|
|
|
|
|
|
|
unsigned set_id(const boost::optional<unsigned>& i);
|
2024-10-07 20:41:34 +02:00
|
|
|
|
|
|
|
|
void populate_derived();
|
2023-09-17 12:30:17 +02:00
|
|
|
};
|
|
|
|
|
|
2024-11-28 12:57:08 +01:00
|
|
|
class IFC_PARSE_API IfcLateBoundEntity : public IfcBaseEntity {
|
|
|
|
|
private:
|
|
|
|
|
const IfcParse::declaration* decl_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
IfcLateBoundEntity(const IfcParse::declaration* decl, IfcEntityInstanceData&& data) : IfcBaseEntity(std::move(data)),
|
|
|
|
|
decl_(decl) {}
|
|
|
|
|
|
|
|
|
|
virtual const IfcParse::declaration& declaration() const {
|
|
|
|
|
return *decl_;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
// TODO: Investigate whether these should be template classes instead
|
|
|
|
|
class IFC_PARSE_API IfcBaseType : public IfcBaseClass {
|
|
|
|
|
public:
|
2024-08-23 20:29:07 +02:00
|
|
|
IfcBaseType(IfcEntityInstanceData&& data)\
|
|
|
|
|
: IfcBaseClass(std::move(data))
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
IfcBaseType()
|
2025-02-21 16:12:16 +01:00
|
|
|
: IfcBaseClass(IfcEntityInstanceData(in_memory_attribute_storage(1)))
|
2024-08-23 20:29:07 +02:00
|
|
|
{}
|
2023-09-17 12:30:17 +02:00
|
|
|
|
|
|
|
|
virtual const IfcParse::declaration& declaration() const = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace IfcUtil
|
2017-06-05 17:26:58 +02:00
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
namespace IfcUtil {
|
|
|
|
|
template <typename T>
|
|
|
|
|
T IfcBaseEntity::get_value(const std::string& name) const {
|
2024-08-23 20:29:07 +02:00
|
|
|
auto attr = get(name);
|
|
|
|
|
return (T) attr;
|
2017-06-05 17:26:58 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
template <typename T>
|
|
|
|
|
T IfcBaseEntity::get_value(const std::string& name, const T& default_value) const {
|
2024-08-23 20:29:07 +02:00
|
|
|
auto attr = get(name);
|
|
|
|
|
if (attr.isNull()) {
|
2023-09-17 12:30:17 +02:00
|
|
|
return default_value;
|
|
|
|
|
}
|
2024-08-23 20:29:07 +02:00
|
|
|
return (T) attr;
|
2023-03-31 15:19:39 -04:00
|
|
|
}
|
2024-08-23 20:29:07 +02:00
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
} // namespace IfcUtil
|
2023-03-31 15:19:39 -04:00
|
|
|
|
2024-08-23 20:29:07 +02:00
|
|
|
template <class U>
|
|
|
|
|
typename U::list::ptr aggregate_of_instance::as() {
|
|
|
|
|
typename U::list::ptr result(new typename U::list);
|
|
|
|
|
for (it i = begin(); i != end(); ++i) {
|
|
|
|
|
if ((*i)->template as<U>()) {
|
|
|
|
|
result->push((*i)->template as<U>());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class U>
|
|
|
|
|
typename aggregate_of_aggregate_of<U>::ptr aggregate_of_aggregate_of_instance::as() {
|
|
|
|
|
typename aggregate_of_aggregate_of<U>::ptr result(new aggregate_of_aggregate_of<U>);
|
|
|
|
|
for (outer_it outer = begin(); outer != end(); ++outer) {
|
|
|
|
|
const std::vector<IfcUtil::IfcBaseClass*>& from = *outer;
|
|
|
|
|
typename std::vector<U*> to;
|
|
|
|
|
for (inner_it inner = from.begin(); inner != from.end(); ++inner) {
|
|
|
|
|
if ((*inner)->template as<U>()) {
|
|
|
|
|
to.push_back((*inner)->template as<U>());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result->push(to);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-05 17:26:58 +02:00
|
|
|
#endif
|