MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / finalize

Function finalize

src/serializers/schema_dependent/XmlSerializer.cpp:550–864  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

548} // ~unnamed namespace
549
550void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
551 POSTFIX_SCHEMA(argument_name_map).insert(std::make_pair("GlobalId", "id"));
552
553 IfcSchema::IfcProject::list::ptr projects = file->instances_by_type<IfcSchema::IfcProject>();
554 if (projects->size() != 1) {
555 Logger::Message(Logger::LOG_ERROR, "Expected a single IfcProject");
556 return;
557 }
558 IfcSchema::IfcProject* project = *projects->begin();
559
560 ptree root, header, units, decomposition, properties, quantities, types, layers, materials, work, calendars, connections, groups;
561
562 auto catch_exceptions = [this](const auto& fn) {
563 try {
564 return fn();
565 } catch(const std::exception& e) {
566 Logger::Error(e);
567 static std::invoke_result_t<decltype(fn)> v;
568 return v;
569 }
570 };
571
572 // Write the SPF header as XML nodes.
573 BOOST_FOREACH(const std::string & s, catch_exceptions([this]() { return file->header().file_description()->description(); })) {
574 header.add_child("file_description.description", ptree(s));
575 }
576 BOOST_FOREACH(const std::string& s, catch_exceptions([this]() { return file->header().file_name()->author(); })) {
577 header.add_child("file_name.author", ptree(s));
578 }
579 BOOST_FOREACH(const std::string& s, catch_exceptions([this]() { return file->header().file_name()->organization(); })) {
580 header.add_child("file_name.organization", ptree(s));
581 }
582 BOOST_FOREACH(const std::string& s, catch_exceptions([this]() { return file->header().file_schema()->schema_identifiers(); })) {
583 header.add_child("file_schema.schema_identifiers", ptree(s));
584 }
585 try {
586 header.put("file_description.implementation_level", file->header().file_description()->implementation_level());
587 }
588 catch (const IfcParse::IfcException& ex) {
589 std::stringstream ss;
590 ss << "Failed to get ifc file header file_description implementation_level, error: '" << ex.what() << "'";
591 Logger::Message(Logger::LOG_ERROR, ss.str());
592 }
593 try {
594 header.put("file_name.name", file->header().file_name()->name());
595 }
596 catch (const IfcParse::IfcException& ex) {
597 std::stringstream ss;
598 ss << "Failed to get ifc file header file_name name, error: '" << ex.what() << "'";
599 Logger::Message(Logger::LOG_ERROR, ss.str());
600 }
601 try {
602 header.put("file_name.time_stamp", file->header().file_name()->time_stamp());
603 }
604 catch (const IfcParse::IfcException& ex) {
605 std::stringstream ss;
606 ss << "Failed to get ifc file header file_name time_stamp, error: '" << ex.what() << "'";
607 Logger::Message(Logger::LOG_ERROR, ss.str());

Callers

nothing calls this directly

Calls 15

MessageClass · 0.85
fnFunction · 0.85
format_propertiesFunction · 0.85
writeGroupToNodeFunction · 0.85
format_quantitiesFunction · 0.85
format_tasksFunction · 0.85
putMethod · 0.80
implementation_levelMethod · 0.80
whatMethod · 0.80
time_stampMethod · 0.80
preprocessor_versionMethod · 0.80

Tested by

no test coverage detected