Skip to content

Commit 80066ba

Browse files
committed
Different hack for allowing f.header.file_description.file.header.file_description.file
1 parent 7cb1f07 commit 80066ba

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

src/ifcopenshell-python/ifcopenshell/file.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,24 @@ def schema(self) -> ifcopenshell.util.schema.IFC_SCHEMA:
497497
return "".join("".join(map(str, t)) if t[1] else "" for t in zip(prefixes, version_tuple[0:2]))
498498

499499

500+
class file_header:
501+
def __init__(self, file, header_data):
502+
self.file = file
503+
self.header_data = header_data
504+
505+
@property
506+
def file_description(self) -> entity_instance:
507+
return entity_instance.wrap_value(self.header_data.file_description_py(), file=self.file)
508+
509+
@property
510+
def file_name(self) -> entity_instance:
511+
return entity_instance.wrap_value(self.header_data.file_name_py(), file=self.file)
512+
513+
@property
514+
def file_schema(self) -> entity_instance:
515+
return entity_instance.wrap_value(self.header_data.file_schema_py(), file=self.file)
516+
517+
500518
class file:
501519
"""Base class for containing IFC files.
502520
@@ -514,7 +532,7 @@ class file:
514532
"""
515533

516534
wrapped_data: ifcopenshell_wrapper.file
517-
header: ifcopenshell_wrapper.IfcSpfHeader
535+
header: file_header
518536
units: dict[str, entity_instance] = {}
519537
history_size: int = 64
520538
history: list[Transaction]
@@ -1029,12 +1047,7 @@ def to_string(self) -> str:
10291047

10301048
@property
10311049
def header(self):
1032-
try: # Temporary workaround until new builds are ready. See #7131.
1033-
h = self.wrapped_data.header()
1034-
except:
1035-
return self.wrapped_data.header
1036-
object.__setattr__(h, "file_ref", lambda inst: entity_instance.wrap_value(inst, file=self))
1037-
return h
1050+
return file_header(self, self.wrapped_data.header())
10381051

10391052
@property
10401053
def storage(self) -> Optional[rocksdb_file_storage]:

src/ifcwrap/IfcParseWrapper.i

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ private:
651651
%extend IfcParse::IfcSpfHeader {
652652
// Cast to base class pointers for SWIG, because
653653
// it has no idea about the schema definitions.
654+
// The code to access these methods as attributes
655+
// is in file.py
654656
IfcUtil::IfcBaseClass* file_description_py() {
655657
return $self->file_description();
656658
}
@@ -660,14 +662,6 @@ private:
660662
IfcUtil::IfcBaseClass* file_schema_py() {
661663
return $self->file_schema();
662664
}
663-
664-
%pythoncode %{
665-
# Hide the getters with read-only property implementations
666-
# self.file_ref is set in ifcopenshell.file.header()
667-
file_description = property(lambda self: self.file_ref(self.file_description_py()))
668-
file_name = property(lambda self: self.file_ref(self.file_name_py()))
669-
file_schema = property(lambda self: self.file_ref(self.file_schema_py()))
670-
%}
671665
};
672666

673667
%extend IfcParse::FileDescription {

0 commit comments

Comments
 (0)