Commit 9fe19b10 authored by Yumin Yuan's avatar Yumin Yuan
Browse files

Add MeshItem to attribute system for associating meshes

parent 1b0f10bb
......@@ -52,6 +52,8 @@ namespace smtk
class Item;
class ItemDefinition;
class System;
class MeshItem;
class MeshItemDefinition;
class MeshSelectionItem;
class MeshSelectionItemDefinition;
class ModelEntityItem;
......@@ -292,6 +294,8 @@ namespace smtk
typedef smtk::shared_ptr< smtk::attribute::IntItemDefinition > IntItemDefinitionPtr;
typedef smtk::shared_ptr< smtk::attribute::StringItem > StringItemPtr;
typedef smtk::shared_ptr< smtk::attribute::StringItemDefinition > StringItemDefinitionPtr;
typedef smtk::shared_ptr< smtk::attribute::MeshItem > MeshItemPtr;
typedef smtk::shared_ptr< smtk::attribute::MeshItemDefinition > MeshItemDefinitionPtr;
typedef smtk::shared_ptr< smtk::attribute::MeshSelectionItem > MeshSelectionItemPtr;
typedef smtk::shared_ptr< smtk::attribute::MeshSelectionItemDefinition > MeshSelectionItemDefinitionPtr;
typedef smtk::shared_ptr< smtk::attribute::ModelEntityItem > ModelEntityItemPtr;
......@@ -311,6 +315,8 @@ namespace smtk
typedef smtk::shared_ptr< const smtk::attribute::IntItemDefinition > ConstIntItemDefinitionPtr;
typedef smtk::shared_ptr< const smtk::attribute::StringItem > ConstStringItemPtr;
typedef smtk::shared_ptr< const smtk::attribute::StringItemDefinition > ConstStringItemDefinitionPtr;
typedef smtk::shared_ptr< const smtk::attribute::MeshItem > ConstMeshItemPtr;
typedef smtk::shared_ptr< const smtk::attribute::MeshItemDefinition > ConstMeshItemDefinitionPtr;
typedef smtk::shared_ptr< const smtk::attribute::MeshSelectionItem > ConstMeshSelectionItemPtr;
typedef smtk::shared_ptr< const smtk::attribute::MeshSelectionItemDefinition > ConstMeshSelectionItemDefinitionPtr;
typedef smtk::shared_ptr< const smtk::attribute::ModelEntityItem > ConstModelEntityItemPtr;
......
......@@ -10,6 +10,7 @@
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/MeshItem.h"
#include "smtk/attribute/MeshSelectionItem.h"
#include "smtk/attribute/ModelEntityItem.h"
#include "smtk/attribute/ModelEntityItemDefinition.h"
......@@ -599,3 +600,8 @@ smtk::attribute::MeshSelectionItemPtr Attribute::findMeshSelection(const std::st
{ return smtk::dynamic_pointer_cast<MeshSelectionItem>(this->find(nameStr)); }
smtk::attribute::ConstMeshSelectionItemPtr Attribute::findMeshSelection(const std::string &nameStr) const
{ return smtk::dynamic_pointer_cast<const MeshSelectionItem>(this->find(nameStr)); }
smtk::attribute::MeshItemPtr Attribute::findMesh(const std::string &nameStr)
{ return smtk::dynamic_pointer_cast<MeshItem>(this->find(nameStr)); }
smtk::attribute::ConstMeshItemPtr Attribute::findMesh(const std::string &nameStr) const
{ return smtk::dynamic_pointer_cast<const MeshItem>(this->find(nameStr)); }
......@@ -168,6 +168,8 @@ namespace smtk
MeshSelectionItemPtr findMeshSelection(const std::string &name);
ConstMeshSelectionItemPtr findMeshSelection(const std::string &name) const;
MeshItemPtr findMesh(const std::string &name);
ConstMeshItemPtr findMesh(const std::string &name) const;
// These methods only applies to Attributes whose
// definition returns true for isNodal()
......
......@@ -16,6 +16,8 @@ set(attributeHeaders
Item.h
ItemDefinition.h
System.h
MeshItem.h
MeshItemDefinition.h
MeshSelectionItem.h
MeshSelectionItemDefinition.h
ModelEntityItem.h
......@@ -49,6 +51,8 @@ set(attributeSrcs
Item.cxx
ItemDefinition.cxx
System.cxx
MeshItem.cxx
MeshItemDefinition.cxx
MeshSelectionItem.cxx
MeshSelectionItemDefinition.cxx
ModelEntityItem.cxx
......
......@@ -235,6 +235,8 @@ std::string Item::type2String(Item::Type t)
return "ModelEntity";
case MESH_SELECTION:
return "MeshSelection";
case MESH_ENTITY:
return "MeshEntity";
default:
return "";
}
......@@ -287,6 +289,10 @@ Item::Type Item::string2Type(const std::string &s)
{
return MESH_SELECTION;
}
if (s == "MeshEntity")
{
return MESH_ENTITY;
}
return NUMBER_OF_TYPES;
}
//----------------------------------------------------------------------------
......@@ -53,6 +53,7 @@ namespace smtk
COLOR,
MODEL_ENTITY,
MESH_SELECTION,
MESH_ENTITY,
NUMBER_OF_TYPES
};
......
//=========================================================================
// 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/attribute/MeshItem.h"
#include "smtk/attribute/MeshItemDefinition.h"
#include "smtk/attribute/Attribute.h"
#include <iostream>
#include <stdio.h>
#include <algorithm> // std::set_difference
using namespace smtk::attribute;
//----------------------------------------------------------------------------
MeshItem::MeshItem(Attribute* owningAttribute,
int itemPosition):
Item(owningAttribute, itemPosition)
{
}
//----------------------------------------------------------------------------
MeshItem::MeshItem(Item* inOwningItem,
int itemPosition,
int inSubGroupPosition):
Item(inOwningItem, itemPosition, inSubGroupPosition)
{
}
//----------------------------------------------------------------------------
bool MeshItem::
setDefinition(smtk::attribute::ConstItemDefinitionPtr adef)
{
// Note that we do a dynamic cast here since we don't
// know if the proper definition is being passed
const MeshItemDefinition* def =
dynamic_cast<const MeshItemDefinition*>(adef.get());
// Call the parent's set definition - similar to constructor calls
// we call from base to derived
if ((def == NULL) || (!Item::setDefinition(adef)))
{
return false;
}
this->m_meshValues.clear();
return true;
}
//----------------------------------------------------------------------------
MeshItem::~MeshItem()
{
}
//----------------------------------------------------------------------------
Item::Type MeshItem::type() const
{
const MeshItemDefinition* def =
static_cast<const MeshItemDefinition*>(this->definition().get());
if (def != NULL)
{
return def->type();
}
return Item::MESH_ENTITY;
}
//----------------------------------------------------------------------------
std::size_t MeshItem::numberOfValues() const
{
return this->m_meshValues.size();
}
//----------------------------------------------------------------------------
/// Return the number of values required by this item's definition (if it has one).
std::size_t MeshItem::numberOfRequiredValues() const
{
const MeshItemDefinition *def =
static_cast<const MeshItemDefinition*>(this->m_definition.get());
if (def == NULL)
{
return 0;
}
return def->numberOfRequiredValues();
}
// A convenience method returning whether the item's definition is extensible.
bool MeshItem::isExtensible() const
{
smtk::attribute::ConstMeshItemDefinitionPtr def =
smtk::dynamic_pointer_cast<const MeshItemDefinition>(
this->definition());
if (!def)
return false;
return def->isExtensible();
}
//----------------------------------------------------------------------------
bool MeshItem::setValue(const smtk::common::UUID& uuid,
const smtk::mesh::MeshSet& vals)
{
smtk::attribute::MeshItem::const_mesh_it it =
this->m_meshValues.find(uuid);
const MeshItemDefinition* def =
static_cast<const MeshItemDefinition *>(this->definition().get());
if (!def->isExtensible() && it == this->m_meshValues.end() &&
this->m_meshValues.size() >= def->numberOfRequiredValues())
{
// The maximum number of values is fixed
return false;
}
this->m_meshValues[uuid] = vals;
return true;
}
//----------------------------------------------------------------------------
bool MeshItem::appendValue(const smtk::common::UUID& uuid,
const smtk::mesh::MeshSet& vals)
{
smtk::attribute::MeshItem::const_mesh_it it =
this->m_meshValues.find(uuid);
const MeshItemDefinition* def =
static_cast<const MeshItemDefinition *>(this->definition().get());
if (!def->isExtensible() && it == this->m_meshValues.end() &&
this->m_meshValues.size() >= def->numberOfRequiredValues())
{
// The maximum number of values is fixed
return false;
}
this->m_meshValues[uuid] = smtk::mesh::set_union(
this->m_meshValues[uuid], vals);
return true;
}
//----------------------------------------------------------------------------
void MeshItem::removeValue(const smtk::common::UUID& uuid,
const smtk::mesh::MeshSet& vals)
{
const MeshItemDefinition* def =
static_cast<const MeshItemDefinition *>(this->definition().get());
smtk::attribute::MeshItem::const_mesh_it it =
this->m_meshValues.find(uuid);
if(it != this->m_meshValues.end())
{
if(!vals.is_empty()) // remove the vals from collection map
{
this->m_meshValues[uuid] = smtk::mesh::set_difference(
this->m_meshValues[uuid], vals);
}
else if(def->isExtensible())
{
this->m_meshValues.erase(it);
}
}
}
//----------------------------------------------------------------------------
smtk::mesh::MeshSet MeshItem::value(
const smtk::common::UUID& uuid) const
{
smtk::attribute::MeshItem::const_mesh_it it =
this->m_meshValues.find(uuid);
if(it != this->m_meshValues.end())
{
return it->second;
}
return smtk::mesh::MeshSet();
}
//----------------------------------------------------------------------------
void MeshItem::reset()
{
this->m_meshValues.clear();
}
//----------------------------------------------------------------------------
void MeshItem::copyFrom(ItemPtr sourceItem, CopyInfo& info)
{
// Assigns the contents to be same as sourceItem
// Assuming they have the same number of required values
Item::copyFrom(sourceItem, info);
this->reset();
MeshItemPtr sourceMeshItem =
smtk::dynamic_pointer_cast<MeshItem>(sourceItem);
this->m_meshValues.insert(sourceMeshItem->begin(),
sourceMeshItem->end());
}
//----------------------------------------------------------------------------
smtk::attribute::MeshItem::const_mesh_it MeshItem::begin() const
{
return this->m_meshValues.begin();
}
smtk::attribute::MeshItem::const_mesh_it MeshItem::end() const
{
return this->m_meshValues.end();
}
//=========================================================================
// 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_attribute_MeshItem_h
#define __smtk_attribute_MeshItem_h
#include "smtk/CoreExports.h"
#include "smtk/PublicPointerDefs.h"
#include "smtk/attribute/Item.h"
#include "smtk/mesh/MeshSet.h"
#include <string>
#include <set>
#include <map>
namespace smtk {
namespace attribute {
/**\brief Provide a way for an attribute to refer to meshsets.
*
*/
class SMTKCORE_EXPORT MeshItem : public Item
{
public:
typedef std::map<smtk::common::UUID, smtk::mesh::MeshSet >::const_iterator const_mesh_it;
smtkTypeMacro(MeshItem);
virtual ~MeshItem();
virtual Item::Type type() const;
std::size_t numberOfRequiredValues() const;
bool isExtensible() const;
bool setValue(const smtk::common::UUID&, const smtk::mesh::MeshSet&);
bool appendValue(const smtk::common::UUID&, const smtk::mesh::MeshSet&);
void removeValue(const smtk::common::UUID&, const smtk::mesh::MeshSet&);
std::size_t numberOfValues() const;
smtk::mesh::MeshSet value(const smtk::common::UUID&) const;
virtual void reset();
virtual void copyFrom(
const smtk::attribute::ItemPtr sourceItem,
smtk::attribute::Item::CopyInfo& info);
const_mesh_it begin() const;
const_mesh_it end() const;
protected:
friend class MeshItemDefinition;
MeshItem(Attribute *owningAttribute, int itemPosition);
MeshItem(Item *owningItem, int position, int subGroupPosition);
virtual bool setDefinition(smtk::attribute::ConstItemDefinitionPtr vdef);
std::map<smtk::common::UUID, smtk::mesh::MeshSet >m_meshValues;
};
} // namespace attribute
} // namespace smtk
#endif // __smtk_attribute_MeshItem_h
//=========================================================================
// 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/attribute/MeshItemDefinition.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/MeshItem.h"
using namespace smtk::attribute;
//----------------------------------------------------------------------------
MeshItemDefinition::
MeshItemDefinition(const std::string &myName):
ItemDefinition(myName)
{
this->m_numberOfRequiredValues = 0;
this->m_isExtensible = false;
}
//----------------------------------------------------------------------------
MeshItemDefinition::~MeshItemDefinition()
{
}
//----------------------------------------------------------------------------
Item::Type MeshItemDefinition::type() const
{
return Item::MESH_ENTITY;
}
/// Return the number of values (mesh entities) required by this definition.
std::size_t MeshItemDefinition::numberOfRequiredValues() const
{
return this->m_numberOfRequiredValues;
}
/// Set the number of values (model entities) required by this definition. Use 0 when there is no requirement.
void MeshItemDefinition::setNumberOfRequiredValues(std::size_t esize)
{
if (esize == this->m_numberOfRequiredValues)
{
return;
}
this->m_numberOfRequiredValues = esize;
}
//----------------------------------------------------------------------------
bool MeshItemDefinition::isValueValid(const smtk::mesh::MeshSet &val) const
{
return !val.is_empty(); // should we allow empty meshset?
}
//----------------------------------------------------------------------------
smtk::attribute::ItemPtr MeshItemDefinition::buildItem(
Attribute *owningAttribute, int itemPosition) const
{
return smtk::attribute::ItemPtr(new MeshItem(owningAttribute,
itemPosition));
}
//----------------------------------------------------------------------------
smtk::attribute::ItemPtr MeshItemDefinition::buildItem(
Item *owningItem, int itemPosition, int subGroupPosition) const
{
return smtk::attribute::ItemPtr(new MeshItem(owningItem,
itemPosition,
subGroupPosition));
}
//----------------------------------------------------------------------------
smtk::attribute::ItemDefinitionPtr
smtk::attribute::MeshItemDefinition::
createCopy(smtk::attribute::ItemDefinition::CopyInfo& info) const
{
(void)info;
smtk::attribute::MeshItemDefinitionPtr newDef =
smtk::attribute::MeshItemDefinition::New(this->name());
ItemDefinition::copyTo(newDef);
newDef->setNumberOfRequiredValues(this->numberOfRequiredValues());
newDef->setIsExtensible(m_isExtensible);
return newDef;
}
//----------------------------------------------------------------------------
//=========================================================================
// 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.
//=========================================================================
// .NAME MeshItemDefinition.h -
// .SECTION Description
// .SECTION See Also
#ifndef __smtk_attribute_MeshItemDefinition_h
#define __smtk_attribute_MeshItemDefinition_h
#include "smtk/CoreExports.h"
#include "smtk/PublicPointerDefs.h"
#include "smtk/attribute/ItemDefinition.h"
#include "smtk/mesh/MeshSet.h"
namespace smtk
{
namespace attribute
{
class Attribute;
class SMTKCORE_EXPORT MeshItemDefinition:
public ItemDefinition
{
public:
smtkTypeMacro(MeshItemDefinition);
static smtk::attribute::MeshItemDefinitionPtr New(const std::string &myName)
{ return smtk::attribute::MeshItemDefinitionPtr(new MeshItemDefinition(myName));}
virtual ~MeshItemDefinition();
virtual Item::Type type() const;
std::size_t numberOfRequiredValues() const;
void setNumberOfRequiredValues(std::size_t esize);
bool isValueValid(const smtk::mesh::MeshSet &val) const;
bool isExtensible() const { return this->m_isExtensible; }
void setIsExtensible(bool extensible) { this->m_isExtensible = extensible; }
virtual smtk::attribute::ItemPtr buildItem(Attribute *owningAttribute,
int itemPosition) const;
virtual smtk::attribute::ItemPtr buildItem(Item *owningItem,
int position,
int subGroupPosition) const;
virtual smtk::attribute::ItemDefinitionPtr
createCopy(smtk::attribute::ItemDefinition::CopyInfo& info) const;
protected:
MeshItemDefinition(const std::string &myName);
std::size_t m_numberOfRequiredValues;
bool m_isExtensible;
};
}
}
#endif /* __smtk_attribute_MeshItemDefinition_h */
......@@ -32,6 +32,8 @@
#include "smtk/attribute/System.h"
#include "smtk/attribute/StringItem.h"
#include "smtk/attribute/StringItemDefinition.h"
#include "smtk/attribute/MeshItem.h"
#include "smtk/attribute/MeshItemDefinition.h"
#include "smtk/attribute/MeshSelectionItem.h"
#include "smtk/attribute/MeshSelectionItemDefinition.h"
#include "smtk/attribute/ModelEntityItem.h"
......@@ -847,6 +849,10 @@ void XmlDocV1Parser::processDefinition(xml_node &defNode)
idef = def->addItemDefinition<smtk::attribute::MeshSelectionItemDefinition>(itemName);
this->processMeshSelectionDef(node, smtk::dynamic_pointer_cast<smtk::attribute::MeshSelectionItemDefinition>(idef));
break;
case smtk::attribute::Item::MESH_ENTITY:
idef = def->addItemDefinition<smtk::attribute::MeshItemDefinition>(itemName);
this->processMeshEntityDef(node, smtk::dynamic_pointer_cast<smtk::attribute::MeshItemDefinition>(idef));
break;
default:
smtkErrorMacro(this->m_logger, "Unsupported Item definition Type: "
<< node.name()
......@@ -1029,7 +1035,15 @@ void XmlDocV1Parser::processMeshSelectionDef(pugi::xml_node &node,
smtkWarningMacro(this->m_logger,
"The Mesh Selection defs should only be availabe starting Attribute Version 2 Format"
<< idef->name());
return;
}
//----------------------------------------------------------------------------
void XmlDocV1Parser::processMeshEntityDef(pugi::xml_node &node,
attribute::MeshItemDefinitionPtr idef)
{
(void)node;
smtkWarningMacro(this->m_logger,
"The Mesh Entity defs should only be availabe starting Attribute Version 2 Format"
<< idef->name());
}
//----------------------------------------------------------------------------
......@@ -1239,6 +1253,17 @@ void XmlDocV1Parser::processValueDef(pugi::xml_node &node,
smtkErrorMacro(this->m_logger, "Item definition " << citemName << " already exists");
}
break;
case smtk::attribute::Item::MESH_ENTITY:
if( (cidef = idef->addItemDefinition<smtk::attribute::MeshItemDefinition>(citemName)) )
{
this->processMeshEntityDef(cinode,
smtk::dynamic_pointer_cast<smtk::attribute::MeshItemDefinition>(cidef));
}
else
{
smtkErrorMacro(this->m_logger, "Item definition " << citemName << " already exists");
}
break;
default:
smtkErrorMacro(this->m_logger, "Unsupported Item definition Type: "
<< cinode.name()
......@@ -1605,6 +1630,18 @@ void XmlDocV1Parser::processGroupDef(pugi::xml_node &node,
}
this->processItemDef(child, idef);
break;
case smtk::attribute::Item::MESH_ENTITY:
idef = def->addItemDefinition<smtk::attribute::MeshItemDefinition>(itemName);
if (!idef)
{
smtkErrorMacro(this->m_logger,
"Failed to create String Item definition Type: " << child.name()
<< " needed to create Group Definition: " << def->name());
continue;
}
this->processMeshEntityDef(child,
smtk::dynamic_pointer_cast<smtk::attribute::MeshItemDefinition>(idef));
break;
default:
smtkErrorMacro(this->m_logger,
"Unsupported Item definition Type: " << child.name()
......@@ -1839,6 +1876,9 @@ void XmlDocV1Parser::processItem(xml_node &node,
case smtk::attribute::Item::MESH_SELECTION:
this->processMeshSelectionItem(node, smtk::dynamic_pointer_cast<smtk::attribute::MeshSelectionItem>(item));
break;
case smtk::attribute::Item::MESH_ENTITY:
this->processMeshEntityItem(node, smtk::dynamic_pointer_cast<smtk::attribute::MeshItem>(item));
break;
case smtk::attribute::Item::VOID:
// Nothing to do!
break;
......@@ -2168,6 +2208,15 @@ void XmlDocV1Parser::processModelEntityItem(pugi::xml_node &node,
//----------------------------------------------------------------------------
void XmlDocV1Parser::processMeshSelectionItem(pugi::xml_node &node,
attribute::MeshSelectionItemPtr item)
{
(void)node;
smtkWarningMacro(this->m_logger,
"All Mesh Selection Items will be ignored for Attribute Version 1 Format"
<< item->name());
}