MeVisLab Toolbox Reference
SoCSODrawOnSurfaceActions.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2016, 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 #pragma once
14 
15 #include "SoCSODrawOnSurface.h"
16 
17 #include <View2DPosition.h>
18 #include <Inventor/SoPickedPoint.h>
19 
21 {
22 public:
23  SoCSODrawOnSurfaceDrawAction(SoCSODrawOnSurface* owner, int modifierKey) : SoPointingAction(owner, "SoCSODrawOnSurfaceAction")
24  {
25  setTriggerMask(modifierKey);
26  }
27 
28  void setTriggerMask(int modifierKey)
29  {
30  if (modifierKey == AllModifiersMask)
31  {
33  }
34  else
35  {
36  setTrigger(Button1Mask | modifierKey);
37  }
38  }
39 
40  bool isInViewportRegion(const SoPointerPosition& pos) const
41  {
42  const SbVec2s& windowSize = pos.getAction()->getViewportRegion().getWindowSize();
43  return (pos[0] >= 0) &&
44  (pos[1] >= 0) &&
45  (pos[0] <= windowSize[0]) &&
46  (pos[1] <= windowSize[1]);
47  }
48 
49  bool isSensitiveAt(const SoPointerPosition& pos) override
50  {
51  if (pos.getAction() && static_cast<SoCSODrawOnSurface*>(getOwner())->hasCSOList())
52  {
53  const SoPickedPoint* pickedPoint = pos.getAction()->getPickedPoint();
54  if (pickedPoint)
55  {
56  return true;
57  }
58  }
59  return false;
60  }
61 
62  void startPressAt(const SoPointerPosition& pos) override
63  {
64  static_cast<SoCSODrawOnSurface*>(getOwner())->startPressAt(pos);
65  }
66 
67  void dragMoveTo(const SoPointerPosition& pos) override
68  {
69  if (!isInViewportRegion(pos))
70  {
71  static_cast<SoCSODrawOnSurface*>(getOwner())->cancel();
72  }
73  else
74  {
75  static_cast<SoCSODrawOnSurface*>(getOwner())->dragMoveTo(pos);
76  }
77  }
78 
79  SoPointingAction* endPress(int) override
80  {
81  static_cast<SoCSODrawOnSurface*>(getOwner())->endPress();
82  return nullptr;
83  }
84 
85  int getCurrentCursor(SoViewerProxy*) const override
86  {
87  return static_cast<SoCSODrawOnSurface*>(getOwner())->cursorShapeDraw.getValue();
88  }
89 };
90 
92 
94 {
95 public:
97  void execute() override;
98 };
99 
101  : SoCommandAction(owner, "Cancel")
102 {
104  setEnabled(false);
105 }
106 
108 {
109  static_cast<SoCSODrawOnSurface*>(getOwner())->cancel();
110 }
111 
113 
115 {
116 public:
118  void execute() override;
119 };
120 
122  : SoCommandAction(owner, "Undo")
123 {
125  setEnabled(true);
126 }
127 
129 {
130  static_cast<SoCSODrawOnSurface*>(getOwner())->undo();
131 }
132 
134 
136 {
137 public:
139  void execute() override;
140 };
141 
143  : SoCommandAction(owner, "Undo")
144 {
146  setEnabled(true);
147 }
148 
150 {
151  static_cast<SoCSODrawOnSurface*>(getOwner())->redo();
152 }
@ ESCAPE
Definition: SoKeyGrabber.h:148
@ Y
Definition: SoKeyGrabber.h:76
@ Z
Definition: SoKeyGrabber.h:77
SoCSODrawOnSurfaceCancelCommandAction(SoCSODrawOnSurface *owner)
void execute() override
Execute the action. Must be overridden by user.
void startPressAt(const SoPointerPosition &pos) override
Starts a drag at given device position.
bool isSensitiveAt(const SoPointerPosition &pos) override
Returns true if the gesture is startable at the given device position.
int getCurrentCursor(SoViewerProxy *) const override
Returns the cursor ID to display for this action, as defined in SoViewerProxy.h - this gets (at least...
void dragMoveTo(const SoPointerPosition &pos) override
Continues the drag to given device position.
SoCSODrawOnSurfaceDrawAction(SoCSODrawOnSurface *owner, int modifierKey)
bool isInViewportRegion(const SoPointerPosition &pos) const
SoPointingAction * endPress(int) override
Ends the drag at last device position.
void execute() override
Execute the action. Must be overridden by user.
SoCSODrawOnSurfaceRedoCommandAction(SoCSODrawOnSurface *owner)
SoCSODrawOnSurfaceUndoCommandAction(SoCSODrawOnSurface *owner)
void execute() override
Execute the action. Must be overridden by user.
SoCommandAction is the base class for instantaneous actions.
ManagedKeyboardShortcut Shortcut
Class Shortcut encapsulates the combination of modifier keys and another key that activates a command...
bool setShortcut(const std::string &shortcut)
Set the (only) default key shortcut (as string describing the shortcut, see ManagedKeyboardShortcut::...
virtual void setEnabled(bool enabled)
Sets the enabled status of this interaction.
Definition: SoInteraction.h:79
SoInteractionOwner * getOwner() const
Definition: SoInteraction.h:72
SoPointerPosition manages the current position of the mouse cursor.
SoHandleEventAction * getAction() const
SoPointingAction is the base class for any mouse based interaction.
@ Button1Mask
Left button.
void setTrigger(int triggerMask, int ignoreMask=0)
Sets the (only) default modifier/button mask for triggering this action.
This class gives access to state of a viewer during scene graph traversal.
Definition: SoViewerProxy.h:30