Salome HOME
Dump Image data to python script (Feature #13).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Operation.cxx
index 9bdf11e031f00ae0908c53a7286c1df6894fbcdd..3183b3b82b8af70118e8c0409844a9e51e0f5971 100644 (file)
@@ -36,6 +36,8 @@
 #include <SUIT_MessageBox.h>
 #include <SUIT_Study.h>
 
+#include <QApplication>
+
 HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule )
 : LightApp_Operation(),
   myModule( theModule ),
@@ -82,8 +84,6 @@ void HYDROGUI_Operation::startOperation()
 {
   LightApp_Operation::startOperation();
 
-  doc()->StartOperation();
-
   if( inputPanel() )
   {
     myModule->getApp()->desktop()->addDockWidget( Qt::RightDockWidgetArea, inputPanel() );
@@ -93,8 +93,6 @@ void HYDROGUI_Operation::startOperation()
 
 void HYDROGUI_Operation::abortOperation()
 {
-  doc()->AbortOperation();
-
   LightApp_Operation::abortOperation();
 
   if( inputPanel() )
@@ -103,8 +101,6 @@ void HYDROGUI_Operation::abortOperation()
 
 void HYDROGUI_Operation::commitOperation()
 {
-  doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) );
-
   LightApp_Operation::commitOperation();
 
   if( inputPanel() )
@@ -126,6 +122,24 @@ void HYDROGUI_Operation::processCancel()
 {
 }
 
+void HYDROGUI_Operation::startDocOperation()
+{
+  // Open transaction in the model document
+  doc()->StartOperation();
+}
+
+void HYDROGUI_Operation::abortDocOperation()
+{
+  // Abort transaction in the model document
+  doc()->AbortOperation();
+}
+
+void HYDROGUI_Operation::commitDocOperation()
+{
+  // Commit transaction in the model document
+  doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) );
+}
+
 Handle_HYDROData_Document HYDROGUI_Operation::doc() const
 {
   return HYDROData_Document::Document( myModule->getStudyId() );
@@ -133,15 +147,41 @@ Handle_HYDROData_Document HYDROGUI_Operation::doc() const
 
 void HYDROGUI_Operation::onApply()
 {
+  QApplication::setOverrideCursor( Qt::WaitCursor );
+
+  startDocOperation();
+
   int anUpdateFlags = 0;
   QString anErrorMsg;
-  if( processApply( anUpdateFlags, anErrorMsg ) )
+
+  bool aResult = false;
+  
+  try
+  {
+    aResult = processApply( anUpdateFlags, anErrorMsg );
+  }
+  catch ( Standard_Failure )
+  {
+    Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
+    anErrorMsg = aFailure->GetMessageString();
+    aResult = false;
+  }
+  catch ( ... )
+  {
+    aResult = false;
+  }
+  
+  QApplication::restoreOverrideCursor();
+
+  if ( aResult )
   {
     module()->update( anUpdateFlags );
+    commitDocOperation();
     commit();
   }
   else
   {
+    abortDocOperation();
     QString aMsg = tr( "INPUT_VALID_DATA" );
     if( !anErrorMsg.isEmpty() )
       aMsg.prepend( anErrorMsg + "\n" );