2020-05-17 18:32:56 +10:00
|
|
|
def get_psets(element):
|
|
|
|
|
psets = {}
|
|
|
|
|
try:
|
2020-11-01 20:08:27 +07:00
|
|
|
if element.is_a("IfcTypeObject"):
|
2020-05-17 18:32:56 +10:00
|
|
|
if element.HasPropertySets:
|
|
|
|
|
for definition in element.HasPropertySets:
|
2020-08-04 20:18:08 +10:00
|
|
|
psets[definition.Name] = get_property_definition(definition)
|
2020-05-17 18:32:56 +10:00
|
|
|
else:
|
|
|
|
|
for relationship in element.IsDefinedBy:
|
2020-11-01 20:08:27 +07:00
|
|
|
if relationship.is_a("IfcRelDefinesByProperties"):
|
2020-05-17 18:32:56 +10:00
|
|
|
definition = relationship.RelatingPropertyDefinition
|
2020-08-04 20:18:08 +10:00
|
|
|
psets[definition.Name] = get_property_definition(definition)
|
2020-05-17 18:32:56 +10:00
|
|
|
except Exception as e:
|
|
|
|
|
import traceback
|
2020-11-01 20:08:27 +07:00
|
|
|
|
|
|
|
|
print("failed to load properties: {}".format(e))
|
2020-05-17 18:32:56 +10:00
|
|
|
traceback.print_exc()
|
|
|
|
|
return psets
|
|
|
|
|
|
2020-08-04 20:18:08 +10:00
|
|
|
|
|
|
|
|
def get_property_definition(definition):
|
2020-05-17 18:32:56 +10:00
|
|
|
if definition is not None:
|
|
|
|
|
props = {}
|
2020-11-01 20:08:27 +07:00
|
|
|
if definition.is_a("IfcElementQuantity"):
|
2020-08-04 20:18:08 +10:00
|
|
|
props.update(get_quantities(definition.Quantities))
|
2020-11-01 20:08:27 +07:00
|
|
|
elif definition.is_a("IfcPropertySet"):
|
2020-08-04 20:18:08 +10:00
|
|
|
props.update(get_properties(definition.HasProperties))
|
2020-05-17 18:32:56 +10:00
|
|
|
else:
|
|
|
|
|
# Entity introduced in IFC4
|
|
|
|
|
# definition.is_a('IfcPreDefinedPropertySet'):
|
|
|
|
|
for prop in range(4, len(definition)):
|
|
|
|
|
props[definition.attribute_name(prop)] = definition[prop]
|
|
|
|
|
return props
|
2020-08-04 20:18:08 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_quantities(quantities):
|
|
|
|
|
results = {}
|
|
|
|
|
for quantity in quantities:
|
2020-11-01 20:08:27 +07:00
|
|
|
if quantity.is_a("IfcPhysicalSimpleQuantity"):
|
2020-08-04 20:18:08 +10:00
|
|
|
results[quantity.Name] = quantity[3]
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_properties(properties):
|
|
|
|
|
results = {}
|
|
|
|
|
for prop in properties:
|
2020-11-01 20:08:27 +07:00
|
|
|
if prop.is_a("IfcPropertySingleValue"):
|
2020-09-05 12:20:16 +10:00
|
|
|
results[prop.Name] = prop.NominalValue.wrappedValue
|
2020-11-01 20:08:27 +07:00
|
|
|
elif prop.is_a("IfcComplexProperty"):
|
2020-08-04 20:18:08 +10:00
|
|
|
data = prop.get_info()
|
2020-11-01 20:08:27 +07:00
|
|
|
data["properties"] = get_properties(prop.HasProperties)
|
|
|
|
|
del data["HasProperties"]
|
2020-08-04 20:18:08 +10:00
|
|
|
results[prop.Name] = data
|
|
|
|
|
return results
|
2020-08-04 21:08:49 +10:00
|
|
|
|
|
|
|
|
|
2020-08-08 17:58:45 +10:00
|
|
|
def get_type(element):
|
2020-11-01 20:08:27 +07:00
|
|
|
if hasattr(element, "IsTypedBy") and element.IsTypedBy:
|
2020-08-08 17:58:45 +10:00
|
|
|
return element.IsTypedBy[0].RelatingType
|
2020-11-01 20:08:27 +07:00
|
|
|
elif hasattr(element, "IsDefinedBy") and element.IsDefinedBy: # IFC2X3
|
2020-08-08 17:58:45 +10:00
|
|
|
for relationship in element.IsDefinedBy:
|
2020-11-01 20:08:27 +07:00
|
|
|
if relationship.is_a("IfcRelDefinesByType"):
|
2020-08-08 17:58:45 +10:00
|
|
|
return relationship.RelatingType
|
|
|
|
|
|
|
|
|
|
|
2020-12-02 09:03:18 +11:00
|
|
|
def get_material(element):
|
|
|
|
|
if hasattr(element, "HasAssociations") and element.HasAssociations:
|
|
|
|
|
for relationship in element.HasAssociations:
|
|
|
|
|
if relationship.is_a("IfcRelAssociatesMaterial"):
|
2020-12-03 22:17:46 +11:00
|
|
|
if relationship.RelatingMaterial.is_a("IfcMaterialLayerSetUsage"):
|
|
|
|
|
return relationship.RelatingMaterial.ForLayerSet
|
|
|
|
|
elif relationship.RelatingMaterial.is_a("IfcMaterialProfileSetUsage"):
|
|
|
|
|
return relationship.RelatingMaterial.ForProfileSet
|
2020-12-02 09:03:18 +11:00
|
|
|
return relationship.RelatingMaterial
|
|
|
|
|
relating_type = get_type(element)
|
|
|
|
|
if hasattr(relating_type, "HasAssociations") and relating_type.HasAssociations:
|
|
|
|
|
for relationship in relating_type.HasAssociations:
|
|
|
|
|
if relationship.is_a("IfcRelAssociatesMaterial"):
|
2020-12-03 22:17:46 +11:00
|
|
|
if relationship.RelatingMaterial.is_a("IfcMaterialLayerSetUsage"):
|
|
|
|
|
return relationship.RelatingMaterial.ForLayerSet
|
|
|
|
|
elif relationship.RelatingMaterial.is_a("IfcMaterialProfileSetUsage"):
|
|
|
|
|
return relationship.RelatingMaterial.ForProfileSet
|
2020-12-02 09:03:18 +11:00
|
|
|
return relationship.RelatingMaterial
|
|
|
|
|
|
|
|
|
|
|
2021-01-22 15:52:48 +11:00
|
|
|
def get_container(element):
|
|
|
|
|
if hasattr(element, "ContainedInStructure") and element.ContainedInStructure:
|
|
|
|
|
return element.ContainedInStructure[0].RelatingStructure
|
|
|
|
|
|
|
|
|
|
|
2020-08-04 21:08:49 +10:00
|
|
|
def replace_attribute(element, old, new):
|
|
|
|
|
for i, attribute in enumerate(element):
|
|
|
|
|
if attribute == old:
|
|
|
|
|
element[i] = new
|
|
|
|
|
elif isinstance(attribute, tuple):
|
|
|
|
|
new_attribute = list(attribute)
|
|
|
|
|
for j, item in enumerate(attribute):
|
|
|
|
|
if item == old:
|
|
|
|
|
new_attribute[j] = new
|
|
|
|
|
element[i] = new_attribute
|
2021-01-01 12:15:18 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_representation_of_context(representation, context, subcontext=None, target_view=None):
|
|
|
|
|
if target_view is not None:
|
|
|
|
|
return (
|
|
|
|
|
representation.ContextOfItems.is_a("IfcGeometricRepresentationSubContext")
|
|
|
|
|
and representation.ContextOfItems.TargetView == target_view
|
|
|
|
|
and representation.ContextOfItems.ContextIdentifier == subcontext
|
|
|
|
|
and representation.ContextOfItems.ContextType == context
|
|
|
|
|
)
|
|
|
|
|
elif subcontext is not None:
|
|
|
|
|
return (
|
|
|
|
|
representation.ContextOfItems.is_a("IfcGeometricRepresentationSubContext")
|
|
|
|
|
and representation.ContextOfItems.ContextIdentifier == subcontext
|
|
|
|
|
and representation.ContextOfItems.ContextType == context
|
|
|
|
|
)
|
|
|
|
|
elif representation.ContextOfItems.ContextType == context:
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_representation(element, context, subcontext=None, target_view=None):
|
|
|
|
|
if element.is_a("IfcProduct") and element.Representation:
|
|
|
|
|
for r in element.Representation.Representations:
|
|
|
|
|
if is_representation_of_context(r, context, subcontext, target_view):
|
|
|
|
|
return r
|
|
|
|
|
elif element.is_a("IfcTypeProduct") and element.RepresentationMaps:
|
|
|
|
|
for r in element.RepresentationMaps:
|
|
|
|
|
if is_representation_of_context(r.MappedRepresentation, context, subcontext, target_view):
|
|
|
|
|
return r.MappedRepresentation
|