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/Item.h" // For Item Types.
24 #include "smtk/attribute/Tag.h"
25 #include "smtk/common/Categories.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::common::Categories& categories() const { return m_categories; }
96 
98  smtk::common::Categories::Expression& localCategories() { return m_localCategories; }
99  const smtk::common::Categories::Expression& localCategories() const { return m_localCategories; }
100 
106  {
107  m_localCategories = catExp;
108  }
109 
114  {
115  return m_combinationMode;
116  }
118  {
119  m_combinationMode = mode;
120  }
122 
123  //Get the item definition's advance level:
124  //if mode is 1 then the write access level is returned;
125  //else the read access level is returned
126  unsigned int advanceLevel(int mode = 0) const
127  {
128  return (mode == 1 ? m_advanceLevel[1] : m_advanceLevel[0]);
129  }
130  unsigned int localAdvanceLevel(int mode = 0) const
131  {
132  return (mode == 1 ? m_localAdvanceLevel[1] : m_localAdvanceLevel[0]);
133  }
134  void setLocalAdvanceLevel(int mode, unsigned int level);
135  // Convenience Method that sets both read and write to the same value
136  void setLocalAdvanceLevel(unsigned int level);
137 
138  // unsetAdvanceLevel causes the item to return its
139  // definition advance level information for the specified mode when calling
140  // the advanceLevel(mode) method
141  void unsetLocalAdvanceLevel(int mode = 0);
142  // Returns true if the item is returning its local
143  // advance level information
144  bool hasLocalAdvanceLevelInfo(int mode = 0) const
145  {
146  return (mode == 1 ? m_hasLocalAdvanceLevelInfo[1] : m_hasLocalAdvanceLevelInfo[0]);
147  }
148  const std::string& detailedDescription() const { return m_detailedDescription; }
149  void setDetailedDescription(const std::string& text) { m_detailedDescription = text; }
150 
151  const std::string& briefDescription() const { return m_briefDescription; }
152  void setBriefDescription(const std::string& text) { m_briefDescription = text; }
153 
155  const Tags& tags() const { return m_tags; }
156 
160  const Tag* tag(const std::string& name) const;
161  Tag* tag(const std::string& name);
163 
166  bool addTag(const Tag& tag);
167  bool removeTag(const std::string& name);
169 
171  const shared_ptr<units::System>& unitsSystem() const { return m_unitsSystem; }
172 
173  virtual smtk::attribute::ItemPtr buildItem(Attribute* owningAttribute, int itemPosition)
174  const = 0;
175  virtual smtk::attribute::ItemPtr buildItem(Item* owningItem, int position, int subGroupPosition)
176  const = 0;
177  virtual smtk::attribute::ItemDefinitionPtr createCopy(
179 
180 protected:
181  // The constructor must have the value for m_name passed
182  // in because that should never change.
183  ItemDefinition(const std::string& myname);
184  void copyTo(ItemDefinitionPtr def) const;
185  virtual void applyCategories(
186  const smtk::common::Categories::Stack& inheritedFromParent,
187  smtk::common::Categories& inheritedToParent);
188  virtual void applyAdvanceLevels(
189  const unsigned int& readLevelFromParent,
190  const unsigned int& writeLevelFromParent);
191 
195  virtual void setUnitsSystem(const shared_ptr<units::System>& unitsSystem);
196 
197  int m_version;
198  bool m_isOptional;
199  bool m_isEnabledByDefault;
200  std::string m_label;
201  common::Categories::Expression m_localCategories;
202  common::Categories m_categories;
203  std::string m_detailedDescription;
204  std::string m_briefDescription;
205  bool m_hasLocalAdvanceLevelInfo[2];
206  unsigned int m_localAdvanceLevel[2];
207  unsigned int m_advanceLevel[2];
208  attribute::Tags m_tags;
210  std::shared_ptr<units::System> m_unitsSystem;
211 
212 private:
213  // constant value that should never be changed
214  const std::string m_name;
215 };
216 } // namespace attribute
217 } // namespace smtk
218 
219 #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:65
PublicPointerDefs.h
smtk::attribute::Definition
Stores the definition of an attribute.
Definition: Definition.h:48
smtk::attribute::ItemDefinition::unitsSystem
const shared_ptr< units::System > & unitsSystem() const
Return the unitsSystem of the Definition.
Definition: ItemDefinition.h:171
smtk::common::Categories::Expression
Definition: Categories.h:166
smtk::attribute::ItemDefinition
Definition: ItemDefinition.h:42
smtk::attribute::ItemDefinition::setLocalCategories
void setLocalCategories(const smtk::common::Categories::Expression &catExp)
Sets the local categories.
Definition: ItemDefinition.h:105
smtk::attribute::ItemDefinition::categoryInheritanceMode
smtk::common::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::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:155
smtk::attribute::ItemDefinition::categories
const smtk::common::Categories & categories() const
Returns the categories (both explicitly assigned and inherited) associated to the Item Definition.
Definition: ItemDefinition.h:95
smtk::attribute::ItemDefinition::setCategoryInheritanceMode
void setCategoryInheritanceMode(smtk::common::Categories::CombinationMode mode)
Determines how the Definition should combine its local category Set with the category constraints bei...
Definition: ItemDefinition.h:117
smtk::attribute::ItemDefinition::localCategories
smtk::common::Categories::Expression & localCategories()
Returns the categories::Expression explicitly assigned to the Items Definition.
Definition: ItemDefinition.h:98
smtk::common::Categories::CombinationMode
CombinationMode
Definition: Categories.h:36
smtk::attribute::ValueItemDefinition
Definition: ValueItemDefinition.h:41
smtk::attribute::Resource
Store information about attribute definitions and instances.
Definition: Resource.h:80
smtk::attribute::Attribute
Represent a (possibly composite) value according to a definition.
Definition: Attribute.h:51
smtk::common::Categories
Represents the category constraints associated with smtk objects such as Attributes,...
Definition: Categories.h:33
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:151
smtk::common::Categories::Stack
Definition: Categories.h:225
smtk::attribute::ItemDefinitionPtr
smtk::shared_ptr< smtk::attribute::ItemDefinition > ItemDefinitionPtr
Definition: PublicPointerDefs.h:480
smtk::attribute::ResourcePtr
smtk::shared_ptr< smtk::attribute::Resource > ResourcePtr
Definition: PublicPointerDefs.h:611