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 #include "SUIT_Study.h"
21 #include "SUIT_Desktop.h"
22 #include "SUIT_Operation.h"
23 #include "SUIT_DataObject.h"
24 #include "SUIT_MessageBox.h"
25 #include "SUIT_Application.h"
26 #include <qvaluevector.h>
29 * Support study management. Object management. Operation management.
33 SUIT_Study::SUIT_Study( SUIT_Application* app )
37 myIsModified( false ),
39 myBlockChangeState( false )
45 myRoot = new SUIT_DataObject();
46 myOperations.setAutoDelete( false );
47 myOperations.setAutoDelete( false );
51 SUIT_Study::~SUIT_Study()
60 int SUIT_Study::id() const
66 *\retval root data object.
68 SUIT_DataObject* SUIT_Study::root() const
76 SUIT_Application* SUIT_Study::application() const
84 QString SUIT_Study::studyName() const
90 *\retval active operation.
92 SUIT_Operation* SUIT_Study::activeOperation() const
94 return myOperations.count() > 0 ? myOperations.getLast() : 0;
98 *\retval TRUE - if study saved, else FALSE.
100 bool SUIT_Study::isSaved() const
106 *\retval TRUE - if study modified, else FALSE.
108 bool SUIT_Study::isModified() const
114 *Close document. NOT IMPLEMENTED.
116 void SUIT_Study::closeDocument(bool permanently)
121 Custom document initialization to be performed \n
122 within onNewDoc() handler can be put here
124 void SUIT_Study::createDocument()
129 * Open document. Sets file name. return true.
131 bool SUIT_Study::openDocument( const QString& fileName )
135 myIsModified = false;
141 * Save document as \a fileName. Set file name.
143 bool SUIT_Study::saveDocumentAs( const QString& fileName )
147 myIsModified = false;
153 *\retval TRUE - if document saved successful, else FALSE.
155 bool SUIT_Study::saveDocument()
157 return saveDocumentAs( myName );
161 *Abort all operations.
163 void SUIT_Study::abortAllOperations()
165 myBlockChangeState = true;
166 for( SUIT_Operation* op = myOperations.first(); op; op = myOperations.next() )
168 myBlockChangeState = false;
169 myOperations.clear();
173 Update study. NOT IMPLEMENTED HERE.
175 void SUIT_Study::update()
182 void SUIT_Study::sendChangesNotification()
184 emit studyModified( this );
188 Set study saved to \a on.
190 void SUIT_Study::setIsSaved( const bool on )
196 Set study modified to \a on.
198 void SUIT_Study::setIsModified( const bool on )
204 Set study modified to \a on.
206 void SUIT_Study::Modified()
208 setIsModified( TRUE );
209 sendChangesNotification();
215 void SUIT_Study::setRoot( SUIT_DataObject* obj )
220 // This is necessary in order not to destroy the complete tree of objects
222 obj->reparentChildren( myRoot );
231 void SUIT_Study::setStudyName( const QString& name )
237 * \brief Verifies whether operation can be activated above already started ones
238 * \param theOp - operation to be checked
239 * \return NULL if operation can be activated, pointer to operation which denies
240 * starting tested operation
242 * Verifies whether operation can be activated above already started ones. This method
243 * is called from SUIT_Study::start() and SUIT_Study::resume() methods.
245 SUIT_Operation* SUIT_Study::blockingOperation( SUIT_Operation* theOp ) const
247 if( theOp->isGranted() )
250 Operations tmpOps( myOperations );
251 SUIT_Operation* anOp = 0;
252 for ( anOp = tmpOps.last(); anOp; anOp = tmpOps.prev() )
254 if ( anOp != 0 && anOp!= theOp && !anOp->isValid( theOp ) )
262 * \brief Starts operation
263 * \param theOp - operation to be started
264 * \param toCheck - if parameters is equal TRUE then checking performed whether
265 * all already started operations allow to start this operation above them (default
267 * \return TRUE if operation is started, FALSE otherwise
269 * Verifies whether theOp operation can be started above already started ones (if toCheck
270 * parameter is equal TRUE) and starts it
272 bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck )
274 if ( !theOp || myOperations.find( theOp ) >= 0 )
277 theOp->setExecStatus( SUIT_Operation::Rejected );
278 theOp->setStudy( this );
280 if ( !theOp->isReadyToStart() )
285 while( SUIT_Operation* anOp = blockingOperation( theOp ) )
287 int anAnsw = SUIT_MessageBox::warn2( application()->desktop(),
288 tr( "OPERATION_LAUNCH" ), tr( "PREVIOUS_NOT_FINISHED" ),
289 tr( "CONTINUE" ), tr( "CANCEL" ), 0, 1, 1 );
298 SUIT_Operation* anOp = activeOperation();
301 activeOperation()->suspendOperation();
302 anOp->setState( SUIT_Operation::Suspended );
305 theOp->setState( SUIT_Operation::Running );
306 myOperations.append( theOp );
308 emit theOp->started( theOp );
309 operationStarted( theOp );
310 theOp->startOperation();
316 * \brief Aborts operation
317 * \param theOp - operation to be aborted
318 * \return TRUE if operation is aborted successfully
320 * Verifies whether operation already started and aborts it in this case (sets execution
321 * status to Rejected and stops operation)
323 bool SUIT_Study::abort( SUIT_Operation* theOp )
325 if ( !theOp || myOperations.find( theOp ) == -1 )
328 theOp->setExecStatus( SUIT_Operation::Rejected );
330 theOp->abortOperation();
331 operationAborted( theOp );
332 emit theOp->aborted( theOp );
340 * \brief Commits operation
341 * \param theOp - operation to be committed
342 * \return TRUE if operation is committed successfully
344 * Verifies whether operation already started and commits it in this case (sets execution
345 * status to Accepted and stops operation)
347 bool SUIT_Study::commit( SUIT_Operation* theOp )
349 if ( !theOp || myOperations.find( theOp ) == -1 )
352 theOp->setExecStatus( SUIT_Operation::Accepted );
354 theOp->commitOperation();
355 operationCommited( theOp );
356 emit theOp->committed( theOp );
360 emit studyModified( this );
366 * \brief Commits operation
367 * \param theOp - operation to be committed
368 * \return TRUE if operation is suspended successfully
370 * Verifies whether operation already started and suspends it in this case. Operations
371 * ususlly are suspended to start other one above them.
373 bool SUIT_Study::suspend( SUIT_Operation* theOp )
375 if ( !theOp || myOperations.find( theOp ) == -1 || theOp->state() == SUIT_Operation::Suspended )
378 theOp->setState( SUIT_Operation::Suspended );
379 theOp->suspendOperation();
380 emit theOp->suspended( theOp );
386 * \brief Resumes operation
387 * \param theOp - operation to be resumed
388 * \return TRUE if operation is aborted successfully
390 * Verifies whether operation already started but suspended and resumesit in this case.
392 bool SUIT_Study::resume( SUIT_Operation* theOp )
394 if ( !theOp || myOperations.find( theOp ) == -1 ||
395 theOp->state() == SUIT_Operation::Running ||
396 blockingOperation( theOp ) != 0 )
399 if ( myOperations.count() > 0 )
400 suspend( myOperations.last() );
402 theOp->setState( SUIT_Operation::Running );
403 theOp->resumeOperation();
405 // Move operation at the end of list in order to sort it in the order of activation.
406 // As result active operation is a last operation of list, operation which was active
407 // before currently active operation is located before it and so on
408 myOperations.remove( theOp );
409 myOperations.append( theOp );
411 emit theOp->resumed( theOp );
416 * \brief Stops operation
417 * \param theOp - operation to be stopped
419 * Stops operation. This private method is called from abort() and commit() ones to perform
420 * common actions when operation is stopped
422 void SUIT_Study::stop( SUIT_Operation* theOp )
424 theOp->setState( SUIT_Operation::Waiting );
425 myOperations.remove( theOp );
427 // get last operation which can be resumed
428 SUIT_Operation* anOp, *aResultOp = 0;
429 for ( anOp = myOperations.last(); anOp; anOp = myOperations.prev() )
431 if ( anOp && anOp != theOp && blockingOperation( anOp ) == 0 )
438 theOp->stopOperation();
439 operationStopped( theOp );
440 emit theOp->stopped( theOp );
447 * \brief Get all started operations
448 * \return List of all started operations
450 const QPtrList<SUIT_Operation>& SUIT_Study::operations() const
456 * \brief Perform some actions when operation starting
458 void SUIT_Study::operationStarted( SUIT_Operation* op )
463 if ( op->testFlags( SUIT_Operation::Transaction ) )
464 op->openTransaction();
468 * \brief Perform some actions when operation aborted
470 void SUIT_Study::operationAborted( SUIT_Operation* op )
472 if ( op->testFlags( SUIT_Operation::Transaction ) )
473 op->abortTransaction();
477 * \brief Perform some actions when operation commited
479 void SUIT_Study::operationCommited( SUIT_Operation* op )
481 if ( op->testFlags( SUIT_Operation::Transaction ) )
482 op->commitTransaction( op->operationName() );
486 * \brief Perform some actions when operation stopped
488 void SUIT_Study::operationStopped( SUIT_Operation* )
493 * \brief Opens transaction for data modifications.
495 bool SUIT_Study::openTransaction()
501 * \brief Aborts transaction and all performed data modifications.
503 bool SUIT_Study::abortTransaction()
509 * \brief Commits transaction and all performed data modifications.
511 bool SUIT_Study::commitTransaction( const QString& )
517 * \brief Returns TRUE if transaction is opened.
519 bool SUIT_Study::hasTransaction() const
525 * \brief Restores the study state.
527 void SUIT_Study::restoreState(int savePoint)
529 // Redefined in SalomeApp_Study.
530 // Called from SALOME_Session_i::restoreVisualState(CORBA::Long theSavePoint)