3 // Copyright (C) 2005 CEA/DEN, EDF R&D
7 // File : SalomeApp_Operation.h
8 // Author : Sergey LITONIN
11 #include <SalomeApp_Operation.h>
12 #include <SalomeApp_Module.h>
13 #include <SalomeApp_Application.h>
14 #include <SalomeApp_Operation.h>
15 #include <SalomeApp_SelectionMgr.h>
16 #include <SalomeApp_Dialog.h>
18 #include <SUIT_Desktop.h>
20 #include <qapplication.h>
26 * Constructor sets myModule in NULL and myIsAutoResumed in TRUE
28 SalomeApp_Operation::SalomeApp_Operation()
29 : SUIT_Operation( 0 ),
31 myIsAutoResumed( true )
38 * Destructor does nothing
40 SalomeApp_Operation::~SalomeApp_Operation()
46 * \brief Gets module of operation
47 * \return Pointer to the module
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
52 SalomeApp_Module* SalomeApp_Operation::module() const
59 * \brief Sets module of operation
60 * \param theModule - module to be set
62 * Sets pointer to the module. It is strongly recomended to set valid pointer on the
63 * module before start of operation
65 void SalomeApp_Operation::setModule( SalomeApp_Module* theModule )
68 setApplication( myModule ? myModule->application() : 0 );
69 setStudy( application() ? application()->activeStudy() : 0 );
73 * \brief Gets desktop of operation
74 * \return Pointer to the desktop
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
79 SUIT_Desktop* SalomeApp_Operation::desktop() const
81 return application() != 0 ? application()->desktop() : 0;
85 * \brief Enable dialog of operation
87 * Virtual method redefined from the base class. Enable dialog if it was desabled (in
88 * suspend method) and activate selection
90 void SalomeApp_Operation::resumeOperation()
92 SUIT_Operation::resumeOperation();
93 setDialogActive( true );
97 * \brief Performs actions needed for starting operation
99 * Virtual method redefined from the base class. Connect signal of selection manager to
100 * onSelectionDone() slot
102 void SalomeApp_Operation::startOperation()
105 connect( selectionMgr(), SIGNAL( selectionChanged() ), SLOT( onSelectionDone() ) );
107 //If suspended operation was stopped during starting other operation,
108 //the dialog is inactive now, We must activate it
109 setDialogActive( true );
113 * \brief Performs actions needed for suspending operation
115 * Virtual method redefined from the base class. This implementation calls corresponding
116 * method of base class and cals setDialogActive( false )
118 void SalomeApp_Operation::suspendOperation()
120 SUIT_Operation::suspendOperation();
121 setDialogActive( false );
124 //=======================================================================
125 // name : abortOperation
126 // Purpose : Hide dialog box (if it is exists)
127 //=======================================================================
129 * \brief Performs actions needed for aborting operation
131 * Virtual method redefined from the base class calls corresponding method of base class
132 * and hides dialog box (if it is exists), disconnect slots from selection manager
134 void SalomeApp_Operation::abortOperation()
136 SUIT_Operation::abortOperation();
137 setDialogActive( true );
142 disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionDone() ) );
146 * \brief Performs actions needed for committing operation
148 * Virtual method redefined from the base class calls corresponding method of base class
149 * and hides dialog box (if it is exists), disconnect slots from selection manager
151 void SalomeApp_Operation::commitOperation()
153 SUIT_Operation::commitOperation();
154 setDialogActive( true );
159 disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionDone() ) );
164 * \return Pointer to the dialog of this operation or NULL if it does not exist
166 * This method should be redefined in derived classes if they use dialogs. If this
167 * function returns pointer to dialog then dialog will be correctly
168 * -# deactivated in suspendOperation method
169 * -# activated in resumeOperation method
170 * -# hidden in abortOperation and commitOperation methods
172 SalomeApp_Dialog* SalomeApp_Operation::dlg() const
178 * \brief Activates selection
180 * Virtual method should be redefined in derived classes if they use own selection modes
181 * (different from default)
183 void SalomeApp_Operation::activateSelection()
188 * \brief Virtual method called when selection is changed
190 * Virtual method should be redefined in derived classes if they works with selection
191 * to provide reaction on the change of selection
193 void SalomeApp_Operation::selectionDone()
198 * \brief Gets active operation
200 * This method provided for convinience calls SUIT_Study::activeOperation() one
202 SUIT_Operation* SalomeApp_Operation::activeOperation() const
204 return study() != 0 ? study()->activeOperation() : 0;
208 * \brief Gets selection manager
210 * This method provided for convinience calls SalomeApp_Application::selectionMgr() one
212 SalomeApp_SelectionMgr* SalomeApp_Operation::selectionMgr() const
214 SUIT_Application* app = application();
215 if ( app != 0 && app->inherits( "SalomeApp_Application" ) )
216 return ( (SalomeApp_Application*)app )->selectionMgr();
222 * \brief Call selectionDone() method
224 * Call selectionDone() method if operator is an active one (see selectionDone() for more
227 void SalomeApp_Operation::onSelectionDone()
234 * \brief Update object browser or/and viewer etc.
235 * \param flags - update flags
237 * This method provided for convinience calls SalomeApp_Module::update() one (see
238 * SalomeApp_Module::update() for more description)
240 void SalomeApp_Operation::update( const int flags )
243 myModule->update( flags );
247 * \brief Activate/Deactivate dialog of operation
248 * \param active - State of the dialog to be set
250 * Activate/Deactivate dialog of operation. This method called from startOperation(),
251 * suspendOperation() ones and so on
253 void SalomeApp_Operation::setDialogActive( const bool active )
260 dlg()->setActiveWindow();
266 * \brief Gets autoresume property
267 * \return Autoresume property.
269 * Autoresume property is used during automatic resuming operation. If operation is
270 * suspended and cursor is moved above dialog of the operation then operation is resumed
271 * automatically (if possible). It can be resumed only program call otherwise (see
272 * SalomeApp_SwitchOp for more description). This property is TRUE by default and may be
273 * changed with setAutoResumed() method call.
275 bool SalomeApp_Operation::isAutoResumed() const
277 return myIsAutoResumed;
281 * \brief Sets autoresume property
282 * \param on - Value to be set
283 * \return Autoresume property.
285 * Sets autoresume property (see isAutoResumed() for more description)
287 void SalomeApp_Operation::setAutoResumed( const bool on )
289 myIsAutoResumed = on;