- Add support for IFC4 nurbs surfaces (IfcBSplineSurfaceWithKnots and IfcAdvancedFace)

- Remove unnecessary typedefs
This commit is contained in:
Thomas Krijnen
2014-05-04 14:42:55 +00:00
parent e87b8988cd
commit 1b54ba039d
33 changed files with 17860 additions and 20428 deletions
+3389 -3395
View File
File diff suppressed because it is too large Load Diff
+4402 -5708
View File
File diff suppressed because it is too large Load Diff
+4036 -4053
View File
File diff suppressed because it is too large Load Diff
+5192 -6722
View File
File diff suppressed because it is too large Load Diff
+22 -22
View File
@@ -90,13 +90,13 @@ IfcSchema::IfcOwnerHistory* IfcHierarchyHelper::addOwnerHistory() {
}
IfcSchema::IfcProject* IfcHierarchyHelper::addProject(IfcSchema::IfcOwnerHistory* owner_hist) {
IfcSchema::IfcRepresentationContext::list rep_contexts (new IfcTemplatedEntityList<IfcSchema::IfcRepresentationContext>());
IfcSchema::IfcRepresentationContext::list::ptr rep_contexts (new IfcSchema::IfcRepresentationContext::list);
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());
IfcEntityList::ptr 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);
@@ -236,7 +236,7 @@ void IfcHierarchyHelper::addExtrudedPolyline(IfcSchema::IfcShapeRepresentation*
IfcSchema::IfcAxis2Placement2D* place, IfcSchema::IfcAxis2Placement3D* place2,
IfcSchema::IfcDirection* dir, IfcSchema::IfcRepresentationContext* context)
{
IfcSchema::IfcCartesianPoint::list cartesian_points (new IfcTemplatedEntityList<IfcSchema::IfcCartesianPoint>());
IfcSchema::IfcCartesianPoint::list::ptr cartesian_points (new IfcSchema::IfcCartesianPoint::list);
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));
}
@@ -248,7 +248,7 @@ void IfcHierarchyHelper::addExtrudedPolyline(IfcSchema::IfcShapeRepresentation*
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();
IfcSchema::IfcRepresentationItem::list::ptr items = rep->Items();
items->push(solid);
rep->setItems(items);
@@ -261,8 +261,8 @@ IfcSchema::IfcProductDefinitionShape* IfcHierarchyHelper::addExtrudedPolyline(co
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::IfcRepresentation::list::ptr reps (new IfcSchema::IfcRepresentation::list);
IfcSchema::IfcRepresentationItem::list::ptr items (new IfcSchema::IfcRepresentationItem::list);
IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation(context
? context
: getSingle<IfcSchema::IfcRepresentationContext>(), std::string("Body"), std::string("SweptSolid"), items);
@@ -287,7 +287,7 @@ void IfcHierarchyHelper::addBox(IfcSchema::IfcShapeRepresentation* rep, double w
AddEntity(profile);
AddEntity(solid);
IfcSchema::IfcRepresentationItem::list items = rep->Items();
IfcSchema::IfcRepresentationItem::list::ptr items = rep->Items();
items->push(solid);
rep->setItems(items);
} else {
@@ -304,8 +304,8 @@ void IfcHierarchyHelper::addBox(IfcSchema::IfcShapeRepresentation* rep, double w
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::IfcRepresentation::list::ptr reps (new IfcSchema::IfcRepresentation::list);
IfcSchema::IfcRepresentationItem::list::ptr items (new IfcSchema::IfcRepresentationItem::list);
IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation(
context ? context : getSingle<IfcSchema::IfcRepresentationContext>(), std::string("Body"), std::string("SweptSolid"), items);
reps->push(rep);
@@ -321,16 +321,16 @@ void IfcHierarchyHelper::clipRepresentation(IfcSchema::IfcProductRepresentation*
{
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::list::ptr reps = shape->Representations();
for (IfcSchema::IfcRepresentation::list::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>());
IfcSchema::IfcRepresentationItem::list::ptr items = rep->Items();
IfcSchema::IfcRepresentationItem::list::ptr new_items (new IfcSchema::IfcRepresentationItem::list);
AddEntity(plane);
AddEntity(half_space);
for (IfcSchema::IfcRepresentationItem::it i = items->begin(); i != items->end(); ++i) {
for (IfcSchema::IfcRepresentationItem::list::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);
@@ -351,11 +351,11 @@ IfcSchema::IfcPresentationStyleAssignment* IfcHierarchyHelper::setSurfaceColour(
: 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());
IfcEntityList::ptr 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());
IfcEntityList::ptr surface_styles(new IfcEntityList());
surface_styles->push(surface_style);
IfcSchema::IfcPresentationStyleAssignment* style_assignment =
new IfcSchema::IfcPresentationStyleAssignment(surface_styles);
@@ -371,17 +371,17 @@ void IfcHierarchyHelper::setSurfaceColour(IfcSchema::IfcProductRepresentation* s
IfcSchema::IfcPresentationStyleAssignment* style_assignment)
{
#ifdef USE_IFC4
IfcEntities style_assignments (new IfcEntityList());
IfcEntityList::ptr style_assignments (new IfcEntityList);
#else
IfcSchema::IfcPresentationStyleAssignment::list style_assignments (new IfcTemplatedEntityList<IfcSchema::IfcPresentationStyleAssignment>());
IfcSchema::IfcPresentationStyleAssignment::list::ptr style_assignments (new IfcSchema::IfcPresentationStyleAssignment::list);
#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::list::ptr reps = shape->Representations();
for (IfcSchema::IfcRepresentation::list::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::list::ptr items = rep->Items();
for (IfcSchema::IfcRepresentationItem::list::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);
+9 -9
View File
@@ -56,7 +56,7 @@ public:
template <class T>
T* getSingle() {
typename T::list ts = EntitiesByType<T>();
typename T::list::ptr ts = EntitiesByType<T>();
if (ts->Size() != 1) return 0;
return *ts->begin();
}
@@ -76,12 +76,12 @@ public:
void addRelatedObject(IfcSchema::IfcObjectDefinition* related_object,
IfcSchema::IfcObjectDefinition* relating_object, IfcSchema::IfcOwnerHistory* owner_hist = 0)
{
typename T::list li = EntitiesByType<T>();
typename T::list::ptr li = EntitiesByType<T>();
bool found = false;
for (typename T::it i = li->begin(); i != li->end(); ++i) {
for (typename T::list::it i = li->begin(); i != li->end(); ++i) {
T* rel = *i;
if (rel->RelatingObject() == relating_object) {
IfcSchema::IfcObjectDefinition::list products = rel->RelatedObjects();
IfcSchema::IfcObjectDefinition::list::ptr products = rel->RelatedObjects();
products->push(related_object);
rel->setRelatedObjects(products);
found = true;
@@ -95,7 +95,7 @@ public:
if (! owner_hist) {
owner_hist = addOwnerHistory();
}
IfcSchema::IfcObjectDefinition::list relating_objects (new IfcTemplatedEntityList<IfcSchema::IfcObjectDefinition>());
IfcSchema::IfcObjectDefinition::list::ptr 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);
@@ -144,12 +144,12 @@ 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>();
IfcSchema::IfcRelContainedInSpatialStructure::list::ptr li = EntitiesByType<IfcSchema::IfcRelContainedInSpatialStructure>();
bool found = false;
for (IfcSchema::IfcRelContainedInSpatialStructure::it i = li->begin(); i != li->end(); ++i) {
for (IfcSchema::IfcRelContainedInSpatialStructure::list::it i = li->begin(); i != li->end(); ++i) {
IfcSchema::IfcRelContainedInSpatialStructure* rel = *i;
if (rel->RelatingStructure() == relating_object) {
IfcSchema::IfcProduct::list products = rel->RelatedElements();
IfcSchema::IfcProduct::list::ptr products = rel->RelatedElements();
products->push((IfcSchema::IfcProduct*)related_object);
rel->setRelatedElements(products);
found = true;
@@ -163,7 +163,7 @@ inline void IfcHierarchyHelper::addRelatedObject <IfcSchema::IfcRelContainedInSp
if (! owner_hist) {
owner_hist = addOwnerHistory();
}
IfcSchema::IfcProduct::list relating_objects (new IfcTemplatedEntityList<IfcSchema::IfcProduct>());
IfcSchema::IfcProduct::list::ptr 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);
+68 -55
View File
@@ -415,7 +415,7 @@ ArgumentList::ArgumentList(Tokens* t, std::vector<unsigned int>& ids) {
}
}
void ArgumentList::Push(ArgumentPtr l) {
void ArgumentList::Push(Argument* l) {
list.push_back(l);
}
@@ -428,7 +428,7 @@ ArgumentList::operator double() const { throw IfcException("Argument is not a nu
ArgumentList::operator std::string() const { throw IfcException("Argument is not a string"); }
ArgumentList::operator std::vector<double>() const {
std::vector<double> r;
std::vector<ArgumentPtr>::const_iterator it;
std::vector<Argument*>::const_iterator it;
for ( it = list.begin(); it != list.end(); ++ it ) {
r.push_back(**it);
}
@@ -436,7 +436,7 @@ ArgumentList::operator std::vector<double>() const {
}
ArgumentList::operator std::vector<int>() const {
std::vector<int> r;
std::vector<ArgumentPtr>::const_iterator it;
std::vector<Argument*>::const_iterator it;
for ( it = list.begin(); it != list.end(); ++ it ) {
r.push_back(**it);
}
@@ -444,26 +444,39 @@ ArgumentList::operator std::vector<int>() const {
}
ArgumentList::operator std::vector<std::string>() const {
std::vector<std::string> r;
std::vector<ArgumentPtr>::const_iterator it;
std::vector<Argument*>::const_iterator it;
for ( it = list.begin(); it != list.end(); ++ it ) {
r.push_back(**it);
}
return r;
}
ArgumentList::operator IfcUtil::IfcSchemaEntity() const { throw IfcException("Argument is not an IFC type"); }
ArgumentList::operator IfcUtil::IfcBaseClass*() const { throw IfcException("Argument is not an IFC type"); }
//ArgumentList::operator IfcUtil::IfcAbstractSelect::ptr() const { throw IfcException("Argument is not an IFC type"); }
ArgumentList::operator IfcEntities() const {
IfcEntities l ( new IfcEntityList() );
std::vector<ArgumentPtr>::const_iterator it;
ArgumentList::operator IfcEntityList::ptr() const {
IfcEntityList::ptr l ( new IfcEntityList() );
std::vector<Argument*>::const_iterator it;
for ( it = list.begin(); it != list.end(); ++ it ) {
// FIXME: account for $
const IfcUtil::IfcSchemaEntity entity = **it;
IfcUtil::IfcBaseClass* entity = **it;
l->push(entity);
}
return l;
}
ArgumentList::operator IfcEntityListList::ptr() const {
IfcEntityListList::ptr l ( new IfcEntityListList() );
std::vector<Argument*>::const_iterator it;
for ( it = list.begin(); it != list.end(); ++ it ) {
const Argument* arg = *it;
const ArgumentList* arg_list;
if ((arg_list = dynamic_cast<const ArgumentList*>(arg))) {
IfcEntityList::ptr e = *arg_list;
l->push(e);
}
}
return l;
}
unsigned int ArgumentList::Size() const { return (unsigned int) list.size(); }
ArgumentPtr ArgumentList::operator [] (unsigned int i) const {
Argument* ArgumentList::operator [] (unsigned int i) const {
if ( i >= list.size() )
throw IfcException("Argument index out of range");
return list[i];
@@ -471,7 +484,7 @@ ArgumentPtr ArgumentList::operator [] (unsigned int i) const {
std::string ArgumentList::toString(bool upper) const {
std::stringstream ss;
ss << "(";
for( std::vector<ArgumentPtr>::const_iterator it = list.begin(); it != list.end(); it ++ ) {
for( std::vector<Argument*>::const_iterator it = list.begin(); it != list.end(); it ++ ) {
if ( it != list.begin() ) ss << ",";
ss << (*it)->toString(upper);
}
@@ -480,7 +493,7 @@ std::string ArgumentList::toString(bool upper) const {
}
bool ArgumentList::isNull() const { return false; }
ArgumentList::~ArgumentList() {
for( std::vector<ArgumentPtr>::iterator it = list.begin(); it != list.end(); it ++ ) {
for( std::vector<Argument*>::iterator it = list.begin(); it != list.end(); it ++ ) {
delete (*it);
}
list.clear();
@@ -496,10 +509,11 @@ TokenArgument::operator std::string() const { return TokenFunc::asString(token);
TokenArgument::operator std::vector<double>() const { throw IfcException("Argument is not a list of floats"); }
TokenArgument::operator std::vector<int>() const { throw IfcException("Argument is not a list of ints"); }
TokenArgument::operator std::vector<std::string>() const { throw IfcException("Argument is not a list of strings"); }
TokenArgument::operator IfcUtil::IfcSchemaEntity() const { return token.first->file->EntityById(TokenFunc::asInt(token)); }
TokenArgument::operator IfcEntities() const { throw IfcException("Argument is not a list of entities"); }
TokenArgument::operator IfcUtil::IfcBaseClass*() const { return token.first->file->EntityById(TokenFunc::asInt(token)); }
TokenArgument::operator IfcEntityList::ptr() const { throw IfcException("Argument is not a list of entities"); }
TokenArgument::operator IfcEntityListList::ptr() const { throw IfcException("Argument is not a list of entity lists"); }
unsigned int TokenArgument::Size() const { return 1; }
ArgumentPtr TokenArgument::operator [] (unsigned int i) const { throw IfcException("Argument is not a list of arguments"); }
Argument* TokenArgument::operator [] (unsigned int i) const { throw IfcException("Argument is not a list of arguments"); }
std::string TokenArgument::toString(bool upper) const {
if ( upper && TokenFunc::isString(token) ) {
return IfcWrite::IfcCharacterEncoder(TokenFunc::asString(token));
@@ -518,13 +532,14 @@ EntityArgument::operator std::string() const { throw IfcException("Argument is n
EntityArgument::operator std::vector<double>() const { throw IfcException("Argument is not a list of floats"); }
EntityArgument::operator std::vector<int>() const { throw IfcException("Argument is not a list of ints"); }
EntityArgument::operator std::vector<std::string>() const { throw IfcException("Argument is not a list of strings"); }
EntityArgument::operator IfcUtil::IfcSchemaEntity() const { return entity; }
EntityArgument::operator IfcUtil::IfcBaseClass*() const { return entity; }
//EntityArgument::operator IfcUtil::IfcAbstractSelect::ptr() const { return entity; }
EntityArgument::operator IfcEntities() const { throw IfcException("Argument is not a list of entities"); }
EntityArgument::operator IfcEntityList::ptr() const { throw IfcException("Argument is not a list of entities"); }
EntityArgument::operator IfcEntityListList::ptr() const { throw IfcException("Argument is not a list of entity lists"); }
unsigned int EntityArgument::Size() const { return 1; }
ArgumentPtr EntityArgument::operator [] (unsigned int i) const { throw IfcException("Argument is not a list of arguments"); }
Argument* EntityArgument::operator [] (unsigned int i) const { throw IfcException("Argument is not a list of arguments"); }
std::string EntityArgument::toString(bool upper) const {
ArgumentPtr arg = entity->wrappedValue();
Argument* arg = entity->wrappedValue();
IfcParse::TokenArgument* token_arg = dynamic_cast<IfcParse::TokenArgument*>(arg);
const bool is_string = TokenFunc::isString(token_arg->token);
std::string token_string = token_arg ? (is_string
@@ -548,13 +563,11 @@ EntityArgument::~EntityArgument() { delete entity; }
//
// Reads an Entity from the list of Tokens
//
Entity::Entity(unsigned int i, IfcFile* f) { //: file(f) {
Entity::Entity(unsigned int i, IfcFile* f) : _id(i), args(0) {
file = f;
Token datatype = f->tokens->Next();
if ( ! TokenFunc::isDatatype(datatype)) throw IfcException("Unexpected token while parsing entity");
_type = IfcSchema::Type::FromString(TokenFunc::asString(datatype));
_id = i;
args = ArgumentPtr();
offset = datatype.second;
}
@@ -572,7 +585,7 @@ Entity::Entity(unsigned int i, IfcFile* f, unsigned int o) { // : file(f) {
//
// Access the Nth argument from the ArgumentList
//
ArgumentPtr Entity::getArgument(unsigned int i) {
Argument* Entity::getArgument(unsigned int i) {
if ( ! args ) {
std::vector<unsigned int> ids;
Load(ids, true);
@@ -580,7 +593,7 @@ ArgumentPtr Entity::getArgument(unsigned int i) {
return (*args)[i];
}
unsigned int Entity::getArgumentCount() {
unsigned int Entity::getArgumentCount() const {
if ( ! args ) {
std::vector<unsigned int> ids;
Load(ids, true);
@@ -591,7 +604,7 @@ unsigned int Entity::getArgumentCount() {
//
// Load the ArgumentList
//
void Entity::Load(std::vector<unsigned int>& ids, bool seek) {
void Entity::Load(std::vector<unsigned int>& ids, bool seek) const {
if ( seek ) {
file->tokens->stream->Seek(offset);
Token datatype = file->tokens->Next();
@@ -612,7 +625,7 @@ IfcSchema::Type::Enum Entity::type() const {
//
// Returns the CamelCase string representation of the datatype as it is defined in the schema
//
std::string Entity::datatype() {
std::string Entity::datatype() const {
return IfcSchema::Type::ToString(_type);
}
@@ -620,7 +633,7 @@ std::string Entity::datatype() {
// Returns a string representation of the entity
// Note that this initializes the entity if it is not initialized
//
std::string Entity::toString(bool upper) {
std::string Entity::toString(bool upper) const {
if ( ! args ) {
std::vector<unsigned int> ids;
Load(ids, true);
@@ -641,9 +654,9 @@ Entity::~Entity() {
//
// Returns the entities of type c that have this entity in their ArgumentList
//
IfcEntities Entity::getInverse(IfcSchema::Type::Enum c) {
IfcEntities l = IfcEntities(new IfcEntityList());
IfcEntities all = file->EntitiesByReference(_id);
IfcEntityList::ptr Entity::getInverse(IfcSchema::Type::Enum c) {
IfcEntityList::ptr l = IfcEntityList::ptr(new IfcEntityList());
IfcEntityList::ptr all = file->EntitiesByReference(_id);
if ( ! all ) return l;
for( IfcEntityList::it it = all->begin(); it != all->end();++ it ) {
if ( c == IfcSchema::Type::ALL || (*it)->is(c) ) {
@@ -652,9 +665,9 @@ IfcEntities Entity::getInverse(IfcSchema::Type::Enum c) {
}
return l;
}
IfcEntities Entity::getInverse(IfcSchema::Type::Enum c, int i, const std::string& a) {
IfcEntities l = IfcEntities(new IfcEntityList());
IfcEntities all = getInverse(c);
IfcEntityList::ptr Entity::getInverse(IfcSchema::Type::Enum c, int i, const std::string& a) {
IfcEntityList::ptr l = IfcEntityList::ptr(new IfcEntityList());
IfcEntityList::ptr all = getInverse(c);
for( IfcEntityList::it it = all->begin(); it != all->end();++ it ) {
const std::string s = *(*it)->entity->getArgument(i);
if ( s == a ) {
@@ -702,8 +715,8 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
unsigned int currentId = 0;
lastId = 0;
int x = 0;
EntityPtr e;
IfcUtil::IfcSchemaEntity entity = 0;
Entity* e;
IfcUtil::IfcBaseClass* entity = 0;
Logger::Status("Scanning file...");
while ( ! file->eof ) {
if ( currentId ) {
@@ -721,7 +734,7 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
Logger::Status(ss.str(), false);
}
if ( entity->is(IfcSchema::Type::IfcRoot) ) {
IfcSchema::IfcRoot::ptr ifc_root = (IfcSchema::IfcRoot::ptr) entity;
IfcSchema::IfcRoot* ifc_root = (IfcSchema::IfcRoot*) entity;
try {
const std::string guid = ifc_root->GlobalId();
if ( byguid.find(guid) != byguid.end() ) {
@@ -736,9 +749,9 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
}
IfcSchema::Type::Enum ty = entity->type();
do {
IfcEntities L = EntitiesByType(ty);
IfcEntityList::ptr L = EntitiesByType(ty);
if ( L == 0 ) {
L = IfcEntities(new IfcEntityList());
L = IfcEntityList::ptr(new IfcEntityList());
bytype[ty] = L;
}
L->push(entity);
@@ -762,9 +775,9 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
if ( TokenFunc::isOperator(token,'=') ) {
currentId = id;
} else if (entity) {
IfcEntities L = EntitiesByReference(id);
IfcEntityList::ptr L = EntitiesByReference(id);
if ( L == 0 ) {
L = IfcEntities(new IfcEntityList());
L = IfcEntityList::ptr(new IfcEntityList());
byref[id] = L;
}
L->push(entity);
@@ -775,14 +788,14 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
Logger::Status("\rDone scanning file ");
return true;
}
void IfcFile::AddEntities(IfcEntities es) {
void IfcFile::AddEntities(IfcEntityList::ptr es) {
for( IfcEntityList::it i = es->begin(); i != es->end(); ++ i ) {
AddEntity(*i);
}
}
void IfcFile::AddEntity(IfcUtil::IfcSchemaEntity entity) {
void IfcFile::AddEntity(IfcUtil::IfcBaseClass* entity) {
if ( entity->is(IfcSchema::Type::IfcRoot) ) {
IfcSchema::IfcRoot::ptr ifc_root = (IfcSchema::IfcRoot::ptr) entity;
IfcSchema::IfcRoot* ifc_root = (IfcSchema::IfcRoot*) entity;
try {
const std::string guid = ifc_root->GlobalId();
if ( byguid.find(guid) != byguid.end() ) {
@@ -797,9 +810,9 @@ void IfcFile::AddEntity(IfcUtil::IfcSchemaEntity entity) {
}
IfcSchema::Type::Enum ty = entity->type();
do {
IfcEntities L = EntitiesByType(ty);
IfcEntityList::ptr L = EntitiesByType(ty);
if ( L == 0 ) {
L = IfcEntities(new IfcEntityList());
L = IfcEntityList::ptr(new IfcEntityList());
bytype[ty] = L;
}
L->push(entity);
@@ -822,33 +835,33 @@ void IfcFile::AddEntity(IfcUtil::IfcSchemaEntity entity) {
byid[new_id] = entity;
}
IfcEntities IfcFile::EntitiesByType(IfcSchema::Type::Enum t) {
IfcEntityList::ptr IfcFile::EntitiesByType(IfcSchema::Type::Enum t) {
MapEntitiesByType::const_iterator it = bytype.find(t);
return (it == bytype.end()) ? IfcEntities() : it->second;
return (it == bytype.end()) ? IfcEntityList::ptr() : it->second;
}
IfcEntities IfcFile::EntitiesByType(const std::string& t) {
IfcEntityList::ptr 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(IfcSchema::Type::FromString(ty));
}
IfcEntities IfcFile::EntitiesByReference(int t) {
IfcEntityList::ptr IfcFile::EntitiesByReference(int t) {
MapEntitiesByRef::const_iterator it = byref.find(t);
return (it == byref.end()) ? IfcEntities() : it->second;
return (it == byref.end()) ? IfcEntityList::ptr() : it->second;
}
IfcUtil::IfcSchemaEntity IfcFile::EntityById(int id) {
IfcUtil::IfcBaseClass* IfcFile::EntityById(int id) {
MapEntityById::const_iterator it = byid.find(id);
if ( it == byid.end() ) {
MapOffsetById::const_iterator it2 = offsets.find(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 = IfcSchema::SchemaEntity(e);
Entity* e = new Entity(id,this,offset);
IfcUtil::IfcBaseClass* entity = IfcSchema::SchemaEntity(e);
byid[id] = entity;
return entity;
}
return it->second;
}
IfcSchema::IfcRoot::ptr IfcFile::EntityByGuid(const std::string& guid) {
IfcSchema::IfcRoot* IfcFile::EntityByGuid(const std::string& guid) {
MapEntityByGuid::const_iterator it = byguid.find(guid);
if ( it == byguid.end() ) {
throw IfcException("Entity not found");
@@ -900,7 +913,7 @@ std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f) {
os << "DATA;" << std::endl;
for ( MapEntityById::const_iterator it = f.begin(); it != f.end(); ++ it ) {
const IfcEntity e = it->second;
const IfcUtil::IfcBaseClass* e = it->second;
os << e->entity->toString(true) << ";" << std::endl;
}
+43 -45
View File
@@ -52,12 +52,9 @@
namespace IfcParse {
class Entity;
class Entities;
class IfcFile;
typedef Entity* EntityPtr;
typedef SHARED_PTR<Entities> EntitiesPtr;
class Tokens;
typedef std::pair<Tokens*,unsigned> Token;
/// Provides functions to convert Tokens to binary data
@@ -118,8 +115,8 @@ namespace IfcParse {
/// ==========
class ArgumentList: public Argument {
private:
std::vector<ArgumentPtr> list;
void Push(ArgumentPtr l);
std::vector<Argument*> list;
void Push(Argument* l);
public:
ArgumentList(Tokens* t, std::vector<unsigned int>& ids);
~ArgumentList();
@@ -130,11 +127,12 @@ namespace IfcParse {
operator std::vector<double>() const;
operator std::vector<int>() const;
operator std::vector<std::string>() const;
operator IfcUtil::IfcSchemaEntity() const;
operator IfcUtil::IfcBaseClass*() const;
//operator IfcUtil::IfcAbstractSelect::ptr() const;
operator IfcEntities() const;
operator IfcEntityList::ptr() const;
operator IfcEntityListList::ptr() const;
unsigned int Size() const;
ArgumentPtr operator [] (unsigned int i) const;
Argument* operator [] (unsigned int i) const;
std::string toString(bool upper=false) const;
bool isNull() const;
};
@@ -155,11 +153,12 @@ namespace IfcParse {
operator std::vector<double>() const;
operator std::vector<int>() const;
operator std::vector<std::string>() const;
operator IfcUtil::IfcSchemaEntity() const;
operator IfcUtil::IfcBaseClass*() const;
//operator IfcUtil::IfcAbstractSelect::ptr() const;
operator IfcEntities() const;
operator IfcEntityList::ptr() const;
operator IfcEntityListList::ptr() const;
unsigned int Size() const;
ArgumentPtr operator [] (unsigned int i) const;
Argument* operator [] (unsigned int i) const;
std::string toString(bool upper=false) const;
bool isNull() const;
};
@@ -180,11 +179,12 @@ namespace IfcParse {
operator std::vector<double>() const;
operator std::vector<int>() const;
operator std::vector<std::string>() const;
operator IfcUtil::IfcSchemaEntity() const;
operator IfcUtil::IfcBaseClass*() const;
//operator IfcUtil::IfcAbstractSelect::ptr() const;
operator IfcEntities() const;
operator IfcEntityList::ptr() const;
operator IfcEntityListList::ptr() const;
unsigned int Size() const;
ArgumentPtr operator [] (unsigned int i) const;
Argument* operator [] (unsigned int i) const;
std::string toString(bool upper=false) const;
bool isNull() const;
};
@@ -194,9 +194,8 @@ namespace IfcParse {
/// ============================
class Entity : public IfcAbstractEntity {
private:
//IfcFile* file;
ArgumentPtr args;
IfcSchema::Type::Enum _type;
mutable Argument* args;
mutable IfcSchema::Type::Enum _type;
public:
/// The EXPRESS ENTITY_INSTANCE_NAME
unsigned int _id;
@@ -205,26 +204,24 @@ namespace IfcParse {
Entity(unsigned int i, IfcFile* t);
Entity(unsigned int i, IfcFile* t, unsigned int o);
~Entity();
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();
IfcEntityList::ptr getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL);
IfcEntityList::ptr getInverse(IfcSchema::Type::Enum c, int i, const std::string& a);
void Load(std::vector<unsigned int>& ids, bool seek=false) const;
Argument* getArgument (unsigned int i);
unsigned int getArgumentCount() const;
std::string toString(bool upper=false) const;
std::string datatype() const;
IfcSchema::Type::Enum type() const;
bool is(IfcSchema::Type::Enum v) const;
unsigned int id();
bool isWritable();
};
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;
typedef std::map<IfcSchema::Type::Enum, IfcEntityList::ptr> MapEntitiesByType;
typedef std::map<unsigned int, IfcUtil::IfcBaseClass*> MapEntityById;
typedef std::map<std::string, IfcSchema::IfcRoot*> MapEntityByGuid;
typedef std::map<unsigned int, IfcEntityList::ptr> MapEntitiesByRef;
typedef std::map<unsigned int, unsigned int> MapOffsetById;
/// This class provides several static convenience functions and variables
/// and provide access to the entities in an IFC file
@@ -257,36 +254,37 @@ public:
/// NOTE: This also returns subtypes of the requested type, for example:
/// IfcWall will also return IfcWallStandardCase entities
template <class T>
typename T::list EntitiesByType() {
IfcEntities e = EntitiesByType(T::Class());
typename T::list l ( new IfcTemplatedEntityList<T>() );
if ( e && e->Size() )
typename T::list::ptr EntitiesByType() {
IfcEntityList::ptr e = EntitiesByType(T::Class());
typename T::list::ptr l(new typename T::list);
if (e && e->Size()) {
for ( IfcEntityList::it it = e->begin(); it != e->end(); ++ it ) {
l->push(reinterpret_pointer_cast<IfcUtil::IfcBaseClass,T>(*it));
l->push((T*)*it);
}
return l;
}
return l;
}
/// Returns all entities in the file that match the positional argument.
/// NOTE: This also returns subtypes of the requested type, for example:
/// IfcWall will also return IfcWallStandardCase entities
IfcEntities EntitiesByType(IfcSchema::Type::Enum t);
IfcEntityList::ptr EntitiesByType(IfcSchema::Type::Enum t);
/// Returns all entities in the file that match the positional argument.
/// NOTE: This also returns subtypes of the requested type, for example:
/// IfcWall will also return IfcWallStandardCase entities
IfcEntities EntitiesByType(const std::string& t);
IfcEntityList::ptr EntitiesByType(const std::string& t);
/// Returns all entities in the file that reference the id
IfcEntities EntitiesByReference(int id);
IfcEntityList::ptr EntitiesByReference(int id);
/// Returns the entity with the specified id
IfcEntity EntityById(int id);
IfcUtil::IfcBaseClass* EntityById(int id);
/// Returns the entity with the specified GlobalId
IfcSchema::IfcRoot::ptr EntityByGuid(const std::string& guid);
IfcSchema::IfcRoot* EntityByGuid(const std::string& guid);
bool Init(const std::string& fn);
bool Init(std::istream& fn, int len);
bool Init(void* data, int len);
bool Init(IfcParse::IfcSpfStream* f);
unsigned int FreshId() { MaxId ++; return MaxId; }
void AddEntity(IfcUtil::IfcSchemaEntity e);
void AddEntities(IfcEntities es);
void AddEntity(IfcUtil::IfcBaseClass* entity);
void AddEntities(IfcEntityList::ptr es);
void filename(const std::string& s);
std::string filename() const;
+12 -12
View File
@@ -20,10 +20,10 @@
#include "IfcUtil.h"
#include <iostream>
void IfcEntityList::push(IfcUtil::IfcSchemaEntity l) {
void IfcEntityList::push(IfcUtil::IfcBaseClass* l) {
if ( l ) ls.push_back(l);
}
void IfcEntityList::push(IfcEntities l) {
void IfcEntityList::push(const IfcEntityList::ptr& l) {
for( it i = l->begin(); i != l->end(); ++i ) {
if ( *i ) ls.push_back(*i);
}
@@ -31,18 +31,18 @@ void IfcEntityList::push(IfcEntities l) {
int IfcEntityList::Size() const { return (unsigned int) ls.size(); }
IfcEntityList::it IfcEntityList::begin() { return ls.begin(); }
IfcEntityList::it IfcEntityList::end() { return ls.end(); }
IfcUtil::IfcSchemaEntity IfcEntityList::operator[] (int i) {
IfcUtil::IfcBaseClass* IfcEntityList::operator[] (int i) {
return ls[i];
}
IfcEntities IfcEntityList::getInverse(IfcSchema::Type::Enum c) {
IfcEntities l = IfcEntities(new IfcEntityList());
IfcEntityList::ptr IfcEntityList::getInverse(IfcSchema::Type::Enum c) {
IfcEntityList::ptr l = IfcEntityList::ptr(new IfcEntityList());
for( it i = begin(); i != end(); ++i ) {
l->push((*i)->entity->getInverse(c));
}
return l;
}
IfcEntities IfcEntityList::getInverse(IfcSchema::Type::Enum c, int ar, const std::string& a) {
IfcEntities l = IfcEntities(new IfcEntityList());
IfcEntityList::ptr IfcEntityList::getInverse(IfcSchema::Type::Enum c, int ar, const std::string& a) {
IfcEntityList::ptr l = IfcEntityList::ptr(new IfcEntityList());
for( it i = begin(); i != end(); ++i ) {
l->push((*i)->entity->getInverse(c,ar,a));
}
@@ -51,15 +51,15 @@ IfcEntities IfcEntityList::getInverse(IfcSchema::Type::Enum c, int ar, const std
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; }
IfcUtil::IfcEntitySelect::IfcEntitySelect(IfcBaseClass* b) { entity = b->entity; }
IfcUtil::IfcEntitySelect::IfcEntitySelect(IfcAbstractEntity* e) { entity = e; }
bool IfcUtil::IfcEntitySelect::isSimpleType() { return false; }
IfcUtil::IfcEntitySelect::~IfcEntitySelect() { delete entity; }
bool IfcUtil::IfcArgumentSelect::is(IfcSchema::Type::Enum v) const { return _type == v; }
IfcSchema::Type::Enum IfcUtil::IfcArgumentSelect::type() const { return _type; }
IfcUtil::IfcArgumentSelect::IfcArgumentSelect(IfcSchema::Type::Enum t, ArgumentPtr a) { _type = t; arg = a; }
ArgumentPtr IfcUtil::IfcArgumentSelect::wrappedValue() { return arg; }
IfcUtil::IfcArgumentSelect::IfcArgumentSelect(IfcSchema::Type::Enum t, Argument* a) { _type = t; arg = a; }
Argument* IfcUtil::IfcArgumentSelect::wrappedValue() { return arg; }
bool IfcUtil::IfcArgumentSelect::isSimpleType() { return true; }
IfcUtil::IfcArgumentSelect::~IfcArgumentSelect() { delete arg; }
@@ -70,7 +70,7 @@ void Logger::SetOutput(std::ostream* l1, std::ostream* l2) {
log2 = &log_stream;
}
}
void Logger::Message(Logger::Severity type, const std::string& message, const IfcAbstractEntityPtr entity) {
void Logger::Message(Logger::Severity type, const std::string& message, IfcAbstractEntity* entity) {
if ( log2 && type >= verbosity ) {
(*log2) << "[" << severity_strings[type] << "] " << message << std::endl;
if ( entity ) (*log2) << entity->toString() << std::endl;
+113 -69
View File
@@ -32,71 +32,51 @@
#include "../ifcparse/Ifc2x3enum.h"
#endif
class IfcAbstractEntity;
//typedef SHARED_PTR<IfcAbstractEntity> IfcAbstractEntityPtr;
typedef IfcAbstractEntity* IfcAbstractEntityPtr;
class IfcEntityList;
typedef SHARED_PTR<IfcEntityList> IfcEntities;
class Argument;
//typedef SHARED_PTR<Argument> ArgumentPtr;
typedef Argument* ArgumentPtr;
template <class F, class T>
inline T* reinterpret_pointer_cast(F* from) {
return (T*)from;
//SHARED_PTR<void> v = std::tr1::static_pointer_cast<void,F>(from);
//return std::tr1::static_pointer_cast<T,void>(v);
}
class IfcEntityList;
class IfcEntityListList;
class IfcAbstractEntity;
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
};
}
namespace IfcUtil {
class IfcBaseClass {
public:
IfcAbstractEntityPtr entity;
virtual bool is(IfcSchema::Type::Enum v) const = 0;
virtual IfcSchema::Type::Enum type() const = 0;
};
class IfcBaseEntity : public IfcBaseClass {
public:
virtual unsigned int getArgumentCount() const = 0;
virtual ArgumentType getArgumentType(unsigned int i) const = 0;
virtual ArgumentPtr getArgument(unsigned int i) const = 0;
virtual const char* getArgumentName(unsigned int i) const = 0;
};
//typedef SHARED_PTR<IfcBaseClass> IfcSchemaEntity;
typedef IfcBaseClass* IfcSchemaEntity;
class IfcBaseClass {
public:
IfcAbstractEntity* entity;
virtual bool is(IfcSchema::Type::Enum v) const = 0;
virtual IfcSchema::Type::Enum type() const = 0;
};
class IfcBaseEntity : public IfcBaseClass {
public:
virtual unsigned int getArgumentCount() const = 0;
virtual ArgumentType getArgumentType(unsigned int i) const = 0;
virtual Argument* getArgument(unsigned int i) const = 0;
virtual const char* getArgumentName(unsigned int i) const = 0;
};
}
template <class T>
class IfcTemplatedEntityList;
class IfcEntityList {
std::vector<IfcUtil::IfcSchemaEntity> ls;
std::vector<IfcUtil::IfcBaseClass*> ls;
public:
typedef std::vector<IfcUtil::IfcSchemaEntity>::const_iterator it;
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);
typedef SHARED_PTR<IfcEntityList> ptr;
typedef std::vector<IfcUtil::IfcBaseClass*>::const_iterator it;
ptr getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL);
ptr getInverse(IfcSchema::Type::Enum c, int i, const std::string& a);
void push(IfcUtil::IfcBaseClass* l);
void push(const ptr& l);
it begin();
it end();
IfcUtil::IfcSchemaEntity operator[] (int i);
IfcUtil::IfcBaseClass* operator[] (int i);
int Size() const;
template <class U>
typename U::list as() {
typename U::list r(new IfcTemplatedEntityList<U>());
typename U::list::ptr as() {
typename U::list::ptr r(new typename U::list);
for ( it i = begin(); i != end(); ++ i ) if ((*i)->is(U::Class())) r->push((U*)*i);
return r;
}
@@ -106,38 +86,101 @@ template <class T>
class IfcTemplatedEntityList {
std::vector<T*> ls;
public:
typedef SHARED_PTR< IfcTemplatedEntityList<T> > ptr;
typedef typename std::vector<T*>::const_iterator it;
inline void push(T* t) {if (t) ls.push_back(t);}
inline void push(SHARED_PTR< IfcTemplatedEntityList<T> > t) { for ( typename T::it it = t->begin(); it != t->end(); ++it ) push(*it); }
inline void push(ptr t) { for ( typename T::list::it it = t->begin(); it != t->end(); ++it ) push(*it); }
inline it begin() { return ls.begin(); }
inline it end() { return ls.end(); }
inline unsigned int Size() const { return (unsigned int) ls.size(); }
IfcEntities generalize() {
IfcEntities r (new IfcEntityList());
IfcEntityList::ptr generalize() {
IfcEntityList::ptr 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>());
typename U::list::ptr as() {
typename U::list::ptr r(new typename U::list);
for ( it i = begin(); i != end(); ++ i ) if ((*i)->is(U::Class())) r->push(*i);
return r;
}
};
template <class T>
class IfcTemplatedEntityListList;
class IfcEntityListList {
std::vector< std::vector<IfcUtil::IfcBaseClass*> > ls;
public:
typedef SHARED_PTR< IfcEntityListList > ptr;
typedef std::vector< std::vector<IfcUtil::IfcBaseClass*> >::const_iterator outer_it;
typedef std::vector<IfcUtil::IfcBaseClass*>::const_iterator inner_it;
void push(const std::vector<IfcUtil::IfcBaseClass*>& l) {
ls.push_back(l);
}
void push(const IfcEntityList::ptr& l) {
std::vector<IfcUtil::IfcBaseClass*> li;
for (std::vector<IfcUtil::IfcBaseClass*>::const_iterator jt = l->begin(); jt != l->end(); ++jt) {
li.push_back(*jt);
}
push(li);
}
outer_it begin() { return ls.begin(); }
outer_it end() { return ls.end(); }
int Size() const { return ls.size(); }
template <class U>
typename IfcTemplatedEntityListList<U>::ptr as() {
typename IfcTemplatedEntityListList<U>::ptr r(new IfcTemplatedEntityListList<U>);
const bool all = U::Class() == IfcSchema::Type::ALL;
for (outer_it outer = begin(); outer != end(); ++ outer) {
const std::vector<IfcUtil::IfcBaseClass*>& from = *outer;
typename std::vector<U*> to;
for (inner_it inner = from.begin(); inner != from.end(); ++ inner) {
if (all || (*inner)->is(U::Class())) to.push_back((U*)*inner);
}
r->push(to);
}
return r;
}
};
template <class T>
class IfcTemplatedEntityListList {
std::vector< std::vector<T*> > ls;
public:
typedef typename SHARED_PTR< IfcTemplatedEntityListList<T> > ptr;
typedef typename std::vector< std::vector<T*> >::const_iterator outer_it;
typedef typename std::vector<T*>::const_iterator inner_it;
void push(const std::vector<T*>& t) {ls.push_back(t);}
outer_it begin() { return ls.begin(); }
outer_it end() { return ls.end(); }
unsigned int Size() const { return (unsigned int) ls.size(); }
IfcEntityListList::ptr generalize() {
IfcEntityListList::ptr r (new IfcEntityListList());
for (outer_it outer = begin(); outer != end(); ++ outer) {
const std::vector<T*>& from = *outer;
std::vector<IfcUtil::IfcBaseClass*> to;
for (inner_it inner = from.begin(); inner != from.end(); ++ inner) {
to.push_back(*inner);
}
r->push(to);
}
return r;
}
};
namespace IfcUtil {
class IfcAbstractSelect : public IfcBaseClass {
public:
typedef SHARED_PTR< IfcTemplatedEntityList<IfcAbstractSelect> > list;
typedef IfcTemplatedEntityList<IfcAbstractSelect>::it it;
typedef IfcAbstractSelect* ptr;
typedef IfcTemplatedEntityList<IfcAbstractSelect> list;
virtual bool isSimpleType() = 0;
static IfcSchema::Type::Enum Class() { return IfcSchema::Type::ALL; }
};
class IfcEntitySelect : public IfcAbstractSelect {
public:
typedef IfcEntitySelect* ptr;
IfcEntitySelect(IfcSchemaEntity b);
IfcEntitySelect(IfcAbstractEntityPtr e);
IfcEntitySelect(IfcBaseClass* b);
IfcEntitySelect(IfcAbstractEntity* e);
~IfcEntitySelect();
bool is(IfcSchema::Type::Enum v) const;
IfcSchema::Type::Enum type() const;
@@ -145,12 +188,12 @@ namespace IfcUtil {
};
class IfcArgumentSelect : public IfcAbstractSelect {
IfcSchema::Type::Enum _type;
ArgumentPtr arg;
Argument* arg;
public:
typedef IfcArgumentSelect* ptr;
IfcArgumentSelect(IfcSchema::Type::Enum t, ArgumentPtr a);
IfcArgumentSelect(IfcSchema::Type::Enum t, Argument* a);
~IfcArgumentSelect();
ArgumentPtr wrappedValue();
Argument* wrappedValue();
bool is(IfcSchema::Type::Enum v) const;
IfcSchema::Type::Enum type() const;
bool isSimpleType();
@@ -172,11 +215,12 @@ public:
virtual operator std::vector<double>() const = 0;
virtual operator std::vector<int>() const = 0;
virtual operator std::vector<std::string>() const = 0;
virtual operator IfcUtil::IfcSchemaEntity() const = 0;
virtual operator IfcUtil::IfcBaseClass*() const = 0;
//virtual operator IfcUtil::IfcAbstractSelect::ptr() const = 0;
virtual operator IfcEntities() const = 0;
virtual operator IfcEntityList::ptr() const = 0;
virtual operator IfcEntityListList::ptr() const = 0;
virtual unsigned int Size() const = 0;
virtual ArgumentPtr operator [] (unsigned int i) const = 0;
virtual Argument* operator [] (unsigned int i) const = 0;
virtual std::string toString(bool upper=false) const = 0;
virtual bool isNull() const = 0;
virtual ~Argument() {};
@@ -185,15 +229,15 @@ public:
class IfcAbstractEntity {
public:
IfcParse::IfcFile* file;
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 IfcEntityList::ptr getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL) = 0;
virtual IfcEntityList::ptr getInverse(IfcSchema::Type::Enum c, int i, const std::string& a) = 0;
virtual std::string datatype() const = 0;
virtual Argument* getArgument (unsigned int i) = 0;
virtual unsigned int getArgumentCount() const = 0;
virtual ~IfcAbstractEntity() {};
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 std::string toString(bool upper=false) const = 0;
virtual unsigned int id() = 0;
virtual bool isWritable() = 0;
};
@@ -214,7 +258,7 @@ public:
static void Verbosity(Severity v);
static Severity Verbosity();
/// Log a message to the output stream
static void Message(Severity type, const std::string& message, const IfcAbstractEntityPtr entity=0);
static void Message(Severity type, const std::string& message, IfcAbstractEntity* entity=0);
static void Status(const std::string& message, bool new_line=true);
static void ProgressBar(int progress);
static std::string GetLog();
+10 -9
View File
@@ -39,7 +39,7 @@ namespace IfcWrite {
class IfcWritableEntity : public IfcAbstractEntity {
private:
std::map<int,bool> writemask;
std::map<int,ArgumentPtr> args;
std::map<int,Argument*> args;
IfcSchema::Type::Enum _type;
int* _id;
bool arg_writable(int i);
@@ -50,14 +50,14 @@ namespace IfcWrite {
~IfcWritableEntity();
int setId(int i=-1);
IfcWritableEntity(IfcAbstractEntity* e);
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();
IfcEntityList::ptr getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL);
IfcEntityList::ptr getInverse(IfcSchema::Type::Enum c, int i, const std::string& a);
std::string datatype() const;
Argument* getArgument (unsigned int i);
unsigned int getArgumentCount() const;
IfcSchema::Type::Enum type() const;
bool is(IfcSchema::Type::Enum v) const;
std::string toString(bool upper=false);
std::string toString(bool upper=false) const;
unsigned int id();
bool isWritable();
void setArgument(int i);
@@ -67,8 +67,9 @@ namespace IfcWrite {
void setArgument(int i,int v, const char* c);
void setArgument(int i,const std::string& v);
void setArgument(int i,double v);
void setArgument(int i,IfcUtil::IfcSchemaEntity v);
void setArgument(int i,IfcEntities v);
void setArgument(int i,IfcUtil::IfcBaseClass* v);
void setArgument(int i,IfcEntityList::ptr v);
void setArgument(int i,IfcEntityListList::ptr v);
void setArgument(int i,const std::vector<double>& v);
void setArgument(int i,const std::vector<std::string>& v);
void setArgument(int i,const std::vector<int>& v);
+52 -31
View File
@@ -49,10 +49,10 @@ IfcWritableEntity::IfcWritableEntity(IfcAbstractEntity* e)
}
}
// TODO: Reove redundancy with IfcParse::Entity
IfcEntities IfcWritableEntity::getInverse(IfcSchema::Type::Enum c) {
IfcEntities l = IfcEntities(new IfcEntityList());
IfcEntityList::ptr IfcWritableEntity::getInverse(IfcSchema::Type::Enum c) {
IfcEntityList::ptr l = IfcEntityList::ptr(new IfcEntityList);
int id = _id ? *_id : setId();
IfcEntities all = file->EntitiesByReference(id);
IfcEntityList::ptr all = file->EntitiesByReference(id);
if ( ! all ) return l;
for( IfcEntityList::it it = all->begin(); it != all->end();++ it ) {
if ( c == IfcSchema::Type::ALL || (*it)->is(c) ) {
@@ -61,9 +61,9 @@ IfcEntities IfcWritableEntity::getInverse(IfcSchema::Type::Enum c) {
}
return l;
}
IfcEntities IfcWritableEntity::getInverse(IfcSchema::Type::Enum c, int i, const std::string& a) {
IfcEntities l = IfcEntities(new IfcEntityList());
IfcEntities all = getInverse(c);
IfcEntityList::ptr IfcWritableEntity::getInverse(IfcSchema::Type::Enum c, int i, const std::string& a) {
IfcEntityList::ptr l = IfcEntityList::ptr(new IfcEntityList);
IfcEntityList::ptr all = getInverse(c);
for( IfcEntityList::it it = all->begin(); it != all->end();++ it ) {
const std::string s = *(*it)->entity->getArgument(i);
if ( s == a ) {
@@ -73,12 +73,11 @@ IfcEntities IfcWritableEntity::getInverse(IfcSchema::Type::Enum c, int i, const
return l;
}
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(); }
std::string IfcWritableEntity::datatype() const { return IfcSchema::Type::ToString(_type); }
Argument* IfcWritableEntity::getArgument (unsigned int i) { if ( i >= getArgumentCount() ) throw IfcParse::IfcException("Argument not set"); return args[i]; }unsigned int IfcWritableEntity::getArgumentCount() const {return args.size(); }
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::string IfcWritableEntity::toString(bool upper) const {
std::stringstream ss;
std::string dt = datatype();
if ( upper ) {
@@ -86,9 +85,9 @@ std::string IfcWritableEntity::toString(bool upper) {
}
if ( _id ) ss << "#" << *_id;
ss << "=" << dt << "(";
for ( std::map<int,ArgumentPtr>::const_iterator it = args.begin(); it != args.end(); ++ it ) {
for ( std::map<int,Argument*>::const_iterator it = args.begin(); it != args.end(); ++ it ) {
if ( it != args.begin() ) ss << ",";
const ArgumentPtr a = it->second;
const Argument* a = it->second;
ss << it->second->toString(upper);
}
ss << ")";
@@ -139,14 +138,21 @@ void IfcWritableEntity::setArgument(int i,const std::string& v){
void IfcWritableEntity::setArgument(int i,double v){
_setArgument(i, v);
}
void IfcWritableEntity::setArgument(int i,IfcUtil::IfcSchemaEntity v){
void IfcWritableEntity::setArgument(int i,IfcUtil::IfcBaseClass* v){
if ( v ) {
_setArgument(i, v);
} else {
_setArgument(i, boost::none);
}
}
void IfcWritableEntity::setArgument(int i,IfcEntities v){
void IfcWritableEntity::setArgument(int i,IfcEntityList::ptr v){
if ( v.get() ) {
_setArgument(i, v);
} else {
_setArgument(i, boost::none);
}
}
void IfcWritableEntity::setArgument(int i,IfcEntityListList::ptr v){
if ( v.get() ) {
_setArgument(i, v);
} else {
@@ -175,8 +181,9 @@ public:
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(); }
int operator()(const IfcUtil::IfcBaseClass* const& i) const { return -1; }
int operator()(const IfcEntityList::ptr& i) const { return i->Size(); }
int operator()(const IfcEntityListList::ptr& i) const { return i->Size(); }
};
class StringBuilderVisitor : public boost::static_visitor<void> {
@@ -241,7 +248,7 @@ public:
void operator()(const IfcWriteArgument::EnumerationReference& i) {
data << "." << i.enumeration_value << ".";
}
void operator()(const IfcUtil::IfcSchemaEntity& i) {
void operator()(const IfcUtil::IfcBaseClass* const& i) {
IfcAbstractEntity* e = i->entity;
if ( IfcSchema::Type::IsSimple(e->type()) ) {
data << e->toString(upper);
@@ -249,7 +256,7 @@ public:
data << "#" << e->id();
}
}
void operator()(const IfcEntities& i) {
void operator()(const IfcEntityList::ptr& i) {
data << "(";
for (IfcEntityList::it it = i->begin(); it != i->end(); ++it) {
if (it != i->begin()) data << ",";
@@ -257,6 +264,19 @@ public:
}
data << ")";
}
void operator()(const IfcEntityListList::ptr& i) {
data << "(";
for (IfcEntityListList::outer_it outer_it = i->begin(); outer_it != i->end(); ++outer_it) {
data << "(";
if (outer_it != i->begin()) data << ",";
for (IfcEntityListList::inner_it inner_it = outer_it->begin(); inner_it != outer_it->end(); ++inner_it) {
if (inner_it != outer_it->begin()) data << ",";
(*this)(*inner_it);
}
data << ")";
}
data << ")";
}
operator std::string() { return data.str(); }
};
@@ -267,10 +287,11 @@ 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>(); }
IfcWriteArgument::operator IfcUtil::IfcBaseClass*() const { return as<IfcUtil::IfcBaseClass*>(); }
IfcWriteArgument::operator IfcEntityList::ptr() const { return as<IfcEntityList::ptr>(); }
IfcWriteArgument::operator IfcEntityListList::ptr() const { throw; }
bool IfcWriteArgument::isNull() const { return argumentType() == argument_type_null; }
ArgumentPtr IfcWriteArgument::operator [] (unsigned int i) const { throw IfcParse::IfcException("Invalid cast"); }
Argument* 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);
@@ -290,17 +311,17 @@ IfcWriteArgument::argument_type IfcWriteArgument::argumentType() const {
return static_cast<argument_type>(container.which());
}
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) {
IfcEntityList::ptr IfcSelectHelperEntity::getInverse(IfcSchema::Type::Enum,int,const std::string &) {throw IfcParse::IfcException("Invalid cast");}
IfcEntityList::ptr IfcSelectHelperEntity::getInverse(IfcSchema::Type::Enum) {throw IfcParse::IfcException("Invalid cast");}
std::string IfcSelectHelperEntity::datatype() const { return IfcSchema::Type::ToString(_type); }
Argument* IfcSelectHelperEntity::getArgument(unsigned int i) {
if ( i != 0 ) throw IfcParse::IfcException("Invalid cast");
return arg;
}
unsigned int IfcSelectHelperEntity::getArgumentCount() { return 1; }
unsigned int IfcSelectHelperEntity::getArgumentCount() const { return 1; }
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::string IfcSelectHelperEntity::toString(bool upper) const {
std::stringstream ss;
std::string dt = datatype();
if ( upper ) {
@@ -344,16 +365,16 @@ EntityBuffer* EntityBuffer::i = 0;
EntityBuffer* EntityBuffer::instance() {
if ( ! i ) {
i = new EntityBuffer();
i->buffer = IfcEntities(new IfcEntityList());
i->buffer = IfcEntityList::ptr(new IfcEntityList);
}
return i;
}
IfcEntities EntityBuffer::Get() {
IfcEntityList::ptr EntityBuffer::Get() {
return instance()->buffer;
}
void EntityBuffer::Clear() {
instance()->buffer = IfcEntities(new IfcEntityList());
instance()->buffer = IfcEntityList::ptr(new IfcEntityList);
}
void EntityBuffer::Add(IfcUtil::IfcSchemaEntity e) {
void EntityBuffer::Add(IfcUtil::IfcBaseClass* e) {
instance()->buffer->push(e);
}
+20 -16
View File
@@ -82,11 +82,13 @@ namespace IfcWrite {
// 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,
IfcUtil::IfcBaseClass*,
// 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
IfcEntityList::ptr,
// A list of list of entities. E.g. ((#1, #2), (#3))
IfcEntityListList::ptr
> container;
public:
enum argument_type {
@@ -100,8 +102,9 @@ namespace IfcWrite {
argument_type_vector_double,
argument_type_vector_string,
argument_type_enumeration,
argument_type_schema_entity,
argument_type_entities
argument_type_entity,
argument_type_entity_list,
argument_type_entity_list_list
};
IfcWriteArgument(IfcAbstractEntity* e) : entity(e) {}
template <typename T> const T& as() const {
@@ -121,10 +124,11 @@ namespace IfcWrite {
operator std::vector<double>() const;
operator std::vector<int>() const;
operator std::vector<std::string>() const;
operator IfcUtil::IfcSchemaEntity() const;
operator IfcEntities() const;
operator IfcUtil::IfcBaseClass*() const;
operator IfcEntityList::ptr() const;
operator IfcEntityListList::ptr() const;
bool isNull() const;
ArgumentPtr operator [] (unsigned int i) const;
Argument* operator [] (unsigned int i) const;
std::string toString(bool upper=false) const;
unsigned int Size() const;
argument_type argumentType() const;
@@ -141,14 +145,14 @@ namespace IfcWrite {
public:
// FIXME: Make this a non-pointer argument and implement a copy constructor
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();
IfcEntityList::ptr getInverse(IfcSchema::Type::Enum,int,const std::string &);
IfcEntityList::ptr getInverse(IfcSchema::Type::Enum);
std::string datatype() const;
Argument* getArgument(unsigned int i);
unsigned int getArgumentCount() const;
IfcSchema::Type::Enum type() const;
bool is(IfcSchema::Type::Enum t) const;
std::string toString(bool upper = false);
std::string toString(bool upper = false) const;
unsigned int id();
bool isWritable();
};
@@ -183,13 +187,13 @@ namespace IfcWrite {
// This way they can be added in a single batch to the IfcFile
class EntityBuffer {
private:
IfcEntities buffer;
IfcEntityList::ptr buffer;
static EntityBuffer* i;
static EntityBuffer* instance();
public:
static IfcEntities Get();
static IfcEntityList::ptr Get();
static void Clear();
static void Add(IfcUtil::IfcSchemaEntity e);
static void Add(IfcUtil::IfcBaseClass* e);
};
}