Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
omni::input::Interface Class Referenceabstract

Generic input interface. More...

#include <Interface.h>

Inheritance diagram for omni::input::Interface:
Inheritance graph
[legend]
Collaboration diagram for omni::input::Interface:
Collaboration graph
[legend]

Public Types

typedef Interface interface_type
 
typedef std::vector< Interface
const * > 
inputlist_type
 
typedef std::map< QString,
std::unique_ptr< Interface > > 
container_type
 
typedef std::function< void()> callback_type
 
typedef std::set< QString > categoryset_type
 

Public Member Functions

 Interface (Interface const *_parent=nullptr)
 
virtual ~Interface ()
 Virtual destructor. More...
 
virtual GLuint textureId () const =0
 An input must return an OpenGL texture ID. More...
 
virtual void update ()
 Update interface. More...
 
virtual QSize size () const =0
 An input must return width and height information. More...
 
size_t numberOfChildren () const
 
int width () const
 Return width from size. More...
 
int height () const
 Return height from size. More...
 
virtual categoryset_type categories () const
 Input can have a fixed set of categories. More...
 
QString infoText () const
 Optional info text. More...
 
virtual QWidget * widget ()
 Make new parameter widget. More...
 
virtual QWidget * controlWidget ()
 Make new large control widget for live mode. More...
 
virtual bool canAdd ()
 Returns true if this input can be added E.g., an input can be added after an initial settings dialog was approved or it has valid settings. More...
 
virtual bool canHaveChildren () const
 
int setUpdateCallback (callback_type _updatedCallback)
 Insert a new callback when input has updated and returns its unique id. More...
 
callback_type updatedCallback (int _id)
 
void triggerUpdateCallbacks () const
 
void removeUpdateCallback (int _id)
 
InterfaceaddInput (QString const &_id, Id const &_typeId)
 Add new input with given type id. Returns nullptr if input with typeid does not exist. More...
 
InterfaceaddInput (QString const &_id, Interface *_i)
 Input with id and return pointer to input when successfully added. More...
 
QString getId (Interface const *) const
 Get id of child interface. More...
 
virtual void removeInput (QString const &_id)
 Remove input with id. More...
 
InterfacegetInput (QString const &_id)
 Return pointer of input with id, nullptr if input does not exist. More...
 
Interface const * getInput (QString const &_id) const
 Return pointer of input with id, nullptr if input does not exist. More...
 
container_type const & children () const
 Return children. More...
 
Interface const * parent () const
 Return parent interface (const version) More...
 
QString path () const
 Return absolute path of interface. More...
 
void setParent (Interface *)
 Set new parent. More...
 
virtual void toPropertyMap (PropertyMap &) const
 Serialize to property map. More...
 
virtual void fromPropertyMap (PropertyMap const &)
 Deserialize from property map. More...
 
inputlist_type getAllInputs () const
 Returns a list of input maintained by controller, except this one. More...
 
- Public Member Functions inherited from omni::TypeIdInterface
virtual ~TypeIdInterface ()
 
virtual Id getTypeId () const =0
 Returns type id of object. More...
 
virtual void registerInFactory () const =0
 Register the inherited class in factory. More...
 

Private Member Functions

virtual void activate ()
 
virtual void deactivate ()
 
void getInputsRecurse (Interface const *_root, inputlist_type &_list, bool _excludeThis=true) const
 
int genCallbackId () const
 

Private Attributes

Interface const * parent_ = nullptr
 
std::map< int, callback_typeupdatedCallbacks_
 

Friends

class Controller
 

Detailed Description

Generic input interface.

Member Typedef Documentation

typedef std::function<void ()> omni::input::Interface::callback_type
typedef std::set<QString> omni::input::Interface::categoryset_type
typedef std::map<QString, std::unique_ptr<Interface> > omni::input::Interface::container_type

Constructor & Destructor Documentation

omni::input::Interface::Interface ( Interface const *  _parent = nullptr)
30  : parent_(_parent) {
31  Controller::instance()->add(this);
32  }
Interface const * parent_
Definition: Interface.h:217
static Controller * instance()
Definition: Controller.cpp:33
void add(input::Interface *)
Definition: Controller.cpp:76
omni::input::Interface::~Interface ( )
virtual

Virtual destructor.

Removing input from global controller also deactivates it

35  {
36  updatedCallbacks_.clear();
37  /// Removing input from global controller also deactivates it
39  }
std::map< int, callback_type > updatedCallbacks_
Definition: Interface.h:218
void remove(input::Interface *)
Definition: Controller.cpp:82
static Controller * instance()
Definition: Controller.cpp:33

Member Function Documentation

