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 units
34 {
35 struct System;
36 }
37 
38 namespace smtk
39 {
40 namespace attribute
41 {
42 class SMTKCORE_EXPORT ItemDefinition
43 {
44  friend class Definition;
45  friend class GroupItemDefinition;
46  friend class ReferenceItemDefinition;
47  friend class ValueItemDefinition;
48 
49 public:
51  // Temp structure used for copying definitions
52  struct CopyInfo
53  {
54  // Reference to resource that is getting modified ("to")
55  const smtk::attribute::Resource& ToResource;
56  // List of ValueItemDefinitions that reference expressions not currently in this resource
57  std::queue<std::pair<std::string, smtk::attribute::ItemDefinitionPtr>> UnresolvedExpItems;
59  : ToResource(*resource)
60  {
61  }
62  };
63 
64  virtual ~ItemDefinition();
65  // The name used to access the item - this name is unique w/r to the attribute
66  // or parent item
67  const std::string& name() const { return m_name; }
68 
69  virtual Item::Type type() const = 0;
70  // The label is what can be displayed in an application. Unlike the type
71  // which is constant w/r to the definition, an application can change the label
72  const std::string& label() const { return (!m_label.empty() ? m_label : m_name); }
73 
74  void setLabel(const std::string& newLabel) { m_label = newLabel; }
75 
76  int version() const { return m_version; }
77  void setVersion(int myVersion) { m_version = myVersion; }
78 
79  bool isOptional() const { return m_isOptional; }
80 
81  void setIsOptional(bool isOptionalValue) { m_isOptional = isOptionalValue; }
82 
83  // This only comes into play if the item is optional
84  bool isEnabledByDefault() const { return m_isEnabledByDefault; }
85 
86  void setIsEnabledByDefault(bool isEnabledByDefaultValue)
87  {
88  m_isEnabledByDefault = isEnabledByDefaultValue;
89  }
90 
95  const smtk::attribute::Categories& categories() const { return m_categories; }
96 
98  smtk::attribute::Categories::Set& localCategories() { return m_localCategories; }
99  const smtk::attribute::Categories::Set& localCategories() const { return m_localCategories; }
100 
106  {
107  m_localCategories = catSet;
108  }
109 
113  Categories::CombinationMode categoryInheritanceMode() const { return m_combinationMode; }
114  void setCategoryInheritanceMode(Categories::CombinationMode mode) { m_combinationMode = mode; }
116 
117  //Get the item definition's advance level:
118  //if mode is 1 then the write access level is returned;
119  //else the read access level is returned
120  unsigned int advanceLevel(int mode = 0) const
121  {
122  return (mode == 1 ? m_advanceLevel[1] : m_advanceLevel[0]);
123  }
124  unsigned int localAdvanceLevel(int mode = 0) const
125  {
126  return (mode == 1 ? m_localAdvanceLevel[1] : m_localAdvanceLevel[0]);
127  }
128  void setLocalAdvanceLevel(int mode, unsigned int level);
129  // Convenience Method that sets both read and write to the same value
130  void setLocalAdvanceLevel(unsigned int level);
131 
132  // unsetAdvanceLevel causes the item to return its
133  // definition advance level information for the specified mode when calling
134  // the advanceLevel(mode) method
135  void unsetLocalAdvanceLevel(int mode = 0);
136  // Returns true if the item is returning its local
137  // advance level information
138  bool hasLocalAdvanceLevelInfo(int mode = 0) const
139  {
140  return (mode == 1 ? m_hasLocalAdvanceLevelInfo[1] : m_hasLocalAdvanceLevelInfo[0]);
141  }
142  const std::string& detailedDescription() const { return m_detailedDescription; }
143  void setDetailedDescription(const std::string& text) { m_detailedDescription = text; }
144 
145  const std::string& briefDescription() const { return m_briefDescription; }
146  void setBriefDescription(const std::string& text) { m_briefDescription = text; }
147 
149  const Tags& tags() const { return m_tags; }
150 
154  const Tag* tag(const std::string& name) const;
155  Tag* tag(const std::string& name);
157 
160  bool addTag(const Tag& tag);
161  bool removeTag(const std::string& name);
163 
165  const shared_ptr<units::System>& unitsSystem() const { return m_unitsSystem; }
166 
167  virtual smtk::attribute::ItemPtr buildItem(Attribute* owningAttribute, int itemPosition)
168  const = 0;
169  virtual smtk::attribute::ItemPtr buildItem(Item* owningItem, int position, int subGroupPosition)
170  const = 0;
171  virtual smtk::attribute::ItemDefinitionPtr createCopy(
173 
174 protected:
175  // The constructor must have the value for m_name passed
176  // in because that should never change.
177  ItemDefinition(const std::string& myname);
178  void copyTo(ItemDefinitionPtr def) const;
179  virtual void applyCategories(
180  const smtk::attribute::Categories::Stack& inheritedFromParent,
181  smtk::attribute::Categories& inheritedToParent);
182  virtual void applyAdvanceLevels(
183  const unsigned int& readLevelFromParent,
184  const unsigned int& writeLevelFromParent);
185 
189  virtual void setUnitsSystem(const shared_ptr<units::System>& unitsSystem);
190 
191  int m_version;
192  bool m_isOptional;
193  bool m_isEnabledByDefault;
194  std::string m_label;
195  attribute::Categories::Set m_localCategories;
196  attribute::Categories m_categories;
197  std::string m_detailedDescription;
198  std::string m_briefDescription;
199  bool m_hasLocalAdvanceLevelInfo[2];
200  unsigned int m_localAdvanceLevel[2];
201  unsigned int m_advanceLevel[2];
202  attribute::Tags m_tags;
203  Categories::CombinationMode m_combinationMode;
204  std::shared_ptr<units::System> m_unitsSystem;
205 
206 private:
207  // constant value that should never be changed
208  const std::string m_name;
209 };
210 } // namespace attribute
211 } // namespace smtk
212 
213 #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:56
PublicPointerDefs.h
smtk::attribute::Definition
Stores the definition of an attribute.
Definition: Definition.h:45
smtk::attribute::Categories::Stack
Definition: Categories.h:146
smtk::attribute::ItemDefinition::unitsSystem
const shared_ptr< units::System > & unitsSystem() const
Return the unitsSystem of the Definition.
Definition: ItemDefinition.h:165
smtk::attribute::ItemDefinition
Definition: ItemDefinition.h:42
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:113
smtk::attribute::ItemDefinition::localCategories
smtk::attribute::Categories::Set & localCategories()
Returns the categories::Set explicitly assigned to the Items Definition.
Definition: ItemDefinition.h:98
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:52
smtk::attribute::Item
The base class for items that hold information inside an attribute.
Definition: Item.h:47
smtk::attribute::ItemDefinition::tags
const Tags & tags() const
return the smtk::attribute::Tags associated with the Definition
Definition: ItemDefinition.h:149
smtk::attribute::ValueItemDefinition
Definition: ValueItemDefinition.h:41
smtk::attribute::Resource
Store information about attribute definitions and instances.
Definition: Resource.h:76
smtk::attribute::Attribute
Represent a (possibly composite) value according to a definition.
Definition: Attribute.h:50
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:114
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:474
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:131
smtk::attribute::ItemDefinitionPtr
smtk::shared_ptr< smtk::attribute::ItemDefinition > ItemDefinitionPtr
Definition: PublicPointerDefs.h:480
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:95
smtk::attribute::ItemDefinition::setLocalCategories
void setLocalCategories(const smtk::attribute::Categories::Set &catSet)
Sets the local categories.
Definition: ItemDefinition.h:105
smtk::attribute::ResourcePtr
smtk::shared_ptr< smtk::attribute::Resource > ResourcePtr
Definition: PublicPointerDefs.h:611