SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
smtk::attribute::Attribute Class Reference

Represent a (possibly composite) value according to a definition. More...

#include <Attribute.h>

Inheritance diagram for smtk::attribute::Attribute:
[legend]
Collaboration diagram for smtk::attribute::Attribute:
[legend]

Classes

struct  CompareByName
 
class  GuardedLinks
 

Public Member Functions

 smtkTypeMacro (smtk::attribute::Attribute)
 
AttributePtr shared_from_this ()
 
std::shared_ptr< const Attributeshared_from_this () const
 
std::string name () const override
 Return the name of the object - by default it will return the UUID but that can be overridden.
 
const std::string & type () const
 
std::vector< std::string > types () const
 
bool isA (const smtk::attribute::DefinitionPtr &def) const
 
const smtk::attribute::DefinitionPtrdefinition () const
 
const double * color () const
 
void setColor (double r, double g, double b, double alpha)
 
void setColor (const double *l_color)
 
bool isColorSet () const
 
void unsetColor ()
 
unsigned int advanceLevel (int mode=0) const
 Get the Attribute 's advance level. More...
 
void setLocalAdvanceLevel (int mode, unsigned int level)
 
unsigned int localAdvanceLevel (int mode=0) const
 
void unsetLocalAdvanceLevel (int mode=0)
 
bool hasLocalAdvanceLevelInfo (int mode=0) const
 
const std::vector< smtk::attribute::ItemPtr > & items () const
 
smtk::attribute::ItemPtr item (int ith) const
 
smtk::attribute::ItemPtr find (const std::string &name, SearchStyle style=RECURSIVE_ACTIVE)
 Return the item with the given inName, searching in the given style. More...
 
smtk::attribute::ConstItemPtr find (const std::string &name, SearchStyle style=RECURSIVE_ACTIVE) const
 
std::size_t numberOfItems () const
 
template<typename T >
T::Ptr findAs (const std::string &name, SearchStyle style=RECURSIVE_ACTIVE)
 
template<typename T >
T::ConstPtr findAs (const std::string &name, SearchStyle style=RECURSIVE_ACTIVE) const
 
template<typename T >
void filterItems (T &values, std::function< bool(typename T::value_type)> test, bool activeChildren=true)
 Given a container, filter items in the attribute by a lambda function. More...
 
IntItemPtr findInt (const std::string &name)
 
ConstIntItemPtr findInt (const std::string &name) const
 
DoubleItemPtr findDouble (const std::string &name)
 
ConstDoubleItemPtr findDouble (const std::string &name) const
 
StringItemPtr findString (const std::string &name)
 
ConstStringItemPtr findString (const std::string &name) const
 
FileItemPtr findFile (const std::string &name)
 
ConstFileItemPtr findFile (const std::string &name) const
 
DirectoryItemPtr findDirectory (const std::string &name)
 
ConstDirectoryItemPtr findDirectory (const std::string &name) const
 
GroupItemPtr findGroup (const std::string &name)
 
ConstGroupItemPtr findGroup (const std::string &name) const
 
ModelEntityItemPtr findModelEntity (const std::string &name)
 
ConstModelEntityItemPtr findModelEntity (const std::string &name) const
 
VoidItemPtr findVoid (const std::string &name)
 
ConstVoidItemPtr findVoid (const std::string &name) const
 
DateTimeItemPtr findDateTime (const std::string &name)
 
ConstDateTimeItemPtr findDateTime (const std::string &name) const
 
ReferenceItemPtr findReference (const std::string &name)
 
ConstReferenceItemPtr findReference (const std::string &name) const
 
template<typename T >
entityRefsAs (const std::string &name) const
 
ResourceItemPtr findResource (const std::string &name)
 
ConstResourceItemPtr findResource (const std::string &name) const
 
ComponentItemPtr findComponent (const std::string &name)
 
ConstComponentItemPtr findComponent (const std::string &name) const
 
ConstReferenceItemPtr associatedObjects () const
 
ReferenceItemPtr associatedObjects ()
 
bool isObjectAssociated (const smtk::common::UUID &uid) const
 
