Commit 5796503f authored by David Thompson's avatar David Thompson

Assign default names to meshes upon import.

parent 21eea530
......@@ -54,6 +54,7 @@ Collection::Collection()
, m_floatData(new MeshFloatData)
, m_stringData(new MeshStringData)
, m_integerData(new MeshIntegerData)
, m_nameCounter(-1)
, m_internals(new InternalImpl())
{
}
......@@ -66,6 +67,7 @@ Collection::Collection(const smtk::common::UUID& collectionID)
, m_floatData(new MeshFloatData)
, m_stringData(new MeshStringData)
, m_integerData(new MeshIntegerData)
, m_nameCounter(-1)
, m_internals(new InternalImpl())
{
}
......@@ -79,6 +81,7 @@ Collection::Collection(smtk::mesh::InterfacePtr interface)
, m_floatData(new MeshFloatData)
, m_stringData(new MeshStringData)
, m_integerData(new MeshIntegerData)
, m_nameCounter(-1)
, m_internals(new InternalImpl(interface))
{
}
......@@ -91,6 +94,7 @@ Collection::Collection(const smtk::common::UUID& collectionID, smtk::mesh::Inter
, m_floatData(new MeshFloatData)
, m_stringData(new MeshStringData)
, m_integerData(new MeshIntegerData)
, m_nameCounter(-1)
, m_internals(new InternalImpl(interface))
{
}
......@@ -249,6 +253,30 @@ smtk::mesh::PointConnectivity Collection::pointConnectivity() const
return ms.pointConnectivity();
}
void Collection::assignDefaultNames()
{
smtk::resource::Component::Visitor nameAssigner = [this](
const smtk::resource::Component::Ptr& comp) {
auto mset = comp ? comp->as<smtk::mesh::Component>() : nullptr;
if (!mset || !mset->name().empty())
{
return;
}
// Keep generating names until we find an unused one.
std::string nameToTry;
do
{
m_nameCounter++;
std::ostringstream namer;
namer << "mesh " << m_nameCounter;
nameToTry = namer.str();
} while (this->meshes(nameToTry).isValid());
mset->mesh().setName(nameToTry);
};
this->visit(nameAssigner);
}
smtk::mesh::MeshSet Collection::meshes() const
{
return smtk::mesh::MeshSet(this->shared_from_this(), m_internals->mesh_root_handle());
......
......@@ -163,6 +163,9 @@ public:
smtk::mesh::PointConnectivity pointConnectivity()
const; //all point connectivity info for all cells
/// Assign a machine-generated name to any mesh component that does not have a user-assigned name.
void assignDefaultNames();
//For any mesh set that has a name we return that name. It is possible
//that the we have un-named mesh sets.
std::vector<std::string> meshNames() const;
......@@ -363,6 +366,8 @@ private:
smtk::shared_ptr<MeshStringData> m_stringData;
smtk::shared_ptr<MeshIntegerData> m_integerData;
int m_nameCounter;
//holds a reference to the specific backend interface
class InternalImpl;
smtk::mesh::Collection::InternalImpl* m_internals;
......
......@@ -19,6 +19,7 @@
#include "smtk/attribute/Resource.h"
#include "smtk/attribute/ResourceItem.h"
#include "smtk/attribute/StringItem.h"
#include "smtk/attribute/VoidItem.h"
#include "smtk/io/ImportMesh.h"
......@@ -77,6 +78,12 @@ Import::Result Import::operateInternal()
smtk::mesh::for_each(collection->meshes(), addMeshToResult);
auto assignNames = this->parameters()->findVoid("assign default names");
if (assignNames && assignNames->isEnabled())
{
collection->assignDefaultNames();
}
result->findResource("resource")->appendValue(collection);
return result;
......
......@@ -11,8 +11,14 @@
</File>
<String Name="label" Label="Domain Property" NumberOfRequiredValues="1" AdvanceLevel="1">
<DefaultValue></DefaultValue>
</String>
<DefaultValue></DefaultValue>
</String>
<Void Name="assign default names" Optional="true" IsEnabledByDefault="true" AdvanceLevel="1">
<BriefDescription>
Upon importing, assign names to meshes that have no name already.
</BriefDescription>
</Void>
</ItemDefinitions>
</AttDef>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment