From: mkr Date: Wed, 3 Jun 2015 10:04:45 +0000 (+0300) Subject: refs #562: basic logic for Strickler table operation and dialog. X-Git-Tag: v1.4.1~6^2~4^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=35d2822e3e33ca225dcc1ba24e6684a43e3bb2d1;p=modules%2Fhydro.git refs #562: basic logic for Strickler table operation and dialog. --- diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 569e47a5..abdbc312 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -477,6 +477,7 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case EditDigueId: anOp = new HYDROGUI_DigueOp( aModule, theId == EditDigueId ); break; + case ImportStricklerTableFromFileId: case EditStricklerTableId: anOp = new HYDROGUI_StricklerTableOp( aModule, theId == EditStricklerTableId ); break; diff --git a/src/HYDROGUI/HYDROGUI_StricklerTableDlg.cxx b/src/HYDROGUI/HYDROGUI_StricklerTableDlg.cxx index 37ab3bea..1d13f24f 100644 --- a/src/HYDROGUI/HYDROGUI_StricklerTableDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_StricklerTableDlg.cxx @@ -17,18 +17,104 @@ // #include "HYDROGUI_StricklerTableDlg.h" +#include "HYDROGUI_Module.h" +#include + +#include +#include +#include +#include +#include + +#include #include +#include +#include +#include HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModule, const QString& theTitle ) : HYDROGUI_InputPanel( theModule, theTitle ), myName(NULL) { + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + + // Import Strickler table from file + myFileNameGroup = new QGroupBox( tr( "IMPORT_STRICKLER_TABLE_FROM_FILE" ), this ); + + QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup ); + + myFileName = new QLineEdit( myFileNameGroup ); + myFileName->setReadOnly( true ); + + myBrowseBtn = new QToolButton( myFileNameGroup ); + myBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) ); + + QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup ); + aFileNameLayout->setMargin( 5 ); + aFileNameLayout->setSpacing( 5 ); + aFileNameLayout->addWidget( aFileNameLabel ); + aFileNameLayout->addWidget( myFileName ); + aFileNameLayout->addWidget( myBrowseBtn ); + + // Strickler table name + myNameGroup = new QGroupBox( tr( "STRICKLER_TABLE_NAME" ), this ); + + QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myNameGroup ); + myName = new QLineEdit( myNameGroup ); + + QBoxLayout* anImageNameLayout = new QHBoxLayout( myNameGroup ); + anImageNameLayout->setMargin( 5 ); + anImageNameLayout->setSpacing( 5 ); + anImageNameLayout->addWidget( anImageNameLabel ); + anImageNameLayout->addWidget( myName ); + + // Strickler table + //... + + // Common + addWidget( myFileNameGroup ); + addWidget( myNameGroup ); + //addWidget( myTableGroup ); + addStretch(); + + connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) ); + + setMinimumWidth( 350 ); } HYDROGUI_StricklerTableDlg::~HYDROGUI_StricklerTableDlg() { } +void HYDROGUI_StricklerTableDlg::setIsEdit( const bool theIsEdit ) +{ + myFileNameGroup->setVisible( !theIsEdit ); + myNameGroup->setEnabled( theIsEdit ); + //myTableGroup->setEnabled( theIsEdit ); +} + +void HYDROGUI_StricklerTableDlg::reset() +{ + myFileName->clear(); + + myName->clear(); + myNameGroup->setEnabled( false ); + + //myTableGroup->setEnabled( false ); + + //myIsInitialized = false; +} + +QString HYDROGUI_StricklerTableDlg::getFileName() const +{ + return myFileName->text(); +} + +void HYDROGUI_StricklerTableDlg::setFileName( const QString& theName ) +{ + myFileName->setText( theName ); +} + void HYDROGUI_StricklerTableDlg::setStricklerTableName( const QString& theName ) { myName->setText(theName); @@ -38,3 +124,14 @@ QString HYDROGUI_StricklerTableDlg::getStricklerTableName() const { return myName->text(); } + +void HYDROGUI_StricklerTableDlg::onBrowse() +{ + QString aFilter( tr( "STRICKLER_TABLE_FILTER" ) ); + QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_STRICKLER_TABLE_FROM_FILE" ), true ); + if( !aFileName.isEmpty() ) + { + setFileName( aFileName ); + emit fileSelected( aFileName ); + } +} diff --git a/src/HYDROGUI/HYDROGUI_StricklerTableDlg.h b/src/HYDROGUI/HYDROGUI_StricklerTableDlg.h index 95f1261b..282648de 100644 --- a/src/HYDROGUI/HYDROGUI_StricklerTableDlg.h +++ b/src/HYDROGUI/HYDROGUI_StricklerTableDlg.h @@ -21,7 +21,9 @@ #include "HYDROGUI_InputPanel.h" +class QGroupBox; class QLineEdit; +class QToolButton; class HYDROGUI_StricklerTableDlg : public HYDROGUI_InputPanel { @@ -31,11 +33,29 @@ public: HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModule, const QString& theTitle ); virtual ~HYDROGUI_StricklerTableDlg(); - void setStricklerTableName( const QString& theName ); - QString getStricklerTableName() const; + void setIsEdit( const bool theIsEdit ); + void reset(); + + QString getFileName() const; + void setFileName( const QString& theName ); + + void setStricklerTableName( const QString& theName ); + QString getStricklerTableName() const; + +protected slots: + void onBrowse(); + +signals: + void fileSelected( const QString& theFileName ); private: - QLineEdit* myName; + QGroupBox* myFileNameGroup; //!< The group for the source Strickler table file selection + QLineEdit* myFileName; //!< Source Strickler table file name input field + QToolButton* myBrowseBtn; + + QGroupBox* myNameGroup; //!< The group for the Strickler table name input field + QLineEdit* myName; //!< The Strickler table name input field + }; #endif diff --git a/src/HYDROGUI/HYDROGUI_StricklerTableOp.cxx b/src/HYDROGUI/HYDROGUI_StricklerTableOp.cxx index c7be5462..88de04a2 100644 --- a/src/HYDROGUI/HYDROGUI_StricklerTableOp.cxx +++ b/src/HYDROGUI/HYDROGUI_StricklerTableOp.cxx @@ -19,6 +19,12 @@ #include "HYDROGUI_StricklerTableOp.h" #include "HYDROGUI_StricklerTableDlg.h" +#include "HYDROGUI_Tool.h" +#include "HYDROGUI_DataObject.h" + +#include + +#include HYDROGUI_StricklerTableOp::HYDROGUI_StricklerTableOp( HYDROGUI_Module* theModule, bool theIsEdit ) : HYDROGUI_Operation( theModule ), @@ -33,25 +39,139 @@ HYDROGUI_StricklerTableOp::~HYDROGUI_StricklerTableOp() } void HYDROGUI_StricklerTableOp::startOperation() -{ +{ + HYDROGUI_Operation::startOperation(); + + HYDROGUI_StricklerTableDlg* aPanel = (HYDROGUI_StricklerTableDlg*)inputPanel(); + //aPanel->reset(); + //aPanel->setIsEdit( myIsEdit ); + + if( myIsEdit ) + { + if ( isApplyAndClose() ) + myEditedObject = Handle(HYDROData_StricklerTable)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if ( !myEditedObject.IsNull() ) + { + // Edit selected Strickler table + } + else + { + // Import Strickler table from file + } + } } void HYDROGUI_StricklerTableOp::abortOperation() { + //... + + HYDROGUI_Operation::abortOperation(); } void HYDROGUI_StricklerTableOp::commitOperation() { + //... + + HYDROGUI_Operation::commitOperation(); } HYDROGUI_InputPanel* HYDROGUI_StricklerTableOp::createInputPanel() const { - HYDROGUI_StricklerTableDlg* aDlg = new HYDROGUI_StricklerTableDlg( module(), getName() ); - return aDlg; + HYDROGUI_StricklerTableDlg* aPanel = new HYDROGUI_StricklerTableDlg( module(), getName() ); + connect( aPanel, SIGNAL( fileSelected( const QString& ) ), SLOT( onFileSelected() ) ); + return aPanel; } bool HYDROGUI_StricklerTableOp::processApply( int& theUpdateFlags, QString& theErrorMsg, QStringList& theBrowseObjectsEntries ) { + HYDROGUI_StricklerTableDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return false; + + QString aFilePath; + if( !myIsEdit ) + { + aFilePath = aPanel->getFileName(); + if ( aFilePath.isEmpty() ) + { + theErrorMsg = tr( "SELECT_STRICKLER_TABLE_FILE" ).arg( aFilePath ); + 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() ) + { + 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; } + +void HYDROGUI_StricklerTableOp::onFileSelected() +{ + HYDROGUI_StricklerTableDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + QString anStricklerTableName = aPanel->getStricklerTableName().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->setStricklerTableName( anStricklerTableName ); + } +} diff --git a/src/HYDROGUI/HYDROGUI_StricklerTableOp.h b/src/HYDROGUI/HYDROGUI_StricklerTableOp.h index a6ed3782..a3b40e2f 100644 --- a/src/HYDROGUI/HYDROGUI_StricklerTableOp.h +++ b/src/HYDROGUI/HYDROGUI_StricklerTableOp.h @@ -32,14 +32,17 @@ public: virtual ~HYDROGUI_StricklerTableOp(); protected: - virtual void startOperation(); - virtual void abortOperation(); - virtual void commitOperation(); + virtual void startOperation(); + virtual void abortOperation(); + virtual void commitOperation(); virtual HYDROGUI_InputPanel* createInputPanel() const; - virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg, - QStringList& theBrowseObjectsEntries ); + virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg, + QStringList& theBrowseObjectsEntries ); + +protected slots: + void onFileSelected(); private: bool myIsEdit; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 02f0bf9c..fa95456b 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -253,6 +253,10 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) PREF_VIEWER_AUTO_FITALL Make automatic fit all after show object operation + + STRICKLER_TABLE_FILTER + Strickler table files (*.txt);;All files (*.* *) + @@ -2261,6 +2265,26 @@ Polyline should consist from one not closed curve. STRICKLER_TABLE_NAME Strickler table name + + IMPORT_STRICKLER_TABLE_FROM_FILE + Import Strickler table from file + + + FILE_NAME + File name + + + STRICKLER_TABLE_NAME + Strickler table name + + + NAME + Name + + + DEFAULT_STRICKLER_TABLE_NAME + Strickler table + @@ -2277,6 +2301,10 @@ Polyline should consist from one not closed curve. EDIT_STRICKLER_TABLE Edit Strickler table + + SELECT_STRICKLER_TABLE_FILE + The Strickler table file is not chosen +