SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
14 #ifndef smtk_attribute_Attribute_h
15 #define smtk_attribute_Attribute_h
17 #include "smtk/CoreExports.h"
19 #include "smtk/resource/Component.h"
21 #include "smtk/attribute/CopyAssignmentOptions.h"
22 #include "smtk/attribute/ReferenceItem.h"
23 #include "smtk/attribute/SearchStyle.h"
24 #include "smtk/attribute/ValueItem.h"
26 #include "smtk/common/Deprecation.h"
27 #include "smtk/common/UUID.h"
65 return lhs->name() < rhs->name();
72 auto left = lhs.lock();
77 auto right = rhs.lock();
82 return left->name() < right->name();
87 const std::string& myName,
98 return static_pointer_cast<Attribute>(Component::shared_from_this());
101 std::shared_ptr<const Attribute> shared_from_this()
const
103 return static_pointer_cast<const Attribute>(Component::shared_from_this());
107 std::string
name()
const override {
return m_name; }
109 const std::string& type()
const;
110 std::vector<std::string> types()
const;
114 const double* color()
const;
115 void setColor(
double r,
double g,
double b,
double alpha);
116 void setColor(
const double* l_color)
118 this->setColor(l_color[0], l_color[1], l_color[2], l_color[3]);
120 bool isColorSet()
const {
return m_isColorSet; }
121 void unsetColor() { m_isColorSet =
false; }
130 unsigned int advanceLevel(
int mode = 0)
const;
131 void setLocalAdvanceLevel(
int mode,
unsigned int level);
132 unsigned int localAdvanceLevel(
int mode = 0)
const
134 return (mode == 1 ? m_localAdvanceLevel[1] : m_localAdvanceLevel[0]);
139 void unsetLocalAdvanceLevel(
int mode = 0);
142 bool hasLocalAdvanceLevelInfo(
int mode = 0)
const
144 return (mode == 1 ? m_hasLocalAdvanceLevelInfo[1] : m_hasLocalAdvanceLevelInfo[0]);
147 const std::vector<smtk::attribute::ItemPtr>& items()
const {
return m_items; }
152 : (static_cast<unsigned int>(ith) >= m_items.size() ?
smtk::attribute::
ItemPtr()
153 : m_items[static_cast<std::size_t>(ith)]);
167 itemAtPath(
const std::string& path,
const std::string& sep =
"/",
bool activeOnly =
false)
const;
169 itemAtPath(
const std::string& path,
const std::string& sep =
"/",
bool activeOnly =
false);
172 typename T::ConstPtr itemAtPathAs(
173 const std::string& path,
174 const std::string& sep =
"/",
175 bool activeOnly =
false)
const;
178 itemAtPathAs(
const std::string& path,
const std::string& sep =
"/",
bool activeOnly =
false);
183 SMTK_DEPRECATED_IN_24_11(
"Use Item::path() instead.")
184 std::
string itemPath(const
ItemPtr& item, const std::
string& sep = "/") const;
190 std::
size_t numberOfItems()
const {
return m_items.size(); }
211 std::function<
bool(
typename T::value_type)> test,
212 bool activeChildren =
true);
244 T entityRefsAs(
const std::string& name)
const;
269 T associatedModelEntities()
const;
272 T associatedObjects()
const;
289 const CopyAssignmentOptions& options = CopyAssignmentOptions());
293 const CopyAssignmentOptions& options,
308 void detachItemsFromOwningResource();
321 bool removeAllAssociations(
bool partialRemovalOk =
false);
333 bool appliesToBoundaryNodes()
const {
return m_appliesToBoundaryNodes; }
334 void setAppliesToBoundaryNodes(
bool appliesValue) { m_appliesToBoundaryNodes = appliesValue; }
335 bool appliesToInteriorNodes()
const {
return m_appliesToInteriorNodes; }
336 void setAppliesToInteriorNodes(
bool appliesValue) { m_appliesToInteriorNodes = appliesValue; }
348 bool isValid(
bool useActiveCategories =
true)
const;
349 bool isValid(
const std::set<std::string>& categories)
const;
360 bool requestCatagories =
true,
361 bool includeReadAccess =
false,
362 unsigned int readAccessLevel = 0)
const;
369 m_userData[key] = value;
395 bool canEvaluate()
const;
399 bool doesEvalaute()
const;
403 std::unique_ptr<smtk::attribute::Evaluator> createEvaluator()
const;
417 const std::string& units()
const;
420 const std::string&
localUnits()
const {
return m_localUnits; }
430 bool setLocalUnits(
const std::string& newUnits);
435 bool supportsUnits()
const;
454 std::unique_lock<std::mutex> m_guard;
469 const std::string& myName,
476 void removeAllItems();
482 void setName(
const std::string& newname) { m_name = newname; }
488 std::vector<smtk::attribute::ItemPtr>
m_items;
494 std::map<std::string, smtk::simulation::UserDataPtr>
m_userData;
502 bool m_hasLocalAdvanceLevelInfo[2];
503 unsigned int m_localAdvanceLevel[2];
509 std::map<std::string, smtk::simulation::UserDataPtr>::const_iterator it =
m_userData.find(key);
513 inline void Attribute::setColor(
double r,
double g,
double b,
double a)
523 T Attribute::entityRefsAs(
const std::string& iname)
const
532 for (
auto it = itm->begin(); it != itm->end(); ++it)
539 typename T::value_type entry = std::dynamic_pointer_cast<smtk::model::Entity>(*it);
542 result.insert(result.end(), entry);
549 T Attribute::associatedObjects()
const
564 auto entry = std::dynamic_pointer_cast<typename T::value_type::element_type>(*it);
567 result.insert(result.end(), entry);
589 typename T::value_type entry = std::dynamic_pointer_cast<smtk::model::Entity>(*it);
592 result.insert(result.end(), entry);
604 return smtk::dynamic_pointer_cast<T>(this->
itemAtPath(path, sep, activeOnly));
611 return smtk::dynamic_pointer_cast<const T>(this->
itemAtPath(path, sep, activeOnly));
615 typename T::Ptr Attribute::findAs(
const std::string& iname,
SearchStyle style)
617 return smtk::dynamic_pointer_cast<T>(this->
find(iname, style));
621 typename T::ConstPtr Attribute::findAs(
const std::string& iname,
SearchStyle style)
const
623 return smtk::dynamic_pointer_cast<const T>(this->
find(iname, style));
629 std::function<
bool(
typename T::value_type)> test,
633 std::function<void(
ItemPtr,
bool)> visitor =
635 typename T::value_type testItem =
636 smtk::dynamic_pointer_cast<typename T::value_type::element_type>(item);
638 if (testItem && test(testItem))
640 filtered.insert(filtered.end(), testItem);
643 item->visitChildren(visitor, activeChildrenLocal);
646 for (std::size_t index = 0; index < this->numberOfItems(); ++index)
648 visitor(this->item(
static_cast<int>(index)), activeChildren);
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
const std::string & localUnits() const
Return the units locally set on the attribute.
Definition: Attribute.h:420
Stores the definition of an attribute.
Definition: Definition.h:47
smtk::shared_ptr< smtk::attribute::Definition > DefinitionPtr
Definition: PublicPointerDefs.h:457
smtk::attribute::DefinitionPtr m_definition
Returns true if the attribute is valid.
Definition: Attribute.h:490
SearchStyle
How should searches for items be conducted?
Definition: SearchStyle.h:24
smtk::shared_ptr< smtk::attribute::FileItem > FileItemPtr
Definition: PublicPointerDefs.h:506
double m_color[4]
Returns true if the attribute is valid.
Definition: Attribute.h:499
smtk::shared_ptr< const smtk::attribute::ComponentItem > ConstComponentItemPtr
Definition: PublicPointerDefs.h:601
smtk::shared_ptr< smtk::simulation::UserData > UserDataPtr
Definition: PublicPointerDefs.h:678
std::set< smtk::common::UUID > UUIDs
Definition: PublicPointerDefs.h:31
smtk::shared_ptr< const smtk::attribute::ModelEntityItem > ConstModelEntityItemPtr
Definition: PublicPointerDefs.h:586
smtk::shared_ptr< smtk::attribute::ComponentItem > ComponentItemPtr
Definition: PublicPointerDefs.h:546
smtk::shared_ptr< const smtk::attribute::GroupItem > ConstGroupItemPtr
Definition: PublicPointerDefs.h:574
bool m_appliesToInteriorNodes
Returns true if the attribute is valid.
Definition: Attribute.h:492
void clearAllUserData()
Returns true if the attribute is valid.
Definition: Attribute.h:373
void resetId(const smtk::common::UUID &newId)
This allows the resource to change an Attribute ID.
Definition: Attribute.h:485
bool m_isColorSet
Returns true if the attribute is valid.
Definition: Attribute.h:493
std::vector< smtk::attribute::ItemPtr > m_items
Returns true if the attribute is valid.
Definition: Attribute.h:488
Log messages for later presentation to a user or a file.
Definition: Logger.h:94
smtk::shared_ptr< smtk::attribute::GroupItem > GroupItemPtr
Definition: PublicPointerDefs.h:514
smtk::attribute::ItemPtr find(const std::string &name, SearchStyle style=RECURSIVE_ACTIVE)
Return the item with the given inName, searching in the given style.
Definition: Attribute.cxx:902
Definition: Attribute.h:437
std::string m_localUnits
Returns true if the attribute is valid.
Definition: Attribute.h:504
bool m_appliesToBoundaryNodes
Returns true if the attribute is valid.
Definition: Attribute.h:491
The ComponentLinks class is a component-specific API for manipulating unidirectional links from a com...
Definition: ComponentLinks.h:40
bool isAboutToBeDeleted() const
Returns true if the attribute is valid.
Definition: Attribute.h:375
smtk::shared_ptr< smtk::attribute::StringItem > StringItemPtr
Definition: PublicPointerDefs.h:523
bool m_aboutToBeDeleted
Returns true if the attribute is valid.
Definition: Attribute.h:498
smtk::shared_ptr< const smtk::attribute::ResourceItem > ConstResourceItemPtr
Definition: PublicPointerDefs.h:596
smtk::shared_ptr< smtk::attribute::ResourceItem > ResourceItemPtr
Definition: PublicPointerDefs.h:542
smtk::shared_ptr< const smtk::attribute::StringItem > ConstStringItemPtr
Definition: PublicPointerDefs.h:582
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.
Definition: Attribute.h:627
const common::UUID & id() const override
Returns true if the attribute is valid.
Definition: Attribute.h:377
smtk::attribute::ConstItemPtr itemAtPath(const std::string &path, const std::string &sep="/", bool activeOnly=false) const
Find an item via its path with respects to the attribute.
Definition: Attribute.cxx:188
smtk::shared_ptr< const smtk::attribute::ReferenceItem > ConstReferenceItemPtr
Definition: PublicPointerDefs.h:591
void clearUserData(const std::string &key)
Returns true if the attribute is valid.
Definition: Attribute.h:372
void setIncludeIndex(std::size_t index)
Returns true if the attribute is valid.
Definition: Attribute.h:388
T::ConstPtr itemAtPathAs(const std::string &path, const std::string &sep="/", bool activeOnly=false) const
Find an item via its path with respects to the attribute.
Definition: Attribute.h:609
#define smtkTypeMacro(...)
Add typedefs to a class for identifcation.
Definition: SharedFromThis.h:128
smtk::shared_ptr< smtk::attribute::IntItem > IntItemPtr
Definition: PublicPointerDefs.h:519
smtk::common::UUID m_id
Returns true if the attribute is valid.
Definition: Attribute.h:500
void setName(const std::string &newname)
Returns true if the attribute is valid.
Definition: Attribute.h:482
smtk::shared_ptr< smtk::attribute::DirectoryItem > DirectoryItemPtr
Definition: PublicPointerDefs.h:498
smtk::shared_ptr< smtk::attribute::Attribute > AttributePtr
Definition: PublicPointerDefs.h:463
smtk::shared_ptr< const smtk::attribute::DateTimeItem > ConstDateTimeItemPtr
Definition: PublicPointerDefs.h:551
@ RECURSIVE_ACTIVE
Recursively search for an active item.
Definition: SearchStyle.h:32
smtk::shared_ptr< smtk::attribute::ReferenceItem > ReferenceItemPtr
Definition: PublicPointerDefs.h:538
smtk::shared_ptr< smtk::attribute::ModelEntityItem > ModelEntityItemPtr
Definition: PublicPointerDefs.h:527
smtk::shared_ptr< const smtk::attribute::Item > ConstItemPtr
Definition: PublicPointerDefs.h:476
smtk::shared_ptr< smtk::attribute::VoidItem > VoidItemPtr
Definition: PublicPointerDefs.h:534
Store information about attribute definitions and instances.
Definition: Resource.h:78
smtk::shared_ptr< smtk::attribute::DateTimeItem > DateTimeItemPtr
Definition: PublicPointerDefs.h:494
#define smtkSuperclassMacro(...)
Add a typedef to the superclass of this class.
Definition: SharedFromThis.h:147
Represent a (possibly composite) value according to a definition.
Definition: Attribute.h:50
Represents the category constraints associated with an Attribute, Attribute Definition,...
Definition: Categories.h:33
T associatedModelEntities() const
Return a container of associated entityref-subclass instances.
Definition: Attribute.h:574
smtk::shared_ptr< const smtk::attribute::DoubleItem > ConstDoubleItemPtr
Definition: PublicPointerDefs.h:561
smtk::shared_ptr< smtk::attribute::DoubleItem > DoubleItemPtr
Definition: PublicPointerDefs.h:502
std::size_t includeIndex() const
Returns true if the attribute is valid.
Definition: Attribute.h:390
ReferenceItemPtr m_associatedObjects
Returns true if the attribute is valid.
Definition: Attribute.h:489
std::map< std::string, smtk::simulation::UserDataPtr > m_userData
Returns true if the attribute is valid.
Definition: Attribute.h:494
void addItem(smtk::attribute::ItemPtr &iPtr)
Returns true if the attribute is valid.
Definition: Attribute.h:481
Component is the base class for records stored in an smtk::resource::Resource.
Definition: Component.h:43
smtk::shared_ptr< smtk::resource::PersistentObject > PersistentObjectPtr
Definition: PublicPointerDefs.h:292
std::string name() const override
Return the name of the object - by default it will return the UUID but that can be overridden.
Definition: Attribute.h:107
smtk::shared_ptr< const smtk::attribute::FileItem > ConstFileItemPtr
Definition: PublicPointerDefs.h:565
smtk::shared_ptr< smtk::attribute::Item > ItemPtr
Definition: PublicPointerDefs.h:474
std::size_t m_includeIndex
Returns true if the attribute is valid.
Definition: Attribute.h:501
smtk::shared_ptr< const smtk::attribute::IntItem > ConstIntItemPtr
Definition: PublicPointerDefs.h:578
smtk::shared_ptr< const smtk::attribute::VoidItem > ConstVoidItemPtr
Definition: PublicPointerDefs.h:606
Definition: Attribute.h:59
smtk::weak_ptr< smtk::attribute::Attribute > WeakAttributePtr
Definition: PublicPointerDefs.h:467
smtk::simulation::UserDataPtr userData(const std::string &key) const
Returns true if the attribute is valid.
Definition: Attribute.h:507
std::set< smtk::model::EntityRef > EntityRefs
Definition: PublicPointerDefs.h:162
void setUserData(const std::string &key, smtk::simulation::UserDataPtr value)
Returns true if the attribute is valid.
Definition: Attribute.h:367
std::string m_name
Returns true if the attribute is valid.
Definition: Attribute.h:487
A lightweight entityref pointing to a model entity's resource.
Definition: EntityRef.h:112
smtk::shared_ptr< const smtk::attribute::DirectoryItem > ConstDirectoryItemPtr
Definition: PublicPointerDefs.h:556
smtk::shared_ptr< smtk::attribute::Resource > ResourcePtr
Definition: PublicPointerDefs.h:611
smtk::shared_ptr< smtk::resource::Resource > ResourcePtr
Definition: PublicPointerDefs.h:302