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/UUID.h"
62 return lhs->name() < rhs->name();
69 auto left = lhs.lock();
74 auto right = rhs.lock();
79 return left->name() < right->name();
84 const std::string& myName,
91 const std::string& myName,
98 ~Attribute()
override;
102 return static_pointer_cast<Attribute>(Component::shared_from_this());
105 std::shared_ptr<const Attribute> shared_from_this()
const
107 return static_pointer_cast<const Attribute>(Component::shared_from_this());
111 std::string
name()
const override {
return m_name; }
113 const std::string& type()
const;
114 std::vector<std::string> types()
const;
118 const double* color()
const;
119 void setColor(
double r,
double g,
double b,
double alpha);
120 void setColor(
const double* l_color)
122 this->setColor(l_color[0], l_color[1], l_color[2], l_color[3]);
124 bool isColorSet()
const {
return m_isColorSet; }
125 void unsetColor() { m_isColorSet =
false; }
134 unsigned int advanceLevel(
int mode = 0)
const;
135 void setLocalAdvanceLevel(
int mode,
unsigned int level);
136 unsigned int localAdvanceLevel(
int mode = 0)
const
138 return (mode == 1 ? m_localAdvanceLevel[1] : m_localAdvanceLevel[0]);
143 void unsetLocalAdvanceLevel(
int mode = 0);
146 bool hasLocalAdvanceLevelInfo(
int mode = 0)
const
148 return (mode == 1 ? m_hasLocalAdvanceLevelInfo[1] : m_hasLocalAdvanceLevelInfo[0]);
151 const std::vector<smtk::attribute::ItemPtr>& items()
const {
return m_items; }
156 : (static_cast<unsigned int>(ith) >= m_items.size() ?
smtk::attribute::
ItemPtr()
157 : m_items[static_cast<std::size_t>(ith)]);
171 itemAtPath(
const std::string& path,
const std::string& seps =
"/",
bool activeOnly =
false)
const;
173 itemAtPath(
const std::string& path,
const std::string& seps =
"/",
bool activeOnly =
false);
176 typename T::ConstPtr itemAtPathAs(
177 const std::string& path,
178 const std::string& seps =
"/",
179 bool activeOnly =
false)
const;
182 itemAtPathAs(
const std::string& path,
const std::string& seps =
"/",
bool activeOnly =
false);
187 std::string itemPath(
const ItemPtr& item,
const std::string& seps =
"/")
const;
193 std::size_t numberOfItems()
const {
return m_items.size(); }
214 std::function<
bool(
typename T::value_type)> test,
215 bool activeChildren =
true);
247 T entityRefsAs(
const std::string& name)
const;
272 T associatedModelEntities()
const;
275 T associatedObjects()
const;
292 const CopyAssignmentOptions& options = CopyAssignmentOptions());
296 const CopyAssignmentOptions& options,
311 void detachItemsFromOwningResource();
324 bool removeAllAssociations(
bool partialRemovalOk =
false);
336 bool appliesToBoundaryNodes()
const {
return m_appliesToBoundaryNodes; }
337 void setAppliesToBoundaryNodes(
bool appliesValue) { m_appliesToBoundaryNodes = appliesValue; }
338 bool appliesToInteriorNodes()
const {
return m_appliesToInteriorNodes; }
339 void setAppliesToInteriorNodes(
bool appliesValue) { m_appliesToInteriorNodes = appliesValue; }
345 bool isValid(
bool useActiveCategories =
true)
const;
346 bool isValid(
const std::set<std::string>& categories)
const;
357 bool requestCatagories =
true,
358 bool includeReadAccess =
false,
359 unsigned int readAccessLevel = 0)
const;
366 m_userData[key] = value;
369 void clearUserData(
const std::string& key) { m_userData.erase(key); }
370 void clearAllUserData() { m_userData.clear(); }
372 bool isAboutToBeDeleted()
const {
return m_aboutToBeDeleted; }
384 void setIncludeIndex(std::size_t index) { m_includeIndex = index; }
386 std::size_t includeIndex()
const {
return m_includeIndex; }
391 bool canEvaluate()
const;
395 bool doesEvalaute()
const;
399 std::unique_ptr<smtk::attribute::Evaluator> createEvaluator()
const;
418 std::unique_lock<std::mutex> m_guard;
433 const std::string& myName,
441 void removeAllItems();
447 void setName(
const std::string& newname) { m_name = newname; }
450 std::vector<smtk::attribute::ItemPtr> m_items;
453 bool m_appliesToBoundaryNodes;
454 bool m_appliesToInteriorNodes;
456 std::map<std::string, smtk::simulation::UserDataPtr> m_userData;
460 bool m_aboutToBeDeleted;
463 std::size_t m_includeIndex;
464 bool m_hasLocalAdvanceLevelInfo[2];
465 unsigned int m_localAdvanceLevel[2];
470 std::map<std::string, smtk::simulation::UserDataPtr>::const_iterator it = m_userData.find(key);
474 inline void Attribute::setColor(
double r,
double g,
double b,
double a)
484 T Attribute::entityRefsAs(
const std::string& iname)
const
493 for (
auto it = itm->begin(); it != itm->end(); ++it)
500 typename T::value_type entry = std::dynamic_pointer_cast<smtk::model::Entity>(*it);
503 result.insert(result.end(), entry);
510 T Attribute::associatedObjects()
const
513 if (!m_associatedObjects)
518 for (
auto it = m_associatedObjects->begin(); it != m_associatedObjects->end(); ++it)
525 auto entry = std::dynamic_pointer_cast<typename T::value_type::element_type>(*it);
528 result.insert(result.end(), entry);
538 if (!m_associatedObjects)
543 for (
auto it = m_associatedObjects->begin(); it != m_associatedObjects->end(); ++it)
550 typename T::value_type entry = std::dynamic_pointer_cast<smtk::model::Entity>(*it);
553 result.insert(result.end(), entry);
565 return smtk::dynamic_pointer_cast<T>(this->
itemAtPath(path, seps, activeOnly));
572 return smtk::dynamic_pointer_cast<const T>(this->
itemAtPath(path, seps, activeOnly));
576 typename T::Ptr Attribute::findAs(
const std::string& iname,
SearchStyle style)
578 return smtk::dynamic_pointer_cast<T>(this->
find(iname, style));
582 typename T::ConstPtr Attribute::findAs(
const std::string& iname,
SearchStyle style)
const
584 return smtk::dynamic_pointer_cast<const T>(this->
find(iname, style));
590 std::function<
bool(
typename T::value_type)> test,
594 std::function<void(
ItemPtr,
bool)> visitor =
596 typename T::value_type testItem =
597 smtk::dynamic_pointer_cast<typename T::value_type::element_type>(item);
599 if (testItem && test(testItem))
601 filtered.insert(filtered.end(), testItem);
604 item->visitChildren(visitor, activeChildrenLocal);
607 for (std::size_t index = 0; index < this->numberOfItems(); ++index)
609 visitor(this->item(
static_cast<int>(index)), activeChildren);
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
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.
Definition: Attribute.cxx:194
Definition: Definition.h:45
smtk::shared_ptr< smtk::attribute::Definition > DefinitionPtr
Definition: PublicPointerDefs.h:450
SearchStyle
How should searches for items be conducted?
Definition: SearchStyle.h:24
smtk::shared_ptr< smtk::attribute::FileItem > FileItemPtr
Definition: PublicPointerDefs.h:499
smtk::shared_ptr< const smtk::attribute::ComponentItem > ConstComponentItemPtr
Definition: PublicPointerDefs.h:594
smtk::shared_ptr< smtk::simulation::UserData > UserDataPtr
Definition: PublicPointerDefs.h:671
std::set< smtk::common::UUID > UUIDs
Definition: PublicPointerDefs.h:31
smtk::shared_ptr< const smtk::attribute::ModelEntityItem > ConstModelEntityItemPtr
Definition: PublicPointerDefs.h:579
smtk::shared_ptr< smtk::attribute::ComponentItem > ComponentItemPtr
Definition: PublicPointerDefs.h:539
smtk::shared_ptr< const smtk::attribute::GroupItem > ConstGroupItemPtr
Definition: PublicPointerDefs.h:567
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:507
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:923
Definition: Attribute.h:401
The ComponentLinks class is a component-specific API for maninpulating unidirectional links from a co...
Definition: ComponentLinks.h:40
smtk::shared_ptr< smtk::attribute::StringItem > StringItemPtr
Definition: PublicPointerDefs.h:516
smtk::shared_ptr< const smtk::attribute::ResourceItem > ConstResourceItemPtr
Definition: PublicPointerDefs.h:589
smtk::shared_ptr< smtk::attribute::ResourceItem > ResourceItemPtr
Definition: PublicPointerDefs.h:535
smtk::shared_ptr< const smtk::attribute::StringItem > ConstStringItemPtr
Definition: PublicPointerDefs.h:575
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:588
const common::UUID & id() const override
Return a unique identifier for the object which will be persistent across sessions.
Definition: Attribute.h:374
smtk::shared_ptr< const smtk::attribute::ReferenceItem > ConstReferenceItemPtr
Definition: PublicPointerDefs.h:584
#define smtkTypeMacro(...)
Add typedefs to a class for identifcation.
Definition: SharedFromThis.h:51
smtk::shared_ptr< smtk::attribute::IntItem > IntItemPtr
Definition: PublicPointerDefs.h:512
smtk::shared_ptr< smtk::attribute::DirectoryItem > DirectoryItemPtr
Definition: PublicPointerDefs.h:491
smtk::shared_ptr< smtk::attribute::Attribute > AttributePtr
Definition: PublicPointerDefs.h:456
smtk::shared_ptr< const smtk::attribute::DateTimeItem > ConstDateTimeItemPtr
Definition: PublicPointerDefs.h:544
bool setId(const common::UUID &uid) override
Assign an ID to this object (used by readers; not for arbitrary reuse).
Definition: Attribute.h:375
@ RECURSIVE_ACTIVE
Recursively search for an active item.
Definition: SearchStyle.h:32
smtk::shared_ptr< smtk::attribute::ReferenceItem > ReferenceItemPtr
Definition: PublicPointerDefs.h:531
smtk::shared_ptr< smtk::attribute::ModelEntityItem > ModelEntityItemPtr
Definition: PublicPointerDefs.h:520
smtk::shared_ptr< const smtk::attribute::Item > ConstItemPtr
Definition: PublicPointerDefs.h:469
smtk::shared_ptr< smtk::attribute::VoidItem > VoidItemPtr
Definition: PublicPointerDefs.h:527
Store information about attribute definitions and instances.
Definition: Resource.h:77
smtk::shared_ptr< smtk::attribute::DateTimeItem > DateTimeItemPtr
Definition: PublicPointerDefs.h:487
Represent a (possibly composite) value according to a definition.
Definition: Attribute.h:49
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.
Definition: Attribute.h:570
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:535
smtk::shared_ptr< const smtk::attribute::DoubleItem > ConstDoubleItemPtr
Definition: PublicPointerDefs.h:554
smtk::shared_ptr< smtk::attribute::DoubleItem > DoubleItemPtr
Definition: PublicPointerDefs.h:495
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:285
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:111
smtk::shared_ptr< const smtk::attribute::FileItem > ConstFileItemPtr
Definition: PublicPointerDefs.h:558
smtk::shared_ptr< smtk::attribute::Item > ItemPtr
Definition: PublicPointerDefs.h:467
smtk::shared_ptr< const smtk::attribute::IntItem > ConstIntItemPtr
Definition: PublicPointerDefs.h:571
smtk::shared_ptr< const smtk::attribute::VoidItem > ConstVoidItemPtr
Definition: PublicPointerDefs.h:599
Definition: Attribute.h:56
smtk::weak_ptr< smtk::attribute::Attribute > WeakAttributePtr
Definition: PublicPointerDefs.h:460
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:549
smtk::shared_ptr< smtk::attribute::Resource > ResourcePtr
Definition: PublicPointerDefs.h:604
smtk::shared_ptr< smtk::resource::Resource > ResourcePtr
Definition: PublicPointerDefs.h:295