mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-10-03 05:22:06 +00:00
Reflection of object properties.
This commit is contained in:
@@ -28,7 +28,7 @@ header = """
|
|||||||
# #
|
# #
|
||||||
# Note this script uses funcparserlib, which is available at: #
|
# Note this script uses funcparserlib, which is available at: #
|
||||||
# http://code.google.com/p/funcparserlib/ #
|
# http://code.google.com/p/funcparserlib/ #
|
||||||
# The script only works with revision e1df5066addd because it uses the some() #
|
# The script only works with revision 30f7ee896bc9 because it uses the some() #
|
||||||
# parser and is incompatible with other changes as well. #
|
# parser and is incompatible with other changes as well. #
|
||||||
# #
|
# #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -95,7 +95,7 @@ schema_version = ''
|
|||||||
enumerations = set()
|
enumerations = set()
|
||||||
selections = set()
|
selections = set()
|
||||||
entity_names = set()
|
entity_names = set()
|
||||||
simple_types = set()
|
simple_types = {}
|
||||||
selectable_simple_types = set()
|
selectable_simple_types = set()
|
||||||
argument_count = {}
|
argument_count = {}
|
||||||
parent_relations = {}
|
parent_relations = {}
|
||||||
@@ -127,9 +127,36 @@ class ArrayType:
|
|||||||
return "SHARED_PTR< IfcTemplatedEntityList<IfcAbstractSelect> >"
|
return "SHARED_PTR< IfcTemplatedEntityList<IfcAbstractSelect> >"
|
||||||
else:
|
else:
|
||||||
return "std::vector<%(type)s> /*[%(lower)s:%(upper)s]*/"%self.__dict__
|
return "std::vector<%(type)s> /*[%(lower)s:%(upper)s]*/"%self.__dict__
|
||||||
|
def type_enum(self):
|
||||||
|
if self.type in simple_types:
|
||||||
|
t = simple_types[self.type].type_enum()
|
||||||
|
else:
|
||||||
|
t = self.type
|
||||||
|
if t in entity_names or t == "ENTITY":
|
||||||
|
return "ENTITY_LIST"
|
||||||
|
elif t in selections:
|
||||||
|
return "ENTITY_LIST"
|
||||||
|
elif t == "int":
|
||||||
|
return "VECTOR_INT"
|
||||||
|
elif t == "double" or t == "DOUBLE":
|
||||||
|
return "VECTOR_DOUBLE"
|
||||||
|
elif t == "std::string" or t == "STRING":
|
||||||
|
return "VECTOR_STRING"
|
||||||
|
elif isinstance(t, BinaryType):
|
||||||
|
return "UNKNOWN"
|
||||||
|
else:
|
||||||
|
assert False, t
|
||||||
|
|
||||||
class ScalarType:
|
class ScalarType:
|
||||||
def __init__(self,l): self.type = express_to_cpp.get(l,l)
|
def __init__(self,l): self.type = express_to_cpp.get(l,l)
|
||||||
def __str__(self): return self.type
|
def __str__(self): return self.type
|
||||||
|
def type_enum(self):
|
||||||
|
if self.type in simple_types:
|
||||||
|
return simple_types[self.type].type_enum()
|
||||||
|
elif self.type in entity_names:
|
||||||
|
return "ENTITY"
|
||||||
|
else:
|
||||||
|
return { "bool":"BOOL","int":"INT","double":"DOUBLE","std::string":"STRING"}[self.type]
|
||||||
class EnumType:
|
class EnumType:
|
||||||
def __init__(self,l):
|
def __init__(self,l):
|
||||||
self.v = [(x,'%s_%s'%('%(fancy_name)s',x)) for x in l]
|
self.v = [(x,'%s_%s'%('%(fancy_name)s',x)) for x in l]
|
||||||
@@ -142,17 +169,22 @@ class EnumType:
|
|||||||
elif generator_mode == 'SOURCE_FROM':
|
elif generator_mode == 'SOURCE_FROM':
|
||||||
return "".join([' if(s=="%s"%s) return %s::%s;\n'%(v1.upper()," "*(self.maxlen-len(v1)),"%(name)s",v2) for v1,v2 in self.v])
|
return "".join([' if(s=="%s"%s) return %s::%s;\n'%(v1.upper()," "*(self.maxlen-len(v1)),"%(name)s",v2) for v1,v2 in self.v])
|
||||||
def __len__(self): return len(self.v)
|
def __len__(self): return len(self.v)
|
||||||
|
def type_enum(self):
|
||||||
|
return "ENUMERATION"
|
||||||
class SelectType:
|
class SelectType:
|
||||||
def __init__(self,l):
|
def __init__(self,l):
|
||||||
for x in l:
|
for x in l:
|
||||||
if x in simple_types: selectable_simple_types.add(x)
|
if x in simple_types: selectable_simple_types.add(x)
|
||||||
def __str__(self): return "IfcSchemaEntity"
|
def __str__(self): return "IfcSchemaEntity"
|
||||||
|
def type_enum(self): return "ENTITY"
|
||||||
class BinaryType:
|
class BinaryType:
|
||||||
def __init__(self,l): self.l = int(l)
|
def __init__(self,l): self.l = int(l)
|
||||||
def __str__(self): return "char[%s]"%self.l
|
def __str__(self): return "char[%s]"%self.l
|
||||||
|
def type_enum(self): raise NotImplementedError()
|
||||||
class InverseType:
|
class InverseType:
|
||||||
def __init__(self,l):
|
def __init__(self,l):
|
||||||
self.name, self.type, self.reference = l
|
self.name, self.type, self.reference = l
|
||||||
|
def type_enum(self): return "ENTITY"
|
||||||
class Typedef:
|
class Typedef:
|
||||||
def __init__(self,l):
|
def __init__(self,l):
|
||||||
self.name,self.type=l[1:3]
|
self.name,self.type=l[1:3]
|
||||||
@@ -161,7 +193,7 @@ class Typedef:
|
|||||||
enumerations.add(self.name)
|
enumerations.add(self.name)
|
||||||
self.len = len(self.type)
|
self.len = len(self.type)
|
||||||
elif isinstance(self.type,SelectType): selections.add(self.name)
|
elif isinstance(self.type,SelectType): selections.add(self.name)
|
||||||
simple_types.add(self.name)
|
simple_types[self.name] = self
|
||||||
comment = IfcDocumentation.description(self.name)
|
comment = IfcDocumentation.description(self.name)
|
||||||
self.comment = comment+"\n" if comment else ''
|
self.comment = comment+"\n" if comment else ''
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -177,6 +209,8 @@ class Typedef:
|
|||||||
s += ("%(name)s::%(name)s %(name)s::FromString(const std::string& s) {\n%(type)s throw IfcException(\"Unable to find find keyword in schema\");\n}"%self.__dict__)%self.__dict__
|
s += ("%(name)s::%(name)s %(name)s::FromString(const std::string& s) {\n%(type)s throw IfcException(\"Unable to find find keyword in schema\");\n}"%self.__dict__)%self.__dict__
|
||||||
generator_mode = 'SOURCE'
|
generator_mode = 'SOURCE'
|
||||||
return s
|
return s
|
||||||
|
def type_enum(self):
|
||||||
|
return self.type.type_enum()
|
||||||
class Argument(object):
|
class Argument(object):
|
||||||
def __init__(self,l):
|
def __init__(self,l):
|
||||||
self.name, self.optional, self.type = l
|
self.name, self.optional, self.type = l
|
||||||
@@ -220,6 +254,33 @@ class ArgumentList:
|
|||||||
return_type = "%(type)s*"%a.__dict__
|
return_type = "%(type)s*"%a.__dict__
|
||||||
s += "\n%s%s%s %s%s()%s"%(comment,indent,return_type,class_name,a.name,function_body)
|
s += "\n%s%s%s %s%s()%s"%(comment,indent,return_type,class_name,a.name,function_body)
|
||||||
argv += 1
|
argv += 1
|
||||||
|
|
||||||
|
if generator_mode == 'HEADER':
|
||||||
|
s += "\n virtual unsigned int getArgumentCount() const { return %(n_arguments)d; }" % dict(class_name=self.class_name, n_arguments=len(self.l) + argument_start(self.class_name))
|
||||||
|
|
||||||
|
s += "\n virtual ArgumentType getArgumentType(unsigned int i) const {"
|
||||||
|
s += " switch (i) {"
|
||||||
|
for i, a in enumerate(self.l):
|
||||||
|
s += "case %d: " % (i + argument_start(self.class_name))
|
||||||
|
s += "return %s; " % a.type.type_enum()
|
||||||
|
s += "}"
|
||||||
|
if self.parent_class is not None:
|
||||||
|
s += " return %s::getArgumentType(i); }" % self.parent_class
|
||||||
|
else:
|
||||||
|
s += " throw IfcException(\"argument out of range\"); }"
|
||||||
|
|
||||||
|
s += "\n virtual const char* getArgumentName(unsigned int i) const {"
|
||||||
|
s += " switch (i) {"
|
||||||
|
for i, a in enumerate(self.l):
|
||||||
|
s += "case %d: " % (i + argument_start(self.class_name))
|
||||||
|
s += "return \"%s\"; " % a.name
|
||||||
|
s += "}"
|
||||||
|
if self.parent_class is not None:
|
||||||
|
s += " return %s::getArgumentName(i); }" % self.parent_class
|
||||||
|
else:
|
||||||
|
s += " throw IfcException(\"argument out of range\"); }"
|
||||||
|
|
||||||
|
s += "\n virtual ArgumentPtr getArgument(unsigned int i) const { return entity->getArgument(i); }"
|
||||||
return s
|
return s
|
||||||
class InverseList:
|
class InverseList:
|
||||||
def __init__(self,l):
|
def __init__(self,l):
|
||||||
@@ -237,6 +298,7 @@ class Classdef:
|
|||||||
def __init__(self,l):
|
def __init__(self,l):
|
||||||
self.class_name, self.parent_class, self.arguments, self.inverse = l
|
self.class_name, self.parent_class, self.arguments, self.inverse = l
|
||||||
self.arguments.class_name = self.class_name
|
self.arguments.class_name = self.class_name
|
||||||
|
self.arguments.parent_class = self.parent_class
|
||||||
entity_names.add(self.class_name)
|
entity_names.add(self.class_name)
|
||||||
parent_relations[self.class_name] = self.parent_class
|
parent_relations[self.class_name] = self.parent_class
|
||||||
argument_count[self.class_name] = len(self.arguments)
|
argument_count[self.class_name] = len(self.arguments)
|
||||||
@@ -245,7 +307,7 @@ class Classdef:
|
|||||||
comment = IfcDocumentation.description(self.class_name)
|
comment = IfcDocumentation.description(self.class_name)
|
||||||
comment = comment+"\n" if comment else ''
|
comment = comment+"\n" if comment else ''
|
||||||
return "%sclass %s : public %s {\npublic:%s%s%s\n};" % (comment,self.class_name,
|
return "%sclass %s : public %s {\npublic:%s%s%s\n};" % (comment,self.class_name,
|
||||||
"IfcBaseClass" if self.parent_class is None else self.parent_class,
|
"IfcBaseEntity" if self.parent_class is None else self.parent_class,
|
||||||
self.arguments,
|
self.arguments,
|
||||||
self.inverse,
|
self.inverse,
|
||||||
("\n bool is(Type::Enum v) const;"+
|
("\n bool is(Type::Enum v) const;"+
|
||||||
@@ -354,9 +416,11 @@ print >>h_file, """#ifndef %(schema_upper)s_H
|
|||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "../ifcparse/IfcUtil.h"
|
#include "../ifcparse/IfcUtil.h"
|
||||||
|
#include "../ifcparse/IfcException.h"
|
||||||
#include "../ifcparse/%(schema)senum.h"
|
#include "../ifcparse/%(schema)senum.h"
|
||||||
|
|
||||||
using namespace IfcUtil;
|
using namespace IfcUtil;
|
||||||
|
using IfcParse::IfcException;
|
||||||
|
|
||||||
#define RETURN_INVERSE(T) \\
|
#define RETURN_INVERSE(T) \\
|
||||||
IfcEntities e = entity->getInverse(T::Class()); \\
|
IfcEntities e = entity->getInverse(T::Class()); \\
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* *
|
* *
|
||||||
* This file has been generated from IFC2X3_TC1.exp. Do not make modifications *
|
* This file has been generated from /tmp/IFC2X3_FINAL.exp. Do not make modifications *
|
||||||
* but instead modify the python script that has been used to generate this. *
|
* but instead modify the python script that has been used to generate this. *
|
||||||
* *
|
* *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
@@ -6283,11 +6283,11 @@ IfcElectricalElement::IfcElectricalElement(IfcAbstractEntityPtr e) { if (!is(Typ
|
|||||||
// Function implementations for IfcElement
|
// Function implementations for IfcElement
|
||||||
bool IfcElement::hasTag() { return !entity->getArgument(7)->isNull(); }
|
bool IfcElement::hasTag() { return !entity->getArgument(7)->isNull(); }
|
||||||
IfcIdentifier IfcElement::Tag() { return *entity->getArgument(7); }
|
IfcIdentifier IfcElement::Tag() { return *entity->getArgument(7); }
|
||||||
IfcRelConnectsStructuralElement::list IfcElement::HasStructuralMember() { RETURN_INVERSE(IfcRelConnectsStructuralElement) }
|
|
||||||
IfcRelFillsElement::list IfcElement::FillsVoids() { RETURN_INVERSE(IfcRelFillsElement) }
|
IfcRelFillsElement::list IfcElement::FillsVoids() { RETURN_INVERSE(IfcRelFillsElement) }
|
||||||
IfcRelConnectsElements::list IfcElement::ConnectedTo() { RETURN_INVERSE(IfcRelConnectsElements) }
|
IfcRelConnectsElements::list IfcElement::ConnectedTo() { RETURN_INVERSE(IfcRelConnectsElements) }
|
||||||
IfcRelCoversBldgElements::list IfcElement::HasCoverings() { RETURN_INVERSE(IfcRelCoversBldgElements) }
|
IfcRelCoversBldgElements::list IfcElement::HasCoverings() { RETURN_INVERSE(IfcRelCoversBldgElements) }
|
||||||
IfcRelProjectsElement::list IfcElement::HasProjections() { RETURN_INVERSE(IfcRelProjectsElement) }
|
IfcRelProjectsElement::list IfcElement::HasProjections() { RETURN_INVERSE(IfcRelProjectsElement) }
|
||||||
|
IfcRelConnectsStructuralElement::list IfcElement::HasStructuralMember() { RETURN_INVERSE(IfcRelConnectsStructuralElement) }
|
||||||
IfcRelReferencedInSpatialStructure::list IfcElement::ReferencedInStructures() { RETURN_INVERSE(IfcRelReferencedInSpatialStructure) }
|
IfcRelReferencedInSpatialStructure::list IfcElement::ReferencedInStructures() { RETURN_INVERSE(IfcRelReferencedInSpatialStructure) }
|
||||||
IfcRelConnectsPortToElement::list IfcElement::HasPorts() { RETURN_INVERSE(IfcRelConnectsPortToElement) }
|
IfcRelConnectsPortToElement::list IfcElement::HasPorts() { RETURN_INVERSE(IfcRelConnectsPortToElement) }
|
||||||
IfcRelVoidsElement::list IfcElement::HasOpenings() { RETURN_INVERSE(IfcRelVoidsElement) }
|
IfcRelVoidsElement::list IfcElement::HasOpenings() { RETURN_INVERSE(IfcRelVoidsElement) }
|
||||||
@@ -9071,7 +9071,7 @@ IfcLoadGroupTypeEnum::IfcLoadGroupTypeEnum IfcStructuralLoadGroup::PredefinedTyp
|
|||||||
IfcActionTypeEnum::IfcActionTypeEnum IfcStructuralLoadGroup::ActionType() { return IfcActionTypeEnum::FromString(*entity->getArgument(6)); }
|
IfcActionTypeEnum::IfcActionTypeEnum IfcStructuralLoadGroup::ActionType() { return IfcActionTypeEnum::FromString(*entity->getArgument(6)); }
|
||||||
IfcActionSourceTypeEnum::IfcActionSourceTypeEnum IfcStructuralLoadGroup::ActionSource() { return IfcActionSourceTypeEnum::FromString(*entity->getArgument(7)); }
|
IfcActionSourceTypeEnum::IfcActionSourceTypeEnum IfcStructuralLoadGroup::ActionSource() { return IfcActionSourceTypeEnum::FromString(*entity->getArgument(7)); }
|
||||||
bool IfcStructuralLoadGroup::hasCoefficient() { return !entity->getArgument(8)->isNull(); }
|
bool IfcStructuralLoadGroup::hasCoefficient() { return !entity->getArgument(8)->isNull(); }
|
||||||
IfcRatioMeasure IfcStructuralLoadGroup::Coefficient() { return *entity->getArgument(8); }
|
IfcPositiveRatioMeasure IfcStructuralLoadGroup::Coefficient() { return *entity->getArgument(8); }
|
||||||
bool IfcStructuralLoadGroup::hasPurpose() { return !entity->getArgument(9)->isNull(); }
|
bool IfcStructuralLoadGroup::hasPurpose() { return !entity->getArgument(9)->isNull(); }
|
||||||
IfcLabel IfcStructuralLoadGroup::Purpose() { return *entity->getArgument(9); }
|
IfcLabel IfcStructuralLoadGroup::Purpose() { return *entity->getArgument(9); }
|
||||||
IfcStructuralResultGroup::list IfcStructuralLoadGroup::SourceOfResultGroup() { RETURN_INVERSE(IfcStructuralResultGroup) }
|
IfcStructuralResultGroup::list IfcStructuralLoadGroup::SourceOfResultGroup() { RETURN_INVERSE(IfcStructuralResultGroup) }
|
||||||
|
|||||||
+2720
-106
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* *
|
* *
|
||||||
* This file has been generated from IFC2X3_TC1.exp. Do not make modifications *
|
* This file has been generated from /tmp/IFC2X3_FINAL.exp. Do not make modifications *
|
||||||
* but instead modify the python script that has been used to generate this. *
|
* but instead modify the python script that has been used to generate this. *
|
||||||
* *
|
* *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|||||||
+19
-4
@@ -33,6 +33,11 @@ typedef IfcAbstractEntity* IfcAbstractEntityPtr;
|
|||||||
class IfcEntityList;
|
class IfcEntityList;
|
||||||
typedef SHARED_PTR<IfcEntityList> IfcEntities;
|
typedef SHARED_PTR<IfcEntityList> IfcEntities;
|
||||||
|
|
||||||
|
class Argument;
|
||||||
|
//typedef SHARED_PTR<Argument> ArgumentPtr;
|
||||||
|
typedef Argument* ArgumentPtr;
|
||||||
|
|
||||||
|
|
||||||
template <class F, class T>
|
template <class F, class T>
|
||||||
inline T* reinterpret_pointer_cast(F* from) {
|
inline T* reinterpret_pointer_cast(F* from) {
|
||||||
return (T*)from;
|
return (T*)from;
|
||||||
@@ -40,6 +45,12 @@ inline T* reinterpret_pointer_cast(F* from) {
|
|||||||
//return std::tr1::static_pointer_cast<T,void>(v);
|
//return std::tr1::static_pointer_cast<T,void>(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace IfcUtil {
|
||||||
|
enum ArgumentType {
|
||||||
|
INT, BOOL, DOUBLE, STRING, VECTOR_INT, VECTOR_DOUBLE, VECTOR_STRING, ENTITY, ENTITY_LIST, ENUMERATION, UNKNOWN
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
namespace IfcUtil {
|
namespace IfcUtil {
|
||||||
|
|
||||||
class IfcBaseClass {
|
class IfcBaseClass {
|
||||||
@@ -49,6 +60,14 @@ public:
|
|||||||
virtual Ifc2x3::Type::Enum type() const = 0;
|
virtual Ifc2x3::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 SHARED_PTR<IfcBaseClass> IfcSchemaEntity;
|
||||||
typedef IfcBaseClass* IfcSchemaEntity;
|
typedef IfcBaseClass* IfcSchemaEntity;
|
||||||
|
|
||||||
@@ -81,10 +100,6 @@ public:
|
|||||||
inline unsigned int Size() const { return (unsigned int) ls.size(); }
|
inline unsigned int Size() const { return (unsigned int) ls.size(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Argument;
|
|
||||||
//typedef SHARED_PTR<Argument> ArgumentPtr;
|
|
||||||
typedef Argument* ArgumentPtr;
|
|
||||||
|
|
||||||
namespace IfcUtil {
|
namespace IfcUtil {
|
||||||
class IfcAbstractSelect : public IfcBaseClass {
|
class IfcAbstractSelect : public IfcBaseClass {
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user