mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 02:47:48 +00:00
Revive XML serializer
This commit is contained in:
@@ -32,9 +32,28 @@
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
|
||||
#include "XmlSerializer.h"
|
||||
|
||||
namespace {
|
||||
struct factory_t {
|
||||
XmlSerializer* operator()(IfcParse::IfcFile* file, const std::string& xml_filename) const {
|
||||
MAKE_TYPE_NAME(XmlSerializer)* s = new MAKE_TYPE_NAME(XmlSerializer)(file, xml_filename);
|
||||
s->setFile(file);
|
||||
return s;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void MAKE_INIT_FN(XmlSerializer)(XmlSerializerFactory::Factory* mapping) {
|
||||
static const std::string schema_name = STRINGIFY(IfcSchema);
|
||||
factory_t factory;
|
||||
mapping->bind(schema_name, factory);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
std::map<std::string, std::string> argument_name_map;
|
||||
// TODO: Make this a member of XmlSerializer?
|
||||
std::map<std::string, std::string> MAKE_TYPE_NAME(argument_name_map);
|
||||
|
||||
// Format an IFC attribute and maybe returns as string. Only literal scalar
|
||||
// values are converted. Things like entity instances and lists are omitted.
|
||||
@@ -108,7 +127,7 @@ boost::optional<std::string> format_attribute(const Argument* argument, IfcUtil:
|
||||
} else if (e->declaration().is(IfcSchema::IfcLocalPlacement::Class())) {
|
||||
IfcSchema::IfcLocalPlacement* placement = e->as<IfcSchema::IfcLocalPlacement>();
|
||||
gp_Trsf trsf;
|
||||
IfcGeom::Kernel kernel;
|
||||
IfcGeom::MAKE_TYPE_NAME(Kernel) kernel;
|
||||
|
||||
if (kernel.convert(placement, trsf)) {
|
||||
std::stringstream stream;
|
||||
@@ -138,8 +157,8 @@ ptree& format_entity_instance(IfcUtil::IfcBaseEntity* instance, ptree& child, pt
|
||||
|
||||
std::string argument_name = instance->declaration().attribute_by_index(i)->name();
|
||||
std::map<std::string, std::string>::const_iterator argument_name_it;
|
||||
argument_name_it = argument_name_map.find(argument_name);
|
||||
if (argument_name_it != argument_name_map.end()) {
|
||||
argument_name_it = MAKE_TYPE_NAME(argument_name_map).find(argument_name);
|
||||
if (argument_name_it != MAKE_TYPE_NAME(argument_name_map).end()) {
|
||||
argument_name = argument_name_it->second;
|
||||
}
|
||||
const IfcUtil::ArgumentType argument_type = instance->data().getArgument(i)->type();
|
||||
@@ -326,8 +345,8 @@ void format_quantities(IfcSchema::IfcPhysicalQuantity::list::ptr quantities, ptr
|
||||
|
||||
} // ~unnamed namespace
|
||||
|
||||
void XmlSerializer::finalize() {
|
||||
argument_name_map.insert(std::make_pair("GlobalId", "id"));
|
||||
void MAKE_TYPE_NAME(XmlSerializer)::finalize() {
|
||||
MAKE_TYPE_NAME(argument_name_map).insert(std::make_pair("GlobalId", "id"));
|
||||
|
||||
IfcSchema::IfcProject::list::ptr projects = file->instances_by_type<IfcSchema::IfcProject>();
|
||||
if (projects->size() != 1) {
|
||||
|
||||
Reference in New Issue
Block a user