1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : LightApp_Operation.h
24 // Author : Sergey LITONIN
27 #include "LightApp_Operation.h"
28 #include "LightApp_Module.h"
29 #include "LightApp_Application.h"
30 #include "LightApp_SelectionMgr.h"
31 #include "LightApp_Dialog.h"
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Study.h>
39 * Constructor sets myModule in NULL and myIsAutoResumed in \c true
41 LightApp_Operation::LightApp_Operation()
42 : SUIT_Operation( 0 ),
44 myIsAutoResumed( true )
51 * Destructor does nothing
53 LightApp_Operation::~LightApp_Operation()
59 * \brief Gets module of operation
60 * \return Pointer to the module
62 * Gets pointer to the module or NULL if module was not set. It is strongly recomended to
63 * set valid pointer on the module before start of operation
65 LightApp_Module* LightApp_Operation::module() const
72 * \brief Sets module of operation
73 * \param theModule - module to be set
75 * Sets pointer to the module. It is strongly recomended to set valid pointer on the
76 * module before start of operation
78 void LightApp_Operation::setModule( LightApp_Module* theModule )
81 setApplication( myModule ? myModule->application() : 0 );
82 setStudy( application() ? application()->activeStudy() : 0 );
86 * \brief Gets desktop of operation
87 * \return Pointer to the desktop
89 * Gets pointer to the desktop or NULL if application was not set. It is strongly recomended
90 * to set valid pointer on the application before start of operation
92 SUIT_Desktop* LightApp_Operation::desktop() const
94 return application() != 0 ? application()->desktop() : 0;
98 * \brief Enable dialog of operation
100 * Virtual method redefined from the base class. Enable dialog if it was desabled (in
101 * suspend method) and activate selection
103 void LightApp_Operation::resumeOperation()
105 SUIT_Operation::resumeOperation();
106 setDialogActive( true );
110 * \brief Performs actions needed for starting operation
112 * Virtual method redefined from the base class. Connect signal of selection manager to
113 * onSelectionDone() slot
115 void LightApp_Operation::startOperation()
118 connect( selectionMgr(), SIGNAL( selectionChanged() ), SLOT( onSelectionDone() ) );
120 //If suspended operation was stopped during starting other operation,
121 //the dialog is inactive now, We must activate it
122 setDialogActive( true );
126 * \brief Performs actions needed for suspending operation
128 * Virtual method redefined from the base class. This implementation calls corresponding
129 * method of base class and cals setDialogActive( false )
131 void LightApp_Operation::suspendOperation()
133 SUIT_Operation::suspendOperation();
134 setDialogActive( false );
138 * \brief Performs actions needed for aborting operation
140 * Virtual method redefined from the base class calls corresponding method of base class
141 * and hides dialog box (if it is exists), disconnect slots from selection manager
143 void LightApp_Operation::abortOperation()
145 SUIT_Operation::abortOperation();
146 setDialogActive( true );
151 disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionDone() ) );
155 * \brief Performs actions needed for committing operation
157 * Virtual method redefined from the base class calls corresponding method of base class
158 * and hides dialog box (if it is exists), disconnect slots from selection manager
160 void LightApp_Operation::commitOperation()
162 SUIT_Operation::commitOperation();
163 setDialogActive( true );
168 disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionDone() ) );
173 * \return Pointer to the dialog of this operation or NULL if it does not exist
175 * This method should be redefined in derived classes if they use dialogs. If this
176 * function returns pointer to dialog then dialog will be correctly
177 * -# deactivated in suspendOperation method
178 * -# activated in resumeOperation method
179 * -# hidden in abortOperation and commitOperation methods
181 LightApp_Dialog* LightApp_Operation::dlg() const
187 * \brief Activates selection
189 * Virtual method should be redefined in derived classes if they use own selection modes
190 * (different from default)
192 void LightApp_Operation::activateSelection()
197 * \brief Virtual method called when selection is changed
199 * Virtual method should be redefined in derived classes if they works with selection
200 * to provide reaction on the change of selection
202 void LightApp_Operation::selectionDone()
207 * \brief Gets active operation
209 * This method provided for convinience calls SUIT_Study::activeOperation() one
211 SUIT_Operation* LightApp_Operation::activeOperation() const
213 return study() != 0 ? study()->activeOperation() : 0;
217 * \brief Gets selection manager
219 * This method provided for convinience calls LightApp_Application::selectionMgr() one
221 LightApp_SelectionMgr* LightApp_Operation::selectionMgr() const
223 SUIT_Application* app = application();
224 if ( app != 0 && app->inherits( "LightApp_Application" ) )
225 return ( (LightApp_Application*)app )->selectionMgr();
231 * \brief Call selectionDone() method
233 * Call selectionDone() method if operator is an active one (see selectionDone() for more
236 void LightApp_Operation::onSelectionDone()
243 * \brief Update object browser or/and viewer etc.
244 * \param flags - update flags
246 * This method provided for convinience calls LightApp_Module::update() one (see
247 * LightApp_Module::update() for more description)
249 void LightApp_Operation::update( const int flags )
252 myModule->update( flags );
256 * \brief Activate/Deactivate dialog of operation
257 * \param active - State of the dialog to be set
259 * Activate/Deactivate dialog of operation. This method called from startOperation(),
260 * suspendOperation() ones and so on
262 void LightApp_Operation::setDialogActive( const bool active )
269 dlg()->activateWindow();
275 * \brief Gets autoresume property
276 * \return Autoresume property.
278 * Autoresume property is used during automatic resuming operation. If operation is
279 * suspended and cursor is moved above dialog of the operation then operation is resumed
280 * automatically (if possible). It can be resumed only program call otherwise (see
281 * LightApp_SwitchOp for more description). This property is \c true by default and may be
282 * changed with setAutoResumed() method call.
284 bool LightApp_Operation::isAutoResumed() const
286 return myIsAutoResumed;
290 * \brief Sets autoresume property
291 * \param on - Value to be set
292 * \return Autoresume property.
294 * Sets autoresume property (see isAutoResumed() for more description)
296 void LightApp_Operation::setAutoResumed( const bool on )
298 myIsAutoResumed = on;