1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : LightApp_Operation.h
20 // Author : Sergey LITONIN
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>
30 #include <SUIT_Desktop.h>
32 #include <qapplication.h>
38 * Constructor sets myModule in NULL and myIsAutoResumed in TRUE
40 LightApp_Operation::LightApp_Operation()
41 : SUIT_Operation( 0 ),
43 myIsAutoResumed( true )
50 * Destructor does nothing
52 LightApp_Operation::~LightApp_Operation()
58 * \brief Gets module of operation
59 * \return Pointer to the module
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
64 LightApp_Module* LightApp_Operation::module() const
71 * \brief Sets module of operation
72 * \param theModule - module to be set
74 * Sets pointer to the module. It is strongly recomended to set valid pointer on the
75 * module before start of operation
77 void LightApp_Operation::setModule( LightApp_Module* theModule )
80 setApplication( myModule ? myModule->application() : 0 );
81 setStudy( application() ? application()->activeStudy() : 0 );
85 * \brief Gets desktop of operation
86 * \return Pointer to the desktop
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
91 SUIT_Desktop* LightApp_Operation::desktop() const
93 return application() != 0 ? application()->desktop() : 0;
97 * \brief Enable dialog of operation
99 * Virtual method redefined from the base class. Enable dialog if it was desabled (in
100 * suspend method) and activate selection
102 void LightApp_Operation::resumeOperation()
104 SUIT_Operation::resumeOperation();
105 setDialogActive( true );
109 * \brief Performs actions needed for starting operation
111 * Virtual method redefined from the base class. Connect signal of selection manager to
112 * onSelectionDone() slot
114 void LightApp_Operation::startOperation()
117 connect( selectionMgr(), SIGNAL( selectionChanged() ), SLOT( onSelectionDone() ) );
119 //If suspended operation was stopped during starting other operation,
120 //the dialog is inactive now, We must activate it
121 setDialogActive( true );
125 * \brief Performs actions needed for suspending operation
127 * Virtual method redefined from the base class. This implementation calls corresponding
128 * method of base class and cals setDialogActive( false )
130 void LightApp_Operation::suspendOperation()
132 SUIT_Operation::suspendOperation();
133 setDialogActive( false );
137 * \brief Performs actions needed for aborting operation
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
142 void LightApp_Operation::abortOperation()
144 SUIT_Operation::abortOperation();
145 setDialogActive( true );
150 disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionDone() ) );
154 * \brief Performs actions needed for committing operation
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
159 void LightApp_Operation::commitOperation()
161 SUIT_Operation::commitOperation();
162 setDialogActive( true );
167 disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionDone() ) );
172 * \return Pointer to the dialog of this operation or NULL if it does not exist
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
180 LightApp_Dialog* LightApp_Operation::dlg() const
186 * \brief Activates selection
188 * Virtual method should be redefined in derived classes if they use own selection modes
189 * (different from default)
191 void LightApp_Operation::activateSelection()
196 * \brief Virtual method called when selection is changed
198 * Virtual method should be redefined in derived classes if they works with selection
199 * to provide reaction on the change of selection
201 void LightApp_Operation::selectionDone()
206 * \brief Gets active operation
208 * This method provided for convinience calls SUIT_Study::activeOperation() one
210 SUIT_Operation* LightApp_Operation::activeOperation() const
212 return study() != 0 ? study()->activeOperation() : 0;
216 * \brief Gets selection manager
218 * This method provided for convinience calls LightApp_Application::selectionMgr() one
220 LightApp_SelectionMgr* LightApp_Operation::selectionMgr() const
222 SUIT_Application* app = application();
223 if ( app != 0 && app->inherits( "LightApp_Application" ) )
224 return ( (LightApp_Application*)app )->selectionMgr();
230 * \brief Call selectionDone() method
232 * Call selectionDone() method if operator is an active one (see selectionDone() for more
235 void LightApp_Operation::onSelectionDone()
242 * \brief Update object browser or/and viewer etc.
243 * \param flags - update flags
245 * This method provided for convinience calls LightApp_Module::update() one (see
246 * LightApp_Module::update() for more description)
248 void LightApp_Operation::update( const int flags )
251 myModule->update( flags );
255 * \brief Activate/Deactivate dialog of operation
256 * \param active - State of the dialog to be set
258 * Activate/Deactivate dialog of operation. This method called from startOperation(),
259 * suspendOperation() ones and so on
261 void LightApp_Operation::setDialogActive( const bool active )
268 dlg()->setActiveWindow();
274 * \brief Gets autoresume property
275 * \return Autoresume property.
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.
283 bool LightApp_Operation::isAutoResumed() const
285 return myIsAutoResumed;
289 * \brief Sets autoresume property
290 * \param on - Value to be set
291 * \return Autoresume property.
293 * Sets autoresume property (see isAutoResumed() for more description)
295 void LightApp_Operation::setAutoResumed( const bool on )
297 myIsAutoResumed = on;