#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.Nullify();
if ( myIsEdit )
{
- myEditedObject = Handle(HYDROData_Calculation)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+ myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
if ( !myEditedObject.IsNull() )
{
anObjectName = myEditedObject->GetName();
}
}
}
+ else
+ {
+ myEditedObject =
+ Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
+ myEditedObject->SetName(anObjectName);
+ }
aPanel->setObjectName( anObjectName );
+ aPanel->setEditedObject( myEditedObject );
aPanel->setSelectedGeomObjects( aSelectedObjects );
createPreview();
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_CalculationCase) aCalculObj = myIsEdit ? myEditedObject :
+ // Handle(HYDROData_CalculationCase)::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;
- }
- }
-
- Handle(HYDROData_Document) aDocument = doc();
-
- Handle(HYDROData_Calculation) aCalculObj = myIsEdit ? myEditedObject :
- Handle(HYDROData_Calculation)::DownCast( aDocument->CreateObject( KIND_CALCULATION ) );
- if ( aCalculObj.IsNull() )
- return false;
+ theUpdateFlags = UF_Model;
- aCalculObj->SetName( anObjectName );
+ return true;
+}
- QStringList aRefObjectNames = aPanel->getSelectedGeomObjects();
- HYDROData_SequenceOfObjects aGeomObjects =
- HYDROGUI_Tool::FindObjectsByNames( module(), aRefObjectNames );
+void HYDROGUI_CalculationOp::onApply()
+{
+ QApplication::setOverrideCursor( Qt::WaitCursor );
- aCalculObj->SetGeometryObjects( aGeomObjects );
+ int anUpdateFlags = 0;
+ QString anErrorMsg;
- 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()