Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
Medical Imaging Interaction Toolkit
mitkToolEvents.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkToolEvents_h
14 #define mitkToolEvents_h
15 
16 #pragma GCC visibility push(default)
17 #include <itkEventObject.h>
18 #pragma GCC visibility pop
19 
20 namespace mitk
21 {
50 #pragma GCC visibility push(default)
51  itkEventMacroDeclaration(ToolEvent, itk::ModifiedEvent); // Definition is in mitkTool.cpp
52 #pragma GCC visibility pop
53 
83  template <typename T>
84  class ParameterToolEvent : public ToolEvent
85  {
86  public:
88  typedef ToolEvent Superclass;
89 
90  ParameterToolEvent(const T parameter) : m_Parameter(parameter) {}
91  ParameterToolEvent(const Self &s) : ToolEvent(s), m_Parameter(s.m_Parameter) {}
92  ~ParameterToolEvent() override {}
93  const char *GetEventName() const override { return "ParameterToolEvent"; }
94  bool CheckEvent(const ::itk::EventObject *e) const override { return dynamic_cast<const Self *>(e); }
95  ::itk::EventObject *MakeObject() const override { return new Self(m_Parameter); }
96  const T GetParameter() const { return m_Parameter; }
97  protected:
98  const T m_Parameter;
99 
100  private:
102 
103  void operator=(const Self &);
104  };
105 
135  template <typename T, typename U>
136  class TwoParameterToolEvent : public ToolEvent
137  {
138  public:
140  typedef ToolEvent Superclass;
141 
142  TwoParameterToolEvent(const T parameter1, const U parameter2) : m_Parameter1(parameter1), m_Parameter2(parameter2)
143  {
144  }
145 
148  const char *GetEventName() const override { return "TwoParameterToolEvent"; }
149  bool CheckEvent(const ::itk::EventObject *e) const override { return dynamic_cast<const Self *>(e); }
150  ::itk::EventObject *MakeObject() const override { return new Self(m_Parameter1, m_Parameter2); }
151  const T GetParameter1() const { return m_Parameter1; }
152  const U GetParameter2() const { return m_Parameter2; }
153  protected:
154  const T m_Parameter1;
155  const U m_Parameter2;
156 
157  private:
159 
160  void operator=(const Self &);
161  };
162 
166 
167 } // namespace
168 
169 // some macros to let tools define their own event classes as inner classes (should then inherit from something like
170 // FloatToolEvent
171 // inheritance, because it allows observers to distinguish events
172 
173 #define mitkToolEventMacro(eventname, baseevent) \
174  \
175 class eventname : public baseevent\
176 {virtual const char * GetEventName() const {return #eventname; \
177  } \
178  \
179 } \
180  ;
181 
182 #define mitkToolEventMacro1Param(eventname, paramtype1) \
183  \
184 class eventname : public ParameterToolEvent<paramtype1> \
185  \
186 { \
187  public: \
188  virtual const char *GetEventName() const { return #eventname "(" #paramtype1 ")"; } \
189  eventname(const paramtype1 parameter) : ParameterToolEvent<paramtype1>(parameter) {} \
190  private: \
191  eventname(); \
192  \
193 };
194 
195 #define mitkToolEventMacro2Param(eventname, paramtype1, paramtype2) \
196  \
197 class eventname : public TwoParameterToolEvent<paramtype1, paramtype2> \
198  \
199 { \
200  public: \
201  virtual const char *GetEventName() const { return #eventname "(" #paramtype1 "," #paramtype2 ")"; } \
202  eventname(const paramtype1 parameter1, const paramtype2 parameter2) \
203  : TwoParameterToolEvent<paramtype1, paramtype2>(parameter1, parameter2) \
204  { \
205  } \
206  \
207  private: \
208  eventname(); \
209  \
210 };
211 
212 #endif
mitk::FloatToolEvent
ParameterToolEvent< float > FloatToolEvent
Definition: mitkToolEvents.h:164
mitk::TwoParameterToolEvent::CheckEvent
bool CheckEvent(const ::itk::EventObject *e) const override
Definition: mitkToolEvents.h:149
mitk::ParameterToolEvent::Self
ParameterToolEvent Self
Definition: mitkToolEvents.h:87
mitk::ParameterToolEvent::m_Parameter
const T m_Parameter
Definition: mitkToolEvents.h:98
mitk::ParameterToolEvent
Tool event with 1 parameter.
Definition: mitkToolEvents.h:84
mitk::ParameterToolEvent::ParameterToolEvent
ParameterToolEvent(const Self &s)
Definition: mitkToolEvents.h:91
mitk::IntegerToolEvent
ParameterToolEvent< int > IntegerToolEvent
Definition: mitkToolEvents.h:163
mitk::ParameterToolEvent::Superclass
ToolEvent Superclass
Definition: mitkToolEvents.h:88
mitk::TwoParameterToolEvent::MakeObject
::itk::EventObject * MakeObject() const override
Definition: mitkToolEvents.h:150
mitk::BoolToolEvent
ParameterToolEvent< bool > BoolToolEvent
Definition: mitkToolEvents.h:165
mitk::TwoParameterToolEvent::m_Parameter2
const U m_Parameter2
Definition: mitkToolEvents.h:155
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::ParameterToolEvent::~ParameterToolEvent
~ParameterToolEvent() override
Definition: mitkToolEvents.h:92
mitk::ParameterToolEvent::MakeObject
::itk::EventObject * MakeObject() const override
Definition: mitkToolEvents.h:95
mitk::TwoParameterToolEvent::GetEventName
const char * GetEventName() const override
Definition: mitkToolEvents.h:148
mitk::TwoParameterToolEvent
Tool event with 1 parameter.
Definition: mitkToolEvents.h:136
mitk::TwoParameterToolEvent::GetParameter2
const U GetParameter2() const
Definition: mitkToolEvents.h:152
mitk::TwoParameterToolEvent::m_Parameter1
const T m_Parameter1
Definition: mitkToolEvents.h:154
mitk::ParameterToolEvent::CheckEvent
bool CheckEvent(const ::itk::EventObject *e) const override
Definition: mitkToolEvents.h:94
mitk::TwoParameterToolEvent::TwoParameterToolEvent
TwoParameterToolEvent(const T parameter1, const U parameter2)
Definition: mitkToolEvents.h:142
mitk::ParameterToolEvent::GetParameter
const T GetParameter() const
Definition: mitkToolEvents.h:96
mitk::ParameterToolEvent::ParameterToolEvent
ParameterToolEvent(const T parameter)
Definition: mitkToolEvents.h:90
mitk::TwoParameterToolEvent::Superclass
ToolEvent Superclass
Definition: mitkToolEvents.h:140
mitk::TwoParameterToolEvent::Self
TwoParameterToolEvent Self
Definition: mitkToolEvents.h:139
mitk::TwoParameterToolEvent::TwoParameterToolEvent
TwoParameterToolEvent(const Self &s)
Definition: mitkToolEvents.h:146
mitk::itkEventMacroDeclaration
itkEventMacroDeclaration(BoundingShapeInteractionEvent, itk::AnyEvent)
mitk::TwoParameterToolEvent::GetParameter1
const T GetParameter1() const
Definition: mitkToolEvents.h:151
mitk::ParameterToolEvent::GetEventName
const char * GetEventName() const override
Definition: mitkToolEvents.h:93
mitk::TwoParameterToolEvent::~TwoParameterToolEvent
~TwoParameterToolEvent() override
Definition: mitkToolEvents.h:147