mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
typing
This commit is contained in:
@@ -27,7 +27,7 @@ import ifcopenshell.util.representation
|
||||
import ifcopenshell.util.type
|
||||
import ifcopenshell.util.schema
|
||||
import ifcopenshell.util.element
|
||||
from typing import Optional, Union, Literal, Any
|
||||
from typing import Optional, Union, Literal
|
||||
|
||||
|
||||
def reassign_class(
|
||||
@@ -56,7 +56,6 @@ def reassign_class(
|
||||
Reassigning type class to occurrence (and vice versa) is supported.
|
||||
|
||||
:param product: The IfcProduct that you want to change the class of.
|
||||
:type product: ifcopenshell.entity_instance
|
||||
:param ifc_class: The new IFC class you want to change it to.
|
||||
:param predefined_type: In case you want to change the predefined type
|
||||
too. User defined types are also allowed, just type what you want.
|
||||
@@ -77,25 +76,18 @@ def reassign_class(
|
||||
"""
|
||||
usecase = Usecase()
|
||||
usecase.file = file
|
||||
usecase.settings = {
|
||||
"product": product,
|
||||
"ifc_class": ifc_class,
|
||||
"predefined_type": predefined_type,
|
||||
}
|
||||
return usecase.execute()
|
||||
return usecase.execute(product, ifc_class, predefined_type)
|
||||
|
||||
|
||||
class Usecase:
|
||||
file: ifcopenshell.file
|
||||
settings: dict[str, Any]
|
||||
|
||||
def execute(self):
|
||||
ifc_class: str = self.settings["ifc_class"]
|
||||
product: ifcopenshell.entity_instance = self.settings["product"]
|
||||
predefined_type: Union[str, None] = self.settings["predefined_type"]
|
||||
|
||||
def execute(
|
||||
self, product: ifcopenshell.entity_instance, ifc_class: str, predefined_type: Union[str, None]
|
||||
) -> ifcopenshell.entity_instance:
|
||||
was_type_product_before = product.is_a("IfcTypeProduct")
|
||||
schema = ifcopenshell.schema_by_name(self.file.schema)
|
||||
is_type_product_after: bool
|
||||
is_type_product_after = schema.declaration_by_name(ifc_class)._is("IfcTypeProduct")
|
||||
|
||||
if was_type_product_before == is_type_product_after:
|
||||
|
||||
@@ -28,9 +28,7 @@ def unassign_type(file: ifcopenshell.file, related_objects: list[ifcopenshell.en
|
||||
and material usages associated with the previously assigned type.
|
||||
|
||||
:param related_objects: List of IfcElement occurrences.
|
||||
:type related_objects: list[ifcopenshell.entity_instance]
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
|
||||
@@ -50,23 +48,21 @@ def unassign_type(file: ifcopenshell.file, related_objects: list[ifcopenshell.en
|
||||
# Change our mind. Maybe it's a different type?
|
||||
ifcopenshell.api.type.unassign_type(model, related_objects=[furniture])
|
||||
"""
|
||||
settings = {"related_objects": related_objects}
|
||||
|
||||
related_objects = set(settings["related_objects"])
|
||||
related_objects_set = set(related_objects)
|
||||
|
||||
if file.schema == "IFC2X3":
|
||||
rels = set(
|
||||
rel
|
||||
for object in related_objects
|
||||
for object in related_objects_set
|
||||
if (rel := next((rel for rel in object.IsDefinedBy if rel.is_a("IfcRelDefinesByType")), None))
|
||||
)
|
||||
else:
|
||||
rels = set(rel for object in related_objects if (rel := next((rel for rel in object.IsTypedBy), None)))
|
||||
rels = set(rel for object in related_objects_set if (rel := next((rel for rel in object.IsTypedBy), None)))
|
||||
|
||||
for rel in rels:
|
||||
related_objects = set(rel.RelatedObjects) - related_objects
|
||||
if related_objects:
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
related_objects_set = set(rel.RelatedObjects) - related_objects_set
|
||||
if related_objects_set:
|
||||
rel.RelatedObjects = list(related_objects_set)
|
||||
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
|
||||
else:
|
||||
history = rel.OwnerHistory
|
||||
|
||||
@@ -21,6 +21,7 @@ import json
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.util.classification
|
||||
from typing import Union
|
||||
|
||||
|
||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||
@@ -31,7 +32,7 @@ with open(os.path.join(cwd, "ifc4_to_brick.json")) as f:
|
||||
ifc4_to_brick_map = json.load(f)
|
||||
|
||||
|
||||
def get_brick_type(element):
|
||||
def get_brick_type(element: ifcopenshell.entity_instance) -> Union[str, None]:
|
||||
references = ifcopenshell.util.classification.get_references(element)
|
||||
for reference in references:
|
||||
system = ifcopenshell.util.classification.get_classification(reference)
|
||||
@@ -61,10 +62,10 @@ def get_brick_type(element):
|
||||
return f"https://brickschema.org/schema/Brick#System"
|
||||
|
||||
|
||||
def get_element_feeds(element):
|
||||
def get_element_feeds(element: ifcopenshell.entity_instance) -> set[ifcopenshell.entity_instance]:
|
||||
current_element = element
|
||||
processed_elements = set()
|
||||
downstream_equipment = set()
|
||||
downstream_equipment: set[ifcopenshell.entity_instance] = set()
|
||||
|
||||
# A queue is a list of branches. A branch is a list of elements in
|
||||
# sequence, each one connecting to another element. An element in a
|
||||
|
||||
Reference in New Issue
Block a user