Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / LightApp / LightApp_Operation.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 //  File   : LightApp_Operation.h
20 //  Author : Sergey LITONIN
21 //  Module : LightApp
22
23 #include <LightApp_Operation.h>
24 #include <LightApp_Module.h>
25 #include <LightApp_Application.h>
26 #include <LightApp_Operation.h>
27 #include <LightApp_SelectionMgr.h>
28 #include <LightApp_Dialog.h>
29
30 #include <SUIT_Desktop.h>
31
32 #include <qapplication.h>
33
34
35 /*!
36  * \brief Constructor
37 *
38 * Constructor sets myModule in NULL and myIsAutoResumed in TRUE
39 */
40 LightApp_Operation::LightApp_Operation()
41 : SUIT_Operation( 0 ),
42   myModule( 0 ),
43   myIsAutoResumed( true )
44 {
45 }
46
47 /*!
48  * \brief Destructor
49 *
50 * Destructor does nothing
51 */
52 LightApp_Operation::~LightApp_Operation()
53 {
54   
55 }
56
57 /*!
58  * \brief Gets module of operation
59   * \return Pointer to the module 
60 *
61 * Gets pointer to the module or NULL if module was not set. It is strongly recomended to
62 * set valid pointer on the module before start of operation
63 */
64 LightApp_Module* LightApp_Operation::module() const
65 {
66   return myModule;
67 }
68
69
70 /*!
71  * \brief Sets module of operation
72  * \param theModule - module to be set
73 *
74 * Sets pointer to the module. It is strongly recomended to set valid pointer on the
75 * module before start of operation
76 */
77 void LightApp_Operation::setModule( LightApp_Module* theModule )
78 {
79   myModule = theModule;
80   setApplication( myModule ? myModule->application() : 0 );
81   setStudy( application() ? application()->activeStudy() : 0 );
82 }
83
84 /*!
85  * \brief Gets desktop of operation
86   * \return Pointer to the desktop
87 *
88 * Gets pointer to the desktop or NULL if application was not set. It is strongly recomended
89 * to set valid pointer on the application before start of operation
90 */
91 SUIT_Desktop* LightApp_Operation::desktop() const
92 {
93   return application() != 0 ? application()->desktop() : 0;
94 }
95
96 /*!
97  * \brief Enable dialog of operation
98 *
99 * Virtual method redefined from the base class. Enable dialog if it was desabled (in
100 * suspend method) and activate selection
101 */
102 void LightApp_Operation::resumeOperation()
103 {
104   SUIT_Operation::resumeOperation();
105   setDialogActive( true );
106 }
107
108 /*!
109  * \brief Performs actions needed for starting operation
110 *
111 * Virtual method redefined from the base class. Connect signal of selection manager to
112 * onSelectionDone() slot
113 */
114 void LightApp_Operation::startOperation()
115 {
116   if( selectionMgr() )
117     connect( selectionMgr(), SIGNAL( selectionChanged() ), SLOT( onSelectionDone() ) );
118     
119   //If suspended operation was stopped during starting other operation,
120   //the dialog is inactive now, We must activate it
121   setDialogActive( true );
122 }
123
124 /*!
125  * \brief Performs actions needed for suspending operation
126 *
127 * Virtual method redefined from the base class. This implementation calls corresponding
128 * method of base class and cals setDialogActive( false )
129 */
130 void LightApp_Operation::suspendOperation()
131 {
132   SUIT_Operation::suspendOperation();
133   setDialogActive( false );
134 }
135
136 /*!
137  * \brief Performs actions needed for aborting operation
138 *
139 * Virtual method redefined from the base class calls corresponding method of base class
140 * and hides dialog box (if it is exists), disconnect slots from selection manager
141 */
142 void LightApp_Operation::abortOperation()
143 {
144   SUIT_Operation::abortOperation();
145   setDialogActive( true );
146   if ( dlg() )
147     dlg()->hide();
148
149   if( selectionMgr() )
150     disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionDone() ) );
151 }
152
153 /*!
154  * \brief Performs actions needed for committing operation
155 *
156 * Virtual method redefined from the base class calls corresponding method of base class
157 * and hides dialog box (if it is exists), disconnect slots from selection manager
158 */
159 void LightApp_Operation::commitOperation()
160 {
161   SUIT_Operation::commitOperation();
162   setDialogActive( true );
163   if ( dlg() )
164     dlg()->hide();
165
166   if( selectionMgr() )
167     disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionDone() ) );
168 }
169
170 /*!
171  * \brief Gets dialog
172   * \return Pointer to the dialog of this operation or NULL if it does not exist
173 *
174 * This method should be redefined in derived classes if they use dialogs. If this
175 * function returns pointer to dialog then dialog will be correctly
176 * -# deactivated in suspendOperation method
177 * -# activated in resumeOperation method
178 * -# hidden in abortOperation and commitOperation methods
179 */
180 LightApp_Dialog* LightApp_Operation::dlg() const
181 {
182   return 0;
183 }
184
185 /*!
186  * \brief Activates selection
187 *
188 * Virtual method should be redefined in derived classes if they use own selection modes
189 * (different from default)
190 */
191 void LightApp_Operation::activateSelection()
192 {
193 }
194
195 /*!
196  * \brief Virtual method called when selection is changed
197 *
198 * Virtual method should be redefined in derived classes if they works with selection
199 * to provide reaction on the change of selection
200 */
201 void LightApp_Operation::selectionDone()
202 {
203 }
204
205 /*!
206  * \brief Gets active operation
207 *
208 * This method provided for convinience calls SUIT_Study::activeOperation() one
209 */
210 SUIT_Operation* LightApp_Operation::activeOperation() const
211 {
212   return study() != 0 ? study()->activeOperation() : 0;
213 }
214
215 /*!
216  * \brief Gets selection manager
217 *
218 * This method provided for convinience calls LightApp_Application::selectionMgr() one
219 */
220 LightApp_SelectionMgr* LightApp_Operation::selectionMgr() const
221 {
222   SUIT_Application* app = application();
223   if ( app != 0 && app->inherits( "LightApp_Application" ) )
224     return ( (LightApp_Application*)app )->selectionMgr();
225   else
226     return 0;
227 }
228
229 /*!
230  * \brief Call selectionDone() method 
231 *
232 * Call selectionDone() method if operator is an active one (see selectionDone() for more
233 * description )
234 */
235 void LightApp_Operation::onSelectionDone()
236 {
237   if ( isActive() )
238     selectionDone();
239 }
240
241 /*!
242  * \brief Update object browser or/and viewer etc.
243  * \param flags - update flags
244 *
245 * This method provided for convinience calls LightApp_Module::update() one (see
246 * LightApp_Module::update() for more description)
247 */
248 void LightApp_Operation::update( const int flags )
249 {
250   if ( myModule != 0 )
251     myModule->update( flags );
252 }
253
254 /*!
255  * \brief Activate/Deactivate dialog of operation
256  * \param active - State of the dialog to be set
257 *
258 * Activate/Deactivate dialog of operation. This method called from startOperation(),
259 * suspendOperation() ones and so on
260 */
261 void LightApp_Operation::setDialogActive( const bool active )
262 {
263   if( dlg() )
264   {
265     if( active )
266     {
267       activateSelection();
268       dlg()->setActiveWindow();
269     }
270   }
271 }
272
273 /*!
274  * \brief Gets autoresume property
275  * \return Autoresume property.
276 *
277 * Autoresume property is used during automatic resuming operation. If operation is
278 * suspended and cursor is moved above dialog of the operation then operation is resumed
279 * automatically (if possible). It can be resumed only program call otherwise (see
280 * LightApp_SwitchOp for more description). This property is TRUE by default and may be
281 * changed with setAutoResumed() method call.
282 */
283 bool LightApp_Operation::isAutoResumed() const
284 {
285   return myIsAutoResumed;
286 }
287
288 /*!
289  * \brief Sets autoresume property
290  * \param on - Value to be set
291  * \return Autoresume property.
292 *
293 * Sets autoresume property (see isAutoResumed() for more description)
294 */
295 void LightApp_Operation::setAutoResumed( const bool on )
296 {
297   myIsAutoResumed = on;
298 }