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

Generated on 28 Jul 2016 for Hugintrunk by  doxygen 1.4.7