Skip to content

Commit 4f31b94

Browse files
committed
1 parent f6645b1 commit 4f31b94

2 files changed

Lines changed: 27 additions & 16 deletions

File tree

src/ifcconvert/ColladaSerializer.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
#include <cmath>
3434

3535
using namespace IfcSchema;
36-
using namespace boost::numeric::ublas;
3736

38-
static void collada_id(std::string &s)
37+
static std::string& collada_id(std::string& s)
3938
{
4039
IfcUtil::sanitate_material_name(s);
4140
IfcUtil::escape_xml(s);
41+
return s;
4242
}
4343

4444
void ColladaSerializer::ColladaExporter::ColladaGeometries::addFloatSource(const std::string& mesh_id,
@@ -270,6 +270,7 @@ void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const IfcGeom::
270270
} else {
271271
name = parent.unique_id();
272272
}
273+
collada_id(name);
273274

274275
const std::string& id = name;
275276

@@ -396,10 +397,18 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme
396397
slabSuffix = differentiateSlabTypes(o);
397398
}
398399

399-
const std::string name = serializer->settings().get(SerializerSettings::USE_ELEMENT_GUIDS) ?
400-
o->guid() : (serializer->settings().get(SerializerSettings::USE_ELEMENT_NAMES) ?
401-
o->name() : (serializer->settings().get(SerializerSettings::USE_ELEMENT_TYPES) ? o->type() + slabSuffix : o->unique_id()));
402-
const std::string representation_id = "representation-" + o->geometry().id();
400+
std::string name = serializer->settings().get(SerializerSettings::USE_ELEMENT_GUIDS)
401+
? o->guid()
402+
: (serializer->settings().get(SerializerSettings::USE_ELEMENT_NAMES)
403+
? o->name()
404+
: (serializer->settings().get(SerializerSettings::USE_ELEMENT_TYPES)
405+
? (o->type() + slabSuffix)
406+
: o->unique_id()));
407+
collada_id(name);
408+
409+
std::string representation_id = "representation-" + o->geometry().id();
410+
collada_id(representation_id);
411+
403412
std::vector<std::string> material_references;
404413
foreach(const IfcGeom::Material& material, mesh.materials()) {
405414
if (!materials.contains(material)) {
@@ -423,28 +432,31 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme
423432

424433
std::string ColladaSerializer::ColladaExporter::differentiateSlabTypes(const IfcGeom::TriangulationElement<real_t>* o) {
425434
IfcSlab* slab = (IfcSlab*)o->product();
435+
std::string result;
426436
switch (slab->PredefinedType())
427437
{
428438
case (IfcSlabTypeEnum::IfcSlabType_FLOOR):
429-
return "_Floor";
439+
result = "_Floor";
430440
break;
431441
case (IfcSlabTypeEnum::IfcSlabType_ROOF):
432-
return "_Roof";
442+
result = "_Roof";
433443
break;
434444
case (IfcSlabTypeEnum::IfcSlabType_LANDING):
435-
return "_Landing";
445+
result = "_Landing";
436446
break;
437447
case (IfcSlabTypeEnum::IfcSlabType_BASESLAB):
438-
return "_BaseSlab";
448+
result = "_BaseSlab";
439449
break;
440450
case (IfcSlabTypeEnum::IfcSlabType_NOTDEFINED):
441-
return "_NotDefined";
451+
result = "_NotDefined";
442452
break;
443453
default:
444-
if (slab->hasObjectType()) { return "_" + slab->ObjectType(); }
445-
else { return "_Unknown"; }
454+
if (slab->hasObjectType()) { result = "_" + slab->ObjectType(); }
455+
else { result = "_Unknown"; }
446456
break;
447457
}
458+
collada_id(result);
459+
return result;
448460
}
449461

450462
void ColladaSerializer::ColladaExporter::endDocument() {
@@ -532,7 +544,6 @@ void ColladaSerializer::write(const IfcGeom::TriangulationElement<real_t>* o) {
532544
exporter.write(o);
533545
}
534546

535-
536547
void ColladaSerializer::finalize() {
537548
exporter.endDocument();
538549
}

src/ifcparse/IfcUtil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,20 @@ void IfcUtil::sanitate_material_name(std::string &str)
161161

162162
void IfcUtil::escape_xml(std::string &str)
163163
{
164+
boost::replace_all(str, "&", "&amp;");
164165
boost::replace_all(str, "\"", "&quot;");
165166
boost::replace_all(str, "'", "&apos;");
166167
boost::replace_all(str, "<", "&lt;");
167168
boost::replace_all(str, ">", "&gt;");
168-
boost::replace_all(str, "&", "&amp;");
169169
}
170170

171171
void IfcUtil::unescape_xml(std::string &str)
172172
{
173+
boost::replace_all(str, "&amp;", "&");
173174
boost::replace_all(str, "&quot;", "\"");
174175
boost::replace_all(str, "&apos;", "'");
175176
boost::replace_all(str, "&lt;", "<");
176177
boost::replace_all(str, "&gt;", ">");
177-
boost::replace_all(str, "&amp;", "&");
178178
}
179179

180180
std::vector<std::string> IfcUtil::IfcBaseEntity::getAttributeNames() const {

0 commit comments

Comments
 (0)