Salome HOME
Minor changes.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Operation.cxx
index 5fe0773011920a6249b00a52e8eb911453bc1ebb..761083b8b64e90628ba81754c8d740b1d8119a6c 100644 (file)
@@ -45,6 +45,7 @@ HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule )
   myModule( theModule ),
   myPanel( 0 ),
   myIsPrintErrorMessage( true ),
+  myIsTransactionOpened( false ),
   myPreviewManager( 0 ),
   myPreviewZLayer( -1 )
 {
@@ -182,20 +183,21 @@ void HYDROGUI_Operation::stopOperation()
 
   // pop the operation from the cached map of active operations
   QStack<HYDROGUI_Operation*>& anOperations = myModule->getActiveOperations();
-  if ( anOperations.top() == this )
-  {
-    anOperations.pop();
-  }
-  else {
-    // find in the stack the current operation and remove it from the stack
-    QVectorIterator<HYDROGUI_Operation*> aVIt( anOperations );
-    aVIt.toBack();
-    aVIt.previous(); // skip the top show/hide operation
-    while ( aVIt.hasPrevious() )
+  if ( !anOperations.empty() ) {
+    if ( anOperations.top() == this )
+      anOperations.pop();
+    else
     {
-      HYDROGUI_Operation* anOp = aVIt.previous();
-      if ( anOp == this )
-        anOperations.remove( anOperations.lastIndexOf( anOp ) );
+      // find in the stack the current operation and remove it from the stack
+      QVectorIterator<HYDROGUI_Operation*> aVIt( anOperations );
+      aVIt.toBack();
+      aVIt.previous(); // skip the top show/hide operation
+      while ( aVIt.hasPrevious() )
+      {
+        HYDROGUI_Operation* anOp = aVIt.previous();
+        if ( anOp == this )
+          anOperations.remove( anOperations.lastIndexOf( anOp ) );
+      }
     }
   }
   // release the preview manager with removing the added preview Z layer
@@ -241,23 +243,35 @@ void HYDROGUI_Operation::processCancel()
 
 void HYDROGUI_Operation::startDocOperation()
 {
-  // Open transaction in the model document
+  // Open transaction in the model document only if it not
+  // already opened by other operation (intended for nested operations)
   if ( !doc()->IsOperation() )
+  {
     doc()->StartOperation();
+    myIsTransactionOpened = true;
+  }
 }
 
 void HYDROGUI_Operation::abortDocOperation()
 {
-  // Abort transaction in the model document
-  if ( doc()->IsOperation() )
+  // Abort transaction in the model document only if it was 
+  // opened by this operation (intended for nested operations)
+  if ( myIsTransactionOpened && doc()->IsOperation() )
+  {
     doc()->AbortOperation();
+    myIsTransactionOpened = false;
+  }
 }
 
 void HYDROGUI_Operation::commitDocOperation()
 {
-  // Commit transaction in the model document
-  if ( doc()->IsOperation() )
+  // Commit transaction in the model document only if it was 
+  // opened by this operation (intended for nested operations)
+  if ( myIsTransactionOpened && doc()->IsOperation() )
+  {
     doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) );
+    myIsTransactionOpened = false;
+  }
 }
 
 Handle_HYDROData_Document HYDROGUI_Operation::doc() const