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 #include "smtk/common/Deprecation.h"
27 
28 #include <queue>
29 #include <set>
30 #include <string>
31 #include <utility>
32 #include <vector>
33 
34 namespace units
35 {
36 struct System;
37 }
38 
39 namespace smtk
40 {
41 namespace attribute
42 {
43 class SMTKCORE_EXPORT ItemDefinition
44 {
45  friend class Definition;
46  friend class GroupItemDefinition;
47  friend class ReferenceItemDefinition;
48  friend class ValueItemDefinition;
49 
50 public:
52  // Temp structure used for copying definitions
53  struct CopyInfo
54  {
55  // Reference to resource that is getting modified ("to")
56  const smtk::attribute::Resource& ToResource;
57  // List of ValueItemDefinitions that reference expressions not currently in this resource
58  std::queue<std::pair<std::string, smtk::attribute::ItemDefinitionPtr>> UnresolvedExpItems;
60  : ToResource(*resource)
61  {
62  }
63  };
64 
65  virtual ~ItemDefinition();
66  // The name used to access the item - this name is unique w/r to the attribute
67  // or parent item
68  const std::string& name() const { return m_name; }
69 
70  virtual Item::Type type() const = 0;
71  // The label is what can be displayed in an application. Unlike the type
72  // which is constant w/r to the definition, an application can change the label
73  const std::string& label() const { return (!m_label.empty() ? m_label : m_name); }
74 
75  void setLabel(const std::string& newLabel) { m_label = newLabel; }
76 
77  int version() const { return m_version; }
78  void setVersion(int myVersion) { m_version = myVersion; }
79 
80  bool isOptional() const { return m_isOptional; }
81 
82  void setIsOptional(bool isOptionalValue) { m_isOptional = isOptionalValue; }
83 
84  // This only comes into play if the item is optional
85  bool isEnabledByDefault() const { return m_isEnabledByDefault; }
86 
87  void setIsEnabledByDefault(bool isEnabledByDefaultValue)
88  {
89  m_isEnabledByDefault = isEnabledByDefaultValue;
90  }
91 
96  const smtk::common::Categories& categories() const { return m_categories; }
97 
99  smtk::common::Categories::Expression& localCategories() { return m_localCategories; }
100  const smtk::common::Categories::Expression& localCategories() const { return m_localCategories; }
101 
107  {
108  m_localCategories = catExp;
109  }
110 
115  {
116  return m_combinationMode;
117  }
119  {
120  m_combinationMode = mode;
121  }
123 
124  //Get the item definition's advance level:
125  //if mode is 1 then the write access level is returned;
126  //else the read access level is returned
127  unsigned int advanceLevel(int mode = 0) const
128  {
129  return (mode == 1 ? m_advanceLevel[1] : m_advanceLevel[0]);
130  }
131  unsigned int localAdvanceLevel(int mode = 0) const
132  {
133  return (mode == 1 ? m_localAdvanceLevel[1] : m_localAdvanceLevel[0]);
134  }
135  void setLocalAdvanceLevel(int mode, unsigned int level);
136  // Convenience Method that sets both read and write to the same value
137  void setLocalAdvanceLevel(unsigned int level);
138 
139  // unsetAdvanceLevel causes the item to return its
140  // definition advance level information for the specified mode when calling
141  // the advanceLevel(mode) method
142  void unsetLocalAdvanceLevel(int mode = 0);
143  // Returns true if the item is returning its local
144  // advance level information
145  bool hasLocalAdvanceLevelInfo(int mode = 0) const
146  {
147  return (mode == 1 ? m_hasLocalAdvanceLevelInfo[1] : m_hasLocalAdvanceLevelInfo[0]);
148  }
149  const std::string& detailedDescription() const { return m_detailedDescription; }
150  void setDetailedDescription(const std::string& text) { m_detailedDescription = text; }
151 
152  const std::string& briefDescription() const { return m_briefDescription; }
153  void setBriefDescription(const std::string& text) { m_briefDescription = text; }
154 
156  const Tags& tags() const { return m_tags; }
157 
161  const Tag* tag(const std::string& name) const;
162  Tag* tag(const std::string& name);
164 
167  bool addTag(const Tag& tag);
168  bool removeTag(const std::string& name);
170 
172  const shared_ptr<units::System>& unitSystem() const { return m_unitSystem; }
173  SMTK_DEPRECATED_IN_25_06("Use unitSystem() instead.")
174  const shared_ptr<units::System>& unitsSystem() const { return m_unitSystem; }
175 
176  virtual smtk::attribute::ItemPtr buildItem(Attribute* owningAttribute, int itemPosition)
177  const = 0;
178  virtual smtk::attribute::ItemPtr buildItem(Item* owningItem, int position, int subGroupPosition)
179  const = 0;
180  virtual smtk::attribute::ItemDefinitionPtr createCopy(
182 
183 protected:
184  // The constructor must have the value for m_name passed
185  // in because that should never change.
186  ItemDefinition(const std::string& myname);
187  void copyTo(ItemDefinitionPtr def) const;
188  virtual void applyCategories(
189  const smtk::common::Categories::Stack& inheritedFromParent,
190  smtk::common::Categories& inheritedToParent);
191  virtual void applyAdvanceLevels(
192  const unsigned int& readLevelFromParent,
193  const unsigned int& writeLevelFromParent);
194 
198  virtual void setUnitSystem(const shared_ptr<units::System>& unitSystem);
199  SMTK_DEPRECATED_IN_25_06("Use setUnitSystem() instead.")
200  virtual void setUnitsSystem(const shared_ptr<units::System>& unitsSystem)
201  {
202  this->setUnitSystem(unitsSystem);
203  }
204 
205  int m_version;
206  bool m_isOptional;
207  bool m_isEnabledByDefault;
208  std::string m_label;
209  common::Categories::Expression m_localCategories;
210  common::Categories m_categories;
211  std::string m_detailedDescription;
212  std::string m_briefDescription;
213  bool m_hasLocalAdvanceLevelInfo[2];
214  unsigned int m_localAdvanceLevel[2];
215  unsigned int m_advanceLevel[2];
216  attribute::Tags m_tags;
218  std::shared_ptr<units::System> m_unitSystem;
219 
220 private:
221  // constant value that should never be changed
222  const std::string m_name;
223 };
224 } // namespace attribute
225 } // namespace smtk
226 
227 #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:49
smtk::common::Categories::Expression
Definition: Categories.h:166
smtk::attribute::ItemDefinition
Definition: ItemDefinition.h:43
smtk::attribute::ItemDefinition::setLocalCategories
void setLocalCategories(const smtk::common::Categories::Expression &catExp)
Sets the local categories.
Definition: ItemDefinition.h:106
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:114
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:53
smtk::attribute::ItemDefinition::tags
const Tags & tags() const
return the smtk::attribute::Tags associated with the Definition
Definition: ItemDefinition.h:156
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:96
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:118
smtk::attribute::ItemDefinition::unitSystem
const shared_ptr< units::System > & unitSystem() const
Return the unitSystem of the Definition.
Definition: ItemDefinition.h:172
smtk::attribute::ItemDefinition::localCategories
smtk::common::Categories::Expression & localCategories()
Returns the categories::Expression explicitly assigned to the Items Definition.
Definition: ItemDefinition.h:99
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::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:407
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:153
smtk::common::Categories::Stack
Definition: Categories.h:225
smtk::attribute::ItemDefinitionPtr
smtk::shared_ptr< smtk::attribute::ItemDefinition > ItemDefinitionPtr
Definition: PublicPointerDefs.h:413
smtk::attribute::ResourcePtr
smtk::shared_ptr< smtk::attribute::Resource > ResourcePtr
Definition: PublicPointerDefs.h:544