mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
typing
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
import ifcopenshell.api.owner
|
import ifcopenshell.api.owner
|
||||||
import ifcopenshell.api.geometry
|
import ifcopenshell.api.geometry
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
def assign_representation(
|
def assign_representation(
|
||||||
@@ -31,7 +32,10 @@ def assign_representation(
|
|||||||
|
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
def execute(self):
|
file: ifcopenshell.file
|
||||||
|
settings: dict[str, Any]
|
||||||
|
|
||||||
|
def execute(self) -> None:
|
||||||
if self.settings["product"].is_a("IfcProduct"):
|
if self.settings["product"].is_a("IfcProduct"):
|
||||||
product_type = ifcopenshell.util.element.get_type(self.settings["product"])
|
product_type = ifcopenshell.util.element.get_type(self.settings["product"])
|
||||||
if (
|
if (
|
||||||
@@ -73,7 +77,9 @@ class Usecase:
|
|||||||
self.assign_product_representation(element, mapped_representation)
|
self.assign_product_representation(element, mapped_representation)
|
||||||
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": self.settings["product"]})
|
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
|
definition = product.Representation
|
||||||
if not definition:
|
if not definition:
|
||||||
definition = self.file.createIfcProductDefinitionShape()
|
definition = self.file.createIfcProductDefinitionShape()
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import ifcopenshell.api.geometry
|
import ifcopenshell.api.geometry
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
def unassign_representation(
|
def unassign_representation(
|
||||||
@@ -30,13 +31,20 @@ def unassign_representation(
|
|||||||
|
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
def execute(self):
|
file: ifcopenshell.file
|
||||||
if self.settings["product"].is_a("IfcProduct"):
|
settings: dict[str, Any]
|
||||||
self.unassign_product_representation(self.settings["product"], self.settings["representation"])
|
|
||||||
elif self.settings["product"].is_a("IfcTypeProduct"):
|
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()
|
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 [])
|
representations = list(product.Representation.Representations or [])
|
||||||
if representation not in representations:
|
if representation not in representations:
|
||||||
return
|
return
|
||||||
@@ -46,8 +54,7 @@ class Usecase:
|
|||||||
else:
|
else:
|
||||||
product.Representation.Representations = representations
|
product.Representation.Representations = representations
|
||||||
|
|
||||||
def unassign_type_representation(self):
|
def unassign_type_representation(self) -> None:
|
||||||
|
|
||||||
matching_representation_map = None
|
matching_representation_map = None
|
||||||
representation_maps = self.settings["product"].RepresentationMaps or []
|
representation_maps = self.settings["product"].RepresentationMaps or []
|
||||||
|
|
||||||
@@ -63,11 +70,11 @@ class Usecase:
|
|||||||
] or None
|
] or None
|
||||||
self.remove_representation_map_only(matching_representation_map)
|
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()
|
representation_map.MappedRepresentation = self.file.createIfcShapeRepresentation()
|
||||||
ifcopenshell.util.element.remove_deep2(self.file, representation_map)
|
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 = []
|
mapped_representations = []
|
||||||
just_representations = []
|
just_representations = []
|
||||||
for map_usage in representation_map.MapUsage or []:
|
for map_usage in representation_map.MapUsage or []:
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import ifcopenshell.util.schema
|
import ifcopenshell.util.schema
|
||||||
from typing import List
|
|
||||||
|
|
||||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
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]
|
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())
|
schema = ifcopenshell.util.schema.get_fallback_schema(schema.upper())
|
||||||
return entity_to_type_map[schema].get(ifc_class, [])
|
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())
|
schema = ifcopenshell.util.schema.get_fallback_schema(schema.upper())
|
||||||
return type_to_entity_map[schema].get(ifc_type_class, [])
|
return type_to_entity_map[schema].get(ifc_type_class, [])
|
||||||
|
|||||||
Reference in New Issue
Block a user