bool isObjectAssociated (const smtk::resource::PersistentObjectPtr &componentPtr) const
 
bool canBeAssociated (const smtk::resource::PersistentObjectPtr &obj) const
 
bool canBeDisassociated (const smtk::resource::PersistentObjectPtr &obj, AttributePtr &probAtt) const
 
ConstReferenceItemPtr associations () const
 
ReferenceItemPtr associations ()
 
bool isEntityAssociated (const smtk::common::UUID &entity) const
 Is the model entity associated with this attribute? More...
 
bool isEntityAssociated (const smtk::model::EntityRef &entityref) const
 Is the model entity of the entityref associated with this attribute? More...
 
smtk::common::UUIDs associatedModelEntityIds () const
 Return the associated model entities as a set of UUIDs.
 
template<typename T >
associatedModelEntities () const
 Return a container of associated entityref-subclass instances. More...
 
template<typename T >
associatedObjects () const
 
bool associate (smtk::resource::PersistentObjectPtr obj)
 
bool associateEntity (const smtk::common::UUID &entity)
 Associate a new-style model ID (a UUID) with this attribute. More...
 
bool associateEntity (const smtk::model::EntityRef &entity)
 Associate a new-style model ID (a EntityRef) with this attribute. More...
 
void disassociateEntity (const smtk::common::UUID &entity, bool reverse=true)
 Disassociate a new-style model ID (a UUID) from this attribute. More...
 
void disassociateEntity (const smtk::model::EntityRef &entity, bool reverse=true)
 Disassociate a new-style model entity (a EntityRef) from this attribute.
 
bool disassociate (smtk::resource::PersistentObjectPtr obj, AttributePtr &probAtt, bool reverse=true)
 Disassociate attribute from an object. More...
 
bool disassociate (smtk::resource::PersistentObjectPtr obj, bool reverse=true)
 Disassociate attribute from an object. Returns true if successful.
 
bool assign (const AttributePtr &sourceAtt, const CopyAssignmentOptions &options=CopyAssignmentOptions())
 
bool assign (const AttributePtr &sourceAtt, const CopyAssignmentOptions &options, smtk::io::Logger &logger)
 
void detachItemsFromOwningResource ()
 Sever dependencies between items and the owning resource. More...
 
bool removeAllAssociations (bool partialRemovalOk=false)
 Remove all associations of this attribute with model entities. More...
 
bool removeExpungedEntities (const smtk::model::EntityRefs &expungedEnts)
 Remove expunged Entities from attribute. More...
 
bool appliesToBoundaryNodes () const
 
void setAppliesToBoundaryNodes (bool appliesValue)
 
bool appliesToInteriorNodes () const
 
void setAppliesToInteriorNodes (bool appliesValue)
 
const smtk::attribute::Categoriescategories () const
 The categories that the attribute applies to. More...
 
bool isValid (bool useActiveCategories=true) const
 Validate the attribute against its definition. More...
 
bool isValid (const std::set< std::string > &categories) const
 
bool isRelevant (bool includeCategories=true, bool includeReadAccess=false, unsigned int readAccessLevel=0) const
 Returns true if the attribute is relevant. More...
 
smtk::attribute::ResourcePtr attributeResource () const
 
const smtk::resource::ResourcePtr resource () const override
 Components are required to return their owning resource (if any). More...
 
void setUserData (const std::string &key, smtk::simulation::UserDataPtr value)
 
smtk::simulation::UserDataPtr userData (const std::string &key) const
 
void clearUserData (const std::string &key)
 
void clearAllUserData ()
 
bool isAboutToBeDeleted () const
 
const common::UUIDid () const override
 Return a unique identifier for the object which will be persistent across sessions.
 
bool setId (const common::UUID &uid) override
 Assign an ID to this object (used by readers; not for arbitrary reuse). More...
 
void setIncludeIndex (std::size_t index)
 
std::size_t includeIndex () const
 
bool canEvaluate () const
 
bool doesEvalaute () const
 
std::unique_ptr< smtk::attribute::EvaluatorcreateEvaluator () const
 
