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