#include "HYDROGUI_StricklerTableOp.h"
#include "HYDROGUI_StricklerTableDlg.h"
-#include "HYDROGUI_Tool.h"
#include "HYDROGUI_DataObject.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_OCCDisplayer.h"
+#include "HYDROGUI_Operations.h"
+#include "HYDROGUI_Tool2.h"
+#include "HYDROGUI_UpdateFlags.h"
#include <HYDROData_Document.h>
+#include <LightApp_UpdateFlags.h>
+
#include <QFileInfo>
-HYDROGUI_StricklerTableOp::HYDROGUI_StricklerTableOp( HYDROGUI_Module* theModule, bool theIsEdit )
-: HYDROGUI_Operation( theModule ),
- myIsEdit( theIsEdit )
+HYDROGUI_StricklerTableOp::HYDROGUI_StricklerTableOp( HYDROGUI_Module* theModule, int theType )
+ : HYDROGUI_Operation( theModule ),
+ myType( theType )
{
- setName( theIsEdit ? tr( "EDIT_STRICKLER_TABLE" ) : tr( "IMPORT_STRICKLER_TABLE" ) );
+ setName( isEdit() ? tr( "EDIT_STRICKLER_TABLE" ) :
+ ( isImport() ? tr( "IMPORT_STRICKLER_TABLE" ) : tr( "EXPORT_STRICKLER_TABLE" ) ) );
}
-
HYDROGUI_StricklerTableOp::~HYDROGUI_StricklerTableOp()
{
}
void HYDROGUI_StricklerTableOp::startOperation()
{
- HYDROGUI_Operation::startOperation();
+ HYDROGUI_Operation::startOperation();
+
+ HYDROGUI_StricklerTableDlg* aPanel = (HYDROGUI_StricklerTableDlg*)inputPanel();
+ aPanel->reset();
- HYDROGUI_StricklerTableDlg* aPanel = (HYDROGUI_StricklerTableDlg*)inputPanel();
- //aPanel->reset();
- //aPanel->setIsEdit( myIsEdit );
+ if ( !isImport() && isApplyAndClose() )
+ myObject = Handle(HYDROData_StricklerTable)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
- if( myIsEdit )
- {
- if ( isApplyAndClose() )
- myEditedObject = Handle(HYDROData_StricklerTable)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
- if ( !myEditedObject.IsNull() )
+ if ( isEdit() )
{
- // Edit selected Strickler table
+ if ( !myObject.IsNull() )
+ {
+ // Edit selected Strickler table
+ aPanel->setTableName( myObject->GetName() );
+ aPanel->setGuiData( myObject );
+ }
}
- else
+ else if ( isExport() )
{
- // Import Strickler table from file
+ if ( !myObject.IsNull() )
+ aPanel->setTableName( myObject->GetName() );
}
- }
+ aPanel->setTableNameReadOnly( isExport() );
}
void HYDROGUI_StricklerTableOp::abortOperation()
{
- //...
-
- HYDROGUI_Operation::abortOperation();
+ HYDROGUI_Operation::abortOperation();
}
void HYDROGUI_StricklerTableOp::commitOperation()
{
- //...
-
- HYDROGUI_Operation::commitOperation();
+ HYDROGUI_Operation::commitOperation();
}
HYDROGUI_InputPanel* HYDROGUI_StricklerTableOp::createInputPanel() const
{
- HYDROGUI_StricklerTableDlg* aPanel = new HYDROGUI_StricklerTableDlg( module(), getName() );
- connect( aPanel, SIGNAL( fileSelected( const QString& ) ), SLOT( onFileSelected() ) );
- return aPanel;
+ int type = isEdit() ? HYDROGUI_StricklerTableDlg::Edit : ( isImport() ? HYDROGUI_StricklerTableDlg::Import : HYDROGUI_StricklerTableDlg::Export );
+ HYDROGUI_StricklerTableDlg* aPanel = new HYDROGUI_StricklerTableDlg( module(), getName(), type );
+ connect( aPanel, SIGNAL( fileSelected( const QString& ) ), SLOT( onFileSelected() ) );
+ return aPanel;
}
bool HYDROGUI_StricklerTableOp::processApply( int& theUpdateFlags, QString& theErrorMsg,
- QStringList& theBrowseObjectsEntries )
+ QStringList& theBrowseObjectsEntries )
{
- HYDROGUI_StricklerTableDlg* aPanel = ::qobject_cast<HYDROGUI_StricklerTableDlg*>( inputPanel() );
- if ( !aPanel )
- return false;
-
- QString aFilePath;
- if( !myIsEdit )
- {
- aFilePath = aPanel->getFileName();
- if ( aFilePath.isEmpty() )
+ HYDROGUI_StricklerTableDlg* aPanel = ::qobject_cast<HYDROGUI_StricklerTableDlg*>( inputPanel() );
+ if ( !aPanel )
+ return false;
+
+ QString aFilePath;
+ if( !isEdit() )
+ {
+ aFilePath = aPanel->getFileName();
+ if ( aFilePath.isEmpty() )
+ {
+ theErrorMsg = tr( "SELECT_STRICKLER_TABLE_FILE" ).arg( aFilePath );
+ return false;
+ }
+ }
+
+ QString aStricklerTableName = aPanel->getTableName().simplified();
+ if ( aStricklerTableName.isEmpty() )
{
- theErrorMsg = tr( "SELECT_STRICKLER_TABLE_FILE" ).arg( aFilePath );
- return false;
+ theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
+ return false;
}
- }
-
- QString aStricklerTableName = aPanel->getStricklerTableName().simplified();
- if ( aStricklerTableName.isEmpty() )
- {
- theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
- return false;
- }
-
- if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aStricklerTableName ) )
- {
- // check that there are no other objects with the same name in the document
- Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aStricklerTableName );
- if( !anObject.IsNull() )
+
+ if ( isImport() || ( isEdit() && !myObject.IsNull() && myObject->GetName() != aStricklerTableName ) )
{
- theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aStricklerTableName );
- return false;
+ // check that there are no other objects with the same name in the document
+ Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aStricklerTableName );
+ if( !anObject.IsNull() )
+ {
+ theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aStricklerTableName );
+ return false;
+ }
}
- }
-
- Handle(HYDROData_StricklerTable) aStricklerTableObj;
- if( myIsEdit )
- aStricklerTableObj = myEditedObject;
- else
- {
- aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( doc()->CreateObject( KIND_STRICKLER_TABLE ) );
- QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj );
- theBrowseObjectsEntries.append( anEntry );
- }
-
- if( aStricklerTableObj.IsNull() )
- return false;
-
- aStricklerTableObj->SetName( aStricklerTableName );
-
- if( myIsEdit )
- {
- // Get data from input panel's table and save it into data model object
- }
- else
- {
- // Import data from Strickler table file into data model model object
- aStricklerTableObj->Import( HYDROGUI_Tool::ToAsciiString( aFilePath ) );
- }
-
- aStricklerTableObj->Update();
-
- if( !myIsEdit )
- {
- QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj );
- theBrowseObjectsEntries.append( anEntry );
- }
-
- return true;
+
+ Handle(HYDROData_StricklerTable) aStricklerTableObj;
+ if ( isImport() )
+ {
+ aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( doc()->CreateObject( KIND_STRICKLER_TABLE ) );
+ QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj );
+ theBrowseObjectsEntries.append( anEntry );
+ }
+ else
+ aStricklerTableObj = myObject;
+
+ if ( aStricklerTableObj.IsNull() )
+ return false;
+
+ if ( isExport() )
+ {
+ bool res = false;
+ QString aFilePath = aPanel->getFileName().simplified();
+ if ( !aFilePath.isEmpty() )
+ res = aStricklerTableObj->Export( aFilePath );
+ return res;
+ }
+
+ startDocOperation();
+
+ aStricklerTableObj->SetName( aStricklerTableName );
+
+ if( isEdit() )
+ {
+ // Get data from input panel's table and save it into data model object
+ aPanel->getGuiData( aStricklerTableObj );
+ }
+ else
+ {
+ // Import data from Strickler table file into data model object
+ aStricklerTableObj->Import( aFilePath );
+ }
+
+ aStricklerTableObj->Update();
+
+ commitDocOperation();
+
+ if( !isEdit() )
+ {
+ QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj );
+ theBrowseObjectsEntries.append( anEntry );
+ } else {
+ module()->getOCCDisplayer()->SetToUpdateColorScale();
+ }
+
+ theUpdateFlags |= UF_ObjBrowser | UF_OCCViewer;
+
+ return true;
}
void HYDROGUI_StricklerTableOp::onFileSelected()
{
- HYDROGUI_StricklerTableDlg* aPanel =
- ::qobject_cast<HYDROGUI_StricklerTableDlg*>( inputPanel() );
- if ( !aPanel )
- return;
-
- QString anStricklerTableName = aPanel->getStricklerTableName().simplified();
- if ( anStricklerTableName.isEmpty() )
- {
- anStricklerTableName = aPanel->getFileName();
- if ( !anStricklerTableName.isEmpty() ) {
- anStricklerTableName = QFileInfo( anStricklerTableName ).baseName();
- }
+ HYDROGUI_StricklerTableDlg* aPanel =
+ ::qobject_cast<HYDROGUI_StricklerTableDlg*>( inputPanel() );
+ if ( !aPanel )
+ return;
- if ( anStricklerTableName.isEmpty() ) {
- anStricklerTableName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STRICKLER_TABLE_NAME" ) );
+ QString anStricklerTableName = aPanel->getTableName().simplified();
+ if ( anStricklerTableName.isEmpty() )
+ {
+ anStricklerTableName = aPanel->getFileName();
+ if ( !anStricklerTableName.isEmpty() ) {
+ anStricklerTableName = QFileInfo( anStricklerTableName ).baseName();
+ }
+
+ if ( anStricklerTableName.isEmpty() ) {
+ anStricklerTableName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STRICKLER_TABLE_NAME" ) );
+ }
+ aPanel->setTableName( anStricklerTableName );
}
- aPanel->setStricklerTableName( anStricklerTableName );
- }
+}
+
+bool HYDROGUI_StricklerTableOp::isEdit() const
+{
+ return myType == EditStricklerTableId;
+}
+
+bool HYDROGUI_StricklerTableOp::isImport() const
+{
+ return myType == ImportStricklerTableFromFileId;
+}
+
+bool HYDROGUI_StricklerTableOp::isExport() const
+{
+ return myType == ExportStricklerTableFromFileId;
}