This commit is contained in:
Thomas Krijnen
2017-09-10 16:59:05 +02:00
parent f6645b19ef
commit 4f31b9467a
2 changed files with 27 additions and 16 deletions
+25 -14
View File
@@ -33,12 +33,12 @@
#include <cmath> #include <cmath>
using namespace IfcSchema; using namespace IfcSchema;
using namespace boost::numeric::ublas;
static void collada_id(std::string &s) static std::string& collada_id(std::string& s)
{ {
IfcUtil::sanitate_material_name(s); IfcUtil::sanitate_material_name(s);
IfcUtil::escape_xml(s); IfcUtil::escape_xml(s);
return s;
} }
void ColladaSerializer::ColladaExporter::ColladaGeometries::addFloatSource(const std::string& mesh_id, void ColladaSerializer::ColladaExporter::ColladaGeometries::addFloatSource(const std::string& mesh_id,
@@ -270,6 +270,7 @@ void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const IfcGeom::
} else { } else {
name = parent.unique_id(); name = parent.unique_id();
} }
collada_id(name);
const std::string& id = name; const std::string& id = name;
@@ -396,10 +397,18 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme
slabSuffix = differentiateSlabTypes(o); slabSuffix = differentiateSlabTypes(o);
} }
const std::string name = serializer->settings().get(SerializerSettings::USE_ELEMENT_GUIDS) ? std::string name = serializer->settings().get(SerializerSettings::USE_ELEMENT_GUIDS)
o->guid() : (serializer->settings().get(SerializerSettings::USE_ELEMENT_NAMES) ? ? o->guid()
o->name() : (serializer->settings().get(SerializerSettings::USE_ELEMENT_TYPES) ? o->type() + slabSuffix : o->unique_id())); : (serializer->settings().get(SerializerSettings::USE_ELEMENT_NAMES)
const std::string representation_id = "representation-" + o->geometry().id(); ? o->name()
: (serializer->settings().get(SerializerSettings::USE_ELEMENT_TYPES)
? (o->type() + slabSuffix)
: o->unique_id()));
collada_id(name);
std::string representation_id = "representation-" + o->geometry().id();
collada_id(representation_id);
std::vector<std::string> material_references; std::vector<std::string> material_references;
foreach(const IfcGeom::Material& material, mesh.materials()) { foreach(const IfcGeom::Material& material, mesh.materials()) {
if (!materials.contains(material)) { if (!materials.contains(material)) {
@@ -423,28 +432,31 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme
std::string ColladaSerializer::ColladaExporter::differentiateSlabTypes(const IfcGeom::TriangulationElement<real_t>* o) { std::string ColladaSerializer::ColladaExporter::differentiateSlabTypes(const IfcGeom::TriangulationElement<real_t>* o) {
IfcSlab* slab = (IfcSlab*)o->product(); IfcSlab* slab = (IfcSlab*)o->product();
std::string result;
switch (slab->PredefinedType()) switch (slab->PredefinedType())
{ {
case (IfcSlabTypeEnum::IfcSlabType_FLOOR): case (IfcSlabTypeEnum::IfcSlabType_FLOOR):
return "_Floor"; result = "_Floor";
break; break;
case (IfcSlabTypeEnum::IfcSlabType_ROOF): case (IfcSlabTypeEnum::IfcSlabType_ROOF):
return "_Roof"; result = "_Roof";
break; break;
case (IfcSlabTypeEnum::IfcSlabType_LANDING): case (IfcSlabTypeEnum::IfcSlabType_LANDING):
return "_Landing"; result = "_Landing";
break; break;
case (IfcSlabTypeEnum::IfcSlabType_BASESLAB): case (IfcSlabTypeEnum::IfcSlabType_BASESLAB):
return "_BaseSlab"; result = "_BaseSlab";
break; break;
case (IfcSlabTypeEnum::IfcSlabType_NOTDEFINED): case (IfcSlabTypeEnum::IfcSlabType_NOTDEFINED):
return "_NotDefined"; result = "_NotDefined";
break; break;
default: default:
if (slab->hasObjectType()) { return "_" + slab->ObjectType(); } if (slab->hasObjectType()) { result = "_" + slab->ObjectType(); }
else { return "_Unknown"; } else { result = "_Unknown"; }
break; break;
} }
collada_id(result);
return result;
} }
void ColladaSerializer::ColladaExporter::endDocument() { void ColladaSerializer::ColladaExporter::endDocument() {
@@ -532,7 +544,6 @@ void ColladaSerializer::write(const IfcGeom::TriangulationElement<real_t>* o) {
exporter.write(o); exporter.write(o);
} }
void ColladaSerializer::finalize() { void ColladaSerializer::finalize() {
exporter.endDocument(); exporter.endDocument();
} }
+2 -2
View File
@@ -161,20 +161,20 @@ void IfcUtil::sanitate_material_name(std::string &str)
void IfcUtil::escape_xml(std::string &str) void IfcUtil::escape_xml(std::string &str)
{ {
boost::replace_all(str, "&", "&amp;");
boost::replace_all(str, "\"", "&quot;"); boost::replace_all(str, "\"", "&quot;");
boost::replace_all(str, "'", "&apos;"); boost::replace_all(str, "'", "&apos;");
boost::replace_all(str, "<", "&lt;"); boost::replace_all(str, "<", "&lt;");
boost::replace_all(str, ">", "&gt;"); boost::replace_all(str, ">", "&gt;");
boost::replace_all(str, "&", "&amp;");
} }
void IfcUtil::unescape_xml(std::string &str) void IfcUtil::unescape_xml(std::string &str)
{ {
boost::replace_all(str, "&amp;", "&");
boost::replace_all(str, "&quot;", "\""); boost::replace_all(str, "&quot;", "\"");
boost::replace_all(str, "&apos;", "'"); boost::replace_all(str, "&apos;", "'");
boost::replace_all(str, "&lt;", "<"); boost::replace_all(str, "&lt;", "<");
boost::replace_all(str, "&gt;", ">"); boost::replace_all(str, "&gt;", ">");
boost::replace_all(str, "&amp;", "&");
} }
std::vector<std::string> IfcUtil::IfcBaseEntity::getAttributeNames() const { std::vector<std::string> IfcUtil::IfcBaseEntity::getAttributeNames() const {