Commit 26f5e674 authored by David Thompson's avatar David Thompson Committed by Kitware Robot

Merge topic 'mesh-names'

154bd374 Edit the mesh component release note.
e0800f3e Make mesh names editable.
4cd942d7 mesh/moab/Tags: create name tag if necessary.
5796503f Assign default names to meshes upon import.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: T.J. Corona's avatarT.J. Corona <tj.corona@kitware.com>
Merge-request: !1328
parents 21eea530 154bd374
......@@ -9,3 +9,7 @@ attribute.
`smtk::mesh::Component` is now used to send/retrieve meshsets to/from
attributes.
Mesh resources and components now appear in the resource tree view
and mesh component names may be edited in place using the new
SetMeshName operator.
......@@ -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;
......
......@@ -53,7 +53,8 @@ public:
, m_tagData()
{
//populate our tag
m_iface->tag_get_handle(NAME_TAG_NAME, NAME_TAG_SIZE, ::moab::MB_TYPE_OPAQUE, m_tag);
auto res = m_iface->tag_get_handle(NAME_TAG_NAME, NAME_TAG_SIZE, ::moab::MB_TYPE_OPAQUE, m_tag,
::moab::MB_TAG_SPARSE | ::moab::MB_TAG_CREAT);
}
//reset our warnings to the original level
#ifdef _MSC_VER
......
......@@ -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>
......
......@@ -19,6 +19,7 @@
#include "smtk/mesh/core/CellSet.h"
#include "smtk/mesh/core/Component.h"
#include "smtk/mesh/core/MeshSet.h"
#include "smtk/mesh/operators/SetMeshName.h"
#include "smtk/model/Entity.h"
#include "smtk/model/EntityRef.h"
......@@ -67,7 +68,9 @@ bool ComponentPhraseContent::editable(ContentType attr) const
if (attr == TITLE || attr == COLOR)
{
auto modelComp = dynamic_pointer_cast<smtk::model::Entity>(m_component);
return !!modelComp;
auto meshComp = dynamic_pointer_cast<smtk::mesh::Component>(m_component);
// Models may be assigned a color and a name; meshes may be assigned a name.
return !!modelComp || (attr == TITLE && !!meshComp);
}
}
return false;
......@@ -193,6 +196,21 @@ bool ComponentPhraseContent::editStringValue(ContentType attr, const std::string
}
}
}
auto meshComp = std::dynamic_pointer_cast<smtk::mesh::Component>(m_component);
if (meshComp)
{
auto op = smtk::mesh::SetMeshName::create();
if (op->parameters()->associate(meshComp))
{
op->parameters()->findString("name")->setValue(val);
auto res = op->operate();
if (res->findInt("outcome")->value() ==
static_cast<int>(smtk::operation::Operation::Outcome::SUCCEEDED))
{
return true;
}
}
}
}
return false;
}
......
......@@ -180,8 +180,9 @@ void SubphraseGenerator::componentsOfResource(
}
else if (meshRsrc)
{
constexpr int mutability = static_cast<int>(smtk::view::PhraseContent::ContentType::TITLE);
smtk::resource::Component::Visitor visitor = [&](const smtk::resource::Component::Ptr& entry) {
result.push_back(ComponentPhraseContent::createPhrase(entry, 0, src));
result.push_back(ComponentPhraseContent::createPhrase(entry, mutability, src));
};
meshRsrc->visit(visitor);
}
......
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