1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkContextInteractorStyle.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME vtkContextInteractorStyle - An interactor for chart views
16 // It observes the user events (mouse events) and propagates them
17 // to the scene. If the scene doesn't eat the event, it is propagated
18 // to the interactor style superclass.
19 //
20 // .SECTION Description
21 
22 #ifndef vtkContextInteractorStyle_h
23 #define vtkContextInteractorStyle_h
24 
25 #include "vtkViewsContext2DModule.h" // For export macro
26 #include "vtkInteractorStyle.h"
27 #include "vtkNew.h" // For ivars
28 #include "vtkWeakPointer.h" // For ivars
29 
30 class vtkContextMouseEvent;
31 class vtkContextScene;
32 
33 class VTKVIEWSCONTEXT2D_EXPORT vtkContextInteractorStyle : public vtkInteractorStyle
34 {
35 public:
36   static vtkContextInteractorStyle *New();
37   vtkTypeMacro(vtkContextInteractorStyle, vtkInteractorStyle);
38   void PrintSelf(ostream& os, vtkIndent indent);
39 
40   // Description:
41   // Set the scene to forward user events to.
42   // Refresh the view when the scene is dirty and no event is being processed.
43   // The scene is observed (vtkCommand::ModifiedEvent) and a refresh on the
44   // view is called appropriately: scene is dirty and no event is being
45   // processed.
46   void SetScene(vtkContextScene* scene);
47 
48   // Description:
49   // Return the observed scene.
50   vtkContextScene* GetScene();
51 
52   // Description:
53   // Called when the scene is modified. Refresh the scene if needed.
54   virtual void OnSceneModified();
55 
56   // Description:
57   // Called when the user moves the mouse
58   // Default behavior forwards the event to the observed scene.
59   virtual void OnMouseMove();
60 
61   // Description:
62   // Called when the user clicks the mouse left button.
63   // Default behavior forwards the event to the observed scene.
64   virtual void OnLeftButtonDown();
65 
66   // Description:
67   // Called when the user releases the mouse left button.
68   // Default behavior forwards the event to the observed scene.
69   virtual void OnLeftButtonUp();
70 
71   // Description:
72   // Called when the user clicks the mouse middle button.
73   // Default behavior forwards the event to the observed scene.
74   virtual void OnMiddleButtonDown();
75 
76   // Description:
77   // Called when the user releases the mouse middle button.
78   // Default behavior forwards the event to the observed scene.
79   virtual void OnMiddleButtonUp();
80 
81   // Description:
82   // Called when the user clicks the mouse right button.
83   // Default behavior forwards the event to the observed scene.
84   virtual void OnRightButtonDown();
85 
86   // Description:
87   // Called when the user releases the mouse right button.
88   // Default behavior forwards the event to the observed scene.
89   virtual void OnRightButtonUp();
90 
91   // Description:
92   // Called when the user moves the mouse wheel forward.
93   // Default behavior forwards the event to the observed scene.
94   virtual void OnMouseWheelForward();
95 
96   // Description:
97   // Called when the user moves the mouse wheel backward.
98   // Default behavior forwards the event to the observed scene.
99   virtual void OnMouseWheelBackward();
100 
101   // Description:
102   // Place holder for future implementation.
103   // Default behavior forwards the event to the observed scene.
104   virtual void OnSelection(unsigned int rect[5]);
105 
106   // Description:
107   // Handle key presses.
108   virtual void OnChar();
109 
110   // Description:
111   // Called when the user presses a key.
112   virtual void OnKeyPress();
113 
114   // Description:
115   // Called when the user releases a key.
116   virtual void OnKeyRelease();
117 
118 protected:
119   vtkContextInteractorStyle();
120   ~vtkContextInteractorStyle();
121 
122   static void ProcessSceneEvents(vtkObject* object, unsigned long event,
123                                  void* clientdata, void* calldata);
124 
125   static void ProcessInteractorEvents(vtkObject* object, unsigned long event,
126                                       void* clientdata, void* calldata);
127 
128   virtual void RenderNow();
129 
130   // Description:
131   // Inform the interactor style that an event is being processed.
132   // That way is knows to not refresh the view (the view will eventually be
133   // refreshed at the end.
134   void BeginProcessingEvent();
135 
136   // Description:
137   // Inform the interactor style that an event is finished to be processed.
138   // If no other event is being processed it check if the scene needs to be
139   // rendered (scene is dirty)
140   void EndProcessingEvent();
141 
142   vtkWeakPointer<vtkContextScene> Scene;
143   vtkNew<vtkCallbackCommand> SceneCallbackCommand;
144   vtkNew<vtkCallbackCommand> InteractorCallbackCommand;
145   int                 ProcessingEvents;
146   unsigned long int   LastSceneRepaintMTime;
147 
148   int                 TimerId;
149   bool                TimerCallbackInitialized;
150 
151 private:
152   vtkContextInteractorStyle(const vtkContextInteractorStyle&); // Not implemented
153   void operator=(const vtkContextInteractorStyle&); // Not implemented
154 
155   void ConstructMouseEvent(vtkContextMouseEvent &event, int button);
156   bool ProcessMousePress(const vtkContextMouseEvent &event);
157 };
158 
159 #endif
160