This commit is contained in:
Thomas Krijnen
2026-01-10 11:52:08 +01:00
parent 0604db06e9
commit 0a9e29ce45
6 changed files with 15 additions and 25 deletions
@@ -197,9 +197,7 @@ class entity_instance_mixin:
except IndexError as e: except IndexError as e:
# get_argument_index returns 0xFFFFFFFF if attribute is not found # get_argument_index returns 0xFFFFFFFF if attribute is not found
if index == 0xFFFFFFFF: if index == 0xFFFFFFFF:
raise AttributeError( raise AttributeError("entity instance of type '%s' has no attribute '%s'" % (self.is_a(True), key))
"entity instance of type '%s' has no attribute '%s'" % (self.is_a(True), key)
)
raise e raise e
def __getitem__(self, key: int) -> Any: def __getitem__(self, key: int) -> Any:
@@ -210,18 +208,17 @@ class entity_instance_mixin:
def __setitem__(self, idx: int, value: T) -> T: def __setitem__(self, idx: int, value: T) -> T:
if self.file and self.file.transaction: if self.file and self.file.transaction:
self.file.transaction.store_edit(self, idx, value) self.file.transaction.store_edit(self, idx, value)
self.set_attribute_value_py(idx, value) self.set_attribute_value_py(idx, value)
return value return value
def __eq__(self, other: entity_instance_mixin) -> bool: def __eq__(self, other: entity_instance_mixin) -> bool:
if not isinstance(self, type(other)): if not isinstance(self, type(other)):
return False return False
else: else:
raise NotImplementedError raise NotImplementedError
def is_entity(self) -> bool: def is_entity(self) -> bool:
"""Tests whether the instance is an entity type as opposed to a simple data type. """Tests whether the instance is an entity type as opposed to a simple data type.
+8 -7
View File
@@ -232,8 +232,10 @@ class Transaction:
else: else:
assert_never(operation["action"]) assert_never(operation["action"])
import struct import struct
def consume_buffer(val, inner): def consume_buffer(val, inner):
while val: while val:
s = struct.unpack("@q", val[:8])[0] s = struct.unpack("@q", val[:8])[0]
@@ -506,22 +508,22 @@ class file_mixin:
registry = {} registry = {}
def post_init(self, iden = None): def post_init(self, iden=None):
if iden is None: if iden is None:
iden = int(self.this) iden = int(self.this)
if state := self.registry.get(iden): if state := self.registry.get(iden):
self.state = state self.state = state
else: else:
self.state = self.registry[iden] = [[],[],None] self.state = self.registry[iden] = [[], [], None]
@property @property
def history(self): def history(self):
return self.state[0] return self.state[0]
@property @property
def future(self): def future(self):
return self.state[1] return self.state[1]
@property @property
def transaction(self): def transaction(self):
return self.state[2] return self.state[2]
@@ -529,7 +531,7 @@ class file_mixin:
@transaction.setter @transaction.setter
def transaction(self, v): def transaction(self, v):
self.state[2] = v self.state[2] = v
def set_history_size(self, size: int) -> None: def set_history_size(self, size: int) -> None:
self.history_size = size self.history_size = size
while len(self.history) > self.history_size: while len(self.history) > self.history_size:
@@ -699,7 +701,6 @@ class file_mixin:
else: else:
raise TypeError("Indexing into file requires either an integral number or compressed guid string") raise TypeError("Indexing into file requires either an integral number or compressed guid string")
def add(self, inst: ifcopenshell.entity_instance, _id: int = None) -> ifcopenshell.entity_instance: def add(self, inst: ifcopenshell.entity_instance, _id: int = None) -> ifcopenshell.entity_instance:
"""Adds an entity including any dependent entities to an IFC file. """Adds an entity including any dependent entities to an IFC file.
If the entity already exists, it is not re-added. Existence of entity is checked by it's `.identity()`. If the entity already exists, it is not re-added. Existence of entity is checked by it's `.identity()`.
@@ -710,7 +711,7 @@ class file_mixin:
if self.transaction: if self.transaction:
max_id = self.getMaxId() max_id = self.getMaxId()
result = self._add(inst, -1 if _id is None else _id) result = self._add(inst, -1 if _id is None else _id)
if self.transaction: if self.transaction:
@@ -507,9 +507,7 @@ def create_shape(
""" """
return wrap_shape_creation( return wrap_shape_creation(
settings, settings,
ifcopenshell_wrapper.create_shape( ifcopenshell_wrapper.create_shape(settings, inst, repr if repr is not None else None, geometry_library),
settings, inst, repr if repr is not None else None, geometry_library
),
) )
+1 -3
View File
@@ -430,9 +430,7 @@ class sqlite_entity(entity_instance):
self.sqlite_wrapper.inverse_attribute_cache[name] = tuple(results) self.sqlite_wrapper.inverse_attribute_cache[name] = tuple(results)
return self.sqlite_wrapper.inverse_attribute_cache[name] return self.sqlite_wrapper.inverse_attribute_cache[name]
raise AttributeError( raise AttributeError("entity instance of type '%s' has no attribute '%s'" % (self.is_a(True), name))
"entity instance of type '%s' has no attribute '%s'" % (self.is_a(True), name)
)
def unserialise_value(self, value): def unserialise_value(self, value):
if isinstance(value, (tuple, list)): if isinstance(value, (tuple, list)):
@@ -387,9 +387,7 @@ try:
self.stream_wrapper.inverse_attribute_cache[name] = tuple(results) self.stream_wrapper.inverse_attribute_cache[name] = tuple(results)
return self.stream_wrapper.inverse_attribute_cache[name] return self.stream_wrapper.inverse_attribute_cache[name]
raise AttributeError( raise AttributeError("entity instance of type '%s' has no attribute '%s'" % (self.is_a(True), name))
"entity instance of type '%s' has no attribute '%s'" % (self.is_a(True), name)
)
def __eq__(self, other: stream_entity) -> bool: def __eq__(self, other: stream_entity) -> bool:
if not isinstance(self, type(other)): if not isinstance(self, type(other)):
@@ -639,9 +639,7 @@ def set_element_value(
except: except:
# Try to cast # Try to cast
data_type = ifcopenshell.util.attribute.get_primitive_type( data_type = ifcopenshell.util.attribute.get_primitive_type(
element.declaration() element.declaration().as_entity().attribute_by_index(element.get_argument_index(key))
.as_entity()
.attribute_by_index(element.get_argument_index(key))
) )
if data_type == "string": if data_type == "string":
value = str(value) value = str(value)