Commit d471925f authored by David Thompson's avatar David Thompson Committed by Kitware Robot

Merge topic 'component-consequences'

c57053cd Follow through on changes required by resource inheritance.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !932
parents 8364dd7e c57053cd
......@@ -27,6 +27,10 @@ These subsystems are:
* The **simulation** (also known as the **export**) system, which is a set of utilities
that lets you convert resources (e.g., attribute, model, and mesh collections) into
an input deck for a simulation using Python scripts (or C++ if you wish).
* The **view** system provides user interface functionality that is independent of any
particular operating system or platform. It serves as a layer between the resource
system and the visual layout of resources so that multiple views of the same resources
can exist in the same application.
* A **common** system holding utility classes.
* Python **bindings** that enable SMTK to
be used *by* python scripts *and* SMTK to run python scripts as part of its normal operations.
......
......@@ -27,8 +27,8 @@ smtk_source_group(simulation)
add_subdirectory(io)
smtk_source_group(io)
#add_subdirectory(view)
#smtk_source_group(view)
add_subdirectory(view)
smtk_source_group(view)
set(smtk_headers
${commonHeaders}
......@@ -37,6 +37,7 @@ set(smtk_headers
${operationHeaders}
${meshHeaders}
${modelHeaders}
${viewHeaders}
${simulationHeaders}
${ioHeaders}
)
......@@ -47,6 +48,7 @@ set(smtk_srcs
${operationSrcs}
${meshSrcs}
${modelSrcs}
${viewSrcs}
${simulationSrcs}
${ioSrcs}
)
......
......@@ -47,6 +47,8 @@ namespace attribute
{
class Attribute;
class Collection;
class ComponentItem;
class ComponentItemDefinition;
class RefItem;
class RefItemDefinition;
class DateTimeItem;
......@@ -192,6 +194,12 @@ class VolumeUse;
typedef std::vector<smtk::model::VolumeUse> VolumeUses;
}
namespace view
{
class DescriptivePhrase;
class SubphraseGenerator;
}
namespace bridge
{
// These classes are in the SMTKRemote library, which
......@@ -236,8 +244,12 @@ typedef smtk::shared_ptr<smtk::resource::Component> ComponentPtr;
typedef std::set<smtk::resource::ComponentPtr> ComponentSet;
typedef smtk::shared_ptr<smtk::resource::SelectionManager> SelectionManagerPtr;
typedef smtk::shared_ptr<smtk::resource::Set> SetPtr;
typedef smtk::shared_ptr<const smtk::resource::Component> ConstComponentPtr;
typedef smtk::shared_ptr<const smtk::resource::Resource> ConstResourcePtr;
typedef smtk::shared_ptr<const smtk::resource::Set> ConstSetPtr;
typedef std::vector<ResourcePtr> ResourceArray;
typedef std::vector<ComponentPtr> ComponentArray;
typedef std::set<ComponentPtr> ComponentSet;
}
namespace operation
......@@ -301,6 +313,7 @@ typedef smtk::shared_ptr<smtk::model::StoredResource> StoredResourcePtr;
typedef smtk::shared_ptr<const smtk::model::StoredResource> ConstStoredResourcePtr;
typedef smtk::shared_ptr<smtk::model::Entity> EntityPtr;
typedef smtk::weak_ptr<smtk::model::Entity> WeakEntityPtr;
typedef std::vector<smtk::model::EntityPtr> EntityArray;
typedef smtk::shared_ptr<smtk::model::Arrangement> ArrangementPtr;
typedef smtk::weak_ptr<smtk::model::Arrangement> WeakArrangementPtr;
typedef smtk::shared_ptr<smtk::model::Tessellation> TessellationPtr;
......@@ -367,6 +380,8 @@ typedef smtk::shared_ptr<const smtk::attribute::ModelEntityItemDefinition>
typedef smtk::shared_ptr<smtk::attribute::ModelEntityItemDefinition> ModelEntityItemDefinitionPtr;
typedef smtk::shared_ptr<smtk::attribute::VoidItem> VoidItemPtr;
typedef smtk::shared_ptr<smtk::attribute::VoidItemDefinition> VoidItemDefinitionPtr;
typedef smtk::shared_ptr<smtk::attribute::ComponentItem> ComponentItemPtr;
typedef smtk::shared_ptr<smtk::attribute::ComponentItemDefinition> ComponentItemDefinitionPtr;
typedef smtk::shared_ptr<const smtk::attribute::DateTimeItem> ConstDateTimeItemPtr;
typedef smtk::shared_ptr<const smtk::attribute::DateTimeItemDefinition>
......@@ -395,6 +410,9 @@ typedef smtk::shared_ptr<const smtk::attribute::MeshSelectionItemDefinition>
typedef smtk::shared_ptr<const smtk::attribute::ModelEntityItem> ConstModelEntityItemPtr;
typedef smtk::shared_ptr<const smtk::attribute::ModelEntityItemDefinition>
ConstModelEntityItemDefinitionPtr;
typedef smtk::shared_ptr<const smtk::attribute::ComponentItem> ConstComponentItemPtr;
typedef smtk::shared_ptr<const smtk::attribute::ComponentItemDefinition>
ConstComponentItemDefinitionPtr;
typedef smtk::shared_ptr<const smtk::attribute::VoidItem> ConstVoidItemPtr;
typedef smtk::shared_ptr<const smtk::attribute::VoidItemDefinition> ConstVoidItemDefinitionPtr;
typedef smtk::shared_ptr<const smtk::attribute::RefItem> ConstRefItemPtr;
......@@ -405,6 +423,15 @@ typedef smtk::shared_ptr<const smtk::attribute::Collection> ConstCollectionPtr;
typedef smtk::weak_ptr<smtk::attribute::Collection> WeakCollectionPtr;
}
namespace view
{
typedef smtk::shared_ptr<smtk::view::DescriptivePhrase> DescriptivePhrasePtr;
typedef smtk::weak_ptr<smtk::view::DescriptivePhrase> WeakDescriptivePhrasePtr;
typedef std::vector<DescriptivePhrasePtr> DescriptivePhrases;
typedef smtk::shared_ptr<smtk::view::SubphraseGenerator> SubphraseGeneratorPtr;
typedef smtk::weak_ptr<smtk::view::SubphraseGenerator> WeakSubphraseGeneratorPtr;
}
namespace bridge
{
namespace remote
......
......@@ -352,6 +352,16 @@ bool Attribute::removeExpungedEntities(const smtk::model::EntityRefs& expungedEn
return associationChanged;
}
bool Attribute::isComponentAssociated(const smtk::common::UUID& entity) const
{
return m_associatedComponents ? m_associatedComponents->has(entity) : false;
}
bool Attribute::isComponentAssociated(const smtk::resource::ComponentPtr& comp) const
{
return m_associatedComponents ? m_associatedComponents->has(comp) : false;
}
/**\brief Is the model \a entity associated with this attribute?
*
*/
......@@ -652,3 +662,12 @@ smtk::attribute::ConstDateTimeItemPtr Attribute::findDateTime(const std::string&
{
return smtk::dynamic_pointer_cast<const DateTimeItem>(this->find(nameStr));
}
smtk::attribute::ComponentItemPtr Attribute::findComponent(const std::string& nameStr)
{
return smtk::dynamic_pointer_cast<ComponentItem>(this->find(nameStr));
}
smtk::attribute::ConstComponentItemPtr Attribute::findComponent(const std::string& nameStr) const
{
return smtk::dynamic_pointer_cast<const ComponentItem>(this->find(nameStr));
}
......@@ -18,6 +18,7 @@
#include "smtk/PublicPointerDefs.h"
#include "smtk/resource/Component.h"
#include "smtk/attribute/ComponentItem.h"
#include "smtk/attribute/GroupItem.h"
#include "smtk/attribute/ModelEntityItem.h"
#include "smtk/attribute/SearchStyle.h"
......@@ -70,12 +71,12 @@ public:
}
// NOTE: To rename an attribute use the collection!
const std::string& name() const { return this->m_name; }
const std::string& name() const { return m_name; }
const std::string& type() const;
std::vector<std::string> types() const;
bool isA(smtk::attribute::DefinitionPtr def) const;
smtk::attribute::DefinitionPtr definition() const { return this->m_definition; }
smtk::attribute::DefinitionPtr definition() const { return m_definition; }
const double* color() const;
void setColor(double r, double g, double b, double alpha);
......@@ -83,18 +84,18 @@ public:
{
this->setColor(l_color[0], l_color[1], l_color[2], l_color[3]);
}
bool isColorSet() const { return this->m_isColorSet; }
void unsetColor() { this->m_isColorSet = false; }
bool isColorSet() const { return m_isColorSet; }
void unsetColor() { m_isColorSet = false; }
bool isMemberOf(const std::string& category) const;
bool isMemberOf(const std::vector<std::string>& categories) const;
smtk::attribute::ItemPtr item(int ith) const
{
return (ith < 0) ? smtk::attribute::ItemPtr()
: (static_cast<unsigned int>(ith) >= this->m_items.size()
? smtk::attribute::ItemPtr()
: this->m_items[static_cast<std::size_t>(ith)]);
return (ith < 0)
? smtk::attribute::ItemPtr()
: (static_cast<unsigned int>(ith) >= m_items.size() ? smtk::attribute::ItemPtr()
: m_items[static_cast<std::size_t>(ith)]);
}
smtk::attribute::ConstItemPtr itemAtPath(
......@@ -109,7 +110,7 @@ public:
smtk::attribute::ItemPtr find(const std::string& name, SearchStyle style = ACTIVE_CHILDREN);
smtk::attribute::ConstItemPtr find(
const std::string& name, SearchStyle style = ACTIVE_CHILDREN) const;
std::size_t numberOfItems() const { return this->m_items.size(); }
std::size_t numberOfItems() const { return m_items.size(); }
template <typename T>
typename T::Ptr findAs(const std::string& name, SearchStyle style = ACTIVE_CHILDREN);
......@@ -163,10 +164,19 @@ public:
DateTimeItemPtr findDateTime(const std::string& name);
ConstDateTimeItemPtr findDateTime(const std::string& name) const;
ComponentItemPtr findComponent(const std::string& name);
ConstComponentItemPtr findComponent(const std::string& name) const;
void references(std::vector<smtk::attribute::ItemPtr>& list) const;
ConstModelEntityItemPtr associations() const { return this->m_associations; }
ModelEntityItemPtr associations() { return this->m_associations; }
ConstComponentItemPtr associatedComponents() const { return m_associatedComponents; }
ComponentItemPtr associatedComponents() { return m_associatedComponents; }
bool isComponentAssociated(const smtk::common::UUID& uid) const;
bool isComponentAssociated(const smtk::resource::ComponentPtr& componentPtr) const;
ConstModelEntityItemPtr associations() const { return m_associations; }
ModelEntityItemPtr associations() { return m_associations; }
bool isEntityAssociated(const smtk::common::UUID& entity) const;
bool isEntityAssociated(const smtk::model::EntityRef& entityref) const;
......@@ -197,16 +207,10 @@ public:
// These methods only applies to Attributes whose
// definition returns true for isNodal()
bool appliesToBoundaryNodes() const { return this->m_appliesToBoundaryNodes; }
void setAppliesToBoundaryNodes(bool appliesValue)
{
this->m_appliesToBoundaryNodes = appliesValue;
}
bool appliesToInteriorNodes() const { return this->m_appliesToInteriorNodes; }
void setAppliesToInteriorNodes(bool appliesValue)
{
this->m_appliesToInteriorNodes = appliesValue;
}
bool appliesToBoundaryNodes() const { return m_appliesToBoundaryNodes; }
void setAppliesToBoundaryNodes(bool appliesValue) { m_appliesToBoundaryNodes = appliesValue; }
bool appliesToInteriorNodes() const { return m_appliesToInteriorNodes; }
void setAppliesToInteriorNodes(bool appliesValue) { m_appliesToInteriorNodes = appliesValue; }
bool isValid() const;
......@@ -216,13 +220,13 @@ public:
void setUserData(const std::string& key, smtk::simulation::UserDataPtr value)
{
this->m_userData[key] = value;
m_userData[key] = value;
}
smtk::simulation::UserDataPtr userData(const std::string& key) const;
void clearUserData(const std::string& key) { this->m_userData.erase(key); }
void clearAllUserData() { this->m_userData.clear(); }
void clearUserData(const std::string& key) { m_userData.erase(key); }
void clearAllUserData() { m_userData.clear(); }
bool isAboutToBeDeleted() const { return this->m_aboutToBeDeleted; }
bool isAboutToBeDeleted() const { return m_aboutToBeDeleted; }
common::UUID id() const override { return m_id; }
......@@ -232,29 +236,27 @@ protected:
Attribute(const std::string& myName, smtk::attribute::DefinitionPtr myDefinition);
void removeAllItems();
void addItem(smtk::attribute::ItemPtr iPtr) { this->m_items.push_back(iPtr); }
void setName(const std::string& newname) { this->m_name = newname; }
void addItem(smtk::attribute::ItemPtr iPtr) { m_items.push_back(iPtr); }
void setName(const std::string& newname) { m_name = newname; }
void addReference(smtk::attribute::RefItem* attRefItem, std::size_t pos)
{
this->m_references[attRefItem].insert(pos);
m_references[attRefItem].insert(pos);
}
// This removes a specific ref item
void removeReference(smtk::attribute::RefItem* attRefItem, std::size_t pos)
{
this->m_references[attRefItem].erase(pos);
m_references[attRefItem].erase(pos);
}
// This removes all references to a specific Ref Item
void removeReference(smtk::attribute::RefItem* attRefItem)
{
this->m_references.erase(attRefItem);
}
void removeReference(smtk::attribute::RefItem* attRefItem) { m_references.erase(attRefItem); }
void setId(const common::UUID& myID) override { m_id = myID; }
std::string m_name;
std::vector<smtk::attribute::ItemPtr> m_items;
ModelEntityItemPtr m_associations;
ComponentItemPtr m_associatedComponents;
smtk::attribute::DefinitionPtr m_definition;
std::map<smtk::attribute::RefItem*, std::set<std::size_t> > m_references;
bool m_appliesToBoundaryNodes;
......@@ -271,18 +273,17 @@ protected:
inline smtk::simulation::UserDataPtr Attribute::userData(const std::string& key) const
{
std::map<std::string, smtk::simulation::UserDataPtr>::const_iterator it =
this->m_userData.find(key);
return ((it == this->m_userData.end()) ? smtk::simulation::UserDataPtr() : it->second);
std::map<std::string, smtk::simulation::UserDataPtr>::const_iterator it = m_userData.find(key);
return ((it == m_userData.end()) ? smtk::simulation::UserDataPtr() : it->second);
}
inline void Attribute::setColor(double r, double g, double b, double a)
{
this->m_isColorSet = true;
this->m_color[0] = r;
this->m_color[1] = g;
this->m_color[2] = b;
this->m_color[3] = a;
m_isColorSet = true;
m_color[0] = r;
m_color[1] = g;
m_color[2] = b;
m_color[3] = a;
}
template <typename T>
......@@ -311,13 +312,13 @@ template <typename T>
T Attribute::associatedModelEntities() const
{
T result;
if (!this->m_associations)
if (!m_associations)
{
return result;
}
smtk::model::EntityRefArray::const_iterator it;
for (it = this->m_associations->begin(); it != this->m_associations->end(); ++it)
for (it = m_associations->begin(); it != m_associations->end(); ++it)
{
typename T::value_type entry(*it);
if (entry.isValid())
......
set(attributeHeaders
Attribute.h
ComponentItem.h
ComponentItemDefinition.h
Definition.h
DateTimeItem.h
DateTimeItemDefinition.h
......@@ -39,6 +41,8 @@ set(attributeHeaders
set(attributeSrcs
Attribute.cxx
ComponentItem.cxx
ComponentItemDefinition.cxx
DateTimeItem.cxx
DateTimeItemDefinition.cxx
Definition.cxx
......
//=========================================================================
// 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/ComponentItem.h"
#include "smtk/attribute/ComponentItemDefinition.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/Collection.h"
using namespace smtk::attribute;
ComponentItem::ComponentItem(Attribute* owningAttribute, int itemPosition)
: Item(owningAttribute, itemPosition)
{
}
ComponentItem::ComponentItem(Item* inOwningItem, int itemPosition, int mySubGroupPosition)
: Item(inOwningItem, itemPosition, mySubGroupPosition)
{
}
ComponentItem::~ComponentItem()
{
}
Item::Type ComponentItem::type() const
{
return COMPONENT;
}
bool ComponentItem::isValid() const
{
if (!this->isEnabled())
{
return true;
}
// Do we have at least the number of required values present?
if (this->numberOfValues() < this->numberOfRequiredValues())
{
return false;
}
for (auto it = this->m_values.begin(); it != this->m_values.end(); ++it)
{
// If the pointer is NULL then it's unset:
if (!(*it))
{
return false;
}
}
return true;
}
std::size_t ComponentItem::numberOfValues() const
{
return this->m_values.size();
}
bool ComponentItem::setNumberOfValues(std::size_t newSize)
{
// If the current size is the same just return
if (this->numberOfValues() == newSize)
{
return true;
}
// Next - are we allowed to change the number of values?
const ComponentItemDefinition* def =
static_cast<const ComponentItemDefinition*>(this->definition().get());
if (!def->isExtensible())
return false; // You may not resize.
// Next - are we within the prescribed limits?
std::size_t n = def->numberOfRequiredValues();
if (newSize < n)
return false; // The number of values requested is too small.
n = def->maxNumberOfValues();
if (n > 0 && newSize > n)
return false; // The number of values requested is too large.
this->m_values.resize(newSize);
return true;
}
smtk::attribute::ConstComponentItemDefinitionPtr ComponentItem::definition() const
{
smtk::attribute::ConstComponentItemDefinitionPtr ptr =
smtk::dynamic_pointer_cast<const smtk::attribute::ComponentItemDefinition>(this->m_definition);
return ptr;
}
std::size_t ComponentItem::numberOfRequiredValues() const
{
const ComponentItemDefinition* def =
static_cast<const ComponentItemDefinition*>(this->m_definition.get());
if (def == NULL)
{
return 0;
}
return def->numberOfRequiredValues();
}
smtk::resource::ComponentPtr ComponentItem::value(std::size_t i) const
{
if (i >= static_cast<std::size_t>(this->m_values.size()))
return smtk::resource::ComponentPtr();
auto result = this->m_values[i];
return result;
}
bool ComponentItem::setValue(smtk::resource::ComponentPtr val)
{
return this->setValue(0, val);
}
bool ComponentItem::setValue(std::size_t i, smtk::resource::ComponentPtr val)
{
const ComponentItemDefinition* def =
static_cast<const ComponentItemDefinition*>(this->definition().get());
if (i < this->m_values.size() && def->isValueValid(val))
{
this->m_values[i] = val;
return true;
}
return false;
}
bool ComponentItem::appendValue(smtk::resource::ComponentPtr val)
{
// First - is this value valid?
const ComponentItemDefinition* def =
static_cast<const ComponentItemDefinition*>(this->definition().get());
if (!def->isValueValid(val))
{
return false;
}
// Second - is the value already in the item?
std::size_t emptyIndex, n = this->numberOfValues();
bool foundEmpty = false;
for (std::size_t i = 0; i < n; ++i)
{
if (this->isSet(i) && (this->value(i) == val))
{
return true;
}
if (!this->isSet(i))
{
foundEmpty = true;
emptyIndex = i;
}
}
// If not, was there a space available?
if (foundEmpty)
{
return this->setValue(emptyIndex, val);
}
// Finally - are we allowed to change the number of values?
if ((def->isExtensible() && def->maxNumberOfValues() &&
this->m_values.size() >= def->maxNumberOfValues()) ||
(!def->isExtensible() && this->m_values.size() >= def->numberOfRequiredValues()))
{
// The number of values is fixed or we reached the max number of items
return false;
}
this->m_values.push_back(val);
return true;
}
bool ComponentItem::removeValue(std::size_t i)
{
//First - are we allowed to change the number of values?
const ComponentItemDefinition* def =
static_cast<const ComponentItemDefinition*>(this->definition().get());
if (!def->isExtensible())
{
return this->setValue(i, smtk::resource::ComponentPtr()); // The number of values is fixed
}
this->m_values.erase(this->m_values.begin() + i);
return true;
}
void ComponentItem::reset()
{
this->m_values.clear();
if (this->numberOfRequiredValues() > 0)
this->m_values.resize(this->numberOfRequiredValues());
}
std::string ComponentItem::valueAsString() const
{
return this->valueAsString(0);
}
std::string ComponentItem::valueAsString(std::size_t i) const
{
smtk::resource::ComponentPtr val = this->value(i);
std::ostringstream str;
str << "[" << val->resource()->id() << "," << val->id() << "]";
return str.str();
}
bool ComponentItem::isSet(std::size_t i) const
{
return i < this->m_values.size() ? !!this->m_values[i] : false;
}
void ComponentItem::unset(std::size_t i)
{
this->setValue(i, smtk::resource::ComponentPtr());
}
bool ComponentItem::assign(ConstItemPtr& sourceItem, unsigned int options)
{
// Cast input pointer to ComponentItem
smtk::shared_ptr<const ComponentItem> sourceComponentItem =
smtk::dynamic_pointer_cast<const ComponentItem>(sourceItem);
if (!sourceComponentItem)
{
return false; // Source is not a model entity item
}
// Are we suppose to assign the model enity values?
if (options & Item::IGNORE_RESOURCE_COMPONENTS)
{
return Item::assign(sourceItem, options);
}
// Update values
// Only set values if both att collections are using the same model
this->setNumberOfValues(sourceComponentItem->numberOfValues());
for (std::size_t i = 0; i < sourceComponentItem->numberOfValues(); ++i)
{
if (sourceComponentItem->isSet(i))
{
smtk::resource::ComponentPtr val = sourceComponentItem->value(i);
this->setValue(i, val);
}
else
{
this->unset(i);
}
}
return Item::assign(sourceItem, options);
}
bool ComponentItem::isExtensible() const
{
smtk::attribute::ConstComponentItemDefinitionPtr def =
smtk::dynamic_pointer_cast<const ComponentItemDefinition>(this->definition());
if (!def)
return false;
return def->isExtensible();
}
bool ComponentItem::has(const smtk::common::UUID& entity) const
{
return this->find(entity) >= 0;
}
bool ComponentItem::has(smtk::resource::ComponentPtr entity) const
{
return this->find(entity) >= 0;
}
smtk::resource::ComponentArray::const_iterator ComponentItem::begin() const
{
return this->m_values.begin();
}
smtk::resource::ComponentArray::const_iterator ComponentItem::end() const
{
return this->m_values.end();
}
std::ptrdiff_t ComponentItem::find(const smtk::common::UUID& uid) const
{
std::ptrdiff_t idx = 0;
smtk::resource::ComponentArray::const_iterator it;
for (it = this->begin(); it != this->end(); ++it, ++idx)
{
if ((*it)->id() == uid)
{
return idx;
}
}
return -1;
}
std::ptrdiff_t ComponentItem::find(smtk::resource::ComponentPtr comp) const
{
std::ptrdiff_t idx = 0;
smtk::resource::ComponentArray::const_iterator it;
for (it = this->begin(); it != this->end(); ++it, ++idx)
{
if (*it == comp)
{
return idx;
}
}
return -1;
}
bool ComponentItem::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 ComponentItemDefinition* def = dynamic_cast<const ComponentItemDefinition*>(adef.get());
// Call the parent's set definition - similar to constructor calls
// we call from base to derived
if