#include <LightApp_Application.h>
#include <LightApp_UpdateFlags.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Desktop.h>
+
#include <QApplication>
HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
void HYDROGUI_CalculationOp::startOperation()
{
HYDROGUI_Operation::startOperation();
+
+ // Begin transaction
+ startDocOperation();
HYDROGUI_CalculationDlg* aPanel =
::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
{
myEditedObject =
Handle(HYDROData_Calculation)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
+ myEditedObject->SetName(anObjectName);
}
aPanel->setObjectName( anObjectName );
void HYDROGUI_CalculationOp::abortOperation()
{
closePreview();
-
+ // Abort transaction
+ abortDocOperation();
HYDROGUI_Operation::abortOperation();
}
void HYDROGUI_CalculationOp::commitOperation()
{
closePreview();
-
+ // Commit transaction
+ commitDocOperation();
HYDROGUI_Operation::commitOperation();
}
if ( !aPanel )
return false;
- QString anObjectName = aPanel->getObjectName().simplified();
- if ( anObjectName.isEmpty() )
- {
- theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
- return false;
- }
+ //QString anObjectName = aPanel->getObjectName().simplified();
+ //if ( anObjectName.isEmpty() )
+ //{
+ // theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
+ // return false;
+ //}
+
+ //// check that there are no other objects with the same name in the document
+ //if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
+ //{
+ // Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
+ // if ( !anObject.IsNull() )
+ // {
+ // theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
+ // return false;
+ // }
+ //}
+
+ //Handle(HYDROData_Document) aDocument = doc();
+
+ //Handle(HYDROData_Calculation) aCalculObj = myIsEdit ? myEditedObject :
+ // Handle(HYDROData_Calculation)::DownCast( aDocument->CreateObject( KIND_CALCULATION ) );
+ //if ( aCalculObj.IsNull() )
+ // return false;
+
+ //aCalculObj->SetName( anObjectName );
+
+ //QStringList aRefObjectNames = aPanel->getSelectedGeomObjects();
+ //HYDROData_SequenceOfObjects aGeomObjects =
+ // HYDROGUI_Tool::FindObjectsByNames( module(), aRefObjectNames );
- // check that there are no other objects with the same name in the document
- if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
- {
- Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
- if ( !anObject.IsNull() )
- {
- theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
- return false;
- }
- }
+ theUpdateFlags = UF_Model;
- Handle(HYDROData_Document) aDocument = doc();
+ return true;
+}
- Handle(HYDROData_Calculation) aCalculObj = myIsEdit ? myEditedObject :
- Handle(HYDROData_Calculation)::DownCast( aDocument->CreateObject( KIND_CALCULATION ) );
- if ( aCalculObj.IsNull() )
- return false;
+void HYDROGUI_CalculationOp::onApply()
+{
+ QApplication::setOverrideCursor( Qt::WaitCursor );
- aCalculObj->SetName( anObjectName );
+ int anUpdateFlags = 0;
+ QString anErrorMsg;
- QStringList aRefObjectNames = aPanel->getSelectedGeomObjects();
- HYDROData_SequenceOfObjects aGeomObjects =
- HYDROGUI_Tool::FindObjectsByNames( module(), aRefObjectNames );
-
- theUpdateFlags = UF_Model;
+ 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();
- return true;
+ if ( aResult )
+ {
+ module()->update( anUpdateFlags );
+ commit();
+ }
+ else
+ {
+ abort();
+ QString aMsg = tr( "INPUT_VALID_DATA" );
+ if( !anErrorMsg.isEmpty() )
+ aMsg.prepend( anErrorMsg + "\n" );
+ SUIT_MessageBox::critical( module()->getApp()->desktop(),
+ tr( "INSUFFICIENT_INPUT_DATA" ),
+ aMsg );
+ }
}
void HYDROGUI_CalculationOp::onSplitZones()