mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 02:23:34 +00:00
Merge remote-tracking branch 'origin/ifcviewer' into datamodel-v1.0
This commit is contained in:
@@ -93,6 +93,11 @@ except Exception:
|
||||
from . import guid
|
||||
from .ifcopenshell_wrapper import entity_instance, file
|
||||
from .file import rocksdb_lazy_instance
|
||||
# Hacks!
|
||||
from .entity_instance import _patch_swig_comparisons
|
||||
_patch_swig_comparisons()
|
||||
del _patch_swig_comparisons
|
||||
# End hacks!
|
||||
from .sql import sqlite, sqlite_entity
|
||||
|
||||
# explicitly specify available imported symbols
|
||||
@@ -388,15 +393,24 @@ def stream2_from_string(data: str) -> Generator[dict]:
|
||||
yield inst
|
||||
|
||||
|
||||
def convert_path_to_rocksdb(ifcspf_path: Union[Path, str], rocksdb_path: Union[Path, str]) -> None:
|
||||
def convert_path_to_rocksdb(
|
||||
ifcspf_path: Union[Path, str],
|
||||
rocksdb_path: Union[Path, str],
|
||||
skip_supertypes: Optional[list[str]] = None,
|
||||
) -> None:
|
||||
"""Converts an IFC-SPF file on disk to the IfcOpenShell-specific
|
||||
RocksDB encoding. RocksDB is an embedded key-value store that allows
|
||||
partial reads and is therefore more memory efficient with larger files.
|
||||
|
||||
:param ifcspf_path: Input file path - needs to exist
|
||||
:param rocksdb_path: RocksDB file path (directory) - may exist, but result may then be invalid
|
||||
:param skip_supertypes: Optional list of entity type names. Any instance
|
||||
whose declaration is-a (or subclasses) one of these names will be
|
||||
omitted from the resulting RocksDB. Note: references to skipped
|
||||
instances become dangling - reads that walk into them will fail.
|
||||
"""
|
||||
ser = ifcopenshell_wrapper.RocksDbSerializer(str(ifcspf_path), str(rocksdb_path), True)
|
||||
skip = list(skip_supertypes) if skip_supertypes else []
|
||||
ser = ifcopenshell_wrapper.RocksDbSerializer(str(ifcspf_path), str(rocksdb_path), True, skip)
|
||||
ser.finalize()
|
||||
|
||||
|
||||
|
||||
@@ -213,11 +213,17 @@ class entity_instance_mixin:
|
||||
return value
|
||||
|
||||
def __eq__(self, other: entity_instance_mixin) -> bool:
|
||||
if not isinstance(self, type(other)):
|
||||
if other is None or not isinstance(other, entity_instance_mixin):
|
||||
return False
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
def __ne__(self, other: entity_instance_mixin) -> bool:
|
||||
if other is None or not isinstance(other, entity_instance_mixin):
|
||||
return True
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
def is_entity(self) -> bool:
|
||||
"""Tests whether the instance is an entity type as opposed to a simple data type.
|
||||
|
||||
@@ -395,3 +401,45 @@ class entity_instance_mixin:
|
||||
assert return_type is dict
|
||||
assert len(ignore) == 0
|
||||
return ifcopenshell_wrapper.get_info_cpp(self, recursive, include_identifier)
|
||||
|
||||
|
||||
# Alias for backwards compatibility — external code imports this name.
|
||||
entity_instance = entity_instance_mixin
|
||||
|
||||
|
||||
# Monkey-patch SWIG's __eq__, __ne__, __lt__ on the generated entity_instance
|
||||
# class to guard against None / non-entity arguments. SWIG generates these
|
||||
# directly on the class (overriding the mixin), and they pass arguments straight
|
||||
# to C++ which rejects null references.
|
||||
# Deferred until after ifcopenshell_wrapper finishes loading to avoid circular import.
|
||||
_swig_comparisons_patched = False
|
||||
|
||||
|
||||
def _patch_swig_comparisons():
|
||||
global _swig_comparisons_patched
|
||||
if _swig_comparisons_patched:
|
||||
return
|
||||
_swig_cls = ifcopenshell_wrapper.entity_instance
|
||||
_orig_eq = _swig_cls.__eq__
|
||||
_orig_ne = _swig_cls.__ne__
|
||||
_orig_lt = _swig_cls.__lt__
|
||||
|
||||
def _safe_eq(self, other):
|
||||
if other is None or not isinstance(other, _swig_cls):
|
||||
return NotImplemented
|
||||
return _orig_eq(self, other)
|
||||
|
||||
def _safe_ne(self, other):
|
||||
if other is None or not isinstance(other, _swig_cls):
|
||||
return NotImplemented
|
||||
return _orig_ne(self, other)
|
||||
|
||||
def _safe_lt(self, other):
|
||||
if other is None or not isinstance(other, _swig_cls):
|
||||
return NotImplemented
|
||||
return _orig_lt(self, other)
|
||||
|
||||
_swig_cls.__eq__ = _safe_eq
|
||||
_swig_cls.__ne__ = _safe_ne
|
||||
_swig_cls.__lt__ = _safe_lt
|
||||
_swig_comparisons_patched = True
|
||||
|
||||
Reference in New Issue
Block a user