Unify GeometrySerializers' object ID logic. Fixes #397.

This commit is contained in:
Stinkfist0
2018-06-07 14:34:25 +03:00
committed by Thomas Krijnen
parent bd5e25889a
commit 505d234ea2
5 changed files with 41 additions and 58 deletions
+26 -50
View File
@@ -263,20 +263,13 @@ void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const IfcGeom::
{ 0, 0, 0, 1 } { 0, 0, 0, 1 }
}; };
// Chose a name of the parent object std::string name = serializer->object_id(&parent);
std::string name = "";
if (serializer->settings().get(SerializerSettings::USE_ELEMENT_TYPES)) {
name = parent.type() + " " + parent.name();
} else {
name = parent.unique_id();
}
collada_id(name); collada_id(name);
const std::string& id = name;
COLLADASW::Node *current_node; COLLADASW::Node *current_node;
current_node = new COLLADASW::Node(mSW); current_node = new COLLADASW::Node(mSW);
current_node->setNodeId(id); current_node->setNodeId(name);
/// @todo redundant information using ID as both ID and Name, maybe omit Name or allow specifying what would be used as the name
current_node->setNodeName(name); current_node->setNodeName(name);
current_node->setType(COLLADASW::Node::NODE); current_node->setType(COLLADASW::Node::NODE);
current_node->start(); current_node->start();
@@ -391,19 +384,7 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme
{ {
const IfcGeom::Representation::Triangulation<real_t>& mesh = o->geometry(); const IfcGeom::Representation::Triangulation<real_t>& mesh = o->geometry();
std::string slabSuffix = ""; std::string name = serializer->object_id(o);
if (o->type() == "IfcSlab")
{
slabSuffix = differentiateSlabTypes(o);
}
std::string name = serializer->settings().get(SerializerSettings::USE_ELEMENT_GUIDS)
? o->guid()
: (serializer->settings().get(SerializerSettings::USE_ELEMENT_NAMES)
? o->name()
: (serializer->settings().get(SerializerSettings::USE_ELEMENT_TYPES)
? (o->type() + slabSuffix)
: o->unique_id()));
collada_id(name); collada_id(name);
std::string representation_id = "representation-" + o->geometry().id(); std::string representation_id = "representation-" + o->geometry().id();
@@ -430,33 +411,28 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme
deferreds.push_back(deferred); deferreds.push_back(deferred);
} }
std::string ColladaSerializer::ColladaExporter::differentiateSlabTypes(const IfcGeom::TriangulationElement<real_t>* o) { std::string ColladaSerializer::differentiateSlabTypes(const IfcSchema::IfcSlab* slab)
IfcSlab* slab = (IfcSlab*)o->product(); {
std::string result; switch (slab->PredefinedType())
switch (slab->PredefinedType()) {
{ case IfcSlabTypeEnum::IfcSlabType_FLOOR: return "_Floor";
case (IfcSlabTypeEnum::IfcSlabType_FLOOR): case IfcSlabTypeEnum::IfcSlabType_ROOF: return "_Roof";
result = "_Floor"; case IfcSlabTypeEnum::IfcSlabType_LANDING: return "_Landing";
break; case IfcSlabTypeEnum::IfcSlabType_BASESLAB: return "_BaseSlab";
case (IfcSlabTypeEnum::IfcSlabType_ROOF): case IfcSlabTypeEnum::IfcSlabType_NOTDEFINED: return "_NotDefined";
result = "_Roof"; default: return slab->hasObjectType() ? "_" + slab->ObjectType() : "_Unknown";
break; }
case (IfcSlabTypeEnum::IfcSlabType_LANDING): }
result = "_Landing";
break; std::string ColladaSerializer::object_id(const IfcGeom::Element<real_t>* o) /*override*/
case (IfcSlabTypeEnum::IfcSlabType_BASESLAB): {
result = "_BaseSlab"; if (settings_.get(SerializerSettings::USE_ELEMENT_TYPES)) {
break; const std::string slabSuffix = (o->product() && o->product()->is(IfcSchema::IfcSlab::Class()))
case (IfcSlabTypeEnum::IfcSlabType_NOTDEFINED): ? differentiateSlabTypes(o->product()->as<IfcSchema::IfcSlab>())
result = "_NotDefined"; : "";
break; return o->type() + slabSuffix;
default: }
if (slab->hasObjectType()) { result = "_" + slab->ObjectType(); } return GeometrySerializer::object_id(o);
else { result = "_Unknown"; }
break;
}
collada_id(result);
return result;
} }
void ColladaSerializer::ColladaExporter::endDocument() { void ColladaSerializer::ColladaExporter::endDocument() {
+5 -1
View File
@@ -189,7 +189,6 @@ private:
COLLADABU::NativeString filename; COLLADABU::NativeString filename;
COLLADASW::StreamWriter stream; COLLADASW::StreamWriter stream;
ColladaScene scene; ColladaScene scene;
std::string differentiateSlabTypes(const IfcGeom::TriangulationElement<real_t>* o);
public: public:
/// @param double_precision Whether to use "double precision" (up to 16 decimals) or not (6 or 7 decimals). /// @param double_precision Whether to use "double precision" (up to 16 decimals) or not (6 or 7 decimals).
ColladaExporter(const std::string& scene_name, const std::string& fn, ColladaSerializer *_serializer, ColladaExporter(const std::string& scene_name, const std::string& fn, ColladaSerializer *_serializer,
@@ -235,6 +234,11 @@ public:
unit_magnitude = magnitude; unit_magnitude = magnitude;
} }
void setFile(IfcParse::IfcFile*) {} void setFile(IfcParse::IfcFile*) {}
std::string object_id(const IfcGeom::Element<real_t>* o) /*override*/;
private:
static std::string differentiateSlabTypes(const IfcSchema::IfcSlab *slab);
}; };
#endif #endif
+8
View File
@@ -82,6 +82,14 @@ public:
const SerializerSettings& settings() const { return settings_; } const SerializerSettings& settings() const { return settings_; }
SerializerSettings& settings() { return settings_; } SerializerSettings& settings() { return settings_; }
/// Returns ID for the object depending on the used setting.
virtual std::string object_id(const IfcGeom::Element<real_t>* o)
{
if (settings_.get(SerializerSettings::USE_ELEMENT_GUIDS)) return o->guid();
if (settings_.get(SerializerSettings::USE_ELEMENT_NAMES)) return o->name();
return o->unique_id();
}
protected: protected:
SerializerSettings settings_; SerializerSettings settings_;
}; };
+1 -3
View File
@@ -466,9 +466,7 @@ std::string SvgSerializer::nameElement(const IfcGeom::Element<real_t>* elem)
{ {
std::ostringstream oss; std::ostringstream oss;
const std::string type = "product"; const std::string type = "product";
const std::string name = (settings().get(SerializerSettings::USE_ELEMENT_GUIDS) const std::string name = object_id(elem);
? elem->guid() : (settings().get(SerializerSettings::USE_ELEMENT_NAMES)
? elem->name() : elem->unique_id()));
oss << "id=\"" << type << "-" << name<< "\""; oss << "id=\"" << type << "-" << name<< "\"";
return oss.str(); return oss.str();
} }
+1 -4
View File
@@ -73,10 +73,7 @@ void WaveFrontOBJSerializer::writeMaterial(const IfcGeom::Material& style)
void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>* o) void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>* o)
{ {
const std::string name = (settings().get(SerializerSettings::USE_ELEMENT_GUIDS) obj_stream << "g " << object_id(o) << "\n";
? o->guid() : (settings().get(SerializerSettings::USE_ELEMENT_NAMES)
? o->name() : o->unique_id()));
obj_stream << "g " << name << "\n";
obj_stream << "s 1" << "\n"; obj_stream << "s 1" << "\n";
const IfcGeom::Representation::Triangulation<real_t>& mesh = o->geometry(); const IfcGeom::Representation::Triangulation<real_t>& mesh = o->geometry();