const GuardedLinks guardedLinks () const
 
GuardedLinks guardedLinks ()
 
smtk::attribute::ConstItemPtr itemAtPath (const std::string &path, const std::string &seps="/", bool activeOnly=false) const
 Find an item via its path with respects to the attribute. More...
 
smtk::attribute::ItemPtr itemAtPath (const std::string &path, const std::string &seps="/", bool activeOnly=false)
 Find an item via its path with respects to the attribute. More...
 
template<typename T >
T::ConstPtr itemAtPathAs (const std::string &path, const std::string &seps="/", bool activeOnly=false) const
 Find an item via its path with respects to the attribute. More...
 
template<typename T >
T::Ptr itemAtPathAs (const std::string &path, const std::string &seps="/", bool activeOnly=false)
 Return an item given its path, converted to a given pointer type.
 
std::string itemPath (const ItemPtr &item, const std::string &seps="/") const
 Formats the full path to the item with respect to the attribute.
 
- Public Member Functions inherited from smtk::resource::Component
 smtkTypeMacro (smtk::resource::Component)
 
 smtkSuperclassMacro (smtk::resource::PersistentObject)
 
 smtkSharedFromThisMacro (smtk::resource::PersistentObject)
 
virtual ResourceparentResource () const
 Return a raw (not shared) pointer to the resource that owns this component. More...
 
template<typename ResourceType >
ResourceType * parentResourceAs () const
 This variant of parentResource casts the result to the given ResourceType.
 
Linkslinks () override
 Return the links that connect this component to external resources/components.
 
const Linkslinks () const override
 
Propertiesproperties () override
 Return properties defined on this component.
 
const Propertiesproperties () const override
 
- Public Member Functions inherited from smtk::resource::PersistentObject
 smtkTypeMacroBase (smtk::resource::PersistentObject)
 
template<typename T >
T::Ptr as ()
 Attempt to cast this object to a subclass.
 
template<typename T >
T::ConstPtr as () const
 Attempt to cast this object to a subclass.
 

Static Public Member Functions

static smtk::attribute::AttributePtr New (const std::string &myName, const smtk::attribute::DefinitionPtr &myDefinition)
 
static smtk::attribute::AttributePtr New (const std::string &myName, const smtk::attribute::DefinitionPtr &myDefinition, const smtk::common::UUID &myId)
 

Protected Member Functions

 Attribute (const std::string &myName, const smtk::attribute::DefinitionPtr &myDefinition, const smtk::common::UUID &myId)
 
 Attribute (const std::string &myName, const smtk::attribute::DefinitionPtr &myDefinition)
 
void build ()
 Constructs the attribute from its definition.
 
void removeAllItems ()
 
void forceDisassociate (smtk::resource::PersistentObjectPtr)
 Used to disassociate an attribute from an object without checking constraints. More...
 
void addItem (smtk::attribute::ItemPtr &iPtr)
 
void setName (const std::string &newname)
 

Protected Attributes

std::string m_name
 
std::vector< smtk::attribute::ItemPtrm_items
 
ReferenceItemPtr m_associatedObjects
 
smtk::attribute::DefinitionPtr m_definition
 
bool m_appliesToBoundaryNodes
 
bool m_appliesToInteriorNodes
 
bool m_isColorSet
 
std::map< std::string, smtk::simulation::UserDataPtrm_userData
 
bool m_aboutToBeDeleted
 
double m_color [4]
 
smtk::common::UUID m_id
 
std::size_t m_includeIndex
 
bool m_hasLocalAdvanceLevelInfo [2]
 
unsigned int m_localAdvanceLevel [2]
 

Friends

class smtk::attribute::Definition
 
class smtk::attribute::Resource
 

Additional Inherited Members

- Public Types inherited from smtk::resource::Component
typedef std::function< void(const ComponentPtr &)> Visitor
 
typedef detail::ComponentLinks Links
 
typedef detail::ComponentProperties Properties
 

Detailed Description

Represent a (possibly composite) value according to a definition.

Member Function Documentation

◆ advanceLevel()

