MeVisLab Toolbox Reference
SoInteractionProvider.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2008, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef SO_INTERACTION_PROVIDER_H
14 #define SO_INTERACTION_PROVIDER_H
15 
18 
20 #include "SoInteraction.h"
21 
22 class SoState;
23 
24 class SoCommandAction;
25 class SoPointingAction;
26 class SoOffsetAction;
27 class SoPointerPosition;
28 
29 #include <ThirdPartyWarningsDisable.h>
30 #include <Inventor/nodes/SoNode.h>
31 #include <boost/unordered_map.hpp>
32 
33 #include <list>
34 #include <ThirdPartyWarningsRestore.h>
35 
39 {
40 public:
43 
45 
47  virtual std::list<SoInteraction*> getInteractions(SoState* state) = 0;
48 
50  template<class T>
51  std::list<T*> getInteractionsOfType(SoState* state);
52 
55  virtual std::list<SoCommandAction*> getCommandActions(SoState* state);
56  virtual std::list<SoPointingAction*> getPointingActions(SoState* state);
57  virtual std::list<SoOffsetAction*> getOffsetActions(SoState* state);
59 
61  virtual void pointerPosition(SoState* state, const SoPointerPosition& pos) = 0;
62 
64  virtual void pointerLeftWindow(SoState* state) = 0;
65 
66  // \name Registry of SoNode types that can provide interactions:
69  typedef SoInteractionProvider* (*GetProviderFunc)(SoNode*);
70 
72  static void registerInteractionProviderNode(SoType type, GetProviderFunc func);
73 
78 
79 private:
81  static boost::unordered_map<int,GetProviderFunc>* _providerFunctions;
82 };
83 
84 template<class T>
85 std::list<T*> SoInteractionProvider::getInteractionsOfType(SoState* state)
86 {
87  std::list<T*> result;
88  std::list<SoInteraction*> interactions = getInteractions(state);
89  std::list<SoInteraction*>::const_iterator it = interactions.begin();
90  for(;it!=interactions.end();it++) {
91  if ((*it)->isOfType<T>()) {
92  result.push_back(static_cast<T*>(*it));
93  }
94  }
95  return result;
96 }
97 
98 #endif // __SoInteractionProvider_H
@ T
Definition: SoKeyGrabber.h:71
#define SOMANAGEDINTERACTION_API
File to resolve system dependencies in View2D library.
SoCommandAction is the base class for instantaneous actions.
SoInteractionProvider is an abstract interface class that provides interactions to the SoInteractionC...
static SoInteractionProvider * getInteractionProvider(SoNode *node)
Get a SoInteractionProvider from a SoNode if registered, else NULL.
static void registerInteractionProviderNode(SoType type, GetProviderFunc func)
Register a function to obtain a SoInteractionProvider from a SoNode.
virtual void pointerLeftWindow(SoState *state)=0
This is called when the mouse cursor leaves the window.
virtual std::list< SoPointingAction * > getPointingActions(SoState *state)
SoInteractionProvider()
Default constructor.
virtual std::list< SoOffsetAction * > getOffsetActions(SoState *state)
std::list< T * > getInteractionsOfType(SoState *state)
Returns list of interactions of a specific type:
virtual std::list< SoCommandAction * > getCommandActions(SoState *state)
virtual std::list< SoInteraction * > getInteractions(SoState *state)=0
Returns the list of all interactions of this provider.
virtual void pointerPosition(SoState *state, const SoPointerPosition &pos)=0
Override this to always be informed of the current mouse cursor position.
SoOffsetAction is the base class for any interaction that only provides (numeric) offsets in one or t...
SoPointerPosition manages the current position of the mouse cursor.
SoPointingAction is the base class for any mouse based interaction.