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,
94 const std::string& myName,
101 ~Attribute()
override;
105 return static_pointer_cast<Attribute>(Component::shared_from_this());
108 std::shared_ptr<const Attribute> shared_from_this()
const
110 return static_pointer_cast<const Attribute>(Component::shared_from_this());
114 std::string
name()
const override {
return m_name; }
116 const std::string& type()
const;
117 std::vector<std::string> types()
const;
121 const double* color()
const;
122 void setColor(
double r,
double g,
double b,
double alpha);
123 void setColor(
const double* l_color)
125 this->setColor(l_color[0], l_color[1], l_color[2], l_color[3]);
127 bool isColorSet()
const {
return m_isColorSet; }
128 void unsetColor() { m_isColorSet =
false; }
137 unsigned int advanceLevel(
int mode = 0)
const;
138 void setLocalAdvanceLevel(
int mode,
unsigned int level);
139 unsigned int localAdvanceLevel(
int mode = 0)
const
141 return (mode == 1 ? m_localAdvanceLevel[1] : m_localAdvanceLevel[0]);
146 void unsetLocalAdvanceLevel(
int mode = 0);
149 bool hasLocalAdvanceLevelInfo(
int mode = 0)
const
151 return (mode == 1 ? m_hasLocalAdvanceLevelInfo[1] : m_hasLocalAdvanceLevelInfo[0]);
154 const std::vector<smtk::attribute::ItemPtr>& items()
const {
return m_items; }
159 : (static_cast<unsigned int>(ith) >= m_items.size() ?
smtk::attribute::
ItemPtr()
160 : m_items[static_cast<std::size_t>(ith)]);
174 itemAtPath(
const std::string& path,
const std::string& sep =
"/",
bool activeOnly =
false)
const;
176 itemAtPath(
const std::string& path,
const std::string& sep =
"/",
bool activeOnly =
false);
179 typename T::ConstPtr itemAtPathAs(
180 const std::string& path,
181 const std::string& sep =
"/",
182 bool activeOnly =
false)
const;
185 itemAtPathAs(
const std::string& path,
const std::string& sep =
"/",
bool activeOnly =
false);
190 SMTK_DEPRECATED_IN_NEXT(
"Use Item::path() instead.")
191 std::
string itemPath(const
ItemPtr& item, const std::
string& sep = "/") const;
197 std::
size_t numberOfItems()
const {
return m_items.size(); }
218 std::function<
bool(
typename T::value_type)> test,
219 bool activeChildren =
true);
251 T entityRefsAs(
const std::string& name)
const;
276 T associatedModelEntities()
const;
279 T associatedObjects()
const;
296 const CopyAssignmentOptions& options = CopyAssignmentOptions());
300 const CopyAssignmentOptions& options,
315 void detachItemsFromOwningResource();
328 bool removeAllAssociations(
bool partialRemovalOk =
false);
340 bool appliesToBoundaryNodes()
const {
return m_appliesToBoundaryNodes; }
341 void setAppliesToBoundaryNodes(
bool appliesValue) { m_appliesToBoundaryNodes = appliesValue; }
342 bool appliesToInteriorNodes()
const {
return m_appliesToInteriorNodes; }
343 void setAppliesToInteriorNodes(
bool appliesValue) { m_appliesToInteriorNodes = appliesValue; }
349 bool isValid(
bool useActiveCategories =
true)
const;
350 bool isValid(
const std::set<std::string>& categories)
const;
361 bool requestCatagories =
true,
362 bool includeReadAccess =
false,
363 unsigned int readAccessLevel = 0)
const;
370 m_userData[key] = value;
373 void clearUserData(
const std::string& key) { m_userData.erase(key); }
374 void clearAllUserData() { m_userData.clear(); }
376 bool isAboutToBeDeleted()
const {
return m_aboutToBeDeleted; }
388 void setIncludeIndex(std::size_t index) { m_includeIndex = index; }
390 std::size_t includeIndex()
const {
return m_includeIndex; }
395 bool canEvaluate()
const;
399 bool doesEvalaute()
const;
403 std::unique_ptr<smtk::attribute::Evaluator> createEvaluator()
const;
422 std::unique_lock<std::mutex> m_guard;
437 const std::string& myName,
445 void removeAllItems();
451 void setName(
const std::string& newname) { m_name = newname; }
454 std::vector<smtk::attribute::ItemPtr> m_items;
457 bool m_appliesToBoundaryNodes;
458 bool m_appliesToInteriorNodes;
460 std::map<std::string, smtk::simulation::UserDataPtr> m_userData;
464 bool m_aboutToBeDeleted;
467 std::size_t m_includeIndex;
468 bool m_hasLocalAdvanceLevelInfo[2];
469 unsigned int m_localAdvanceLevel[2];
474 std::map<std::string, smtk::simulation::UserDataPtr>::const_iterator it = m_userData.find(key);
478 inline void Attribute::setColor(
double r,
double g,
double b,
double a)
488 T Attribute::entityRefsAs(
const std::string& iname)
const
497 for (
auto it = itm->begin(); it != itm->end(); ++it)
504 typename T::value_type entry = std::dynamic_pointer_cast<smtk::model::Entity>(*it);
507 result.insert(result.end(), entry);
514 T Attribute::associatedObjects()
const
517 if (!m_associatedObjects)
522 for (
auto it = m_associatedObjects->begin(); it != m_associatedObjects->end(); ++it)
529 auto entry = std::dynamic_pointer_cast<typename T::value_type::element_type>(*it);
532 result.insert(result.end(), entry);
542 if (!m_associatedObjects)
547 for (
auto it = m_associatedObjects->begin(); it != m_associatedObjects->end(); ++it)
554 typename T::value_type entry = std::dynamic_pointer_cast<smtk::model::Entity>(*it);
557 result.insert(result.end(), entry);
569 return smtk::dynamic_pointer_cast<T>(this->
itemAtPath(path, sep, activeOnly));
576 return smtk::dynamic_pointer_cast<const T>(this->
itemAtPath(path, sep, activeOnly));
580 typename T::Ptr Attribute::findAs(
const std::string& iname,
SearchStyle style)
582 return smtk::dynamic_pointer_cast<T>(this->
find(iname, style));
586 typename T::ConstPtr Attribute::findAs(
const std::string& iname,
SearchStyle style)
const
588 return smtk::dynamic_pointer_cast<const T>(this->
find(iname, style));
594 std::function<
bool(
typename T::value_type)> test,
598 std::function<void(
ItemPtr,
bool)> visitor =
600 typename T::value_type testItem =
601 smtk::dynamic_pointer_cast<typename T::value_type::element_type>(item);
603 if (testItem && test(testItem))
605 filtered.insert(filtered.end(), testItem);
608 item->visitChildren(visitor, activeChildrenLocal);
611 for (std::size_t index = 0; index < this->numberOfItems(); ++index)
613 visitor(this->item(
static_cast<int>(index)), activeChildren);
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
Stores the definition of an attribute.
Definition: Definition.h:45
smtk::shared_ptr< smtk::attribute::Definition > DefinitionPtr
Definition: PublicPointerDefs.h:457
SearchStyle
How should searches for items be conducted?
Definition: SearchStyle.h:24
smtk::shared_ptr< smtk::attribute::FileItem > FileItemPtr
Definition: PublicPointerDefs.h:506
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
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:904
Definition: Attribute.h:405
The ComponentLinks class is a component-specific API for manipulating unidirectional links from a com...
Definition: ComponentLinks.h:40
smtk::shared_ptr< smtk::attribute::StringItem > StringItemPtr
Definition: PublicPointerDefs.h:523
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:592
const common::UUID & id() const override
Return a unique identifier for the object which will be persistent across sessions.
Definition: Attribute.h:378
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:191
smtk::shared_ptr< const smtk::attribute::ReferenceItem > ConstReferenceItemPtr
Definition: PublicPointerDefs.h:591
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:574
#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::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
bool setId(const common::UUID &uid) override
Assign an ID to this object (used by readers; not for arbitrary reuse).
Definition: Attribute.h:379
@ 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:76
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:32
T associatedModelEntities() const
Return a container of associated entityref-subclass instances.
Definition: Attribute.h:539
smtk::shared_ptr< const smtk::attribute::DoubleItem > ConstDoubleItemPtr
Definition: PublicPointerDefs.h:561
smtk::shared_ptr< smtk::attribute::DoubleItem > DoubleItemPtr
Definition: PublicPointerDefs.h:502
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:114
smtk::shared_ptr< const smtk::attribute::FileItem > ConstFileItemPtr
Definition: PublicPointerDefs.h:565
smtk::shared_ptr< smtk::attribute::Item > ItemPtr
Definition: PublicPointerDefs.h:474
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
std::set< smtk::model::EntityRef > EntityRefs
Definition: PublicPointerDefs.h:162
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