Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Interface.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OMNI_INPUT_INTERFACE_H_
21 #define OMNI_INPUT_INTERFACE_H_
22 
23 #include <memory>
24 #include <set>
25 #include <map>
26 #include <functional>
27 #include <QOpenGLTexture>
28 #include <omni/exception.h>
29 #include <omni/PluginInfo.h>
31 #include <omni/mapping/Interface.h>
32 
33 namespace omni {
34  namespace input {
35  namespace exception {
36  /**@brief Exception is thrown when accessing input of a children
37  @detail Is only thrown when input cannot accept children
38  **/
40  public:
42 
43  inline QString message() const throw()
44  {
45  return QString("Input cannot have children!");
46  }
47  };
48  }
49 
50  class Controller;
51 
52  /// Generic input interface
53  class Interface :
54  public TypeIdInterface,
55  public PropertyMapSerializer,
56  private std::map<QString, std::unique_ptr<Interface> >{
57  public:
58  friend class Controller;
59 
61  typedef std::vector<Interface const*> inputlist_type;
62  typedef std::map<QString, std::unique_ptr<Interface> >container_type;
63  typedef std::function<void ()> callback_type;
64  typedef std::set<QString> categoryset_type;
65 
66  using container_type::empty;
67  using container_type::begin;
68  using container_type::end;
69  using container_type::clear;
70 
71  Interface(Interface const *_parent = nullptr);
72 
73  /// Virtual destructor
74  virtual ~Interface();
75 
76  /// An input must return an OpenGL texture ID
77  virtual GLuint textureId() const = 0;
78 
79  /// Update interface
80  inline virtual void update() {}
81 
82  /// An input must return width and height information
83  virtual QSize size() const = 0;
84 
85  inline size_t numberOfChildren() const {
86  return container_type::size();
87  }
88 
89  /// Return width from size
90  inline int width() const
91  {
92  return size().width();
93  }
94 
95  /// Return height from size
96  inline int height() const
97  {
98  return size().height();
99  }
100 
101  /// Input can have a fixed set of categories
102  virtual categoryset_type categories() const {
103  return categoryset_type();
104  }
105 
106  /// Optional info text
107  QString infoText() const {
108  return QString();
109  }
110 
111  /// Make new parameter widget
112  virtual QWidget* widget();
113 
114  /// Make new large control widget for live mode
115  inline virtual QWidget* controlWidget() {
116  return nullptr;
117  }
118 
119  /**@brief Returns true if this input can be added
120  @detail E.g., an input can be added after an initial settings dialog
121  was approved or it has valid settings.
122  @return Flag if input can be added
123  **/
124  inline virtual bool canAdd() {
125  return true;
126  }
127 
128  inline virtual bool canHaveChildren() const {
129  return false;
130  }
131 
132  /// Insert a new callback when input has updated and returns its unique id
133  inline int setUpdateCallback(callback_type _updatedCallback) {
134  int _id = genCallbackId();
135  updatedCallbacks_[_id] = _updatedCallback;
136  return _id;
137  }
138 
139  inline callback_type updatedCallback(int _id) {
140  return updatedCallbacks_.at(_id);
141  }
142 
143  void triggerUpdateCallbacks() const {
144  for (auto& _idCallback : updatedCallbacks_) {
145  _idCallback.second();
146  }
147  }
148 
149  inline void removeUpdateCallback(int _id) {
150  updatedCallbacks_.erase(_id);
151  }
152 
153  /**@brief Add new input with given type id. Returns nullptr if input
154  with typeid does not exist
155  @param _id Id for the input
156  *@param _typeId Type id of input to determine which kind of input is
157  * created
158  **/
159  Interface* addInput(QString const& _id,
160  Id const& _typeId);
161 
162  /// Input with id and return pointer to input when successfully added
163  Interface* addInput(QString const& _id,
164  Interface *_i);
165 
166  /// Get id of child interface
167  QString getId(Interface const*) const;
168 
169  /// Remove input with id
170  virtual void removeInput(QString const& _id);
171 
172  /// Return pointer of input with id, nullptr if input does not exist
173  Interface * getInput(QString const& _id);
174 
175  /// Return pointer of input with id, nullptr if input does not exist
176  Interface const * getInput(QString const& _id) const;
177 
178  /// Return children
179  container_type const& children() const;
180 
181  /// Return parent interface (const version)
182  Interface const * parent() const;
183 
184  /// Return absolute path of interface
185  QString path() const;
186 
187  /// Set new parent
188  void setParent(Interface *);
189 
190  /// Serialize to property map
191  virtual void toPropertyMap(PropertyMap&) const;
192 
193  /// Deserialize from property map
194  virtual void fromPropertyMap(PropertyMap const&);
195 
196  /// Returns a list of input maintained by controller, except this one
198 
199  private:
200  inline virtual void activate() {
201  }
202 
203  inline virtual void deactivate() {
204  }
205 
206  void getInputsRecurse(Interface const* _root, inputlist_type& _list, bool _excludeThis = true) const;
207 
208  int genCallbackId() const {
209  for (size_t i = 0; i <= updatedCallbacks_.size(); ++i) {
210  if (!updatedCallbacks_.count(i)) {
211  return i;
212  }
213  }
214  return updatedCallbacks_.size();
215  }
216 
217  Interface const *parent_ = nullptr;
218  std::map<int,callback_type> updatedCallbacks_;
219  };
220 
221  /// Input Factory typedef
223  }
224 
227 }
228 
229 #define OMNI_INPUT_INTERFACE_IID "org.omnidome.input.Interface"
230 
232 
233 #define OMNI_INPUT_PLUGIN_DECL \
234  Q_OBJECT \
235  Q_PLUGIN_METADATA(IID OMNI_INPUT_INTERFACE_IID) \
236  Q_INTERFACES(omni::input::Interface) \
237  OMNI_PLUGIN_TYPE("Input")
238 
239 #endif /* OMNI_INPUT_INTERFACE_H_ */
virtual GLuint textureId() const =0
An input must return an OpenGL texture ID.
std::map< int, callback_type > updatedCallbacks_
Definition: Interface.h:218
virtual categoryset_type categories() const
Input can have a fixed set of categories.
Definition: Interface.h:102
AbstractFactory< Interface, Interface const * > Factory
Input Factory typedef.
Definition: Interface.h:222
inputlist_type getAllInputs() const
Returns a list of input maintained by controller, except this one.
Definition: Interface.cpp:120
std::vector< Interface const * > inputlist_type
Definition: Interface.h:61
size_t numberOfChildren() const
Definition: Interface.h:85
Id type for classes An Id must only contain alpha numerical characters and must begin with a letter...
Definition: Id.h:34
Definition: exception.h:71
Interface(Interface const *_parent=nullptr)
Definition: Interface.cpp:30
int width() const
Return width from size.
Definition: Interface.h:90
Interface const * parent_
Definition: Interface.h:217
Exception is thrown when accessing input of a children Is only thrown when input cannot accept child...
Definition: Interface.h:39
virtual void fromPropertyMap(PropertyMap const &)
Deserialize from property map.
Definition: Interface.cpp:156
Interface const * parent() const
Return parent interface (const version)
Definition: Interface.cpp:107
QString message() const
This is the method which throw the message string.
Definition: Interface.h:43
int setUpdateCallback(callback_type _updatedCallback)
Insert a new callback when input has updated and returns its unique id.
Definition: Interface.h:133
virtual void removeInput(QString const &_id)
Remove input with id.
Definition: Interface.cpp:62
Interface * addInput(QString const &_id, Id const &_typeId)
Add new input with given type id. Returns nullptr if input with typeid does not exist.
Definition: Interface.cpp:41
void getInputsRecurse(Interface const *_root, inputlist_type &_list, bool _excludeThis=true) const
Definition: Interface.cpp:130
std::set< QString > categoryset_type
Definition: Interface.h:64
Input controller controls which inputs are currently active Implemented as a singleton.
Definition: Controller.h:31
#define OMNI_EXCEPTION(EXCEPTION)
Definition: exception.h:55
Interface interface_type
Definition: Interface.h:60
virtual void deactivate()
Definition: Interface.h:203
virtual bool canHaveChildren() const
Definition: Interface.h:128
input::Factory InputFactory
Definition: Interface.h:226
container_type const & children() const
Return children.
Definition: Interface.cpp:78
Generic input interface.
Definition: Interface.h:53
void setParent(Interface *)
Set new parent.
Definition: Interface.cpp:111
#define OMNI_INPUT_INTERFACE_IID
Definition: Interface.h:229
virtual QWidget * controlWidget()
Make new large control widget for live mode.
Definition: Interface.h:115
int genCallbackId() const
Definition: Interface.h:208
Interface * getInput(QString const &_id)
Return pointer of input with id, nullptr if input does not exist.
Definition: Interface.cpp:66
virtual bool canAdd()
Returns true if this input can be added E.g., an input can be added after an initial settings dialog...
Definition: Interface.h:124
callback_type updatedCallback(int _id)
Definition: Interface.h:139
void triggerUpdateCallbacks() const
Definition: Interface.h:143
std::map< QString, std::unique_ptr< Interface > > container_type
Definition: Interface.h:62
Abstract Interface with a single virtual member function which returns.
Definition: TypeIdInterface.h:28
QString infoText() const
Optional info text.
Definition: Interface.h:107
virtual QSize size() const =0
An input must return width and height information.
int height() const
Return height from size.
Definition: Interface.h:96
void removeUpdateCallback(int _id)
Definition: Interface.h:149
virtual void toPropertyMap(PropertyMap &) const
Serialize to property map.
Definition: Interface.cpp:145
virtual QWidget * widget()
Make new parameter widget.
Definition: Interface.cpp:116
virtual void activate()
Definition: Interface.h:200
input::Interface Input
Definition: Interface.h:225
std::function< void()> callback_type
Definition: Interface.h:63
virtual ~Interface()
Virtual destructor.
Definition: Interface.cpp:34
QString getId(Interface const *) const
Get id of child interface.
Definition: Interface.cpp:82
The central factory class.
Definition: factory.hpp:38
virtual void update()
Update interface.
Definition: Interface.h:80
QString path() const
Return absolute path of interface.
Definition: Interface.cpp:93