Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ToolHelper.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
24 /* A preview tool helper manages information that any tool may want to use,
25  * and guides the interaction between tools. These features are available:
26  * - Notification of user events:
27  * - When the mouse moves
28  * - When the set of images under the mouse pointer changes
29  * - When the mouse button is pressed / released.
30  * - When a key is pressed / released
31  * - Notifications when drawing things on the preview, allowing:
32  * - Drawing under / above the set of images.
33  * - Drawing under / above each individual image.
34  * - Replacing or stopping the drawing of each individual image.
35  * - Notification of when:
36  * - The tool is activated.
37  * - The tool can request the mouse position.
38  * - The tool can request a list of images under the mouse.
39  * - The tool can access the panorama, and make changes to it.
40  * - The tool can access the ViewState. This allows it to respond to, and cause,
41  * interactive changes.
42  * - The tool can deactivate itself, for example, when asked to give up events.
43  * - Possible extensions:
44  * - What images have been selected
45  * - Provide a menu over the preview
46  */
47 
48 #ifndef _PREVIEWTOOLHELPER_H
49 #define _PREVIEWTOOLHELPER_H
50 
51 #if __APPLE__
52 #include "panoinc_WX.h"
53 #include "panoinc.h"
54 #endif
55 
56 #include "base_wx/wxutils.h"
57 #include "base_wx/platform.h"
58 #include <wx/defs.h>
59 #include <wx/event.h>
60 #include <wx/string.h>
61 
62 #include <set>
63 #include <vector>
64 
65 #include <hugin_math/hugin_math.h>
66 #include "ViewState.h"
67 #include "panodata/Panorama.h"
68 
69 class Tool;
70 class PreviewTool;
71 class OverviewTool;
73 class PlaneOverviewTool;
74 class GLPreviewFrame;
75 
77 {
78 public:
79  enum Event
80  {
85  };
89  virtual ~ToolHelper();
90  // working with tools
91  // Activate a tool, the tool will then request notifications it needs.
92  // Then return a list of tools that had to be dactivated to comply.
93  std::set<Tool*> ActivateTool(Tool *tool);
94  // deactivate a tool: remove all it's notifications.
95  virtual void DeactivateTool(Tool *tool);
96 
97  // Events
98  // the x and y coordinates are in pixels from the top left of the panorama.
99  virtual void MouseMoved(int x, int y, wxMouseEvent & e);
100  // pressed is true if the button is pushed down, false if let go
101  void MouseButtonEvent(wxMouseEvent &e);
102  void MouseWheelEvent(wxMouseEvent &e);
103  // keycode is the wxWidgets keycode.
104  void KeypressEvent(int keycode, int modifiers, bool pressed);
105  void BeforeDrawImages();
106  void AfterDrawImages();
107  void MarkDirty();
108  // Return true if we want it drawn, return false and draw the image as the
109  // tools specify otherwise.
110  bool BeforeDrawImageNumber(unsigned int image);
111  void AfterDrawImageNumber(unsigned int image);
112  void MouseEnter(int x, int y, wxMouseEvent & e);
113  void MouseLeave();
114 
115  // Get information
116  std::set<unsigned int> GetImageNumbersUnderMouse();
117 
120 
124 
125  // Setting up notifications
126  void NotifyMe(Event event, Tool *tool);
127  void NotifyMeBeforeDrawing(unsigned int image_nr, Tool *tool);
128  void NotifyMeAfterDrawing(unsigned int image_nr, Tool *tool);
129  void DoNotNotifyMe(Event event, Tool *tool);
130  void DoNotNotifyMeBeforeDrawing(unsigned int image_nr, Tool *tool);
131  void DoNotNotifyMeAfterDrawing(unsigned int image_nr, Tool *tool);
132 
133  // status message to be something relevant for a tool.
134  void SetStatusMessage(wxString message);
135 
137  // return set of images under given position
140 
141 protected:
142  std::set<Tool *> tools_deactivated;
146 
149 
150  // What tools are notified of what events.
151  std::set<Tool *> mouse_move_notified_tools;
152  std::set<Tool *> mouse_button_notified_tools;
153  std::set<Tool *> keypress_notified_tools;
154  std::set<Tool *> draw_under_notified_tools;
155  std::set<Tool *> draw_over_notified_tools;
158  std::set<Tool *> mouse_wheel_notified_tools;
159  std::set<Tool *> m_tools_need_dirty_flag;
160  // these are vectors: the index is the image that a single tool uses.
161  std::vector<std::set<Tool *> > image_draw_begin_tools;
162  std::vector<std::set<Tool *> > image_draw_end_tools;
163  // stop notifying the given tool of an event.
164  void RemoveTool(Tool *tool, Tool **single);
165  void RemoveTool(Tool *tool, std::set<Tool *> *set);
166  void RemoveTool(Tool *tool, std::vector<std::set<Tool *> > *vector);
167  void RemoveTool(Tool *tool, std::vector<std::set<Tool *> > *vector,
168  unsigned int index);
169  // set the tool up for notification, deactivating any tools in the way.
170  void AddTool(Tool *tool, Tool **single);
171  void AddTool(Tool *tool, std::set<Tool *> *set);
172  void AddTool(Tool *tool, std::vector<std::set<Tool *> > *vector,
173  unsigned int index);
174 
175  // is the set of images under the mouse up to date?
177  // which images are under the mouse?
178  std::set<unsigned int> images_under_mouse;
179  void UpdateImagesUnderMouse();
181 };
182 
184 {
185 public:
188  GLPreviewFrame * frame) : ToolHelper(pano, visualization_state, frame) {}
190 
191  void MouseMoved(int x, int y, wxMouseEvent & e);
192 
193 };
194 
196 {
197 public:
200  GLPreviewFrame * frame) : ToolHelper(pano, visualization_state, frame) {}
202 
203 };
204 
206 {
207 public:
212 
216  };
217 
220 
221  void MouseMoved(int x, int y, wxMouseEvent & e);
222 
223  void BeforeDrawImagesBack();
224  void BeforeDrawImagesFront();
225  void AfterDrawImagesBack();
226  void AfterDrawImagesFront();
227 
228  void DeactivateTool(Tool *tool);
229 
230 protected:
235 
236 };
237 
238 
240 {
241 public:
246 
247  void MouseMoved(int x, int y, wxMouseEvent & e);
248 
249  double getPlaneX() {return plane_x;}
250  double getPlaneY() {return plane_y;}
251 
252 private:
253 
254  double plane_x;
255  double plane_y;
256 
257 };
258 
259 #endif
implementation of huginApp Class
hugin_utils::FDiff2D GetMousePanoPosition()
Definition: ToolHelper.cpp:295
void MouseWheelEvent(wxMouseEvent &e)
Definition: ToolHelper.cpp:156
std::set< Tool * > ActivateTool(Tool *tool)
Definition: ToolHelper.cpp:53
std::set< Tool * > m_tools_need_dirty_flag
Definition: ToolHelper.h:159
void AfterDrawImageNumber(unsigned int image)
Definition: ToolHelper.cpp:233
The OpenGL preview frame.
ViewState * GetViewStatePtr()
Definition: ToolHelper.cpp:305
std::set< Tool * > draw_under_notified_tools_back
Definition: ToolHelper.h:231
void NotifyMeBeforeDrawing(unsigned int image_nr, Tool *tool)
Definition: ToolHelper.cpp:349
void AfterDrawImages()
Definition: ToolHelper.cpp:189
std::vector< std::set< Tool * > > image_draw_begin_tools
Definition: ToolHelper.h:161
misc math function &amp; classes used by other parts of the program
HuginBase::Panorama * pano
Definition: ToolHelper.h:143
void RemoveTool(Tool *tool, Tool **single)
Definition: ToolHelper.cpp:420
HuginBase::Panorama * GetPanoramaPtr()
Definition: ToolHelper.cpp:310
void MouseMoved(int x, int y, wxMouseEvent &e)
Definition: ToolHelper.cpp:720
virtual void DeactivateTool(Tool *tool)
Definition: ToolHelper.cpp:60
GLPreviewFrame * frame
Definition: ToolHelper.h:145
void DoNotNotifyMeAfterDrawing(unsigned int image_nr, Tool *tool)
Definition: ToolHelper.cpp:403
include file for the hugin project
void NotifyMe(Event event, Tool *tool)
Definition: ToolHelper.cpp:315
std::set< unsigned int > GetImageNumbersUnderMouse()
Definition: ToolHelper.cpp:281
void UpdateImagesUnderMouse()
Definition: ToolHelper.cpp:109
bool mouse_over_pano
Definition: ToolHelper.h:176
VisualizationState * visualization_state
Definition: ToolHelper.h:144
bool images_under_mouse_current
Definition: ToolHelper.h:176
void DeactivateTool(Tool *tool)
Definition: ToolHelper.cpp:703
std::vector< std::set< Tool * > > image_draw_end_tools
Definition: ToolHelper.h:162
ToolHelper(HuginBase::Panorama *pano, VisualizationState *visualization_state, GLPreviewFrame *frame)
Definition: ToolHelper.cpp:34
VisualizationState * GetVisualizationStatePtr()
Definition: ToolHelper.cpp:300
void DoNotNotifyMe(PanosphereOverviewEvent event, PanosphereOverviewTool *tool)
Definition: ToolHelper.cpp:654
hugin_utils::FDiff2D GetMouseScreenPosition()
Definition: ToolHelper.cpp:290
std::set< unsigned int > UIntSet
Definition: PanoramaData.h:51
bool BeforeDrawImageNumber(unsigned int image)
Definition: ToolHelper.cpp:212
double mouse_pano_y
Definition: ToolHelper.h:148
PlaneOverviewToolHelper(HuginBase::Panorama *pano, VisualizationState *visualization_state, GLPreviewFrame *frame)
Definition: ToolHelper.cpp:714
Model for a panorama.
Definition: Panorama.h:152
void DoNotNotifyMeBeforeDrawing(unsigned int image_nr, Tool *tool)
Definition: ToolHelper.cpp:397
void MouseEnter(int x, int y, wxMouseEvent &e)
Definition: ToolHelper.cpp:248
std::set< Tool * > mouse_move_notified_tools
Definition: ToolHelper.h:151
std::set< Tool * > draw_under_notified_tools
Definition: ToolHelper.h:154
Definition: Tool.h:42
bool IsMouseOverPano()
Definition: ToolHelper.h:136
PreviewToolHelper(HuginBase::Panorama *pano, VisualizationState *visualization_state, GLPreviewFrame *frame)
Definition: ToolHelper.h:186
std::set< Tool * > draw_over_notified_tools_front
Definition: ToolHelper.h:234
std::set< Tool * > mouse_wheel_notified_tools
Definition: ToolHelper.h:158
std::set< Tool * > really_draw_over_notified_tools
Definition: ToolHelper.h:156
virtual ~ToolHelper()
Definition: ToolHelper.cpp:49
void NotifyMe(PanosphereOverviewEvent event, PanosphereOverviewTool *tool)
Definition: ToolHelper.cpp:637
double mouse_screen_x
Definition: ToolHelper.h:147
void MouseButtonEvent(wxMouseEvent &e)
Definition: ToolHelper.cpp:148
std::set< Tool * > tools_deactivated
Definition: ToolHelper.h:142
double mouse_screen_y
Definition: ToolHelper.h:147
std::set< Tool * > keypress_notified_tools
Definition: ToolHelper.h:153
std::set< unsigned int > images_under_mouse
Definition: ToolHelper.h:178
std::set< Tool * > images_under_mouse_notified_tools
Definition: ToolHelper.h:157
void KeypressEvent(int keycode, int modifiers, bool pressed)
Definition: ToolHelper.cpp:165
std::set< Tool * > draw_over_notified_tools_back
Definition: ToolHelper.h:233
include file for the hugin project
std::set< Tool * > draw_under_notified_tools_front
Definition: ToolHelper.h:232
void DoNotNotifyMe(Event event, Tool *tool)
Definition: ToolHelper.cpp:361
void NotifyMeAfterDrawing(unsigned int image_nr, Tool *tool)
Definition: ToolHelper.cpp:355
void MouseMoved(int x, int y, wxMouseEvent &e)
Definition: ToolHelper.cpp:492
void MouseLeave()
Definition: ToolHelper.cpp:263
void InvalidateImagesUnderMouse()
Definition: ToolHelper.cpp:88
virtual void MouseMoved(int x, int y, wxMouseEvent &e)
Definition: ToolHelper.cpp:75
void SetStatusMessage(wxString message)
Definition: ToolHelper.cpp:409
void MouseMoved(int x, int y, wxMouseEvent &e)
Definition: ToolHelper.cpp:510
double mouse_pano_x
Definition: ToolHelper.h:148
std::set< Tool * > draw_over_notified_tools
Definition: ToolHelper.h:155
PanosphereOverviewToolHelper(HuginBase::Panorama *pano, VisualizationState *visualization_state, GLPreviewFrame *frame)
Definition: ToolHelper.cpp:631
void AddTool(Tool *tool, Tool **single)
Definition: ToolHelper.cpp:458
void BeforeDrawImages()
Definition: ToolHelper.cpp:173
std::set< Tool * > mouse_button_notified_tools
Definition: ToolHelper.h:152
GLPreviewFrame * GetPreviewFrame()
Definition: ToolHelper.h:139
OverviewToolHelper(HuginBase::Panorama *pano, VisualizationState *visualization_state, GLPreviewFrame *frame)
Definition: ToolHelper.h:198
HuginBase::UIntSet GetImagesUnderPos(const hugin_utils::FDiff2D &pos)
Definition: ToolHelper.cpp:121
void MarkDirty()
Definition: ToolHelper.cpp:203