unsigned int Attribute::advanceLevel ( int  mode = 0) const

Get the Attribute 's advance level.

if mode is 1 then the write access level is returned; else the read access level is returned The information can either be specificied directly to the attribute using setLocalAdvanceLevel() or from the attributes's definition. NOTE: This information is used in GUI only

◆ associatedModelEntities()

template<typename T >
T smtk::attribute::Attribute::associatedModelEntities

Return a container of associated entityref-subclass instances.

This method returns a container (usually a std::vector or std::set) of entityref-subclass instances (e.g., Edge, EdgeUse, Loop) that are associated with this attribute.

Note that if you request a container of EntityRef entities, you will obtain all of the associated model entities. However, if you request a container of some subclass, only entities of that type will be returned. For example, if an attribute is associated with two faces, an edge, a group, and a shell, calling associatedModelEntities<EntityRefs>() will return 5 EntityRef entries while associatedModelEntities<CellEntities>() will return 3 entries (2 faces and 1 edge) since the other entities do not construct valid CellEntity instances.

◆ associateEntity() [1/2]

bool Attribute::associateEntity ( const smtk::common::UUID objId)

Associate a new-style model ID (a UUID) with this attribute.

This function returns true when the association is valid and successful. It will return false if the association is prohibited.

◆ associateEntity() [2/2]

bool Attribute::associateEntity ( const smtk::model::EntityRef entityRef)

Associate a new-style model ID (a EntityRef) with this attribute.

This function returns true when the association is valid and successful. It may return false if the association is prohibited. (This is not currently implemented.)

◆ categories()

const smtk::attribute::Categories & Attribute::categories ( ) const

The categories that the attribute applies to.

Typically a category will be a simulation type like heat transfer, fluid flow, etc.

◆ detachItemsFromOwningResource()

void Attribute::detachItemsFromOwningResource ( )

Sever dependencies between items and the owning resource.

Some items implicitly interact with the parent resource to store and retrieve data (e.g. ReferenceItem uses links to retrieve references). For items with this type of relationship with the owning resource, this method disables those routines, forcing the item (and, therefore, the containing attribute) to satisfy its API without using the owning resource. This is useful when an attribute has been removed from its parent resource and is still held by ancillary routines (i.e. when the attribute is expunged and Operation observers are inspecting expunged resources).

◆ disassociate()

bool Attribute::disassociate ( smtk::resource::PersistentObjectPtr  obj,
AttributePtr probAtt,
bool  reverse = true 
)

Disassociate attribute from an object.

Returns true if successful, else it will set probAtt to attribute using this as a prerequisite

◆ disassociateEntity()

void Attribute::disassociateEntity ( const smtk::common::UUID entity,
bool  reverse = true 
)

Disassociate a new-style model ID (a UUID) from this attribute.

If reverse is true (the default), then the model resource is notified of the item's disassociation immediately after its removal from this attribute, allowing the model and attribute to stay in sync.

◆ filterItems()

template<typename T >
void smtk::attribute::Attribute::filterItems ( T &  values,
std::function< bool(typename T::value_type)>  test,
bool  activeChildren = true 
)

Given a container, filter items in the attribute by a lambda function.

Parameters
valuesa container which holds items
testa lambda function which would be applied on children items Example filter double and int items [](Item::Ptr item) { return item->type() == DoubleType || item->type() == IntType; } Example filter modelEntity items [](ModelEntity::Ptr item) { return true; }
activeChildrena flag indicates whether it should be applied to active children only or not

◆ find()

smtk::attribute::ItemPtr Attribute::find ( const std::string &  inName,
SearchStyle  style = RECURSIVE_ACTIVE 
)

Return the item with the given inName, searching in the given style.

The search style dictates whether children of conditional items are included and, if so, whether all of their children are searched or just the active children. The default is to search active children.

◆ forceDisassociate()

void Attribute::forceDisassociate ( smtk::resource::PersistentObjectPtr  obj)
protected

Used to disassociate an attribute from an object without checking constraints.

Typical use is either when all attributes are being disassociated from the same object or if the attribute is being deleted.

