Commit 08d3f257 authored by Yumin Yuan's avatar Yumin Yuan
Browse files

Consolidate SetProperty op to also handle mesh property

parent 9987965e
......@@ -15,9 +15,13 @@
#include "smtk/model/Manager.h"
#include "smtk/model/Model.h"
#include "smtk/mesh/Manager.h"
#include "smtk/mesh/Collection.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/DoubleItem.h"
#include "smtk/attribute/MeshItem.h"
#include "smtk/attribute/ModelEntityItem.h"
#include "smtk/attribute/StringItem.h"
......@@ -60,6 +64,30 @@ void SetProperty::setPropertyValue(const std::string& pname, typename VI::Ptr it
}
}
template<typename V, typename VL, typename VD, typename VI>
void SetMeshPropertyValue(const std::string& name, typename VI::Ptr item,
smtk::mesh::CollectionPtr c, const smtk::mesh::MeshSet& mesh)
{
EntityRefArray::iterator it;
if (!item || item->numberOfValues() == 0)
{
// Erase the property of this type from these entities,
// if they had the property in the first place.
c->removeProperty<VD>(mesh, name);
}
else
{
// Get the array of values from the item.
VL values;
values.reserve(item->numberOfValues());
for (std::size_t i = 0; i < item->numberOfValues(); ++i)
values.push_back(item->value(i));
// Add or overwrite the property with the values.
(*c->meshProperties<VD>(mesh))[name] = values;
}
}
void SetProperty::setName(const std::string& pname, smtk::model::EntityRefArray& entities)
{
smtk::model::EntityRefArray::iterator it;
......@@ -128,6 +156,29 @@ smtk::model::OperatorResult SetProperty::operateInternal()
else if (propName == "visible" && integerItem->numberOfValues() > 0)
this->setVisibility(integerItem->value(0), entities);
// check whether there are mesh entities's properties need to be changed
smtk::attribute::MeshItemPtr meshItem = this->findMesh("meshes");
smtk::mesh::MeshList modifiedMeshes;
if(meshItem)
{
smtk::model::ManagerPtr modelmgr = this->manager();
smtk::mesh::ManagerPtr meshmgr = modelmgr->meshes();
smtk::attribute::MeshItem::const_mesh_it it;
for(it = meshItem->begin(); it != meshItem->end(); ++it)
{
smtk::mesh::CollectionPtr c = meshmgr->collection(it->collectionId());
if(!c)
continue;
SetMeshPropertyValue<String,StringList,StringData,StringItem>(
nameItem->value(0), stringItem, c, *it);
SetMeshPropertyValue<Float,FloatList,FloatData,DoubleItem>(
nameItem->value(0), floatItem, c, *it);
SetMeshPropertyValue<Integer,IntegerList,IntegerData,IntItem>(
nameItem->value(0), integerItem, c, *it);
modifiedMeshes.push_back(*it);
}
}
smtk::model::OperatorResult result = this->createResult(
smtk::model::OPERATION_SUCCEEDED);
......@@ -143,6 +194,15 @@ smtk::model::OperatorResult SetProperty::operateInternal()
for (int i = 0; i < numEntitiesOut; ++i, ++it)
resultEntities->setValue(i, *it);
// Return the list of meshes that were potentially modified.
if (modifiedMeshes.size() > 0)
{
smtk::attribute::MeshItemPtr resultMeshes =
result->findMesh("mesh_modified");
if(resultMeshes)
resultMeshes->appendValues(modifiedMeshes);
}
return result;
}
......
......@@ -23,8 +23,6 @@ set(meshSrcs
moab/MergeMeshVertices.cxx
moab/Readers.cxx
moab/Writers.cxx
operators/SetProperty.cxx
)
set(meshHeaders
......@@ -52,12 +50,8 @@ set(meshHeaders
moab/Interface.h
moab/Allocator.h
moab/HandleRange.h
operators/SetProperty.h
)
smtk_operator_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/SetProperty.sbt" defOpXML)
#install the headers
smtk_public_headers(${meshHeaders})
......
//=========================================================================
// 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/SetProperty.h"
#include "smtk/model/Session.h"
#include "smtk/model/Manager.h"
#include "smtk/mesh/Manager.h"
#include "smtk/mesh/Collection.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/DoubleItem.h"
#include "smtk/attribute/MeshItem.h"
#include "smtk/attribute/ModelEntityItem.h"
#include "smtk/attribute/StringItem.h"
using namespace smtk::model;
using smtk::attribute::StringItem;
using smtk::attribute::DoubleItem;
using smtk::attribute::IntItem;
namespace smtk {
namespace mesh {
template<typename V, typename VL, typename VD, typename VI>
void SetPropertyValue(const std::string& name, typename VI::Ptr item,
smtk::mesh::CollectionPtr c, const smtk::mesh::MeshSet& mesh)
{
EntityRefArray::iterator it;
if (!item || item->numberOfValues() == 0)
{
// Erase the property of this type from these entities,
// if they had the property in the first place.
c->removeProperty<VD>(mesh, name);
}
else
{
// Get the array of values from the item.
VL values;
values.reserve(item->numberOfValues());
for (std::size_t i = 0; i < item->numberOfValues(); ++i)
values.push_back(item->value(i));
// Add or overwrite the property with the values.
(*c->meshProperties<VD>(mesh))[name] = values;
}
}
smtk::model::OperatorResult SetProperty::operateInternal()
{
smtk::attribute::StringItemPtr nameItem = this->findString("name");
smtk::attribute::StringItemPtr stringItem = this->findString("string value");
smtk::attribute::DoubleItemPtr floatItem = this->findDouble("float value");
smtk::attribute::IntItemPtr integerItem = this->findInt("integer value");
smtk::attribute::MeshItemPtr meshItem = this->findMesh("meshes");
std::string propname = nameItem->value(0);
if (propname.empty())
return this->createResult(smtk::model::OPERATION_FAILED);
std::map<smtk::common::UUID, smtk::mesh::MeshSet > modifiedMeshes;
smtk::model::ManagerPtr modelmgr = this->manager();
smtk::mesh::ManagerPtr meshmgr = modelmgr->meshes();
smtk::attribute::MeshItem::const_mesh_it it;
for(it = meshItem->begin(); it != meshItem->end(); ++it)
{
smtk::mesh::CollectionPtr c = meshmgr->collection(it->first);
if(c->isValid())
{
SetPropertyValue<String,StringList,StringData,StringItem>(
propname, stringItem, c, it->second);
SetPropertyValue<Float,FloatList,FloatData,DoubleItem>(
propname, floatItem, c, it->second);
SetPropertyValue<Integer,IntegerList,IntegerData,IntItem>(
propname, integerItem, c, it->second);
modifiedMeshes[c->entity()] = it->second;
}
}
if (modifiedMeshes.size() == 0)
return this->createResult(smtk::model::OPERATION_FAILED);
smtk::model::OperatorResult result = this->createResult(
smtk::model::OPERATION_SUCCEEDED);
// Return the list of meshes that were potentially
// modified so that remote sessions can track what records
// need to be re-fetched.
smtk::attribute::MeshItemPtr resultMeshes =
result->findMesh("mesh_modified");
for(it = modifiedMeshes.begin(); it != modifiedMeshes.end(); ++it)
resultMeshes->setValue(it->first, it->second);
return result;
}
} //namespace mesh
} // namespace smtk
#include "smtk/mesh/SetProperty_xml.h"
smtkImplementsModelOperator(
SMTKCORE_EXPORT,
smtk::mesh::SetProperty,
set_mesh_property,
"set mesh property",
SetProperty_xml,
smtk::model::Session);
//=========================================================================
// 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_SetProperty_h
#define __smtk_mesh_SetProperty_h
#include "smtk/model/Operator.h"
namespace smtk {
namespace mesh {
class SMTKCORE_EXPORT SetProperty : public smtk::model::Operator
{
public:
smtkTypeMacro(SetProperty);
smtkCreateMacro(SetProperty);
smtkSharedFromThisMacro(Operator);
smtkDeclareModelOperator();
protected:
virtual smtk::model::OperatorResult operateInternal();
};
} //namespace mesh
} // namespace smtk
#endif // __smtk_mesh_SetProperty_h
<?xml version="1.0" encoding="utf-8" ?>
<!-- Description of the CMB Discrete Model "edge" Operator -->
<SMTK_AttributeSystem Version="2">
<Definitions>
<!-- Operator -->
<AttDef Type="set mesh property" BaseType="operator" AdvanceLevel="11">
<AssociationsDef Name="model" NumberOfRequiredValues="1">
<MembershipMask>model</MembershipMask>
</AssociationsDef>
<BriefDescription>
Set (or remove) a property value on a set of meshsets.
</BriefDescription>
<DetailedDescription>
Set (or remove) a property value on a set of meshsets.
The string, integer, and floating-point values are all optional.
Any combination may be specified.
All that are specified are set; those unspecified are removed.
For example, specifying both a string and an integer value for
the "foo" property would set those values in the mesh collection's
string and integer maps while removing "foo" from the associated
meshsets' floating-point map.
</DetailedDescription>
<ItemDefinitions>
<MeshEntity Name="meshes" NumberOfRequiredValues="1" Extensible="true">
</MeshEntity>
<String Name="name" NumberOfRequiredValues="1">
<BriefDescription>The name of the property to set.</BriefDescription>
</String>
<Double Name="float value" NumberOfRequiredValues="0" Extensible="true">
<BriefDescription>Floating-point value(s) of the property.</BriefDescription>
</Double>
<String Name="string value" NumberOfRequiredValues="0" Extensible="true">
<BriefDescription>String value(s) of the property.</BriefDescription>
</String>
<Int Name="integer value" NumberOfRequiredValues="0" Extensible="true">
<BriefDescription>Integer value(s) of the property.</BriefDescription>
</Int>
</ItemDefinitions>
</AttDef>
<!-- Result -->
<AttDef Type="result(set mesh property)" BaseType="result">
<ItemDefinitions>
<MeshEntity Name="mesh_modified" NumberOfRequiredValues="1"/>
</ItemDefinitions>
</AttDef>
</Definitions>
</SMTK_AttributeSystem>
......@@ -10,14 +10,17 @@
#include "smtk/model/operators/SetProperty.h"
#include "smtk/model/Session.h"
#include "smtk/model/CellEntity.h"
#include "smtk/model/Manager.h"
#include "smtk/model/Model.h"
#include "smtk/mesh/Manager.h"
#include "smtk/mesh/Collection.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/DoubleItem.h"
#include "smtk/attribute/MeshItem.h"
#include "smtk/attribute/ModelEntityItem.h"
#include "smtk/attribute/StringItem.h"
......@@ -54,6 +57,30 @@ void SetPropertyValue(const std::string& name, typename VI::Ptr item, EntityRefA
}
}
template<typename V, typename VL, typename VD, typename VI>
void SetMeshPropertyValue(const std::string& name, typename VI::Ptr item,
smtk::mesh::CollectionPtr c, const smtk::mesh::MeshSet& mesh)
{
EntityRefArray::iterator it;
if (!item || item->numberOfValues() == 0)
{
// Erase the property of this type from these entities,
// if they had the property in the first place.
c->removeProperty<VD>(mesh, name);
}
else
{
// Get the array of values from the item.
VL values;
values.reserve(item->numberOfValues());
for (std::size_t i = 0; i < item->numberOfValues(); ++i)
values.push_back(item->value(i));
// Add or overwrite the property with the values.
(*c->meshProperties<VD>(mesh))[name] = values;
}
}
smtk::model::OperatorResult SetProperty::operateInternal()
{
smtk::attribute::StringItemPtr nameItem = this->findString("name");
......@@ -73,6 +100,29 @@ smtk::model::OperatorResult SetProperty::operateInternal()
SetPropertyValue<Integer,IntegerList,IntegerData,IntItem>(
nameItem->value(0), integerItem, entities);
// check whether there are mesh entities's properties need to be changed
smtk::attribute::MeshItemPtr meshItem = this->findMesh("meshes");
smtk::mesh::MeshList modifiedMeshes;
if(meshItem)
{
smtk::model::ManagerPtr modelmgr = this->manager();
smtk::mesh::ManagerPtr meshmgr = modelmgr->meshes();
smtk::attribute::MeshItem::const_mesh_it it;
for(it = meshItem->begin(); it != meshItem->end(); ++it)
{
smtk::mesh::CollectionPtr c = meshmgr->collection(it->collectionId());
if(!c)
continue;
SetMeshPropertyValue<String,StringList,StringData,StringItem>(
nameItem->value(0), stringItem, c, *it);
SetMeshPropertyValue<Float,FloatList,FloatData,DoubleItem>(
nameItem->value(0), floatItem, c, *it);
SetMeshPropertyValue<Integer,IntegerList,IntegerData,IntItem>(
nameItem->value(0), integerItem, c, *it);
modifiedMeshes.push_back(*it);
}
}
smtk::model::OperatorResult result = this->createResult(
smtk::model::OPERATION_SUCCEEDED);
......@@ -88,6 +138,15 @@ smtk::model::OperatorResult SetProperty::operateInternal()
for (int i = 0; i < numEntitiesOut; ++i, ++it)
resultEntities->setValue(i, *it);
// Return the list of meshes that were potentially modified.
if (modifiedMeshes.size() > 0)
{
smtk::attribute::MeshItemPtr resultMeshes =
result->findMesh("mesh_modified");
if(resultMeshes)
resultMeshes->appendValues(modifiedMeshes);
}
return result;
}
......
......@@ -22,6 +22,8 @@
entities' floating-point map.
</DetailedDescription>
<ItemDefinitions>
<MeshEntity Name="meshes" NumberOfRequiredValues="0" Extensible="true" AdvanceLevel="11">
</MeshEntity>
<String Name="name" NumberOfRequiredValues="1">
<BriefDescription>The name of the property to set.</BriefDescription>
</String>
......@@ -39,6 +41,7 @@
<!-- Result -->
<AttDef Type="result(set property)" BaseType="result">
<!-- The modified entities are stored in the base result's "modified" item. -->
<MeshEntity Name="mesh_modified" NumberOfRequiredValues="0" Extensible="true" AdvanceLevel="11"/>
</AttDef>
</Definitions>
</SMTK_AttributeSystem>
Supports Markdown
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