Slicer 5.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkMRMLLayerDMWidgetEventTranslationNode.h
Go to the documentation of this file.
1/*==============================================================================
2
3 Program: 3D Slicer
4
5 Copyright (c) Kitware SAS
6
7 See COPYRIGHT.txt
8 or http://www.slicer.org/copyright/copyright.txt for details.
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 This file was originally developed by Thibault Pelletier, Kitware SAS,
17 and was partially funded by ANR grants ANR-22-CE45-0034 and ANR-18-RHUS-005.
18
19==============================================================================*/
20
21#ifndef __vtkMRMLLayerDMWidgetEventTranslationNode_h
22#define __vtkMRMLLayerDMWidgetEventTranslationNode_h
23
24#include "vtkSlicerLayerDMModuleMRMLExport.h"
25
26// Slicer includes
27#include <vtkMRMLNode.h>
29
30// VTK includes
31#include <vtkCommand.h>
32#include <vtkEvent.h>
33
34// STL includes
35#include <map>
36
38
43class VTK_SLICER_LAYERDM_MODULE_MRML_EXPORT vtkMRMLLayerDMWidgetEventTranslationNode : public vtkMRMLNode
44{
45public:
48
51
52 void PrintSelf(ostream& os, vtkIndent indent) override;
53
57
58 void ReadXMLAttributes(const char** atts) override;
59 void WriteXML(ostream& of, int indent) override;
60
62 const char* GetNodeTagName() override;
63
68 static unsigned long GetEndInteractionEvent(unsigned long startInteractionEvent);
69
72 static unsigned long GetClickEvent(unsigned long releaseEvent);
73
75 void SetTranslation(int widgetState, unsigned long interactionEvent, unsigned long widgetEvent, int modifier = vtkEvent::NoModifier);
76
78 void SetTranslationClickAndDrag(int widgetState,
79 unsigned long interactionEvent,
80 int widgetStateDragging,
81 unsigned long widgetStartEvent,
82 unsigned long widgetEndEvent,
83 int modifiers = vtkEvent::NoModifier);
84
86 void SetTranslationKeyboard(int widgetState,
87 const std::string& keySym,
88 unsigned long widgetEvent,
89 int modifier = vtkEvent::NoModifier,
90 int repeatCount = 1,
91 unsigned long keyEvent = vtkCommand::KeyPressEvent);
92
98 int RemoveTranslationEvent(unsigned long widgetEvent);
99
105 bool BlockTranslationEvent(unsigned long widgetEvent, bool isBlocked);
106
111 bool BlockAllTranslationEvents(bool isBlocked);
112
118 unsigned long Translate(int widgetState, vtkMRMLInteractionEventData* eventData);
119
121 void Clear();
122
125
126protected:
129
130private:
132 struct EventKey
133 {
134 bool operator==(const EventKey& other) const { return this->AsTuple() == other.AsTuple(); }
135 bool operator<(const EventKey& other) const { return this->AsTuple() < other.AsTuple(); }
136 std::tuple<int, unsigned long, int, int, std::string> AsTuple() const
137 {
138 return std::make_tuple(this->WidgetState, this->EventId, this->Modifier, this->RepeatCount, this->KeySym);
139 }
140
143 static int ThresholdRepeatCount(int repeatCount) { return std::max(1, repeatCount); }
144
145 int WidgetState{ vtkMRMLAbstractWidget::WidgetStateAny };
146 unsigned long EventId{ vtkCommand::NoEvent };
147 int Modifier{ vtkEvent::NoModifier };
148 int RepeatCount{ 1 };
149 std::string KeySym;
150 };
151
152 void SetTranslation(const EventKey& key, unsigned long widgetEvent);
153 unsigned long Translate(EventKey key) const;
154 bool IsWidgetEventBlocked(unsigned long widgetEvent) const;
155 unsigned long GetWidgetEvent(const EventKey& key) const;
156
157 static std::string ToString(const std::map<EventKey, unsigned long>& eventMap, const vtkIndent* indent, const std::string& eol);
158 static std::string ToString(const std::pair<EventKey, unsigned long>& eventPair);
159
160 static std::map<EventKey, unsigned long> EventMapFromString(const std::string& value);
161 static std::pair<EventKey, unsigned long> EventPairFromString(const std::string& value);
162
163 std::map<EventKey, unsigned long> EventMap;
164 std::set<unsigned long> BlockedEvents;
165 bool IsBlocked{};
166};
167
168#endif
@ WidgetStateAny
this state is used for referring to any widget state (for defining event translations)
void SetTranslationClickAndDrag(int widgetState, unsigned long interactionEvent, int widgetStateDragging, unsigned long widgetStartEvent, unsigned long widgetEndEvent, int modifiers=vtkEvent::NoModifier)
Set translation for mouse click and drag events.
void Clear()
Clears all widget translations contained in the node.
void PrintSelf(ostream &os, vtkIndent indent) override
vtkMRMLNode * CreateNodeInstance() override
Create instance of the default node. Like New only virtual.
vtkMRMLCopyContentMacro(vtkMRMLLayerDMWidgetEventTranslationNode)
void ReadXMLAttributes(const char **atts) override
int RemoveTranslationEvent(unsigned long widgetEvent)
static unsigned long GetEndInteractionEvent(unsigned long startInteractionEvent)
void SetTranslation(int widgetState, unsigned long interactionEvent, unsigned long widgetEvent, int modifier=vtkEvent::NoModifier)
Set translation for mouse click events.
static vtkMRMLLayerDMWidgetEventTranslationNode * New()
bool BlockTranslationEvent(unsigned long widgetEvent, bool isBlocked)
vtkMRMLLayerDMWidgetEventTranslationNode(const vtkMRMLLayerDMWidgetEventTranslationNode &)=delete
bool BlockAllTranslationEvents(bool isBlocked)
void operator=(const vtkMRMLLayerDMWidgetEventTranslationNode &)=delete
const char * GetNodeTagName() override
void WriteXML(ostream &of, int indent) override
void SetTranslationKeyboard(int widgetState, const std::string &keySym, unsigned long widgetEvent, int modifier=vtkEvent::NoModifier, int repeatCount=1, unsigned long keyEvent=vtkCommand::KeyPressEvent)
Set translation for keystroke events.
~vtkMRMLLayerDMWidgetEventTranslationNode() override=default
unsigned long Translate(int widgetState, vtkMRMLInteractionEventData *eventData)
static unsigned long GetClickEvent(unsigned long releaseEvent)