]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Several useless methods removed. canActivate method rewritten
authorsln <sln@opencascade.com>
Fri, 8 Jul 2005 08:49:36 +0000 (08:49 +0000)
committersln <sln@opencascade.com>
Fri, 8 Jul 2005 08:49:36 +0000 (08:49 +0000)
src/SUIT/SUIT_Study.cxx
src/SUIT/SUIT_Study.h

index 243447ca2a92a818482ea349e1369b1c1ebaa072..3263f6818702f0165ce33e4595154972885376e2 100755 (executable)
@@ -6,6 +6,8 @@
 #include "SUIT_MessageBox.h"
 #include "SUIT_Application.h"
 
+#include <qvaluevector.h>
+
 SUIT_Study::SUIT_Study( SUIT_Application* app )
 : QObject(),
 myApp( app ),
@@ -59,7 +61,7 @@ SUIT_Operation* SUIT_Study::activeOperation() const
   for( ; anIt!=aLast; anIt++ )
     if( (*anIt)->isActive() )
       return *anIt;
-  
+
   return 0;
 }
 
@@ -148,67 +150,41 @@ void SUIT_Study::setStudyName( const QString& name )
   myName = name;
 }
 
-bool SUIT_Study::canActivate( SUIT_Operation* op, SUIT_Operation** refusingOp ) const
+//=======================================================================
+// name    : canActivate
+// Purpose : Verify whether operation can be activated (abort other operations
+//           if necessary)
+//=======================================================================
+bool SUIT_Study::canActivate( SUIT_Operation* op )
 {
-  if( !op )
-  {
-    if( refusingOp )
-      *refusingOp = 0;      
+  if( !op || myOperations.find( op ) >= 0 )
     return false;
-  }
 
   if( op->isGranted() )
     return true;
 
-  Operations::const_iterator anIt = myOperations.begin(),
-                             aLast = myOperations.end();
-  for( ; anIt!=aLast; anIt++ )
-    if( !(*anIt)->isValid( op ) )
-    {
-      if( refusingOp )
-        *refusingOp = *anIt;
-      return false;
-    }
-    
-  return true;
-}
+  QValueVector<SUIT_Operation*> anOps( myOperations.count() );
+  SUIT_Operation* anOp = 0;
+  int i = 0, n;
+  for ( anOp = myOperations.last(); anOp; anOp = myOperations.prev() )
+    anOps[ i++ ] = anOp;
 
-void SUIT_Study::connectOperation( SUIT_Operation* op, const bool conn ) const
-{
-  if( !op )
-    return;
-    
-  if( conn )
-  {
-    connect( op, SIGNAL( started( SUIT_Operation* ) ), this, SLOT( onAddOperation( SUIT_Operation* ) ) );
-    connect( op, SIGNAL( stoped( SUIT_Operation* ) ), this, SLOT( onRemoveOperation( SUIT_Operation* ) ) );
-    connect( op, SIGNAL( resumed( SUIT_Operation* ) ), this, SLOT( onOperationResume( SUIT_Operation* ) ) );
-  }
-  else
+  for ( i = 0, n = anOps.count(); i < n; i++ )
   {
-    disconnect( op, SIGNAL( started( SUIT_Operation* ) ), this, SLOT( onAddOperation( SUIT_Operation* ) ) );
-    disconnect( op, SIGNAL( stoped( SUIT_Operation* ) ), this, SLOT( onRemoveOperation( SUIT_Operation* ) ) );
-    disconnect( op, SIGNAL( resumed( SUIT_Operation* ) ), this, SLOT( onOperationResume( SUIT_Operation* ) ) );
+    SUIT_Operation* currOp = anOps[ i ];
+    if( currOp != 0 && !currOp->isValid( op ) )
+    {
+       int anAnsw = SUIT_MessageBox::warn2( application()->desktop(), tr( "Operation launch" ),
+                                            tr( "Previous operation is not finished and will be aborted." ),
+                                            tr( "Continue" ), tr( "Cancel" ), 0, 1, 1 );
+      if( anAnsw == 1 )
+        return false;
+      else
+        currOp->abort();
+    }
   }
-}
 
-void SUIT_Study::onAddOperation( SUIT_Operation* op )
-{
-  myOperations.append( op );
-}
-
-void SUIT_Study::onRemoveOperation( SUIT_Operation* op )
-{
-  myOperations.remove( op );
-}
-
-void SUIT_Study::onOperationResume( SUIT_Operation* op )
-{
-  Operations::const_iterator anIt = myOperations.begin(),
-                             aLast = myOperations.end();
-  for( ; anIt!=aLast; anIt++ )
-    if( *anIt!=op )
-      (*anIt)->suspend();
+  return true;
 }
 
 //=======================================================================
@@ -226,20 +202,8 @@ void SUIT_Study::start( SUIT_Operation* op, const bool check )
   if ( !op->isReadyToStart() )
     return;
 
-  if ( check )
-  {
-    SUIT_Operation* refusingOperation = 0;
-    while( canActivate( op, &refusingOperation ) && refusingOperation )
-    {
-      int anAnsw = SUIT_MessageBox::warn2( application()->desktop(), tr( "Operation launch" ),
-                                           tr( "Previous operation is not finished and will be aborted." ),
-                                           tr( "Continue" ), tr( "Cancel" ), 0, 1, 1 );
-      if( anAnsw == 1 )
-        return;  // user refuse to start this operation
-      else
-        refusingOperation->abort();
-    }
-  }
+  if ( check && !canActivate( op ) )
+    return;
 
   if ( activeOperation() )
     activeOperation()->suspendOperation();
@@ -305,6 +269,13 @@ void SUIT_Study::resume( SUIT_Operation* op )
 
   op->setState( SUIT_Operation::Running );
   op->resumeOperation();
+  
+  // Move operation at the end of list in order to sort it in the order of activation.
+  // As result active operation is a last operation of list operation which was active
+  // before currently active operation is located before it and so on
+  myOperations.remove( op );
+  myOperations.append( op );
+  
   emit op->resumed( op );
 }
 
index 6ab11d1f1fd22b22359f9b2e6b3e544bbe1329c6..c6d0c521ce1d57db90aadae2978cbe1baa442a57 100755 (executable)
@@ -46,8 +46,7 @@ public:
   // Operation management
   SUIT_Operation*   activeOperation() const;
   virtual void      abortAllOperations();
-  virtual bool      canActivate( SUIT_Operation*, SUIT_Operation** = 0 ) const;
-  virtual void      connectOperation( SUIT_Operation*, const bool ) const;
+  virtual bool      canActivate( SUIT_Operation* );
 
   void              start( SUIT_Operation*, const bool check = true );
   //!< Starts operation.
@@ -69,11 +68,6 @@ protected:
   virtual void      setRoot( SUIT_DataObject* );
   virtual void      setStudyName( const QString& );
 
-private slots:
-  void onAddOperation( SUIT_Operation* );
-  void onRemoveOperation( SUIT_Operation* );
-  void onOperationResume( SUIT_Operation* );
-  
 private:
   typedef QPtrList<SUIT_Operation> Operations;
   void              stop( SUIT_Operation* );