Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITK_TOOL_EVENTS_H
18 #define MITK_TOOL_EVENTS_H
19 
20 #pragma GCC visibility push(default)
21 #include <itkEventObject.h>
22 #pragma GCC visibility pop
23 
24 namespace mitk
25 {
54 #pragma GCC visibility push(default)
55  itkEventMacro(ToolEvent, itk::ModifiedEvent);
56 #pragma GCC visibility pop
57 
87  template <typename T>
88  class ParameterToolEvent : public ToolEvent
89  {
90  public:
92  typedef ToolEvent Superclass;
93 
94  ParameterToolEvent(const T parameter) : m_Parameter(parameter) {}
95  ParameterToolEvent(const Self &s) : ToolEvent(s), m_Parameter(s.m_Parameter) {}
96  virtual ~ParameterToolEvent() {}
97  virtual const char *GetEventName() const override { return "ParameterToolEvent"; }
98  virtual bool CheckEvent(const ::itk::EventObject *e) const override { return dynamic_cast<const Self *>(e); }
99  virtual ::itk::EventObject *MakeObject() const override { return new Self(m_Parameter); }
100  const T GetParameter() const { return m_Parameter; }
101  protected:
102  const T m_Parameter;
103 
104  private:
106 
107  void operator=(const Self &);
108  };
109 
139  template <typename T, typename U>
140  class TwoParameterToolEvent : public ToolEvent
141  {
142  public:
144  typedef ToolEvent Superclass;
145 
146  TwoParameterToolEvent(const T parameter1, const U parameter2) : m_Parameter1(parameter1), m_Parameter2(parameter2)
147  {
148  }
149 
152  virtual const char *GetEventName() const override { return "TwoParameterToolEvent"; }
153  virtual bool CheckEvent(const ::itk::EventObject *e) const override { return dynamic_cast<const Self *>(e); }
154  virtual ::itk::EventObject *MakeObject() const override { return new Self(m_Parameter1, m_Parameter2); }
155  const T GetParameter1() const { return m_Parameter1; }
156  const T GetParameter2() const { return m_Parameter2; }
157  protected:
158  const T m_Parameter1;
159  const U m_Parameter2;
160 
161  private:
163 
164  void operator=(const Self &);
165  };
166 
170 
171 } // namespace
172 
173 // some macros to let tools define their own event classes as inner classes (should then inherit from something like
174 // FloatToolEvent
175 // inheritance, because it allows observers to distinguish events
176 
177 #define mitkToolEventMacro(eventname, baseevent) \
178  \
179 class eventname : public baseevent\
180 {virtual const char * GetEventName() const {return #eventname; \
181  } \
182  \
183 } \
184  ;
185 
186 #define mitkToolEventMacro1Param(eventname, paramtype1) \
187  \
188 class eventname : public ParameterToolEvent<paramtype1> \
189  \
190 { \
191  public: \
192  virtual const char *GetEventName() const { return #eventname "(" #paramtype1 ")"; } \
193  eventname(const paramtype1 parameter) : ParameterToolEvent<paramtype1>(parameter) {} \
194  private: \
195  eventname(); \
196  \
197 };
198 
199 #define mitkToolEventMacro2Param(eventname, paramtype1, paramtype2) \
200  \
201 class eventname : public TwoParameterToolEvent<paramtype1, paramtype2> \
202  \
203 { \
204  public: \
205  virtual const char *GetEventName() const { return #eventname "(" #paramtype1 "," #paramtype2 ")"; } \
206  eventname(const paramtype1 parameter1, const paramtype2 parameter2) \
207  : TwoParameterToolEvent<paramtype1, paramtype2>(parameter1, parameter2) \
208  { \
209  } \
210  \
211  private: \
212  eventname(); \
213  \
214 };
215 
216 #endif
ParameterToolEvent Self
ParameterToolEvent< bool > BoolToolEvent
const T GetParameter() const
virtual const char * GetEventName() const override
virtual bool CheckEvent(const ::itk::EventObject *e) const override
DataCollection - Class to facilitate loading/accessing structured data.
ParameterToolEvent< float > FloatToolEvent
TwoParameterToolEvent(const T parameter1, const U parameter2)
const T GetParameter1() const
Tool event with 1 parameter.
ParameterToolEvent(const T parameter)
Tool event with 1 parameter.
itkEventMacro(ContourModelEvent, itk::AnyEvent)
virtual const char * GetEventName() const override
TwoParameterToolEvent Self
virtual ::itk::EventObject * MakeObject() const override
TwoParameterToolEvent(const Self &s)
const T GetParameter2() const
ParameterToolEvent(const Self &s)
virtual ::itk::EventObject * MakeObject() const override
virtual bool CheckEvent(const ::itk::EventObject *e) const override
ParameterToolEvent< int > IntegerToolEvent