Salome HOME
Parent object parameter added to constructor.
[modules/gui.git] / src / SUIT / SUIT_Study.cxx
index 9c2af0282d394045b990ba003b537826bd85eecb..2f83179c4655966d56b8fd458e7de08a701a4bd3 100755 (executable)
@@ -1,3 +1,21 @@
+// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either 
+// version 2.1 of the License.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// License along with this library; if not, write to the Free Software 
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/
+//
 #include "SUIT_Study.h"
 
 #include "SUIT_Desktop.h"
@@ -26,9 +44,6 @@ myBlockChangeState( false )
 
   myRoot = new SUIT_DataObject();
   myOperations.setAutoDelete( false );
-
-  connect( this, SIGNAL( changeOperationState( bool ) ), this, SLOT( onChangeOperationState( bool ) ) );
-
   myOperations.setAutoDelete( false );
 }
 
@@ -192,6 +207,10 @@ void SUIT_Study::setRoot( SUIT_DataObject* obj )
   if ( myRoot == obj )
     return;
 
+  // This is necessary in order not to destroy the complete tree of objects
+  if ( obj )
+    obj->reparentChildren( myRoot );
+
   delete myRoot;
   myRoot = obj;
 }
@@ -256,10 +275,10 @@ bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck )
     while( SUIT_Operation* anOp = blockingOperation( theOp ) )
     {
       int anAnsw = SUIT_MessageBox::warn2( application()->desktop(),
-         tr( "OPERATION_LAUNCH" ), tr( "PREVIOUS_NOT_FINISHED" ),
-         tr( "CONTINUE" ), tr( "CANCEL" ), 0, 1, 1 );
+                                           tr( "OPERATION_LAUNCH" ), tr( "PREVIOUS_NOT_FINISHED" ),
+                                           tr( "CONTINUE" ), tr( "CANCEL" ), 0, 1, 1 );
 
-      if( anAnsw == 1 )
+      if ( anAnsw == 1 )
         return false;
       else
         anOp->abort();
@@ -275,9 +294,11 @@ bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck )
 
   theOp->setState( SUIT_Operation::Running );
   myOperations.append( theOp );
   emit theOp->started( theOp );
+  operationStarted( theOp );
   theOp->startOperation();
-  
+
   return true;
 }
 
@@ -294,10 +315,14 @@ bool SUIT_Study::abort( SUIT_Operation* theOp )
   if ( !theOp || myOperations.find( theOp ) == -1 )
     return false;
 
-  theOp->abortOperation();
   theOp->setExecStatus( SUIT_Operation::Rejected );
+
+  theOp->abortOperation();
+  operationAborted( theOp );
   emit theOp->aborted( theOp );
+
   stop( theOp );
+
   return true;
 }
 
@@ -314,11 +339,16 @@ bool SUIT_Study::commit( SUIT_Operation* theOp )
   if ( !theOp || myOperations.find( theOp ) == -1 )
     return false;
 
-  theOp->commitOperation();
   theOp->setExecStatus( SUIT_Operation::Accepted );
+
+  theOp->commitOperation();
+  operationCommited( theOp );
   emit theOp->committed( theOp );
+
   stop( theOp );
+
   emit studyModified( this );
+
   return true;
 }
 
@@ -386,14 +416,19 @@ void SUIT_Study::stop( SUIT_Operation* theOp )
 
   // get last operation which can be resumed
   SUIT_Operation* anOp, *aResultOp = 0;
-  for( anOp = myOperations.last(); anOp; anOp = myOperations.prev() )
+  for ( anOp = myOperations.last(); anOp; anOp = myOperations.prev() )
+  {
     if ( anOp && anOp != theOp && blockingOperation( anOp ) == 0 )
     {
       aResultOp = anOp;
       break;
     }
+  }
 
+  theOp->stopOperation();
+  operationStopped( theOp );
   emit theOp->stopped( theOp );
+
   if ( aResultOp )
     resume( aResultOp );
 }
@@ -407,12 +442,71 @@ const QPtrList<SUIT_Operation>& SUIT_Study::operations() const
   return myOperations;
 }
 
+/*!
+ * \brief Perform some actions when operation starting
+*/
+void SUIT_Study::operationStarted( SUIT_Operation* op )
+{
+  if ( !op )
+    return;
 
+  if ( op->testFlags( SUIT_Operation::Transaction ) )
+    op->openTransaction();
+}
 
+/*!
+ * \brief Perform some actions when operation aborted
+*/
+void SUIT_Study::operationAborted( SUIT_Operation* op )
+{
+  if ( op->testFlags( SUIT_Operation::Transaction ) )
+    op->abortTransaction();
+}
 
+/*!
+ * \brief Perform some actions when operation commited
+*/
+void SUIT_Study::operationCommited( SUIT_Operation* op )
+{
+  if ( op->testFlags( SUIT_Operation::Transaction ) )
+    op->commitTransaction( op->operationName() );
+}
 
+/*!
+ * \brief Perform some actions when operation stopped
+*/
+void SUIT_Study::operationStopped( SUIT_Operation* )
+{
+}
 
+/*!
+ * \brief Opens transaction for data modifications.
+*/
+bool SUIT_Study::openTransaction()
+{
+  return true;
+}
 
+/*!
+ * \brief Aborts transaction and all performed data modifications.
+*/
+bool SUIT_Study::abortTransaction()
+{
+  return true;
+}
 
+/*!
+ * \brief Commits transaction and all performed data modifications.
+*/
+bool SUIT_Study::commitTransaction( const QString& )
+{
+  return true;
+}
 
-
+/*!
+ * \brief Returns TRUE if transaction is opened.
+*/
+bool SUIT_Study::hasTransaction() const
+{
+  return false;
+}