mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-28 15:53:00 +00:00
Fix missing IFC descriptions for already added pset props
Example - https://files.catbox.moe/dg1mzk.png
This commit is contained in:
@@ -296,7 +296,13 @@ def add_attribute_enum_items_descriptions(
|
|||||||
new_enum_description.name = description
|
new_enum_description.name = description
|
||||||
|
|
||||||
|
|
||||||
def add_attribute_description(attribute_blender: bonsai.bim.prop.Attribute, attribute_ifc=None):
|
def add_attribute_description(
|
||||||
|
attribute_blender: bonsai.bim.prop.Attribute,
|
||||||
|
attribute_ifc: Union[ifcopenshell.entity_instance, None] = None,
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
:param attribute_ifc: IFC Entity to use as a fallback source of description (using "Description" attribute).
|
||||||
|
"""
|
||||||
if not attribute_blender.name:
|
if not attribute_blender.name:
|
||||||
return
|
return
|
||||||
version = tool.Ifc.get_schema()
|
version = tool.Ifc.get_schema()
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ def enable_pset_editing(
|
|||||||
has_template = False
|
has_template = False
|
||||||
|
|
||||||
if pset:
|
if pset:
|
||||||
pset_tool.import_pset_from_existing(pset, props)
|
pset_tool.import_pset_from_existing(pset, props, pset_template)
|
||||||
pset_tool.set_active_pset(props, pset, has_template)
|
pset_tool.set_active_pset(props, pset, has_template)
|
||||||
else:
|
else:
|
||||||
pset_tool.enable_proposed_pset(props, pset_name, pset_type, has_template)
|
pset_tool.enable_proposed_pset(props, pset_name, pset_type, has_template)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ from typing import Union, Literal, Any, TYPE_CHECKING, assert_never
|
|||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from bonsai.bim.prop import Attribute
|
||||||
from bonsai.bim.module.pset.prop import (
|
from bonsai.bim.module.pset.prop import (
|
||||||
PsetProperties,
|
PsetProperties,
|
||||||
GlobalPsetProperties,
|
GlobalPsetProperties,
|
||||||
@@ -171,8 +172,16 @@ class Pset(bonsai.core.tool.Pset):
|
|||||||
return special_type
|
return special_type
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def import_pset_from_existing(cls, pset: ifcopenshell.entity_instance, props: PsetProperties) -> None:
|
def import_pset_from_existing(
|
||||||
pset_props = []
|
cls,
|
||||||
|
pset: ifcopenshell.entity_instance,
|
||||||
|
props: PsetProperties,
|
||||||
|
pset_template: Union[ifcopenshell.entity_instance, None],
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
:param pset_template: Pset Template to use as a source for descriptions.
|
||||||
|
"""
|
||||||
|
pset_props: tuple[ifcopenshell.entity_instance, ...] = ()
|
||||||
if pset.is_a("IfcElementQuantity"):
|
if pset.is_a("IfcElementQuantity"):
|
||||||
pset_props = pset.Quantities
|
pset_props = pset.Quantities
|
||||||
elif pset.is_a("IfcPropertySet"):
|
elif pset.is_a("IfcPropertySet"):
|
||||||
@@ -180,6 +189,16 @@ class Pset(bonsai.core.tool.Pset):
|
|||||||
elif pset.is_a("IfcMaterialProperties") or pset.is_a("IfcProfileProperties"):
|
elif pset.is_a("IfcMaterialProperties") or pset.is_a("IfcProfileProperties"):
|
||||||
pset_props = pset.Properties
|
pset_props = pset.Properties
|
||||||
|
|
||||||
|
prop_templates: dict[str, ifcopenshell.entity_instance] = {}
|
||||||
|
if pset_template:
|
||||||
|
prop_templates = {prop.Name: prop for prop in pset_template.HasPropertyTemplates}
|
||||||
|
|
||||||
|
def process_prop_description(metadata: Attribute) -> None:
|
||||||
|
prop_name = metadata.name
|
||||||
|
if prop_name not in prop_templates:
|
||||||
|
return
|
||||||
|
bonsai.bim.helper.add_attribute_description(metadata, prop_templates[prop_name])
|
||||||
|
|
||||||
for prop in sorted(pset_props, key=lambda p: p.Name):
|
for prop in sorted(pset_props, key=lambda p: p.Name):
|
||||||
if props.properties.get(prop.Name):
|
if props.properties.get(prop.Name):
|
||||||
continue # This property has already been added from a template
|
continue # This property has already been added from a template
|
||||||
@@ -230,6 +249,7 @@ class Pset(bonsai.core.tool.Pset):
|
|||||||
metadata.is_optional = True
|
metadata.is_optional = True
|
||||||
metadata.special_type = cls.get_special_type_for_prop(prop)
|
metadata.special_type = cls.get_special_type_for_prop(prop)
|
||||||
metadata.set_value(metadata.get_value_default() if metadata.is_null else value)
|
metadata.set_value(metadata.get_value_default() if metadata.is_null else value)
|
||||||
|
process_prop_description(metadata)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_prop_template_primitive_type(cls, prop_template: ifcopenshell.entity_instance) -> str:
|
def get_prop_template_primitive_type(cls, prop_template: ifcopenshell.entity_instance) -> str:
|
||||||
@@ -333,7 +353,7 @@ class Pset(bonsai.core.tool.Pset):
|
|||||||
|
|
||||||
# For every prop we first ensure that existing prop value type matches the template value type
|
# For every prop we first ensure that existing prop value type matches the template value type
|
||||||
# to prevent data loss and error casting data.
|
# to prevent data loss and error casting data.
|
||||||
# Property will be added later by import_pset_from_existing.
|
# Existing property will be added later by import_pset_from_existing.
|
||||||
for prop_template in sorted(pset_template.HasPropertyTemplates, key=lambda p: p.Name):
|
for prop_template in sorted(pset_template.HasPropertyTemplates, key=lambda p: p.Name):
|
||||||
if (
|
if (
|
||||||
not prop_template.is_a("IfcSimplePropertyTemplate")
|
not prop_template.is_a("IfcSimplePropertyTemplate")
|
||||||
|
|||||||
Reference in New Issue
Block a user