mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 05:17:58 +00:00
Support for schemas using TYPE definitions to redeclare BINARY types
This commit is contained in:
@@ -52,11 +52,11 @@ class Mapping:
|
|||||||
def simple_type_parent(self, type):
|
def simple_type_parent(self, type):
|
||||||
parent = self.schema.types[type].type.type
|
parent = self.schema.types[type].type.type
|
||||||
if isinstance(parent, nodes.AggregationType): parent = None
|
if isinstance(parent, nodes.AggregationType): parent = None
|
||||||
return None if parent in self.express_to_cpp_typemapping else parent
|
return None if str(parent) in self.express_to_cpp_typemapping else parent
|
||||||
|
|
||||||
def make_type_string(self, type):
|
def make_type_string(self, type):
|
||||||
if isinstance(type, str):
|
if isinstance(type, (str, nodes.BinaryType)):
|
||||||
return self.express_to_cpp_typemapping.get(type, type)
|
return self.express_to_cpp_typemapping.get(str(type), type)
|
||||||
else:
|
else:
|
||||||
is_list = self.schema.is_entity(type.type)
|
is_list = self.schema.is_entity(type.type)
|
||||||
is_nested_list = isinstance(type.type, nodes.AggregationType)
|
is_nested_list = isinstance(type.type, nodes.AggregationType)
|
||||||
@@ -83,12 +83,8 @@ class Mapping:
|
|||||||
|
|
||||||
def make_argument_type(self, attr):
|
def make_argument_type(self, attr):
|
||||||
def _make_argument_type(type):
|
def _make_argument_type(type):
|
||||||
if type in self.express_to_cpp_typemapping:
|
if self.schema.is_entity(type) or isinstance(type, nodes.SelectType):
|
||||||
return self.express_to_cpp_typemapping.get(type, type).split('::')[-1].upper()
|
|
||||||
elif self.schema.is_entity(type) or isinstance(type, nodes.SelectType):
|
|
||||||
return "ENTITY_INSTANCE"
|
return "ENTITY_INSTANCE"
|
||||||
elif self.schema.is_type(type):
|
|
||||||
return _make_argument_type(self.schema.types[type].type.type)
|
|
||||||
elif isinstance(type, nodes.BinaryType):
|
elif isinstance(type, nodes.BinaryType):
|
||||||
return "BINARY"
|
return "BINARY"
|
||||||
elif isinstance(type, nodes.EnumerationType):
|
elif isinstance(type, nodes.EnumerationType):
|
||||||
@@ -97,17 +93,21 @@ class Mapping:
|
|||||||
ty = _make_argument_type(type.type)
|
ty = _make_argument_type(type.type)
|
||||||
if ty == "UNKNOWN": return "UNKNOWN"
|
if ty == "UNKNOWN": return "UNKNOWN"
|
||||||
return "AGGREGATE_OF_" + ty
|
return "AGGREGATE_OF_" + ty
|
||||||
|
elif str(type) in self.express_to_cpp_typemapping:
|
||||||
|
return self.express_to_cpp_typemapping.get(str(type), type).split('::')[-1].upper()
|
||||||
|
elif self.schema.is_type(type):
|
||||||
|
return _make_argument_type(self.schema.types[type].type.type)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Unable to map type %r for attribute %r" % (type, attr))
|
raise ValueError("Unable to map type %r for attribute %r" % (type, attr))
|
||||||
ty = _make_argument_type(attr.type if hasattr(attr, 'type') else attr)
|
ty = _make_argument_type(attr.type if hasattr(attr, 'type') else attr)
|
||||||
if ty not in self.supported_argument_types:
|
if ty not in self.supported_argument_types:
|
||||||
print("Attribute %r mapped as 'unknown'" % (type, attr), file=sys.stderr)
|
print("Attribute %r mapped as 'unknown'" % (attr), file=sys.stderr)
|
||||||
ty = 'UNKNOWN'
|
ty = 'UNKNOWN'
|
||||||
return "IfcUtil::Argument_%s" % ty
|
return "IfcUtil::Argument_%s" % ty
|
||||||
|
|
||||||
def get_type_dep(self, type):
|
def get_type_dep(self, type):
|
||||||
if isinstance(type, str):
|
if isinstance(type, str):
|
||||||
return self.express_to_cpp_typemapping.get(type, type)
|
return self.express_to_cpp_typemapping.get(str(type), type)
|
||||||
else:
|
else:
|
||||||
return self.get_type_dep(type.type)
|
return self.get_type_dep(type.type)
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ class Mapping:
|
|||||||
ty = self.get_parameter_type(attr_type.type if is_nested_list else attr_type, False, allow_entities, False)
|
ty = self.get_parameter_type(attr_type.type if is_nested_list else attr_type, False, allow_entities, False)
|
||||||
if self.schema.is_select(attr_type.type):
|
if self.schema.is_select(attr_type.type):
|
||||||
type_str = templates.untyped_list
|
type_str = templates.untyped_list
|
||||||
elif self.schema.is_simpletype(ty) or ty in self.express_to_cpp_typemapping.values():
|
elif self.schema.is_simpletype(ty) or str(ty) in self.express_to_cpp_typemapping.values():
|
||||||
tmpl = templates.nested_array_type if is_nested_list else templates.array_type
|
tmpl = templates.nested_array_type if is_nested_list else templates.array_type
|
||||||
type_str = tmpl % {
|
type_str = tmpl % {
|
||||||
'instance_type' : ty,
|
'instance_type' : ty,
|
||||||
|
|||||||
@@ -22,15 +22,15 @@ import collections
|
|||||||
|
|
||||||
class Schema:
|
class Schema:
|
||||||
def is_enumeration(self, v):
|
def is_enumeration(self, v):
|
||||||
return v in self.enumerations
|
return str(v) in self.enumerations
|
||||||
def is_select(self, v):
|
def is_select(self, v):
|
||||||
return v in self.selects
|
return str(v) in self.selects
|
||||||
def is_simpletype(self, v):
|
def is_simpletype(self, v):
|
||||||
return v in self.simpletypes
|
return str(v) in self.simpletypes
|
||||||
def is_type(self, v):
|
def is_type(self, v):
|
||||||
return v in self.types
|
return str(v) in self.types
|
||||||
def is_entity(self, v):
|
def is_entity(self, v):
|
||||||
return v in self.entities
|
return str(v) in self.entities
|
||||||
def __init__(self, parsetree):
|
def __init__(self, parsetree):
|
||||||
self.name = parsetree[1]
|
self.name = parsetree[1]
|
||||||
|
|
||||||
@@ -43,4 +43,4 @@ class Schema:
|
|||||||
|
|
||||||
self.enumerations = of_type(nodes.EnumerationType)
|
self.enumerations = of_type(nodes.EnumerationType)
|
||||||
self.selects = of_type(nodes.SelectType)
|
self.selects = of_type(nodes.SelectType)
|
||||||
self.simpletypes = of_type(str, nodes.AggregationType)
|
self.simpletypes = of_type(str, nodes.AggregationType, nodes.BinaryType)
|
||||||
|
|||||||
Reference in New Issue
Block a user