virtual void omni::input::Interface::activate ( )
inlineprivatevirtual
200  {
201  }
Input * omni::input::Interface::addInput ( QString const &  _id,
Id const &  _typeId 
)

Add new input with given type id. Returns nullptr if input with typeid does not exist.

Parameters
_idId for the input
_typeIdType id of input to determine which kind of input is created
42  {
43  std::unique_ptr<Input> _input(Factory::create(_typeId, this));
44 
45  if (!_input) return nullptr;
46 
47  _input->parent_ = this;
48  container_type::operator[](_id) = std::move(_input);
49  return container_type::at(_id).get();
50  }
static interface_type * create(const key_type &_key, const ARGS &..._args)
Instantiates an object of the class by id and constructor arguments.
Definition: factory.hpp:101
Interface * omni::input::Interface::addInput ( QString const &  _id,
Interface _i 
)

Input with id and return pointer to input when successfully added.

52  {
53  if (container_type::count(_id) != 0) {
54  return nullptr;
55  }
56  container_type::operator[](_id).reset(_i);
57  _i->parent_ = this;
58 
59  return container_type::operator[](_id).get();
60  }
virtual bool omni::input::Interface::canAdd ( )
inlinevirtual

Returns true if this input can be added E.g., an input can be added after an initial settings dialog was approved or it has valid settings.

Returns
Flag if input can be added
124  {
125  return true;
126  }
virtual bool omni::input::Interface::canHaveChildren ( ) const
inlinevirtual

Reimplemented in omni::input::List.

128  {
129  return false;
130  }
virtual categoryset_type omni::input::Interface::categories ( ) const
inlinevirtual

Input can have a fixed set of categories.

Reimplemented in omni::input::TestImage.

102  {
103  return categoryset_type();
104  }
std::set< QString > categoryset_type
Definition: Interface.h:64
Interface::container_type const & omni::input::Interface::children ( ) const

Return children.

78  {
79  return *this;
80  }
virtual QWidget* omni::input::Interface::controlWidget ( )
inlinevirtual

Make new large control widget for live mode.

115  {
116  return nullptr;
117  }
virtual void omni::input::Interface::deactivate ( )
inlineprivatevirtual
203  {
204  }
void omni::input::Interface::fromPropertyMap ( PropertyMap const &  _map)
virtual

Deserialize from property map.

Deserialize from stream.

Reimplemented in omni::input::List, omni::input::TestImage, and omni::input::Framebuffer.

156  {
157  using namespace omni::util;
158  clear();
159  PropertyMap _children = _map.getValue("children",PropertyMap());
160  auto _ids = _children.ids();
161 
162  for (auto& _id : _ids) {
163  _children.getPtr(_id,[&](Id const& _typeId) ->
164  input::Interface *
165  {
166  return addInput(_id, _typeId);
167  });
168  }
169  }
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
int omni::input::Interface::genCallbackId ( ) const
inlineprivate
208  {
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  }
std::map< int, callback_type > updatedCallbacks_
Definition: Interface.h:218
Interface::inputlist_type omni::input::Interface::getAllInputs ( ) const

Returns a list of input maintained by controller, except this one.

120  {
121  inputlist_type _inputs;
122  Interface const* _root = this;
123  while (_root->parent()) {
124  _root = _root->parent();
125  }
126  getInputsRecurse(_root,_inputs,true);
127  return _inputs;
128  }
std::vector< Interface const * > inputlist_type
Definition: Interface.h:61
Interface(Interface const *_parent=nullptr)
Definition: Interface.cpp:30
void getInputsRecurse(Interface const *_root, inputlist_type &_list, bool _excludeThis=true) const
Definition: Interface.cpp:130
QString omni::input::Interface::getId ( Interface const *  _i) const

Get id of child interface.

82  {
83  if (_i->parent() != this) return "";
84 
85  for (auto& _child : *this) {
86  if (_i == _child.second.get()) {
87  return _child.first;
88  }
89  }
90  return QString("");
91  }
Interface * omni::input::Interface::getInput ( QString const &  _id)

Return pointer of input with id, nullptr if input does not exist.

66  {
67  if (container_type::count(_id) == 0) return nullptr;
68 
69  return container_type::at(_id).get();
70  }
Interface const * omni::input::Interface::getInput ( QString const &  _id) const

Return pointer of input with id, nullptr if input does not exist.

