mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 10:57:49 +00:00
Use struct instead of namespace to represent schema
This commit is contained in:
@@ -46,6 +46,7 @@ class Implementation(codegen.Base):
|
||||
templates.enumeration_function,
|
||||
max_id = len(enum.values),
|
||||
name = name,
|
||||
schema_name = schema_name,
|
||||
values = catc(map(stringify, enum.values)),
|
||||
from_string_statements = catnl(templates.enum_from_string_stmt%dict(context,**locals()) for value in enum.values)
|
||||
)
|
||||
@@ -55,7 +56,12 @@ class Implementation(codegen.Base):
|
||||
for name, type in mapping.schema.entities.items():
|
||||
parent_type_test = "" if not type.supertypes or len(type.supertypes) != 1 \
|
||||
else templates.parent_type_test%(type.supertypes[0])
|
||||
|
||||
constructor_arguments = mapping.get_assignable_arguments(type, include_derived = True)
|
||||
# if name == "IfcCartesianPoint":
|
||||
# import pprint
|
||||
# pprint.pprint(constructor_arguments)
|
||||
# exit()
|
||||
constructor_arguments_str = catc("%(full_type)s v%(index)d_%(name)s"%a for a in constructor_arguments if not a['is_derived'])
|
||||
attributes = []
|
||||
constructor_implementations = []
|
||||
@@ -66,6 +72,7 @@ class Implementation(codegen.Base):
|
||||
write_attr(
|
||||
templates.const_function,
|
||||
class_name = name,
|
||||
schema_name = schema_name,
|
||||
name = 'has%s'%arg['name'],
|
||||
arguments = '',
|
||||
return_type = 'bool',
|
||||
@@ -88,9 +95,10 @@ class Implementation(codegen.Base):
|
||||
class_name = name,
|
||||
name = arg['name'],
|
||||
arguments = '',
|
||||
schema_name = schema_name,
|
||||
return_type = arg['non_optional_type'],
|
||||
body = tmpl % {'index': arg['index']-1,
|
||||
'type' : arg['non_optional_type'].split('::')[0],
|
||||
'type' : arg['non_optional_type'].replace('::Value', ''),
|
||||
'list_instance_type' : arg['list_instance_type']}
|
||||
)
|
||||
|
||||
@@ -109,8 +117,9 @@ class Implementation(codegen.Base):
|
||||
name = 'set%s'%arg['name'],
|
||||
arguments = '%s v'%arg['non_optional_type'],
|
||||
return_type = 'void',
|
||||
schema_name = schema_name,
|
||||
body = tmpl % {'index': arg['index']-1,
|
||||
'type' : arg['non_optional_type'].split('::')[0]}
|
||||
'type' : arg['non_optional_type'].replace('::Value', '')}
|
||||
)
|
||||
|
||||
if arg['is_derived']:
|
||||
@@ -125,7 +134,7 @@ class Implementation(codegen.Base):
|
||||
else templates.constructor_stmt
|
||||
impl = tmpl % {'name' : deref_name,
|
||||
'index' : arg['index']-1,
|
||||
'type' : arg['non_optional_type'].split('::')[0]}
|
||||
'type' : arg['non_optional_type'].replace('::Value', '')}
|
||||
if is_optional_non_naked_ptr:
|
||||
impl = templates.constructor_stmt_optional%{'name' : arg_name,
|
||||
'index' : arg['index']-1,
|
||||
@@ -138,10 +147,11 @@ class Implementation(codegen.Base):
|
||||
|
||||
inverse = [templates.const_function % {
|
||||
'class_name' : name,
|
||||
'schema_name' : schema_name,
|
||||
'name' : i.name,
|
||||
'arguments' : '',
|
||||
'return_type' : '%s::list::ptr' % i.entity,
|
||||
'body' : templates.get_inverse % {'type': i.entity, 'index':get_attribute_index(i.entity, i.attribute)}
|
||||
'return_type' : '::%s::%s::list::ptr' % (schema_name, i.entity),
|
||||
'body' : templates.get_inverse % {'type': i.entity, 'index':get_attribute_index(i.entity, i.attribute), 'schema_name' : schema_name}
|
||||
} for i in (type.inverse.elements if type.inverse else [])]
|
||||
|
||||
superclass = "%s((IfcEntityInstanceData*)0)" % type.supertypes[0] if len(type.supertypes) == 1 else 'IfcUtil::IfcBaseEntity()'
|
||||
@@ -154,7 +164,8 @@ class Implementation(codegen.Base):
|
||||
constructor_implementation = cat(constructor_implementations),
|
||||
attributes = nl(catnl(attributes)),
|
||||
inverse = nl(catnl(inverse)),
|
||||
superclass = superclass
|
||||
superclass = superclass,
|
||||
schema_name = schema_name
|
||||
)
|
||||
|
||||
selectable_simple_types = sorted(set(sum([b.values for a,b in mapping.schema.selects.items()], [])) & set(map(str, mapping.schema.types.keys())))
|
||||
@@ -201,7 +212,7 @@ class Implementation(codegen.Base):
|
||||
simpletype_impl_constructor = templates.simpletype_impl_constructor_templated if mapping.is_templated_list(type) \
|
||||
else templates.simpletype_impl_constructor
|
||||
|
||||
def compose(params):
|
||||
def compose(params, schema_name=schema_name):
|
||||
class_name, attr_type, superclass, superclass_init, name, tmpl, return_type, args, body = params
|
||||
underlying_type = mapping.list_instance_type(type)
|
||||
arguments = ",".join(args)
|
||||
@@ -218,8 +229,8 @@ class Implementation(codegen.Base):
|
||||
))))
|
||||
simple_type_impl.append('')
|
||||
|
||||
external_definitions = ["extern entity* %s_type;" % n for n in mapping.schema.entities.keys() ] + \
|
||||
["extern type_declaration* %s_type;" % n for n in mapping.schema.simpletypes.keys()]
|
||||
external_definitions = [("extern entity* %s_%%s_type;" % mapping.schema.name.capitalize()) % n for n in mapping.schema.entities.keys() ] + \
|
||||
[("extern type_declaration* %s_%%s_type;" % mapping.schema.name.capitalize()) % n for n in mapping.schema.simpletypes.keys()]
|
||||
|
||||
self.str = templates.implementation % {
|
||||
'schema_name_upper' : mapping.schema.name.upper(),
|
||||
|
||||
@@ -122,7 +122,7 @@ class Mapping:
|
||||
is_ptr = False
|
||||
|
||||
if self.schema.is_enumeration(attr_type):
|
||||
type_str = '%s::%s'%(attr_type, attr_type)
|
||||
type_str = '::%s::%s::Value' % (self.schema.name.capitalize(), attr_type)
|
||||
elif isinstance(type_str, nodes.AggregationType):
|
||||
is_nested_list = isinstance(attr_type.type, nodes.AggregationType)
|
||||
ty = self.get_parameter_type(attr_type.type if is_nested_list else attr_type, False, allow_entities, False)
|
||||
@@ -141,8 +141,10 @@ class Mapping:
|
||||
type_str = tmpl % {
|
||||
'instance_type': ty
|
||||
}
|
||||
elif allow_pointer and (self.schema.is_entity(type_str) or self.schema.is_select(type_str)):
|
||||
type_str += '*'
|
||||
elif (self.schema.is_entity(type_str) or self.schema.is_select(type_str)):
|
||||
type_str = '::%s::%s' % (self.schema.name.capitalize(), attr_type)
|
||||
if allow_pointer:
|
||||
type_str += "*"
|
||||
is_ptr = True
|
||||
elif not allow_pointer and self.schema.is_select(type_str):
|
||||
type_str = "IfcUtil::IfcBaseClass*"
|
||||
@@ -166,7 +168,13 @@ class Mapping:
|
||||
def list_instance_type(self, attr):
|
||||
attr_type = attr.type if isinstance(attr, nodes.ExplicitAttribute) else attr
|
||||
if isinstance(attr_type, str): return None
|
||||
f = lambda v : 'IfcUtil::IfcBaseClass' if self.schema.is_select(v) else str(v)
|
||||
def f(v):
|
||||
v = self.flatten_type(v)
|
||||
if self.schema.is_select(v):
|
||||
return 'IfcUtil::IfcBaseClass'
|
||||
elif str(v) in self.schema.types or str(v) in self.schema.entities:
|
||||
return "::%s::%s" % (self.schema.name.capitalize(), v)
|
||||
else: return str(v)
|
||||
if self.is_array(attr_type):
|
||||
if not isinstance(attr_type, str) and self.is_array(attr_type.type):
|
||||
if isinstance(attr_type.type, str):
|
||||
|
||||
@@ -47,7 +47,7 @@ class SchemaClass(codegen.Base):
|
||||
elif isinstance(type, str):
|
||||
if mapping.schema.is_type(type) or mapping.schema.is_entity(type):
|
||||
if emitted_names is None or type.lower() in emitted_types:
|
||||
return "new named_type(%s_type)" % type
|
||||
return "new named_type(%s_%s_type)" % (schema_name, type)
|
||||
else:
|
||||
raise UnmetDependenciesException(type)
|
||||
else:
|
||||
@@ -75,7 +75,6 @@ class SchemaClass(codegen.Base):
|
||||
'#include "../ifcparse/%(schema_name_title)s.h"' % locals(),
|
||||
'',
|
||||
'using namespace IfcParse;',
|
||||
'using namespace %(schema_name_title)s;' % locals(),
|
||||
'']
|
||||
|
||||
collections_by_type = (('entity', mapping.schema.entities ),
|
||||
@@ -85,7 +84,7 @@ class SchemaClass(codegen.Base):
|
||||
|
||||
for cpp_type, collection in collections_by_type:
|
||||
for name in collection.keys():
|
||||
statements.append('%(cpp_type)s* %(name)s_type = 0;' % locals())
|
||||
statements.append('%(cpp_type)s* %(schema_name)s_%(name)s_type = 0;' % locals())
|
||||
|
||||
declarations_by_index = []
|
||||
|
||||
@@ -96,7 +95,7 @@ class SchemaClass(codegen.Base):
|
||||
#pragma optimize("", off)
|
||||
#endif
|
||||
""")
|
||||
statements.append('IfcParse::schema_definition* populate_schema() {')
|
||||
statements.append('IfcParse::schema_definition* %(schema_name)s_populate_schema() {' % locals())
|
||||
|
||||
emitted_types = set()
|
||||
while len(emitted_types) < len(mapping.schema.simpletypes):
|
||||
@@ -109,20 +108,20 @@ class SchemaClass(codegen.Base):
|
||||
# print("Unmet", repr(name))
|
||||
continue
|
||||
|
||||
statements.append(' %(name)s_type = new type_declaration("%(name)s", %%(index_in_schema_%(name)s)d, %(declared_type)s);' % locals())
|
||||
statements.append(' %(schema_name)s_%(name)s_type = new type_declaration("%(name)s", %%(index_in_schema_%(name)s)d, %(declared_type)s);' % locals())
|
||||
emitted_types.add(name.lower())
|
||||
|
||||
declared_types.append('%(name)s_type' % locals())
|
||||
declared_types.append('%(schema_name)s_%(name)s_type' % locals())
|
||||
declarations_by_index.append(name)
|
||||
|
||||
for name, enum in mapping.schema.enumerations.items():
|
||||
statements.append(' {')
|
||||
statements.append(' std::vector<std::string> items; items.reserve(%d);' % len(enum.values))
|
||||
statements.extend(map(lambda v: ' items.push_back("%s");' % v, sorted(enum.values)))
|
||||
statements.append(' %(name)s_type = new enumeration_type("%(name)s", %%(index_in_schema_%(name)s)d, items);' % locals())
|
||||
statements.append(' %(schema_name)s_%(name)s_type = new enumeration_type("%(name)s", %%(index_in_schema_%(name)s)d, items);' % locals())
|
||||
statements.append(' }')
|
||||
|
||||
declared_types.append('%(name)s_type' % locals())
|
||||
declared_types.append('%(schema_name)s_%(name)s_type' % locals())
|
||||
declarations_by_index.append(name)
|
||||
|
||||
emitted_entities = set()
|
||||
@@ -130,11 +129,11 @@ class SchemaClass(codegen.Base):
|
||||
for name, type in mapping.schema.entities.items():
|
||||
if name.lower() in emitted_entities: continue
|
||||
if len(type.supertypes) == 0 or set(map(lambda s: s.lower(), type.supertypes)) < emitted_entities:
|
||||
supertype = '0' if len(type.supertypes) == 0 else '%s_type' % type.supertypes[0]
|
||||
statements.append(' %(name)s_type = new entity("%(name)s", %%(index_in_schema_%(name)s)d, %(supertype)s);' % locals())
|
||||
supertype = '0' if len(type.supertypes) == 0 else '%s_%s_type' % (schema_name, type.supertypes[0])
|
||||
statements.append(' %(schema_name)s_%(name)s_type = new entity("%(name)s", %%(index_in_schema_%(name)s)d, %(supertype)s);' % locals())
|
||||
emitted_entities.add(name.lower())
|
||||
|
||||
declared_types.append('%(name)s_type' % locals())
|
||||
declared_types.append('%(schema_name)s_%(name)s_type' % locals())
|
||||
declarations_by_index.append(name)
|
||||
|
||||
emmited = emitted_types | emitted_entities | set(mapping.schema.enumerations.keys())
|
||||
@@ -146,13 +145,13 @@ class SchemaClass(codegen.Base):
|
||||
if set(map(lambda s: s.lower(),type.values)) < emmited:
|
||||
statements.append(' {')
|
||||
statements.append(' std::vector<const declaration*> items; items.reserve(%d);' % len(type.values))
|
||||
statements.extend(map(lambda v: ' items.push_back(%s_type);' % v, sorted(type.values)))
|
||||
statements.append(' %(name)s_type = new select_type("%(name)s", %%(index_in_schema_%(name)s)d, items);' % locals())
|
||||
statements.extend(map(lambda v: ' items.push_back(%s_%s_type);' % (schema_name, v), sorted(type.values)))
|
||||
statements.append(' %(schema_name)s_%(name)s_type = new select_type("%(name)s", %%(index_in_schema_%(name)s)d, items);' % locals())
|
||||
statements.append(' }')
|
||||
emitted_selects.add(name.lower())
|
||||
emmited.add(name)
|
||||
|
||||
declared_types.append('%(name)s_type' % locals())
|
||||
declared_types.append('%(schema_name)s_%(name)s_type' % locals())
|
||||
declarations_by_index.append(name)
|
||||
|
||||
num_declarations = len(declared_types)
|
||||
@@ -169,7 +168,7 @@ class SchemaClass(codegen.Base):
|
||||
statements.append(' attributes.push_back(new entity::attribute("%(attr_name)s", %(decl_type)s, %(optional)s));' % locals())
|
||||
statements.append(' std::vector<bool> derived; derived.reserve(%d);' % len(attribute_names))
|
||||
statements.append(' ' + " ".join(map(lambda b: 'derived.push_back(%s);' % str(b in derived).lower(), attribute_names)))
|
||||
statements.append(' %(name)s_type->set_attributes(attributes, derived);' % locals())
|
||||
statements.append(' %(schema_name)s_%(name)s_type->set_attributes(attributes, derived);' % locals())
|
||||
statements.append(' }')
|
||||
|
||||
for name, type in mapping.schema.entities.items():
|
||||
@@ -185,8 +184,8 @@ class SchemaClass(codegen.Base):
|
||||
attr_name, aggr_type, entity_ref = attr.name, attr.type, attr.entity
|
||||
if aggr_type is None: aggr_type = 'unspecified'
|
||||
attribute_entity, attribute_entity_index = find_inverse_name_and_index(entity_ref, attr.attribute)
|
||||
statements.append(' attributes.push_back(new entity::inverse_attribute("%(attr_name)s", entity::inverse_attribute::%(aggr_type)s_type, %(bound1)d, %(bound2)d, %(entity_ref)s_type, %(attribute_entity)s_type->attributes()[%(attribute_entity_index)d]));' % locals())
|
||||
statements.append(' %(name)s_type->set_inverse_attributes(attributes);' % locals())
|
||||
statements.append(' attributes.push_back(new entity::inverse_attribute("%(attr_name)s", entity::inverse_attribute::%(aggr_type)s_type, %(bound1)d, %(bound2)d, %(schema_name)s_%(entity_ref)s_type, %(schema_name)s_%(attribute_entity)s_type->attributes()[%(attribute_entity_index)d]));' % locals())
|
||||
statements.append(' %(schema_name)s_%(name)s_type->set_inverse_attributes(attributes);' % locals())
|
||||
statements.append(' }')
|
||||
|
||||
statements.append('')
|
||||
@@ -208,7 +207,7 @@ class SchemaClass(codegen.Base):
|
||||
|
||||
statements.extend(('const schema_definition& get_schema() {',
|
||||
'',
|
||||
' static const schema_definition* s = populate_schema();',
|
||||
' static const schema_definition* s = %(schema_name)s_populate_schema();' % locals(),
|
||||
' return *s;',
|
||||
'}','}','',''))
|
||||
|
||||
@@ -228,7 +227,7 @@ class SchemaClass(codegen.Base):
|
||||
%s
|
||||
default: throw IfcParse::IfcException(data->type()->name() + " cannot be instantiated");
|
||||
}
|
||||
""" % "\n ".join(map(lambda tup: "case %d: return new %s(data);" % tup, filter(can_be_instantiated, enumerate(declarations_by_index))))
|
||||
""" % "\n ".join(map(lambda tup: ("case %%d: return new ::%s::%%s(data);" % schema_name_title) % tup, filter(can_be_instantiated, enumerate(declarations_by_index))))
|
||||
|
||||
statements[statements.index("{factory_placeholder}")] = """
|
||||
class %(schema_name)s_instance_factory : public IfcParse::instance_factory {
|
||||
|
||||
@@ -38,7 +38,7 @@ header = """
|
||||
|
||||
#define IfcSchema %(schema_name)s
|
||||
|
||||
namespace %(schema_name)s {
|
||||
struct %(schema_name)s {
|
||||
|
||||
const IfcParse::schema_definition& get_schema();
|
||||
|
||||
@@ -50,8 +50,7 @@ const char* const Identifier = "%(schema_name_upper)s";
|
||||
%(declarations)s
|
||||
|
||||
%(class_definitions)s
|
||||
IFC_PARSE_API void InitStringMap();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
"""
|
||||
@@ -65,52 +64,10 @@ enum_header = """
|
||||
#include <string>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#define IfcSchema %(schema_name)s
|
||||
|
||||
namespace %(schema_name)s {
|
||||
|
||||
namespace Type {
|
||||
typedef enum {
|
||||
%(types)s, UNDEFINED
|
||||
} Enum;
|
||||
IFC_PARSE_API boost::optional<Enum> Parent(Enum v);
|
||||
IFC_PARSE_API Enum FromString(const std::string& s);
|
||||
IFC_PARSE_API const std::string& ToString(Enum v);
|
||||
IFC_PARSE_API bool IsSimple(Enum v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
"""
|
||||
|
||||
lb_header = """
|
||||
#ifndef %(schema_name_upper)sRT_H
|
||||
#define %(schema_name_upper)sRT_H
|
||||
|
||||
#define IfcSchema %(schema_name)s
|
||||
|
||||
#include "../ifcparse/ifc_parse_api.h"
|
||||
#include "../ifcparse/IfcBaseClass.h"
|
||||
#include "../ifcparse/IfcEntityDescriptor.h"
|
||||
|
||||
namespace %(schema_name)s {
|
||||
namespace Type {
|
||||
IFC_PARSE_API int GetAttributeCount(Enum t);
|
||||
IFC_PARSE_API int GetAttributeIndex(Enum t, const std::string& a);
|
||||
IFC_PARSE_API IfcUtil::ArgumentType GetAttributeType(Enum t, unsigned char a);
|
||||
IFC_PARSE_API Enum GetAttributeEntity(Enum t, unsigned char a);
|
||||
IFC_PARSE_API const std::string& GetAttributeName(Enum t, unsigned char a);
|
||||
IFC_PARSE_API bool GetAttributeOptional(Enum t, unsigned char a);
|
||||
IFC_PARSE_API bool GetAttributeDerived(Enum t, unsigned char a);
|
||||
IFC_PARSE_API std::pair<const char*, int> GetEnumerationIndex(Enum t, const std::string& a);
|
||||
IFC_PARSE_API std::pair<Enum, unsigned> GetInverseAttribute(Enum t, const std::string& a);
|
||||
IFC_PARSE_API std::set<std::string> GetInverseAttributeNames(Enum t);
|
||||
IFC_PARSE_API void PopulateDerivedFields(IfcEntityInstanceData* e);
|
||||
}}
|
||||
|
||||
#endif
|
||||
"""
|
||||
lb_header = """"""
|
||||
|
||||
implementation= """
|
||||
#include "../ifcparse/%(schema_name)s.h"
|
||||
@@ -120,45 +77,12 @@ implementation= """
|
||||
|
||||
#include <map>
|
||||
|
||||
using namespace %(schema_name)s;
|
||||
using namespace IfcParse;
|
||||
using namespace IfcWrite;
|
||||
|
||||
// External definitions
|
||||
%(external_definitions)s
|
||||
|
||||
const std::string& Type::ToString(Enum v) {
|
||||
if (v < 0 || v >= %(max_id)d) throw IfcException("Unable to find find keyword in schema");
|
||||
static std::string names[] = { %(type_name_strings)s };
|
||||
return names[v];
|
||||
}
|
||||
|
||||
static std::map<std::string,Type::Enum> string_map;
|
||||
void %(schema_name)s::InitStringMap() {
|
||||
%(string_map_statements)s
|
||||
}
|
||||
|
||||
Type::Enum Type::FromString(const std::string& s) {
|
||||
if (string_map.empty()) InitStringMap();
|
||||
std::map<std::string,Type::Enum>::const_iterator it = string_map.find(s);
|
||||
if ( it == string_map.end() ) throw IfcException("Unable to find find keyword in schema");
|
||||
else return it->second;
|
||||
}
|
||||
|
||||
static int parent_map[] = {%(parent_type_statements)s};
|
||||
boost::optional<Type::Enum> Type::Parent(Enum v){
|
||||
const int p = parent_map[static_cast<int>(v)];
|
||||
if (p >= 0) {
|
||||
return static_cast<Type::Enum>(p);
|
||||
} else {
|
||||
return boost::none;
|
||||
}
|
||||
}
|
||||
|
||||
bool Type::IsSimple(Enum v) {
|
||||
return %(simple_type_statement)s;
|
||||
}
|
||||
|
||||
%(enumeration_functions)s
|
||||
|
||||
%(simple_type_impl)s
|
||||
@@ -166,172 +90,7 @@ bool Type::IsSimple(Enum v) {
|
||||
%(entity_implementations)s
|
||||
"""
|
||||
|
||||
lb_implementation = """
|
||||
#include <set>
|
||||
|
||||
#include "../ifcparse/%(schema_name)s.h"
|
||||
#include "../ifcparse/%(schema_name)s-latebound.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "../ifcparse/IfcWrite.h"
|
||||
#include "../ifcparse/IfcBaseClass.h"
|
||||
#include "../ifcparse/IfcEntityDescriptor.h"
|
||||
|
||||
using namespace %(schema_name)s;
|
||||
using namespace IfcParse;
|
||||
using namespace IfcWrite;
|
||||
using namespace IfcUtil;
|
||||
|
||||
typedef std::map<Type::Enum,IfcEntityDescriptor*> entity_descriptor_map_t;
|
||||
typedef std::map<Type::Enum,IfcEnumerationDescriptor*> enumeration_descriptor_map_t;
|
||||
typedef std::map<Type::Enum, std::map<std::string, std::pair<Type::Enum, int> > > inverse_map_t;
|
||||
typedef std::map<Type::Enum,std::set<int> > derived_map_t;
|
||||
|
||||
entity_descriptor_map_t entity_descriptor_map;
|
||||
enumeration_descriptor_map_t enumeration_descriptor_map;
|
||||
inverse_map_t inverse_map;
|
||||
derived_map_t derived_map;
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma optimize( "", off )
|
||||
#endif
|
||||
|
||||
void InitDescriptorMap() {
|
||||
IfcEntityDescriptor* current;
|
||||
%(entity_descriptors)s
|
||||
// Enumerations
|
||||
std::vector<std::string> values;
|
||||
%(enumeration_descriptors)s
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma optimize( "", on )
|
||||
#endif
|
||||
|
||||
void InitInverseMap() {
|
||||
%(inverse_implementations)s
|
||||
}
|
||||
|
||||
void InitDerivedMap() {
|
||||
%(derived_field_statements)s
|
||||
}
|
||||
|
||||
int Type::GetAttributeIndex(Enum t, const std::string& a) {
|
||||
if (entity_descriptor_map.empty()) ::InitDescriptorMap();
|
||||
std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t);
|
||||
if ( i == entity_descriptor_map.end() ) throw IfcException("Type not found");
|
||||
else return i->second->getArgumentIndex(a);
|
||||
}
|
||||
|
||||
int Type::GetAttributeCount(Enum t) {
|
||||
if (entity_descriptor_map.empty()) ::InitDescriptorMap();
|
||||
std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t);
|
||||
if ( i == entity_descriptor_map.end() ) throw IfcException("Type not found");
|
||||
else return i->second->getArgumentCount();
|
||||
}
|
||||
|
||||
ArgumentType Type::GetAttributeType(Enum t, unsigned char a) {
|
||||
if (entity_descriptor_map.empty()) ::InitDescriptorMap();
|
||||
std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t);
|
||||
if ( i == entity_descriptor_map.end() ) throw IfcException("Type not found");
|
||||
else return i->second->getArgumentType(a);
|
||||
}
|
||||
|
||||
Type::Enum Type::GetAttributeEntity(Enum t, unsigned char a) {
|
||||
if (entity_descriptor_map.empty()) ::InitDescriptorMap();
|
||||
std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t);
|
||||
if ( i == entity_descriptor_map.end() ) throw IfcException("Type not found");
|
||||
else return i->second->getArgumentEntity(a);
|
||||
}
|
||||
|
||||
const std::string& Type::GetAttributeName(Enum t, unsigned char a) {
|
||||
if (entity_descriptor_map.empty()) ::InitDescriptorMap();
|
||||
std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t);
|
||||
if ( i == entity_descriptor_map.end() ) throw IfcException("Type not found");
|
||||
else return i->second->getArgumentName(a);
|
||||
}
|
||||
|
||||
bool Type::GetAttributeOptional(Enum t, unsigned char a) {
|
||||
if (entity_descriptor_map.empty()) ::InitDescriptorMap();
|
||||
std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t);
|
||||
if ( i == entity_descriptor_map.end() ) throw IfcException("Type not found");
|
||||
else return i->second->getArgumentOptional(a);
|
||||
}
|
||||
|
||||
bool Type::GetAttributeDerived(Enum t, unsigned char a) {
|
||||
if (derived_map.empty()) ::InitDerivedMap();
|
||||
std::map<Type::Enum,std::set<int> >::const_iterator i = derived_map.find(t);
|
||||
return i != derived_map.end() && i->second.find(a) != i->second.end();
|
||||
}
|
||||
|
||||
std::pair<const char*, int> Type::GetEnumerationIndex(Enum t, const std::string& a) {
|
||||
if (enumeration_descriptor_map.empty()) ::InitDescriptorMap();
|
||||
std::map<Type::Enum,IfcEnumerationDescriptor*>::const_iterator i = enumeration_descriptor_map.find(t);
|
||||
if ( i == enumeration_descriptor_map.end() ) throw IfcException("Value not found");
|
||||
else return i->second->getIndex(a);
|
||||
}
|
||||
|
||||
std::pair<Type::Enum, unsigned> Type::GetInverseAttribute(Enum t, const std::string& a) {
|
||||
if (inverse_map.empty()) ::InitInverseMap();
|
||||
inverse_map_t::const_iterator it;
|
||||
inverse_map_t::mapped_type::const_iterator jt;
|
||||
for(;;) {
|
||||
it = inverse_map.find(t);
|
||||
if (it != inverse_map.end()) {
|
||||
jt = it->second.find(a);
|
||||
if (jt != it->second.end()) {
|
||||
return jt->second;
|
||||
}
|
||||
}
|
||||
boost::optional<Enum> pt = Parent(t);
|
||||
if (pt) {
|
||||
t = *pt;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
throw IfcException("Attribute not found");
|
||||
}
|
||||
|
||||
std::set<std::string> Type::GetInverseAttributeNames(Enum t) {
|
||||
if (inverse_map.empty()) ::InitInverseMap();
|
||||
inverse_map_t::const_iterator it;
|
||||
inverse_map_t::mapped_type::const_iterator jt;
|
||||
|
||||
std::set<std::string> return_value;
|
||||
|
||||
for (;;) {
|
||||
it = inverse_map.find(t);
|
||||
if (it != inverse_map.end()) {
|
||||
for (jt = it->second.begin(); jt != it->second.end(); ++jt) {
|
||||
return_value.insert(jt->first);
|
||||
}
|
||||
}
|
||||
boost::optional<Enum> pt = Parent(t);
|
||||
if (pt) {
|
||||
t = *pt;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
void Type::PopulateDerivedFields(IfcEntityInstanceData* e) {
|
||||
if (derived_map.empty()) ::InitDerivedMap();
|
||||
std::map<Type::Enum, std::set<int> >::const_iterator i = derived_map.find(e->type());
|
||||
if (i != derived_map.end()) {
|
||||
for (std::set<int>::const_iterator it = i->second.begin(); it != i->second.end(); ++it) {
|
||||
IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();
|
||||
attr->set(IfcWrite::IfcWriteArgument::Derived());
|
||||
e->setArgument(*it, attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
lb_implementation = """"""
|
||||
|
||||
entity_descriptor = """ current = entity_descriptor_map[Type::%(type)s] = new IfcEntityDescriptor(Type::%(type)s,%(parent_statement)s);
|
||||
%(entity_descriptor_attributes)s"""
|
||||
@@ -365,25 +124,25 @@ simpletype_impl_argument_type = "if (i == 0) { return %(attr_type)s; } else { th
|
||||
simpletype_impl_argument = "return data_->getArgument(i);"
|
||||
simpletype_impl_is_with_supertype = "return v == %(class_name)s_type || %(superclass)s::is(v);"
|
||||
simpletype_impl_is_without_supertype = "return v == %(class_name)s_type;"
|
||||
simpletype_impl_type = "return *%(class_name)s_type;"
|
||||
simpletype_impl_class = "return *%(class_name)s_type;"
|
||||
simpletype_impl_type = "return *%(schema_name)s_%(class_name)s_type;"
|
||||
simpletype_impl_class = "return *%(schema_name)s_%(class_name)s_type;"
|
||||
simpletype_impl_explicit_constructor = "data_ = e;"
|
||||
simpletype_impl_constructor = "data_ = new IfcEntityInstanceData(%(class_name)s_type); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(v" +"); data_->setArgument(0, attr);}"
|
||||
simpletype_impl_constructor_templated = "data_ = new IfcEntityInstanceData(%(class_name)s_type); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(v->generalize()); data_->setArgument(0, attr);}"
|
||||
simpletype_impl_constructor = "data_ = new IfcEntityInstanceData(%(schema_name)s_%(class_name)s_type); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(v" +"); data_->setArgument(0, attr);}"
|
||||
simpletype_impl_constructor_templated = "data_ = new IfcEntityInstanceData(%(schema_name)s_%(class_name)s_type); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(v->generalize()); data_->setArgument(0, attr);}"
|
||||
simpletype_impl_cast = "return *data_->getArgument(0);"
|
||||
simpletype_impl_cast_templated = "IfcEntityList::ptr es = *data_->getArgument(0); return es->as<%(underlying_type)s>();"
|
||||
simpletype_impl_declaration = "return *%(class_name)s_type;"
|
||||
simpletype_impl_declaration = "return *%(schema_name)s_%(class_name)s_type;"
|
||||
|
||||
select = """%(documentation)s
|
||||
typedef IfcUtil::IfcBaseClass %(name)s;
|
||||
"""
|
||||
|
||||
enumeration = """namespace %(name)s {
|
||||
enumeration = """struct %(name)s {
|
||||
%(documentation)s
|
||||
typedef enum {%(values)s} %(name)s;
|
||||
IFC_PARSE_API const char* ToString(%(name)s v);
|
||||
IFC_PARSE_API %(name)s FromString(const std::string& s);
|
||||
}
|
||||
typedef enum {%(values)s} Value;
|
||||
IFC_PARSE_API static const char* ToString(Value v);
|
||||
IFC_PARSE_API static Value FromString(const std::string& s);
|
||||
};
|
||||
"""
|
||||
|
||||
entity = """%(documentation)s
|
||||
@@ -398,13 +157,13 @@ public:
|
||||
"""
|
||||
|
||||
enumeration_function="""
|
||||
const char* %(name)s::ToString(%(name)s v) {
|
||||
const char* %(schema_name)s::%(name)s::ToString(Value v) {
|
||||
if ( v < 0 || v >= %(max_id)d ) throw IfcException("Unable to find find keyword in schema");
|
||||
const char* names[] = { %(values)s };
|
||||
return names[v];
|
||||
}
|
||||
|
||||
%(name)s::%(name)s %(name)s::FromString(const std::string& s) {
|
||||
%(schema_name)s::%(name)s::Value %(schema_name)s::%(name)s::FromString(const std::string& s) {
|
||||
%(from_string_statements)s
|
||||
throw IfcException("Unable to find find keyword in schema");
|
||||
}
|
||||
@@ -413,19 +172,19 @@ const char* %(name)s::ToString(%(name)s v) {
|
||||
entity_implementation = """// Function implementations for %(name)s
|
||||
%(attributes)s
|
||||
%(inverse)s
|
||||
const IfcParse::entity& %(name)s::declaration() const { return *%(name)s_type; }
|
||||
const IfcParse::entity& %(name)s::Class() { return *%(name)s_type; }
|
||||
%(name)s::%(name)s(IfcEntityInstanceData* e) : %(superclass)s { if (!e) return; if (e->type() != %(name)s_type) throw IfcException("Unable to find find keyword in schema"); data_ = e; }
|
||||
%(name)s::%(name)s(%(constructor_arguments)s) : %(superclass)s {data_ = new IfcEntityInstanceData(%(name)s_type); %(constructor_implementation)s }
|
||||
const IfcParse::entity& %(schema_name)s::%(name)s::declaration() const { return *%(schema_name)s_%(name)s_type; }
|
||||
const IfcParse::entity& %(schema_name)s::%(name)s::Class() { return *%(schema_name)s_%(name)s_type; }
|
||||
%(schema_name)s::%(name)s::%(name)s(IfcEntityInstanceData* e) : %(superclass)s { if (!e) return; if (e->type() != %(schema_name)s_%(name)s_type) throw IfcException("Unable to find find keyword in schema"); data_ = e; }
|
||||
%(schema_name)s::%(name)s::%(name)s(%(constructor_arguments)s) : %(superclass)s {data_ = new IfcEntityInstanceData(%(schema_name)s_%(name)s_type); %(constructor_implementation)s }
|
||||
"""
|
||||
|
||||
optional_attribute_description = "/// Whether the optional attribute %s is defined for this %s"
|
||||
|
||||
function = "%(return_type)s %(class_name)s::%(name)s(%(arguments)s) { %(body)s }"
|
||||
const_function = "%(return_type)s %(class_name)s::%(name)s(%(arguments)s) const { %(body)s }"
|
||||
constructor = "%(class_name)s::%(class_name)s(%(arguments)s) { %(body)s }"
|
||||
constructor_single_initlist = "%(class_name)s::%(class_name)s(%(arguments)s) : %(superclass)s(%(superclass_init)s) { %(body)s }"
|
||||
cast_function = "%(class_name)s::operator %(return_type)s() const { %(body)s }"
|
||||
function = "%(return_type)s %(schema_name)s::%(class_name)s::%(name)s(%(arguments)s) { %(body)s }"
|
||||
const_function = "%(return_type)s %(schema_name)s::%(class_name)s::%(name)s(%(arguments)s) const { %(body)s }"
|
||||
constructor = "%(schema_name)s::%(class_name)s::%(class_name)s(%(arguments)s) { %(body)s }"
|
||||
constructor_single_initlist = "%(schema_name)s::%(class_name)s::%(class_name)s(%(arguments)s) : %(superclass)s(%(superclass_init)s) { %(body)s }"
|
||||
cast_function = "%(schema_name)s::%(class_name)s::operator %(return_type)s() const { %(body)s }"
|
||||
|
||||
array_type = "std::vector< %(instance_type)s > /*[%(lower)s:%(upper)s]*/"
|
||||
nested_array_type = "std::vector< std::vector< %(instance_type)s > >"
|
||||
@@ -450,7 +209,7 @@ get_attr_stmt_entity = "return (%(type)s)((IfcUtil::IfcBaseClass*)(*data_->getAr
|
||||
get_attr_stmt_array = "IfcEntityList::ptr es = *data_->getArgument(%(index)d); return es->as<%(list_instance_type)s>();"
|
||||
get_attr_stmt_nested_array = "IfcEntityListList::ptr es = *data_->getArgument(%(index)d); return es->as<%(list_instance_type)s>();"
|
||||
|
||||
get_inverse = "return data_->getInverse(Type::%(type)s, %(index)d)->as<%(type)s>();"
|
||||
get_inverse = "return data_->getInverse(%(schema_name)s_%(type)s_type, %(index)d)->as<%(type)s>();"
|
||||
|
||||
set_attr_stmt = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(v" +");data_->setArgument(%(index)d,attr);}"
|
||||
set_attr_stmt_enum = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(IfcWrite::IfcWriteArgument::EnumerationReference(v,%(type)s::ToString(v)));data_->setArgument(%(index)d,attr);}"
|
||||
|
||||
+6029
-6030
File diff suppressed because it is too large
Load Diff
+7649
-8661
File diff suppressed because one or more lines are too long
+2618
-2619
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
+7135
-7136
File diff suppressed because it is too large
Load Diff
+8966
-10163
File diff suppressed because one or more lines are too long
+3225
-3226
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
+19
-5
@@ -97,7 +97,7 @@ public:
|
||||
IfcFile(std::istream& fn, int len);
|
||||
IfcFile(void* data, int len);
|
||||
IfcFile(IfcParse::IfcSpfStream* f);
|
||||
IfcFile(const IfcParse::schema_definition* schema = IfcParse::schema_by_name(IfcSchema::Identifier));
|
||||
IfcFile(const IfcParse::schema_definition* schema = IfcParse::schema_by_name("IFC4"));
|
||||
|
||||
~IfcFile();
|
||||
|
||||
@@ -149,7 +149,7 @@ public:
|
||||
IfcUtil::IfcBaseClass* instance_by_id(int id);
|
||||
|
||||
/// Returns the entity with the specified GlobalId
|
||||
IfcUtil::IfcBaseClass* instance_by_guid(const std::string& guid);
|
||||
virtual IfcUtil::IfcBaseClass* instance_by_guid(const std::string& guid);
|
||||
|
||||
/// Performs a depth-first traversal, returning all entity instance
|
||||
/// attributes as a flat list. NB: includes the root instance specified
|
||||
@@ -170,8 +170,6 @@ public:
|
||||
|
||||
std::string createTimestamp() const;
|
||||
|
||||
std::pair<IfcSchema::IfcNamedUnit*, double> getUnit(IfcSchema::IfcUnitEnum::IfcUnitEnum);
|
||||
|
||||
void load(const IfcEntityInstanceData&);
|
||||
void load(unsigned entity_instance_name, std::vector<Argument*>& attributes);
|
||||
|
||||
@@ -180,8 +178,24 @@ public:
|
||||
void unregister_inverse(unsigned, IfcUtil::IfcBaseClass*);
|
||||
|
||||
const IfcParse::schema_definition* schema() const { return schema_; }
|
||||
|
||||
std::pair<IfcUtil::IfcBaseClass*, double> getUnit(const std::string& unit_type);
|
||||
};
|
||||
|
||||
template <typename Schema>
|
||||
class IFC_PARSE_API IfcFileWithSchema : public IfcFile {
|
||||
public:
|
||||
std::pair<typename Schema::IfcNamedUnit*, double> getUnit(typename Schema::IfcUnitEnum::Value unit_type) {
|
||||
std::pair<IfcUtil::IfcBaseClass*, double> unit_info = IfcFile::getUnit(Schema::IfcUnitEnum::ToString(unit_type));
|
||||
return std::make_pair(unit_info.first->as<typename Schema::IfcNamedUnit>(), unit_info.second);
|
||||
}
|
||||
|
||||
/// Returns the entity with the specified GlobalId
|
||||
virtual typename Schema::IfcRoot::list::ptr instance_by_guid(const std::string& guid) {
|
||||
return IfcFile::instance_by_guid(guid)->as<Schema::IfcRoot>();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
+56
-25
@@ -1281,8 +1281,8 @@ void IfcFile::initialize_(IfcParse::IfcSpfStream* s) {
|
||||
}
|
||||
|
||||
if (schema_ == 0) {
|
||||
schema_ = IfcParse::schema_by_name(IfcSchema::Identifier);
|
||||
Logger::Message(Logger::LOG_ERROR, "Unable to deduce schema version from header identifiers");
|
||||
schema_ = IfcParse::schema_by_name("IFC4");
|
||||
Logger::Message(Logger::LOG_ERROR, "Unable to deduce schema version from header identifiers, defaulting to IFC4");
|
||||
}
|
||||
|
||||
ifcroot_type_ = schema_->declaration_by_name("IfcRoot");
|
||||
@@ -1538,8 +1538,8 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity) {
|
||||
we->setArgument(i, copy);
|
||||
} else if (decl && decl->is(*schema()->declaration_by_name("IfcLengthMeasure"))) {
|
||||
if (boost::math::isnan(conversion_factor)) {
|
||||
const std::pair<IfcSchema::IfcNamedUnit*, double> this_file_unit = getUnit(IfcSchema::IfcUnitEnum::IfcUnit_LENGTHUNIT);
|
||||
const std::pair<IfcSchema::IfcNamedUnit*, double> other_file_unit = other_file->getUnit(IfcSchema::IfcUnitEnum::IfcUnit_LENGTHUNIT);
|
||||
const std::pair<IfcUtil::IfcBaseClass*, double> this_file_unit = getUnit("LENGTHUNIT");
|
||||
const std::pair<IfcUtil::IfcBaseClass*, double> other_file_unit = other_file->getUnit("LENGTHUNIT");
|
||||
std::cerr << other_file_unit.second << " " << this_file_unit.second << std::endl;
|
||||
if (this_file_unit.first && other_file_unit.first) {
|
||||
conversion_factor = other_file_unit.second / this_file_unit.second;
|
||||
@@ -1938,7 +1938,7 @@ void IfcFile::setDefaultHeaderValues() {
|
||||
std::vector<std::string> file_description, schema_identifiers, empty_vector;
|
||||
|
||||
file_description.push_back("ViewDefinition [CoordinationView]");
|
||||
schema_identifiers.push_back(IfcSchema::Identifier);
|
||||
schema_identifiers.push_back(schema()->name());
|
||||
|
||||
header().file_description().description(file_description);
|
||||
header().file_description().implementation_level("2;1");
|
||||
@@ -1954,38 +1954,69 @@ void IfcFile::setDefaultHeaderValues() {
|
||||
header().file_schema().schema_identifiers(schema_identifiers);
|
||||
}
|
||||
|
||||
std::pair<IfcSchema::IfcNamedUnit*, double> IfcFile::getUnit(IfcSchema::IfcUnitEnum::IfcUnitEnum type) {
|
||||
std::pair<IfcSchema::IfcNamedUnit*, double> return_value((IfcSchema::IfcNamedUnit*)0, 1.);
|
||||
IfcSchema::IfcProject::list::ptr projects = instances_by_type<IfcSchema::IfcProject>();
|
||||
std::pair<IfcUtil::IfcBaseClass*, double> IfcFile::getUnit(const std::string& unit_type) {
|
||||
std::pair<IfcUtil::IfcBaseClass*, double> return_value(0, 1.);
|
||||
IfcEntityList::ptr projects = instances_by_type(schema()->declaration_by_name("IfcProject"));
|
||||
|
||||
if (projects->size() == 1) {
|
||||
IfcSchema::IfcProject* project = *projects->begin();
|
||||
IfcEntityList::ptr units = project->UnitsInContext()->Units();
|
||||
IfcUtil::IfcBaseClass* project = *projects->begin();
|
||||
|
||||
IfcUtil::IfcBaseClass* unit_assignment = *project->data().getArgument(
|
||||
project->declaration().as_entity()->attribute_index("UnitsInContext")
|
||||
);
|
||||
|
||||
IfcEntityList::ptr units = *unit_assignment->data().getArgument(
|
||||
unit_assignment->declaration().as_entity()->attribute_index("Units")
|
||||
);
|
||||
|
||||
for (IfcEntityList::it it = units->begin(); it != units->end(); ++it) {
|
||||
IfcSchema::IfcUnit* unit = *it;
|
||||
if (unit->declaration().is(IfcSchema::Type::IfcNamedUnit)) {
|
||||
IfcSchema::IfcNamedUnit* named_unit = (IfcSchema::IfcNamedUnit*) unit;
|
||||
if (named_unit->UnitType() != type) {
|
||||
if (unit->declaration().is("IfcNamedUnit")) {
|
||||
const std::string file_unit_type = *unit->data().getArgument(
|
||||
unit->declaration().as_entity()->attribute_index("UnitType")
|
||||
);
|
||||
|
||||
if (file_unit_type != unit_type) {
|
||||
continue;
|
||||
}
|
||||
IfcSchema::IfcSIUnit* siunit = 0;
|
||||
if (named_unit->declaration().is(IfcSchema::Type::IfcConversionBasedUnit)) {
|
||||
IfcSchema::IfcConversionBasedUnit* u = (IfcSchema::IfcConversionBasedUnit*)named_unit;
|
||||
IfcSchema::IfcMeasureWithUnit* mu = u->ConversionFactor();
|
||||
return_value.second *= static_cast<double>(*mu->ValueComponent()->data().getArgument(0));
|
||||
return_value.first = named_unit;
|
||||
if (mu->UnitComponent()->declaration().is(IfcSchema::Type::IfcSIUnit)) {
|
||||
siunit = (IfcSchema::IfcSIUnit*) mu->UnitComponent();
|
||||
|
||||
IfcUtil::IfcBaseClass* siunit = 0;
|
||||
if (unit->declaration().is("IfcConversionBasedUnit")) {
|
||||
IfcUtil::IfcBaseClass* mu = *unit->data().getArgument(
|
||||
unit->declaration().as_entity()->attribute_index("ConversionFactor")
|
||||
);
|
||||
|
||||
IfcUtil::IfcBaseClass* vlc = *mu->data().getArgument(
|
||||
mu->declaration().as_entity()->attribute_index("ValueComponent")
|
||||
);
|
||||
|
||||
IfcUtil::IfcBaseClass* unc = *mu->data().getArgument(
|
||||
mu->declaration().as_entity()->attribute_index("ValueComponent")
|
||||
);
|
||||
|
||||
return_value.second *= static_cast<double>(*vlc->data().getArgument(0));
|
||||
return_value.first = unit;
|
||||
|
||||
if (unc->declaration().is("IfcSIUnit")) {
|
||||
siunit = unc;
|
||||
}
|
||||
} else if (named_unit->declaration().is(IfcSchema::Type::IfcSIUnit)) {
|
||||
return_value.first = siunit = (IfcSchema::IfcSIUnit*) named_unit;
|
||||
|
||||
} else if (unit->declaration().is("IfcSIUnit")) {
|
||||
return_value.first = siunit = unit;
|
||||
}
|
||||
|
||||
if (siunit) {
|
||||
if (siunit->hasPrefix()) {
|
||||
return_value.second *= IfcSIPrefixToValue(siunit->Prefix());
|
||||
Argument* prefix = siunit->data().getArgument(
|
||||
siunit->declaration().as_entity()->attribute_index("Prefix")
|
||||
);
|
||||
|
||||
if (!prefix->isNull()) {
|
||||
return_value.second *= IfcSIPrefixToValue(*prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
@@ -18,26 +18,27 @@
|
||||
********************************************************************************/
|
||||
#include "IfcSIPrefix.h"
|
||||
|
||||
double IfcParse::IfcSIPrefixToValue(IfcSchema::IfcSIPrefix::IfcSIPrefix v) {
|
||||
if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_EXA ) return 1.e18;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_PETA ) return 1.e15;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_TERA ) return 1.e12;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_GIGA ) return 1.e9;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_MEGA ) return 1.e6;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_KILO ) return 1.e3;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_HECTO ) return 1.e2;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_DECA ) return 1.;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_DECI ) return 1.e-1;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_CENTI ) return 1.e-2;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_MILLI ) return 1.e-3;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_MICRO ) return 1.e-6;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_NANO ) return 1.e-9;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_PICO ) return 1.e-12;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_FEMTO ) return 1.e-15;
|
||||
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_ATTO ) return 1.e-18;
|
||||
double IfcParse::IfcSIPrefixToValue(const std::string& v) {
|
||||
if ( v == "EXA" ) return 1.e18;
|
||||
else if ( v == "PETA" ) return 1.e15;
|
||||
else if ( v == "TERA" ) return 1.e12;
|
||||
else if ( v == "GIGA" ) return 1.e9;
|
||||
else if ( v == "MEGA" ) return 1.e6;
|
||||
else if ( v == "KILO" ) return 1.e3;
|
||||
else if ( v == "HECTO" ) return 1.e2;
|
||||
else if ( v == "DECA" ) return 1.;
|
||||
else if ( v == "DECI" ) return 1.e-1;
|
||||
else if ( v == "CENTI" ) return 1.e-2;
|
||||
else if ( v == "MILLI" ) return 1.e-3;
|
||||
else if ( v == "MICRO" ) return 1.e-6;
|
||||
else if ( v == "NANO" ) return 1.e-9;
|
||||
else if ( v == "PICO" ) return 1.e-12;
|
||||
else if ( v == "FEMTO" ) return 1.e-15;
|
||||
else if ( v == "ATTO" ) return 1.e-18;
|
||||
else return 1.;
|
||||
}
|
||||
|
||||
/*
|
||||
double IfcParse::get_SI_equivalent(IfcSchema::IfcNamedUnit* named_unit) {
|
||||
double scale = 1.;
|
||||
IfcSchema::IfcSIUnit* si_unit = 0;
|
||||
@@ -63,4 +64,5 @@ double IfcParse::get_SI_equivalent(IfcSchema::IfcNamedUnit* named_unit) {
|
||||
}
|
||||
|
||||
return scale;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -24,8 +24,8 @@
|
||||
#include "ifc_parse_api.h"
|
||||
|
||||
namespace IfcParse {
|
||||
IFC_PARSE_API double IfcSIPrefixToValue(IfcSchema::IfcSIPrefix::IfcSIPrefix);
|
||||
IFC_PARSE_API double get_SI_equivalent(IfcSchema::IfcNamedUnit*);
|
||||
IFC_PARSE_API double IfcSIPrefixToValue(const std::string& prefix);
|
||||
// IFC_PARSE_API double get_SI_equivalent(IfcSchema::IfcNamedUnit*);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -36,7 +36,7 @@ static const char * const DATA = "DATA";
|
||||
using namespace IfcParse;
|
||||
|
||||
HeaderEntity::HeaderEntity(const char * const datatype, IfcFile* file)
|
||||
: IfcEntityInstanceData(IfcSchema::Type::UNDEFINED, file), _datatype(datatype)
|
||||
: IfcEntityInstanceData(0, file), _datatype(datatype)
|
||||
{
|
||||
if (file) {
|
||||
offset_in_file_ = file->stream->Tell();
|
||||
|
||||
@@ -57,12 +57,12 @@ void IfcEntityList::remove(IfcUtil::IfcBaseClass* instance) {
|
||||
}
|
||||
}
|
||||
|
||||
IfcEntityList::ptr IfcEntityList::filtered(const std::set<IfcSchema::Type::Enum>& entities) {
|
||||
IfcEntityList::ptr IfcEntityList::filtered(const std::set<const IfcParse::declaration*>& entities) {
|
||||
IfcEntityList::ptr return_value(new IfcEntityList);
|
||||
for (it it = begin(); it != end(); ++it) {
|
||||
bool contained = false;
|
||||
for (std::set<IfcSchema::Type::Enum>::const_iterator jt = entities.begin(); jt != entities.end(); ++jt) {
|
||||
if ((*it)->declaration().is(*jt)) {
|
||||
for (std::set<const IfcParse::declaration*>::const_iterator jt = entities.begin(); jt != entities.end(); ++jt) {
|
||||
if ((*it)->declaration().is(**jt)) {
|
||||
contained = true;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user