This commit is contained in:
Andrej730
2024-09-03 15:17:17 +05:00
parent bec1d913c5
commit acbdc0ed4c
3 changed files with 34 additions and 14 deletions
@@ -19,6 +19,7 @@
import ifcopenshell.api.owner
import ifcopenshell.api.geometry
import ifcopenshell.util.element
from typing import Any
def assign_representation(
@@ -31,7 +32,10 @@ def assign_representation(
class Usecase:
def execute(self):
file: ifcopenshell.file
settings: dict[str, Any]
def execute(self) -> None:
if self.settings["product"].is_a("IfcProduct"):
product_type = ifcopenshell.util.element.get_type(self.settings["product"])
if (
@@ -73,7 +77,9 @@ class Usecase:
self.assign_product_representation(element, mapped_representation)
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": self.settings["product"]})
def assign_product_representation(self, product, representation):
def assign_product_representation(
self, product: ifcopenshell.entity_instance, representation: ifcopenshell.entity_instance
) -> None:
definition = product.Representation
if not definition:
definition = self.file.createIfcProductDefinitionShape()
@@ -18,6 +18,7 @@
import ifcopenshell.api.geometry
import ifcopenshell.util.element
from typing import Any
def unassign_representation(
@@ -30,13 +31,20 @@ def unassign_representation(
class Usecase:
def execute(self):
if self.settings["product"].is_a("IfcProduct"):
self.unassign_product_representation(self.settings["product"], self.settings["representation"])
elif self.settings["product"].is_a("IfcTypeProduct"):
file: ifcopenshell.file
settings: dict[str, Any]
def execute(self) -> None:
product: ifcopenshell.entity_instance = self.settings["product"]
representation: ifcopenshell.entity_instance = self.settings["representation"]
if product.is_a("IfcProduct"):
self.unassign_product_representation(product, representation)
elif product.is_a("IfcTypeProduct"):
self.unassign_type_representation()
def unassign_product_representation(self, product, representation):
def unassign_product_representation(
self, product: ifcopenshell.entity_instance, representation: ifcopenshell.entity_instance
) -> None:
representations = list(product.Representation.Representations or [])
if representation not in representations:
return
@@ -46,8 +54,7 @@ class Usecase:
else:
product.Representation.Representations = representations
def unassign_type_representation(self):
def unassign_type_representation(self) -> None:
matching_representation_map = None
representation_maps = self.settings["product"].RepresentationMaps or []
@@ -63,11 +70,11 @@ class Usecase:
] or None
self.remove_representation_map_only(matching_representation_map)
def remove_representation_map_only(self, representation_map):
def remove_representation_map_only(self, representation_map: ifcopenshell.entity_instance) -> None:
representation_map.MappedRepresentation = self.file.createIfcShapeRepresentation()
ifcopenshell.util.element.remove_deep2(self.file, representation_map)
def unassign_products_using_mapped_representation(self, representation_map):
def unassign_products_using_mapped_representation(self, representation_map: ifcopenshell.entity_instance) -> None:
mapped_representations = []
just_representations = []
for map_usage in representation_map.MapUsage or []:
@@ -19,7 +19,6 @@
import os
import json
import ifcopenshell.util.schema
from typing import List
cwd = os.path.dirname(os.path.realpath(__file__))
@@ -52,11 +51,19 @@ for schema in mapped_schemas:
type_to_entity_map[schema][element_type] = [e for e in elements if guessed_element in e]
def get_applicable_types(ifc_class: str, schema="IFC4") -> List[str]:
def get_applicable_types(ifc_class: str, schema="IFC4") -> list[str]:
"""Get applicable types IFC classes for the occurrence IFC class.
E.g. "IfcWindow" -> ["IfcWindowType"].
"""
schema = ifcopenshell.util.schema.get_fallback_schema(schema.upper())
return entity_to_type_map[schema].get(ifc_class, [])
def get_applicable_entities(ifc_type_class: str, schema="IFC4") -> List[str]:
def get_applicable_entities(ifc_type_class: str, schema="IFC4") -> list[str]:
"""Get applicable occurrence IFC classes for the type IFC class.
E.g. "IfcWindowType" -> ["IfcWindow"].
"""
schema = ifcopenshell.util.schema.get_fallback_schema(schema.upper())
return type_to_entity_map[schema].get(ifc_type_class, [])