This commit is contained in:
Andrej730
2025-06-17 11:46:15 +05:00
parent 404c39873d
commit 9282ccabb3
13 changed files with 77 additions and 39 deletions
@@ -26,7 +26,7 @@ import operator
import subprocess
import sys
import time
from typing import Union, Any, TypeVar, overload, TYPE_CHECKING
from typing import Union, Any, TypeVar, overload, TYPE_CHECKING, cast, NoReturn
from collections.abc import Callable, Sequence
from . import ifcopenshell_wrapper
@@ -64,17 +64,20 @@ def set_unsupported_attribute(*args):
# done for each invocation of __setitem__. Now this
# mapping is built once during initialization of the
# module.
_method_dict = {}
MethodList = list[Callable[[ifcopenshell_wrapper.entity_instance, int, Any], Union[None, NoReturn]]]
"""List of setter methods for class attributes."""
_method_dict: dict[str, MethodList] = {}
"""Mapping of entity classes (e.g. 'IFC4.IfcWall') to MethodLists."""
def register_schema_attributes(schema: ifcopenshell_wrapper.schema_definition) -> None:
for decl in schema.declarations():
decl: ifcopenshell_wrapper.declaration
if hasattr(decl, "argument_types"):
fq_name = ".".join((schema.name(), decl.name()))
# get type strings as reported by IfcOpenShell C++
type_strs = decl.argument_types()
type_strs = cast(Sequence[str], type_strs)
# convert case for setter function
type_strs = [x.title().replace(" ", "") for x in type_strs]
@@ -16,6 +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/>.
import ifcopenshell
from typing import Any, Union, Literal
# `std::vector<xxx>` usually translated to `tuple[xxx, ...]`.
@@ -775,6 +776,9 @@ class entity(declaration):
def supertype(self) -> Union[entity, None]: ...
class entity_instance:
file: ifcopenshell.file
"""Reference to IFC file to prevent it's garbage collection, if entity is still used."""
file_: Any
id_: Any
def data(self, *args): ...
@@ -282,9 +282,10 @@ def get_cost_values(cost_item: ifcopenshell.entity_instance) -> list[dict[str, s
def get_cost_schedule_types(file: ifcopenshell.file) -> list[dict[str, str]]:
schema: ifcopenshell_wrapper.schema_definition = ifcopenshell_wrapper.schema_by_name(file.schema_identifier)
schema = ifcopenshell_wrapper.schema_by_name(file.schema_identifier)
results = []
declaration = schema.declaration_by_name("IfcCostSchedule")
declaration = schema.declaration_by_name("IfcCostSchedule").as_entity()
assert declaration
version = file.schema_identifier
for attribute in declaration.attributes():
if attribute.name() == "PredefinedType":
@@ -136,8 +136,8 @@ def get_subtypes(
[<entity IfcFlowSegment>, <entity IfcCableCarrierSegment>, ..., <entity IfcPipeSegment>]
"""
def get_classes(decl):
results = []
def get_classes(decl: ifcopenshell_wrapper.entity) -> list[ifcopenshell_wrapper.entity]:
results: list[ifcopenshell_wrapper.entity] = []
if not decl.is_abstract():
results.append(decl)
for subtype in decl.subtypes():
@@ -172,7 +172,7 @@ def reassign_class(
if not ifc_file:
ifc_file = element.file
schema: ifcopenshell_wrapper.schema_definition = ifcopenshell_wrapper.schema_by_name(ifc_file.schema_identifier)
schema = ifcopenshell_wrapper.schema_by_name(ifc_file.schema_identifier)
try:
declaration = schema.declaration_by_name(new_class)
except RuntimeError:
@@ -815,12 +815,13 @@ def iter_element_and_attributes_per_type(ifc_file: ifcopenshell.file, attr_type_
None,
None,
]:
schema: ifcopenshell_wrapper.schema_definition = ifcopenshell_wrapper.schema_by_name(ifc_file.schema_identifier)
schema = ifcopenshell_wrapper.schema_by_name(ifc_file.schema_identifier)
for element in ifc_file:
entity = schema.declaration_by_name(element.is_a())
entity = schema.declaration_by_name(element.is_a()).as_entity()
assert entity
attrs = entity.all_attributes()
attrs_derived: tuple[bool, ...] = entity.derived()
attrs_derived = entity.derived()
for attr, val, is_derived in zip(attrs, list(element), attrs_derived):
if is_derived:
continue