mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Add id() and is_a() functions to entity_instance class Make filename argument to open() function optional
This commit is contained in:
@@ -30,6 +30,13 @@ IfcParse::IfcUntypedEntity::IfcUntypedEntity(IfcAbstractEntity* e) {
|
||||
entity = e;
|
||||
_type = e->type();
|
||||
}
|
||||
unsigned int IfcParse::IfcUntypedEntity::id() const {
|
||||
if (entity->file) {
|
||||
return static_cast<unsigned int>(entity->id());
|
||||
} else {
|
||||
throw IfcException("Entity not bound to a file");
|
||||
}
|
||||
}
|
||||
bool IfcParse::IfcUntypedEntity::is(IfcSchema::Type::Enum v) const {
|
||||
IfcSchema::Type::Enum _ty = _type;
|
||||
if (v == _ty) return true;
|
||||
|
||||
@@ -17,10 +17,13 @@ namespace IfcParse {
|
||||
public:
|
||||
IfcUntypedEntity(const std::string& s);
|
||||
IfcUntypedEntity(IfcAbstractEntity* e);
|
||||
|
||||
bool is(IfcSchema::Type::Enum v) const;
|
||||
IfcSchema::Type::Enum type() const;
|
||||
bool is_a(const std::string& s) const;
|
||||
std::string is_a() const;
|
||||
|
||||
unsigned int id() const;
|
||||
unsigned int getArgumentCount() const;
|
||||
IfcUtil::ArgumentType getArgumentType(unsigned int i) const;
|
||||
ArgumentPtr getArgument(unsigned int i) const;
|
||||
|
||||
@@ -17,10 +17,13 @@ namespace IfcParse {
|
||||
IfcSchema::Type::Enum _type;
|
||||
public:
|
||||
IfcUntypedEntity(const std::string& s);
|
||||
|
||||
bool is(IfcSchema::Type::Enum v) const;
|
||||
IfcSchema::Type::Enum type() const;
|
||||
bool is_a(const std::string& s) const;
|
||||
std::string is_a() const;
|
||||
|
||||
unsigned int id() const;
|
||||
unsigned int getArgumentCount() const;
|
||||
IfcUtil::ArgumentType getArgumentType(unsigned int i) const;
|
||||
ArgumentPtr getArgument(unsigned int i) const;
|
||||
|
||||
+6
-4
@@ -43,12 +43,14 @@ class entity_instance:
|
||||
self.wrapped_data.set_argument(idx, entity_instance.map_value(value))
|
||||
def __len__(self): return len(self.wrapped_data)
|
||||
def __repr__(self): return repr(self.wrapped_data)
|
||||
def is_a(self, *args): return self.wrapped_data.is_a(*args)
|
||||
def id(self): return self.wrapped_data.id()
|
||||
|
||||
|
||||
class file:
|
||||
instances = []
|
||||
def __init__(self, f):
|
||||
self.wrapped_data = f
|
||||
def __init__(self, f=None):
|
||||
self.wrapped_data = f or ifc_wrapper.file()
|
||||
def create_entity(self,type,*args,**kwargs):
|
||||
e = entity_instance(ifc_wrapper.entity_instance(type))
|
||||
attrs = list(enumerate(args)) + \
|
||||
@@ -94,8 +96,8 @@ class guid:
|
||||
return '{%s-%s-%s-%s-%s}'%(g[:8], g[8:12], g[12:16], g[16:20], g[20:])
|
||||
|
||||
|
||||
def open(fn):
|
||||
return file(ifc_wrapper.open(fn))
|
||||
def open(fn=None):
|
||||
return file(ifc_wrapper.open(fn)) if fn else file()
|
||||
|
||||
def create_shape(inst, settings): return ifc_wrapper.create_shape(inst.wrapped_data, settings)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user