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 "PT/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(PT::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 MouseLeave();
00112     
00113     // Get information
00114     std::set<unsigned int> GetImageNumbersUnderMouse();
00115 
00116     hugin_utils::FDiff2D GetMouseScreenPosition();
00117     hugin_utils::FDiff2D GetMousePanoPosition();
00118 
00119     VisualizationState *GetVisualizationStatePtr();
00120     ViewState* GetViewStatePtr();
00121     PT::Panorama *GetPanoramaPtr();
00122     
00123     // Setting up notifications
00124     void NotifyMe(Event event, Tool *tool);
00125     void NotifyMeBeforeDrawing(unsigned int image_nr, Tool *tool);
00126     void NotifyMeAfterDrawing(unsigned int image_nr, Tool *tool);
00127     void DoNotNotifyMe(Event event, Tool *tool);
00128     void DoNotNotifyMeBeforeDrawing(unsigned int image_nr, Tool *tool);
00129     void DoNotNotifyMeAfterDrawing(unsigned int image_nr, Tool *tool);
00130     
00131     // status message to be something relevant for a tool.
00132     void SetStatusMessage(wxString message);
00133 
00134     bool IsMouseOverPano() {return mouse_over_pano;}
00135     
00136     GLPreviewFrame * GetPreviewFrame() {return frame;}
00137     
00138 protected:
00139     std::set<Tool *> tools_deactivated;
00140     PT::Panorama *pano;
00141     VisualizationState *visualization_state;
00142     GLPreviewFrame *frame;
00143     
00144     double mouse_screen_x, mouse_screen_y;
00145     double mouse_pano_x, mouse_pano_y;
00146     
00147     // What tools are notified of what events.
00148     std::set<Tool *> mouse_move_notified_tools;
00149     std::set<Tool *> mouse_button_notified_tools;
00150     std::set<Tool *> keypress_notified_tools;
00151     std::set<Tool *> draw_under_notified_tools;
00152     std::set<Tool *> draw_over_notified_tools;
00153     std::set<Tool *> really_draw_over_notified_tools;
00154     std::set<Tool *> images_under_mouse_notified_tools;
00155     std::set<Tool *> mouse_wheel_notified_tools;
00156     // these are vectors: the index is the image that a single tool uses.
00157     std::vector<std::set<Tool *> > image_draw_begin_tools;
00158     std::vector<std::set<Tool *> >  image_draw_end_tools;
00159     // stop notifying the given tool of an event.
00160     void RemoveTool(Tool *tool, Tool **single);
00161     void RemoveTool(Tool *tool, std::set<Tool *> *set);
00162     void RemoveTool(Tool *tool, std::vector<std::set<Tool *> > *vector);
00163     void RemoveTool(Tool *tool, std::vector<std::set<Tool *> > *vector,
00164                     unsigned int index);
00165     // set the tool up for notification, deactivating any tools in the way.
00166     void AddTool(Tool *tool, Tool **single);
00167     void AddTool(Tool *tool, std::set<Tool *> *set);
00168     void AddTool(Tool *tool, std::vector<std::set<Tool *> > *vector,
00169                  unsigned int index);
00170                  
00171     // is the set of images under the mouse up to date?
00172     bool images_under_mouse_current, mouse_over_pano;
00173     // which images are under the mouse?
00174     std::set<unsigned int> images_under_mouse;
00175     virtual void UpdateImagesUnderMouse() = 0;
00176     void InvalidateImagesUnderMouse();
00177 };
00178 
00179 class PreviewToolHelper : public ToolHelper
00180 {
00181 public:
00182     PreviewToolHelper(PT::Panorama *pano,
00183                       VisualizationState *visualization_state,
00184                       GLPreviewFrame * frame) : ToolHelper(pano, visualization_state, frame) {}
00185     ~PreviewToolHelper() {}
00186 
00187     void MouseMoved(int x, int y, wxMouseEvent & e);
00188     void UpdateImagesUnderMouse();
00189 
00190 };
00191 
00192 class OverviewToolHelper : public ToolHelper
00193 {
00194 public:
00195     OverviewToolHelper(PT::Panorama *pano,
00196                       VisualizationState *visualization_state,
00197                       GLPreviewFrame * frame) : ToolHelper(pano, visualization_state, frame) {}
00198     ~OverviewToolHelper() {}
00199 
00200 };
00201 
00202 class PanosphereOverviewToolHelper : public OverviewToolHelper
00203 {
00204 public:
00205     PanosphereOverviewToolHelper(PT::Panorama *pano,
00206                       VisualizationState *visualization_state,
00207                       GLPreviewFrame * frame);
00208     ~PanosphereOverviewToolHelper();
00209 
00210     enum PanosphereOverviewEvent {
00211         DRAW_UNDER_IMAGES_BACK, DRAW_UNDER_IMAGES_FRONT,
00212         DRAW_OVER_IMAGES_BACK, DRAW_OVER_IMAGES_FRONT
00213     };
00214 
00215     void NotifyMe(PanosphereOverviewEvent event, PanosphereOverviewTool * tool);
00216     void DoNotNotifyMe(PanosphereOverviewEvent event, PanosphereOverviewTool *tool);
00217 
00218     void MouseMoved(int x, int y, wxMouseEvent & e);
00219     void UpdateImagesUnderMouse();
00220 
00221     void BeforeDrawImagesBack();
00222     void BeforeDrawImagesFront();
00223     void AfterDrawImagesBack();
00224     void AfterDrawImagesFront();
00225     
00226     void DeactivateTool(Tool *tool);
00227 
00228 protected:
00229     std::set<Tool *> draw_under_notified_tools_back;
00230     std::set<Tool *> draw_under_notified_tools_front;
00231     std::set<Tool *> draw_over_notified_tools_back;
00232     std::set<Tool *> draw_over_notified_tools_front;
00233     
00234 };
00235 
00236 
00237 class PlaneOverviewToolHelper : public OverviewToolHelper
00238 {
00239 public:
00240     PlaneOverviewToolHelper(PT::Panorama *pano,
00241                       VisualizationState *visualization_state,
00242                       GLPreviewFrame * frame);
00243     ~PlaneOverviewToolHelper();
00244 
00245     void MouseMoved(int x, int y, wxMouseEvent & e);
00246     void UpdateImagesUnderMouse();
00247     
00248     double getPlaneX() {return plane_x;}
00249     double getPlaneY() {return plane_y;}
00250 
00251 private:
00252 
00253     double plane_x;
00254     double plane_y;
00255 
00256 };
00257 
00258 #endif

Generated on 27 Nov 2014 for Hugintrunk by  doxygen 1.4.7