ToolHelper.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00024 /* A preview tool helper manages information that any tool may want to use,
00025  * and guides the interaction between tools. These features are available:
00026  * - Notification of user events:
00027  *      - When the mouse moves
00028  *      - When the set of images under the mouse pointer changes
00029  *      - When the mouse button is pressed / released.
00030  *      - When a key is pressed / released
00031  * - Notifications when drawing things on the preview, allowing:
00032  *      - Drawing under / above the set of images.
00033  *      - Drawing under / above each individual image.
00034  *      - Replacing or stopping the drawing of each individual image.
00035  * - Notification of when:
00036  *      - The tool is activated.
00037  * - The tool can request the mouse position.
00038  * - The tool can request a list of images under the mouse.
00039  * - The tool can access the panorama, and make changes to it.
00040  * - The tool can access the ViewState. This allows it to respond to, and cause,
00041  *     interactive changes.
00042  * - The tool can deactivate itself, for example, when asked to give up events.
00043  * - Possible extensions:
00044  *      - What images have been selected
00045  *      - Provide a menu over the preview
00046  */
00047 
00048 #ifndef _PREVIEWTOOLHELPER_H
00049 #define _PREVIEWTOOLHELPER_H
00050 
00051 #if __APPLE__
00052 #include "panoinc_WX.h"
00053 #include "panoinc.h"
00054 #endif
00055 
00056 #include "hugin_utils/utils.h"
00057 #include "base_wx/platform.h"
00058 #include <wx/defs.h>
00059 #include <wx/event.h>
00060 #include <wx/string.h>
00061 
00062 #include <set>
00063 #include <vector>
00064 
00065 #include <hugin_math/hugin_math.h>
00066 #include "ViewState.h"
00067 #include "panodata/Panorama.h"
00068 
00069 class Tool;
00070 class PreviewTool;
00071 class OverviewTool;
00072 class PanosphereOverviewTool;
00073 class PlaneOverviewTool;
00074 class GLPreviewFrame;
00075 
00076 class ToolHelper
00077 {
00078 public:
00079     enum Event
00080     {
00081         MOUSE_MOVE, MOUSE_PRESS, KEY_PRESS,
00082         DRAW_UNDER_IMAGES, DRAW_OVER_IMAGES,
00083         IMAGES_UNDER_MOUSE_CHANGE, REALLY_DRAW_OVER_IMAGES,
00084         MOUSE_WHEEL
00085     };
00086     ToolHelper(HuginBase::Panorama *pano,
00087                       VisualizationState *visualization_state,
00088                       GLPreviewFrame * frame);
00089     ~ToolHelper();
00090     // working with tools
00091     // Activate a tool, the tool will then request notifications it needs.
00092     // Then return a list of tools that had to be dactivated to comply.
00093     std::set<Tool*> ActivateTool(Tool *tool);
00094     // deactivate a tool: remove all it's notifications.
00095     virtual void DeactivateTool(Tool *tool);
00096     
00097     // Events
00098     // the x and y coordinates are in pixels from the top left of the panorama.
00099     virtual void MouseMoved(int x, int y, wxMouseEvent & e);
00100     // pressed is true if the button is pushed down, false if let go
00101     void MouseButtonEvent(wxMouseEvent &e);
00102     void MouseWheelEvent(wxMouseEvent &e);
00103     // keycode is the wxWidgets keycode.
00104     void KeypressEvent(int keycode, int modifiers, bool pressed);
00105     void BeforeDrawImages();
00106     void AfterDrawImages();
00107     // Return true if we want it drawn, return false and draw the image as the
00108     // tools specify otherwise.
00109     bool BeforeDrawImageNumber(unsigned int image);
00110     void AfterDrawImageNumber(unsigned int image);
00111     void MouseEnter(int x, int y, wxMouseEvent & e);
00112     void MouseLeave();
00113     
00114     // Get information
00115     std::set<unsigned int> GetImageNumbersUnderMouse();
00116 
00117     hugin_utils::FDiff2D GetMouseScreenPosition();
00118     hugin_utils::FDiff2D GetMousePanoPosition();
00119 
00120     VisualizationState *GetVisualizationStatePtr();
00121     ViewState* GetViewStatePtr();
00122     HuginBase::Panorama *GetPanoramaPtr();
00123     
00124     // Setting up notifications
00125     void NotifyMe(Event event, Tool *tool);
00126     void NotifyMeBeforeDrawing(unsigned int image_nr, Tool *tool);
00127     void NotifyMeAfterDrawing(unsigned int image_nr, Tool *tool);
00128     void DoNotNotifyMe(Event event, Tool *tool);
00129     void DoNotNotifyMeBeforeDrawing(unsigned int image_nr, Tool *tool);
00130     void DoNotNotifyMeAfterDrawing(unsigned int image_nr, Tool *tool);
00131     
00132     // status message to be something relevant for a tool.
00133     void SetStatusMessage(wxString message);
00134 
00135     bool IsMouseOverPano() {return mouse_over_pano;}
00136     
00137     GLPreviewFrame * GetPreviewFrame() {return frame;}
00138     
00139 protected:
00140     std::set<Tool *> tools_deactivated;
00141     HuginBase::Panorama *pano;
00142     VisualizationState *visualization_state;
00143     GLPreviewFrame *frame;
00144     
00145     double mouse_screen_x, mouse_screen_y;
00146     double mouse_pano_x, mouse_pano_y;
00147     
00148     // What tools are notified of what events.
00149     std::set<Tool *> mouse_move_notified_tools;
00150     std::set<Tool *> mouse_button_notified_tools;
00151     std::set<Tool *> keypress_notified_tools;
00152     std::set<Tool *> draw_under_notified_tools;
00153     std::set<Tool *> draw_over_notified_tools;
00154     std::set<Tool *> really_draw_over_notified_tools;
00155     std::set<Tool *> images_under_mouse_notified_tools;
00156     std::set<Tool *> mouse_wheel_notified_tools;
00157     // these are vectors: the index is the image that a single tool uses.
00158     std::vector<std::set<Tool *> > image_draw_begin_tools;
00159     std::vector<std::set<Tool *> >  image_draw_end_tools;
00160     // stop notifying the given tool of an event.
00161     void RemoveTool(Tool *tool, Tool **single);
00162     void RemoveTool(Tool *tool, std::set<Tool *> *set);
00163     void RemoveTool(Tool *tool, std::vector<std::set<Tool *> > *vector);
00164     void RemoveTool(Tool *tool, std::vector<std::set<Tool *> > *vector,
00165                     unsigned int index);
00166     // set the tool up for notification, deactivating any tools in the way.
00167     void AddTool(Tool *tool, Tool **single);
00168     void AddTool(Tool *tool, std::set<Tool *> *set);
00169     void AddTool(Tool *tool, std::vector<std::set<Tool *> > *vector,
00170                  unsigned int index);
00171                  
00172     // is the set of images under the mouse up to date?
00173     bool images_under_mouse_current, mouse_over_pano;
00174     // which images are under the mouse?
00175     std::set<unsigned int> images_under_mouse;
00176     virtual void UpdateImagesUnderMouse() = 0;
00177     void InvalidateImagesUnderMouse();
00178 };
00179 
00180 class PreviewToolHelper : public ToolHelper
00181 {
00182 public:
00183     PreviewToolHelper(HuginBase::Panorama *pano,
00184                       VisualizationState *visualization_state,
00185                       GLPreviewFrame * frame) : ToolHelper(pano, visualization_state, frame) {}
00186     ~PreviewToolHelper() {}
00187 
00188     void MouseMoved(int x, int y, wxMouseEvent & e);
00189     void UpdateImagesUnderMouse();
00190 
00191 };
00192 
00193 class OverviewToolHelper : public ToolHelper
00194 {
00195 public:
00196     OverviewToolHelper(HuginBase::Panorama *pano,
00197                       VisualizationState *visualization_state,
00198                       GLPreviewFrame * frame) : ToolHelper(pano, visualization_state, frame) {}
00199     ~OverviewToolHelper() {}
00200 
00201 };
00202 
00203 class PanosphereOverviewToolHelper : public OverviewToolHelper
00204 {
00205 public:
00206     PanosphereOverviewToolHelper(HuginBase::Panorama *pano,
00207                       VisualizationState *visualization_state,
00208                       GLPreviewFrame * frame);
00209     ~PanosphereOverviewToolHelper();
00210 
00211     enum PanosphereOverviewEvent {
00212         DRAW_UNDER_IMAGES_BACK, DRAW_UNDER_IMAGES_FRONT,
00213         DRAW_OVER_IMAGES_BACK, DRAW_OVER_IMAGES_FRONT
00214     };
00215 
00216     void NotifyMe(PanosphereOverviewEvent event, PanosphereOverviewTool * tool);
00217     void DoNotNotifyMe(PanosphereOverviewEvent event, PanosphereOverviewTool *tool);
00218 
00219     void MouseMoved(int x, int y, wxMouseEvent & e);
00220     void UpdateImagesUnderMouse();
00221 
00222     void BeforeDrawImagesBack();
00223     void BeforeDrawImagesFront();
00224     void AfterDrawImagesBack();
00225     void AfterDrawImagesFront();
00226     
00227     void DeactivateTool(Tool *tool);
00228 
00229 protected:
00230     std::set<Tool *> draw_under_notified_tools_back;
00231     std::set<Tool *> draw_under_notified_tools_front;
00232     std::set<Tool *> draw_over_notified_tools_back;
00233     std::set<Tool *> draw_over_notified_tools_front;
00234     
00235 };
00236 
00237 
00238 class PlaneOverviewToolHelper : public OverviewToolHelper
00239 {
00240 public:
00241     PlaneOverviewToolHelper(HuginBase::Panorama *pano,
00242                       VisualizationState *visualization_state,
00243                       GLPreviewFrame * frame);
00244     ~PlaneOverviewToolHelper();
00245 
00246     void MouseMoved(int x, int y, wxMouseEvent & e);
00247     void UpdateImagesUnderMouse();
00248     
00249     double getPlaneX() {return plane_x;}
00250     double getPlaneY() {return plane_y;}
00251 
00252 private:
00253 
00254     double plane_x;
00255     double plane_y;
00256 
00257 };
00258 
00259 #endif

Generated on 4 Sep 2015 for Hugintrunk by  doxygen 1.4.7