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) ifcopenshell.util.element.remove_deep2(self.file, representation_map)
def unassign_products_using_mapped_representation(self, representation_map: ifcopenshell.entity_instance) -> None: def unassign_products_using_mapped_representation(self, representation_map: ifcopenshell.entity_instance) -> None:
mapped_representations = [] mapped_representations: list[dict[str, ifcopenshell.entity_instance]] = []
just_representations = [] just_representations: list[ifcopenshell.entity_instance] = []
for map_usage in representation_map.MapUsage or []: for map_usage in representation_map.MapUsage or []:
for inverse in self.file.get_inverse(map_usage): for inverse in self.file.get_inverse(map_usage):
if not inverse.is_a("IfcShapeRepresentation"): if not inverse.is_a("IfcShapeRepresentation"):
@@ -109,4 +109,4 @@ class Usecase:
for item in mapped_representations: for item in mapped_representations:
self.unassign_product_representation(item["product"], item["representation"]) self.unassign_product_representation(item["product"], item["representation"])
for representation in just_representations: 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/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
import functools import functools
import importlib import importlib
import numbers import numbers
@@ -25,12 +26,15 @@ import operator
import subprocess import subprocess
import sys import sys
import time 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 collections.abc import Callable, Sequence
from . import ifcopenshell_wrapper from . import ifcopenshell_wrapper
from . import settings from . import settings
if TYPE_CHECKING:
import ifcopenshell
try: try:
import logging import logging
except ImportError: except ImportError:
@@ -150,7 +154,8 @@ class entity_instance:
wrapped_data: ifcopenshell_wrapper.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): if isinstance(e, tuple):
e = ifcopenshell_wrapper.new_IfcBaseClass(*e) e = ifcopenshell_wrapper.new_IfcBaseClass(*e)
super().__setattr__("wrapped_data", e) super().__setattr__("wrapped_data", e)
@@ -423,7 +428,7 @@ class entity_instance:
"""Return the STEP numerical identifier""" """Return the STEP numerical identifier"""
return self.wrapped_data.id() 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)): if not isinstance(self, type(other)):
return False return False
elif None in (self.wrapped_data.file, other.wrapped_data.file): 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 # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # 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, ...]`. # `std::vector<xxx>` usually translated to `tuple[xxx, ...]`.
@@ -832,12 +832,12 @@ class file:
guid_map_: Any guid_map_: Any
stream: Any stream: Any
def FreshId(self): ... def FreshId(self): ...
def add(self, entity, id): ... def add(self, entity: entity_instance, id: int) -> entity_instance: ...
def addEntities(self, entities): ... def addEntities(self, entities): ...
def batch(self): ... def batch(self): ...
def build_inverses(self): ... def build_inverses(self): ...
def by_guid(self, guid): ... def by_guid(self, guid: str) -> entity_instance: ...
def by_id(self, id): ... def by_id(self, id: int) -> entity_instance: ...
def by_type(self, *args): ... def by_type(self, *args): ...
def by_type_excl_subtypes(self, *args): ... def by_type_excl_subtypes(self, *args): ...
@staticmethod @staticmethod
@@ -848,9 +848,15 @@ class file:
def getMaxId(self): ... def getMaxId(self): ...
def getTotalInverses(self, instance_id): ... def getTotalInverses(self, instance_id): ...
def getUnit(self, unit_type): ... def getUnit(self, unit_type): ...
def get_inverse(self, e): ... def get_inverse(self, e: entity_instance) -> tuple[entity_instance, ...]: ...
def get_inverse_indices(self, *args): ... def get_inverse_indices(self, *args: Union[entity_instance, int]) -> tuple[int, ...]:
def get_total_inverses(self, e): ... """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): ... def good(self): ...
@staticmethod @staticmethod
def guid_map(*args): ... def guid_map(*args): ...
@@ -862,14 +868,14 @@ class file:
def internal_guid_map(self): ... def internal_guid_map(self): ...
def load(self, entity_instance_name, entity, arg4, attribute_index): ... def load(self, entity_instance_name, entity, arg4, attribute_index): ...
def recalculate_id_counter(self): ... def recalculate_id_counter(self): ...
def remove(self, entity): ... def remove(self, entity: entity_instance) -> None: ...
@property @property
def schema(self): ... def schema(self): ...
def to_string(self): ... def to_string(self): ...
@staticmethod @staticmethod
def traverse(instance, max_level): ... def traverse(instance: entity_instance, max_level: int) -> tuple[entity_instance, ...]: ...
@staticmethod @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 try_read_semicolon(self): ...
def types(self) -> tuple[str, ...]: def types(self) -> tuple[str, ...]:
"""Return a tuple of classes present in the file. """Return a tuple of classes present in the file.
@@ -1592,7 +1592,7 @@ def remove_deep2(
if not are_inverses_contained(): if not are_inverses_contained():
return return
to_delete = set() to_delete: set[ifcopenshell.entity_instance] = set()
subgraph = list(ifc_file.traverse(element, breadth_first=True)) subgraph = list(ifc_file.traverse(element, breadth_first=True))
subgraph.extend(also_consider) subgraph.extend(also_consider)
subgraph_set = set(subgraph) subgraph_set = set(subgraph)