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  Categories::CombinationMode categoryInheritanceMode() const { return m_combinationMode; }
109  void setCategoryInheritanceMode(Categories::CombinationMode mode) { m_combinationMode = mode; }
111 
112  //Get the item definition's advance level:
113  //if mode is 1 then the write access level is returned;
114  //else the read access level is returned
115  unsigned int advanceLevel(int mode = 0) const
116  {
117  return (mode == 1 ? m_advanceLevel[1] : m_advanceLevel[0]);
118  }
119  unsigned int localAdvanceLevel(int mode = 0) const
120  {
121  return (mode == 1 ? m_localAdvanceLevel[1] : m_localAdvanceLevel[0]);
122  }
123  void setLocalAdvanceLevel(int mode, unsigned int level);
124  // Convenience Method that sets both read and write to the same value
125  void setLocalAdvanceLevel(unsigned int level);
126 
127  // unsetAdvanceLevel causes the item to return its
128  // definition advance level information for the specified mode when calling
129  // the advanceLevel(mode) method
130  void unsetLocalAdvanceLevel(int mode = 0);
131  // Returns true if the item is returning its local
132  // advance level information
133  bool hasLocalAdvanceLevelInfo(int mode = 0) const
134  {
135  return (mode == 1 ? m_hasLocalAdvanceLevelInfo[1] : m_hasLocalAdvanceLevelInfo[0]);
136  }
137  const std::string& detailedDescription() const { return m_detailedDescription; }
138  void setDetailedDescription(const std::string& text) { m_detailedDescription = text; }
139 
140  const std::string& briefDescription() const { return m_briefDescription; }
141  void setBriefDescription(const std::string& text) { m_briefDescription = text; }
142 
144  const Tags& tags() const { return m_tags; }
145 
149  const Tag* tag(const std::string& name) const;
150  Tag* tag(const std::string& name);
152 
155  bool addTag(const Tag& tag);
156  bool removeTag(const std::string& name);
158 
159  virtual smtk::attribute::ItemPtr buildItem(Attribute* owningAttribute, int itemPosition)
160  const = 0;
161  virtual smtk::attribute::ItemPtr buildItem(Item* owningItem, int position, int subGroupPosition)
162  const = 0;
163  virtual smtk::attribute::ItemDefinitionPtr createCopy(
165 
166 protected:
167  // The constructor must have the value for m_name passed
168  // in because that should never change.
169  ItemDefinition(const std::string& myname);
170  void copyTo(ItemDefinitionPtr def) const;
171  virtual void applyCategories(
172  const smtk::attribute::Categories::Stack& inheritedFromParent,
173  smtk::attribute::Categories& inheritedToParent);
174  virtual void applyAdvanceLevels(
175  const unsigned int& readLevelFromParent,
176  const unsigned int& writeLevelFromParent);
177  int m_version;
178  bool m_isOptional;
179  bool m_isEnabledByDefault;
180  std::string m_label;
181  attribute::Categories::Set m_localCategories;
182  attribute::Categories m_categories;
183  std::string m_detailedDescription;
184  std::string m_briefDescription;
185  bool m_hasLocalAdvanceLevelInfo[2];
186  unsigned int m_localAdvanceLevel[2];
187  unsigned int m_advanceLevel[2];
188  attribute::Tags m_tags;
189  Categories::CombinationMode m_combinationMode;
190 
191 private:
192  // constant value that should never be changed
193  const std::string m_name;
194 };
195 } // namespace attribute
196 } // namespace smtk
197 
198 #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:53
PublicPointerDefs.h
smtk::attribute::Definition
Definition: Definition.h:45
smtk::attribute::Categories::Stack
Definition: Categories.h:146
smtk::attribute::ItemDefinition
Definition: ItemDefinition.h:37
smtk::attribute::ItemDefinition::categoryInheritanceMode
Categories::CombinationMode categoryInheritanceMode() const
Determines how the Definition should combine its local category Set with the category constraints bei...
Definition: ItemDefinition.h:108
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:44
smtk::attribute::ItemDefinition::tags
const Tags & tags() const
return the smtk::attribute::Tags associated with the Definition
Definition: ItemDefinition.h:144
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:109
smtk::attribute::Categories
Represents the category constraints associated with an Attribute, Attribute Definition,...
Definition: Categories.h:32
smtk::attribute::Categories::Set
Categories::Set represents a single category constraint used by the Categories class.
Definition: Categories.h:60
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:35
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