mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-28 15:53:00 +00:00
More work
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
|
||||
#include "../../ifcparse/IfcSIPrefix.h"
|
||||
#include "../../ifcparse/utils.h"
|
||||
#include "../../ifcgeom/kernels/opencascade/IfcGeom.h"
|
||||
#include "../../ifcgeom/abstract_mapping.h"
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
|
||||
@@ -57,7 +57,7 @@ std::map<std::string, std::string> POSTFIX_SCHEMA(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.
|
||||
boost::optional<std::string> format_attribute(const Argument* argument, IfcUtil::ArgumentType argument_type, const std::string& argument_name) {
|
||||
boost::optional<std::string> format_attribute(ifcopenshell::geometry::abstract_mapping* mapping, const Argument* argument, IfcUtil::ArgumentType argument_type, const std::string& argument_name) {
|
||||
boost::optional<std::string> value;
|
||||
|
||||
// Hard-code lat-lon as it represents an array
|
||||
@@ -106,7 +106,7 @@ boost::optional<std::string> format_attribute(const Argument* argument, IfcUtil:
|
||||
IfcUtil::IfcBaseClass* e = *argument;
|
||||
if (!e->declaration().as_entity()) {
|
||||
IfcUtil::IfcBaseType* f = (IfcUtil::IfcBaseType*) e;
|
||||
value = format_attribute(f->data().getArgument(0), f->data().getArgument(0)->type(), argument_name);
|
||||
value = format_attribute(mapping, f->data().getArgument(0), f->data().getArgument(0)->type(), argument_name);
|
||||
} else if (e->declaration().is(IfcSchema::IfcSIUnit::Class()) || e->declaration().is(IfcSchema::IfcConversionBasedUnit::Class())) {
|
||||
// Some string concatenation to have a unit name as a XML attribute.
|
||||
|
||||
@@ -125,21 +125,21 @@ boost::optional<std::string> format_attribute(const Argument* argument, IfcUtil:
|
||||
|
||||
value = unit_name;
|
||||
} else if (e->declaration().is(IfcSchema::IfcLocalPlacement::Class())) {
|
||||
IfcSchema::IfcLocalPlacement* placement = e->as<IfcSchema::IfcLocalPlacement>();
|
||||
gp_Trsf trsf;
|
||||
IfcGeom::POSTFIX_SCHEMA(Kernel) kernel;
|
||||
|
||||
if (kernel.convert(placement, trsf)) {
|
||||
std::stringstream stream;
|
||||
for (int i = 1; i < 5; ++i) {
|
||||
for (int j = 1; j < 4; ++j) {
|
||||
const double trsf_value = trsf.Value(j, i);
|
||||
stream << trsf_value << " ";
|
||||
}
|
||||
stream << ((i == 4) ? "1" : "0 ");
|
||||
auto placement = mapping->map(e);
|
||||
auto matrix = (ifcopenshell::geometry::taxonomy::matrix4*) placement;
|
||||
|
||||
std::stringstream stream;
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
const double trsf_value = matrix->components[i];
|
||||
stream << trsf_value;
|
||||
if (i != 15) {
|
||||
stream << " ";
|
||||
}
|
||||
value = stream.str();
|
||||
}
|
||||
}
|
||||
value = stream.str();
|
||||
|
||||
delete mapping;
|
||||
delete placement;
|
||||
}
|
||||
break; }
|
||||
default:
|
||||
@@ -149,7 +149,7 @@ boost::optional<std::string> format_attribute(const Argument* argument, IfcUtil:
|
||||
}
|
||||
|
||||
// Appends to a node with possibly existing attributes
|
||||
ptree& format_entity_instance(IfcUtil::IfcBaseEntity* instance, ptree& child, ptree& tree, bool as_link = false) {
|
||||
ptree& format_entity_instance(ifcopenshell::geometry::abstract_mapping* mapping, IfcUtil::IfcBaseEntity* instance, ptree& child, ptree& tree, bool as_link = false) {
|
||||
const unsigned n = instance->declaration().attribute_count();
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
try {
|
||||
@@ -172,11 +172,9 @@ ptree& format_entity_instance(IfcUtil::IfcBaseEntity* instance, ptree& child, pt
|
||||
const std::string qualified_name = instance->declaration().name() + "." + argument_name;
|
||||
boost::optional<std::string> value;
|
||||
try {
|
||||
value = format_attribute(argument, argument_type, qualified_name);
|
||||
value = format_attribute(mapping, argument, argument_type, qualified_name);
|
||||
} catch (const std::exception& e) {
|
||||
Logger::Error(e);
|
||||
} catch (const Standard_ConstructionError& e) {
|
||||
Logger::Error(e.GetMessageString(), instance);
|
||||
}
|
||||
|
||||
if (value) {
|
||||
@@ -196,9 +194,9 @@ ptree& format_entity_instance(IfcUtil::IfcBaseEntity* instance, ptree& child, pt
|
||||
|
||||
// Formats an entity instances as a ptree node, and insert into the DOM. Recurses
|
||||
// over the entity attributes and writes them as xml attributes of the node.
|
||||
ptree& format_entity_instance(IfcUtil::IfcBaseEntity* instance, ptree& tree, bool as_link = false) {
|
||||
ptree& format_entity_instance(ifcopenshell::geometry::abstract_mapping* mapping, IfcUtil::IfcBaseEntity* instance, ptree& tree, bool as_link = false) {
|
||||
ptree child;
|
||||
return format_entity_instance(instance, child, tree, as_link);
|
||||
return format_entity_instance(mapping, instance, child, tree, as_link);
|
||||
}
|
||||
|
||||
std::string qualify_unrooted_instance(IfcUtil::IfcBaseClass* inst) {
|
||||
@@ -208,11 +206,11 @@ std::string qualify_unrooted_instance(IfcUtil::IfcBaseClass* inst) {
|
||||
// A function to be called recursively. Template specialization is used
|
||||
// to descend into decomposition, containment and property relationships.
|
||||
template <typename A>
|
||||
ptree& descend(A* instance, ptree& tree) {
|
||||
ptree& descend(ifcopenshell::geometry::abstract_mapping* mapping, A* instance, ptree& tree) {
|
||||
if (instance->declaration().is(IfcSchema::IfcObjectDefinition::Class())) {
|
||||
return descend(instance->template as<IfcSchema::IfcObjectDefinition>(), tree);
|
||||
return descend(mapping, instance->template as<IfcSchema::IfcObjectDefinition>(), tree);
|
||||
} else {
|
||||
return format_entity_instance(instance, tree);
|
||||
return format_entity_instance(mapping, instance, tree);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,8 +230,8 @@ typename V::list::ptr get_related(T* t, F f, G g) {
|
||||
// Descends into the tree by recursing into IfcRelContainedInSpatialStructure,
|
||||
// IfcRelDecomposes, IfcRelDefinesByType, IfcRelDefinesByProperties relations.
|
||||
template <>
|
||||
ptree& descend(IfcSchema::IfcObjectDefinition* product, ptree& tree) {
|
||||
ptree& child = format_entity_instance(product, tree);
|
||||
ptree& descend(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcObjectDefinition* product, ptree& tree) {
|
||||
ptree& child = format_entity_instance(mapping, product, tree);
|
||||
|
||||
if (product->declaration().is(IfcSchema::IfcSpatialStructureElement::Class())) {
|
||||
IfcSchema::IfcSpatialStructureElement* structure = (IfcSchema::IfcSpatialStructureElement*) product;
|
||||
@@ -243,7 +241,7 @@ ptree& descend(IfcSchema::IfcObjectDefinition* product, ptree& tree) {
|
||||
(structure, &IfcSchema::IfcSpatialStructureElement::ContainsElements, &IfcSchema::IfcRelContainedInSpatialStructure::RelatedElements);
|
||||
|
||||
for (IfcSchema::IfcObjectDefinition::list::it it = elements->begin(); it != elements->end(); ++it) {
|
||||
descend(*it, child);
|
||||
descend(mapping, *it, child);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +251,7 @@ ptree& descend(IfcSchema::IfcObjectDefinition* product, ptree& tree) {
|
||||
element, &IfcSchema::IfcElement::HasOpenings, &IfcSchema::IfcRelVoidsElement::RelatedOpeningElement);
|
||||
|
||||
for (IfcSchema::IfcOpeningElement::list::it it = openings->begin(); it != openings->end(); ++it) {
|
||||
descend(*it, child);
|
||||
descend(mapping, *it, child);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +267,7 @@ ptree& descend(IfcSchema::IfcObjectDefinition* product, ptree& tree) {
|
||||
|
||||
for (IfcSchema::IfcObjectDefinition::list::it it = structures->begin(); it != structures->end(); ++it) {
|
||||
IfcSchema::IfcObjectDefinition* ob = *it;
|
||||
descend(ob, child);
|
||||
descend(mapping, ob, child);
|
||||
}
|
||||
|
||||
if (product->declaration().is(IfcSchema::IfcObject::Class())) {
|
||||
@@ -282,13 +280,13 @@ ptree& descend(IfcSchema::IfcObjectDefinition* product, ptree& tree) {
|
||||
for (IfcSchema::IfcPropertySetDefinition::list::it it = property_sets->begin(); it != property_sets->end(); ++it) {
|
||||
IfcSchema::IfcPropertySetDefinition* pset = *it;
|
||||
if (pset->declaration().is(IfcSchema::IfcPropertySet::Class())) {
|
||||
format_entity_instance(pset, child, true);
|
||||
format_entity_instance(mapping, pset, child, true);
|
||||
}
|
||||
if (pset->declaration().is(IfcSchema::IfcElementQuantity::Class())) {
|
||||
format_entity_instance(pset, child, true);
|
||||
format_entity_instance(mapping, pset, child, true);
|
||||
}
|
||||
if (pset->declaration().is(IfcSchema::IfcElementQuantity::Class())) {
|
||||
format_entity_instance(pset, child, true);
|
||||
format_entity_instance(mapping, pset, child, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,19 +302,19 @@ ptree& descend(IfcSchema::IfcObjectDefinition* product, ptree& tree) {
|
||||
|
||||
for (IfcSchema::IfcTypeObject::list::it it = types->begin(); it != types->end(); ++it) {
|
||||
IfcSchema::IfcTypeObject* type = *it;
|
||||
format_entity_instance(type, child, true);
|
||||
format_entity_instance(mapping, type, child, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (product->declaration().is(IfcSchema::IfcProduct::Class())) {
|
||||
std::map<std::string, IfcUtil::IfcBaseEntity*> layers = IfcGeom::Kernel::get_layers(product);
|
||||
std::map<std::string, IfcUtil::IfcBaseEntity*> layers = mapping->get_layers(product);
|
||||
for (std::map<std::string, IfcUtil::IfcBaseEntity*>::const_iterator it = layers.begin(); it != layers.end(); ++it) {
|
||||
// IfcPresentationLayerAssignments don't have GUIDs (only optional Identifier) so use name as the ID.
|
||||
// Note that the IfcPresentationLayerAssignment passed here doesn't really matter as as_link is true
|
||||
// for the format_entity_instance() call.
|
||||
ptree node;
|
||||
node.put("<xmlattr>.xlink:href", "#" + it->first);
|
||||
format_entity_instance(it->second, node, child, true);
|
||||
format_entity_instance(mapping, it->second, node, child, true);
|
||||
}
|
||||
|
||||
IfcSchema::IfcRelAssociates::list::ptr associations = product->HasAssociations();
|
||||
@@ -325,7 +323,7 @@ ptree& descend(IfcSchema::IfcObjectDefinition* product, ptree& tree) {
|
||||
IfcSchema::IfcMaterialSelect* mat = (*it)->as<IfcSchema::IfcRelAssociatesMaterial>()->RelatingMaterial();
|
||||
ptree node;
|
||||
node.put("<xmlattr>.xlink:href", "#" + qualify_unrooted_instance(mat));
|
||||
format_entity_instance((IfcUtil::IfcBaseEntity*) mat, node, child, true);
|
||||
format_entity_instance(mapping, (IfcUtil::IfcBaseEntity*) mat, node, child, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,26 +332,26 @@ ptree& descend(IfcSchema::IfcObjectDefinition* product, ptree& tree) {
|
||||
}
|
||||
|
||||
// Format IfcProperty instances and insert into the DOM. IfcComplexProperties are flattened out.
|
||||
void format_properties(IfcSchema::IfcProperty::list::ptr properties, ptree& node) {
|
||||
void format_properties(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcProperty::list::ptr properties, ptree& node) {
|
||||
for (IfcSchema::IfcProperty::list::it it = properties->begin(); it != properties->end(); ++it) {
|
||||
IfcSchema::IfcProperty* p = *it;
|
||||
if (p->declaration().is(IfcSchema::IfcComplexProperty::Class())) {
|
||||
IfcSchema::IfcComplexProperty* complex = (IfcSchema::IfcComplexProperty*) p;
|
||||
format_properties(complex->HasProperties(), node);
|
||||
format_properties(mapping, complex->HasProperties(), node);
|
||||
} else {
|
||||
format_entity_instance(p, node);
|
||||
format_entity_instance(mapping, p, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Format IfcElementQuantity instances and insert into the DOM.
|
||||
void format_quantities(IfcSchema::IfcPhysicalQuantity::list::ptr quantities, ptree& node) {
|
||||
void format_quantities(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcPhysicalQuantity::list::ptr quantities, ptree& node) {
|
||||
for (IfcSchema::IfcPhysicalQuantity::list::it it = quantities->begin(); it != quantities->end(); ++it) {
|
||||
IfcSchema::IfcPhysicalQuantity* p = *it;
|
||||
ptree& node2 = format_entity_instance(p, node);
|
||||
ptree& node2 = format_entity_instance(mapping, p, node);
|
||||
if (p->declaration().is(IfcSchema::IfcPhysicalComplexQuantity::Class())) {
|
||||
IfcSchema::IfcPhysicalComplexQuantity* complex = (IfcSchema::IfcPhysicalComplexQuantity*)p;
|
||||
format_quantities(complex->HasQuantities(), node2);
|
||||
format_quantities(mapping, complex->HasQuantities(), node2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -435,22 +433,22 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
}
|
||||
|
||||
// Descend into the decomposition structure of the IFC file.
|
||||
descend(project, decomposition);
|
||||
descend(mapping_, project, decomposition);
|
||||
|
||||
// Write all property sets and values as XML nodes.
|
||||
IfcSchema::IfcPropertySet::list::ptr psets = file->instances_by_type<IfcSchema::IfcPropertySet>();
|
||||
for (IfcSchema::IfcPropertySet::list::it it = psets->begin(); it != psets->end(); ++it) {
|
||||
IfcSchema::IfcPropertySet* pset = *it;
|
||||
ptree& node = format_entity_instance(pset, properties);
|
||||
format_properties(pset->HasProperties(), node);
|
||||
ptree& node = format_entity_instance(mapping_, pset, properties);
|
||||
format_properties(mapping_, pset->HasProperties(), node);
|
||||
}
|
||||
|
||||
// Write all quantities and values as XML nodes.
|
||||
IfcSchema::IfcElementQuantity::list::ptr qtosets = file->instances_by_type<IfcSchema::IfcElementQuantity>();
|
||||
for (IfcSchema::IfcElementQuantity::list::it it = qtosets->begin(); it != qtosets->end(); ++it) {
|
||||
IfcSchema::IfcElementQuantity* qto = *it;
|
||||
ptree& node = format_entity_instance(qto, quantities);
|
||||
format_quantities(qto->Quantities(), node);
|
||||
ptree& node = format_entity_instance(mapping_, qto, quantities);
|
||||
format_quantities(mapping_, qto->Quantities(), node);
|
||||
}
|
||||
|
||||
|
||||
@@ -458,7 +456,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
IfcSchema::IfcTypeObject::list::ptr type_objects = file->instances_by_type<IfcSchema::IfcTypeObject>();
|
||||
for (IfcSchema::IfcTypeObject::list::it it = type_objects->begin(); it != type_objects->end(); ++it) {
|
||||
IfcSchema::IfcTypeObject* type_object = *it;
|
||||
ptree& node = descend(type_object, types);
|
||||
ptree& node = descend(mapping_, type_object, types);
|
||||
// ptree& node = format_entity_instance(type_object, types);
|
||||
|
||||
if (type_object->hasHasPropertySets()) {
|
||||
@@ -466,7 +464,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
for (IfcSchema::IfcPropertySetDefinition::list::it jt = property_sets->begin(); jt != property_sets->end(); ++jt) {
|
||||
IfcSchema::IfcPropertySetDefinition* pset = *jt;
|
||||
if (pset->declaration().is(IfcSchema::IfcPropertySet::Class())) {
|
||||
format_entity_instance(pset, node, true);
|
||||
format_entity_instance(mapping_, pset, node, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -477,10 +475,10 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
for (IfcEntityList::it it = unit_assignments->begin(); it != unit_assignments->end(); ++it) {
|
||||
if ((*it)->declaration().is(IfcSchema::IfcNamedUnit::Class())) {
|
||||
IfcSchema::IfcNamedUnit* named_unit = (*it)->as<IfcSchema::IfcNamedUnit>();
|
||||
ptree& node = format_entity_instance(named_unit, units);
|
||||
ptree& node = format_entity_instance(mapping, named_unit, units);
|
||||
node.put("<xmlattr>.SI_equivalent", IfcParse::get_SI_equivalent<IfcSchema>(named_unit));
|
||||
} else if ((*it)->declaration().is(IfcSchema::IfcMonetaryUnit::Class())) {
|
||||
format_entity_instance((*it)->as<IfcSchema::IfcMonetaryUnit>(), units);
|
||||
format_entity_instance(mapping_, (*it)->as<IfcSchema::IfcMonetaryUnit>(), units);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,7 +493,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
layer_names.insert(name);
|
||||
ptree node;
|
||||
node.put("<xmlattr>.id", name);
|
||||
format_entity_instance(*it, node, layers);
|
||||
format_entity_instance(mapping_, *it, node, layers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,16 +519,16 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
if ((*jt)->hasMaterial()) {
|
||||
subnode.put("<xmlattr>.Name", (*jt)->Material()->Name());
|
||||
}
|
||||
format_entity_instance(*jt, subnode, node);
|
||||
format_entity_instance(mapping_, *jt, subnode, node);
|
||||
}
|
||||
} else if (mat->as<IfcSchema::IfcMaterialList>()) {
|
||||
IfcSchema::IfcMaterial::list::ptr mats = mat->as<IfcSchema::IfcMaterialList>()->Materials();
|
||||
for (IfcSchema::IfcMaterial::list::it jt = mats->begin(); jt != mats->end(); ++jt) {
|
||||
ptree subnode;
|
||||
format_entity_instance(*jt, subnode, node);
|
||||
format_entity_instance(mapping_, *jt, subnode, node);
|
||||
}
|
||||
}
|
||||
format_entity_instance((IfcUtil::IfcBaseEntity*) mat, node, materials);
|
||||
format_entity_instance(mapping_, (IfcUtil::IfcBaseEntity*) mat, node, materials);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#ifndef XMLSERIALIZERIMPL_H
|
||||
#define XMLSERIALIZERIMPL_H
|
||||
|
||||
#include "../../ifcgeom/abstract_mapping.h"
|
||||
#include "../../ifcparse/macros.h"
|
||||
#include "../../serializers/XmlSerializer.h"
|
||||
|
||||
@@ -29,10 +30,12 @@
|
||||
class POSTFIX_SCHEMA(XmlSerializer) : public XmlSerializer {
|
||||
private:
|
||||
IfcParse::IfcFile* file;
|
||||
ifcopenshell::geometry::abstract_mapping* mapping_;
|
||||
|
||||
public:
|
||||
POSTFIX_SCHEMA(XmlSerializer)(IfcParse::IfcFile* file, const std::string& xml_filename)
|
||||
: XmlSerializer(0, "")
|
||||
, mapping_(ifcopenshell::geometry::impl::mapping_implementations().construct(file))
|
||||
{
|
||||
this->file = file;
|
||||
this->xml_filename = xml_filename;
|
||||
|
||||
Reference in New Issue
Block a user