mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-30 00:23:14 +00:00
Merge developments from master into the python_wrapper branch
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
#ifndef ARGUMENTTYPE_H
|
||||
#define ARGUMENTTYPE_H
|
||||
|
||||
namespace IfcUtil {
|
||||
enum ArgumentType {
|
||||
Argument_INT, Argument_BOOL, Argument_DOUBLE, Argument_STRING, Argument_VECTOR_INT, Argument_VECTOR_DOUBLE, Argument_VECTOR_STRING, Argument_ENTITY, Argument_ENTITY_LIST, Argument_ENUMERATION, Argument_UNKNOWN
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
+2937
-2770
File diff suppressed because it is too large
Load Diff
@@ -27,7 +27,11 @@
|
||||
#ifndef IFC2X3RT_H
|
||||
#define IFC2X3RT_H
|
||||
|
||||
#include "../ifcparse/ArgumentType.h"
|
||||
#define IfcSchema Ifc2x3
|
||||
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcEntityDescriptor.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
|
||||
namespace Ifc2x3 {
|
||||
namespace Type {
|
||||
@@ -38,7 +42,7 @@ namespace Type {
|
||||
bool GetAttributeOptional(Enum t, unsigned char a);
|
||||
std::pair<const char*, int> GetEnumerationIndex(Enum t, const std::string& a);
|
||||
Enum GetAttributeEnumerationClass(Enum t, unsigned char a);
|
||||
void PopulateDerivedFields(IfcWrite::IfcWritableEntity* e);
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+4517
-3734
File diff suppressed because one or more lines are too long
+5451
-5298
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,48 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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);
|
||||
std::pair<const char*, int> GetEnumerationIndex(Enum t, const std::string& a);
|
||||
Enum GetAttributeEnumerationClass(Enum t, unsigned char a);
|
||||
void PopulateDerivedFields(IfcWrite::IfcWritableEntity* e);
|
||||
}}
|
||||
|
||||
#endif
|
||||
+15752
File diff suppressed because one or more lines are too long
+54630
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -364,4 +364,4 @@ IfcCharacterEncoder::operator std::string() {
|
||||
#ifdef HAVE_ICU
|
||||
UErrorCode IfcCharacterEncoder::status = U_ZERO_ERROR;
|
||||
UConverter* IfcCharacterEncoder::converter = 0;
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,127 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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/Ifc2x3enum.h"
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
|
||||
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
|
||||
+47
-15
@@ -1,21 +1,36 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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 provides functions for loading an IFC file into memory and access *
|
||||
* its entities either by ID, by an IfcSchema::Type or by reference *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef IFCFILE_H
|
||||
#define IFCFILE_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "IfcUtil.h"
|
||||
#include "IfcParse.h"
|
||||
#include "../ifcparse/IfcParse.h"
|
||||
|
||||
namespace IfcParse {
|
||||
|
||||
typedef IfcUtil::IfcSchemaEntity IfcEntity;
|
||||
//typedef IfcEntities IfcEntities;
|
||||
typedef std::map<Ifc2x3::Type::Enum,IfcEntities> MapEntitiesByType;
|
||||
typedef std::map<unsigned int,IfcEntity> MapEntityById;
|
||||
typedef std::map<std::string,Ifc2x3::IfcRoot::ptr> MapEntityByGuid;
|
||||
typedef std::map<unsigned int,IfcEntities> 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 {
|
||||
@@ -27,6 +42,12 @@ private:
|
||||
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();
|
||||
@@ -53,7 +74,7 @@ public:
|
||||
/// 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
|
||||
IfcEntities EntitiesByType(Ifc2x3::Type::Enum t);
|
||||
IfcEntities 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
|
||||
@@ -63,7 +84,7 @@ public:
|
||||
/// Returns the entity with the specified id
|
||||
IfcEntity EntityById(int id);
|
||||
/// Returns the entity with the specified GlobalId
|
||||
Ifc2x3::IfcRoot::ptr EntityByGuid(const std::string& guid);
|
||||
IfcSchema::IfcRoot::ptr EntityByGuid(const std::string& guid);
|
||||
bool Init(const std::string& fn);
|
||||
bool Init(std::istream& fn, int len);
|
||||
bool Init(void* data, int len);
|
||||
@@ -71,8 +92,19 @@ public:
|
||||
unsigned int FreshId() { MaxId ++; return MaxId; }
|
||||
void AddEntity(IfcUtil::IfcSchemaEntity e);
|
||||
void AddEntities(IfcEntities 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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,23 +26,17 @@
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define HAS_BOOST_UUID
|
||||
|
||||
#ifdef HAS_BOOST_UUID
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#endif
|
||||
|
||||
#include "IfcWrite.h"
|
||||
#include "../ifcparse/IfcWrite.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
|
||||
static const char* chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_$";
|
||||
|
||||
#ifdef HAS_BOOST_UUID
|
||||
|
||||
// Converts an unsigned integer into a base64 string of length l
|
||||
std::string base64(unsigned v, int l) {
|
||||
std::string r;
|
||||
@@ -64,7 +58,7 @@ unsigned from_base64(const std::string& s) {
|
||||
for ( std::string::const_iterator i = s.begin()+zeros; i != s.end(); ++ i ) {
|
||||
r *= 64;
|
||||
const char* c = strchr(chars,*i);
|
||||
if ( !c ) throw IfcException("Failed to decode GlobalId");
|
||||
if ( !c ) throw IfcParse::IfcException("Failed to decode GlobalId");
|
||||
r += (c-chars);
|
||||
}
|
||||
return r;
|
||||
@@ -95,10 +89,7 @@ void expand(const std::string& s, std::vector<unsigned char>& v) {
|
||||
// A random number generator for the UUID
|
||||
static boost::uuids::basic_random_generator<boost::mt19937> gen;
|
||||
|
||||
#endif
|
||||
|
||||
IfcWrite::IfcGuidHelper::IfcGuidHelper() {
|
||||
#ifdef HAS_BOOST_UUID
|
||||
boost::uuids::uuid u = gen();
|
||||
std::vector<unsigned char> v(u.size());
|
||||
std::copy(u.begin(), u.end(), v.begin());
|
||||
@@ -108,13 +99,6 @@ IfcWrite::IfcGuidHelper::IfcGuidHelper() {
|
||||
expand(data,v2);
|
||||
boost::uuids::uuid u2;
|
||||
std::copy(v2.begin(), v2.end(), u2.begin());
|
||||
#else
|
||||
if ( ! seeded ) { srand((unsigned int)time(0)); seeded = true; }
|
||||
data.resize(length);
|
||||
for ( unsigned int i = 0; i < length; ++ i ) {
|
||||
data[i] = chars[rand()%strlen(chars)];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
IfcWrite::IfcGuidHelper::operator std::string() const {
|
||||
return data;
|
||||
|
||||
@@ -0,0 +1,390 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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 class is a subclass of the regular IfcFile class that implements *
|
||||
* several convenience functions for creating geometrical representations and *
|
||||
* spatial containers. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "../ifcparse/IfcHierarchyHelper.h"
|
||||
|
||||
IfcSchema::IfcAxis2Placement3D* IfcHierarchyHelper::addPlacement3d(
|
||||
double ox, double oy, double oz,
|
||||
double zx, double zy, double zz,
|
||||
double xx, double xy, double xz)
|
||||
{
|
||||
IfcSchema::IfcDirection* x = addTriplet<IfcSchema::IfcDirection>(xx, xy, xz);
|
||||
IfcSchema::IfcDirection* z = addTriplet<IfcSchema::IfcDirection>(zx, zy, zz);
|
||||
IfcSchema::IfcCartesianPoint* o = addTriplet<IfcSchema::IfcCartesianPoint>(ox, oy, oz);
|
||||
IfcSchema::IfcAxis2Placement3D* p3d = new IfcSchema::IfcAxis2Placement3D(o, z, x);
|
||||
AddEntity(p3d);
|
||||
return p3d;
|
||||
}
|
||||
|
||||
IfcSchema::IfcAxis2Placement2D* IfcHierarchyHelper::addPlacement2d(
|
||||
double ox, double oy,
|
||||
double xx, double xy)
|
||||
{
|
||||
IfcSchema::IfcDirection* x = addDoublet<IfcSchema::IfcDirection>(xx, xy);
|
||||
IfcSchema::IfcCartesianPoint* o = addDoublet<IfcSchema::IfcCartesianPoint>(ox, oy);
|
||||
IfcSchema::IfcAxis2Placement2D* p2d = new IfcSchema::IfcAxis2Placement2D(o, x);
|
||||
AddEntity(p2d);
|
||||
return p2d;
|
||||
}
|
||||
|
||||
IfcSchema::IfcLocalPlacement* IfcHierarchyHelper::addLocalPlacement(
|
||||
double ox, double oy, double oz,
|
||||
double zx, double zy, double zz,
|
||||
double xx, double xy, double xz)
|
||||
{
|
||||
IfcSchema::IfcLocalPlacement* lp = new IfcSchema::IfcLocalPlacement(0,
|
||||
addPlacement3d(ox, oy, oz, zx, zy, zz, xx, xy, xz));
|
||||
|
||||
AddEntity(lp);
|
||||
return lp;
|
||||
}
|
||||
|
||||
IfcSchema::IfcOwnerHistory* IfcHierarchyHelper::addOwnerHistory() {
|
||||
IfcSchema::IfcPerson* person = new IfcSchema::IfcPerson(boost::none, boost::none, std::string(""),
|
||||
boost::none, boost::none, boost::none, boost::none, boost::none);
|
||||
|
||||
IfcSchema::IfcOrganization* organization = new IfcSchema::IfcOrganization(boost::none,
|
||||
"IfcOpenShell", boost::none, boost::none, boost::none);
|
||||
|
||||
IfcSchema::IfcPersonAndOrganization* person_and_org = new IfcSchema::IfcPersonAndOrganization(person, organization, boost::none);
|
||||
IfcSchema::IfcApplication* application = new IfcSchema::IfcApplication(organization,
|
||||
IFCOPENSHELL_VERSION, "IfcOpenShell", "IfcOpenShell");
|
||||
|
||||
int timestamp = (int) time(0);
|
||||
IfcSchema::IfcOwnerHistory* owner_hist = new IfcSchema::IfcOwnerHistory(person_and_org, application,
|
||||
boost::none, IfcSchema::IfcChangeActionEnum::IfcChangeAction_ADDED, boost::none, person_and_org, application, timestamp);
|
||||
|
||||
AddEntity(person);
|
||||
AddEntity(organization);
|
||||
AddEntity(person_and_org);
|
||||
AddEntity(application);
|
||||
AddEntity(owner_hist);
|
||||
|
||||
return owner_hist;
|
||||
}
|
||||
|
||||
IfcSchema::IfcProject* IfcHierarchyHelper::addProject(IfcSchema::IfcOwnerHistory* owner_hist) {
|
||||
IfcSchema::IfcRepresentationContext::list rep_contexts (new IfcTemplatedEntityList<IfcSchema::IfcRepresentationContext>());
|
||||
IfcSchema::IfcGeometricRepresentationContext* rep_context = new IfcSchema::IfcGeometricRepresentationContext(
|
||||
std::string("Plan"), std::string("Model"), 3, 1e-5, addPlacement3d(), addTriplet<IfcSchema::IfcDirection>(0, 1, 0));
|
||||
|
||||
rep_contexts->push(rep_context);
|
||||
|
||||
IfcEntities units (new IfcEntityList());
|
||||
IfcSchema::IfcDimensionalExponents* dimexp = new IfcSchema::IfcDimensionalExponents(0, 0, 0, 0, 0, 0, 0);
|
||||
IfcSchema::IfcSIUnit* unit1 = new IfcSchema::IfcSIUnit(IfcSchema::IfcUnitEnum::IfcUnit_LENGTHUNIT,
|
||||
IfcSchema::IfcSIPrefix::IfcSIPrefix_MILLI, IfcSchema::IfcSIUnitName::IfcSIUnitName_METRE);
|
||||
IfcSchema::IfcSIUnit* unit2a = new IfcSchema::IfcSIUnit(IfcSchema::IfcUnitEnum::IfcUnit_PLANEANGLEUNIT,
|
||||
boost::none, IfcSchema::IfcSIUnitName::IfcSIUnitName_RADIAN);
|
||||
IfcSchema::IfcMeasureWithUnit* unit2b = new IfcSchema::IfcMeasureWithUnit(
|
||||
new IfcWrite::IfcSelectHelper(0.017453293, IfcSchema::Type::IfcPlaneAngleMeasure), unit2a);
|
||||
IfcSchema::IfcConversionBasedUnit* unit2 = new IfcSchema::IfcConversionBasedUnit(dimexp,
|
||||
IfcSchema::IfcUnitEnum::IfcUnit_PLANEANGLEUNIT, "Degrees", unit2b);
|
||||
|
||||
units->push(unit1);
|
||||
units->push(unit2);
|
||||
|
||||
IfcSchema::IfcUnitAssignment* unit_assignment = new IfcSchema::IfcUnitAssignment(units);
|
||||
|
||||
IfcSchema::IfcProject* project = new IfcSchema::IfcProject(IfcWrite::IfcGuidHelper(), owner_hist, boost::none, boost::none,
|
||||
boost::none, boost::none, boost::none, rep_contexts, unit_assignment);
|
||||
|
||||
AddEntity(rep_context);
|
||||
AddEntity(dimexp);
|
||||
AddEntity(unit1);
|
||||
AddEntity(unit2a);
|
||||
AddEntity(unit2b);
|
||||
AddEntity(unit2);
|
||||
AddEntity(unit_assignment);
|
||||
AddEntity(project);
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
void IfcHierarchyHelper::relatePlacements(IfcSchema::IfcProduct* parent, IfcSchema::IfcProduct* product) {
|
||||
IfcSchema::IfcObjectPlacement* place = product->hasObjectPlacement() ? product->ObjectPlacement() : 0;
|
||||
if (place && place->is(IfcSchema::Type::IfcLocalPlacement)) {
|
||||
IfcSchema::IfcLocalPlacement* local_place = (IfcSchema::IfcLocalPlacement*) place;
|
||||
if (parent->hasObjectPlacement()) {
|
||||
local_place->setPlacementRelTo(parent->ObjectPlacement());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IfcSchema::IfcSite* IfcHierarchyHelper::addSite(IfcSchema::IfcProject* proj, IfcSchema::IfcOwnerHistory* owner_hist) {
|
||||
if (! owner_hist) {
|
||||
owner_hist = getSingle<IfcSchema::IfcOwnerHistory>();
|
||||
}
|
||||
if (! owner_hist) {
|
||||
owner_hist = addOwnerHistory();
|
||||
}
|
||||
if (! proj) {
|
||||
proj = getSingle<IfcSchema::IfcProject>();
|
||||
}
|
||||
if (! proj) {
|
||||
proj = addProject(owner_hist);
|
||||
}
|
||||
|
||||
IfcSchema::IfcSite* site = new IfcSchema::IfcSite(IfcWrite::IfcGuidHelper(), owner_hist, boost::none,
|
||||
boost::none, boost::none, addLocalPlacement(), 0, boost::none,
|
||||
IfcSchema::IfcElementCompositionEnum::IfcElementComposition_ELEMENT,
|
||||
boost::none, boost::none, boost::none, boost::none, 0);
|
||||
|
||||
AddEntity(site);
|
||||
addRelatedObject<IfcSchema::IfcRelAggregates>(proj, site);
|
||||
return site;
|
||||
}
|
||||
|
||||
IfcSchema::IfcBuilding* IfcHierarchyHelper::addBuilding(IfcSchema::IfcSite* site, IfcSchema::IfcOwnerHistory* owner_hist) {
|
||||
if (! owner_hist) {
|
||||
owner_hist = getSingle<IfcSchema::IfcOwnerHistory>();
|
||||
}
|
||||
if (! owner_hist) {
|
||||
owner_hist = addOwnerHistory();
|
||||
}
|
||||
if (! site) {
|
||||
site = getSingle<IfcSchema::IfcSite>();
|
||||
}
|
||||
if (! site) {
|
||||
site = addSite(0, owner_hist);
|
||||
}
|
||||
IfcSchema::IfcBuilding* building = new IfcSchema::IfcBuilding(IfcWrite::IfcGuidHelper(), owner_hist, boost::none, boost::none, boost::none,
|
||||
addLocalPlacement(), 0, boost::none, IfcSchema::IfcElementCompositionEnum::IfcElementComposition_ELEMENT,
|
||||
boost::none, boost::none, 0);
|
||||
|
||||
AddEntity(building);
|
||||
addRelatedObject<IfcSchema::IfcRelAggregates>(site, building);
|
||||
relatePlacements(site, building);
|
||||
|
||||
return building;
|
||||
}
|
||||
|
||||
IfcSchema::IfcBuildingStorey* IfcHierarchyHelper::addBuildingStorey(IfcSchema::IfcBuilding* building,
|
||||
IfcSchema::IfcOwnerHistory* owner_hist)
|
||||
{
|
||||
if (! owner_hist) {
|
||||
owner_hist = getSingle<IfcSchema::IfcOwnerHistory>();
|
||||
}
|
||||
if (! owner_hist) {
|
||||
owner_hist = addOwnerHistory();
|
||||
}
|
||||
if (! building) {
|
||||
building = getSingle<IfcSchema::IfcBuilding>();
|
||||
}
|
||||
if (! building) {
|
||||
building = addBuilding(0, owner_hist);
|
||||
}
|
||||
IfcSchema::IfcBuildingStorey* storey = new IfcSchema::IfcBuildingStorey(IfcWrite::IfcGuidHelper(),
|
||||
owner_hist, boost::none, boost::none, boost::none, addLocalPlacement(), 0, boost::none,
|
||||
IfcSchema::IfcElementCompositionEnum::IfcElementComposition_ELEMENT, boost::none);
|
||||
|
||||
AddEntity(storey);
|
||||
addRelatedObject<IfcSchema::IfcRelAggregates>(building, storey);
|
||||
relatePlacements(building, storey);
|
||||
|
||||
return storey;
|
||||
}
|
||||
|
||||
IfcSchema::IfcBuildingStorey* IfcHierarchyHelper::addBuildingProduct(IfcSchema::IfcProduct* product,
|
||||
IfcSchema::IfcBuildingStorey* storey, IfcSchema::IfcOwnerHistory* owner_hist)
|
||||
{
|
||||
if (! owner_hist) {
|
||||
owner_hist = getSingle<IfcSchema::IfcOwnerHistory>();
|
||||
}
|
||||
if (! owner_hist) {
|
||||
owner_hist = addOwnerHistory();
|
||||
}
|
||||
if (! storey) {
|
||||
storey = getSingle<IfcSchema::IfcBuildingStorey>();
|
||||
}
|
||||
if (! storey) {
|
||||
storey = addBuildingStorey(0, owner_hist);
|
||||
}
|
||||
AddEntity(product);
|
||||
addRelatedObject<IfcSchema::IfcRelContainedInSpatialStructure>(storey, product);
|
||||
relatePlacements(storey, product);
|
||||
return storey;
|
||||
}
|
||||
|
||||
void IfcHierarchyHelper::addExtrudedPolyline(IfcSchema::IfcShapeRepresentation* rep, const std::vector<std::pair<double, double> >& points, double h,
|
||||
IfcSchema::IfcAxis2Placement2D* place, IfcSchema::IfcAxis2Placement3D* place2,
|
||||
IfcSchema::IfcDirection* dir, IfcSchema::IfcRepresentationContext* context)
|
||||
{
|
||||
IfcSchema::IfcCartesianPoint::list cartesian_points (new IfcTemplatedEntityList<IfcSchema::IfcCartesianPoint>());
|
||||
for (std::vector<std::pair<double, double> >::const_iterator i = points.begin(); i != points.end(); ++i) {
|
||||
cartesian_points->push(addDoublet<IfcSchema::IfcCartesianPoint>(i->first, i->second));
|
||||
}
|
||||
if (cartesian_points->Size()) cartesian_points->push(*cartesian_points->begin());
|
||||
IfcSchema::IfcPolyline* line = new IfcSchema::IfcPolyline(cartesian_points);
|
||||
IfcSchema::IfcArbitraryClosedProfileDef* profile = new IfcSchema::IfcArbitraryClosedProfileDef(
|
||||
IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, boost::none, line);
|
||||
|
||||
IfcSchema::IfcExtrudedAreaSolid* solid = new IfcSchema::IfcExtrudedAreaSolid(
|
||||
profile, place2 ? place2 : addPlacement3d(), dir ? dir : addTriplet<IfcSchema::IfcDirection>(0, 0, 1), h);
|
||||
|
||||
IfcSchema::IfcRepresentationItem::list items = rep->Items();
|
||||
items->push(solid);
|
||||
rep->setItems(items);
|
||||
|
||||
AddEntity(line);
|
||||
AddEntity(profile);
|
||||
AddEntity(solid);
|
||||
}
|
||||
|
||||
IfcSchema::IfcProductDefinitionShape* IfcHierarchyHelper::addExtrudedPolyline(const std::vector<std::pair<double, double> >& points, double h,
|
||||
IfcSchema::IfcAxis2Placement2D* place, IfcSchema::IfcAxis2Placement3D* place2, IfcSchema::IfcDirection* dir,
|
||||
IfcSchema::IfcRepresentationContext* context)
|
||||
{
|
||||
IfcSchema::IfcRepresentation::list reps (new IfcTemplatedEntityList<IfcSchema::IfcRepresentation>());
|
||||
IfcSchema::IfcRepresentationItem::list items (new IfcTemplatedEntityList<IfcSchema::IfcRepresentationItem>());
|
||||
IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation(context
|
||||
? context
|
||||
: getSingle<IfcSchema::IfcRepresentationContext>(), std::string("Body"), std::string("SweptSolid"), items);
|
||||
reps->push(rep);
|
||||
IfcSchema::IfcProductDefinitionShape* shape = new IfcSchema::IfcProductDefinitionShape(0, 0, reps);
|
||||
AddEntity(rep);
|
||||
AddEntity(shape);
|
||||
addExtrudedPolyline(rep, points, h, place, place2, dir, context);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
void IfcHierarchyHelper::addBox(IfcSchema::IfcShapeRepresentation* rep, double w, double d, double h,
|
||||
IfcSchema::IfcAxis2Placement2D* place, IfcSchema::IfcAxis2Placement3D* place2,
|
||||
IfcSchema::IfcDirection* dir, IfcSchema::IfcRepresentationContext* context)
|
||||
{
|
||||
if (false) {
|
||||
IfcSchema::IfcRectangleProfileDef* profile = new IfcSchema::IfcRectangleProfileDef(
|
||||
IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, 0, place ? place : addPlacement2d(), w, d);
|
||||
IfcSchema::IfcExtrudedAreaSolid* solid = new IfcSchema::IfcExtrudedAreaSolid(profile,
|
||||
place2 ? place2 : addPlacement3d(), dir ? dir : addTriplet<IfcSchema::IfcDirection>(0, 0, 1), h);
|
||||
|
||||
AddEntity(profile);
|
||||
AddEntity(solid);
|
||||
IfcSchema::IfcRepresentationItem::list items = rep->Items();
|
||||
items->push(solid);
|
||||
rep->setItems(items);
|
||||
} else {
|
||||
std::vector<std::pair<double, double> > points;
|
||||
points.push_back(std::pair<double, double>(-w/2, -d/2));
|
||||
points.push_back(std::pair<double, double>(w/2, -d/2));
|
||||
points.push_back(std::pair<double, double>(w/2, d/2));
|
||||
points.push_back(std::pair<double, double>(-w/2, d/2));
|
||||
points.push_back(*points.begin());
|
||||
addExtrudedPolyline(rep, points, h, place, place2, dir, context);
|
||||
}
|
||||
}
|
||||
|
||||
IfcSchema::IfcProductDefinitionShape* IfcHierarchyHelper::addBox(double w, double d, double h, IfcSchema::IfcAxis2Placement2D* place,
|
||||
IfcSchema::IfcAxis2Placement3D* place2, IfcSchema::IfcDirection* dir, IfcSchema::IfcRepresentationContext* context)
|
||||
{
|
||||
IfcSchema::IfcRepresentation::list reps (new IfcTemplatedEntityList<IfcSchema::IfcRepresentation>());
|
||||
IfcSchema::IfcRepresentationItem::list items (new IfcTemplatedEntityList<IfcSchema::IfcRepresentationItem>());
|
||||
IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation(
|
||||
context ? context : getSingle<IfcSchema::IfcRepresentationContext>(), std::string("Body"), std::string("SweptSolid"), items);
|
||||
reps->push(rep);
|
||||
IfcSchema::IfcProductDefinitionShape* shape = new IfcSchema::IfcProductDefinitionShape(0, 0, reps);
|
||||
AddEntity(rep);
|
||||
AddEntity(shape);
|
||||
addBox(rep, w, d, h, place, place2, dir, context);
|
||||
return shape;
|
||||
}
|
||||
|
||||
void IfcHierarchyHelper::clipRepresentation(IfcSchema::IfcProductRepresentation* shape,
|
||||
IfcSchema::IfcAxis2Placement3D* place, bool agree)
|
||||
{
|
||||
IfcSchema::IfcPlane* plane = new IfcSchema::IfcPlane(place);
|
||||
IfcSchema::IfcHalfSpaceSolid* half_space = new IfcSchema::IfcHalfSpaceSolid(plane, agree);
|
||||
IfcSchema::IfcRepresentation::list reps = shape->Representations();
|
||||
for (IfcSchema::IfcRepresentation::it j = reps->begin(); j != reps->end(); ++j) {
|
||||
IfcSchema::IfcRepresentation* rep = *j;
|
||||
if (rep->RepresentationIdentifier() != "Body") continue;
|
||||
rep->setRepresentationType("Clipping");
|
||||
IfcSchema::IfcRepresentationItem::list items = rep->Items();
|
||||
IfcSchema::IfcRepresentationItem::list new_items (new IfcTemplatedEntityList<IfcSchema::IfcRepresentationItem>());
|
||||
AddEntity(plane);
|
||||
AddEntity(half_space);
|
||||
for (IfcSchema::IfcRepresentationItem::it i = items->begin(); i != items->end(); ++i) {
|
||||
IfcSchema::IfcRepresentationItem* item = *i;
|
||||
IfcSchema::IfcBooleanClippingResult* clip = new IfcSchema::IfcBooleanClippingResult(
|
||||
IfcSchema::IfcBooleanOperator::IfcBooleanOperator_DIFFERENCE, item, half_space);
|
||||
AddEntity(clip);
|
||||
new_items->push(clip);
|
||||
}
|
||||
rep->setItems(new_items);
|
||||
}
|
||||
}
|
||||
|
||||
IfcSchema::IfcPresentationStyleAssignment* IfcHierarchyHelper::setSurfaceColour(
|
||||
IfcSchema::IfcProductRepresentation* shape, 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);
|
||||
|
||||
IfcEntities styles(new IfcEntityList());
|
||||
styles->push(rendering);
|
||||
IfcSchema::IfcSurfaceStyle* surface_style = new IfcSchema::IfcSurfaceStyle(
|
||||
boost::none, IfcSchema::IfcSurfaceSide::IfcSurfaceSide_BOTH, styles);
|
||||
IfcEntities surface_styles(new IfcEntityList());
|
||||
surface_styles->push(surface_style);
|
||||
IfcSchema::IfcPresentationStyleAssignment* style_assignment =
|
||||
new IfcSchema::IfcPresentationStyleAssignment(surface_styles);
|
||||
AddEntity(colour);
|
||||
AddEntity(rendering);
|
||||
AddEntity(surface_style);
|
||||
AddEntity(style_assignment);
|
||||
setSurfaceColour(shape, style_assignment);
|
||||
return style_assignment;
|
||||
}
|
||||
|
||||
void IfcHierarchyHelper::setSurfaceColour(IfcSchema::IfcProductRepresentation* shape,
|
||||
IfcSchema::IfcPresentationStyleAssignment* style_assignment)
|
||||
{
|
||||
#ifdef USE_IFC4
|
||||
IfcEntities style_assignments (new IfcEntityList());
|
||||
#else
|
||||
IfcSchema::IfcPresentationStyleAssignment::list style_assignments (new IfcTemplatedEntityList<IfcSchema::IfcPresentationStyleAssignment>());
|
||||
#endif
|
||||
style_assignments->push(style_assignment);
|
||||
IfcSchema::IfcRepresentation::list reps = shape->Representations();
|
||||
for (IfcSchema::IfcRepresentation::it j = reps->begin(); j != reps->end(); ++j) {
|
||||
IfcSchema::IfcRepresentation* rep = *j;
|
||||
if (rep->RepresentationIdentifier() != "Body" && rep->RepresentationIdentifier() != "Facetation") continue;
|
||||
IfcSchema::IfcRepresentationItem::list items = rep->Items();
|
||||
for (IfcSchema::IfcRepresentationItem::it i = items->begin(); i != items->end(); ++i) {
|
||||
IfcSchema::IfcRepresentationItem* item = *i;
|
||||
IfcSchema::IfcStyledItem* styled_item = new IfcSchema::IfcStyledItem(item, style_assignments, boost::none);
|
||||
AddEntity(styled_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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 class is a subclass of the regular IfcFile class that implements *
|
||||
* several convenience functions for creating geometrical representations and *
|
||||
* spatial containers. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef IFCHIERARCHYHELPER_H
|
||||
#define IFCHIERARCHYHELPER_H
|
||||
|
||||
#ifdef USE_IFC4
|
||||
#include "../ifcparse/Ifc4.h"
|
||||
#else
|
||||
#include "../ifcparse/Ifc2x3.h"
|
||||
#endif
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcSpfStream.h"
|
||||
#include "../ifcparse/IfcWrite.h"
|
||||
|
||||
class IfcHierarchyHelper : public IfcParse::IfcFile {
|
||||
public:
|
||||
template <class T>
|
||||
T* addTriplet(double x, double y, double z) {
|
||||
std::vector<double> a; a.push_back(x); a.push_back(y); a.push_back(z);
|
||||
T* t = new T(a);
|
||||
AddEntity(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T* addDoublet(double x, double y) {
|
||||
std::vector<double> a; a.push_back(x); a.push_back(y);
|
||||
T* t = new T(a);
|
||||
AddEntity(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T* getSingle() {
|
||||
typename T::list ts = EntitiesByType<T>();
|
||||
if (ts->Size() != 1) return 0;
|
||||
return *ts->begin();
|
||||
}
|
||||
|
||||
IfcSchema::IfcAxis2Placement3D* addPlacement3d(double ox=0.0, double oy=0.0, double oz=0.0,
|
||||
double zx=0.0, double zy=0.0, double zz=1.0,
|
||||
double xx=1.0, double xy=0.0, double xz=0.0);
|
||||
|
||||
IfcSchema::IfcAxis2Placement2D* addPlacement2d(double ox=0.0, double oy=0.0,
|
||||
double xx=1.0, double xy=0.0);
|
||||
|
||||
IfcSchema::IfcLocalPlacement* addLocalPlacement(double ox=0.0, double oy=0.0, double oz=0.0,
|
||||
double zx=0.0, double zy=0.0, double zz=1.0,
|
||||
double xx=1.0, double xy=0.0, double xz=0.0);
|
||||
|
||||
template <class T>
|
||||
void addRelatedObject(IfcSchema::IfcObjectDefinition* related_object,
|
||||
IfcSchema::IfcObjectDefinition* relating_object, IfcSchema::IfcOwnerHistory* owner_hist = 0)
|
||||
{
|
||||
typename T::list li = EntitiesByType<T>();
|
||||
bool found = false;
|
||||
for (typename T::it i = li->begin(); i != li->end(); ++i) {
|
||||
T* rel = *i;
|
||||
if (rel->RelatingObject() == relating_object) {
|
||||
IfcSchema::IfcObjectDefinition::list products = rel->RelatedObjects();
|
||||
products->push(related_object);
|
||||
rel->setRelatedObjects(products);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! found) {
|
||||
if (! owner_hist) {
|
||||
owner_hist = getSingle<IfcSchema::IfcOwnerHistory>();
|
||||
}
|
||||
if (! owner_hist) {
|
||||
owner_hist = addOwnerHistory();
|
||||
}
|
||||
IfcSchema::IfcObjectDefinition::list relating_objects (new IfcTemplatedEntityList<IfcSchema::IfcObjectDefinition>());
|
||||
relating_objects->push(relating_object);
|
||||
T* t = new T(IfcWrite::IfcGuidHelper(), owner_hist, boost::none, boost::none, related_object, relating_objects);
|
||||
AddEntity(t);
|
||||
}
|
||||
}
|
||||
|
||||
IfcSchema::IfcOwnerHistory* addOwnerHistory();
|
||||
IfcSchema::IfcProject* addProject(IfcSchema::IfcOwnerHistory* owner_hist = 0);
|
||||
void relatePlacements(IfcSchema::IfcProduct* parent, IfcSchema::IfcProduct* product);
|
||||
IfcSchema::IfcSite* addSite(IfcSchema::IfcProject* proj = 0, IfcSchema::IfcOwnerHistory* owner_hist = 0);
|
||||
IfcSchema::IfcBuilding* addBuilding(IfcSchema::IfcSite* site = 0, IfcSchema::IfcOwnerHistory* owner_hist = 0);
|
||||
|
||||
IfcSchema::IfcBuildingStorey* addBuildingStorey(IfcSchema::IfcBuilding* building = 0,
|
||||
IfcSchema::IfcOwnerHistory* owner_hist = 0);
|
||||
|
||||
IfcSchema::IfcBuildingStorey* addBuildingProduct(IfcSchema::IfcProduct* product,
|
||||
IfcSchema::IfcBuildingStorey* storey = 0, IfcSchema::IfcOwnerHistory* owner_hist = 0);
|
||||
|
||||
void addExtrudedPolyline(IfcSchema::IfcShapeRepresentation* rep, const std::vector<std::pair<double, double> >& points, double h,
|
||||
IfcSchema::IfcAxis2Placement2D* place=0, IfcSchema::IfcAxis2Placement3D* place2=0,
|
||||
IfcSchema::IfcDirection* dir=0, IfcSchema::IfcRepresentationContext* context=0);
|
||||
|
||||
IfcSchema::IfcProductDefinitionShape* addExtrudedPolyline(const std::vector<std::pair<double, double> >& points, double h,
|
||||
IfcSchema::IfcAxis2Placement2D* place=0, IfcSchema::IfcAxis2Placement3D* place2=0, IfcSchema::IfcDirection* dir=0,
|
||||
IfcSchema::IfcRepresentationContext* context=0);
|
||||
|
||||
void addBox(IfcSchema::IfcShapeRepresentation* rep, double w, double d, double h,
|
||||
IfcSchema::IfcAxis2Placement2D* place=0, IfcSchema::IfcAxis2Placement3D* place2=0,
|
||||
IfcSchema::IfcDirection* dir=0, IfcSchema::IfcRepresentationContext* context=0);
|
||||
|
||||
IfcSchema::IfcProductDefinitionShape* addBox(double w, double d, double h, IfcSchema::IfcAxis2Placement2D* place=0,
|
||||
IfcSchema::IfcAxis2Placement3D* place2=0, IfcSchema::IfcDirection* dir=0, IfcSchema::IfcRepresentationContext* context=0);
|
||||
|
||||
void clipRepresentation(IfcSchema::IfcProductRepresentation* shape,
|
||||
IfcSchema::IfcAxis2Placement3D* place, bool agree);
|
||||
|
||||
IfcSchema::IfcPresentationStyleAssignment* setSurfaceColour(IfcSchema::IfcProductRepresentation* shape,
|
||||
double r, double g, double b, double a=1.0);
|
||||
|
||||
void setSurfaceColour(IfcSchema::IfcProductRepresentation* shape,
|
||||
IfcSchema::IfcPresentationStyleAssignment* style_assignment);
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
inline void IfcHierarchyHelper::addRelatedObject <IfcSchema::IfcRelContainedInSpatialStructure> (IfcSchema::IfcObjectDefinition* related_object,
|
||||
IfcSchema::IfcObjectDefinition* relating_object, IfcSchema::IfcOwnerHistory* owner_hist)
|
||||
{
|
||||
IfcSchema::IfcRelContainedInSpatialStructure::list li = EntitiesByType<IfcSchema::IfcRelContainedInSpatialStructure>();
|
||||
bool found = false;
|
||||
for (IfcSchema::IfcRelContainedInSpatialStructure::it i = li->begin(); i != li->end(); ++i) {
|
||||
IfcSchema::IfcRelContainedInSpatialStructure* rel = *i;
|
||||
if (rel->RelatingStructure() == relating_object) {
|
||||
IfcSchema::IfcProduct::list products = rel->RelatedElements();
|
||||
products->push((IfcSchema::IfcProduct*)related_object);
|
||||
rel->setRelatedElements(products);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! found) {
|
||||
if (! owner_hist) {
|
||||
owner_hist = getSingle<IfcSchema::IfcOwnerHistory>();
|
||||
}
|
||||
if (! owner_hist) {
|
||||
owner_hist = addOwnerHistory();
|
||||
}
|
||||
IfcSchema::IfcProduct::list relating_objects (new IfcTemplatedEntityList<IfcSchema::IfcProduct>());
|
||||
relating_objects->push((IfcSchema::IfcProduct*)relating_object);
|
||||
IfcSchema::IfcRelContainedInSpatialStructure* t = new IfcSchema::IfcRelContainedInSpatialStructure(IfcWrite::IfcGuidHelper(), owner_hist,
|
||||
boost::none, boost::none, relating_objects, (IfcSchema::IfcSpatialStructureElement*)related_object);
|
||||
|
||||
AddEntity(t);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+94
-46
@@ -21,15 +21,22 @@
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctime>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#include "../ifcparse/IfcCharacterDecoder.h"
|
||||
#include "../ifcparse/IfcParse.h"
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcSpfStream.h"
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
|
||||
#include "../ifcparse/IfcUntypedEntity.h"
|
||||
|
||||
using namespace IfcParse;
|
||||
|
||||
//
|
||||
@@ -37,15 +44,23 @@ using namespace IfcParse;
|
||||
//
|
||||
IfcSpfStream::IfcSpfStream(const std::string& fn) {
|
||||
eof = false;
|
||||
stream.open(fn.c_str(),std::ios_base::binary);
|
||||
if ( ! stream.good() ) {
|
||||
#ifdef _MSC_VER_NO
|
||||
int fn_buffer_size = MultiByteToWideChar(CP_UTF8, 0, fn.c_str(), -1, 0, 0);
|
||||
wchar_t* fn_wide = new wchar_t[fn_buffer_size];
|
||||
MultiByteToWideChar(CP_UTF8, 0, fn.c_str(), -1, fn_wide, fn_buffer_size);
|
||||
stream = _wfopen(fn_wide, L"rb");
|
||||
delete[] fn_wide;
|
||||
#else
|
||||
stream = fopen(fn.c_str(), "rb");
|
||||
#endif
|
||||
if (stream == NULL) {
|
||||
valid = false;
|
||||
return;
|
||||
}
|
||||
valid = true;
|
||||
stream.seekg(0,std::ios_base::end);
|
||||
size = (unsigned int) stream.tellg();
|
||||
stream.seekg(0,std::ios_base::beg);
|
||||
fseek(stream, 0, SEEK_END);
|
||||
size = (unsigned int) ftell(stream);;
|
||||
rewind(stream);
|
||||
#ifdef BUF_SIZE
|
||||
offset = 0;
|
||||
paging = size > BUF_SIZE;
|
||||
@@ -87,7 +102,7 @@ IfcSpfStream::IfcSpfStream(void* data, int l) {
|
||||
|
||||
void IfcSpfStream::Close() {
|
||||
#ifdef BUF_SIZE
|
||||
if ( paging ) stream.close();
|
||||
if ( paging ) fclose(stream);
|
||||
#endif
|
||||
delete[] buffer;
|
||||
}
|
||||
@@ -99,23 +114,22 @@ void IfcSpfStream::ReadBuffer(bool inc) {
|
||||
#ifdef BUF_SIZE
|
||||
if ( inc ) {
|
||||
offset += len;
|
||||
stream.seekg(offset,std::ios_base::beg);
|
||||
fseek(stream, offset, SEEK_SET);
|
||||
}
|
||||
#endif
|
||||
eof = stream.eof();
|
||||
eof = feof(stream) != 0;
|
||||
if ( eof ) return;
|
||||
#ifdef BUF_SIZE
|
||||
stream.read(buffer,size < BUF_SIZE ? size : BUF_SIZE);
|
||||
len = (unsigned int) fread(buffer, 1, size < BUF_SIZE ? size : BUF_SIZE, stream);
|
||||
#else
|
||||
stream.read(buffer,size);
|
||||
len = (unsigned int) fread(buffer, 1, size, stream);
|
||||
#endif
|
||||
len = (unsigned int) stream.gcount();
|
||||
eof = len == 0;
|
||||
ptr = 0;
|
||||
#ifdef BUF_SIZE
|
||||
if (!paging) stream.close();
|
||||
if (!paging) fclose(stream);
|
||||
#else
|
||||
stream.close();
|
||||
fclose(stream);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -134,8 +148,8 @@ void IfcSpfStream::Seek(unsigned int o) {
|
||||
ptr = o - offset;
|
||||
} else {
|
||||
offset = o;
|
||||
stream.clear();
|
||||
stream.seekg(o,std::ios_base::beg);
|
||||
clearerr(stream);
|
||||
fseek(stream, o, SEEK_SET);
|
||||
ReadBuffer(false);
|
||||
}
|
||||
#endif
|
||||
@@ -160,9 +174,9 @@ char IfcSpfStream::Read(unsigned int o) {
|
||||
} else if ( o >= offset && (o < (offset+len)) ) {
|
||||
return buffer[o-offset];
|
||||
} else {
|
||||
stream.clear();
|
||||
stream.seekg(o,std::ios_base::beg);
|
||||
return stream.peek();
|
||||
clearerr(stream);
|
||||
fseek(stream, o, SEEK_SET);
|
||||
return ungetc(getc(stream), stream);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -352,8 +366,8 @@ TokenArgument::TokenArgument(const Token& t) {
|
||||
token = t;
|
||||
}
|
||||
|
||||
EntityArgument::EntityArgument(Ifc2x3::Type::Enum ty, const Token& t) {
|
||||
entity = new Ifc::IfcUntypedEntity(new Entity(0,t.first->file,t.second));
|
||||
EntityArgument::EntityArgument(IfcSchema::Type::Enum ty, const Token& t) {
|
||||
entity = new IfcUntypedEntity(new Entity(0,t.first->file,t.second));
|
||||
}
|
||||
|
||||
//
|
||||
@@ -505,7 +519,7 @@ Entity::Entity(unsigned int i, IfcFile* f) { //: file(f) {
|
||||
file = f;
|
||||
Token datatype = f->tokens->Next();
|
||||
if ( ! TokenFunc::isDatatype(datatype)) throw IfcException("Unexpected token while parsing entity");
|
||||
_type = Ifc2x3::Type::FromString(TokenFunc::asString(datatype));
|
||||
_type = IfcSchema::Type::FromString(TokenFunc::asString(datatype));
|
||||
_id = i;
|
||||
args = ArgumentPtr();
|
||||
offset = datatype.second;
|
||||
@@ -549,7 +563,7 @@ void Entity::Load(std::vector<unsigned int>& ids, bool seek) {
|
||||
file->tokens->stream->Seek(offset);
|
||||
Token datatype = file->tokens->Next();
|
||||
if ( ! TokenFunc::isDatatype(datatype)) throw IfcException("Unexpected token while parsing entity");
|
||||
_type = Ifc2x3::Type::FromString(TokenFunc::asString(datatype));
|
||||
_type = IfcSchema::Type::FromString(TokenFunc::asString(datatype));
|
||||
}
|
||||
Token open = file->tokens->Next();
|
||||
args = new ArgumentList(file->tokens, ids);
|
||||
@@ -558,7 +572,7 @@ void Entity::Load(std::vector<unsigned int>& ids, bool seek) {
|
||||
if ( ! TokenFunc::isOperator(semilocon,';') ) file->tokens->stream->Seek(old_offset);
|
||||
}
|
||||
|
||||
Ifc2x3::Type::Enum Entity::type() const {
|
||||
IfcSchema::Type::Enum Entity::type() const {
|
||||
return _type;
|
||||
}
|
||||
|
||||
@@ -566,7 +580,7 @@ Ifc2x3::Type::Enum Entity::type() const {
|
||||
// Returns the CamelCase string representation of the datatype as it is defined in the schema
|
||||
//
|
||||
std::string Entity::datatype() {
|
||||
return Ifc2x3::Type::ToString(_type);
|
||||
return IfcSchema::Type::ToString(_type);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -597,18 +611,18 @@ Entity::~Entity() {
|
||||
//
|
||||
// Returns the entities of type c that have this entity in their ArgumentList
|
||||
//
|
||||
IfcEntities Entity::getInverse(Ifc2x3::Type::Enum c) {
|
||||
IfcEntities Entity::getInverse(IfcSchema::Type::Enum c) {
|
||||
IfcEntities l = IfcEntities(new IfcEntityList());
|
||||
IfcEntities all = file->EntitiesByReference(_id);
|
||||
if ( ! all ) return l;
|
||||
for( IfcEntityList::it it = all->begin(); it != all->end();++ it ) {
|
||||
if ( c == Ifc2x3::Type::ALL || (*it)->is(c) ) {
|
||||
if ( c == IfcSchema::Type::ALL || (*it)->is(c) ) {
|
||||
l->push(*it);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
IfcEntities Entity::getInverse(Ifc2x3::Type::Enum c, int i, const std::string& a) {
|
||||
IfcEntities Entity::getInverse(IfcSchema::Type::Enum c, int i, const std::string& a) {
|
||||
IfcEntities l = IfcEntities(new IfcEntityList());
|
||||
IfcEntities all = getInverse(c);
|
||||
for( IfcEntityList::it it = all->begin(); it != all->end();++ it ) {
|
||||
@@ -619,7 +633,7 @@ IfcEntities Entity::getInverse(Ifc2x3::Type::Enum c, int i, const std::string& a
|
||||
}
|
||||
return l;
|
||||
}
|
||||
bool Entity::is(Ifc2x3::Type::Enum v) const { return _type == v; }
|
||||
bool Entity::is(IfcSchema::Type::Enum v) const { return _type == v; }
|
||||
unsigned int Entity::id() { return _id; }
|
||||
|
||||
bool Entity::isWritable() {
|
||||
@@ -631,6 +645,7 @@ IfcFile::IfcFile() {
|
||||
lastId = 0;
|
||||
tokens = 0;
|
||||
MaxId = 0;
|
||||
initTimestamp();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -648,7 +663,7 @@ bool IfcFile::Init(void* data, int len) {
|
||||
return IfcFile::Init(new IfcSpfStream(data,len));
|
||||
}
|
||||
bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
|
||||
Ifc2x3::InitStringMap();
|
||||
IfcSchema::InitStringMap();
|
||||
file = f;
|
||||
if ( ! file->valid ) return false;
|
||||
tokens = new Tokens (file,this);
|
||||
@@ -664,8 +679,7 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
|
||||
if ( currentId ) {
|
||||
try {
|
||||
e = new Entity(currentId,this);
|
||||
//entity = Ifc2x3::SchemaEntity(e);
|
||||
entity = new Ifc::IfcUntypedEntity(e);
|
||||
entity = new IfcUntypedEntity(e);
|
||||
} catch (IfcException ex) {
|
||||
currentId = 0;
|
||||
Logger::Message(Logger::LOG_ERROR,ex.what());
|
||||
@@ -676,8 +690,8 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
|
||||
std::stringstream ss; ss << "\r#" << currentId;
|
||||
Logger::Status(ss.str(), false);
|
||||
}
|
||||
if ( entity->is(Ifc2x3::Type::IfcRoot) ) {
|
||||
Ifc2x3::IfcRoot::ptr ifc_root = (Ifc2x3::IfcRoot::ptr) entity;
|
||||
if ( entity->is(IfcSchema::Type::IfcRoot) ) {
|
||||
IfcSchema::IfcRoot::ptr ifc_root = (IfcSchema::IfcRoot::ptr) entity;
|
||||
try {
|
||||
const std::string guid = ifc_root->GlobalId();
|
||||
if ( byguid.find(guid) != byguid.end() ) {
|
||||
@@ -690,7 +704,7 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
|
||||
Logger::Message(Logger::LOG_ERROR,ex.what());
|
||||
}
|
||||
}
|
||||
Ifc2x3::Type::Enum ty = entity->type();
|
||||
IfcSchema::Type::Enum ty = entity->type();
|
||||
do {
|
||||
IfcEntities L = EntitiesByType(ty);
|
||||
if ( L == 0 ) {
|
||||
@@ -698,7 +712,7 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
|
||||
bytype[ty] = L;
|
||||
}
|
||||
L->push(entity);
|
||||
ty = Ifc2x3::Type::Parent(ty);
|
||||
ty = IfcSchema::Type::Parent(ty);
|
||||
} while ( ty > -1 );
|
||||
if ( byid.find(currentId) != byid.end() ) {
|
||||
std::stringstream ss;
|
||||
@@ -706,7 +720,7 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
|
||||
Logger::Message(Logger::LOG_WARNING,ss.str());
|
||||
}
|
||||
byid[currentId] = entity;
|
||||
MaxId = std::max(MaxId,currentId);
|
||||
MaxId = (std::max)(MaxId,currentId);
|
||||
currentId = 0;
|
||||
} else {
|
||||
try { token = tokens->Next(); }
|
||||
@@ -737,8 +751,8 @@ void IfcFile::AddEntities(IfcEntities es) {
|
||||
}
|
||||
}
|
||||
void IfcFile::AddEntity(IfcUtil::IfcSchemaEntity entity) {
|
||||
if ( entity->is(Ifc2x3::Type::IfcRoot) ) {
|
||||
Ifc2x3::IfcRoot::ptr ifc_root = (Ifc2x3::IfcRoot::ptr) entity;
|
||||
if ( entity->is(IfcSchema::Type::IfcRoot) ) {
|
||||
IfcSchema::IfcRoot::ptr ifc_root = (IfcSchema::IfcRoot::ptr) entity;
|
||||
try {
|
||||
const std::string guid = ifc_root->GlobalId();
|
||||
if ( byguid.find(guid) != byguid.end() ) {
|
||||
@@ -751,7 +765,7 @@ void IfcFile::AddEntity(IfcUtil::IfcSchemaEntity entity) {
|
||||
Logger::Message(Logger::LOG_ERROR,ex.what());
|
||||
}
|
||||
}
|
||||
Ifc2x3::Type::Enum ty = entity->type();
|
||||
IfcSchema::Type::Enum ty = entity->type();
|
||||
do {
|
||||
IfcEntities L = EntitiesByType(ty);
|
||||
if ( L == 0 ) {
|
||||
@@ -759,7 +773,7 @@ void IfcFile::AddEntity(IfcUtil::IfcSchemaEntity entity) {
|
||||
bytype[ty] = L;
|
||||
}
|
||||
L->push(entity);
|
||||
ty = Ifc2x3::Type::Parent(ty);
|
||||
ty = IfcSchema::Type::Parent(ty);
|
||||
} while ( ty > -1 );
|
||||
int new_id = -1;
|
||||
// For newly created entities ensure a valid ENTITY_INSTANCE_NAME is set
|
||||
@@ -778,14 +792,14 @@ void IfcFile::AddEntity(IfcUtil::IfcSchemaEntity entity) {
|
||||
byid[new_id] = entity;
|
||||
|
||||
}
|
||||
IfcEntities IfcFile::EntitiesByType(Ifc2x3::Type::Enum t) {
|
||||
IfcEntities IfcFile::EntitiesByType(IfcSchema::Type::Enum t) {
|
||||
MapEntitiesByType::const_iterator it = bytype.find(t);
|
||||
return (it == bytype.end()) ? IfcEntities() : it->second;
|
||||
}
|
||||
IfcEntities IfcFile::EntitiesByType(const std::string& t) {
|
||||
std::string ty = t;
|
||||
for (std::string::iterator p = ty.begin(); p != ty.end(); ++p ) *p = toupper(*p);
|
||||
return EntitiesByType(Ifc2x3::Type::FromString(ty));
|
||||
return EntitiesByType(IfcSchema::Type::FromString(ty));
|
||||
}
|
||||
IfcEntities IfcFile::EntitiesByReference(int t) {
|
||||
MapEntitiesByRef::const_iterator it = byref.find(t);
|
||||
@@ -798,13 +812,13 @@ IfcUtil::IfcSchemaEntity IfcFile::EntityById(int id) {
|
||||
if ( it2 == offsets.end() ) throw IfcException("Entity not found");
|
||||
const unsigned int offset = (*it2).second;
|
||||
EntityPtr e = EntityPtr(new Entity(id,this,offset));
|
||||
IfcUtil::IfcSchemaEntity entity = Ifc2x3::SchemaEntity(e);
|
||||
IfcUtil::IfcSchemaEntity entity = IfcSchema::SchemaEntity(e);
|
||||
byid[id] = entity;
|
||||
return entity;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
Ifc2x3::IfcRoot::ptr IfcFile::EntityByGuid(const std::string& guid) {
|
||||
IfcSchema::IfcRoot::ptr IfcFile::EntityByGuid(const std::string& guid) {
|
||||
MapEntityByGuid::const_iterator it = byguid.find(guid);
|
||||
if ( it == byguid.end() ) {
|
||||
throw IfcException("Entity not found");
|
||||
@@ -838,8 +852,20 @@ std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f) {
|
||||
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_NAME("
|
||||
<< static_cast<std::string>(IfcWrite::IfcCharacterEncoder(f.filename())) << ","
|
||||
<< static_cast<std::string>(IfcWrite::IfcCharacterEncoder(f.timestamp())) << ",("
|
||||
<< static_cast<std::string>(IfcWrite::IfcCharacterEncoder(f.authorOrganisation())) << "),("
|
||||
<< static_cast<std::string>(IfcWrite::IfcCharacterEncoder(f.authorName())) << ","
|
||||
<< static_cast<std::string>(IfcWrite::IfcCharacterEncoder(f.authorEmail()))
|
||||
<< "),'IfcOpenShell " << IFCOPENSHELL_VERSION
|
||||
<< "','IfcOpenShell " << IFCOPENSHELL_VERSION
|
||||
<< "','');" << std::endl;
|
||||
#ifdef USE_IFC4
|
||||
os << "FILE_SCHEMA(('IFC4'));" << std::endl;
|
||||
#else
|
||||
os << "FILE_SCHEMA(('IFC2X3'));" << std::endl;
|
||||
#endif
|
||||
os << "ENDSEC;" << std::endl;
|
||||
os << "DATA;" << std::endl;
|
||||
|
||||
@@ -853,3 +879,25 @@ std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f) {
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
void IfcFile::filename(const std::string& s) { _filename = s; }
|
||||
std::string IfcFile::filename() const { return _filename; }
|
||||
void IfcFile::timestamp(const std::string& s) { _timestamp = s; }
|
||||
std::string IfcFile::timestamp() const { return _timestamp; }
|
||||
void IfcFile::author(const std::string& name, const std::string& email, const std::string& organisation) {
|
||||
_author = name;
|
||||
_author_email = email;
|
||||
_author_organisation = organisation;
|
||||
}
|
||||
std::string IfcFile::authorName() const { return _author; }
|
||||
std::string IfcFile::authorEmail() const { return _author_email; }
|
||||
std::string IfcFile::authorOrganisation() const { return _author_organisation; }
|
||||
void IfcFile::initTimestamp() {
|
||||
char buf[255];
|
||||
time_t t;
|
||||
time(&t);
|
||||
struct tm * ti = localtime (&t);
|
||||
if (strftime(buf,255,"%Y-%m-%dT%H:%M:%S",ti)) {
|
||||
_timestamp = std::string(buf);
|
||||
}
|
||||
}
|
||||
+26
-12
@@ -20,14 +20,14 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* This file provides functions for loading an IFC file into memory and access *
|
||||
* its entities either by ID, by an Ifc2x3::Type or by reference *
|
||||
* its entities either by ID, by an IfcSchema::Type or by reference *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef IFCPARSE_H
|
||||
#define IFCPARSE_H
|
||||
|
||||
#define IFCOPENSHELL_VERSION "0.3.0-rc3"
|
||||
#define IFCOPENSHELL_VERSION "0.5.0-dev"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
@@ -40,10 +40,16 @@
|
||||
#include "../ifcparse/SharedPointer.h"
|
||||
#include "../ifcparse/IfcCharacterDecoder.h"
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/Ifc2x3.h"
|
||||
#include "../ifcparse/IfcSpfStream.h"
|
||||
#include "../ifcparse/IfcUntypedEntity.h"
|
||||
|
||||
#ifdef USE_IFC4
|
||||
#include "../ifcparse/Ifc4.h"
|
||||
#else
|
||||
#include "../ifcparse/Ifc2x3.h"
|
||||
#endif
|
||||
|
||||
#include "../ifcparse/IfcSpfStream.h"
|
||||
|
||||
namespace IfcParse {
|
||||
|
||||
class Entity;
|
||||
@@ -162,9 +168,9 @@ namespace IfcParse {
|
||||
/// ===================== =====================
|
||||
class EntityArgument : public Argument {
|
||||
private:
|
||||
Ifc::IfcUntypedEntity* entity;
|
||||
IfcUntypedEntity* entity;
|
||||
public:
|
||||
EntityArgument(Ifc2x3::Type::Enum ty, const Token& t);
|
||||
EntityArgument(IfcSchema::Type::Enum ty, const Token& t);
|
||||
~EntityArgument();
|
||||
operator int() const;
|
||||
operator bool() const;
|
||||
@@ -189,7 +195,7 @@ namespace IfcParse {
|
||||
private:
|
||||
//IfcFile* file;
|
||||
ArgumentPtr args;
|
||||
Ifc2x3::Type::Enum _type;
|
||||
IfcSchema::Type::Enum _type;
|
||||
public:
|
||||
/// The EXPRESS ENTITY_INSTANCE_NAME
|
||||
unsigned int _id;
|
||||
@@ -198,20 +204,28 @@ namespace IfcParse {
|
||||
Entity(unsigned int i, IfcFile* t);
|
||||
Entity(unsigned int i, IfcFile* t, unsigned int o);
|
||||
~Entity();
|
||||
IfcEntities getInverse(Ifc2x3::Type::Enum c = Ifc2x3::Type::ALL);
|
||||
IfcEntities getInverse(Ifc2x3::Type::Enum c, int i, const std::string& a);
|
||||
IfcEntities getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL);
|
||||
IfcEntities getInverse(IfcSchema::Type::Enum c, int i, const std::string& a);
|
||||
void Load(std::vector<unsigned int>& ids, bool seek=false);
|
||||
ArgumentPtr getArgument (unsigned int i);
|
||||
unsigned int getArgumentCount();
|
||||
std::string toString(bool upper=false);
|
||||
std::string datatype();
|
||||
Ifc2x3::Type::Enum type() const;
|
||||
bool is(Ifc2x3::Type::Enum v) const;
|
||||
IfcSchema::Type::Enum type() const;
|
||||
bool is(IfcSchema::Type::Enum v) const;
|
||||
unsigned int id();
|
||||
bool isWritable();
|
||||
};
|
||||
|
||||
double UnitPrefixToValue( Ifc2x3::IfcSIPrefix::IfcSIPrefix v );
|
||||
typedef IfcUtil::IfcSchemaEntity IfcEntity;
|
||||
//typedef IfcEntities IfcEntities;
|
||||
typedef std::map<IfcSchema::Type::Enum,IfcEntities> MapEntitiesByType;
|
||||
typedef std::map<unsigned int,IfcEntity> MapEntityById;
|
||||
typedef std::map<std::string,IfcSchema::IfcRoot::ptr> MapEntityByGuid;
|
||||
typedef std::map<unsigned int,IfcEntities> MapEntitiesByRef;
|
||||
typedef std::map<unsigned int,unsigned int> MapOffsetById;
|
||||
|
||||
double UnitPrefixToValue( IfcSchema::IfcSIPrefix::IfcSIPrefix v );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@
|
||||
// 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
|
||||
// manner efficiently. To enable the paging functionality uncomment
|
||||
// the following statement.
|
||||
//const int BUF_SIZE = (128 * 1024 * 1024);
|
||||
// #define BUF_SIZE (8 * 1024 * 1024)
|
||||
|
||||
namespace IfcParse {
|
||||
/// The IfcSpfStream class represents a ISO 10303-21 IFC-SPF file in memory.
|
||||
@@ -48,7 +48,7 @@ namespace IfcParse {
|
||||
/// detrimental for the performance of the parser.
|
||||
class IfcSpfStream {
|
||||
private:
|
||||
std::ifstream stream;
|
||||
FILE* stream;
|
||||
char* buffer;
|
||||
unsigned int ptr;
|
||||
unsigned int len;
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "IfcWritableEntity.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
|
||||
#include "IfcUtil.h"
|
||||
#include "IfcWrite.h"
|
||||
#include "Ifc2x3-rt.h"
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcWrite.h"
|
||||
#include "../ifcparse/Ifc2x3-rt.h"
|
||||
|
||||
IfcWrite::IfcWritableEntity* Ifc::IfcUntypedEntity::writable_entity() {
|
||||
#include "IfcUntypedEntity.h"
|
||||
|
||||
using namespace IfcUtil;
|
||||
|
||||
IfcWrite::IfcWritableEntity* IfcParse::IfcUntypedEntity::writable_entity() {
|
||||
IfcWrite::IfcWritableEntity* e;
|
||||
if (entity->isWritable()) {
|
||||
e = (IfcWrite::IfcWritableEntity*) entity;
|
||||
@@ -15,130 +19,131 @@ IfcWrite::IfcWritableEntity* Ifc::IfcUntypedEntity::writable_entity() {
|
||||
}
|
||||
return e;
|
||||
}
|
||||
Ifc::IfcUntypedEntity::IfcUntypedEntity(const std::string& s) {
|
||||
IfcParse::IfcUntypedEntity::IfcUntypedEntity(const std::string& s) {
|
||||
std::string S = s;
|
||||
for (std::string::iterator i = S.begin(); i != S.end(); ++i ) *i = toupper(*i);
|
||||
_type = Ifc2x3::Type::FromString(S);
|
||||
_type = IfcSchema::Type::FromString(S);
|
||||
entity = new IfcWrite::IfcWritableEntity(_type);
|
||||
IfcSchema::Type::PopulateDerivedFields(writable_entity());
|
||||
}
|
||||
Ifc::IfcUntypedEntity::IfcUntypedEntity(IfcAbstractEntity* e) {
|
||||
IfcParse::IfcUntypedEntity::IfcUntypedEntity(IfcAbstractEntity* e) {
|
||||
entity = e;
|
||||
_type = e->type();
|
||||
}
|
||||
bool Ifc::IfcUntypedEntity::is(Ifc2x3::Type::Enum v) const {
|
||||
Ifc2x3::Type::Enum _ty = _type;
|
||||
bool IfcParse::IfcUntypedEntity::is(IfcSchema::Type::Enum v) const {
|
||||
IfcSchema::Type::Enum _ty = _type;
|
||||
if (v == _ty) return true;
|
||||
while (_ty != -1) {
|
||||
_ty = Ifc2x3::Type::Parent(_ty);
|
||||
_ty = IfcSchema::Type::Parent(_ty);
|
||||
if (v == _ty) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
std::string Ifc::IfcUntypedEntity::is_a() const {
|
||||
return Ifc2x3::Type::ToString(_type);
|
||||
std::string IfcParse::IfcUntypedEntity::is_a() const {
|
||||
return IfcSchema::Type::ToString(_type);
|
||||
}
|
||||
bool Ifc::IfcUntypedEntity::is_a(const std::string& s) const {
|
||||
bool IfcParse::IfcUntypedEntity::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(Ifc2x3::Type::FromString(S));
|
||||
return is(IfcSchema::Type::FromString(S));
|
||||
}
|
||||
Ifc2x3::Type::Enum Ifc::IfcUntypedEntity::type() const {
|
||||
IfcSchema::Type::Enum IfcParse::IfcUntypedEntity::type() const {
|
||||
return _type;
|
||||
}
|
||||
unsigned int Ifc::IfcUntypedEntity::getArgumentCount() const {
|
||||
return Ifc2x3::Type::GetAttributeCount(_type);
|
||||
unsigned int IfcParse::IfcUntypedEntity::getArgumentCount() const {
|
||||
return IfcSchema::Type::GetAttributeCount(_type);
|
||||
}
|
||||
IfcUtil::ArgumentType Ifc::IfcUntypedEntity::getArgumentType(unsigned int i) const {
|
||||
return Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
IfcUtil::ArgumentType IfcParse::IfcUntypedEntity::getArgumentType(unsigned int i) const {
|
||||
return IfcSchema::Type::GetAttributeType(_type,i);
|
||||
}
|
||||
ArgumentPtr Ifc::IfcUntypedEntity::getArgument(unsigned int i) const {
|
||||
ArgumentPtr IfcParse::IfcUntypedEntity::getArgument(unsigned int i) const {
|
||||
return entity->getArgument(i);
|
||||
}
|
||||
const char* Ifc::IfcUntypedEntity::getArgumentName(unsigned int i) const {
|
||||
return Ifc2x3::Type::GetAttributeName(_type,i).c_str();
|
||||
const char* IfcParse::IfcUntypedEntity::getArgumentName(unsigned int i) const {
|
||||
return IfcSchema::Type::GetAttributeName(_type,i).c_str();
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::invalid_argument(unsigned int i, const std::string& t) {
|
||||
const std::string arg_name = Ifc2x3::Type::GetAttributeName(_type,i);
|
||||
void IfcParse::IfcUntypedEntity::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 Ifc::IfcUntypedEntity::setArgument(unsigned int i) {
|
||||
bool is_optional = Ifc2x3::Type::GetAttributeOptional(_type, i);
|
||||
void IfcParse::IfcUntypedEntity::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 Ifc::IfcUntypedEntity::setArgument(unsigned int i, int v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
void IfcParse::IfcUntypedEntity::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, (bool) v);
|
||||
} else invalid_argument(i,"INT");
|
||||
writable_entity()->setArgument(i, v == 1);
|
||||
} else invalid_argument(i,"INT");
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::setArgument(unsigned int i, bool v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
void IfcParse::IfcUntypedEntity::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 Ifc::IfcUntypedEntity::setArgument(unsigned int i, double v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
void IfcParse::IfcUntypedEntity::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 Ifc::IfcUntypedEntity::setArgument(unsigned int i, const std::string& a) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
void IfcParse::IfcUntypedEntity::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 = Ifc2x3::Type::GetEnumerationIndex(Ifc2x3::Type::GetAttributeEnumerationClass(_type, i), a);
|
||||
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 Ifc::IfcUntypedEntity::setArgument(unsigned int i, const std::vector<int>& v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
void IfcParse::IfcUntypedEntity::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 Ifc::IfcUntypedEntity::setArgument(unsigned int i, const std::vector<double>& v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
void IfcParse::IfcUntypedEntity::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 Ifc::IfcUntypedEntity::setArgument(unsigned int i, const std::vector<std::string>& v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
void IfcParse::IfcUntypedEntity::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 Ifc::IfcUntypedEntity::setArgument(unsigned int i, Ifc::IfcUntypedEntity* v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
void IfcParse::IfcUntypedEntity::setArgument(unsigned int i, IfcParse::IfcUntypedEntity* 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 Ifc::IfcUntypedEntity::setArgument(unsigned int i, IfcEntities v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
void IfcParse::IfcUntypedEntity::setArgument(unsigned int i, IfcEntities 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,ArgumentPtr> Ifc::IfcUntypedEntity::get_argument(unsigned i) {
|
||||
std::pair<IfcUtil::ArgumentType,ArgumentPtr> IfcParse::IfcUntypedEntity::get_argument(unsigned i) {
|
||||
return std::pair<IfcUtil::ArgumentType,ArgumentPtr>(getArgumentType(i),getArgument(i));
|
||||
}
|
||||
std::pair<IfcUtil::ArgumentType,ArgumentPtr> Ifc::IfcUntypedEntity::get_argument(const std::string& a) {
|
||||
return get_argument(Ifc2x3::Type::GetAttributeIndex(_type,a));
|
||||
std::pair<IfcUtil::ArgumentType,ArgumentPtr> IfcParse::IfcUntypedEntity::get_argument(const std::string& a) {
|
||||
return get_argument(IfcSchema::Type::GetAttributeIndex(_type,a));
|
||||
}
|
||||
unsigned Ifc::IfcUntypedEntity::getArgumentIndex(const std::string& a) const {
|
||||
return Ifc2x3::Type::GetAttributeIndex(_type,a);
|
||||
unsigned IfcParse::IfcUntypedEntity::getArgumentIndex(const std::string& a) const {
|
||||
return IfcSchema::Type::GetAttributeIndex(_type,a);
|
||||
}
|
||||
std::string Ifc::IfcUntypedEntity::toString() {
|
||||
std::string IfcParse::IfcUntypedEntity::toString() {
|
||||
return entity->toString(false);
|
||||
}
|
||||
bool Ifc::IfcUntypedEntity::is_valid() {
|
||||
bool IfcParse::IfcUntypedEntity::is_valid() {
|
||||
const unsigned arg_count = getArgumentCount();
|
||||
bool valid = true;
|
||||
std::ostringstream oss;
|
||||
@@ -149,7 +154,7 @@ bool Ifc::IfcUntypedEntity::is_valid() {
|
||||
const Argument& arg = *getArgument(i);
|
||||
is_null = arg.isNull();
|
||||
} catch(IfcException) {}
|
||||
if (!Ifc2x3::Type::GetAttributeOptional(_type,i) && is_null) {
|
||||
if (!IfcSchema::Type::GetAttributeOptional(_type,i) && is_null) {
|
||||
if (!valid) {
|
||||
oss << ", ";
|
||||
}
|
||||
|
||||
@@ -3,22 +3,22 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "IfcUtil.h"
|
||||
#include "IfcWrite.h"
|
||||
#include "IfcWritableEntity.h"
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcWrite.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
|
||||
namespace Ifc {
|
||||
namespace IfcParse {
|
||||
|
||||
class IfcUntypedEntity : public IfcUtil::IfcBaseEntity {
|
||||
private:
|
||||
Ifc2x3::Type::Enum _type;
|
||||
IfcSchema::Type::Enum _type;
|
||||
IfcWrite::IfcWritableEntity* writable_entity();
|
||||
void invalid_argument(unsigned int i, const std::string& t);
|
||||
public:
|
||||
IfcUntypedEntity(const std::string& s);
|
||||
IfcUntypedEntity(IfcAbstractEntity* e);
|
||||
bool is(Ifc2x3::Type::Enum v) const;
|
||||
Ifc2x3::Type::Enum type() const;
|
||||
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 getArgumentCount() const;
|
||||
|
||||
@@ -34,14 +34,14 @@ IfcEntityList::it IfcEntityList::end() { return ls.end(); }
|
||||
IfcUtil::IfcSchemaEntity IfcEntityList::operator[] (int i) {
|
||||
return ls[i];
|
||||
}
|
||||
IfcEntities IfcEntityList::getInverse(Ifc2x3::Type::Enum c) {
|
||||
IfcEntities IfcEntityList::getInverse(IfcSchema::Type::Enum c) {
|
||||
IfcEntities l = IfcEntities(new IfcEntityList());
|
||||
for( it i = begin(); i != end(); ++i ) {
|
||||
l->push((*i)->entity->getInverse(c));
|
||||
}
|
||||
return l;
|
||||
}
|
||||
IfcEntities IfcEntityList::getInverse(Ifc2x3::Type::Enum c, int ar, const std::string& a) {
|
||||
IfcEntities IfcEntityList::getInverse(IfcSchema::Type::Enum c, int ar, const std::string& a) {
|
||||
IfcEntities l = IfcEntities(new IfcEntityList());
|
||||
for( it i = begin(); i != end(); ++i ) {
|
||||
l->push((*i)->entity->getInverse(c,ar,a));
|
||||
@@ -49,16 +49,16 @@ IfcEntities IfcEntityList::getInverse(Ifc2x3::Type::Enum c, int ar, const std::s
|
||||
return l;
|
||||
}
|
||||
|
||||
bool IfcUtil::IfcEntitySelect::is(Ifc2x3::Type::Enum v) const { return entity->is(v); }
|
||||
Ifc2x3::Type::Enum IfcUtil::IfcEntitySelect::type() const { return entity->type(); }
|
||||
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(IfcSchemaEntity b) { entity = b->entity; }
|
||||
IfcUtil::IfcEntitySelect::IfcEntitySelect(IfcAbstractEntityPtr e) { entity = e; }
|
||||
bool IfcUtil::IfcEntitySelect::isSimpleType() { return false; }
|
||||
IfcUtil::IfcEntitySelect::~IfcEntitySelect() { delete entity; }
|
||||
|
||||
bool IfcUtil::IfcArgumentSelect::is(Ifc2x3::Type::Enum v) const { return _type == v; }
|
||||
Ifc2x3::Type::Enum IfcUtil::IfcArgumentSelect::type() const { return _type; }
|
||||
IfcUtil::IfcArgumentSelect::IfcArgumentSelect(Ifc2x3::Type::Enum t, ArgumentPtr a) { _type = t; arg = a; }
|
||||
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, ArgumentPtr a) { _type = t; arg = a; }
|
||||
ArgumentPtr IfcUtil::IfcArgumentSelect::wrappedValue() { return arg; }
|
||||
bool IfcUtil::IfcArgumentSelect::isSimpleType() { return true; }
|
||||
IfcUtil::IfcArgumentSelect::~IfcArgumentSelect() { delete arg; }
|
||||
@@ -83,6 +83,11 @@ void Logger::Status(const std::string& message, bool new_line) {
|
||||
else (*log1) << std::flush;
|
||||
}
|
||||
}
|
||||
void Logger::ProgressBar(int progress) {
|
||||
if ( log1 ) {
|
||||
Status("\r[" + std::string(progress,'#') + std::string(50 - progress,' ') + "]", false);
|
||||
}
|
||||
}
|
||||
std::string Logger::GetLog() {
|
||||
return log_stream.str();
|
||||
}
|
||||
|
||||
+40
-109
@@ -23,14 +23,14 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "../ifcparse/SharedPointer.h"
|
||||
#include "../ifcparse/Ifc2x3enum.h"
|
||||
#include "../ifcparse/ArgumentType.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
|
||||
#ifdef USE_IFC4
|
||||
#include "../ifcparse/Ifc4enum.h"
|
||||
#else
|
||||
#include "../ifcparse/Ifc2x3enum.h"
|
||||
#endif
|
||||
|
||||
class IfcAbstractEntity;
|
||||
//typedef SHARED_PTR<IfcAbstractEntity> IfcAbstractEntityPtr;
|
||||
@@ -52,102 +52,18 @@ inline T* reinterpret_pointer_cast(F* from) {
|
||||
}
|
||||
|
||||
namespace IfcUtil {
|
||||
enum ArgumentType {
|
||||
Argument_INT, Argument_BOOL, Argument_DOUBLE, Argument_STRING, Argument_VECTOR_INT, Argument_VECTOR_DOUBLE, Argument_VECTOR_STRING, Argument_ENTITY, Argument_ENTITY_LIST, Argument_ENTITY_LIST_LIST, Argument_ENUMERATION, Argument_UNKNOWN
|
||||
};
|
||||
}
|
||||
|
||||
class IfcEnumerationDescriptor {
|
||||
private:
|
||||
Ifc2x3::Type::Enum type;
|
||||
std::vector<std::string> values;
|
||||
public:
|
||||
IfcEnumerationDescriptor(Ifc2x3::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;
|
||||
}
|
||||
Ifc2x3::Type::Enum getType() {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
class IfcEntityDescriptor {
|
||||
public:
|
||||
class IfcArgumentDescriptor
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
bool optional;
|
||||
ArgumentType argument_type;
|
||||
Ifc2x3::Type::Enum data_type;
|
||||
IfcArgumentDescriptor(const std::string& name, bool optional, ArgumentType argument_type, Ifc2x3::Type::Enum data_type)
|
||||
: name(name), optional(optional), argument_type(argument_type), data_type(data_type) {}
|
||||
};
|
||||
private:
|
||||
Ifc2x3::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(Ifc2x3::Type::Enum type, IfcEntityDescriptor* parent)
|
||||
: type(type), parent(parent) {}
|
||||
void add(const std::string& name, bool optional, ArgumentType argument_type, Ifc2x3::Type::Enum data_type = Ifc2x3::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;
|
||||
}
|
||||
Ifc2x3::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 " + Ifc2x3::Type::ToString(type));
|
||||
}
|
||||
};
|
||||
namespace IfcUtil {
|
||||
|
||||
class IfcBaseClass {
|
||||
public:
|
||||
IfcAbstractEntityPtr entity;
|
||||
virtual bool is(Ifc2x3::Type::Enum v) const = 0;
|
||||
virtual Ifc2x3::Type::Enum type() const = 0;
|
||||
virtual bool is(IfcSchema::Type::Enum v) const = 0;
|
||||
virtual IfcSchema::Type::Enum type() const = 0;
|
||||
};
|
||||
|
||||
class IfcBaseEntity : public IfcBaseClass {
|
||||
@@ -163,18 +79,27 @@ typedef IfcBaseClass* IfcSchemaEntity;
|
||||
|
||||
}
|
||||
|
||||
template <class T>
|
||||
class IfcTemplatedEntityList;
|
||||
|
||||
class IfcEntityList {
|
||||
std::vector<IfcUtil::IfcSchemaEntity> ls;
|
||||
public:
|
||||
typedef std::vector<IfcUtil::IfcSchemaEntity>::const_iterator it;
|
||||
IfcEntities getInverse(Ifc2x3::Type::Enum c = Ifc2x3::Type::ALL);
|
||||
IfcEntities getInverse(Ifc2x3::Type::Enum c, int i, const std::string& a);
|
||||
IfcEntities getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL);
|
||||
IfcEntities getInverse(IfcSchema::Type::Enum c, int i, const std::string& a);
|
||||
void push(IfcUtil::IfcSchemaEntity l);
|
||||
void push(IfcEntities l);
|
||||
it begin();
|
||||
it end();
|
||||
IfcUtil::IfcSchemaEntity operator[] (int i);
|
||||
int Size() const;
|
||||
template <class U>
|
||||
typename U::list as() {
|
||||
typename U::list r(new IfcTemplatedEntityList<U>());
|
||||
for ( it i = begin(); i != end(); ++ i ) if ((*i)->is(U::Class())) r->push((U*)*i);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
@@ -186,13 +111,18 @@ public:
|
||||
inline void push(SHARED_PTR< IfcTemplatedEntityList<T> > t) { for ( typename T::it it = t->begin(); it != t->end(); ++it ) push(*it); }
|
||||
inline it begin() { return ls.begin(); }
|
||||
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;
|
||||
}
|
||||
template <class U>
|
||||
typename U::list as() {
|
||||
typename U::list r(new IfcTemplatedEntityList<U>());
|
||||
for ( it i = begin(); i != end(); ++ i ) if ((*i)->is(U::Class())) r->push(*i);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
namespace IfcUtil {
|
||||
@@ -209,20 +139,20 @@ namespace IfcUtil {
|
||||
IfcEntitySelect(IfcSchemaEntity b);
|
||||
IfcEntitySelect(IfcAbstractEntityPtr e);
|
||||
~IfcEntitySelect();
|
||||
bool is(Ifc2x3::Type::Enum v) const;
|
||||
Ifc2x3::Type::Enum type() const;
|
||||
bool is(IfcSchema::Type::Enum v) const;
|
||||
IfcSchema::Type::Enum type() const;
|
||||
bool isSimpleType();
|
||||
};
|
||||
class IfcArgumentSelect : public IfcAbstractSelect {
|
||||
Ifc2x3::Type::Enum _type;
|
||||
IfcSchema::Type::Enum _type;
|
||||
ArgumentPtr arg;
|
||||
public:
|
||||
typedef IfcArgumentSelect* ptr;
|
||||
IfcArgumentSelect(Ifc2x3::Type::Enum t, ArgumentPtr a);
|
||||
IfcArgumentSelect(IfcSchema::Type::Enum t, ArgumentPtr a);
|
||||
~IfcArgumentSelect();
|
||||
ArgumentPtr wrappedValue();
|
||||
bool is(Ifc2x3::Type::Enum v) const;
|
||||
Ifc2x3::Type::Enum type() const;
|
||||
bool is(IfcSchema::Type::Enum v) const;
|
||||
IfcSchema::Type::Enum type() const;
|
||||
bool isSimpleType();
|
||||
};
|
||||
}
|
||||
@@ -255,14 +185,14 @@ public:
|
||||
class IfcAbstractEntity {
|
||||
public:
|
||||
IfcParse::IfcFile* file;
|
||||
virtual IfcEntities getInverse(Ifc2x3::Type::Enum c = Ifc2x3::Type::ALL) = 0;
|
||||
virtual IfcEntities getInverse(Ifc2x3::Type::Enum c, int i, const std::string& a) = 0;
|
||||
virtual IfcEntities getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL) = 0;
|
||||
virtual IfcEntities getInverse(IfcSchema::Type::Enum c, int i, const std::string& a) = 0;
|
||||
virtual std::string datatype() = 0;
|
||||
virtual ArgumentPtr getArgument (unsigned int i) = 0;
|
||||
virtual unsigned int getArgumentCount() = 0;
|
||||
virtual ~IfcAbstractEntity() {};
|
||||
virtual Ifc2x3::Type::Enum type() const = 0;
|
||||
virtual bool is(Ifc2x3::Type::Enum v) const = 0;
|
||||
virtual IfcSchema::Type::Enum type() const = 0;
|
||||
virtual bool is(IfcSchema::Type::Enum v) const = 0;
|
||||
virtual std::string toString(bool upper=false) = 0;
|
||||
virtual unsigned int id() = 0;
|
||||
virtual bool isWritable() = 0;
|
||||
@@ -286,6 +216,7 @@ public:
|
||||
/// Log a message to the output stream
|
||||
static void Message(Severity type, const std::string& message, const IfcAbstractEntityPtr entity=0);
|
||||
static void Status(const std::string& message, bool new_line=true);
|
||||
static void ProgressBar(int progress);
|
||||
static std::string GetLog();
|
||||
};
|
||||
|
||||
|
||||
@@ -40,25 +40,29 @@ namespace IfcWrite {
|
||||
private:
|
||||
std::map<int,bool> writemask;
|
||||
std::map<int,ArgumentPtr> args;
|
||||
Ifc2x3::Type::Enum _type;
|
||||
IfcSchema::Type::Enum _type;
|
||||
int* _id;
|
||||
bool arg_writable(int i);
|
||||
void arg_writable(int i, bool b);
|
||||
template <typename T> void _setArgument(int i, const T&);
|
||||
public:
|
||||
IfcWritableEntity(Ifc2x3::Type::Enum t);
|
||||
IfcWritableEntity(IfcSchema::Type::Enum t);
|
||||
~IfcWritableEntity();
|
||||
int setId(int i=-1);
|
||||
IfcWritableEntity(IfcAbstractEntity* e);
|
||||
IfcEntities getInverse(Ifc2x3::Type::Enum c = Ifc2x3::Type::ALL);
|
||||
IfcEntities getInverse(Ifc2x3::Type::Enum c, int i, const std::string& a);
|
||||
IfcEntities getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL);
|
||||
IfcEntities getInverse(IfcSchema::Type::Enum c, int i, const std::string& a);
|
||||
std::string datatype();
|
||||
ArgumentPtr getArgument (unsigned int i);
|
||||
unsigned int getArgumentCount();
|
||||
Ifc2x3::Type::Enum type() const;
|
||||
bool is(Ifc2x3::Type::Enum v) const;
|
||||
IfcSchema::Type::Enum type() const;
|
||||
bool is(IfcSchema::Type::Enum v) const;
|
||||
std::string toString(bool upper=false);
|
||||
unsigned int id();
|
||||
bool isWritable();
|
||||
void setArgument(int i);
|
||||
void setArgumentDerived(int i);
|
||||
void setArgument(int i,bool v);
|
||||
void setArgument(int i,int v);
|
||||
void setArgument(int i,int v, const char* c);
|
||||
void setArgument(int i,const std::string& v);
|
||||
|
||||
+187
-227
@@ -25,11 +25,14 @@
|
||||
|
||||
using namespace IfcWrite;
|
||||
|
||||
IfcWritableEntity::IfcWritableEntity(Ifc2x3::Type::Enum t) {
|
||||
IfcWritableEntity::IfcWritableEntity(IfcSchema::Type::Enum t) {
|
||||
_type = t;
|
||||
_id = 0;
|
||||
file = 0;
|
||||
}
|
||||
IfcWritableEntity::~IfcWritableEntity() {
|
||||
delete _id;
|
||||
}
|
||||
int IfcWritableEntity::setId(int i) {
|
||||
return *(_id = new int(i > 0 ? i : file->FreshId()));
|
||||
}
|
||||
@@ -46,19 +49,19 @@ IfcWritableEntity::IfcWritableEntity(IfcAbstractEntity* e)
|
||||
}
|
||||
}
|
||||
// TODO: Reove redundancy with IfcParse::Entity
|
||||
IfcEntities IfcWritableEntity::getInverse(Ifc2x3::Type::Enum c) {
|
||||
IfcEntities IfcWritableEntity::getInverse(IfcSchema::Type::Enum c) {
|
||||
IfcEntities l = IfcEntities(new IfcEntityList());
|
||||
int id = _id ? *_id : setId();
|
||||
IfcEntities all = file->EntitiesByReference(id);
|
||||
if ( ! all ) return l;
|
||||
for( IfcEntityList::it it = all->begin(); it != all->end();++ it ) {
|
||||
if ( c == Ifc2x3::Type::ALL || (*it)->is(c) ) {
|
||||
if ( c == IfcSchema::Type::ALL || (*it)->is(c) ) {
|
||||
l->push(*it);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
IfcEntities IfcWritableEntity::getInverse(Ifc2x3::Type::Enum c, int i, const std::string& a) {
|
||||
IfcEntities IfcWritableEntity::getInverse(IfcSchema::Type::Enum c, int i, const std::string& a) {
|
||||
IfcEntities l = IfcEntities(new IfcEntityList());
|
||||
IfcEntities all = getInverse(c);
|
||||
for( IfcEntityList::it it = all->begin(); it != all->end();++ it ) {
|
||||
@@ -70,11 +73,11 @@ IfcEntities IfcWritableEntity::getInverse(Ifc2x3::Type::Enum c, int i, const std
|
||||
return l;
|
||||
}
|
||||
|
||||
std::string IfcWritableEntity::datatype() { return Ifc2x3::Type::ToString(_type); }
|
||||
std::string IfcWritableEntity::datatype() { return IfcSchema::Type::ToString(_type); }
|
||||
ArgumentPtr IfcWritableEntity::getArgument (unsigned int i) { if ( i >= getArgumentCount() ) throw IfcParse::IfcException("Argument not set"); return args[i]; }
|
||||
unsigned int IfcWritableEntity::getArgumentCount() {return args.size(); }
|
||||
Ifc2x3::Type::Enum IfcWritableEntity::type() const { return _type; }
|
||||
bool IfcWritableEntity::is(Ifc2x3::Type::Enum v) const { return _type == v; }
|
||||
IfcSchema::Type::Enum IfcWritableEntity::type() const { return _type; }
|
||||
bool IfcWritableEntity::is(IfcSchema::Type::Enum v) const { return _type == v; }
|
||||
std::string IfcWritableEntity::toString(bool upper) {
|
||||
std::stringstream ss;
|
||||
std::string dt = datatype();
|
||||
@@ -91,7 +94,12 @@ std::string IfcWritableEntity::toString(bool upper) {
|
||||
ss << ")";
|
||||
return ss.str();
|
||||
}
|
||||
unsigned int IfcWritableEntity::id() { if ( !_id ) _id = new int(file->FreshId()); return *_id; }
|
||||
unsigned int IfcWritableEntity::id() {
|
||||
if ( !_id ) {
|
||||
_id = new int(file->FreshId());
|
||||
}
|
||||
return *_id;
|
||||
}
|
||||
bool IfcWritableEntity::isWritable() { return true; }
|
||||
bool IfcWritableEntity::arg_writable(int i) {
|
||||
std::map<int,bool>::const_iterator it = writemask.find(i);
|
||||
@@ -101,254 +109,201 @@ bool IfcWritableEntity::arg_writable(int i) {
|
||||
void IfcWritableEntity::arg_writable(int i, bool b) {
|
||||
writemask[i] = b;
|
||||
}
|
||||
void IfcWritableEntity::setArgument(int i) {
|
||||
|
||||
template <typename T> void IfcWritableEntity::_setArgument(int i, const T& t) {
|
||||
if ( arg_writable(i) ) delete args[i];
|
||||
args[i] = new IfcWriteNullArgument();
|
||||
IfcWriteArgument* arg = new IfcWriteArgument(this);
|
||||
args[i] = arg;
|
||||
arg->set(t);
|
||||
arg_writable(i,true);
|
||||
}
|
||||
|
||||
void IfcWritableEntity::setArgument(int i) {
|
||||
_setArgument(i, boost::none);
|
||||
}
|
||||
void IfcWritableEntity::setArgumentDerived(int i) {
|
||||
_setArgument(i, IfcWriteArgument::Derived());
|
||||
}
|
||||
void IfcWritableEntity::setArgument(int i,int v) {
|
||||
if ( arg_writable(i) ) delete args[i];
|
||||
args[i] = new IfcWriteIntegralArgument(v);
|
||||
arg_writable(i,true);
|
||||
_setArgument(i, v);
|
||||
}
|
||||
void IfcWritableEntity::setArgument(int i,bool v) {
|
||||
_setArgument(i, v);
|
||||
}
|
||||
void IfcWritableEntity::setArgument(int i,int v, const char* c){
|
||||
if ( arg_writable(i) ) delete args[i];
|
||||
args[i] = new IfcWriteEnumerationArgument(v,c);
|
||||
arg_writable(i,true);
|
||||
_setArgument(i, IfcWriteArgument::EnumerationReference(v, c));
|
||||
}
|
||||
void IfcWritableEntity::setArgument(int i,const std::string& v){
|
||||
if ( arg_writable(i) ) delete args[i];
|
||||
args[i] = new IfcWriteIntegralArgument(v);
|
||||
arg_writable(i,true);
|
||||
_setArgument(i, v);
|
||||
}
|
||||
void IfcWritableEntity::setArgument(int i,double v){
|
||||
if ( arg_writable(i) ) delete args[i];
|
||||
args[i] = new IfcWriteIntegralArgument(v);
|
||||
arg_writable(i,true);
|
||||
_setArgument(i, v);
|
||||
}
|
||||
void IfcWritableEntity::setArgument(int i,IfcUtil::IfcSchemaEntity v){
|
||||
if ( arg_writable(i) ) delete args[i];
|
||||
if ( v ) args[i] = new IfcWriteIntegralArgument(v);
|
||||
else args[i] = new IfcWriteNullArgument();
|
||||
arg_writable(i,true);
|
||||
if ( v ) {
|
||||
_setArgument(i, v);
|
||||
} else {
|
||||
_setArgument(i, boost::none);
|
||||
}
|
||||
}
|
||||
void IfcWritableEntity::setArgument(int i,IfcEntities v){
|
||||
if ( arg_writable(i) ) delete args[i];
|
||||
if ( v.get() ) args[i] = new IfcWriteEntityListArgument(v);
|
||||
else args[i] = new IfcWriteNullArgument();
|
||||
arg_writable(i,true);
|
||||
if ( v.get() ) {
|
||||
_setArgument(i, v);
|
||||
} else {
|
||||
_setArgument(i, boost::none);
|
||||
}
|
||||
}
|
||||
void IfcWritableEntity::setArgument(int i,const std::vector<double>& v){
|
||||
if ( arg_writable(i) ) delete args[i];
|
||||
args[i] = new IfcWriteIntegralArgument(v);
|
||||
arg_writable(i,true);
|
||||
_setArgument(i, v);
|
||||
}
|
||||
void IfcWritableEntity::setArgument(int i,const std::vector<std::string>& v){
|
||||
if ( arg_writable(i) ) delete args[i];
|
||||
args[i] = new IfcWriteIntegralArgument(v);
|
||||
arg_writable(i,true);
|
||||
_setArgument(i, v);
|
||||
}
|
||||
void IfcWritableEntity::setArgument(int i,const std::vector<int>& v){
|
||||
if ( arg_writable(i) ) delete args[i];
|
||||
args[i] = new IfcWriteIntegralArgument(v);
|
||||
arg_writable(i,true);
|
||||
_setArgument(i, v);
|
||||
}
|
||||
|
||||
IfcWriteNullArgument::operator int() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator bool() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator double() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator std::string() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator std::vector<double>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator std::vector<int>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator std::vector<std::string>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator IfcUtil::IfcSchemaEntity() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator IfcEntities() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
bool IfcWriteNullArgument::isNull() const { return true; }
|
||||
ArgumentPtr IfcWriteNullArgument::operator [] (unsigned int i) const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
std::string IfcWriteNullArgument::toString(bool upper) const { return "$"; }
|
||||
unsigned int IfcWriteNullArgument::Size() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
class SizeVisitor : public boost::static_visitor<int> {
|
||||
public:
|
||||
int operator()(const boost::none_t& i) const { return -1; }
|
||||
int operator()(const IfcWriteArgument::Derived& i) const { return -1; }
|
||||
int operator()(const int& i) const { return -1; }
|
||||
int operator()(const bool& i) const { return -1; }
|
||||
int operator()(const double& i) const { return -1; }
|
||||
int operator()(const std::string& i) const { return i.size(); }
|
||||
int operator()(const std::vector<int>& i) const { return i.size(); }
|
||||
int operator()(const std::vector<double>& i) const { return i.size(); }
|
||||
int operator()(const std::vector<std::string>& i) const { return i.size(); }
|
||||
int operator()(const IfcWriteArgument::EnumerationReference& i) const { return -1; }
|
||||
int operator()(const IfcUtil::IfcSchemaEntity& i) const { return -1; }
|
||||
int operator()(const IfcEntities& i) const { return i->Size(); }
|
||||
};
|
||||
|
||||
IfcWriteEntityListArgument::IfcWriteEntityListArgument(const IfcEntities& v) { value = v; }
|
||||
IfcWriteEntityListArgument::operator int() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator bool() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator double() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator std::string() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator std::vector<double>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator std::vector<int>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator std::vector<std::string>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator IfcUtil::IfcSchemaEntity() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator IfcEntities() const { return value; }
|
||||
bool IfcWriteEntityListArgument::isNull() const { return false; }
|
||||
unsigned int IfcWriteEntityListArgument::Size() const { return value->Size(); }
|
||||
ArgumentPtr IfcWriteEntityListArgument::operator [] (unsigned int i) const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
std::string IfcWriteEntityListArgument::toString(bool upper) const {
|
||||
std::ostringstream ss;
|
||||
ss << "(";
|
||||
for ( IfcEntityList::it it = value->begin(); it != value->end(); ++ it ) {
|
||||
if ( it != value->begin() ) ss << ",";
|
||||
IfcAbstractEntity* e = (*it)->entity;
|
||||
if ( Ifc2x3::Type::IsSimple(e->type()) ) {
|
||||
ss << e->toString(upper);
|
||||
class StringBuilderVisitor : public boost::static_visitor<void> {
|
||||
private:
|
||||
std::ostringstream& data;
|
||||
template <typename T> void serialize(const std::vector<T>& i) {
|
||||
data << "(";
|
||||
for (typename std::vector<T>::const_iterator it = i.begin(); it != i.end(); ++it) {
|
||||
if (it != i.begin()) data << ",";
|
||||
data << *it;
|
||||
}
|
||||
data << ")";
|
||||
}
|
||||
// The REAL token definition from the IFC SPF standard does not necessarily match
|
||||
// the output of the C++ ostream formatting operation.
|
||||
// REAL = [ SIGN ] DIGIT { DIGIT } "." { DIGIT } [ "E" [ SIGN ] DIGIT { DIGIT } ] .
|
||||
std::string format_double(const double& d) {
|
||||
std::ostringstream oss;
|
||||
oss << d;
|
||||
const std::string str = oss.str();
|
||||
oss.str("");
|
||||
std::string::size_type e = str.find('e');
|
||||
if (e == std::string::npos) {
|
||||
e = str.find('E');
|
||||
}
|
||||
const std::string mantissa = str.substr(0,e);
|
||||
oss << mantissa;
|
||||
if (mantissa.find('.') == std::string::npos) {
|
||||
oss << ".";
|
||||
}
|
||||
if (e != std::string::npos) {
|
||||
oss << "E";
|
||||
oss << str.substr(e+1);
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
void serialize_double(const std::vector<double>& i) {
|
||||
data << "(";
|
||||
for (std::vector<double>::const_iterator it = i.begin(); it != i.end(); ++it) {
|
||||
if (it != i.begin()) data << ",";
|
||||
data << format_double(*it);
|
||||
}
|
||||
data << ")";
|
||||
}
|
||||
bool upper;
|
||||
public:
|
||||
StringBuilderVisitor(std::ostringstream& stream, bool upper = false)
|
||||
: data(stream), upper(upper) {}
|
||||
void operator()(const boost::none_t& i) { data << "$"; }
|
||||
void operator()(const IfcWriteArgument::Derived& i) { data << "*"; }
|
||||
void operator()(const int& i) { data << i; }
|
||||
void operator()(const bool& i) { data << (i ? ".T." : ".F."); }
|
||||
void operator()(const double& i) { data << format_double(i); }
|
||||
void operator()(const std::string& i) {
|
||||
std::string s = i;
|
||||
if (upper) s = IfcCharacterEncoder(s);
|
||||
data << s;
|
||||
}
|
||||
void operator()(const std::vector<int>& i) { serialize(i); }
|
||||
void operator()(const std::vector<double>& i) { serialize_double(i); }
|
||||
void operator()(const std::vector<std::string>& i) { serialize(i); }
|
||||
void operator()(const IfcWriteArgument::EnumerationReference& i) {
|
||||
data << "." << i.enumeration_value << ".";
|
||||
}
|
||||
void operator()(const IfcUtil::IfcSchemaEntity& i) {
|
||||
IfcAbstractEntity* e = i->entity;
|
||||
if ( IfcSchema::Type::IsSimple(e->type()) ) {
|
||||
data << e->toString(upper);
|
||||
} else {
|
||||
if (e->file) {
|
||||
ss << "#" << e->id();
|
||||
data << "#" << e->id();
|
||||
} else {
|
||||
ss << "#?";
|
||||
data << "#?";
|
||||
}
|
||||
}
|
||||
}
|
||||
ss << ")";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
IfcWriteEnumerationArgument::IfcWriteEnumerationArgument(int v, const char* c) {data=v; enumeration_value = c;}
|
||||
IfcWriteEnumerationArgument::operator int() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator bool() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator double() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator std::string() const { return std::string(enumeration_value); }
|
||||
IfcWriteEnumerationArgument::operator std::vector<double>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator std::vector<int>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator std::vector<std::string>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator IfcUtil::IfcSchemaEntity() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator IfcEntities() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
bool IfcWriteEnumerationArgument::isNull() const { return false; }
|
||||
ArgumentPtr IfcWriteEnumerationArgument::operator [] (unsigned int i) const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
std::string IfcWriteEnumerationArgument::toString(bool upper) const { return std::string(".") + enumeration_value + '.';}
|
||||
unsigned int IfcWriteEnumerationArgument::Size() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
|
||||
IfcWriteIntegralArgument::IfcWriteIntegralArgument(int v) {data=new int(v); type = Argument_INT;}
|
||||
IfcWriteIntegralArgument::IfcWriteIntegralArgument(bool v) {data=new bool(v); type = Argument_BOOL;}
|
||||
IfcWriteIntegralArgument::IfcWriteIntegralArgument(double v) {data=new double(v); type = Argument_DOUBLE;}
|
||||
IfcWriteIntegralArgument::IfcWriteIntegralArgument(const std::string& v) {data=new std::string(v); type = Argument_STRING;}
|
||||
IfcWriteIntegralArgument::IfcWriteIntegralArgument(const std::vector<int> v) {data=new std::vector<int>(v); type = Argument_VECTOR_INT;}
|
||||
IfcWriteIntegralArgument::IfcWriteIntegralArgument(const std::vector<double> v) {data=new std::vector<double>(v); type = Argument_VECTOR_DOUBLE;}
|
||||
IfcWriteIntegralArgument::IfcWriteIntegralArgument(const std::vector<std::string> v) {data=new std::vector<std::string>(v); type = Argument_VECTOR_STRING;}
|
||||
IfcWriteIntegralArgument::IfcWriteIntegralArgument(IfcUtil::IfcSchemaEntity v) {data=v; type = Argument_ENTITY;}
|
||||
IfcWriteIntegralArgument::~IfcWriteIntegralArgument() {
|
||||
switch ( type ) {
|
||||
case Argument_INT:
|
||||
delete (int*) data;
|
||||
break;
|
||||
case Argument_BOOL:
|
||||
delete (bool*) data;
|
||||
break;
|
||||
case Argument_DOUBLE:
|
||||
delete (double*) data;
|
||||
break;
|
||||
case Argument_STRING:
|
||||
delete (std::string*) data;
|
||||
break;
|
||||
case Argument_VECTOR_INT:
|
||||
delete (std::vector<int>*) data;
|
||||
break;
|
||||
case Argument_VECTOR_DOUBLE:
|
||||
delete (std::vector<double>*) data;
|
||||
break;
|
||||
case Argument_VECTOR_STRING:
|
||||
delete (std::vector<std::string>*) data;
|
||||
break;
|
||||
case Argument_ENTITY:
|
||||
break;
|
||||
void operator()(const IfcEntities& i) {
|
||||
data << "(";
|
||||
for (IfcEntityList::it it = i->begin(); it != i->end(); ++it) {
|
||||
if (it != i->begin()) data << ",";
|
||||
(*this)(*it);
|
||||
}
|
||||
data << ")";
|
||||
}
|
||||
operator std::string() { return data.str(); }
|
||||
};
|
||||
|
||||
IfcWriteArgument::operator int() const { return as<int>(); }
|
||||
IfcWriteArgument::operator bool() const { return as<bool>(); }
|
||||
IfcWriteArgument::operator double() const { return as<double>(); }
|
||||
IfcWriteArgument::operator std::string() const { return as<std::string>(); }
|
||||
IfcWriteArgument::operator std::vector<double>() const { return as<std::vector<double> >(); }
|
||||
IfcWriteArgument::operator std::vector<int>() const { return as<std::vector<int> >(); }
|
||||
IfcWriteArgument::operator std::vector<std::string>() const { return as<std::vector<std::string > >(); }
|
||||
IfcWriteArgument::operator IfcUtil::IfcSchemaEntity() const { return as<IfcUtil::IfcSchemaEntity>(); }
|
||||
IfcWriteArgument::operator IfcEntities() const { return as<IfcEntities>(); }
|
||||
bool IfcWriteArgument::isNull() const { return argumentType() == argument_type_null; }
|
||||
ArgumentPtr IfcWriteArgument::operator [] (unsigned int i) const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
std::string IfcWriteArgument::toString(bool upper) const {
|
||||
std::ostringstream str;
|
||||
StringBuilderVisitor v(str, upper);
|
||||
container.apply_visitor(v);
|
||||
return v;
|
||||
}
|
||||
IfcWriteIntegralArgument::operator int() const { if ( type != Argument_INT ) throw IfcParse::IfcException("Invalid cast"); return *(int*)data; }
|
||||
IfcWriteIntegralArgument::operator bool() const { if ( type != Argument_BOOL ) throw IfcParse::IfcException("Invalid cast"); return *(bool*)data; }
|
||||
IfcWriteIntegralArgument::operator double() const { if ( type != Argument_DOUBLE ) throw IfcParse::IfcException("Invalid cast"); return *(double*)data; }
|
||||
IfcWriteIntegralArgument::operator std::string() const { if ( type != Argument_STRING ) throw IfcParse::IfcException("Invalid cast"); return *(std::string*)data; }
|
||||
IfcWriteIntegralArgument::operator std::vector<double>() const { if ( type != Argument_VECTOR_DOUBLE ) throw IfcParse::IfcException("Invalid cast"); return *(std::vector<double>*)data; }
|
||||
IfcWriteIntegralArgument::operator std::vector<int>() const { if ( type != Argument_VECTOR_INT ) throw IfcParse::IfcException("Invalid cast"); return *(std::vector<int>*)data; }
|
||||
IfcWriteIntegralArgument::operator std::vector<std::string>() const { if ( type != Argument_VECTOR_STRING ) throw IfcParse::IfcException("Invalid cast"); return *(std::vector<std::string>*)data; }
|
||||
IfcWriteIntegralArgument::operator IfcUtil::IfcSchemaEntity() const { if ( type != Argument_ENTITY ) throw IfcParse::IfcException("Invalid cast"); return (IfcUtil::IfcSchemaEntity)data; }
|
||||
IfcWriteIntegralArgument::operator IfcEntities() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
bool IfcWriteIntegralArgument::isNull() const { return false; }
|
||||
unsigned int IfcWriteIntegralArgument::Size() const {
|
||||
switch ( type ) {
|
||||
case Argument_VECTOR_INT:
|
||||
return ((std::vector<int>*) data)->size();
|
||||
break;
|
||||
case Argument_VECTOR_DOUBLE:
|
||||
return ((std::vector<double>*) data)->size();
|
||||
break;
|
||||
case Argument_VECTOR_STRING:
|
||||
return ((std::vector<std::string>*) data)->size();
|
||||
break;
|
||||
default:
|
||||
unsigned int IfcWriteArgument::Size() const {
|
||||
SizeVisitor v;
|
||||
const int size = container.apply_visitor(v);
|
||||
if (size == -1) {
|
||||
throw IfcParse::IfcException("Invalid cast");
|
||||
break;
|
||||
} else {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
ArgumentPtr IfcWriteIntegralArgument::operator [] (unsigned int i) const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
std::string IfcWriteIntegralArgument::toString(bool upper) const {
|
||||
std::ostringstream ss;
|
||||
switch ( type ) {
|
||||
case Argument_INT:
|
||||
ss << *(int*)data;
|
||||
break;
|
||||
case Argument_BOOL:
|
||||
ss << ((*(bool*) data) ? ".T." : ".F.");
|
||||
break;
|
||||
case Argument_DOUBLE:
|
||||
ss << *(double*) data;
|
||||
break;
|
||||
case Argument_STRING: {
|
||||
std::string d = *(std::string*) data;
|
||||
if ( upper ) d = IfcCharacterEncoder(d);
|
||||
ss << d;
|
||||
break;
|
||||
} case Argument_VECTOR_INT:
|
||||
ss << "(";
|
||||
{const std::vector<int>& v = *(std::vector<int>*) data;
|
||||
for ( std::vector<int>::const_iterator it = v.begin(); it != v.end(); ++ it ) {
|
||||
if ( it != v.begin() ) ss << ",";
|
||||
ss << *it;
|
||||
}}
|
||||
ss << ")";
|
||||
break;
|
||||
case Argument_VECTOR_DOUBLE:
|
||||
ss << "(";
|
||||
{const std::vector<double>& v = *(std::vector<double>*) data;
|
||||
for ( std::vector<double>::const_iterator it = v.begin(); it != v.end(); ++ it ) {
|
||||
if ( it != v.begin() ) ss << ",";
|
||||
ss << *it;
|
||||
}}
|
||||
ss << ")";
|
||||
break;
|
||||
case Argument_VECTOR_STRING:
|
||||
ss << "(";
|
||||
{const std::vector<std::string>& v = *(std::vector<std::string>*) data;
|
||||
for ( std::vector<std::string>::const_iterator it = v.begin(); it != v.end(); ++ it ) {
|
||||
if ( it != v.begin() ) ss << ",";
|
||||
ss << '\'' << *it << '\'';
|
||||
}}
|
||||
ss << ")";
|
||||
break;
|
||||
case Argument_ENTITY:
|
||||
{IfcAbstractEntity* e = ((IfcUtil::IfcSchemaEntity)data)->entity;
|
||||
if ( Ifc2x3::Type::IsSimple(e->type()) ) {
|
||||
ss << e->toString(upper);
|
||||
} else {
|
||||
if (e->file) {
|
||||
ss << "#" << e->id();
|
||||
} else {
|
||||
ss << "#?";
|
||||
}
|
||||
}}
|
||||
break;
|
||||
default: throw IfcParse::IfcException("Invalid cast");
|
||||
}
|
||||
return ss.str();
|
||||
IfcWriteArgument::argument_type IfcWriteArgument::argumentType() const {
|
||||
return static_cast<argument_type>(container.which());
|
||||
}
|
||||
|
||||
IfcEntities IfcSelectHelperEntity::getInverse(Ifc2x3::Type::Enum,int,const std::string &) {throw IfcParse::IfcException("Invalid cast");}
|
||||
IfcEntities IfcSelectHelperEntity::getInverse(Ifc2x3::Type::Enum) {throw IfcParse::IfcException("Invalid cast");}
|
||||
std::string IfcSelectHelperEntity::datatype() { return Ifc2x3::Type::ToString(_type); }
|
||||
IfcEntities IfcSelectHelperEntity::getInverse(IfcSchema::Type::Enum,int,const std::string &) {throw IfcParse::IfcException("Invalid cast");}
|
||||
IfcEntities IfcSelectHelperEntity::getInverse(IfcSchema::Type::Enum) {throw IfcParse::IfcException("Invalid cast");}
|
||||
std::string IfcSelectHelperEntity::datatype() { return IfcSchema::Type::ToString(_type); }
|
||||
ArgumentPtr IfcSelectHelperEntity::getArgument(unsigned int i) {
|
||||
if ( i != 0 ) throw IfcParse::IfcException("Invalid cast");
|
||||
return arg;
|
||||
}
|
||||
unsigned int IfcSelectHelperEntity::getArgumentCount() { return 1; }
|
||||
Ifc2x3::Type::Enum IfcSelectHelperEntity::type() const { return _type; }
|
||||
bool IfcSelectHelperEntity::is(Ifc2x3::Type::Enum t) const { return _type == t; }
|
||||
IfcSchema::Type::Enum IfcSelectHelperEntity::type() const { return _type; }
|
||||
bool IfcSelectHelperEntity::is(IfcSchema::Type::Enum t) const { return _type == t; }
|
||||
std::string IfcSelectHelperEntity::toString(bool upper) {
|
||||
std::stringstream ss;
|
||||
std::string dt = datatype();
|
||||
@@ -361,28 +316,33 @@ std::string IfcSelectHelperEntity::toString(bool upper) {
|
||||
unsigned int IfcSelectHelperEntity::id() { throw IfcParse::IfcException("Invalid cast"); }
|
||||
bool IfcSelectHelperEntity::isWritable() { throw IfcParse::IfcException("Invalid cast"); }
|
||||
|
||||
IfcSelectHelper::IfcSelectHelper(const std::string& v, Ifc2x3::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteIntegralArgument(v);
|
||||
IfcSelectHelper::IfcSelectHelper(const std::string& v, IfcSchema::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteArgument(0);
|
||||
a->set(v);
|
||||
this->entity = new IfcSelectHelperEntity(t,a);
|
||||
}
|
||||
IfcSelectHelper::IfcSelectHelper(const char* const v, Ifc2x3::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteIntegralArgument(std::string(v));
|
||||
IfcSelectHelper::IfcSelectHelper(const char* const v, IfcSchema::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteArgument(0);
|
||||
a->set<std::string>(v);
|
||||
this->entity = new IfcSelectHelperEntity(t,a);
|
||||
}
|
||||
IfcSelectHelper::IfcSelectHelper(int v, Ifc2x3::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteIntegralArgument(v);
|
||||
IfcSelectHelper::IfcSelectHelper(int v, IfcSchema::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteArgument(0);
|
||||
a->set(v);
|
||||
this->entity = new IfcSelectHelperEntity(t,a);
|
||||
}
|
||||
IfcSelectHelper::IfcSelectHelper(double v, Ifc2x3::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteIntegralArgument(v);
|
||||
IfcSelectHelper::IfcSelectHelper(double v, IfcSchema::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteArgument(0);
|
||||
a->set(v);
|
||||
this->entity = new IfcSelectHelperEntity(t,a);
|
||||
}
|
||||
IfcSelectHelper::IfcSelectHelper(bool v, Ifc2x3::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteIntegralArgument(v);
|
||||
IfcSelectHelper::IfcSelectHelper(bool v, IfcSchema::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteArgument(0);
|
||||
a->set(v);
|
||||
this->entity = new IfcSelectHelperEntity(t,a);
|
||||
}
|
||||
bool IfcSelectHelper::is(Ifc2x3::Type::Enum t) const { return entity->is(t); }
|
||||
Ifc2x3::Type::Enum IfcSelectHelper::type() const { return entity->type(); }
|
||||
bool IfcSelectHelper::is(IfcSchema::Type::Enum t) const { return entity->is(t); }
|
||||
IfcSchema::Type::Enum IfcSelectHelper::type() const { return entity->type(); }
|
||||
|
||||
EntityBuffer* EntityBuffer::i = 0;
|
||||
EntityBuffer* EntityBuffer::instance() {
|
||||
|
||||
+93
-103
@@ -28,69 +28,92 @@
|
||||
#ifndef IFCWRITE_H
|
||||
#define IFCWRITE_H
|
||||
|
||||
#include "IfcUtil.h"
|
||||
#include "IfcParse.h"
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcParse.h"
|
||||
|
||||
namespace IfcWrite {
|
||||
|
||||
/// A placeholder class for grouping functionality geared towards writing IFC files
|
||||
/// This class is a writable container for attributes. A fundamental
|
||||
/// difference with the attribute types counterparts defined in the
|
||||
/// IfcParse namespace is that this class has a Boost.Variant member
|
||||
/// for storing its value, whereas the IfcParse classes only contain
|
||||
/// lazy references to byte offsets in the IFC-SPF file.
|
||||
class IfcWriteArgument : public Argument {
|
||||
|
||||
};
|
||||
|
||||
/// A null argument. It will always serialize to $
|
||||
class IfcWriteNullArgument : public IfcWriteArgument {
|
||||
public:
|
||||
operator int() const;
|
||||
operator bool() const;
|
||||
operator double() const;
|
||||
operator std::string() const;
|
||||
operator std::vector<double>() const;
|
||||
operator std::vector<int>() const;
|
||||
operator std::vector<std::string>() const;
|
||||
operator IfcUtil::IfcSchemaEntity() const;
|
||||
operator IfcEntities() const;
|
||||
bool isNull() const;
|
||||
ArgumentPtr operator [] (unsigned int i) const;
|
||||
std::string toString(bool upper=false) const;
|
||||
unsigned int Size() const;
|
||||
};
|
||||
|
||||
/// An entity list argument. It will serialize to (#1,#2,#3)
|
||||
/// with possibly a datatype identifier for SELECT types, e.g:
|
||||
/// (IFCREAL(1.0),IFCINTEGER(1))
|
||||
class IfcWriteEntityListArgument : public IfcWriteArgument {
|
||||
class EnumerationReference {
|
||||
public:
|
||||
int data;
|
||||
const char* enumeration_value;
|
||||
EnumerationReference(int data, const char* enumeration_value)
|
||||
: data(data), enumeration_value(enumeration_value) {}
|
||||
};
|
||||
class Derived {};
|
||||
private:
|
||||
IfcEntities value;
|
||||
IfcAbstractEntity* entity;
|
||||
boost::variant<
|
||||
// A null argument, it will always serialize to $
|
||||
boost::none_t,
|
||||
// A derived argument, it will always serialize to *
|
||||
Derived,
|
||||
// An integer argument, e.g. 123
|
||||
int,
|
||||
// A boolean argument, it will serialize to either .T. or .F.
|
||||
bool,
|
||||
// A floating point argument, e.g. 12.3
|
||||
double,
|
||||
// A character string argument, e.g. 'IfcOpenShell'
|
||||
std::string,
|
||||
// A list of integers, e.g. (1,2,3)
|
||||
std::vector<int>,
|
||||
// A list of floats, e.g. (12.3,4.)
|
||||
std::vector<double>,
|
||||
// A list of strings, e.g. ('Ifc','Open','Shell')
|
||||
std::vector<std::string>,
|
||||
// An enumeration argument, e.g. .USERDEFINED.
|
||||
// To initialize the argument a string representation
|
||||
// has to be explicitely passed of the enumeration value
|
||||
// which is stored internally as an integer. The argument
|
||||
// itself does not keep track of what schema enumeration
|
||||
// type is represented.
|
||||
EnumerationReference,
|
||||
// An entity instance argument. It will either serialize to
|
||||
// e.g. #123 or datatype identifier for simple types, e.g.
|
||||
// IFCREAL(12.3)
|
||||
IfcUtil::IfcSchemaEntity,
|
||||
// An entity list argument. It will either serialize to
|
||||
// e.g. (#1,#2,#3) or datatype identifier for simple types,
|
||||
// e.g. (IFCREAL(1.2),IFCINTEGER(3.))
|
||||
IfcEntities
|
||||
> container;
|
||||
public:
|
||||
IfcWriteEntityListArgument(const IfcEntities& v);
|
||||
operator int() const;
|
||||
operator bool() const;
|
||||
operator double() const;
|
||||
operator std::string() const;
|
||||
operator std::vector<double>() const;
|
||||
operator std::vector<int>() const;
|
||||
operator std::vector<std::string>() const;
|
||||
operator IfcUtil::IfcSchemaEntity() const;
|
||||
operator IfcEntities() const;
|
||||
bool isNull() const;
|
||||
unsigned int Size() const;
|
||||
ArgumentPtr operator [] (unsigned int i) const;
|
||||
std::string toString(bool upper=false) const;
|
||||
};
|
||||
|
||||
/// An enumeration argument. It will serialize to e.g:
|
||||
/// .USERDEFINED. To initialize the argument a string representation
|
||||
/// has to be explicitely passed of the enumeration value which
|
||||
/// is stored internally as an integer. The argument itself
|
||||
/// does not keep track of what schema enumeration type is
|
||||
/// represented.
|
||||
class IfcWriteEnumerationArgument : public IfcWriteArgument {
|
||||
private:
|
||||
int data;
|
||||
const char* enumeration_value;
|
||||
public:
|
||||
IfcWriteEnumerationArgument(int v, const char* c);
|
||||
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_schema_entity,
|
||||
argument_type_entities
|
||||
};
|
||||
IfcWriteArgument(IfcAbstractEntity* e) : entity(e) {}
|
||||
template <typename T> const T& as() const {
|
||||
if (const T* val = boost::get<T>(&container)) {
|
||||
return *val;
|
||||
} else {
|
||||
throw IfcParse::IfcException("Invalid cast");
|
||||
}
|
||||
}
|
||||
template <typename T> void set(const T& t) {
|
||||
container = t;
|
||||
}
|
||||
operator int() const;
|
||||
operator bool() const;
|
||||
operator double() const;
|
||||
@@ -104,38 +127,7 @@ namespace IfcWrite {
|
||||
ArgumentPtr operator [] (unsigned int i) const;
|
||||
std::string toString(bool upper=false) const;
|
||||
unsigned int Size() const;
|
||||
};
|
||||
|
||||
/// An argument for all remaining types of arguments. For example:
|
||||
/// #123 | 1 | 'Value' | (1.0,2.0,3.0). All data is casted to a
|
||||
/// void pointer.
|
||||
class IfcWriteIntegralArgument : public IfcWriteArgument {
|
||||
private:
|
||||
void* data;
|
||||
IfcUtil::ArgumentType type;
|
||||
public:
|
||||
IfcWriteIntegralArgument(int v);
|
||||
IfcWriteIntegralArgument(bool v);
|
||||
IfcWriteIntegralArgument(double v);
|
||||
IfcWriteIntegralArgument(const std::string& v);
|
||||
IfcWriteIntegralArgument(const std::vector<int> v);
|
||||
IfcWriteIntegralArgument(const std::vector<double> v);
|
||||
IfcWriteIntegralArgument(const std::vector<std::string> v);
|
||||
IfcWriteIntegralArgument(IfcUtil::IfcSchemaEntity v);
|
||||
~IfcWriteIntegralArgument();
|
||||
operator int() const;
|
||||
operator bool() const;
|
||||
operator double() const;
|
||||
operator std::string() const;
|
||||
operator std::vector<double>() const;
|
||||
operator std::vector<int>() const;
|
||||
operator std::vector<std::string>() const;
|
||||
operator IfcUtil::IfcSchemaEntity() const;
|
||||
operator IfcEntities() const;
|
||||
bool isNull() const;
|
||||
unsigned int Size() const;
|
||||
ArgumentPtr operator [] (unsigned int i) const;
|
||||
std::string toString(bool upper=false) const;
|
||||
argument_type argumentType() const;
|
||||
};
|
||||
|
||||
/// An entity to help with passing of SELECT arguments that
|
||||
@@ -144,18 +136,18 @@ namespace IfcWrite {
|
||||
/// Proper memory management is difficult for now, so beware.
|
||||
class IfcSelectHelperEntity : public IfcAbstractEntity {
|
||||
private:
|
||||
Ifc2x3::Type::Enum _type;
|
||||
IfcSchema::Type::Enum _type;
|
||||
IfcWriteArgument* arg;
|
||||
public:
|
||||
// FIXME: Make this a non-pointer argument and implement a copy constructor
|
||||
IfcSelectHelperEntity(Ifc2x3::Type::Enum t, IfcWriteArgument* a) : _type(t), arg(a) {}
|
||||
IfcEntities getInverse(Ifc2x3::Type::Enum,int,const std::string &);
|
||||
IfcEntities getInverse(Ifc2x3::Type::Enum);
|
||||
IfcSelectHelperEntity(IfcSchema::Type::Enum t, IfcWriteArgument* a) : _type(t), arg(a) {}
|
||||
IfcEntities getInverse(IfcSchema::Type::Enum,int,const std::string &);
|
||||
IfcEntities getInverse(IfcSchema::Type::Enum);
|
||||
std::string datatype();
|
||||
ArgumentPtr getArgument(unsigned int i);
|
||||
unsigned int getArgumentCount();
|
||||
Ifc2x3::Type::Enum type() const;
|
||||
bool is(Ifc2x3::Type::Enum t) const;
|
||||
IfcSchema::Type::Enum type() const;
|
||||
bool is(IfcSchema::Type::Enum t) const;
|
||||
std::string toString(bool upper = false);
|
||||
unsigned int id();
|
||||
bool isWritable();
|
||||
@@ -167,18 +159,16 @@ namespace IfcWrite {
|
||||
/// Proper memory management is difficult for now, so beware.
|
||||
class IfcSelectHelper : public IfcUtil::IfcBaseClass {
|
||||
public:
|
||||
IfcSelectHelper(const std::string& v, Ifc2x3::Type::Enum t=Ifc2x3::Type::IfcText);
|
||||
IfcSelectHelper(const char* const v, Ifc2x3::Type::Enum t=Ifc2x3::Type::IfcText);
|
||||
IfcSelectHelper(int v, Ifc2x3::Type::Enum t=Ifc2x3::Type::IfcInteger);
|
||||
IfcSelectHelper(double v, Ifc2x3::Type::Enum t=Ifc2x3::Type::IfcReal);
|
||||
IfcSelectHelper(bool v, Ifc2x3::Type::Enum t=Ifc2x3::Type::IfcBoolean);
|
||||
bool is(Ifc2x3::Type::Enum t) const;
|
||||
Ifc2x3::Type::Enum type() const;
|
||||
IfcSelectHelper(const std::string& v, IfcSchema::Type::Enum t=IfcSchema::Type::IfcText);
|
||||
IfcSelectHelper(const char* const v, IfcSchema::Type::Enum t=IfcSchema::Type::IfcText);
|
||||
IfcSelectHelper(int v, IfcSchema::Type::Enum t=IfcSchema::Type::IfcInteger);
|
||||
IfcSelectHelper(double v, IfcSchema::Type::Enum t=IfcSchema::Type::IfcReal);
|
||||
IfcSelectHelper(bool v, IfcSchema::Type::Enum t=IfcSchema::Type::IfcBoolean);
|
||||
bool is(IfcSchema::Type::Enum t) const;
|
||||
IfcSchema::Type::Enum type() const;
|
||||
};
|
||||
|
||||
/// A helper class for the creation of IFC GlobalIds.
|
||||
/// At this moment an actual UUID is not generated according to
|
||||
/// the ISO standard, but merely a sequence of random characters.
|
||||
class IfcGuidHelper {
|
||||
private:
|
||||
std::string data;
|
||||
|
||||
Reference in New Issue
Block a user