Commit 21eea530 authored by T.J. Corona's avatar T.J. Corona Committed by Kitware Robot

Merge topic 'meshset-name-op'

b35321e4 Add SetMeshName operator
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1326
parents 6d120f27 b35321e4
Pipeline #122821 failed with stage
in 0 seconds
......@@ -46,6 +46,7 @@ set(meshSrcs
operators/Import.cxx
operators/InterpolateOntoMesh.cxx
operators/Read.cxx
operators/SetMeshName.cxx
operators/UndoElevateMesh.cxx
operators/Write.cxx
......@@ -103,6 +104,7 @@ set(meshHeaders
operators/Import.h
operators/InterpolateOntoMesh.h
operators/Read.h
operators/SetMeshName.h
operators/UndoElevateMesh.h
operators/Write.h
......@@ -124,6 +126,7 @@ smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/GenerateHotStartData.s
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Import.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/InterpolateOntoMesh.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Read.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/SetMeshName.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/UndoElevateMesh.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Write.sbt" defOpXML)
......
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "smtk/mesh/operators/SetMeshName.h"
#include "smtk/mesh/core/Collection.h"
#include "smtk/mesh/core/Component.h"
#include "smtk/mesh/core/MeshSet.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/ComponentItem.h"
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/StringItem.h"
#include "smtk/mesh/SetMeshName_xml.h"
namespace smtk
{
namespace mesh
{
smtk::mesh::SetMeshName::Result SetMeshName::operateInternal()
{
// Access the name to use when renaming the meshset
smtk::attribute::StringItem::Ptr nameItem = this->parameters()->findString("name");
// Access the meshset to rename
smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations();
smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs<smtk::mesh::Component>();
smtk::mesh::MeshSet meshset = meshComponent->mesh();
// Set the name of the meshset
bool success = meshset.setName(nameItem->value());
if (success == false)
{
return this->createResult(smtk::operation::Operation::Outcome::FAILED);
}
// Create a new result
Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED);
// Access the attribute associated with modified components
result->findComponent("modified")->appendValue(meshComponent);
// Return with success
return result;
}
const char* SetMeshName::xmlDescription() const
{
return SetMeshName_xml;
}
} //namespace mesh
} // namespace smtk
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#ifndef __smtk_mesh_SetMeshName_h
#define __smtk_mesh_SetMeshName_h
#include "smtk/operation/XMLOperation.h"
namespace smtk
{
namespace mesh
{
/**\brief Set the name of a meshset.
*/
class SMTKCORE_EXPORT SetMeshName : public smtk::operation::XMLOperation
{
public:
smtkTypeMacro(smtk::mesh::SetMeshName);
smtkCreateMacro(SetMeshName);
smtkSharedFromThisMacro(smtk::operation::Operation);
smtkSuperclassMacro(smtk::operation::XMLOperation);
protected:
Result operateInternal() override;
virtual const char* xmlDescription() const override;
};
} //namespace mesh
} // namespace smtk
#endif // __smtk_mesh_SetMeshName_h
<?xml version="1.0" encoding="utf-8" ?>
<!-- Description of the mesh "SetMeshName" Operation -->
<SMTK_AttributeResource Version="3">
<Definitions>
<include href="smtk/operation/Operation.xml"/>
<AttDef Type="set mesh name" BaseType="operation" Label="Mesh - Set Name">
<AssociationsDef Name="mesh" NumberOfRequiredValues="1" Extensible="false">
<Accepts><Resource Name="smtk::mesh::Collection" Filter="meshset"/></Accepts>
</AssociationsDef>
<ItemDefinitions>
<String Name="name" NumberOfRequiredValues="1"/>
</ItemDefinitions>
<BriefDescription>
Set a mesh name.
</BriefDescription>
<DetailedDescription>
&lt;p&gt;Set a mesh name.
&lt;p&gt;This operator sets the name of a meshset.
</DetailedDescription>
</AttDef>
<!-- Result -->
<include href="smtk/operation/Result.xml"/>
<AttDef Type="result(set mesh name)" BaseType="result">
<ItemDefinitions>
</ItemDefinitions>
</AttDef>
</Definitions>
</SMTK_AttributeResource>
......@@ -8,10 +8,17 @@
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/StringItem.h"
#include "smtk/io/ImportMesh.h"
#include "smtk/mesh/core/Collection.h"
#include "smtk/mesh/core/Component.h"
#include "smtk/mesh/operators/SetMeshName.h"
#include "smtk/mesh/testing/cxx/helpers.h"
namespace
......@@ -441,6 +448,38 @@ void verify_meshset_set_names(const smtk::mesh::CollectionPtr& c)
c->visit(checkMeshNames);
}
void verify_meshset_set_name_op(const smtk::mesh::CollectionPtr& c)
{
std::size_t numMeshesIteratedOver = 0;
smtk::resource::Component::Visitor setMeshNames = [&](
const smtk::resource::ComponentPtr& component) {
auto meshComponent = std::dynamic_pointer_cast<smtk::mesh::Component>(component);
std::stringstream s;
s << "my_meshset " << numMeshesIteratedOver;
smtk::mesh::SetMeshName::Ptr setMeshNameOp = smtk::mesh::SetMeshName::create();
setMeshNameOp->parameters()->associate(meshComponent);
setMeshNameOp->parameters()->findString("name")->setValue(s.str());
auto result = setMeshNameOp->operate();
test(result->findInt("outcome")->value() ==
static_cast<int>(smtk::operation::Operation::Outcome::SUCCEEDED));
numMeshesIteratedOver++;
};
c->visit(setMeshNames);
numMeshesIteratedOver = 0;
smtk::resource::Component::Visitor checkMeshNames = [&](
const smtk::resource::ComponentPtr& component) {
auto meshComponent = std::dynamic_pointer_cast<smtk::mesh::Component>(component);
std::stringstream s;
s << "my_meshset " << numMeshesIteratedOver;
test(meshComponent->name() == s.str());
numMeshesIteratedOver++;
};
c->visit(checkMeshNames);
}
}
int UnitTestMeshSet(int, char** const)
......@@ -464,6 +503,7 @@ int UnitTestMeshSet(int, char** const)
verify_meshset_for_each(c);
verify_meshset_visit(c);
verify_meshset_set_names(c);
verify_meshset_set_name_op(c);
return 0;
}
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