SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
ItemDefinition.h
1 //=========================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //=========================================================================
10 // .NAME ItemDefinition.h - the definition of a value of an attribute definition.
11 // .SECTION Description
12 // ItemDefinition is meant to store definitions of values that can be
13 // stored inside of an attribute. Derived classes give specific
14 // types of items.
15 // .SECTION See Also
16 
17 #ifndef smtk_attribute_ItemDefinition_h
18 #define smtk_attribute_ItemDefinition_h
19 
20 #include "smtk/CoreExports.h"
21 #include "smtk/PublicPointerDefs.h"
22 #include "smtk/SharedFromThis.h" // For smtkTypeMacro.
23 #include "smtk/attribute/Categories.h"
24 #include "smtk/attribute/Item.h" // For Item Types.
25 #include "smtk/attribute/Tag.h"
26 
27 #include <queue>
28 #include <set>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 namespace smtk
34 {
35 namespace attribute
36 {
37 class SMTKCORE_EXPORT ItemDefinition
38 {
39  friend class Definition;
40  friend class GroupItemDefinition;
41  friend class ReferenceItemDefinition;
42  friend class ValueItemDefinition;
43 
44 public:
46  // Temp structure used for copying definitions
47  struct CopyInfo
48  {
49  // Reference to resource that is getting modified ("to")
50  const smtk::attribute::Resource& ToResource;
51  // List of ValueItemDefinitions that reference expressions not currently in this resource
52  std::queue<std::pair<std::string, smtk::attribute::ItemDefinitionPtr>> UnresolvedExpItems;
54  : ToResource(*resource)
55  {
56  }
57  };
58 
59  virtual ~ItemDefinition();
60  // The name used to access the item - this name is unique w/r to the attribute
61  // or parent item
62  const std::string& name() const { return m_name; }
63 
64  virtual Item::Type type() const = 0;
65  // The label is what can be displayed in an application. Unlike the type
66  // which is constant w/r to the definition, an application can change the label
67  const std::string& label() const { return (!m_label.empty() ? m_label : m_name); }
68 
69  void setLabel(const std::string& newLabel) { m_label = newLabel; }
70 
71  int version() const { return m_version; }
72  void setVersion(int myVersion) { m_version = myVersion; }
73 
74  bool isOptional() const { return m_isOptional; }
75 
76  void setIsOptional(bool isOptionalValue) { m_isOptional = isOptionalValue; }
77 
78  // This only comes into play if the item is optional
79  bool isEnabledByDefault() const { return m_isEnabledByDefault; }
80 
81  void setIsEnabledByDefault(bool isEnabledByDefaultValue)
82  {
83  m_isEnabledByDefault = isEnabledByDefaultValue;
84  }
85 
90  const smtk::attribute::Categories& categories() const { return m_categories; }
91 
93  smtk::attribute::Categories::Set& localCategories() { return m_localCategories; }
94  const smtk::attribute::Categories::Set& localCategories() const { return m_localCategories; }
95 
101  {
102  m_localCategories = catSet;
103  }
104 
108  SMTK_DEPRECATED_IN_22_07("Replaced by ItemDefinition::categoryInheritanceMode.")
109  bool isOkToInherit() const;
110  SMTK_DEPRECATED_IN_22_07("Replaced by ItemDefinition::setCategoryInheritanceMode.")
111  void setIsOkToInherit(bool isOkToInheritValue);
113 
117  Categories::CombinationMode categoryInheritanceMode() const { return m_combinationMode; }
118  void setCategoryInheritanceMode(Categories::CombinationMode mode) { m_combinationMode = mode; }
120 
121  //Get the item definition's advance level:
122  //if mode is 1 then the write access level is returned;
123  //else the read access level is returned
124  unsigned int advanceLevel(int mode = 0) const
125  {
126  return (mode == 1 ? m_advanceLevel[1] : m_advanceLevel[0]);
127  }
128  unsigned int localAdvanceLevel(int mode = 0) const
129  {
130  return (mode == 1 ? m_localAdvanceLevel[1] : m_localAdvanceLevel[0]);
131  }
132  void setLocalAdvanceLevel(int mode, unsigned int level);
133  // Convenience Method that sets both read and write to the same value
134  void setLocalAdvanceLevel(unsigned int level);
135 
136  // unsetAdvanceLevel causes the item to return its
137  // definition advance level information for the specified mode when calling
138  // the advanceLevel(mode) method
139  void unsetLocalAdvanceLevel(int mode = 0);
140  // Returns true if the item is returning its local
141  // advance level information
142  bool hasLocalAdvanceLevelInfo(int mode = 0) const
143  {
144  return (mode == 1 ? m_hasLocalAdvanceLevelInfo[1] : m_hasLocalAdvanceLevelInfo[0]);
145  }
146  const std::string& detailedDescription() const { return m_detailedDescription; }
147  void setDetailedDescription(const std::string& text) { m_detailedDescription = text; }
148 
149  const std::string& briefDescription() const { return m_briefDescription; }
150  void setBriefDescription(const std::string& text) { m_briefDescription = text; }
151 
153  const Tags& tags() const { return m_tags; }
154 
158  const Tag* tag(const std::string& name) const;
159  Tag* tag(const std::string& name);
161 
164  bool addTag(const Tag& tag);
165  bool removeTag(const std::string& name);
167 
168  virtual smtk::attribute::ItemPtr buildItem(Attribute* owningAttribute, int itemPosition)
169  const = 0;
170  virtual smtk::attribute::ItemPtr buildItem(Item* owningItem, int position, int subGroupPosition)
171  const = 0;
172  virtual smtk::attribute::ItemDefinitionPtr createCopy(
174 
175 protected:
176  // The constructor must have the value for m_name passed
177  // in because that should never change.
178  ItemDefinition(const std::string& myname);
179  void copyTo(ItemDefinitionPtr def) const;
180  virtual void applyCategories(
181  const smtk::attribute::Categories::Stack& inheritedFromParent,
182  smtk::attribute::Categories& inheritedToParent);
183  virtual void applyAdvanceLevels(
184  const unsigned int& readLevelFromParent,
185  const unsigned int& writeLevelFromParent);
186  int m_version;
187  bool m_isOptional;
188  bool m_isEnabledByDefault;
189  std::string m_label;
190  attribute::Categories::Set m_localCategories;
191  attribute::Categories m_categories;
192  std::string m_detailedDescription;
193  std::string m_briefDescription;
194  bool m_hasLocalAdvanceLevelInfo[2];
195  unsigned int m_localAdvanceLevel[2];
196  unsigned int m_advanceLevel[2];
197  attribute::Tags m_tags;
198  Categories::CombinationMode m_combinationMode;
199 
200 private:
201  // constant value that should never be changed
202  const std::string m_name;
203 };
204 } // namespace attribute
205 } // namespace smtk
206 
207 #endif /* smtk_attribute_ItemDefinition_h */
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
smtk::attribute::Item::Type
Type
Definition: Item.h:52
PublicPointerDefs.h
smtk::attribute::Definition
Definition: Definition.h:45
smtk::attribute::Categories::Stack
Definition: Categories.h:167
smtk::attribute::ItemDefinition
Definition: ItemDefinition.h:37
smtk::attribute::ItemDefinition::localCategories
smtk::attribute::Categories::Set & localCategories()
Returns the categories::Set explicitly assigned to the Items Definition.
Definition: ItemDefinition.h:93
smtk::attribute::ReferenceItemDefinition
A definition for attribute items that store smtk::resource::PersistentObjectPtr as values.
Definition: ReferenceItemDefinition.h:40
smtk::attribute::Tag
Definition: Tag.h:29
smtk::attribute::ItemDefinition::CopyInfo
Definition: ItemDefinition.h:47
smtk::attribute::Item
Definition: Item.h:43
smtk::attribute::ItemDefinition::tags
const Tags & tags() const
return the smtk::attribute::Tags associated with the Definition
Definition: ItemDefinition.h:153
smtk::attribute::ValueItemDefinition
Definition: ValueItemDefinition.h:41
smtk::attribute::Resource
Store information about attribute definitions and instances.
Definition: Resource.h:77
smtk::attribute::Attribute
Represent a (possibly composite) value according to a definition.
Definition: Attribute.h:49
smtk::attribute::ItemDefinition::setCategoryInheritanceMode
void setCategoryInheritanceMode(Categories::CombinationMode mode)
Determines how the Definition should combine its local category Set with the category constraints bei...
Definition: ItemDefinition.h:118
smtk::attribute::Categories
Represents the category constraints associated with an Attribute, Attribute Definition,...
Definition: Categories.h:34
smtk::attribute::Categories::Set
Categories::Set represents a single category constraint used by the Categories class.
Definition: Categories.h:75
smtk::attribute::ItemPtr
smtk::shared_ptr< smtk::attribute::Item > ItemPtr
Definition: PublicPointerDefs.h:467
SharedFromThis.h
Macros for dealing with shared-pointer classes.
smtk::attribute::GroupItemDefinition
A GroupItemDefinition represents a collection of Item Definitions.
Definition: GroupItemDefinition.h:32
smtkTypeMacroBase
#define smtkTypeMacroBase(...)
Add typedefs to a class for identifcation.
Definition: SharedFromThis.h:55
smtk::attribute::ItemDefinitionPtr
smtk::shared_ptr< smtk::attribute::ItemDefinition > ItemDefinitionPtr
Definition: PublicPointerDefs.h:473
smtk::attribute::Categories::CombinationMode
CombinationMode
Definition: Categories.h:37
smtk::attribute::ItemDefinition::categories
const smtk::attribute::Categories & categories() const
Returns the categories (both explicitly assigned and inherited) associated to the Item Definition.
Definition: ItemDefinition.h:90
smtk::attribute::ItemDefinition::setLocalCategories
void setLocalCategories(const smtk::attribute::Categories::Set &catSet)
Sets the local categories.
Definition: ItemDefinition.h:100
smtk::attribute::ResourcePtr
smtk::shared_ptr< smtk::attribute::Resource > ResourcePtr
Definition: PublicPointerDefs.h:604