Medical Imaging Interaction Toolkit  2018.4.99-c670e289
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 MITK_TOOL_EVENTS_H
14 #define MITK_TOOL_EVENTS_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  itkEventMacro(ToolEvent, itk::ModifiedEvent);
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 
146  TwoParameterToolEvent(const Self &s) : ToolEvent(s), m_Parameter1(s.m_Parameter1), m_Parameter2(s.m_Parameter2) {}
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 T 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
itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent)
ParameterToolEvent Self
const char * GetEventName() const override
ParameterToolEvent< bool > BoolToolEvent
bool CheckEvent(const ::itk::EventObject *e) const override
DataCollection - Class to facilitate loading/accessing structured data.
bool CheckEvent(const ::itk::EventObject *e) const override
const T GetParameter() const
ParameterToolEvent< float > FloatToolEvent
::itk::EventObject * MakeObject() const override
::itk::EventObject * MakeObject() const override
TwoParameterToolEvent(const T parameter1, const U parameter2)
Tool event with 1 parameter.
ParameterToolEvent(const T parameter)
Tool event with 1 parameter.
TwoParameterToolEvent Self
TwoParameterToolEvent(const Self &s)
const char * GetEventName() const override
ParameterToolEvent(const Self &s)
ParameterToolEvent< int > IntegerToolEvent