This commit is contained in:
Andrej
2025-06-10 10:34:14 +05:00
parent 862119834f
commit a37d46ca3d
4 changed files with 28 additions and 17 deletions
@@ -96,8 +96,8 @@ class Usecase:
ifcopenshell.util.element.remove_deep2(self.file, representation_map)
def unassign_products_using_mapped_representation(self, representation_map: ifcopenshell.entity_instance) -> None:
mapped_representations = []
just_representations = []
mapped_representations: list[dict[str, ifcopenshell.entity_instance]] = []
just_representations: list[ifcopenshell.entity_instance] = []
for map_usage in representation_map.MapUsage or []:
for inverse in self.file.get_inverse(map_usage):
if not inverse.is_a("IfcShapeRepresentation"):
@@ -109,4 +109,4 @@ class Usecase:
for item in mapped_representations:
self.unassign_product_representation(item["product"], item["representation"])
for representation in just_representations:
ifcopenshell.api.geometry.remove_representation(self.file, **{"representation": representation})
ifcopenshell.api.geometry.remove_representation(self.file, representation=representation)
@@ -17,6 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
import functools
import importlib
import numbers
@@ -25,12 +26,15 @@ import operator
import subprocess
import sys
import time
from typing import Union, Any, TypeVar, overload
from typing import Union, Any, TypeVar, overload, TYPE_CHECKING
from collections.abc import Callable, Sequence
from . import ifcopenshell_wrapper
from . import settings
if TYPE_CHECKING:
import ifcopenshell
try:
import logging
except ImportError:
@@ -150,7 +154,8 @@ class entity_instance:
wrapped_data: ifcopenshell_wrapper.entity_instance
def __init__(self, e, file=None):
def __init__(self, e: ifcopenshell_wrapper.entity_instance, file: Union[ifcopenshell.file] = None):
# TODO: when it is a tuple?
if isinstance(e, tuple):
e = ifcopenshell_wrapper.new_IfcBaseClass(*e)
super().__setattr__("wrapped_data", e)
@@ -423,7 +428,7 @@ class entity_instance:
"""Return the STEP numerical identifier"""
return self.wrapped_data.id()
def __eq__(self, other: "entity_instance") -> bool:
def __eq__(self, other: entity_instance) -> bool:
if not isinstance(self, type(other)):
return False
elif None in (self.wrapped_data.file, other.wrapped_data.file):
@@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
from typing import Any
from typing import Any, Union
# `std::vector<xxx>` usually translated to `tuple[xxx, ...]`.
@@ -832,12 +832,12 @@ class file:
guid_map_: Any
stream: Any
def FreshId(self): ...
def add(self, entity, id): ...
def add(self, entity: entity_instance, id: int) -> entity_instance: ...
def addEntities(self, entities): ...
def batch(self): ...
def build_inverses(self): ...
def by_guid(self, guid): ...
def by_id(self, id): ...
def by_guid(self, guid: str) -> entity_instance: ...
def by_id(self, id: int) -> entity_instance: ...
def by_type(self, *args): ...
def by_type_excl_subtypes(self, *args): ...
@staticmethod
@@ -848,9 +848,15 @@ class file:
def getMaxId(self): ...
def getTotalInverses(self, instance_id): ...
def getUnit(self, unit_type): ...
def get_inverse(self, e): ...
def get_inverse_indices(self, *args): ...
def get_total_inverses(self, e): ...
def get_inverse(self, e: entity_instance) -> tuple[entity_instance, ...]: ...
def get_inverse_indices(self, *args: Union[entity_instance, int]) -> tuple[int, ...]:
"""Get the attribute indices for each inverse from `get_inverse`, that reference the provided entity..
:param args: entity or it's id. Maximum 1 entity at the time.
"""
...
def get_total_inverses(self, e: entity_instance) -> int: ...
def good(self): ...
@staticmethod
def guid_map(*args): ...
@@ -862,14 +868,14 @@ class file:
def internal_guid_map(self): ...
def load(self, entity_instance_name, entity, arg4, attribute_index): ...
def recalculate_id_counter(self): ...
def remove(self, entity): ...
def remove(self, entity: entity_instance) -> None: ...
@property
def schema(self): ...
def to_string(self): ...
@staticmethod
def traverse(instance, max_level): ...
def traverse(instance: entity_instance, max_level: int) -> tuple[entity_instance, ...]: ...
@staticmethod
def traverse_breadth_first(instance, max_level): ...
def traverse_breadth_first(instance: entity_instance, max_level: int) -> tuple[entity_instance, ...]: ...
def try_read_semicolon(self): ...
def types(self) -> tuple[str, ...]:
"""Return a tuple of classes present in the file.
@@ -1592,7 +1592,7 @@ def remove_deep2(
if not are_inverses_contained():
return
to_delete = set()
to_delete: set[ifcopenshell.entity_instance] = set()
subgraph = list(ifc_file.traverse(element, breadth_first=True))
subgraph.extend(also_consider)
subgraph_set = set(subgraph)