Initial draft of writing and modifying IFC files

This commit is contained in:
Thomas Krijnen
2012-07-18 19:32:58 +00:00
parent 95d2cdc4b6
commit 1d4a999381
8 changed files with 5036 additions and 968 deletions
+6
View File
@@ -95,6 +95,9 @@ ADD_LIBRARY(IfcParse STATIC
../src/ifcparse/IfcUtil.cpp
../src/ifcparse/IfcParse.cpp
../src/ifcparse/IfcCharacterDecoder.cpp
../src/ifcparse/IfcWrite.cpp
../src/ifcparse/IfcGuidHelper.cpp
)
ADD_LIBRARY(IfcGeom STATIC
@@ -155,6 +158,9 @@ SET(include_files_parse
../src/ifcparse/IfcParse.h
../src/ifcparse/IfcUtil.h
../src/ifcparse/SharedPointer.h
../src/ifcparse/IfcWrite.h
../src/ifcparse/IfcWritableEntity.h
)
INSTALL(FILES ${include_files_geom} DESTINATION include/ifcgeom)
INSTALL(FILES ${include_files_parse} DESTINATION include/ifcparse)
+2769 -804
View File
File diff suppressed because it is too large Load Diff
+2123 -164
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -36,6 +36,7 @@ namespace Type {
Enum Parent(Enum v);
Enum FromString(const std::string& s);
std::string ToString(Enum v);
bool IsSimple(Enum v);
}
}
+65
View File
@@ -27,6 +27,7 @@
#include "../ifcparse/IfcException.h"
#include "../ifcparse/IfcUtil.h"
#include "../ifcparse/IfcFile.h"
#include "../ifcparse/IfcWritableEntity.h"
using namespace IfcParse;
@@ -612,6 +613,10 @@ IfcEntities Entity::getInverse(Ifc2x3::Type::Enum c, int i, const std::string& a
bool Entity::is(Ifc2x3::Type::Enum v) const { return _type == v; }
unsigned int Entity::id() { return _id; }
bool Entity::isWritable() {
return false;
}
//
// Parses the IFC file in fn
// Creates the maps
@@ -680,6 +685,7 @@ bool Ifc::Init(IfcParse::File* f) {
Ifc::LogMessage("Warning",ss.str());
}
byid[currentId] = entity;
MaxId = std::max(MaxId,currentId);
currentId = 0;
} else {
try { token = tokens->Next(); }
@@ -760,6 +766,47 @@ bool Ifc::Init(IfcParse::File* f) {
}
return true;
}
void Ifc::AddEntity(IfcUtil::IfcSchemaEntity entity) {
if ( entity->is(Ifc2x3::Type::IfcRoot) ) {
Ifc2x3::IfcRoot::ptr ifc_root = (Ifc2x3::IfcRoot::ptr) entity;
try {
const std::string guid = ifc_root->GlobalId();
if ( byguid.find(guid) != byguid.end() ) {
std::stringstream ss;
ss << "Overwriting entity with guid " << guid;
Ifc::LogMessage("Warning",ss.str());
}
byguid[guid] = ifc_root;
} catch (IfcException ex) {
Ifc::LogMessage("Error",ex.what());
}
}
Ifc2x3::Type::Enum ty = entity->type();
do {
IfcEntities L = EntitiesByType(ty);
if ( L == 0 ) {
L = IfcEntities(new IfcEntityList());
bytype[ty] = L;
}
L->push(entity);
ty = Ifc2x3::Type::Parent(ty);
} while ( ty > -1 );
int new_id = -1;
// For newly created entities ensure a valid ENTITY_INSTANCE_NAME is set
if ( entity->entity->isWritable() ) {
new_id = ((IfcWrite::IfcWritableEntity*)(entity->entity))->setId();
} else {
// TODO: Detect and fix ENTITY_INSTANCE_NAME collisions
new_id = entity->entity->id();
}
if ( byid.find(new_id) != byid.end() ) {
std::stringstream ss;
ss << "Overwriting entity with id " << new_id;
Ifc::LogMessage("Warning",ss.str());
}
byid[new_id] = entity;
}
IfcEntities Ifc::EntitiesByType(Ifc2x3::Type::Enum t) {
MapEntitiesByType::const_iterator it = bytype.find(t);
@@ -851,6 +898,23 @@ MapEntityById::const_iterator Ifc::First() {
MapEntityById::const_iterator Ifc::Last() {
return byid.end();
}
void Ifc::Serialize(std::ostream& os) {
os << "ISO-10303-21;" << std::endl;
os << "HEADER;" << std::endl;
os << "FILE_DESCRIPTION(('ViewDefinition []'),'2;1');" << std::endl;
os << "FILE_NAME('','',(''),('',''),'IfcOpenShell','IfcOpenShell','');" << std::endl;
os << "FILE_SCHEMA(('IFC2X3'));" << std::endl;
os << "ENDSEC;" << std::endl;
os << "DATA;" << std::endl;
for ( MapEntityById::const_iterator it = First(); it != Last(); ++ it ) {
const IfcEntity e = it->second;
os << e->entity->toString(true) << ";" << std::endl;
}
os << "ENDSEC;" << std::endl;
os << "END-ISO-10303-21;" << std::endl;
}
File* Ifc::file = 0;
std::ostream* Ifc::log1 = 0;
@@ -869,3 +933,4 @@ MapEntitiesByRef Ifc::byref;
MapOffsetById Ifc::offsets;
std::stringstream Ifc::log_stream;
int Ifc::Verbosity = 2;
unsigned int Ifc::MaxId = 0;
+5
View File
@@ -203,6 +203,7 @@ namespace IfcParse {
Ifc2x3::Type::Enum type() const;
bool is(Ifc2x3::Type::Enum v) const;
unsigned int id();
bool isWritable();
};
}
@@ -227,6 +228,7 @@ private:
static std::ostream* log1;
static std::ostream* log2;
static std::stringstream log_stream;
static unsigned int MaxId;
public:
/// Returns the first entity in the file, this probably is the entity with the lowest id (EXPRESS ENTITY_NAME)
static MapEntityById::const_iterator First();
@@ -273,6 +275,9 @@ public:
static double PlaneAngleUnit;
static int CircleSegments;
static int Verbosity;
static unsigned int FreshId() { MaxId ++; return MaxId; }
static void AddEntity(IfcUtil::IfcSchemaEntity e);
static void Serialize(std::ostream& os);
};
double UnitPrefixToValue( Ifc2x3::IfcSIPrefix::IfcSIPrefix v );
+51
View File
@@ -73,6 +73,50 @@ typedef IfcBaseClass* IfcSchemaEntity;
}
template <class T>
class Nullable {
private:
T t;
bool null;
public:
Nullable(const T& v) {
t = v;
null = false;
}
Nullable() { null = true; }
operator T() const { return t; }
bool IsNull() const { return null; }
};
template <>
class Nullable<std::string> {
private:
std::string t;
bool null;
public:
Nullable(const std::string& v) {
t = v;
null = false;
}
Nullable() { null = true; }
operator std::string() const { return t; }
Nullable<std::string>& operator =(const char* const c) { t = std::string(c); }
bool IsNull() const { return null; }
};
class Null {
public:
operator Nullable<std::string>() const { return Nullable<std::string>(); }
operator Nullable<std::vector<std::string> >() { return Nullable<std::vector<std::string> >(); }
operator int() { return 0; }
operator void*() { return 0; }
};
#define NULL_STRING Nullable<std::string>()
#define NULL_VECTOR_STRING Nullable<std::vector<std::string> >()
#define IfcNull Null()
class IfcEntityList {
std::vector<IfcUtil::IfcSchemaEntity> ls;
public:
@@ -98,6 +142,11 @@ public:
inline it end() { return ls.end(); }
inline T operator[] (int i) { return ls[i]; }
inline unsigned int Size() const { return (unsigned int) ls.size(); }
IfcEntities generalize() {
IfcEntities r (new IfcEntityList());
for ( it i = begin(); i != end(); ++ i ) r->push(*i);
return r;
}
};
namespace IfcUtil {
@@ -164,6 +213,8 @@ public:
virtual bool is(Ifc2x3::Type::Enum v) const = 0;
virtual std::string toString(bool upper=false) = 0;
virtual unsigned int id() = 0;
virtual bool isWritable() = 0;
//virtual void setArgument(int i,int n);
};
#endif
+16
View File
@@ -173,6 +173,14 @@
RelativePath="..\src\ifcparse\IfcUtil.cpp"
>
</File>
<File
RelativePath="..\src\ifcparse\IfcWrite.cpp"
>
</File>
<File
RelativePath="..\src\ifcparse\IfcGuidHelper.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
@@ -203,6 +211,14 @@
RelativePath="..\src\ifcparse\SharedPointer.h"
>
</File>
<File
RelativePath="..\src\ifcparse\IfcWrite.h"
>
</File>
<File
RelativePath="..\src\ifcparse\IfcWritableEntity.h"
>
</File>
</Filter>
</Files>
<Globals>