Skip to content

Commit d4e4ca3

Browse files
committed
Add id() and is_a() functions to entity_instance class Make filename argument to open() function optional
1 parent f7adeb9 commit d4e4ca3

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/ifcparse/IfcUntypedEntity.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ IfcParse::IfcUntypedEntity::IfcUntypedEntity(IfcAbstractEntity* e) {
3030
entity = e;
3131
_type = e->type();
3232
}
33+
unsigned int IfcParse::IfcUntypedEntity::id() const {
34+
if (entity->file) {
35+
return static_cast<unsigned int>(entity->id());
36+
} else {
37+
throw IfcException("Entity not bound to a file");
38+
}
39+
}
3340
bool IfcParse::IfcUntypedEntity::is(IfcSchema::Type::Enum v) const {
3441
IfcSchema::Type::Enum _ty = _type;
3542
if (v == _ty) return true;

src/ifcparse/IfcUntypedEntity.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ namespace IfcParse {
1717
public:
1818
IfcUntypedEntity(const std::string& s);
1919
IfcUntypedEntity(IfcAbstractEntity* e);
20+
2021
bool is(IfcSchema::Type::Enum v) const;
2122
IfcSchema::Type::Enum type() const;
2223
bool is_a(const std::string& s) const;
2324
std::string is_a() const;
25+
26+
unsigned int id() const;
2427
unsigned int getArgumentCount() const;
2528
IfcUtil::ArgumentType getArgumentType(unsigned int i) const;
2629
ArgumentPtr getArgument(unsigned int i) const;

src/ifcwrap/Interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ namespace IfcParse {
1717
IfcSchema::Type::Enum _type;
1818
public:
1919
IfcUntypedEntity(const std::string& s);
20+
2021
bool is(IfcSchema::Type::Enum v) const;
2122
IfcSchema::Type::Enum type() const;
2223
bool is_a(const std::string& s) const;
2324
std::string is_a() const;
25+
26+
unsigned int id() const;
2427
unsigned int getArgumentCount() const;
2528
IfcUtil::ArgumentType getArgumentType(unsigned int i) const;
2629
ArgumentPtr getArgument(unsigned int i) const;

src/ifcwrap/ifc.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ def __setitem__(self, idx, value):
4343
self.wrapped_data.set_argument(idx, entity_instance.map_value(value))
4444
def __len__(self): return len(self.wrapped_data)
4545
def __repr__(self): return repr(self.wrapped_data)
46+
def is_a(self, *args): return self.wrapped_data.is_a(*args)
47+
def id(self): return self.wrapped_data.id()
4648

4749

4850
class file:
4951
instances = []
50-
def __init__(self, f):
51-
self.wrapped_data = f
52+
def __init__(self, f=None):
53+
self.wrapped_data = f or ifc_wrapper.file()
5254
def create_entity(self,type,*args,**kwargs):
5355
e = entity_instance(ifc_wrapper.entity_instance(type))
5456
attrs = list(enumerate(args)) + \
@@ -94,8 +96,8 @@ def split(g):
9496
return '{%s-%s-%s-%s-%s}'%(g[:8], g[8:12], g[12:16], g[16:20], g[20:])
9597

9698

97-
def open(fn):
98-
return file(ifc_wrapper.open(fn))
99+
def open(fn=None):
100+
return file(ifc_wrapper.open(fn)) if fn else file()
99101

100102
def create_shape(inst, settings): return ifc_wrapper.create_shape(inst.wrapped_data, settings)
101103

0 commit comments

Comments
 (0)