mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-10-03 21:38:12 +00:00
WIP implement qtos. See #1222.
This commit is contained in:
@@ -6,6 +6,7 @@ from blenderbim.bim.ifc import IfcStore
|
||||
class Data:
|
||||
products = {}
|
||||
psets = {}
|
||||
qtos = {}
|
||||
|
||||
@classmethod
|
||||
def load(cls, product_id):
|
||||
@@ -13,7 +14,7 @@ class Data:
|
||||
if not file:
|
||||
return
|
||||
product = file.by_id(product_id)
|
||||
cls.products[product_id] = set()
|
||||
cls.products[product_id] = {"psets": set(), "qtos": set()}
|
||||
if product.is_a("IfcElementType"):
|
||||
cls.add_type_product_psets(product, product_id)
|
||||
else:
|
||||
@@ -36,47 +37,18 @@ class Data:
|
||||
continue
|
||||
if definition.RelatingPropertyDefinition.is_a("IfcPropertySet"):
|
||||
cls.add_pset(definition.RelatingPropertyDefinition, product_id)
|
||||
elif definition.RelatingPropertyDefinition.is_a("IfcElementQuantity"):
|
||||
cls.add_qto(definition.RelatingPropertyDefinition, product_id)
|
||||
|
||||
@classmethod
|
||||
def add_pset(cls, pset, product_id):
|
||||
new_pset = {
|
||||
"Name": pset.Name,
|
||||
"is_expanded": True,
|
||||
"Properties": []
|
||||
"Properties": cls.get_properties_from_template(pset.Name) or []
|
||||
}
|
||||
cls.products[product_id].add(int(pset.id()))
|
||||
cls.products[product_id]["psets"].add(int(pset.id()))
|
||||
cls.psets[int(pset.id())] = new_pset
|
||||
pset_template = blenderbim.bim.schema.ifc.psetqto.get_by_name(pset.Name)
|
||||
if pset_template:
|
||||
for prop_template in pset_template.HasPropertyTemplates:
|
||||
if not prop_template.is_a("IfcSimplePropertyTemplate"):
|
||||
continue # Other types not yet supported
|
||||
enum_items = []
|
||||
if prop_template.TemplateType == "P_SINGLEVALUE":
|
||||
data_type = str(IfcStore.get_schema().declaration_by_name(prop_template.PrimaryMeasureType))
|
||||
elif prop_template.TemplateType == "P_ENUMERATEDVALUE":
|
||||
data_type = "enum"
|
||||
enum_items = [v.wrappedValue for v in prop_template.Enumerators.EnumerationValues]
|
||||
else:
|
||||
continue # Other types not yet supported
|
||||
if "<string>" in data_type:
|
||||
data_type = "string"
|
||||
elif "<real>" in data_type:
|
||||
data_type = "float"
|
||||
elif "<integer>" in data_type:
|
||||
data_type = "integer"
|
||||
elif "<boolean>" in data_type:
|
||||
data_type = "boolean"
|
||||
elif "<enumeration" in data_type:
|
||||
data_type = "enum"
|
||||
enum_items = attribute.type_of_attribute().declared_type().enumeration_items()
|
||||
new_pset["Properties"].append({
|
||||
"Name": prop_template.Name,
|
||||
"value": None,
|
||||
"type": data_type,
|
||||
"enum_items": enum_items,
|
||||
"is_null": True
|
||||
})
|
||||
try:
|
||||
if hasattr(pset, "HasProperties"):
|
||||
props = pset.HasProperties
|
||||
@@ -127,3 +99,74 @@ class Data:
|
||||
"enum_items": [],
|
||||
"is_null": prop.NominalValue.wrappedValue is None
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def add_qto(cls, qto, product_id):
|
||||
new_qto = {
|
||||
"Name": qto.Name,
|
||||
"is_expanded": True,
|
||||
"Properties": cls.get_properties_from_template(qto.Name) or []
|
||||
}
|
||||
cls.products[product_id]["qtos"].add(int(qto.id()))
|
||||
cls.qtos[int(qto.id())] = new_qto
|
||||
for prop in qto.Quantities or []:
|
||||
if prop.is_a("IfcPhysicalSimpleQuantity"):
|
||||
value = prop[3]
|
||||
has_existing_prop = False
|
||||
for existing_prop in new_qto["Properties"]:
|
||||
if existing_prop["Name"] == prop.Name:
|
||||
existing_prop["value"] = float(value)
|
||||
existing_prop["is_null"] = value is None
|
||||
has_existing_prop = True
|
||||
break
|
||||
if not has_existing_prop:
|
||||
new_qto["Properties"].append({
|
||||
"Name": prop.Name,
|
||||
"value": float(value),
|
||||
"type": "float",
|
||||
"enum_items": [],
|
||||
"is_null": value is None
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def get_properties_from_template(cls, name):
|
||||
template = blenderbim.bim.schema.ifc.psetqto.get_by_name(name)
|
||||
if not template:
|
||||
return
|
||||
properties = []
|
||||
for prop_template in template.HasPropertyTemplates:
|
||||
if not prop_template.is_a("IfcSimplePropertyTemplate"):
|
||||
continue # Other types not yet supported
|
||||
enum_items = []
|
||||
|
||||
if prop_template.TemplateType == "P_SINGLEVALUE":
|
||||
data_type = str(IfcStore.get_schema().declaration_by_name(prop_template.PrimaryMeasureType or "IfcLabel"))
|
||||
elif prop_template.TemplateType == "P_ENUMERATEDVALUE":
|
||||
data_type = "enum"
|
||||
enum_items = [v.wrappedValue for v in prop_template.Enumerators.EnumerationValues]
|
||||
elif prop_template.TemplateType in ["Q_LENGTH", "Q_AREA", "Q_VOLUME", "Q_WEIGHT", "Q_TIME"]:
|
||||
data_type = "float"
|
||||
elif prop_template.TemplateType == "Q_COUNT":
|
||||
data_type = "integer"
|
||||
else:
|
||||
continue # Other types not yet supported
|
||||
|
||||
if "<string>" in data_type:
|
||||
data_type = "string"
|
||||
elif "<real>" in data_type:
|
||||
data_type = "float"
|
||||
elif "<integer>" in data_type:
|
||||
data_type = "integer"
|
||||
elif "<boolean>" in data_type:
|
||||
data_type = "boolean"
|
||||
elif "<enumeration" in data_type:
|
||||
data_type = "enum"
|
||||
enum_items = attribute.type_of_attribute().declared_type().enumeration_items()
|
||||
properties.append({
|
||||
"Name": prop_template.Name,
|
||||
"value": None,
|
||||
"type": data_type,
|
||||
"enum_items": enum_items,
|
||||
"is_null": True
|
||||
})
|
||||
return properties
|
||||
|
||||
Reference in New Issue
Block a user