Orfeo Toolbox  3.16
otbMouseClickActionHandler.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbMouseClickActionHandler_h
19 #define __otbMouseClickActionHandler_h
20 
22 
23 namespace otb
24 {
33 template <class TModel, class TView>
36 {
37 public:
43 
45  itkNewMacro(Self);
46 
49 
51  typedef TModel ModelType;
52  typedef typename ModelType::Pointer ModelPointerType;
53 
55  typedef TView ViewType;
56  typedef typename ViewType::Pointer ViewPointerType;
57 
63  virtual bool HandleWidgetEvent(const std::string& widgetId, int event)
64  {
65  if (m_View.IsNotNull() && m_Model.IsNotNull() && this->GetIsActive())
66  {
67  typename ViewType::ImageWidgetType::Pointer source;
68 
69  if (m_ActiveOnScrollWidget && widgetId == m_View->GetScrollWidget()->GetIdentifier())
70  {
71  source = m_View->GetScrollWidget();
72  }
73  else if (m_ActiveOnFullWidget && widgetId == m_View->GetFullWidget()->GetIdentifier())
74  {
75  source = m_View->GetFullWidget();
76  }
77  else if (m_ActiveOnZoomWidget && widgetId == m_View->GetZoomWidget()->GetIdentifier())
78  {
79  source = m_View->GetZoomWidget();
80  }
81 
82  if (source.IsNotNull() && event == FL_PUSH && Fl::event_button() == m_MouseButton)
83  {
84  // Get the clicked index
85  typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint;
86  screenPoint = source->GetMousePosition();
87 
88  // Transform to image point
89  imagePoint = source->GetScreenToImageTransform()->TransformPoint(screenPoint);
90 
91  // Transform to index
92  typename ViewType::IndexType index;
93  index[0] = static_cast<int>(imagePoint[0]);
94  index[1] = static_cast<int>(imagePoint[1]);
95 
96  // Change scaled extract region center
97  m_Model->IndexClicked(index);
98  return true;
99  }
100  }
101  return false;
102  }
103 
105  itkSetObjectMacro(Model, ModelType);
106  itkGetObjectMacro(Model, ModelType);
107 
109  itkSetObjectMacro(View, ViewType);
110  itkGetObjectMacro(View, ViewType);
111 
113  itkSetClampMacro(MouseButton, int, 1, 3);
114  itkGetMacro(MouseButton, int);
115 
116  itkSetMacro(ActiveOnScrollWidget, bool);
117  itkGetMacro(ActiveOnScrollWidget, bool);
118  itkBooleanMacro(ActiveOnScrollWidget);
119 
120  itkSetMacro(ActiveOnFullWidget, bool);
121  itkGetMacro(ActiveOnFullWidget, bool);
122  itkBooleanMacro(ActiveOnFullWidget);
123 
124  itkSetMacro(ActiveOnZoomWidget, bool);
125  itkGetMacro(ActiveOnZoomWidget, bool);
126  itkBooleanMacro(ActiveOnZoomWidget);
127 
128 protected:
132  {
133  }
134 
138  void PrintSelf(std::ostream& os, itk::Indent indent) const
139  {
140  Superclass::PrintSelf(os, indent);
141  }
142 
143 private:
144  MouseClickActionHandler(const Self&); // purposely not implemented
145  void operator =(const Self&); // purposely not implemented
146 
147  // Pointer to the view
149 
150  // Pointer to the model
152 
153  // ClickOnScroll
157 
159 
160 }; // end class
161 } // end namespace otb
162 #endif

Generated at Sun Feb 3 2013 00:38:19 for Orfeo Toolbox with doxygen 1.8.1.1