72  {
73  if (container_type::count(_id) == 0) return nullptr;
74 
75  return container_type::at(_id).get();
76  }
void omni::input::Interface::getInputsRecurse ( Interface const *  _root,
inputlist_type _list,
bool  _excludeThis = true 
) const
private
133  {
134  for (auto& _idChild : *this) {
135  auto* _child = _idChild.second.get();
136  if (!((_child == this) && _excludeThis)) {
137  _list.push_back(_child);
138  }
139 
140  getInputsRecurse(_child,_list,_excludeThis);
141  }
142  }
void getInputsRecurse(Interface const *_root, inputlist_type &_list, bool _excludeThis=true) const
Definition: Interface.cpp:130
int omni::input::Interface::height ( ) const
inline

Return height from size.

97  {
98  return size().height();
99  }
virtual QSize size() const =0
An input must return width and height information.
QString omni::input::Interface::infoText ( ) const
inline

Optional info text.

107  {
108  return QString();
109  }
size_t omni::input::Interface::numberOfChildren ( ) const
inline
85  {
86  return container_type::size();
87  }
Interface const * omni::input::Interface::parent ( ) const

Return parent interface (const version)

107  {
108  return parent_;
109  }
Interface const * parent_
Definition: Interface.h:217
QString omni::input::Interface::path ( ) const

Return absolute path of interface.

93  {
94  if (!parent()) return "/";
95 
96  auto *_parent = parent();
97  QString _path;
98 
99  while (_parent != nullptr) {
100  _path = QString("/") + _parent->getId(this) + _path;
101  _parent = _parent->parent();
102  }
103  return _path;
104  }
Interface const * parent() const
Return parent interface (const version)
Definition: Interface.cpp:107
void omni::input::Interface::removeInput ( QString const &  _id)
virtual

Remove input with id.

Reimplemented in omni::input::List.

62  {
63  container_type::erase(_id);
64  }
void omni::input::Interface::removeUpdateCallback ( int  _id)
inline
149  {
150  updatedCallbacks_.erase(_id);
151  }
std::map< int, callback_type > updatedCallbacks_
Definition: Interface.h:218
void omni::input::Interface::setParent ( Interface _parent)

Set new parent.

111  {
112  parent_ = _parent;
113  }
Interface const * parent_
Definition: Interface.h:217
int omni::input::Interface::setUpdateCallback ( callback_type  _updatedCallback)
inline

Insert a new callback when input has updated and returns its unique id.

133  {
134  int _id = genCallbackId();
135  updatedCallbacks_[_id] = _updatedCallback;
136  return _id;
137  }
std::map< int, callback_type > updatedCallbacks_
Definition: Interface.h:218
int genCallbackId() const
Definition: Interface.h:208
virtual QSize omni::input::Interface::size ( ) const
pure virtual

An input must return width and height information.

Implemented in omni::input::List, and omni::input::Framebuffer.

virtual GLuint omni::input::Interface::textureId ( ) const
pure virtual

An input must return an OpenGL texture ID.

Implemented in omni::input::List, and omni::input::Framebuffer.

void omni::input::Interface::toPropertyMap ( PropertyMap &  _map) const
virtual

Serialize to property map.

Serialize to stream.

Reimplemented in omni::input::List, omni::input::TestImage, and omni::input::Framebuffer.

145  {
146  using namespace omni::util;
147  PropertyMap _children;
148  for (auto& _idChild : children()) {
149  OMNI_DEBUG << _idChild.first << _idChild.second.get();
150  _children.put(_idChild.first,_idChild.second);
151  }
152  _map.put("children",_children);
153  }
container_type const & children() const
Return children.
Definition: Interface.cpp:78
#define OMNI_DEBUG
Definition: util.h:122
void omni::input::Interface::triggerUpdateCallbacks ( ) const
inline
143  {
144  for (auto& _idCallback : updatedCallbacks_) {
145  _idCallback.second();
146  }
147  }
std::map< int, callback_type > updatedCallbacks_
Definition: Interface.h:218
virtual void omni::input::Interface::update ( )
inlinevirtual

Update interface.

Reimplemented in omni::input::TestImage.

80 {}
callback_type omni::input::Interface::updatedCallback ( int  _id)
inline
139  {
140  return updatedCallbacks_.at(_id);
141  }
std::map< int, callback_type > updatedCallbacks_
Definition: Interface.h:218
QWidget * omni::input::Interface::widget ( )
virtual

Make new parameter widget.

Reimplemented in omni::input::List.

116  {
117  return new ui::InputPreview(this);
118  }
int omni::input::Interface::width ( ) const
inline

Return width from size.

91  {
92  return size().width();
93  }
virtual QSize size() const =0
An input must return width and height information.

Friends And Related Function Documentation

friend class Controller
friend

Field Documentation

Interface const* omni::input::Interface::parent_ = nullptr
private
std::map<int,callback_type> omni::input::Interface::updatedCallbacks_
private

The documentation for this class was generated from the following files: