mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
typing
This commit is contained in:
@@ -41,9 +41,9 @@ def remove_representation(
|
||||
styled_items = set()
|
||||
presentation_layer_assignments_items: set[ifcopenshell.entity_instance] = set()
|
||||
presentation_layer_assignments_reps: set[ifcopenshell.entity_instance] = set()
|
||||
textures = set()
|
||||
colours = set()
|
||||
named_profiles = set()
|
||||
textures: set[ifcopenshell.entity_instance] = set()
|
||||
colours: set[ifcopenshell.entity_instance] = set()
|
||||
named_profiles: set[ifcopenshell.entity_instance] = set()
|
||||
for subelement in file.traverse(representation):
|
||||
if subelement.is_a("IfcRepresentationItem"):
|
||||
[styled_items.add(s) for s in subelement.StyledByItem or []]
|
||||
|
||||
@@ -154,8 +154,14 @@ class entity_instance:
|
||||
|
||||
wrapped_data: ifcopenshell_wrapper.entity_instance
|
||||
|
||||
def __init__(self, e: ifcopenshell_wrapper.entity_instance, file: Union[ifcopenshell.file] = None):
|
||||
# TODO: when it is a tuple?
|
||||
def __init__(
|
||||
self,
|
||||
e: Union[ifcopenshell_wrapper.entity_instance, tuple[str, str]],
|
||||
file: Union[ifcopenshell.file, None] = None,
|
||||
):
|
||||
"""
|
||||
:param e: Wrapper's ``entity_instance`` or a tuple ``(schema_identifier, ifc_class)``.
|
||||
"""
|
||||
if isinstance(e, tuple):
|
||||
e = ifcopenshell_wrapper.new_IfcBaseClass(*e)
|
||||
super().__setattr__("wrapped_data", e)
|
||||
@@ -290,11 +296,11 @@ class entity_instance:
|
||||
return value
|
||||
|
||||
@staticmethod
|
||||
def wrap_value(v, file):
|
||||
def wrap(e):
|
||||
def wrap_value(v, file: ifcopenshell.file):
|
||||
def wrap(e: ifcopenshell_wrapper.entity_instance) -> entity_instance:
|
||||
return entity_instance(e, file)
|
||||
|
||||
def is_instance(e):
|
||||
def is_instance(e: Any) -> bool:
|
||||
return isinstance(e, ifcopenshell_wrapper.entity_instance)
|
||||
|
||||
return entity_instance.walk(is_instance, wrap, v)
|
||||
|
||||
@@ -23,6 +23,7 @@ import numbers
|
||||
import zipfile
|
||||
import functools
|
||||
import ifcopenshell
|
||||
import weakref
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional, TYPE_CHECKING, Union, overload, Literal, TypedDict
|
||||
from collections.abc import Callable, Generator
|
||||
@@ -241,7 +242,11 @@ class Transaction:
|
||||
pass
|
||||
|
||||
|
||||
file_dict = {}
|
||||
file_dict: dict[int, weakref.ReferenceType[file]] = {}
|
||||
"""Mapping of internal IfcFile pointer addressed to existing ``ifcopenshell.file``.
|
||||
|
||||
Needed only to quickly access related from ``entity_instance`` it's ``file``.
|
||||
"""
|
||||
|
||||
READ_ERROR = ifcopenshell_wrapper.file_open_status.READ_ERROR
|
||||
NO_HEADER = ifcopenshell_wrapper.file_open_status.NO_HEADER
|
||||
@@ -349,9 +354,7 @@ class file:
|
||||
self.future = []
|
||||
self.transaction: Optional[Transaction] = None
|
||||
|
||||
import weakref
|
||||
|
||||
file_dict[self.file_pointer()] = weakref.ref(self)
|
||||
file_dict[self.wrapped_data.file_pointer()] = weakref.ref(self)
|
||||
|
||||
def __del__(self) -> None:
|
||||
# Avoid infinite recursion if file is failed to initialize
|
||||
@@ -402,7 +405,7 @@ class file:
|
||||
raise UndoSystemError("Error during transaction redo.", transaction) from e
|
||||
self.history.append(transaction)
|
||||
|
||||
def create_entity(self, type: str, *args, **kwargs) -> ifcopenshell.entity_instance:
|
||||
def create_entity(self, type: str, *args: Any, **kwargs: Any) -> ifcopenshell.entity_instance:
|
||||
"""Create a new IFC entity in the file.
|
||||
|
||||
You can also use dynamic methods similar to `ifc_file.createIfcWall(...)`
|
||||
@@ -768,8 +771,9 @@ class file:
|
||||
return file(ifcopenshell_wrapper.read(s))
|
||||
|
||||
@staticmethod
|
||||
def from_pointer(v) -> file:
|
||||
return file_dict.get(v)()
|
||||
def from_pointer(address: int) -> file:
|
||||
assert (f := file_dict[address]()) is not None
|
||||
return f
|
||||
|
||||
def to_string(self) -> str:
|
||||
return self.wrapped_data.to_string()
|
||||
|
||||
@@ -780,7 +780,10 @@ class entity_instance:
|
||||
def data(self, *args): ...
|
||||
def declaration(self) -> declaration: ...
|
||||
def file_pointer(self):
|
||||
"""Internal IfcFile pointer address."""
|
||||
"""Internal IfcFile pointer address.
|
||||
|
||||
Same as ``file.file_pointer``).
|
||||
"""
|
||||
...
|
||||
|
||||
def get_argument(self, *args): ...
|
||||
@@ -865,7 +868,28 @@ class file:
|
||||
def FreshId(self): ...
|
||||
def add(self, entity: entity_instance, id: int) -> entity_instance: ...
|
||||
def addEntities(self, entities): ...
|
||||
def batch(self): ...
|
||||
def batch(self) -> None:
|
||||
"""Enable batch mode.
|
||||
|
||||
Batch mode:
|
||||
1. Calling ``remove(entity)`` does not immediately remove the entity;
|
||||
it marks it for deletion instead.
|
||||
2. When you call ``unbatch()``, all marked entities are deleted in a single operation.
|
||||
|
||||
Difference from usual removal:
|
||||
- In normal mode, removing an entity immediately traverses and removes all inverse references to it.
|
||||
- In batch mode, inverse references are not updated per entity.
|
||||
Instead, the entire inverse reference map is scanned during ``unbatch()``
|
||||
to remove references to all deleted entities.
|
||||
|
||||
Batch deletion may be slower than immediate deletion, depending on the size of the inverse reference map.
|
||||
"""
|
||||
...
|
||||
|
||||
def unbatch(self) -> None:
|
||||
"""Exit batch mode."""
|
||||
...
|
||||
|
||||
def build_inverses(self): ...
|
||||
def by_guid(self, guid: str) -> entity_instance: ...
|
||||
def by_id(self, id: int) -> entity_instance: ...
|
||||
@@ -873,9 +897,15 @@ class file:
|
||||
def by_type_excl_subtypes(self, *args): ...
|
||||
@staticmethod
|
||||
def createTimestamp(): ...
|
||||
def entity_names(self): ...
|
||||
def entity_names(self) -> tuple[int, ...]:
|
||||
"""Get a tuple of step ids present in the file."""
|
||||
...
|
||||
|
||||
def file_pointer(self) -> int:
|
||||
"""Internal IfcFile pointer address."""
|
||||
"""Internal IfcFile pointer address.
|
||||
|
||||
Same as ``int(self.this)``.
|
||||
"""
|
||||
...
|
||||
|
||||
def get_inverses_by_declaration(
|
||||
@@ -907,7 +937,7 @@ class file:
|
||||
def guid_map(*args): ...
|
||||
@property
|
||||
def header(self) -> IfcSpfHeader: ...
|
||||
def ifcroot_type(self): ...
|
||||
def ifcroot_type(self) -> entity: ...
|
||||
def instance_by_guid(self, guid): ...
|
||||
def instances_by_reference(self, id): ...
|
||||
def internal_guid_map(self): ...
|
||||
@@ -931,7 +961,6 @@ class file:
|
||||
|
||||
def types_begin(self): ...
|
||||
def types_end(self): ...
|
||||
def unbatch(self): ...
|
||||
def write(self, fn): ...
|
||||
|
||||
class file_open_status:
|
||||
@@ -1501,7 +1530,7 @@ def less(arg1, arg2): ...
|
||||
def line_segments_to_polygons(s, eps, segments): ...
|
||||
def map_shape(settings, instance): ...
|
||||
def nary_union(sequence): ...
|
||||
def new_IfcBaseClass(schema_identifier, name): ...
|
||||
def new_IfcBaseClass(schema_identifier: str, name: str) -> entity_instance: ...
|
||||
def open(fn): ...
|
||||
def parse_ifcxml(filename): ...
|
||||
def polygons_to_svg(*args): ...
|
||||
|
||||
@@ -1519,7 +1519,7 @@ def unbatch_remove_deep2(ifc_file: ifcopenshell.file) -> ifcopenshell.file:
|
||||
lines = iter(ifc_string.split("\n"))
|
||||
ids_to_delete = iter(sorted([e.id() for e in ifc_file.to_delete]))
|
||||
id_to_delete = next(ids_to_delete, None)
|
||||
result = []
|
||||
result: list[str] = []
|
||||
|
||||
for line in lines:
|
||||
if id_to_delete is None:
|
||||
|
||||
Reference in New Issue
Block a user