diff --git a/src/ifcopenshell-python/ifcopenshell/api/project/create_file.py b/src/ifcopenshell-python/ifcopenshell/api/project/create_file.py index 6eaa324b82..41bc45fdd5 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/project/create_file.py +++ b/src/ifcopenshell-python/ifcopenshell/api/project/create_file.py @@ -51,12 +51,12 @@ def create_file(version: ifcopenshell.util.schema.IFC_SCHEMA = "IFC4") -> ifcope # ... and off we go! """ file = ifcopenshell.file(schema=version) - file.wrapped_data.header.file_name.name = "/dev/null" # Hehehe - file.wrapped_data.header.file_name.time_stamp = ( + file.header.file_name.name = "/dev/null" # Hehehe + file.header.file_name.time_stamp = ( datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).astimezone().replace(microsecond=0).isoformat() ) - file.wrapped_data.header.file_name.preprocessor_version = "IfcOpenShell {}".format(ifcopenshell.version) - file.wrapped_data.header.file_name.originating_system = "IfcOpenShell {}".format(ifcopenshell.version) - file.wrapped_data.header.file_name.authorization = "Nobody" - file.wrapped_data.header.file_description.description = ("ViewDefinition[DesignTransferView]",) + file.header.file_name.preprocessor_version = "IfcOpenShell {}".format(ifcopenshell.version) + file.header.file_name.originating_system = "IfcOpenShell {}".format(ifcopenshell.version) + file.header.file_name.authorization = "Nobody" + file.header.file_description.description = ("ViewDefinition[DesignTransferView]",) return file diff --git a/src/ifcopenshell-python/ifcopenshell/file.py b/src/ifcopenshell-python/ifcopenshell/file.py index 3e44b0d1e0..16444e3702 100644 --- a/src/ifcopenshell-python/ifcopenshell/file.py +++ b/src/ifcopenshell-python/ifcopenshell/file.py @@ -793,3 +793,9 @@ class file: def to_string(self) -> str: return self.wrapped_data.to_string() + + @property + def header(self): + h = self.wrapped_data.header() + object.__setattr__(h, "file_ref", lambda inst: entity_instance.wrap_value(inst, file=self)) + return h diff --git a/src/ifcopenshell-python/test/api/project/test_create_file.py b/src/ifcopenshell-python/test/api/project/test_create_file.py index 8b952777cf..8456e2fe27 100644 --- a/src/ifcopenshell-python/test/api/project/test_create_file.py +++ b/src/ifcopenshell-python/test/api/project/test_create_file.py @@ -26,9 +26,9 @@ class TestCreateFile(test.bootstrap.IFC4): assert ifc.schema == "IFC4" ifc = ifcopenshell.api.project.create_file(version="IFC2X3") assert ifc.schema == "IFC2X3" - assert ifc.wrapped_data.header.file_name.name == "/dev/null" - assert ifc.wrapped_data.header.file_name.time_stamp - assert "IfcOpenShell" in ifc.wrapped_data.header.file_name.preprocessor_version - assert "IfcOpenShell" in ifc.wrapped_data.header.file_name.originating_system - assert ifc.wrapped_data.header.file_name.authorization == "Nobody" - assert ifc.wrapped_data.header.file_description.description == ("ViewDefinition[DesignTransferView]",) + assert ifc.header.file_name.name == "/dev/null" + assert ifc.header.file_name.time_stamp + assert "IfcOpenShell" in ifc.header.file_name.preprocessor_version + assert "IfcOpenShell" in ifc.header.file_name.originating_system + assert ifc.header.file_name.authorization == "Nobody" + assert ifc.header.file_description.description == ("ViewDefinition[DesignTransferView]",) diff --git a/src/ifcopenshell-python/test/file_gc.py b/src/ifcopenshell-python/test/file_gc.py index 8cff9a7e38..f28256a3d0 100644 --- a/src/ifcopenshell-python/test/file_gc.py +++ b/src/ifcopenshell-python/test/file_gc.py @@ -111,7 +111,7 @@ def test_bug_2486_a(): def test_bug_2486_b(): file = ifcopenshell.template.create() - file.wrapped_data.header.file_name.name = "myfile.ifc" + file.header.file_name.name = "myfile.ifc" if __name__ == "__main__": diff --git a/src/ifcparse/Header_section_schema-schema.cpp b/src/ifcparse/Header_section_schema-schema.cpp index 4116491c06..426f4f551c 100644 --- a/src/ifcparse/Header_section_schema-schema.cpp +++ b/src/ifcparse/Header_section_schema-schema.cpp @@ -24,7 +24,7 @@ class HEADER_SECTION_SCHEMA_instance_factory : public IfcParse::instance_factory IfcParse::schema_definition* HEADER_SECTION_SCHEMA_populate_schema() { -const std::string strings[] = {"schema_name"s,"time_stamp_text"s,"file_description"s,"file_name"s,"file_schema"s,"description"s,"implementation_level"s,"name"s,"time_stamp"s,"author"s,"organization"s,"preprocessor_version"s,"originating_system"s,"authorisation"s,"schema_identifiers"s,"HEADER_SECTION_SCHEMA"s}; +const std::string strings[] = {"schema_name"s,"time_stamp_text"s,"file_description"s,"file_name"s,"file_schema"s,"description"s,"implementation_level"s,"name"s,"time_stamp"s,"author"s,"organization"s,"preprocessor_version"s,"originating_system"s,"authorization"s,"schema_identifiers"s,"HEADER_SECTION_SCHEMA"s}; HEADER_SECTION_SCHEMA_types[3] = new type_declaration(strings[0], 3, new simple_type(simple_type::string_type)); HEADER_SECTION_SCHEMA_types[4] = new type_declaration(strings[1], 4, new simple_type(simple_type::string_type)); diff --git a/src/ifcparse/Header_section_schema.cpp b/src/ifcparse/Header_section_schema.cpp index c7fc03ef00..411aaf0ba6 100644 --- a/src/ifcparse/Header_section_schema.cpp +++ b/src/ifcparse/Header_section_schema.cpp @@ -55,14 +55,14 @@ std::string Header_section_schema::file_name::preprocessor_version() const { st void Header_section_schema::file_name::setpreprocessor_version(std::string v) { set_attribute_value(4, v);if constexpr (false)unset_attribute_value(4); } std::string Header_section_schema::file_name::originating_system() const { std::string v = get_attribute_value(5); return v; } void Header_section_schema::file_name::setoriginating_system(std::string v) { set_attribute_value(5, v);if constexpr (false)unset_attribute_value(5); } -std::string Header_section_schema::file_name::authorisation() const { std::string v = get_attribute_value(6); return v; } -void Header_section_schema::file_name::setauthorisation(std::string v) { set_attribute_value(6, v);if constexpr (false)unset_attribute_value(6); } +std::string Header_section_schema::file_name::authorization() const { std::string v = get_attribute_value(6); return v; } +void Header_section_schema::file_name::setauthorization(std::string v) { set_attribute_value(6, v);if constexpr (false)unset_attribute_value(6); } const IfcParse::entity& Header_section_schema::file_name::declaration() const { return *((IfcParse::entity*)HEADER_SECTION_SCHEMA_types[1]); } const IfcParse::entity& Header_section_schema::file_name::Class() { return *((IfcParse::entity*)HEADER_SECTION_SCHEMA_types[1]); } Header_section_schema::file_name::file_name(IfcEntityInstanceData&& e) : IfcUtil::IfcBaseEntity(std::move(e)) { } -Header_section_schema::file_name::file_name(std::string v1_name, std::string v2_time_stamp, std::vector< std::string > /*[1:?]*/ v3_author, std::vector< std::string > /*[1:?]*/ v4_organization, std::string v5_preprocessor_version, std::string v6_originating_system, std::string v7_authorisation) : IfcUtil::IfcBaseEntity(IfcEntityInstanceData(in_memory_attribute_storage(7))) { set_attribute_value(0, (v1_name));set_attribute_value(1, (v2_time_stamp));set_attribute_value(2, (v3_author));set_attribute_value(3, (v4_organization));set_attribute_value(4, (v5_preprocessor_version));set_attribute_value(5, (v6_originating_system));set_attribute_value(6, (v7_authorisation));; populate_derived(); } +Header_section_schema::file_name::file_name(std::string v1_name, std::string v2_time_stamp, std::vector< std::string > /*[1:?]*/ v3_author, std::vector< std::string > /*[1:?]*/ v4_organization, std::string v5_preprocessor_version, std::string v6_originating_system, std::string v7_authorization) : IfcUtil::IfcBaseEntity(IfcEntityInstanceData(in_memory_attribute_storage(7))) { set_attribute_value(0, (v1_name));set_attribute_value(1, (v2_time_stamp));set_attribute_value(2, (v3_author));set_attribute_value(3, (v4_organization));set_attribute_value(4, (v5_preprocessor_version));set_attribute_value(5, (v6_originating_system));set_attribute_value(6, (v7_authorization));; populate_derived(); } // Function implementations for file_schema std::vector< std::string > /*[1:?]*/ Header_section_schema::file_schema::schema_identifiers() const { std::vector< std::string > /*[1:?]*/ v = get_attribute_value(0); return v; } diff --git a/src/ifcparse/Header_section_schema.h b/src/ifcparse/Header_section_schema.h index 80237a627d..efce31a5f2 100644 --- a/src/ifcparse/Header_section_schema.h +++ b/src/ifcparse/Header_section_schema.h @@ -74,12 +74,12 @@ public: void setpreprocessor_version(std::string v); std::string originating_system() const; void setoriginating_system(std::string v); - std::string authorisation() const; - void setauthorisation(std::string v); + std::string authorization() const; + void setauthorization(std::string v); virtual const IfcParse::entity& declaration() const; static const IfcParse::entity& Class(); file_name (IfcEntityInstanceData&& e); - file_name (std::string v1_name, std::string v2_time_stamp, std::vector< std::string > /*[1:?]*/ v3_author, std::vector< std::string > /*[1:?]*/ v4_organization, std::string v5_preprocessor_version, std::string v6_originating_system, std::string v7_authorisation); + file_name (std::string v1_name, std::string v2_time_stamp, std::vector< std::string > /*[1:?]*/ v3_author, std::vector< std::string > /*[1:?]*/ v4_organization, std::string v5_preprocessor_version, std::string v6_originating_system, std::string v7_authorization); typedef aggregate_of< file_name > list; }; diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 747e834f03..bb792a1bfe 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -2590,7 +2590,7 @@ void IfcFile::setDefaultHeaderValues() { header().file_name()->setorganization(string_vector); header().file_name()->setpreprocessor_version("IfcOpenShell " IFCOPENSHELL_VERSION); header().file_name()->setoriginating_system("IfcOpenShell " IFCOPENSHELL_VERSION); - header().file_name()->setauthorisation(empty_string); + header().file_name()->setauthorization(empty_string); header().file_schema()->setschema_identifiers(schema_identifiers); } diff --git a/src/ifcparse/parse_ifcxml.cpp b/src/ifcparse/parse_ifcxml.cpp index 56151626b4..26f0552075 100644 --- a/src/ifcparse/parse_ifcxml.cpp +++ b/src/ifcparse/parse_ifcxml.cpp @@ -344,7 +344,7 @@ static void process_characters(void* user, const xmlChar* character, int len) { } else if (tagname == "originating_system") { header.file_name()->setoriginating_system(txt); } else if (tagname == "authorization") { - header.file_name()->setauthorisation(txt); + header.file_name()->setauthorization(txt); } else if (tagname == "documentation") { header.file_description()->setdescription({txt}); } else { diff --git a/src/ifcwrap/IfcParseWrapper.i b/src/ifcwrap/IfcParseWrapper.i index 8699151993..bab1cbb89b 100644 --- a/src/ifcwrap/IfcParseWrapper.i +++ b/src/ifcwrap/IfcParseWrapper.i @@ -229,9 +229,7 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas } %pythoncode %{ - # Hide the getters with read-only property implementations - header = property(header) - schema = property(schema_name) + schema = property(schema_name) %} } @@ -587,9 +585,10 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas %pythoncode %{ # Hide the getters with read-only property implementations - file_description = property(file_description_py) - file_name = property(file_name_py) - file_schema = property(file_schema_py) + # self.file_ref is set in ifcopenshell.file.header() + file_description = property(lambda self: self.file_ref(self.file_description_py())) + file_name = property(lambda self: self.file_ref(self.file_name_py())) + file_schema = property(lambda self: self.file_ref(self.file_schema_py())) %} }; diff --git a/src/serializers/schema_dependent/XmlSerializer.cpp b/src/serializers/schema_dependent/XmlSerializer.cpp index 87b83693d6..bd9740eac0 100644 --- a/src/serializers/schema_dependent/XmlSerializer.cpp +++ b/src/serializers/schema_dependent/XmlSerializer.cpp @@ -624,7 +624,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() { } try { // @nb inconsistent spelling - header.put("file_name.authorization", file->header().file_name()->authorisation()); + header.put("file_name.authorization", file->header().file_name()->authorization()); } catch (const IfcParse::IfcException& ex) { std::stringstream ss;