2015-01-05 14:11:42 +00:00
|
|
|
/********************************************************************************
|
2011-09-25 09:53:22 +00: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/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
2015-01-05 14:11:42 +00:00
|
|
|
|
2011-09-25 09:53:22 +00:00
|
|
|
#ifndef IFCFILE_H
|
|
|
|
|
#define IFCFILE_H
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
#include <map>
|
2015-02-17 19:48:41 +00:00
|
|
|
#include <set>
|
2018-12-14 12:14:12 +01:00
|
|
|
#include <iterator>
|
2018-04-13 12:48:42 +03:00
|
|
|
#include <boost/unordered_map.hpp>
|
2011-09-25 09:53:22 +00:00
|
|
|
|
2016-07-20 22:49:32 +03:00
|
|
|
#include "ifc_parse_api.h"
|
2016-05-29 18:12:57 +06:00
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
#include "../ifcparse/IfcParse.h"
|
2015-01-05 17:46:23 +00:00
|
|
|
#include "../ifcparse/IfcSpfHeader.h"
|
2017-12-12 10:33:24 +01:00
|
|
|
#include "../ifcparse/IfcSchema.h"
|
2011-09-25 09:53:22 +00:00
|
|
|
|
|
|
|
|
namespace IfcParse {
|
2015-01-05 14:11:42 +00:00
|
|
|
|
|
|
|
|
/// This class provides several static convenience functions and variables
|
|
|
|
|
/// and provide access to the entities in an IFC file
|
2016-07-20 22:49:32 +03:00
|
|
|
class IFC_PARSE_API IfcFile {
|
2015-01-05 14:11:42 +00:00
|
|
|
public:
|
2017-12-13 13:16:49 +01:00
|
|
|
typedef std::map<const IfcParse::declaration*, IfcEntityList::ptr> entities_by_type_t;
|
2018-04-13 12:48:42 +03:00
|
|
|
typedef boost::unordered_map<unsigned int, IfcUtil::IfcBaseClass*> entity_by_id_t;
|
2017-12-13 13:58:58 +01:00
|
|
|
typedef std::map<std::string, IfcUtil::IfcBaseClass*> entity_by_guid_t;
|
2017-06-05 17:26:58 +02:00
|
|
|
typedef std::map<unsigned int, std::vector<unsigned int> > entities_by_ref_t;
|
2018-10-01 15:11:34 +03:00
|
|
|
typedef std::map<unsigned int, IfcEntityList::ptr> ref_map_t;
|
2015-01-05 14:11:42 +00:00
|
|
|
typedef entity_by_id_t::const_iterator const_iterator;
|
2017-08-16 21:46:39 +02:00
|
|
|
|
2018-12-14 11:56:09 +01:00
|
|
|
class type_iterator : private entities_by_type_t::const_iterator {
|
2017-08-16 21:46:39 +02:00
|
|
|
public:
|
|
|
|
|
type_iterator() : entities_by_type_t::const_iterator() {};
|
|
|
|
|
|
|
|
|
|
type_iterator(const entities_by_type_t::const_iterator& it)
|
|
|
|
|
: entities_by_type_t::const_iterator(it)
|
|
|
|
|
{};
|
|
|
|
|
|
|
|
|
|
entities_by_type_t::key_type const * operator->() const {
|
|
|
|
|
return &entities_by_type_t::const_iterator::operator->()->first;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-14 11:56:09 +01:00
|
|
|
entities_by_type_t::key_type const & operator*() const {
|
2017-08-16 21:46:39 +02:00
|
|
|
return entities_by_type_t::const_iterator::operator*().first;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-14 11:56:09 +01:00
|
|
|
type_iterator& operator++() {
|
|
|
|
|
entities_by_type_t::const_iterator::operator++(); return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type_iterator operator++(int) {
|
|
|
|
|
type_iterator tmp(*this); operator++(); return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator!=(const type_iterator& other) const {
|
2018-12-22 14:05:49 +01:00
|
|
|
const entities_by_type_t::const_iterator& self_ = *this;
|
|
|
|
|
const entities_by_type_t::const_iterator& other_ = other;
|
|
|
|
|
return self_ != other_;
|
2017-08-16 21:46:39 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
private:
|
2015-02-17 19:48:41 +00:00
|
|
|
typedef std::map<IfcUtil::IfcBaseClass*, IfcUtil::IfcBaseClass*> entity_entity_map_t;
|
|
|
|
|
|
2017-12-12 10:33:24 +01:00
|
|
|
bool parsing_complete_, good_;
|
2017-12-11 14:47:30 +01:00
|
|
|
|
2017-12-11 17:20:22 +01:00
|
|
|
const IfcParse::schema_definition* schema_;
|
2017-12-13 13:58:58 +01:00
|
|
|
const IfcParse::declaration* ifcroot_type_;
|
2015-01-05 14:11:42 +00:00
|
|
|
|
|
|
|
|
entity_by_id_t byid;
|
|
|
|
|
entities_by_type_t bytype;
|
2017-08-16 21:46:39 +02:00
|
|
|
entities_by_type_t bytype_excl;
|
2015-01-05 14:11:42 +00:00
|
|
|
entities_by_ref_t byref;
|
2018-10-01 15:11:34 +03:00
|
|
|
ref_map_t by_ref_cached_;
|
2015-01-05 14:11:42 +00:00
|
|
|
entity_by_guid_t byguid;
|
2015-02-17 19:48:41 +00:00
|
|
|
entity_entity_map_t entity_file_map;
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
unsigned int MaxId;
|
|
|
|
|
|
2015-01-05 17:46:23 +00:00
|
|
|
IfcSpfHeader _header;
|
|
|
|
|
|
2015-01-16 16:26:40 +00:00
|
|
|
void setDefaultHeaderValues();
|
2017-07-03 14:18:56 +02:00
|
|
|
|
2017-12-12 10:33:24 +01:00
|
|
|
void initialize_(IfcParse::IfcSpfStream* f);
|
|
|
|
|
|
2018-08-29 12:54:25 +02:00
|
|
|
void build_inverses_(IfcUtil::IfcBaseClass*);
|
2015-01-05 14:11:42 +00:00
|
|
|
public:
|
2015-01-05 17:46:23 +00:00
|
|
|
IfcParse::IfcSpfLexer* tokens;
|
2015-01-05 14:11:42 +00:00
|
|
|
IfcParse::IfcSpfStream* stream;
|
|
|
|
|
|
2017-12-12 10:33:24 +01:00
|
|
|
#ifdef USE_MMAP
|
|
|
|
|
IfcFile(const std::string& fn, bool mmap = false);
|
|
|
|
|
#else
|
|
|
|
|
IfcFile(const std::string& fn);
|
|
|
|
|
#endif
|
|
|
|
|
IfcFile(std::istream& fn, int len);
|
|
|
|
|
IfcFile(void* data, int len);
|
|
|
|
|
IfcFile(IfcParse::IfcSpfStream* f);
|
2017-12-13 18:05:10 +01:00
|
|
|
IfcFile(const IfcParse::schema_definition* schema = IfcParse::schema_by_name("IFC4"));
|
2017-12-12 10:33:24 +01:00
|
|
|
|
2017-12-29 13:48:08 +01:00
|
|
|
virtual ~IfcFile();
|
2017-12-12 10:33:24 +01:00
|
|
|
|
|
|
|
|
bool good() const { return good_; }
|
2015-01-05 14:11:42 +00:00
|
|
|
|
2015-02-17 20:07:09 +00:00
|
|
|
/// Returns the first entity in the file, this probably is the entity
|
|
|
|
|
/// with the lowest id (EXPRESS ENTITY_INSTANCE_NAME)
|
2015-01-05 14:11:42 +00:00
|
|
|
const_iterator begin() const;
|
2015-02-17 20:07:09 +00:00
|
|
|
/// Returns the last entity in the file, this probably is the entity
|
|
|
|
|
/// with the highest id (EXPRESS ENTITY_INSTANCE_NAME)
|
2015-01-05 14:11:42 +00:00
|
|
|
const_iterator end() const;
|
2017-08-16 21:46:39 +02:00
|
|
|
|
|
|
|
|
type_iterator types_begin() const;
|
|
|
|
|
type_iterator types_end() const;
|
|
|
|
|
|
|
|
|
|
type_iterator types_incl_super_begin() const;
|
|
|
|
|
type_iterator types_incl_super_end() const;
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
/// Returns all entities in the file that match the template argument.
|
|
|
|
|
/// NOTE: This also returns subtypes of the requested type, for example:
|
|
|
|
|
/// IfcWall will also return IfcWallStandardCase entities
|
|
|
|
|
template <class T>
|
2017-12-13 13:16:49 +01:00
|
|
|
typename T::list::ptr instances_by_type() {
|
|
|
|
|
IfcEntityList::ptr untyped_list = instances_by_type(&T::Class());
|
2015-01-16 16:26:40 +00:00
|
|
|
if (untyped_list) {
|
|
|
|
|
return untyped_list->as<T>();
|
|
|
|
|
} else {
|
|
|
|
|
return typename T::list::ptr(new typename T::list);
|
|
|
|
|
}
|
2015-01-05 14:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-01 11:22:12 +01:00
|
|
|
template <class T>
|
|
|
|
|
typename T::list::ptr instances_by_type_excl_subtypes() {
|
|
|
|
|
IfcEntityList::ptr untyped_list = instances_by_type_excl_subtypes(&T::Class());
|
|
|
|
|
if (untyped_list) {
|
|
|
|
|
return untyped_list->as<T>();
|
|
|
|
|
} else {
|
|
|
|
|
return typename T::list::ptr(new typename T::list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
/// Returns all entities in the file that match the positional argument.
|
|
|
|
|
/// NOTE: This also returns subtypes of the requested type, for example:
|
|
|
|
|
/// IfcWall will also return IfcWallStandardCase entities
|
2017-12-13 13:16:49 +01:00
|
|
|
IfcEntityList::ptr instances_by_type(const IfcParse::declaration*);
|
2015-01-10 22:13:52 +00:00
|
|
|
|
2017-08-16 21:46:39 +02:00
|
|
|
/// Returns all entities in the file that match the positional argument.
|
2017-12-13 13:16:49 +01:00
|
|
|
IfcEntityList::ptr instances_by_type_excl_subtypes(const IfcParse::declaration*);
|
2017-08-16 21:46:39 +02:00
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
/// Returns all entities in the file that match the positional argument.
|
|
|
|
|
/// NOTE: This also returns subtypes of the requested type, for example:
|
|
|
|
|
/// IfcWall will also return IfcWallStandardCase entities
|
2017-12-13 13:16:49 +01:00
|
|
|
IfcEntityList::ptr instances_by_type(const std::string& t);
|
2015-01-10 22:13:52 +00:00
|
|
|
|
2020-07-11 11:55:00 +02:00
|
|
|
/// Returns all entities in the file that match the positional argument.
|
|
|
|
|
IfcEntityList::ptr instances_by_type_excl_subtypes(const std::string& t);
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
/// Returns all entities in the file that reference the id
|
2017-12-13 13:16:49 +01:00
|
|
|
IfcEntityList::ptr instances_by_reference(int id);
|
2015-01-10 22:13:52 +00:00
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
/// Returns the entity with the specified id
|
2017-12-13 13:16:49 +01:00
|
|
|
IfcUtil::IfcBaseClass* instance_by_id(int id);
|
2015-01-10 22:13:52 +00:00
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
/// Returns the entity with the specified GlobalId
|
2019-07-10 16:34:57 +02:00
|
|
|
IfcUtil::IfcBaseClass* instance_by_guid(const std::string& guid);
|
2015-01-05 14:11:42 +00:00
|
|
|
|
2015-02-17 19:48:41 +00:00
|
|
|
/// Performs a depth-first traversal, returning all entity instance
|
|
|
|
|
/// attributes as a flat list. NB: includes the root instance specified
|
|
|
|
|
/// in the first function argument.
|
|
|
|
|
IfcEntityList::ptr traverse(IfcUtil::IfcBaseClass* instance, int max_level=-1);
|
2017-08-22 10:16:07 +02:00
|
|
|
|
2017-12-13 13:58:58 +01:00
|
|
|
IfcEntityList::ptr getInverse(int instance_id, const IfcParse::declaration* type, int attribute_index);
|
2015-01-10 22:13:52 +00:00
|
|
|
|
2018-12-21 12:06:35 +02:00
|
|
|
/// Marks entity as modified so that potential cache for it is invalidated.
|
|
|
|
|
/// @todo Currently the whole cache is invalidated. Implement more fine-grained invalidation.
|
|
|
|
|
void mark_entity_as_modified(int id);
|
|
|
|
|
|
2015-01-10 22:13:52 +00:00
|
|
|
unsigned int FreshId() { return ++MaxId; }
|
2015-01-05 14:11:42 +00:00
|
|
|
|
2015-02-17 19:55:27 +00:00
|
|
|
IfcUtil::IfcBaseClass* addEntity(IfcUtil::IfcBaseClass* entity);
|
2015-02-17 20:07:09 +00:00
|
|
|
void addEntities(IfcEntityList::ptr es);
|
2015-01-05 14:11:42 +00:00
|
|
|
|
2020-09-30 10:24:50 +02:00
|
|
|
/// Removes entity instance from file and unsets references.
|
|
|
|
|
///
|
|
|
|
|
/// Attention when running removeEntity inside a loop over a list of entities to be removed.
|
|
|
|
|
/// This invalidates the iterator. A workaround is to reverse the loop:
|
|
|
|
|
/// boost::shared_ptr<IfcEntityList> entities = ...;
|
|
|
|
|
/// for (auto it = entities->end() - 1; it >= entities->begin(); --it) {
|
|
|
|
|
/// IfcUtil::IfcBaseClass *const inst = *it;
|
|
|
|
|
/// model->removeEntity(inst);
|
|
|
|
|
/// }
|
2015-02-17 19:48:41 +00:00
|
|
|
void removeEntity(IfcUtil::IfcBaseClass* entity);
|
|
|
|
|
|
2015-01-05 17:46:23 +00:00
|
|
|
const IfcSpfHeader& header() const { return _header; }
|
2015-01-16 16:26:40 +00:00
|
|
|
IfcSpfHeader& header() { return _header; }
|
|
|
|
|
|
|
|
|
|
std::string createTimestamp() const;
|
2015-01-05 17:46:23 +00:00
|
|
|
|
2018-01-29 12:11:50 +01:00
|
|
|
size_t load(unsigned entity_instance_name, Argument**& attributes, size_t num_attributes);
|
2019-07-03 12:10:27 +02:00
|
|
|
void seek_to(const IfcEntityInstanceData& data);
|
|
|
|
|
void try_read_semicolon();
|
2017-07-03 14:18:56 +02:00
|
|
|
|
|
|
|
|
void register_inverse(unsigned, Token);
|
|
|
|
|
void register_inverse(unsigned, IfcUtil::IfcBaseClass*);
|
|
|
|
|
void unregister_inverse(unsigned, IfcUtil::IfcBaseClass*);
|
2017-12-11 14:20:30 +01:00
|
|
|
|
2017-12-11 17:20:22 +01:00
|
|
|
const IfcParse::schema_definition* schema() const { return schema_; }
|
2017-12-13 18:05:10 +01:00
|
|
|
|
|
|
|
|
std::pair<IfcUtil::IfcBaseClass*, double> getUnit(const std::string& unit_type);
|
2018-08-29 12:54:25 +02:00
|
|
|
|
|
|
|
|
bool parsing_complete() const { return parsing_complete_; }
|
|
|
|
|
bool& parsing_complete() { return parsing_complete_; }
|
|
|
|
|
|
|
|
|
|
void build_inverses();
|
2017-12-13 18:05:10 +01:00
|
|
|
};
|
|
|
|
|
|
2018-08-29 12:54:25 +02:00
|
|
|
#ifdef WITH_IFCXML
|
|
|
|
|
IFC_PARSE_API IfcFile* parse_ifcxml(const std::string& filename);
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-09-25 09:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
2018-12-14 12:14:12 +01:00
|
|
|
namespace std {
|
|
|
|
|
template <>
|
|
|
|
|
struct iterator_traits<IfcParse::IfcFile::type_iterator> {
|
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
|
typedef const IfcParse::declaration* value_type;
|
|
|
|
|
typedef const IfcParse::declaration*& reference;
|
|
|
|
|
typedef const IfcParse::declaration** pointer;
|
|
|
|
|
typedef std::forward_iterator_tag iterator_category;
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-12-14 11:56:09 +01:00
|
|
|
|
2017-12-13 18:05:10 +01:00
|
|
|
#endif
|