◆ isEntityAssociated() [1/2]

bool Attribute::isEntityAssociated ( const smtk::common::UUID entity) const

Is the model entity associated with this attribute?

◆ isEntityAssociated() [2/2]

bool Attribute::isEntityAssociated ( const smtk::model::EntityRef entityref) const

Is the model entity of the entityref associated with this attribute?

◆ isRelevant()

bool Attribute::isRelevant ( bool  includeCategories = true,
bool  includeReadAccess = false,
unsigned int  readAccessLevel = 0 
) const

Returns true if the attribute is relevant.

If includeCatagories is true and the attribute does not pass it's category checks with respects to the resource's active category settings then return false, If includeReadAccess is true, and if all of the items in the attribute have their advanceLevel > readAccessLevel then return false. Else return true.

◆ isValid()

bool Attribute::isValid ( bool  useActiveCategories = true) const

Validate the attribute against its definition.

This method will only return true when every (required) item in the attribute is set and considered a valid value by its definition. This can be used to ensure that an attribute is in a good state before using it to perform some operation.

If useActiveCategories is true and if the resource has active categories enabled, then the resource's active categories will be taken into consideration

◆ itemAtPath() [1/2]

smtk::attribute::ItemPtr Attribute::itemAtPath ( const std::string &  path,
const std::string &  seps = "/",
bool  activeOnly = false 
)

Find an item via its path with respects to the attribute.

Return an item given a string specifying a path to it.

If activeOnly is true then all items in the path must active (with repsect to a parent ValueItem) else nullptr will be returned. This parameter will have no effect on other types of items. Note that the path should not start with a separator character.

◆ itemAtPath() [2/2]

smtk::attribute::ConstItemPtr Attribute::itemAtPath ( const std::string &  path,
const std::string &  seps = "/",
bool  activeOnly = false 
) const

Find an item via its path with respects to the attribute.

Return an item given a string specifying a path to it.

If activeOnly is true then all items in the path must active (with repsect to a parent ValueItem) else nullptr will be returned. This parameter will have no effect on other types of items. Note that the path should not start with a separator character.

◆ itemAtPathAs()

template<typename T >
T::ConstPtr smtk::attribute::Attribute::itemAtPathAs ( const std::string &  path,
const std::string &  seps = "/",
bool  activeOnly = false 
) const

Find an item via its path with respects to the attribute.

Return an item given a string specifying a path to it.

If activeOnly is true then all items in the path must active (with repsect to a parent ValueItem) else nullptr will be returned. This parameter will have no effect on other types of items. Note that the path should not start with a separator character.

◆ removeAllAssociations()

bool Attribute::removeAllAssociations ( bool  partialRemovalOk = false)

Remove all associations of this attribute with model entities.

When dealing with prerequisite constraints it may not be possible to remove all associations. If partialRemovalOk is true, then all associations that can be removed all. If false, then associations are only removed iff all can be removed. Note that this may reset the associations. If there are any default associations, they will be present but typically there are none.

◆ removeExpungedEntities()

bool Attribute::removeExpungedEntities ( const smtk::model::EntityRefs expungedEnts)

Remove expunged Entities from attribute.

Update attribute when entities has been expunged Note it would check associations and every modelEntityItem.

Parameters
expungedEntsa set of expunged entities
Returns
if association or modelEntityItem has been updated, return true. (then operator widget should update its UI)

◆ resource()

const smtk::resource::ResourcePtr Attribute::resource ( ) const
overridevirtual

Components are required to return their owning resource (if any).

Components may not have an owning resource at some points in their lifecycle, so be sure to verify the returned value is non-null.

Implements smtk::resource::Component.

◆ setId()

bool smtk::attribute::Attribute::setId ( const common::UUID myID)
inlineoverridevirtual

Assign an ID to this object (used by readers; not for arbitrary reuse).

TODO: care must be taken to modify the recorded ID in all links that connect to this object (see Resource::setId and its treatment of manager registration for reference).

Implements smtk::resource::PersistentObject.


The documentation for this class was generated from the following files: