Orfeo Toolbox  3.16
otbVectorDataTranslateGeometryActionHandler.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 __otbVectorDataTranslateGeometryActionHandler_h
19 #define __otbVectorDataTranslateGeometryActionHandler_h
20 
22 #include "otbMacro.h"
23 
24 namespace otb
25 {
32 template<class TModel, class TView>
34 {
35 public:
41 
43  itkNewMacro(Self);
44 
47 
49  typedef TModel ModelType;
50  typedef typename ModelType::Pointer ModelPointerType;
51  typedef typename ModelType::PointType PointType;
52 
54  typedef TView ViewType;
55  typedef typename ViewType::Pointer ViewPointerType;
56 
62  virtual bool HandleWidgetEvent(const std::string& widgetId, int event)
63  {
64  if (m_View.IsNotNull() && m_Model.IsNotNull() && this->GetIsActive())
65  {
66  typename ViewType::ImageWidgetType::Pointer sourceWidget = NULL;
67 
68  if (widgetId == m_View->GetFullWidget()->GetIdentifier())
69  {
70  sourceWidget = m_View->GetFullWidget();
71  }
72  else if (widgetId == m_View->GetZoomWidget()->GetIdentifier())
73  {
74  sourceWidget = m_View->GetZoomWidget();
75  }
76 
77  // Drag using the middle button (2) of the mouse
78  if (sourceWidget && Fl::event_button() == m_DragMouseButton)
79  {
80  switch (event)
81  {
82  case FL_PUSH:
83  {
84  m_InScreenPointPushed = m_View->GetFullWidget()->GetMousePosition();
85  m_PointPushed = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(m_InScreenPointPushed);
86 
87  m_Model->SearchDataNodeIndexFromPoint(m_PointPushed);
88  return true;
89  }
90  case FL_DRAG:
91  {
92  // Get the cursor position
93  PointType inScreenPoint;
94  inScreenPoint[0] = Fl::event_x();
95  inScreenPoint[1] = m_View->GetFullWidget()->h() - Fl::event_y();
96 
97  double tx = -m_InScreenPointPushed[0] + inScreenPoint[0];
98  double ty = -m_InScreenPointPushed[1] + inScreenPoint[1];
99 
100  // Call the model methods
101  m_Model->UpdateGeometryPosition(tx, -ty);
102  m_Model->Update();
103 
104  // Update the variables
105  m_InScreenPointPushed[0] += tx;
106  m_InScreenPointPushed[1] += ty;
107 
108  return true;
109  }
110  default:
111  {
112  return false;
113  }
114  }
115  }
116  }
117  return false;
118  }
119 
121  itkSetObjectMacro(View, ViewType);
122  itkGetObjectMacro(View, ViewType);
123 
125  itkSetObjectMacro(Model, ModelType);
126  itkGetObjectMacro(Model, ModelType);
127 
129  itkSetMacro(DragMouseButton, int);
130  itkGetMacro(DragMouseButton, int);
131 
132 protected:
136  {
137  }
138 
141  {
142  }
144  void PrintSelf(std::ostream& os, itk::Indent indent) const
145  {
146  Superclass::PrintSelf(os, indent);
147  }
148 
149 private:
150  VectorDataTranslateGeometryActionHandler(const Self&); // purposely not implemented
151  void operator =(const Self&); // purposely not implemented
152 
153  // Pointer to the view
155 
156  // Pointer to the model
158 
161 
164 
165 }; // end class
166 } // end namespace otb
167 
168 #endif

Generated at Sun Feb 3 2013 00:54:23 for Orfeo Toolbox with doxygen 1.8.1.1