Commit 13e2e2fa authored by Yumin Yuan's avatar Yumin Yuan
Browse files

Adding descriptive phrases for meshes

parent 95d73a1a
......@@ -124,6 +124,8 @@ namespace smtk
class Loop;
typedef std::vector<smtk::model::Loop> Loops;
class Entity;
class MeshPhrase;
class MeshListPhrase;
class Model;
class Operator;
class PropertyValuePhrase;
......@@ -220,6 +222,8 @@ namespace smtk
typedef smtk::weak_ptr< smtk::model::DescriptivePhrase > WeakDescriptivePhrasePtr;
typedef smtk::shared_ptr< smtk::model::EntityPhrase > EntityPhrasePtr;
typedef smtk::shared_ptr< smtk::model::EntityListPhrase > EntityListPhrasePtr;
typedef smtk::shared_ptr< smtk::model::MeshPhrase > MeshPhrasePtr;
typedef smtk::shared_ptr< smtk::model::MeshListPhrase > MeshListPhrasePtr;
typedef smtk::shared_ptr< smtk::model::PropertyValuePhrase > PropertyValuePhrasePtr;
typedef smtk::shared_ptr< smtk::model::PropertyListPhrase > PropertyListPhrasePtr;
typedef smtk::shared_ptr< smtk::model::SimpleModelSubphrases > SimpleModelSubphrasesPtr;
......
......@@ -27,6 +27,8 @@ set(modelSrcs
GridInfo.cxx
Instance.cxx
Loop.cxx
MeshListPhrase.cxx
MeshPhrase.cxx
Model.cxx
Operator.cxx
PropertyListPhrase.cxx
......@@ -81,6 +83,8 @@ set(modelHeaders
Instance.h
IntegerData.h
Loop.h
MeshListPhrase.h
MeshPhrase.h
Model.h
Operator.h
PropertyType.h
......
......@@ -12,6 +12,7 @@
#include "smtk/SharedFromThis.h"
#include "smtk/model/EntityRef.h"
#include "smtk/mesh/MeshSet.h"
#include <string>
#include <vector>
......@@ -36,6 +37,8 @@ enum DescriptivePhraseType {
STRING_PROPERTY_VALUE, //!< One property of an entity has a list of string values.
INTEGER_PROPERTY_VALUE, //!< One property of an entity has a list of integer values.
ENTITY_HAS_SUBPHRASES, //!< The entity has many phrases of one type; this phrase summarizes them.
MESH_SUMMARY, //!< Summarize an mesh by displaying its name, type, and dimension.
MESH_LIST, //!< Summarize an mesh collection by displaying its name.
INVALID_DESCRIPTION //!< This is used to indicate an invalid or empty descriptive phrase.
};
......@@ -106,6 +109,9 @@ public:
virtual bool isRelatedColorMutable() const { return false; }
virtual bool setRelatedColor(const FloatList& rgba) { (void)rgba; return false; }
virtual smtk::mesh::CollectionPtr relatedMeshCollection() const { return smtk::mesh::CollectionPtr(); }
virtual smtk::mesh::MeshSet relatedMesh() const { return smtk::mesh::MeshSet(); }
unsigned int phraseId() const { return this->m_phraseId; }
SubphraseGeneratorPtr findDelegate();
......
//=========================================================================
// 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/model/MeshListPhrase.h"
#include "smtk/model/EntityPhrase.h"
namespace smtk {
namespace model {
MeshListPhrase::MeshListPhrase()
{
}
/**\brief Initialize an mesh list with an iterable container of meshes.
*
*/
MeshListPhrase::Ptr MeshListPhrase::setup(
const std::vector<smtk::mesh::MeshSet>& meshes, DescriptivePhrase::Ptr parnt)
{
this->DescriptivePhrase::setup(MESH_LIST, parnt);
for (
std::vector<smtk::mesh::MeshSet>::const_iterator it = meshes.begin();
it != meshes.end();
++it)
{
this->m_meshes.push_back(*it);
}
return shared_from_this();
}
MeshListPhrase::Ptr MeshListPhrase::setup(
const std::vector<smtk::mesh::CollectionPtr>& collections, DescriptivePhrase::Ptr parnt)
{
this->DescriptivePhrase::setup(MESH_LIST, parnt);
for (
std::vector<smtk::mesh::CollectionPtr>::const_iterator it = collections.begin();
it != collections.end();
++it)
{
this->m_collections.push_back(*it);
}
return shared_from_this();
}
/// Show the mesh name (or a default name) in the title
std::string MeshListPhrase::title()
{
std::ostringstream message;
std::size_t sz = this->m_collections.size() > 0 ?
this->m_collections.size() : this->m_meshes.size();
message << sz << " ";
std::string strDesc = this->m_collections.size() > 0 ?
"collections" : "meshsets";
this->buildSubphrases();
return message.str();
}
/// Show the entity type in the subtitle
std::string MeshListPhrase::subtitle()
{
return std::string();
}
/// The list of mehses to be presented.
std::vector<smtk::mesh::MeshSet> MeshListPhrase::relatedMeshes() const
{
return this->m_meshes;
}
std::vector<smtk::mesh::CollectionPtr> MeshListPhrase::relatedCollections() const
{
return this->m_collections;
}
} // model namespace
} // smtk namespace
//=========================================================================
// 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_model_MeshListPhrase_h
#define __smtk_model_MeshListPhrase_h
#include "smtk/model/DescriptivePhrase.h"
namespace smtk {
namespace model {
/**\brief Describe a list of meshes or collections for user presentation.
*
*/
class SMTKCORE_EXPORT MeshListPhrase : public DescriptivePhrase
{
public:
smtkTypeMacro(MeshListPhrase);
smtkSharedPtrCreateMacro(DescriptivePhrase);
Ptr setup(const std::vector<smtk::mesh::MeshSet>&,
DescriptivePhrase::Ptr parent = DescriptivePhrasePtr());
Ptr setup(const std::vector<smtk::mesh::CollectionPtr>&,
DescriptivePhrase::Ptr parent = DescriptivePhrasePtr());
virtual ~MeshListPhrase() { }
virtual std::string title();
virtual std::string subtitle();
std::vector<smtk::mesh::CollectionPtr> relatedCollections() const;
std::vector<smtk::mesh::MeshSet> relatedMeshes() const;
protected:
MeshListPhrase();
std::vector<smtk::mesh::MeshSet> m_meshes;
std::vector<smtk::mesh::CollectionPtr> m_collections;
};
} // model namespace
} // smtk namespace
#endif // __smtk_model_MeshListPhrase_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/model/MeshPhrase.h"
#include "smtk/model/CellEntity.h"
#include "smtk/model/EntityListPhrase.h"
#include "smtk/model/Group.h"
#include "smtk/model/Instance.h"
#include "smtk/model/Model.h"
#include "smtk/model/PropertyListPhrase.h"
#include "smtk/model/ShellEntity.h"
#include "smtk/model/Manager.h"
#include "smtk/model/UseEntity.h"
#include "smtk/mesh/Collection.h"
#include "smtk/mesh/MeshSet.h"
#include <sstream>
namespace smtk {
namespace model {
MeshPhrase::MeshPhrase()
{
this->m_mutability = 3; // both color and title are mutable.
}
/**\brief Prepare an MeshPhrase for display a meshset.
*/
MeshPhrase::Ptr MeshPhrase::setup(const smtk::mesh::MeshSet& mesh, DescriptivePhrase::Ptr parnt)
{
this->DescriptivePhrase::setup(MESH_SUMMARY, parnt);
this->m_relatedMesh = mesh;
this->m_mutability = 3; // both color and title are mutable by default.
return this->shared_from_this();
}
/**\brief Prepare an MeshPhrase for display a mesh collection.
*/
MeshPhrase::Ptr MeshPhrase::setup(
const smtk::mesh::CollectionPtr& meshcollection, DescriptivePhrase::Ptr parnt)
{
this->DescriptivePhrase::setup(MESH_SUMMARY, parnt);
this->m_relatedCollection = meshcollection;
this->m_mutability = 3; // both color and title are mutable by default.
return this->shared_from_this();
}
bool MeshPhrase::isCollection() const
{
return this->m_relatedCollection && this->m_relatedCollection->isValid();
}
/// Show the meshset name (or a default name) in the title
std::string MeshPhrase::title()
{
std::string strText = "no mesh";
if(this->isCollection())
{
//strText = "Meshes";
strText = this->m_relatedCollection->name().empty() ? "Meshes" : this->m_relatedCollection->name();
}
else if(!this->m_relatedMesh.is_empty())
{
// trying to use associatied model entity name
smtk::model::EntityRefArray relatedEnts = this->m_relatedMesh.modelEntities();
if(relatedEnts.size() == 1)
{
strText = relatedEnts[0].name();
}
else if(relatedEnts.size() > 1)
{
// assuming we have same dimensions in the set
if(!this->m_relatedMesh.subset(smtk::mesh::Dims3).is_empty())
{
strText = "Volumes";
}
else if(!this->m_relatedMesh.subset(smtk::mesh::Dims2).is_empty())
{
strText = "Faces";
}
else if(!this->m_relatedMesh.subset(smtk::mesh::Dims1).is_empty())
{
strText = "Edges";
}
else
{
strText = "unknown meshes";
}
}
}
return strText;
}
/// True when the meshset is valid and marked as mutable (the default, setMutability(0x1)).
bool MeshPhrase::isTitleMutable() const
{
return false;//(this->m_mutability & 0x1) && !this->m_relatedMesh.is_empty();
}
bool MeshPhrase::setTitle(const std::string& newTitle)
{
/*
// The title is the name, so set the name as long as we're allowed.
if (this->isTitleMutable() && this->m_relatedMesh.name() != newTitle)
{
if (!newTitle.empty())
this->m_relatedMesh.setName(newTitle);
else
{
this->m_relatedMesh.removeStringProperty("name");
// Don't let name be a blank... assign a default.
this->m_relatedMesh.manager()->assignDefaultName(
this->m_relatedMesh.entity());
}
return true;
}
*/
return false;
}
/// Return the meshset for additional context the UI might wish to present.
smtk::mesh::MeshSet MeshPhrase::relatedMesh() const
{
return this->m_relatedMesh;
}
smtk::mesh::CollectionPtr MeshPhrase::relatedMeshCollection() const
{
return this->m_relatedCollection;
}
/// Return a color associated with the related meshset.
FloatList MeshPhrase::relatedColor() const
{
return FloatList(4, 1.);//this->m_relatedMesh.color();
}
/// True when the entity is valid and marked as mutable (the default, setMutability(0x4)).
bool MeshPhrase::isRelatedColorMutable() const
{
return false; //(this->m_mutability & 0x4) && this->m_relatedMesh.isValid();
}
bool MeshPhrase::setRelatedColor(const FloatList& rgba)
{
/*
if (this->isRelatedColorMutable())
{
bool colorValid = rgba.size() == 4;
for (int i = 0; colorValid && i < 4; ++i)
colorValid &= (rgba[i] >= 0. && rgba[i] <= 1.);
if (colorValid)
{
this->m_relatedMesh.setColor(rgba);
return true;
}
}
*/
return false;
}
// Set bit vector indicating mutability; title (0x1), subtitle (0x2), color (0x4).
void MeshPhrase::setMutability(int whatsMutable)
{
this->m_mutability = whatsMutable;
}
} // model namespace
} // smtk namespace
//=========================================================================
// 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_model_MeshPhrase_h
#define __smtk_model_MeshPhrase_h
#include "smtk/model/DescriptivePhrase.h"
namespace smtk {
namespace model {
/**\brief Describe an meshset or collection for user presentation.
*/
class SMTKCORE_EXPORT MeshPhrase : public DescriptivePhrase
{
public:
smtkTypeMacro(MeshPhrase);
smtkSharedPtrCreateMacro(DescriptivePhrase);
Ptr setup(const smtk::mesh::MeshSet& meshset, DescriptivePhrase::Ptr parent = DescriptivePhrasePtr());
Ptr setup(const smtk::mesh::CollectionPtr& meshes, DescriptivePhrase::Ptr parent = DescriptivePhrasePtr());
virtual ~MeshPhrase() { }
virtual std::string title();
virtual bool isTitleMutable() const;
virtual bool setTitle(const std::string& newTitle);
virtual smtk::mesh::MeshSet relatedMesh() const;
virtual smtk::mesh::CollectionPtr relatedMeshCollection() const;
virtual FloatList relatedColor() const;
virtual bool isRelatedColorMutable() const;
virtual bool setRelatedColor(const FloatList& rgba);
void setMutability(int whatsMutable);
bool isCollection() const;
protected:
MeshPhrase();
smtk::mesh::MeshSet m_relatedMesh;
smtk::mesh::CollectionPtr m_relatedCollection;
int m_mutability;
};
} // model namespace
} // smtk namespace
#endif // __smtk_model_MeshPhrase_h
......@@ -150,6 +150,14 @@ DescriptivePhrases SimpleModelSubphrases::subphrases(
case INTEGER_PROPERTY_LIST:
this->childrenOfPropertyList(
dynamic_pointer_cast<PropertyListPhrase>(src), result);
case MESH_SUMMARY:
this->childrenOfMesh(
dynamic_pointer_cast<MeshPhrase>(src), result);
break;
case MESH_LIST:
this->childrenOfMeshList(
dynamic_pointer_cast<MeshListPhrase>(src), result);
break;
default:
break;
}
......@@ -286,6 +294,7 @@ void SimpleModelSubphrases::childrenOfEntity(
this->freeSubmodelsOfModel(phr, ment, result);
this->freeGroupsInModel(phr, ment, result);
this->freeCellsOfModel(phr, ment, result);
this->meshesOfModel(phr, ment, result);
}
else if (ient.isValid())
{
......@@ -316,5 +325,17 @@ void SimpleModelSubphrases::childrenOfPropertyList(
this->propertiesOfPropertyList(plist, plist->relatedPropertyType(), result);
}
void SimpleModelSubphrases::childrenOfMesh(
MeshPhrase::Ptr meshphr, DescriptivePhrases& result)
{
this->meshsetsOfMesh(meshphr, result);
}
void SimpleModelSubphrases::childrenOfMeshList(
MeshListPhrase::Ptr meshlist, DescriptivePhrases& result)
{
this->meshesOfMeshList(meshlist, result);
}
} // namespace model
} // namespace smtk
......@@ -43,6 +43,8 @@ protected:
virtual void childrenOfEntity(EntityPhrase::Ptr, DescriptivePhrases&);
virtual void childrenOfEntityList(EntityListPhrase::Ptr, DescriptivePhrases&);
virtual void childrenOfPropertyList(PropertyListPhrase::Ptr, DescriptivePhrases&);
virtual void childrenOfMesh(MeshPhrase::Ptr, DescriptivePhrases&);
virtual void childrenOfMeshList(MeshListPhrase::Ptr, DescriptivePhrases&);
bool m_abridgeUses;
};
......
......@@ -27,6 +27,10 @@
#include "smtk/model/PropertyListPhrase.h"
#include "smtk/model/PropertyValuePhrase.h"
#include "smtk/mesh/Collection.h"
#include "smtk/mesh/Manager.h"
#include "smtk/mesh/MeshSet.h"
#include <algorithm>
//required for insert_iterator on VS2010+
#include <iterator>
......@@ -287,6 +291,13 @@ void SubphraseGenerator::freeCellsOfModel(
addEntityPhrases(freeCellsInModel, src, this->directLimit(), result);
}
void SubphraseGenerator::meshesOfModel(
DescriptivePhrase::Ptr src, const Model& mod, DescriptivePhrases& result)
{
std::vector<smtk::mesh::CollectionPtr> meshCollections =
mod.manager()->meshes()->associatedCollections(mod);
addMeshPhrases(meshCollections, src, this->directLimit(), result);
}
void SubphraseGenerator::prototypeOfInstance(
DescriptivePhrase::Ptr src, const Instance& ent, DescriptivePhrases& result)
......@@ -390,5 +401,57 @@ void SubphraseGenerator::addEntityProperties(
}
}
void SubphraseGenerator::meshsetsOfMesh(
MeshPhrase::Ptr meshphr, DescriptivePhrases& result)
{
smtk::mesh::MeshSet meshes = meshphr->relatedMesh();
// if this is a mesh collection
if(meshphr->isCollection())
{
this->meshsetsOfCollectionByDim(meshphr, smtk::mesh::Dims3, result);
this->meshsetsOfCollectionByDim(meshphr, smtk::mesh::Dims2, result);
this->meshsetsOfCollectionByDim(meshphr, smtk::mesh::Dims1, result);
}
// if this is a MeshSet
else if(meshes.size() > 1)
{
// if the MeshSet contains more than one mesh, we need to create subphrases for
// each subset, otherwise the meshphr will represent the relatedMesh.
for(std::size_t i=0; i < meshes.size(); ++i)
{
result.push_back(
MeshPhrase::create()->setup(meshes.subset(i), meshphr));
}
}
}
void SubphraseGenerator::meshsetsOfCollectionByDim(
MeshPhrase::Ptr meshphr, smtk::mesh::DimensionType dim, DescriptivePhrases& result)
{
if(meshphr->isCollection())
{
smtk::mesh::CollectionPtr meshcollection = meshphr->relatedMeshCollection();
smtk::mesh::MeshSet dimMeshes = meshcollection->meshes(dim);
if(!dimMeshes.is_empty())
{
result.push_back(
MeshPhrase::create()->setup(dimMeshes, meshphr));
}
}
}
void SubphraseGenerator::meshesOfMeshList(
MeshListPhrase::Ptr src, DescriptivePhrases& result)
{
if(src->relatedCollections().size() > 0)
{
addMeshPhrases(src->relatedCollections(), src, this->directLimit(), result);
}
else if(src->relatedMeshes().size() > 0)
{
addMeshPhrases(src->relatedMeshes(), src, this->directLimit(), result);
}
}
} // namespace model
} // namespace smtk
......@@ -13,6 +13,8 @@
#include "smtk/model/DescriptivePhrase.h"
#include "smtk/model/EntityPhrase.h"
#include "smtk/model/EntityListPhrase.h"
#include "smtk/model/MeshPhrase.h"
#include "smtk/model/MeshListPhrase.h"
#include "smtk/model/PropertyListPhrase.h"
#include "smtk/model/Manager.h" // For PropertyType enum.
......@@ -85,6 +87,12 @@ protected:
void entitiesOfEntityList(EntityListPhrase::Ptr src, const EntityRefArray& ents, DescriptivePhrases& result);
void propertiesOfPropertyList(PropertyListPhrase::Ptr src, PropertyType p, DescriptivePhrases& result);
void meshesOfModel(DescriptivePhrase::Ptr src, const Model& mod, DescriptivePhrases& result);
void meshsetsOfMesh(MeshPhrase::Ptr meshphr, DescriptivePhrases& result);
void meshesOfMeshList(MeshListPhrase::Ptr src, DescriptivePhrases& result);
void meshsetsOfCollectionByDim(
MeshPhrase::Ptr meshphr, smtk::mesh::DimensionType dim, DescriptivePhrases& result);
void addEntityProperties(
PropertyType ptype, std::set<std::string>& props,
DescriptivePhrase::Ptr parent, DescriptivePhrases& result);
......@@ -92,6 +100,9 @@ protected:
template<typename T>
void addEntityPhrases(const T& ents, DescriptivePhrase::Ptr parent, int limit, DescriptivePhrases& result);
template<typename T>
void addMeshPhrases(const T& ents, DescriptivePhrase::Ptr parent, int limit, DescriptivePhrases& result);
int m_directlimit;
bool m_skipAttributes;
bool m_skipProperties;
......@@ -116,6 +127,31 @@ void SubphraseGenerator::addEntityPhrases(
}
}
/**\brief Add child MeshPhrases with an iterable container of meshes.
*
* This templated method is provided so that arrays of MeshSets or Collections
* are both accepted.
*/
template<typename T>
void SubphraseGenerator::addMeshPhrases(
const T& meshes, DescriptivePhrase::Ptr parent, int limit, DescriptivePhrases& result)
{
if (limit < 0 || static_cast<int>(meshes.size()) < limit)
{
for (typename T::const_iterator it = meshes.begin(); it != meshes.end(); ++it)
{
result.push_back(
MeshPhrase::create()->setup(*it, parent));
}
}
else
{
result.push_back(