cherish
EventHandler.h
1 #ifndef EVENTHANDLER
2 #define EVENTHANDLER
3 
4 /* EventHandler
5  * It is represented as a switcher between all the other
6  * user-defined handlers. Depending on the mouse mode (select, edit,
7  * navigate, sketch, etc), it choses the right handle() function of the
8  * corresponding event handler. Of course, all the handlers must be
9  * initialized in the contstructor. The mode can be reset by a user class.
10 */
11 
12 #include <osgGA/GUIEventHandler>
13 #include <osgGA/GUIEventAdapter>
14 #include <osgGA/GUIActionAdapter>
15 #include <osg/ref_ptr>
16 #include <osg/observer_ptr>
17 
18 #include "../libGUI/GLWidget.h"
19 #include "Settings.h"
20 #include "Canvas.h"
21 #include "Photo.h"
22 #include "SVMData.h"
23 #include "DraggableWire.h"
24 #include "CamPoseData.h"
25 #include "EditableWire.h"
26 #include "UserScene.h"
27 #include "RootScene.h"
28 #include "StrokeIntersector.h"
29 #include "Entity2DIntersector.h"
30 #include "LineIntersector.h"
31 #include "PolyLineIntersector.h"
32 #include "PointIntersector.h"
33 #include "VirtualPlaneIntersector.h"
34 #include "BookmarkToolIntersector.h"
35 #include "CanvasNormalProjector.h"
36 
37 class GLWidget;
38 
47 class EventHandler : public osgGA::GUIEventHandler {
48 public:
49  EventHandler(GLWidget* widget, RootScene* scene, cher::MOUSE_MODE mode = cher::SELECT_ENTITY);
50 
52  virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
53 
54  void setMode(cher::MOUSE_MODE mode);
55  cher::MOUSE_MODE getMode() const;
56 
57 protected:
59  void doEraseStroke(entity::Stroke *stroke, int first, int last, cher::EVENT event = cher::EVENT_DRAGGED);
60 
62  void doSelectEntity(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
63 
65  template <typename T1, typename T2>
66  void doSelectCanvas(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa);
67 
70  void doSketch(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
71 
74  void doSketchPolygon(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
75 
77  void doSketchLineSegment(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
78 
80  void doDeleteEntity(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
81 
83  void doEditCanvas(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
84 
86  void doEditCanvasOffset(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
87 
88  /* A sub-method for canvas editing to perform rotation. */
89  void doEditCanvasRotate(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa,
90  osg::Vec3f alongAxis, osg::Vec3f rotAxis);
91 
95  void doCanvasClone(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
96 
100  void doCanvasSeparate(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
101 
103  template <typename T1, typename T2>
104  void doEditPhotoPush(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
105 
107  void doEditEntitiesMove(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
108 
110  void doEditEntitiesScale(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
111 
113  void doEditEntitiesRotate(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
114 
115  /* A method for idle mode of SVM (Single View Metrology) related activity. PolyLineIntersector is used. */
116  void doIdleMouse(const osgGA::GUIEventAdapter & ea, osgGA::GUIActionAdapter & aa);
117 
119  void doHoverWire(const osgGA::GUIEventAdapter & ea, osgGA::GUIActionAdapter & aa);
120 
122  void doHoverPoint(const osgGA::GUIEventAdapter & ea, osgGA::GUIActionAdapter & aa);
123 
125  void doDragPoint(const osgGA::GUIEventAdapter & ea, osgGA::GUIActionAdapter & aa);
126 
128  void doCameraEye(const osgGA::GUIEventAdapter & ea, osgGA::GUIActionAdapter & aa);
129 
131  void doCameraCenter(const osgGA::GUIEventAdapter & ea, osgGA::GUIActionAdapter & aa);
132 
134  void doCameraFocal(const osgGA::GUIEventAdapter & ea, osgGA::GUIActionAdapter & aa);
135 
137  void doPhotoScaleModelPlane(const osgGA::GUIEventAdapter & ea, osgGA::GUIActionAdapter & aa);
138 
140  void doPhotoScaleBookmark(const osgGA::GUIEventAdapter & ea, osgGA::GUIActionAdapter & aa);
141 
142 protected:
144  entity::Stroke* getStroke(const StrokeIntersector::Intersection& result);
145 
146  template <typename EntityType>
147  EntityType* getEntity2D(const Entity2DIntersector<entity::Entity2D>::Intersection& result)
148  {
149  return dynamic_cast<EntityType*>(result.drawable.get());
150  }
151 
153  entity::Canvas* getCanvas(const osgUtil::LineSegmentIntersector::Intersection& result);
154 
156  entity::Photo* getPhoto(const osgUtil::LineSegmentIntersector::Intersection& result);
157 
159  entity::Polygon* getPolygon(const osgUtil::LineSegmentIntersector::Intersection& result);
160 
162  entity::DraggableWire* getDraggableWire(const PolyLineIntersector::Intersection& result);
163 
165  entity::BookmarkTool* getBookmarkTool(const PolyLineIntersector::Intersection& result);
166 
168  int getSelectedPoint(const PointIntersector::Intersection& result);
169 
178  template <typename T>
179  cher::MOUSE_MODE getMouseModeFromName(const T& result, cher::MOUSE_MODE mode_default) const;
180 
185  cher::MOUSE_MODE getMouseModeFromEvent(cher::MOUSE_MODE mode, const osgGA::GUIEventAdapter& ea);
186 
193  template <typename TypeIntersection, typename TypeIntersector>
194  bool getIntersection(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, unsigned int mask,
195  TypeIntersection& resultIntersection);
196 
203  bool getRaytraceCanvasIntersection(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa,
204  double& u, double& v);
205 
209  bool getRaytraceNormalProjection(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa,
210  osg::Vec3f &XC);
211 
217  bool getRaytracePlaneIntersection(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa,
218  const osg::Vec3f& axis, osg::Vec3f& P);
219 
223  template <typename TResult, typename TIntersector>
224  bool setCanvasMouseMode(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, cher::MOUSE_MODE modeDefault, bool selected = true);
225 
226  template <typename TResult, typename TIntersector>
227  std::tuple<bool, TResult> setSVMMouseMode(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, cher::MOUSE_MODE modeDefault);
228 
232  void setDrawableColorFromMode(osg::Drawable* draw);
233 
234  void updateWireGeometry(const PolyLineIntersector::Intersection& intersection);
235  void updatePointGeometry(const PointIntersector::Intersection& intersection);
236  void updateDragPointGeometry(const std::tuple<double, double, bool>& intersection, const osgGA::GUIEventAdapter& ea);
237 
244  void finishAll();
245 
246 protected:
249  osg::observer_ptr<RootScene> m_scene;
251  osg::observer_ptr<entity::DraggableWire> m_selection;
252  osg::observer_ptr<entity::EditableWire> m_selection2;
253  osg::observer_ptr<entity::BookmarkTool> m_tool;
254 };
255 
256 #endif // EVENTHANDLER
257 
entity::Photo * getPhoto(const osgUtil::LineSegmentIntersector::Intersection &result)
Definition: EventHandler.cpp:1049
int getSelectedPoint(const PointIntersector::Intersection &result)
Definition: EventHandler.cpp:1089
cher::MOUSE_MODE getMouseModeFromEvent(cher::MOUSE_MODE mode, const osgGA::GUIEventAdapter &ea)
Definition: EventHandler.cpp:1095
entity::BookmarkTool * getBookmarkTool(const PolyLineIntersector::Intersection &result)
Definition: EventHandler.cpp:1068
void doEditEntitiesRotate(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:713
bool getIntersection(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, unsigned int mask, TypeIntersection &resultIntersection)
Definition: EventHandler.cpp:1445
An OpenSceneGraph events that were passed from Qt&#39;s interface - GLWidget. Event handler is where all ...
Definition: EventHandler.h:47
void doEditPhotoPush(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:1412
void doDeleteEntity(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:386
void doSketch(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:260
void doEditCanvas(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:429
Definition: Canvas.h:31
osg::observer_ptr< RootScene > m_scene
Definition: EventHandler.h:249
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:28
cher::MOUSE_MODE getMouseModeFromName(const T &result, cher::MOUSE_MODE mode_default) const
Definition: EventHandler.cpp:1102
void doPhotoScaleModelPlane(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:927
entity::Canvas * getCanvas(const osgUtil::LineSegmentIntersector::Intersection &result)
Definition: EventHandler.cpp:1038
void doHoverPoint(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:810
EVENT
Definition: Settings.h:160
bool getRaytracePlaneIntersection(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, const osg::Vec3f &axis, osg::Vec3f &P)
Definition: EventHandler.cpp:1163
Geometry class that defined strokes entered by a user. The creation and usage of this class must be f...
Definition: Stroke.h:62
bool getRaytraceCanvasIntersection(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, double &u, double &v)
Definition: EventHandler.cpp:1134
Contains all the entities that will appear on the scene: both user scene and utility entities (i...
Definition: RootScene.h:46
GLWidget * m_glWidget
Definition: EventHandler.h:247
void doCanvasSeparate(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:587
entity::Polygon * getPolygon(const osgUtil::LineSegmentIntersector::Intersection &result)
Definition: EventHandler.cpp:1054
Geometry class that defines opacity polygons drawn by a user. The creation and usage of this class mu...
Definition: Polygon.h:47
MOUSE_MODE
Definition: Settings.h:97
void doHoverWire(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:794
void doEditEntitiesScale(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:665
A proxy class connecting QOpenGLWidget with the content of RootScene; and also to transmit events...
Definition: GLWidget.h:52
void doCameraCenter(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:865
A scene graph class that contains all the geometric entities of entity::SVMData.
Definition: DraggableWire.h:20
void doCanvasClone(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:558
void doEditEntitiesMove(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:617
Settings is a configuration variables file for Cherish: enums, consts, defaults. Contains settings su...
Tool to depict the saved position of a camera and its associated scene state. The BookmarkTool has th...
Definition: ToolGlobal.h:93
void doEditCanvasOffset(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:442
void doCameraEye(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:838
void doSelectEntity(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:1338
Definition: Entity2DIntersector.h:15
entity::Stroke * getStroke(const StrokeIntersector::Intersection &result)
Definition: EventHandler.cpp:1033
void doDragPoint(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:823
void doSketchLineSegment(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:328
void doSelectCanvas(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:1426
cher::MOUSE_MODE m_mode
Definition: EventHandler.h:248
void setDrawableColorFromMode(osg::Drawable *draw)
Definition: EventHandler.cpp:1209
void doPhotoScaleBookmark(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:951
Quad that uses texture to represent a 2D photo in 3D space.
Definition: Photo.h:22
void doCameraFocal(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:892
bool setCanvasMouseMode(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, cher::MOUSE_MODE modeDefault, bool selected=true)
Definition: EventHandler.cpp:1183
entity::DraggableWire * getDraggableWire(const PolyLineIntersector::Intersection &result)
Definition: EventHandler.cpp:1059
void doSketchPolygon(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Definition: EventHandler.cpp:290
void doEraseStroke(entity::Stroke *stroke, int first, int last, cher::EVENT event=cher::EVENT_DRAGGED)
Definition: EventHandler.cpp:250
bool getRaytraceNormalProjection(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, osg::Vec3f &XC)
Definition: EventHandler.cpp:1150
void finishAll()
Definition: EventHandler.cpp:1296