Salome HOME
e00c8dabba627c0370dbb923df1d5bf53a6b9eae
[modules/gui.git] / src / SVTK / SVTK_GenericRenderWindowInteractor.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SALOME VTKViewer : build VTK viewer into Salome desktop
23 //  File   : 
24 //  Author : 
25 //  Module : SALOME
26 //  $Header$
27 //
28 #include "SVTK_GenericRenderWindowInteractor.h"
29 #include "SVTK_Selector.h"
30
31 #include <vtkObjectFactory.h>
32 #include <vtkCommand.h>
33
34 #include <QTimer>
35
36 using namespace std;
37
38 vtkStandardNewMacro(QVTK_GenericRenderWindowInteractor);
39
40 /*!
41   Constructor
42 */
43 QVTK_GenericRenderWindowInteractor
44 ::QVTK_GenericRenderWindowInteractor()
45 {
46   myTimer = new QTimer( ) ;
47   connect(myTimer, SIGNAL(timeout()), this, SLOT(OnTimeOut())) ;
48 }
49
50 /*!
51   Destructor
52 */
53 QVTK_GenericRenderWindowInteractor
54 ::~QVTK_GenericRenderWindowInteractor()
55 {
56   delete myTimer;
57 }
58
59 /*!
60   The slot connects to QTimer::timeout signal to invoke vtkCommand::TimerEvent
61 */
62 void
63 QVTK_GenericRenderWindowInteractor
64 ::OnTimeOut() 
65 {
66   if( GetEnabled() ) {
67     this->InvokeEvent(vtkCommand::TimerEvent,NULL);
68   }
69 }
70
71 /*!
72   Starts the QTimer instance on defined microseconds
73 */
74 int
75 QVTK_GenericRenderWindowInteractor
76 ::CreateTimer(int vtkNotUsed(timertype)) 
77 {
78   //
79   // Start a one-shot timer for <DELAY> ms. 
80   //
81   static int DELAY = 1;
82   myTimer->setSingleShot(TRUE);
83   myTimer->start(DELAY);
84   return 1;
85 }
86
87 /*!
88   Stops the QTimer instance
89 */
90 int
91 QVTK_GenericRenderWindowInteractor
92 ::DestroyTimer(void) 
93 {
94   //
95   // :TRICKY: Tue May  2 00:17:32 2000 Pagey
96   //
97   // QTimer will automatically expire after 10ms. So 
98   // we do not need to do anything here. In fact, we 
99   // should not even Stop() the QTimer here because doing 
100   // this will skip some of the processing that the TimerFunc()
101   // does and will result in undesirable effects. For 
102   // example, this will result in vtkLODActor to leave
103   // the models in low-res mode after the mouse stops
104   // moving. 
105   //
106   return 1;
107 }
108
109
110 vtkStandardNewMacro(SVTK_GenericRenderWindowInteractor);
111
112 /*!
113   Constructor
114 */
115 SVTK_GenericRenderWindowInteractor
116 ::SVTK_GenericRenderWindowInteractor():
117   myRenderWidget(NULL)
118 {
119 }
120
121 /*!
122   Destructor
123 */
124 SVTK_GenericRenderWindowInteractor
125 ::~SVTK_GenericRenderWindowInteractor()
126 {
127 }
128
129 /*!
130   To get access to SVTK_Selector
131 */
132 SVTK_Selector*
133 SVTK_GenericRenderWindowInteractor
134 ::GetSelector()
135 {
136   return mySelector;
137 }
138
139 /*!
140   To initialize mySelector field
141   \param theSelector - new selector
142 */
143 void
144 SVTK_GenericRenderWindowInteractor
145 ::SetSelector(SVTK_Selector* theSelector)
146 {
147   mySelector = theSelector;
148 }
149
150 /*!
151   To get access to QWidget, where vtkRenderWindow maps to.
152 */
153 QWidget*
154 SVTK_GenericRenderWindowInteractor
155 ::GetRenderWidget()
156 {
157   return myRenderWidget;
158 }
159
160 /*!
161   To initialize myRenderWidget field.
162 */
163 void
164 SVTK_GenericRenderWindowInteractor
165 ::SetRenderWidget(QWidget* theRenderWidget)
166 {
167   myRenderWidget = theRenderWidget;
168 }