SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
OperationDecorator.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 #ifndef smtk_view_OperationDecorator_h
11 #define smtk_view_OperationDecorator_h
12 
13 #include "smtk/operation/Operation.h"
14 #include "smtk/string/Token.h"
15 #include "smtk/view/Configuration.h"
16 
17 #include <functional>
18 #include <initializer_list>
19 #include <set>
20 
21 namespace smtk
22 {
23 namespace view
24 {
25 
62 class SMTKCORE_EXPORT OperationDecorator
63 {
64 public:
66  class Entry
67  {
68  public:
70  smtk::operation::Operation::Index m_index{ 0 };
72  mutable std::string m_label;
74  mutable std::string m_buttonLabel;
76  mutable std::string m_toolTip;
78  mutable std::set<smtk::string::Token> m_groups;
79 
80  // TODO: Provide a way to override the operation's icon?
81 
83  mutable int m_precedence{ -1 };
84 
91  Entry(smtk::operation::Operation::Index index)
92  : m_index(index)
93  {
94  }
95 
103  smtk::operation::Operation::Index index,
104  const std::string& label,
105  const std::string& toolTip,
106  const std::set<smtk::string::Token>& groups = {},
107  const std::string& buttonLabel = std::string())
108  : m_index(index)
109  , m_label(label)
110  , m_buttonLabel(buttonLabel)
111  , m_toolTip(toolTip)
112  , m_groups(groups)
113  {
114  }
115 
116  bool operator<(const Entry& other) const { return m_index < other.m_index; }
117 
118  protected:
119  friend class OperationDecorator;
120 
122  Entry() = default;
123  };
124 
125  using Override = std::pair<bool, std::reference_wrapper<const Entry>>;
126 
127  OperationDecorator() = default;
128  OperationDecorator(std::initializer_list<Entry> entries);
129  OperationDecorator(
130  const std::shared_ptr<smtk::operation::Manager>& manager,
131  const Configuration::Component& config);
132  virtual ~OperationDecorator() = default;
133 
135  void dump() const;
136 
138  int insert(const Entry& entry);
139 
141  template<typename OperationType>
142  Override at() const
143  {
144  return this->at(std::type_index(typeid(OperationType)).hash_code());
145  }
146 
148  Override at(smtk::operation::Operation::Index index) const;
149 
151  std::size_t size() const { return m_entries.size(); }
152 
153  static Override none();
154 
155 protected:
156  std::set<Entry> m_entries;
157 };
158 
164 template<typename OperationType>
166 {
167  OperationDecorator::Entry result(std::type_index(typeid(OperationType)).hash_code());
168  return result;
169 }
170 
176 template<typename OperationType>
178  const std::string& label,
179  const std::string& toolTip,
180  const std::set<smtk::string::Token>& groups = {},
181  const std::string& buttonLabel = std::string())
182 {
183  OperationDecorator::Entry result(
184  std::type_index(typeid(OperationType)).hash_code(), label, toolTip, groups, buttonLabel);
185  return result;
186 }
187 
188 } // namespace view
189 } // namespace smtk
190 #endif // smtk_view_OperationDecorator_h
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
smtk::view::OperationDecorator::Entry::Entry
Entry(smtk::operation::Operation::Index index, const std::string &label, const std::string &toolTip, const std::set< smtk::string::Token > &groups={}, const std::string &buttonLabel=std::string())
A constructor that accepts overrides for all parameters.
Definition: OperationDecorator.h:102
smtk::view::wrap
OperationDecorator::Entry wrap()
An Entry-constructor that takes an operation as a parameter.
Definition: OperationDecorator.h:165
smtk::view::OperationDecorator::Entry::m_groups
std::set< smtk::string::Token > m_groups
Groupings in which this operation should appear.
Definition: OperationDecorator.h:78
smtk::view::OperationDecorator::Entry::Entry
Entry(smtk::operation::Operation::Index index)
A constructor that takes an operation index.
Definition: OperationDecorator.h:91
smtk::view::OperationDecorator::at
Override at() const
Return the entry for an operation.
Definition: OperationDecorator.h:142
smtk::view::OperationDecorator::Entry::m_label
std::string m_label
An alternate name for the operation (overriding its native label).
Definition: OperationDecorator.h:72
smtk::view::OperationDecorator::Entry::m_buttonLabel
std::string m_buttonLabel
Same as m_label but with linebreaks to squarify it for presentation.
Definition: OperationDecorator.h:74
smtk::view::OperationDecorator::Entry
An entry indicating how to present an operation to users.
Definition: OperationDecorator.h:66
smtk::view::OperationDecorator::Entry::m_toolTip
std::string m_toolTip
An alternate tool-tip string.
Definition: OperationDecorator.h:76
smtk::view::OperationDecorator::size
std::size_t size() const
Return the number of operation entries.
Definition: OperationDecorator.h:151
smtk::view::OperationDecorator
Decorate operations that should be presented to the user.
Definition: OperationDecorator.h:62