mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-18 11:20:21 +00:00
Merge developments from the python_wrapper branch into master
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,50 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* *
|
||||
* This file has been generated from IFC2X3_TC1.exp. Do not make modifications *
|
||||
* but instead modify the python script that has been used to generate this. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef IFC2X3RT_H
|
||||
#define IFC2X3RT_H
|
||||
|
||||
#define IfcSchema Ifc2x3
|
||||
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcEntityDescriptor.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
|
||||
namespace Ifc2x3 {
|
||||
namespace Type {
|
||||
int GetAttributeCount(Enum t);
|
||||
int GetAttributeIndex(Enum t, const std::string& a);
|
||||
IfcUtil::ArgumentType GetAttributeType(Enum t, unsigned char a);
|
||||
const std::string& GetAttributeName(Enum t, unsigned char a);
|
||||
bool GetAttributeOptional(Enum t, unsigned char a);
|
||||
bool GetAttributeDerived(Enum t, unsigned char a);
|
||||
std::pair<const char*, int> GetEnumerationIndex(Enum t, const std::string& a);
|
||||
std::pair<Enum, unsigned> GetInverseAttribute(Enum t, const std::string& a);
|
||||
Enum GetAttributeEnumerationClass(Enum t, unsigned char a);
|
||||
void PopulateDerivedFields(IfcWrite::IfcWritableEntity* e);
|
||||
}}
|
||||
|
||||
#endif
|
||||
+3666
-2262
File diff suppressed because one or more lines are too long
+4235
-3065
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,50 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* *
|
||||
* This file has been generated from IFC4.exp. Do not make modifications *
|
||||
* but instead modify the python script that has been used to generate this. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef IFC4RT_H
|
||||
#define IFC4RT_H
|
||||
|
||||
#define IfcSchema Ifc4
|
||||
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcEntityDescriptor.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
|
||||
namespace Ifc4 {
|
||||
namespace Type {
|
||||
int GetAttributeCount(Enum t);
|
||||
int GetAttributeIndex(Enum t, const std::string& a);
|
||||
IfcUtil::ArgumentType GetAttributeType(Enum t, unsigned char a);
|
||||
const std::string& GetAttributeName(Enum t, unsigned char a);
|
||||
bool GetAttributeOptional(Enum t, unsigned char a);
|
||||
bool GetAttributeDerived(Enum t, unsigned char a);
|
||||
std::pair<const char*, int> GetEnumerationIndex(Enum t, const std::string& a);
|
||||
std::pair<Enum, unsigned> GetInverseAttribute(Enum t, const std::string& a);
|
||||
Enum GetAttributeEnumerationClass(Enum t, unsigned char a);
|
||||
void PopulateDerivedFields(IfcWrite::IfcWritableEntity* e);
|
||||
}}
|
||||
|
||||
#endif
|
||||
+5389
-3842
File diff suppressed because one or more lines are too long
+4573
-3313
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -30,7 +30,7 @@
|
||||
|
||||
#include "../ifcparse/IfcCharacterDecoder.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcSpfStream.h"
|
||||
|
||||
#define FIRST_SOLIDUS (1 << 1)
|
||||
#define PAGE (1 << 2)
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
typedef unsigned int UChar32;
|
||||
#endif
|
||||
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcSpfStream.h"
|
||||
|
||||
namespace IfcParse {
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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 IFCENTITYDESCRIPTOR_H
|
||||
#define IFCENTITYDESCRIPTOR_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "../ifcparse/SharedPointer.h"
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
|
||||
#ifdef USE_IFC4
|
||||
#include "../ifcparse/Ifc4enum.h"
|
||||
#else
|
||||
#include "../ifcparse/Ifc2x3enum.h"
|
||||
#endif
|
||||
|
||||
namespace IfcUtil {
|
||||
|
||||
class IfcEnumerationDescriptor {
|
||||
private:
|
||||
IfcSchema::Type::Enum type;
|
||||
std::vector<std::string> values;
|
||||
public:
|
||||
IfcEnumerationDescriptor(IfcSchema::Type::Enum type, const std::vector<std::string>& values)
|
||||
: type(type), values(values) {}
|
||||
std::pair<const char*, int> getIndex(const std::string& value) const {
|
||||
std::vector<std::string>::const_iterator it = std::find(values.begin(), values.end(), value);
|
||||
if (it != values.end()) {
|
||||
return std::make_pair(it->c_str(), std::distance(it, values.begin()));
|
||||
} else {
|
||||
throw IfcParse::IfcException("Invalid enumeration value");
|
||||
}
|
||||
}
|
||||
const std::vector<std::string>& getValues() {
|
||||
return values;
|
||||
}
|
||||
IfcSchema::Type::Enum getType() {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
class IfcEntityDescriptor {
|
||||
public:
|
||||
class IfcArgumentDescriptor
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
bool optional;
|
||||
ArgumentType argument_type;
|
||||
IfcSchema::Type::Enum data_type;
|
||||
IfcArgumentDescriptor(const std::string& name, bool optional, ArgumentType argument_type, IfcSchema::Type::Enum data_type)
|
||||
: name(name), optional(optional), argument_type(argument_type), data_type(data_type) {}
|
||||
};
|
||||
private:
|
||||
IfcSchema::Type::Enum type;
|
||||
IfcEntityDescriptor* parent;
|
||||
std::vector<IfcArgumentDescriptor> arguments;
|
||||
unsigned argument_start() const {
|
||||
return parent ? parent->getArgumentCount() : 0;
|
||||
}
|
||||
const IfcArgumentDescriptor& get_argument(unsigned i) const {
|
||||
if (i < arguments.size()) return arguments[i];
|
||||
else throw IfcParse::IfcException("Argument out of range");
|
||||
}
|
||||
public:
|
||||
IfcEntityDescriptor(IfcSchema::Type::Enum type, IfcEntityDescriptor* parent)
|
||||
: type(type), parent(parent) {}
|
||||
void add(const std::string& name, bool optional, ArgumentType argument_type, IfcSchema::Type::Enum data_type = IfcSchema::Type::ALL) {
|
||||
arguments.push_back(IfcArgumentDescriptor(name, optional, argument_type, data_type));
|
||||
}
|
||||
unsigned getArgumentCount() const {
|
||||
return (parent ? parent->getArgumentCount() : 0) + arguments.size();
|
||||
}
|
||||
const std::string& getArgumentName(unsigned i) const {
|
||||
const unsigned a = argument_start();
|
||||
return i < a
|
||||
? parent->getArgumentName(i)
|
||||
: get_argument(i-a).name;
|
||||
}
|
||||
ArgumentType getArgumentType(unsigned i) const {
|
||||
const unsigned a = argument_start();
|
||||
return i < a
|
||||
? parent->getArgumentType(i)
|
||||
: get_argument(i-a).argument_type;
|
||||
}
|
||||
bool getArgumentOptional(unsigned i) const {
|
||||
const unsigned a = argument_start();
|
||||
return i < a
|
||||
? parent->getArgumentOptional(i)
|
||||
: get_argument(i-a).optional;
|
||||
}
|
||||
IfcSchema::Type::Enum getArgumentEnumerationClass(unsigned i) const {
|
||||
const unsigned a = argument_start();
|
||||
return i < a
|
||||
? parent->getArgumentEnumerationClass(i)
|
||||
: get_argument(i-a).data_type;
|
||||
}
|
||||
unsigned getArgumentIndex(const std::string& s) const {
|
||||
unsigned a = argument_start();
|
||||
for(std::vector<IfcArgumentDescriptor>::const_iterator i = arguments.begin(); i != arguments.end(); ++i) {
|
||||
if (i->name == s) return a;
|
||||
a++;
|
||||
}
|
||||
if (parent) return parent->getArgumentIndex(s);
|
||||
throw IfcParse::IfcException(std::string("Argument ") + s + " not found on " + IfcSchema::Type::ToString(type));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
+99
-56
@@ -1,4 +1,4 @@
|
||||
/********************************************************************************
|
||||
/********************************************************************************
|
||||
* *
|
||||
* This file is part of IfcOpenShell. *
|
||||
* *
|
||||
@@ -16,66 +16,109 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* *
|
||||
* Reads a file in chunks of BUF_SIZE and provides functions to access its *
|
||||
* contents randomly and character by character *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
#ifndef IFCFILE_H
|
||||
#define IFCFILE_H
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
// As of IfcOpenShell version 0.3.0 the paging functionality, which
|
||||
// loads a file on disk into multiple chunks, has been disabled.
|
||||
// It proved to be an inefficient way of working with large files,
|
||||
// as often these did not facilitate to be parsed in a sequential
|
||||
// manner efficiently. To enable the paging functionality uncomment
|
||||
// the following statement.
|
||||
// #define BUF_SIZE (8 * 1024 * 1024)
|
||||
#include "../ifcparse/IfcParse.h"
|
||||
|
||||
namespace IfcParse {
|
||||
/// The IfcSpfStream class represents a ISO 10303-21 IFC-SPF file in memory.
|
||||
/// The file is interpreted as a sequence of tokens which are lazily
|
||||
/// interpreted only when requested. If the size of the file is
|
||||
/// larger than BUF_SIZE, the file is split into seperate pages, of
|
||||
/// which only one is simultaneously kept in memory, for files
|
||||
/// that define their entities not in a sequential nature, this is
|
||||
/// detrimental for the performance of the parser.
|
||||
class IfcSpfStream {
|
||||
private:
|
||||
FILE* stream;
|
||||
char* buffer;
|
||||
unsigned int ptr;
|
||||
unsigned int len;
|
||||
void ReadBuffer(bool inc=true);
|
||||
#ifdef BUF_SIZE
|
||||
unsigned int offset;
|
||||
bool paging;
|
||||
#endif
|
||||
public:
|
||||
bool valid;
|
||||
bool eof;
|
||||
unsigned int size;
|
||||
IfcSpfStream(const std::string& fn);
|
||||
IfcSpfStream(std::istream& f, int len);
|
||||
IfcSpfStream(void* data, int len);
|
||||
/// Returns the character at the cursor
|
||||
char Peek();
|
||||
/// Returns the character at specified offset
|
||||
char Read(unsigned int offset);
|
||||
/// Increment the file cursor and reads new page if necessary
|
||||
void Inc();
|
||||
void Close();
|
||||
/// Moves the file cursor to an arbitrary offset in the file
|
||||
void Seek(unsigned int offset);
|
||||
/// Returns the cursor position
|
||||
unsigned int Tell();
|
||||
};
|
||||
|
||||
/// This class provides several static convenience functions and variables
|
||||
/// and provide access to the entities in an IFC file
|
||||
class IfcFile {
|
||||
public:
|
||||
typedef std::map<IfcSchema::Type::Enum, IfcEntityList::ptr> entities_by_type_t;
|
||||
typedef std::map<unsigned int, IfcUtil::IfcBaseClass*> entity_by_id_t;
|
||||
typedef std::map<std::string, IfcSchema::IfcRoot*> entity_by_guid_t;
|
||||
typedef std::map<unsigned int, IfcEntityList::ptr> entities_by_ref_t;
|
||||
typedef std::map<unsigned int, unsigned int> offset_by_id_t;
|
||||
typedef entity_by_id_t::const_iterator const_iterator;
|
||||
private:
|
||||
bool _create_latebound_entities;
|
||||
|
||||
entity_by_id_t byid;
|
||||
entities_by_type_t bytype;
|
||||
entities_by_ref_t byref;
|
||||
entity_by_guid_t byguid;
|
||||
offset_by_id_t offsets;
|
||||
|
||||
unsigned int lastId;
|
||||
unsigned int MaxId;
|
||||
|
||||
std::string _filename;
|
||||
std::string _timestamp;
|
||||
std::string _author;
|
||||
std::string _author_email;
|
||||
std::string _author_organisation;
|
||||
|
||||
void initTimestamp();
|
||||
public:
|
||||
IfcParse::Tokens* tokens;
|
||||
IfcParse::IfcSpfStream* stream;
|
||||
|
||||
IfcFile(bool create_latebound_entities = false);
|
||||
~IfcFile();
|
||||
|
||||
/// Returns the first entity in the file, this probably is the entity with the lowest id (EXPRESS ENTITY_INSTANCE_NAME)
|
||||
const_iterator begin() const;
|
||||
/// Returns the last entity in the file, this probably is the entity with the highes id (EXPRESS ENTITY_INSTANCE_NAME)
|
||||
const_iterator end() const;
|
||||
|
||||
/// 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>
|
||||
typename T::list::ptr EntitiesByType() {
|
||||
IfcEntityList::ptr e = EntitiesByType(T::Class());
|
||||
typename T::list::ptr l(new typename T::list);
|
||||
if (e && e->Size()) {
|
||||
for ( IfcEntityList::it it = e->begin(); it != e->end(); ++ it ) {
|
||||
l->push((T*)*it);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/// 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
|
||||
IfcEntityList::ptr EntitiesByType(IfcSchema::Type::Enum t);
|
||||
/// 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
|
||||
IfcEntityList::ptr EntitiesByType(const std::string& t);
|
||||
/// Returns all entities in the file that reference the id
|
||||
IfcEntityList::ptr EntitiesByReference(int id);
|
||||
/// Returns the entity with the specified id
|
||||
IfcUtil::IfcBaseClass* EntityById(int id);
|
||||
/// Returns the entity with the specified GlobalId
|
||||
IfcSchema::IfcRoot* EntityByGuid(const std::string& guid);
|
||||
|
||||
bool Init(const std::string& fn);
|
||||
bool Init(std::istream& fn, int len);
|
||||
bool Init(void* data, int len);
|
||||
bool Init(IfcParse::IfcSpfStream* f);
|
||||
|
||||
unsigned int FreshId() { MaxId ++; return MaxId; }
|
||||
|
||||
void AddEntity(IfcUtil::IfcBaseClass* entity);
|
||||
void AddEntities(IfcEntityList::ptr es);
|
||||
|
||||
void filename(const std::string& s);
|
||||
std::string filename() const;
|
||||
void timestamp(const std::string& s);
|
||||
std::string timestamp() const;
|
||||
void author(const std::string& name, const std::string& email, const std::string& organisation);
|
||||
std::string authorName() const;
|
||||
std::string authorEmail() const;
|
||||
std::string authorOrganisation() const;
|
||||
|
||||
bool create_latebound_entities() const { return _create_latebound_entities; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -397,10 +397,10 @@ void IfcHierarchyHelper::clipRepresentation(IfcSchema::IfcRepresentation* rep,
|
||||
IfcSchema::IfcPresentationStyleAssignment* IfcHierarchyHelper::addStyleAssignment(double r, double g, double b, double a) {
|
||||
IfcSchema::IfcColourRgb* colour = new IfcSchema::IfcColourRgb(boost::none, r, g, b);
|
||||
IfcSchema::IfcSurfaceStyleRendering* rendering = a == 1.0
|
||||
? new IfcSchema::IfcSurfaceStyleRendering(colour, boost::none, boost::none, boost::none, boost::none, boost::none,
|
||||
boost::none, boost::none, IfcSchema::IfcReflectanceMethodEnum::IfcReflectanceMethod_FLAT)
|
||||
: new IfcSchema::IfcSurfaceStyleRendering(colour, 1.0-a, boost::none, boost::none, boost::none, boost::none,
|
||||
boost::none, boost::none, IfcSchema::IfcReflectanceMethodEnum::IfcReflectanceMethod_FLAT);
|
||||
? new IfcSchema::IfcSurfaceStyleRendering(colour, boost::none, 0, 0, 0, 0,
|
||||
0, 0, IfcSchema::IfcReflectanceMethodEnum::IfcReflectanceMethod_FLAT)
|
||||
: new IfcSchema::IfcSurfaceStyleRendering(colour, 1.0-a, 0, 0, 0, 0,
|
||||
0, 0, IfcSchema::IfcReflectanceMethodEnum::IfcReflectanceMethod_FLAT);
|
||||
|
||||
IfcEntityList::ptr styles(new IfcEntityList());
|
||||
styles->push(rendering);
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcWrite.h"
|
||||
|
||||
#ifdef USE_IFC4
|
||||
#include "../ifcparse/Ifc4-latebound.h"
|
||||
#else
|
||||
#include "../ifcparse/Ifc2x3-latebound.h"
|
||||
#endif
|
||||
|
||||
#include "IfcLateBoundEntity.h"
|
||||
|
||||
using namespace IfcUtil;
|
||||
|
||||
IfcWrite::IfcWritableEntity* IfcParse::IfcLateBoundEntity::writable_entity() {
|
||||
IfcWrite::IfcWritableEntity* e;
|
||||
if (entity->isWritable()) {
|
||||
e = (IfcWrite::IfcWritableEntity*) entity;
|
||||
} else {
|
||||
entity = e = new IfcWrite::IfcWritableEntity(entity);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
IfcParse::IfcLateBoundEntity::IfcLateBoundEntity(const std::string& s) {
|
||||
std::string S = s;
|
||||
for (std::string::iterator i = S.begin(); i != S.end(); ++i ) *i = toupper(*i);
|
||||
_type = IfcSchema::Type::FromString(S);
|
||||
entity = new IfcWrite::IfcWritableEntity(_type);
|
||||
IfcSchema::Type::PopulateDerivedFields(writable_entity());
|
||||
}
|
||||
IfcParse::IfcLateBoundEntity::IfcLateBoundEntity(IfcAbstractEntity* e) {
|
||||
entity = e;
|
||||
_type = e->type();
|
||||
}
|
||||
unsigned int IfcParse::IfcLateBoundEntity::id() const {
|
||||
if (entity->file) {
|
||||
return static_cast<unsigned int>(entity->id());
|
||||
} else {
|
||||
throw IfcException("Entity not bound to a file");
|
||||
}
|
||||
}
|
||||
bool IfcParse::IfcLateBoundEntity::is(IfcSchema::Type::Enum v) const {
|
||||
IfcSchema::Type::Enum _ty = _type;
|
||||
if (v == _ty) return true;
|
||||
while (_ty != -1) {
|
||||
_ty = IfcSchema::Type::Parent(_ty);
|
||||
if (v == _ty) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
std::string IfcParse::IfcLateBoundEntity::is_a() const {
|
||||
return IfcSchema::Type::ToString(_type);
|
||||
}
|
||||
bool IfcParse::IfcLateBoundEntity::is_a(const std::string& s) const {
|
||||
std::string S = s;
|
||||
for (std::string::iterator i = S.begin(); i != S.end(); ++i ) *i = toupper(*i);
|
||||
return is(IfcSchema::Type::FromString(S));
|
||||
}
|
||||
IfcSchema::Type::Enum IfcParse::IfcLateBoundEntity::type() const {
|
||||
return _type;
|
||||
}
|
||||
unsigned int IfcParse::IfcLateBoundEntity::getArgumentCount() const {
|
||||
return IfcSchema::Type::GetAttributeCount(_type);
|
||||
}
|
||||
IfcUtil::ArgumentType IfcParse::IfcLateBoundEntity::getArgumentType(unsigned int i) const {
|
||||
return IfcSchema::Type::GetAttributeDerived(_type, i)
|
||||
? IfcUtil::Argument_DERIVED
|
||||
: IfcSchema::Type::GetAttributeType(_type,i);
|
||||
}
|
||||
Argument* IfcParse::IfcLateBoundEntity::getArgument(unsigned int i) const {
|
||||
return entity->getArgument(i);
|
||||
}
|
||||
const char* IfcParse::IfcLateBoundEntity::getArgumentName(unsigned int i) const {
|
||||
return IfcSchema::Type::GetAttributeName(_type,i).c_str();
|
||||
}
|
||||
void IfcParse::IfcLateBoundEntity::invalid_argument(unsigned int i, const std::string& t) {
|
||||
const std::string arg_name = IfcSchema::Type::GetAttributeName(_type,i);
|
||||
throw IfcException(t + " is not a valid type for '" + arg_name + "'");
|
||||
}
|
||||
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i) {
|
||||
bool is_optional = IfcSchema::Type::GetAttributeOptional(_type, i);
|
||||
if (is_optional) {
|
||||
writable_entity()->setArgument(i);
|
||||
} else invalid_argument(i,"NULL");
|
||||
}
|
||||
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, int v) {
|
||||
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_INT) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else if ( (arg_type == Argument_BOOL) && ( (v == 0) || (v == 1) ) ) {
|
||||
writable_entity()->setArgument(i, v == 1);
|
||||
} else invalid_argument(i,"INT");
|
||||
}
|
||||
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, bool v) {
|
||||
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_BOOL) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"BOOL");
|
||||
}
|
||||
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, double v) {
|
||||
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_DOUBLE) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"DOUBLE");
|
||||
}
|
||||
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, const std::string& a) {
|
||||
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_STRING) {
|
||||
writable_entity()->setArgument(i,a);
|
||||
} else if (arg_type == Argument_ENUMERATION) {
|
||||
std::pair<const char*, int> enum_data = IfcSchema::Type::GetEnumerationIndex(IfcSchema::Type::GetAttributeEnumerationClass(_type, i), a);
|
||||
writable_entity()->setArgument(i, enum_data.second, enum_data.first);
|
||||
} else invalid_argument(i,"STRING");
|
||||
}
|
||||
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, const std::vector<int>& v) {
|
||||
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_VECTOR_INT) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"LIST of INT");
|
||||
}
|
||||
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, const std::vector<double>& v) {
|
||||
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_VECTOR_DOUBLE) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"LIST of DOUBLE");
|
||||
}
|
||||
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, const std::vector<std::string>& v) {
|
||||
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_VECTOR_STRING) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"LIST of STRING");
|
||||
}
|
||||
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, IfcParse::IfcLateBoundEntity* v) {
|
||||
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_ENTITY) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"ENTITY");
|
||||
}
|
||||
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, IfcEntityList::ptr v) {
|
||||
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_ENTITY_LIST) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"LIST of ENTITY");
|
||||
}
|
||||
std::pair<IfcUtil::ArgumentType,Argument*> IfcParse::IfcLateBoundEntity::get_argument(unsigned i) {
|
||||
return std::pair<IfcUtil::ArgumentType,Argument*>(getArgumentType(i),getArgument(i));
|
||||
}
|
||||
std::pair<IfcUtil::ArgumentType,Argument*> IfcParse::IfcLateBoundEntity::get_argument(const std::string& a) {
|
||||
return get_argument(IfcSchema::Type::GetAttributeIndex(_type,a));
|
||||
}
|
||||
unsigned IfcParse::IfcLateBoundEntity::getArgumentIndex(const std::string& a) const {
|
||||
return IfcSchema::Type::GetAttributeIndex(_type,a);
|
||||
}
|
||||
std::string IfcParse::IfcLateBoundEntity::toString() {
|
||||
return entity->toString(false);
|
||||
}
|
||||
IfcEntityList::ptr IfcParse::IfcLateBoundEntity::get_inverse(const std::string& a) {
|
||||
std::pair<IfcSchema::Type::Enum, unsigned> inv = IfcSchema::Type::GetInverseAttribute(_type, a);
|
||||
IfcEntityList::ptr invs = entity->getInverse(inv.first);
|
||||
IfcEntityList::ptr filtered(new IfcEntityList());
|
||||
for (IfcEntityList::it it = invs->begin(); it != invs->end(); ++it) {
|
||||
try {
|
||||
const int id = *(*it)->entity->getArgument(inv.second);
|
||||
if (id == this->entity->id()) { filtered->push(*it); }
|
||||
} catch (...) {}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
bool IfcParse::IfcLateBoundEntity::is_valid() {
|
||||
const unsigned arg_count = getArgumentCount();
|
||||
bool valid = true;
|
||||
std::ostringstream oss;
|
||||
oss << "Argument ";
|
||||
for (unsigned i = 0; i < arg_count; ++i) {
|
||||
bool is_null = true;
|
||||
try {
|
||||
const Argument& arg = *getArgument(i);
|
||||
is_null = arg.isNull();
|
||||
} catch(IfcException) {}
|
||||
if (!IfcSchema::Type::GetAttributeOptional(_type,i) && is_null) {
|
||||
if (!valid) {
|
||||
oss << ", ";
|
||||
}
|
||||
oss << "\"" << getArgumentName(i) << "\"";
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
oss << " not optional";
|
||||
if (!valid) {
|
||||
throw IfcException(oss.str());
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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 IFCLATEBOUNDENTITY_H
|
||||
#define IFCLATEBOUNDENTITY_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcWrite.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
|
||||
namespace IfcParse {
|
||||
|
||||
// TODO: Somehow these methods should become part of IfcBaseEntity directly so
|
||||
// that in the IfcFile class the distinction what entity type to be created is
|
||||
// no longer necessary and weird diagonal casts when creating geometry from
|
||||
// IfcLateBoundEntities are eliminated.
|
||||
class IfcLateBoundEntity : public IfcUtil::IfcBaseEntity {
|
||||
private:
|
||||
IfcSchema::Type::Enum _type;
|
||||
IfcWrite::IfcWritableEntity* writable_entity();
|
||||
void invalid_argument(unsigned int i, const std::string& t);
|
||||
public:
|
||||
IfcLateBoundEntity(const std::string& s);
|
||||
IfcLateBoundEntity(IfcAbstractEntity* e);
|
||||
|
||||
bool is(IfcSchema::Type::Enum v) const;
|
||||
IfcSchema::Type::Enum type() const;
|
||||
bool is_a(const std::string& s) const;
|
||||
std::string is_a() const;
|
||||
|
||||
unsigned int id() const;
|
||||
unsigned int getArgumentCount() const;
|
||||
IfcUtil::ArgumentType getArgumentType(unsigned int i) const;
|
||||
Argument* getArgument(unsigned int i) const;
|
||||
const char* getArgumentName(unsigned int i) const;
|
||||
unsigned getArgumentIndex(const std::string& a) const;
|
||||
|
||||
IfcEntityList::ptr get_inverse(const std::string& a);
|
||||
|
||||
void setArgument(unsigned int i);
|
||||
void setArgument(unsigned int i, int v);
|
||||
void setArgument(unsigned int i, bool v);
|
||||
void setArgument(unsigned int i, double v);
|
||||
void setArgument(unsigned int i, const std::string& v);
|
||||
void setArgument(unsigned int i, const std::vector<int>& v);
|
||||
void setArgument(unsigned int i, const std::vector<double>& v);
|
||||
void setArgument(unsigned int i, const std::vector<std::string>& v);
|
||||
void setArgument(unsigned int i, IfcLateBoundEntity* v);
|
||||
void setArgument(unsigned int i, IfcEntityList::ptr v);
|
||||
|
||||
std::string toString();
|
||||
|
||||
// TODO: Write as SWIG extension methods?
|
||||
std::pair<IfcUtil::ArgumentType,Argument*> get_argument(unsigned i);
|
||||
std::pair<IfcUtil::ArgumentType,Argument*> get_argument(const std::string& a);
|
||||
|
||||
bool is_valid();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+39
-40
@@ -31,8 +31,10 @@
|
||||
#include "../ifcparse/IfcParse.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcSpfStream.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
#include "../ifcparse/IfcLateBoundEntity.h"
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
|
||||
using namespace IfcParse;
|
||||
|
||||
@@ -404,8 +406,13 @@ TokenArgument::TokenArgument(const Token& t) {
|
||||
token = t;
|
||||
}
|
||||
|
||||
EntityArgument::EntityArgument(IfcSchema::Type::Enum ty, const Token& t) {
|
||||
entity = new IfcUtil::IfcArgumentSelect(ty,new TokenArgument(t));
|
||||
EntityArgument::EntityArgument(const Token& t) {
|
||||
IfcParse::IfcFile* file = t.first->file;
|
||||
if (file->create_latebound_entities()) {
|
||||
entity = new IfcLateBoundEntity(new Entity(0, file, t.second));
|
||||
} else {
|
||||
entity = IfcSchema::SchemaEntity(new Entity(0, file, t.second));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -413,6 +420,8 @@ EntityArgument::EntityArgument(IfcSchema::Type::Enum ty, const Token& t) {
|
||||
// Aditionally, stores the ids (i.e. #[\d]+) in a vector
|
||||
//
|
||||
ArgumentList::ArgumentList(Tokens* t, std::vector<unsigned int>& ids) {
|
||||
IfcParse::IfcFile* file = t->file;
|
||||
|
||||
Token next = t->Next();
|
||||
while( next.second || next.first ) {
|
||||
if ( TokenFunc::isOperator(next,',') ) {}
|
||||
@@ -423,11 +432,10 @@ ArgumentList::ArgumentList(Tokens* t, std::vector<unsigned int>& ids) {
|
||||
if ( TokenFunc::isDatatype(next) ) {
|
||||
t->Next();
|
||||
try {
|
||||
Push ( new EntityArgument(IfcSchema::Type::FromString(TokenFunc::asString(next)),t->Next()) );
|
||||
Push ( new EntityArgument(next) );
|
||||
} catch ( IfcException& e ) {
|
||||
Logger::Message(Logger::LOG_ERROR,e.what());
|
||||
}
|
||||
t->Next();
|
||||
} else {
|
||||
Push ( new TokenArgument(next) );
|
||||
}
|
||||
@@ -592,29 +600,14 @@ EntityArgument::operator std::string() const { throw IfcException("Argument is n
|
||||
EntityArgument::operator std::vector<double>() const { throw IfcException("Argument is not a list of floats"); }
|
||||
EntityArgument::operator std::vector<int>() const { throw IfcException("Argument is not a list of ints"); }
|
||||
EntityArgument::operator std::vector<std::string>() const { throw IfcException("Argument is not a list of strings"); }
|
||||
EntityArgument::operator IfcUtil::IfcBaseClass*() const { return entity; }
|
||||
EntityArgument::operator IfcUtil::IfcBaseClass*() const { return entity; }
|
||||
//EntityArgument::operator IfcUtil::IfcAbstractSelect::ptr() const { return entity; }
|
||||
EntityArgument::operator IfcEntityList::ptr() const { throw IfcException("Argument is not a list of entities"); }
|
||||
EntityArgument::operator IfcEntityListList::ptr() const { throw IfcException("Argument is not a list of entity lists"); }
|
||||
unsigned int EntityArgument::Size() const { return 1; }
|
||||
Argument* EntityArgument::operator [] (unsigned int i) const { throw IfcException("Argument is not a list of arguments"); }
|
||||
std::string EntityArgument::toString(bool upper) const {
|
||||
Argument* arg = entity->wrappedValue();
|
||||
IfcParse::TokenArgument* token_arg = dynamic_cast<IfcParse::TokenArgument*>(arg);
|
||||
const bool is_string = TokenFunc::isString(token_arg->token);
|
||||
std::string token_string = token_arg ? (is_string
|
||||
? TokenFunc::asString(token_arg->token)
|
||||
: TokenFunc::toString(token_arg->token))
|
||||
: std::string();
|
||||
std::string dt = IfcSchema::Type::ToString(entity->type());
|
||||
if ( upper ) {
|
||||
for (std::string::iterator p = dt.begin(); p != dt.end(); ++p ) *p = toupper(*p);
|
||||
if (is_string) token_string = IfcWrite::IfcCharacterEncoder(token_string);
|
||||
} else {
|
||||
token_string.insert(token_string.begin(),'\'');
|
||||
token_string.push_back('\'');
|
||||
}
|
||||
return dt + "(" + token_string + ")";
|
||||
return entity->entity->toString(upper);
|
||||
}
|
||||
//return entity->entity->toString(); }
|
||||
bool EntityArgument::isNull() const { return false; }
|
||||
@@ -736,15 +729,17 @@ IfcEntityList::ptr Entity::getInverse(IfcSchema::Type::Enum c, int i, const std:
|
||||
}
|
||||
return l;
|
||||
}
|
||||
bool Entity::is(IfcSchema::Type::Enum v) const { return _type == v; }
|
||||
bool Entity::is(IfcSchema::Type::Enum v) const { return _type == v; }
|
||||
unsigned int Entity::id() { return _id; }
|
||||
|
||||
IfcWrite::IfcWritableEntity* Entity::isWritable() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
IfcFile::IfcFile() {
|
||||
file = 0;
|
||||
IfcFile::IfcFile(bool create_latebound_entities)
|
||||
: _create_latebound_entities(create_latebound_entities)
|
||||
{
|
||||
stream = 0;
|
||||
lastId = 0;
|
||||
tokens = 0;
|
||||
MaxId = 0;
|
||||
@@ -767,9 +762,9 @@ bool IfcFile::Init(void* data, int len) {
|
||||
}
|
||||
bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
|
||||
IfcSchema::InitStringMap();
|
||||
file = f;
|
||||
if ( ! file->valid ) return false;
|
||||
tokens = new Tokens (file,this);
|
||||
stream = f;
|
||||
if ( ! stream->valid ) return false;
|
||||
tokens = new Tokens (stream,this);
|
||||
Token token = TokenPtr();
|
||||
Token previous = TokenPtr();
|
||||
unsigned int currentId = 0;
|
||||
@@ -778,11 +773,15 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
|
||||
Entity* e;
|
||||
IfcUtil::IfcBaseClass* entity = 0;
|
||||
Logger::Status("Scanning file...");
|
||||
while ( ! file->eof ) {
|
||||
while ( ! stream->eof ) {
|
||||
if ( currentId ) {
|
||||
try {
|
||||
e = new Entity(currentId,this);
|
||||
entity = IfcSchema::SchemaEntity(e);
|
||||
if (this->create_latebound_entities()) {
|
||||
entity = new IfcLateBoundEntity(e);
|
||||
} else {
|
||||
entity = IfcSchema::SchemaEntity(e);
|
||||
}
|
||||
} catch (IfcException ex) {
|
||||
currentId = 0;
|
||||
Logger::Message(Logger::LOG_ERROR,ex.what());
|
||||
@@ -947,7 +946,7 @@ void IfcFile::AddEntity(IfcUtil::IfcBaseClass* entity) {
|
||||
}
|
||||
}
|
||||
IfcEntityList::ptr IfcFile::EntitiesByType(IfcSchema::Type::Enum t) {
|
||||
MapEntitiesByType::const_iterator it = bytype.find(t);
|
||||
entities_by_type_t::const_iterator it = bytype.find(t);
|
||||
return (it == bytype.end()) ? IfcEntityList::ptr() : it->second;
|
||||
}
|
||||
IfcEntityList::ptr IfcFile::EntitiesByType(const std::string& t) {
|
||||
@@ -956,13 +955,13 @@ IfcEntityList::ptr IfcFile::EntitiesByType(const std::string& t) {
|
||||
return EntitiesByType(IfcSchema::Type::FromString(ty));
|
||||
}
|
||||
IfcEntityList::ptr IfcFile::EntitiesByReference(int t) {
|
||||
MapEntitiesByRef::const_iterator it = byref.find(t);
|
||||
entities_by_ref_t::const_iterator it = byref.find(t);
|
||||
return (it == byref.end()) ? IfcEntityList::ptr() : it->second;
|
||||
}
|
||||
IfcUtil::IfcBaseClass* IfcFile::EntityById(int id) {
|
||||
MapEntityById::const_iterator it = byid.find(id);
|
||||
entity_by_id_t::const_iterator it = byid.find(id);
|
||||
if ( it == byid.end() ) {
|
||||
MapOffsetById::const_iterator it2 = offsets.find(id);
|
||||
offset_by_id_t::const_iterator it2 = offsets.find(id);
|
||||
if ( it2 == offsets.end() ) throw IfcException("Entity not found");
|
||||
const unsigned int offset = (*it2).second;
|
||||
Entity* e = new Entity(id,this,offset);
|
||||
@@ -973,7 +972,7 @@ IfcUtil::IfcBaseClass* IfcFile::EntityById(int id) {
|
||||
return it->second;
|
||||
}
|
||||
IfcSchema::IfcRoot* IfcFile::EntityByGuid(const std::string& guid) {
|
||||
MapEntityByGuid::const_iterator it = byguid.find(guid);
|
||||
entity_by_guid_t::const_iterator it = byguid.find(guid);
|
||||
if ( it == byguid.end() ) {
|
||||
throw IfcException("Entity not found");
|
||||
} else {
|
||||
@@ -987,18 +986,18 @@ const char* IfcException::what() const throw() { return error.c_str(); }
|
||||
|
||||
// FIXME: Test destructor to delete entity and arg allocations
|
||||
IfcFile::~IfcFile() {
|
||||
for( MapEntityById::const_iterator it = byid.begin(); it != byid.end(); ++ it ) {
|
||||
for( entity_by_id_t::const_iterator it = byid.begin(); it != byid.end(); ++ it ) {
|
||||
delete it->second->entity;
|
||||
delete it->second;
|
||||
}
|
||||
delete file;
|
||||
delete stream;
|
||||
delete tokens;
|
||||
}
|
||||
|
||||
MapEntityById::const_iterator IfcFile::begin() const {
|
||||
IfcFile::entity_by_id_t::const_iterator IfcFile::begin() const {
|
||||
return byid.begin();
|
||||
}
|
||||
MapEntityById::const_iterator IfcFile::end() const {
|
||||
IfcFile::entity_by_id_t::const_iterator IfcFile::end() const {
|
||||
return byid.end();
|
||||
}
|
||||
|
||||
@@ -1023,7 +1022,7 @@ std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f) {
|
||||
os << "ENDSEC;" << std::endl;
|
||||
os << "DATA;" << std::endl;
|
||||
|
||||
for ( MapEntityById::const_iterator it = f.begin(); it != f.end(); ++ it ) {
|
||||
for ( IfcFile::entity_by_id_t::const_iterator it = f.begin(); it != f.end(); ++ it ) {
|
||||
const IfcUtil::IfcBaseClass* e = it->second;
|
||||
os << e->entity->toString(true) << ";" << std::endl;
|
||||
}
|
||||
|
||||
+3
-82
@@ -47,7 +47,7 @@
|
||||
#include "../ifcparse/Ifc2x3.h"
|
||||
#endif
|
||||
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcSpfStream.h"
|
||||
|
||||
namespace IfcParse {
|
||||
|
||||
@@ -178,9 +178,9 @@ namespace IfcParse {
|
||||
/// ===================== =====================
|
||||
class EntityArgument : public Argument {
|
||||
private:
|
||||
IfcUtil::IfcArgumentSelect* entity;
|
||||
IfcUtil::IfcBaseClass* entity;
|
||||
public:
|
||||
EntityArgument(IfcSchema::Type::Enum ty, const Token& t);
|
||||
EntityArgument(const Token& t);
|
||||
~EntityArgument();
|
||||
|
||||
IfcUtil::ArgumentType type() const;
|
||||
@@ -229,85 +229,6 @@ namespace IfcParse {
|
||||
IfcWrite::IfcWritableEntity* isWritable();
|
||||
};
|
||||
|
||||
typedef std::map<IfcSchema::Type::Enum, IfcEntityList::ptr> MapEntitiesByType;
|
||||
typedef std::map<unsigned int, IfcUtil::IfcBaseClass*> MapEntityById;
|
||||
typedef std::map<std::string, IfcSchema::IfcRoot*> MapEntityByGuid;
|
||||
typedef std::map<unsigned int, IfcEntityList::ptr> MapEntitiesByRef;
|
||||
typedef std::map<unsigned int, unsigned int> MapOffsetById;
|
||||
|
||||
/// This class provides several static convenience functions and variables
|
||||
/// and provide access to the entities in an IFC file
|
||||
class IfcFile {
|
||||
private:
|
||||
MapEntityById byid;
|
||||
MapEntitiesByType bytype;
|
||||
MapEntitiesByRef byref;
|
||||
MapEntityByGuid byguid;
|
||||
MapOffsetById offsets;
|
||||
unsigned int lastId;
|
||||
unsigned int MaxId;
|
||||
std::string _filename;
|
||||
std::string _timestamp;
|
||||
std::string _author;
|
||||
std::string _author_email;
|
||||
std::string _author_organisation;
|
||||
void initTimestamp();
|
||||
public:
|
||||
typedef MapEntityById::const_iterator const_iterator;
|
||||
IfcFile();
|
||||
~IfcFile();
|
||||
/// Returns the first entity in the file, this probably is the entity with the lowest id (EXPRESS ENTITY_INSTANCE_NAME)
|
||||
const_iterator begin() const;
|
||||
/// Returns the last entity in the file, this probably is the entity with the highes id (EXPRESS ENTITY_INSTANCE_NAME)
|
||||
const_iterator end() const;
|
||||
IfcParse::IfcSpfStream* file;
|
||||
IfcParse::Tokens* tokens;
|
||||
/// 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>
|
||||
typename T::list::ptr EntitiesByType() {
|
||||
IfcEntityList::ptr e = EntitiesByType(T::Class());
|
||||
typename T::list::ptr l(new typename T::list);
|
||||
if (e && e->Size()) {
|
||||
for ( IfcEntityList::it it = e->begin(); it != e->end(); ++ it ) {
|
||||
l->push((T*)*it);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
/// 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
|
||||
IfcEntityList::ptr EntitiesByType(IfcSchema::Type::Enum t);
|
||||
/// 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
|
||||
IfcEntityList::ptr EntitiesByType(const std::string& t);
|
||||
/// Returns all entities in the file that reference the id
|
||||
IfcEntityList::ptr EntitiesByReference(int id);
|
||||
/// Returns the entity with the specified id
|
||||
IfcUtil::IfcBaseClass* EntityById(int id);
|
||||
/// Returns the entity with the specified GlobalId
|
||||
IfcSchema::IfcRoot* EntityByGuid(const std::string& guid);
|
||||
bool Init(const std::string& fn);
|
||||
bool Init(std::istream& fn, int len);
|
||||
bool Init(void* data, int len);
|
||||
bool Init(IfcParse::IfcSpfStream* f);
|
||||
unsigned int FreshId() { MaxId ++; return MaxId; }
|
||||
void AddEntity(IfcUtil::IfcBaseClass* entity);
|
||||
void AddEntities(IfcEntityList::ptr es);
|
||||
|
||||
void filename(const std::string& s);
|
||||
std::string filename() const;
|
||||
void timestamp(const std::string& s);
|
||||
std::string timestamp() const;
|
||||
void author(const std::string& name, const std::string& email, const std::string& organisation);
|
||||
std::string authorName() const;
|
||||
std::string authorEmail() const;
|
||||
std::string authorOrganisation() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f);
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
/*********************************************************************************
|
||||
* *
|
||||
* Reads a file in chunks of BUF_SIZE and provides functions to access its *
|
||||
* contents randomly and character by character *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef IFCSPFSTREAM_H
|
||||
#define IFCSPFSTREAM_H
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
// As of IfcOpenShell version 0.3.0 the paging functionality, which
|
||||
// loads a file on disk into multiple chunks, has been disabled.
|
||||
// It proved to be an inefficient way of working with large files,
|
||||
// as often these did not facilitate to be parsed in a sequential
|
||||
// manner efficiently. To enable the paging functionality uncomment
|
||||
// the following statement.
|
||||
// #define BUF_SIZE (8 * 1024 * 1024)
|
||||
|
||||
namespace IfcParse {
|
||||
/// The IfcSpfStream class represents a ISO 10303-21 IFC-SPF file in memory.
|
||||
/// The file is interpreted as a sequence of tokens which are lazily
|
||||
/// interpreted only when requested. If the size of the file is
|
||||
/// larger than BUF_SIZE, the file is split into seperate pages, of
|
||||
/// which only one is simultaneously kept in memory, for files
|
||||
/// that define their entities not in a sequential nature, this is
|
||||
/// detrimental for the performance of the parser.
|
||||
class IfcSpfStream {
|
||||
private:
|
||||
FILE* stream;
|
||||
char* buffer;
|
||||
unsigned int ptr;
|
||||
unsigned int len;
|
||||
void ReadBuffer(bool inc=true);
|
||||
#ifdef BUF_SIZE
|
||||
unsigned int offset;
|
||||
bool paging;
|
||||
#endif
|
||||
public:
|
||||
bool valid;
|
||||
bool eof;
|
||||
unsigned int size;
|
||||
IfcSpfStream(const std::string& fn);
|
||||
IfcSpfStream(std::istream& f, int len);
|
||||
IfcSpfStream(void* data, int len);
|
||||
/// Returns the character at the cursor
|
||||
char Peek();
|
||||
/// Returns the character at specified offset
|
||||
char Read(unsigned int offset);
|
||||
/// Increment the file cursor and reads new page if necessary
|
||||
void Inc();
|
||||
void Close();
|
||||
/// Moves the file cursor to an arbitrary offset in the file
|
||||
void Seek(unsigned int offset);
|
||||
/// Returns the cursor position
|
||||
unsigned int Tell();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
+29
-14
@@ -17,9 +17,12 @@
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#include "IfcUtil.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "../ifcparse/IfcException.h"
|
||||
|
||||
#include "IfcUtil.h"
|
||||
|
||||
void IfcEntityList::push(IfcUtil::IfcBaseClass* l) {
|
||||
if ( l ) ls.push_back(l);
|
||||
}
|
||||
@@ -49,19 +52,10 @@ IfcEntityList::ptr IfcEntityList::getInverse(IfcSchema::Type::Enum c, int ar, co
|
||||
return l;
|
||||
}
|
||||
|
||||
bool IfcUtil::IfcEntitySelect::is(IfcSchema::Type::Enum v) const { return entity->is(v); }
|
||||
IfcSchema::Type::Enum IfcUtil::IfcEntitySelect::type() const { return entity->type(); }
|
||||
IfcUtil::IfcEntitySelect::IfcEntitySelect(IfcBaseClass* b) { entity = b->entity; }
|
||||
IfcUtil::IfcEntitySelect::IfcEntitySelect(IfcAbstractEntity* e) { entity = e; }
|
||||
bool IfcUtil::IfcEntitySelect::isSimpleType() { return false; }
|
||||
IfcUtil::IfcEntitySelect::~IfcEntitySelect() { delete entity; }
|
||||
|
||||
bool IfcUtil::IfcArgumentSelect::is(IfcSchema::Type::Enum v) const { return _type == v; }
|
||||
IfcSchema::Type::Enum IfcUtil::IfcArgumentSelect::type() const { return _type; }
|
||||
IfcUtil::IfcArgumentSelect::IfcArgumentSelect(IfcSchema::Type::Enum t, Argument* a) { _type = t; arg = a; }
|
||||
Argument* IfcUtil::IfcArgumentSelect::wrappedValue() { return arg; }
|
||||
bool IfcUtil::IfcArgumentSelect::isSimpleType() { return true; }
|
||||
IfcUtil::IfcArgumentSelect::~IfcArgumentSelect() { delete arg; }
|
||||
unsigned int IfcUtil::IfcBaseType::getArgumentCount() const { return 1; }
|
||||
Argument* IfcUtil::IfcBaseType::getArgument(unsigned int i) const { return entity->getArgument(i); }
|
||||
const char* IfcUtil::IfcBaseType::getArgumentName(unsigned int i) const { if (i == 0) { return "wrappedValue"; } else { throw IfcParse::IfcException("argument out of range"); } }
|
||||
|
||||
void Logger::SetOutput(std::ostream* l1, std::ostream* l2) {
|
||||
log1 = l1;
|
||||
@@ -98,4 +92,25 @@ std::ostream* Logger::log1 = 0;
|
||||
std::ostream* Logger::log2 = 0;
|
||||
std::stringstream Logger::log_stream;
|
||||
Logger::Severity Logger::verbosity = Logger::LOG_NOTICE;
|
||||
const char* Logger::severity_strings[] = { "Notice","Warning","Error" };
|
||||
const char* Logger::severity_strings[] = { "Notice","Warning","Error" };
|
||||
|
||||
static const char* const argument_type_string[] = {
|
||||
"NULL",
|
||||
"DERIVED",
|
||||
"INT",
|
||||
"BOOL",
|
||||
"DOUBLE",
|
||||
"STRING",
|
||||
"VECTOR_INT",
|
||||
"VECTOR_DOUBLE",
|
||||
"VECTOR_STRING",
|
||||
"ENUMERATION",
|
||||
"ENTITY",
|
||||
"ENTITY_LIST",
|
||||
"ENTITY_LIST_LIST",
|
||||
"UNKNOWN"
|
||||
};
|
||||
|
||||
const char* IfcUtil::ArgumentTypeToString(ArgumentType argument_type) {
|
||||
return argument_type_string[static_cast<int>(argument_type)];
|
||||
}
|
||||
|
||||
+13
-32
@@ -42,7 +42,9 @@ namespace IfcWrite {
|
||||
|
||||
namespace IfcUtil {
|
||||
enum ArgumentType {
|
||||
Argument_INT,
|
||||
Argument_NULL,
|
||||
Argument_DERIVED,
|
||||
Argument_INT,
|
||||
Argument_BOOL,
|
||||
Argument_DOUBLE,
|
||||
Argument_STRING,
|
||||
@@ -56,6 +58,8 @@ namespace IfcUtil {
|
||||
Argument_UNKNOWN
|
||||
};
|
||||
|
||||
const char* ArgumentTypeToString(ArgumentType argument_type);
|
||||
|
||||
class IfcBaseClass {
|
||||
public:
|
||||
IfcAbstractEntity* entity;
|
||||
@@ -70,6 +74,14 @@ namespace IfcUtil {
|
||||
virtual Argument* getArgument(unsigned int i) const = 0;
|
||||
virtual const char* getArgumentName(unsigned int i) const = 0;
|
||||
};
|
||||
|
||||
// TODO: Investigate whether these should be template classes instead
|
||||
class IfcBaseType : public IfcBaseEntity {
|
||||
public:
|
||||
virtual unsigned int getArgumentCount() const;
|
||||
virtual Argument* getArgument(unsigned int i) const;
|
||||
virtual const char* getArgumentName(unsigned int i) const;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -185,37 +197,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
namespace IfcUtil {
|
||||
class IfcAbstractSelect : public IfcBaseClass {
|
||||
public:
|
||||
typedef IfcTemplatedEntityList<IfcAbstractSelect> list;
|
||||
virtual bool isSimpleType() = 0;
|
||||
static IfcSchema::Type::Enum Class() { return IfcSchema::Type::ALL; }
|
||||
};
|
||||
class IfcEntitySelect : public IfcAbstractSelect {
|
||||
public:
|
||||
typedef IfcEntitySelect* ptr;
|
||||
IfcEntitySelect(IfcBaseClass* b);
|
||||
IfcEntitySelect(IfcAbstractEntity* e);
|
||||
~IfcEntitySelect();
|
||||
bool is(IfcSchema::Type::Enum v) const;
|
||||
IfcSchema::Type::Enum type() const;
|
||||
bool isSimpleType();
|
||||
};
|
||||
class IfcArgumentSelect : public IfcAbstractSelect {
|
||||
IfcSchema::Type::Enum _type;
|
||||
Argument* arg;
|
||||
public:
|
||||
typedef IfcArgumentSelect* ptr;
|
||||
IfcArgumentSelect(IfcSchema::Type::Enum t, Argument* a);
|
||||
~IfcArgumentSelect();
|
||||
Argument* wrappedValue();
|
||||
bool is(IfcSchema::Type::Enum v) const;
|
||||
IfcSchema::Type::Enum type() const;
|
||||
bool isSimpleType();
|
||||
};
|
||||
}
|
||||
|
||||
namespace IfcParse {
|
||||
class IfcFile;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "../ifcparse/IfcWrite.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
#include "../ifcparse/IfcCharacterDecoder.h"
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
|
||||
using namespace IfcWrite;
|
||||
|
||||
@@ -301,7 +302,7 @@ IfcWriteArgument::operator std::vector<std::string>() const { return as<std::vec
|
||||
IfcWriteArgument::operator IfcUtil::IfcBaseClass*() const { return as<IfcUtil::IfcBaseClass*>(); }
|
||||
IfcWriteArgument::operator IfcEntityList::ptr() const { return as<IfcEntityList::ptr>(); }
|
||||
IfcWriteArgument::operator IfcEntityListList::ptr() const { throw; }
|
||||
bool IfcWriteArgument::isNull() const { return argumentType() == argument_type_null; }
|
||||
bool IfcWriteArgument::isNull() const { return type() == IfcUtil::Argument_NULL; }
|
||||
Argument* IfcWriteArgument::operator [] (unsigned int i) const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
std::string IfcWriteArgument::toString(bool upper) const {
|
||||
std::ostringstream str;
|
||||
@@ -318,18 +319,9 @@ unsigned int IfcWriteArgument::Size() const {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
IfcWriteArgument::argument_type IfcWriteArgument::argumentType() const {
|
||||
return static_cast<argument_type>(container.which());
|
||||
}
|
||||
|
||||
IfcUtil::ArgumentType IfcWriteArgument::type() const {
|
||||
// TODO: Make these the same enumeration
|
||||
int ty = static_cast<int>(container.which()) - 2;
|
||||
if (ty < 0) {
|
||||
return IfcUtil::Argument_UNKNOWN;
|
||||
} else {
|
||||
return static_cast<IfcUtil::ArgumentType>(ty);
|
||||
}
|
||||
return static_cast<IfcUtil::ArgumentType>(container.which());
|
||||
}
|
||||
|
||||
IfcEntityList::ptr IfcSelectHelperEntity::getInverse(IfcSchema::Type::Enum,int,const std::string &) {throw IfcParse::IfcException("Invalid cast");}
|
||||
|
||||
@@ -91,21 +91,6 @@ namespace IfcWrite {
|
||||
IfcEntityListList::ptr
|
||||
> container;
|
||||
public:
|
||||
enum argument_type {
|
||||
argument_type_null,
|
||||
argument_type_derived,
|
||||
argument_type_int,
|
||||
argument_type_bool,
|
||||
argument_type_double,
|
||||
argument_type_string,
|
||||
argument_type_vector_int,
|
||||
argument_type_vector_double,
|
||||
argument_type_vector_string,
|
||||
argument_type_enumeration,
|
||||
argument_type_entity,
|
||||
argument_type_entity_list,
|
||||
argument_type_entity_list_list
|
||||
};
|
||||
IfcWriteArgument(IfcAbstractEntity* e) : entity(e) {}
|
||||
template <typename T> const T& as() const {
|
||||
if (const T* val = boost::get<T>(&container)) {
|
||||
@@ -131,7 +116,6 @@ namespace IfcWrite {
|
||||
Argument* operator [] (unsigned int i) const;
|
||||
std::string toString(bool upper=false) const;
|
||||
unsigned int Size() const;
|
||||
argument_type argumentType() const;
|
||||
IfcUtil::ArgumentType type() const;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user