mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
add_prop_template - consider pset template type for prop/measure types
This commit is contained in:
@@ -23,7 +23,7 @@ import ifcopenshell.util.schema
|
||||
import ifcopenshell.util.type
|
||||
from ifcopenshell.entity_instance import entity_instance
|
||||
from functools import lru_cache
|
||||
from typing import List, Optional
|
||||
from typing import List, Optional, Literal
|
||||
|
||||
templates: dict[str, "PsetQto"] = {}
|
||||
|
||||
@@ -147,3 +147,29 @@ class PsetQto:
|
||||
|
||||
def is_templated(self, name: str) -> bool:
|
||||
return bool(self.get_by_name(name))
|
||||
|
||||
|
||||
def get_pset_template_type(pset_template: entity_instance) -> Literal["PSET", "QTO", None]:
|
||||
"""Get the type of the pset template.
|
||||
If type is mixed or not defined, return None."""
|
||||
|
||||
# Try to identify whether it's pset or qto from the template type.
|
||||
template_type = pset_template.TemplateType
|
||||
if template_type:
|
||||
if template_type.startswith("PSET_"):
|
||||
return "PSET"
|
||||
elif template_type.startswith("QTO_"):
|
||||
return "QTO"
|
||||
# Can also be 'NOTDEFINED'.
|
||||
|
||||
pset_types = set()
|
||||
for prop in pset_template.HasPropertyTemplates:
|
||||
prop_template_type = prop.TemplateType
|
||||
if prop_template_type:
|
||||
if prop_template_type.startswith("P_"):
|
||||
pset_types.add("PSET")
|
||||
else: # All other values are Q_.
|
||||
pset_types.add("QTO")
|
||||
|
||||
pset_type = next(iter(pset_types)) if len(pset_types) == 1 else None
|
||||
return pset_type
|
||||
|
||||
Reference in New Issue
Block a user