MeVisLab Toolbox Reference
SoInteractionOwner.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2014, 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_OWNER_H
14 #define SO_INTERACTION_OWNER_H
15 
18 
19 #include "SoInteractionProvider.h"
20 
21 #include <ThirdPartyWarningsDisable.h>
22 #include <string>
23 #include <ThirdPartyWarningsRestore.h>
24 
25 class SoInteractionOwner;
26 
29 {
30 public:
32 
34  virtual void interactionAdded(SoInteractionOwner* /*owner*/, SoInteraction* /*interaction*/) {}
35 
38  virtual void interactionRemoved(SoInteractionOwner* /*owner*/, SoInteraction* /*interaction*/) {}
39 
41  virtual void ownerDeleted(SoInteractionOwner* /*owner*/) {}
42 };
43 
47 {
48  friend class SoInteraction;
49 
50 public:
53 
55  ~SoInteractionOwner() override;
56 
61  virtual void objRef() = 0;
62  virtual void objUnref() = 0;
63 
65  virtual std::string getID() const;
66 
68  std::list<SoInteraction*> getInteractions(SoState* state) override;
69 
71  void pointerPosition(SoState* state, const SoPointerPosition& pos) override;
72 
74  void pointerLeftWindow(SoState* state) override;
75 
78 
81 
82 protected:
84  virtual void pointerPosition(const SoPointerPosition& /*pos*/) {}
85 
87  virtual void pointerLeftWindow() {}
88 
90  bool hasInteractions() const { return !_interactions.empty(); }
91 
93  template<class T>
94  bool hasInteractionsOfType() const;
95 
102 
103 private:
105  void addInteraction(SoInteraction* interaction);
106 
108  void removeInteraction(SoInteraction* interaction);
109 
111  std::list<SoInteraction*> _interactions;
112 
114  std::list<SoInteractionOwnerListenerInterface*> _listeners;
115 
117  bool _inDestructor;
118 };
119 
120 template<class T>
122 {
123  std::list<SoInteraction*>::const_iterator it = _interactions.begin();
124  for(;it!=_interactions.end();it++) {
125  if ((*it)->isOfType<T>()) {
126  return true;
127  }
128  }
129  return false;
130 }
131 
132 #endif // __SoInteractionOwner_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.
Interface for getting notified about changes in the interaction list of an owner.
virtual void interactionAdded(SoInteractionOwner *, SoInteraction *)
This gets called when an interaction is added to the owner.
virtual ~SoInteractionOwnerListenerInterface()=default
virtual void interactionRemoved(SoInteractionOwner *, SoInteraction *)
This gets called when an interaction is removed from the owner (this is not called when the owner is ...
virtual void ownerDeleted(SoInteractionOwner *)
This gets called when the owner is deleted.
SoInteractionOwner is a mix-in class for instances of SoNode that should have interaction objects.
virtual void objRef()=0
Memory management by reference counting; must be implemented in derived classes.
virtual void pointerPosition(const SoPointerPosition &)
Override this if you always need to be informed of the current mouse cursor position.
void pointerPosition(SoState *state, const SoPointerPosition &pos) override
Same as below, with additional SoState argument. Be defaults simply calls the below version.
void pointerLeftWindow(SoState *state) override
Same as below, with additional SoState argument. Be defaults simply calls the below version.
void addCommandAction(SoCommandAction *)
~SoInteractionOwner() override
The destructor will destroy all interactions created with this object as owner.
std::list< SoInteraction * > getInteractions(SoState *state) override
Returns the list of all interactions of this provider.
bool hasInteractionsOfType() const
Same as above, but asking for a specific type of interaction.
virtual std::string getID() const
Returns the id string for identifying the provider (and its actions).
void addPointingAction(SoPointingAction *)
void addOffsetAction(SoOffsetAction *)
bool hasInteractions() const
Returns whether there are any actions defined by this owner.
void addListener(SoInteractionOwnerListenerInterface *listener)
Add a listener object that is notified of changes in the interaction list.
void removeListener(SoInteractionOwnerListenerInterface *listener)
Remove a listener object that was notified of changes in the interaction list.
virtual void pointerLeftWindow()
This is called when the mouse cursor leaves the window.
SoInteractionOwner()
Default constructor.
virtual void objUnref()=0
SoInteractionProvider is an abstract interface class that provides interactions to the SoInteractionC...
SoInteraction is the base class for SoCommandAction, SoPointingAction, and SoOffsetAction.
Definition: SoInteraction.h:36
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.