]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #562: basic logic for Strickler table operation and dialog.
authormkr <mkr@opencascade.com>
Wed, 3 Jun 2015 10:04:45 +0000 (13:04 +0300)
committermkr <mkr@opencascade.com>
Wed, 3 Jun 2015 10:04:45 +0000 (13:04 +0300)
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_StricklerTableDlg.cxx
src/HYDROGUI/HYDROGUI_StricklerTableDlg.h
src/HYDROGUI/HYDROGUI_StricklerTableOp.cxx
src/HYDROGUI/HYDROGUI_StricklerTableOp.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 569e47a5db82672c7eadac2cebf2933307e4b357..abdbc312404bc11dd2d0b9e83ea78c12ef44307c 100644 (file)
@@ -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;
index 37ab3bea48100d229ec083473f50c7fe07ac3cdc..1d13f24f407041f1216a5bc3e7983759951fa4cc 100644 (file)
 //
 
 #include "HYDROGUI_StricklerTableDlg.h"
+#include "HYDROGUI_Module.h"
 
+#include <LightApp_Application.h>
+
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_FileDlg.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
+
+#include <QGroupBox>
 #include <QLineEdit>
+#include <QToolButton>
+#include <QLayout>
+#include <QLabel>
 
 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 );
+  }
+}
index 95f1261bf874ca7624ae10d558dcd340568bdf89..282648de9455229c1ba88c1c51f5f86c03f2ba2a 100644 (file)
@@ -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
index c7be54623f0543a9a515ec0ea926a494d7259d0b..88de04a2c8e1eeb26744cdb8ee4939add82ffe1c 100644 (file)
 #include "HYDROGUI_StricklerTableOp.h"
 
 #include "HYDROGUI_StricklerTableDlg.h"
+#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_DataObject.h"
+
+#include <HYDROData_Document.h>
+
+#include <QFileInfo>
 
 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<HYDROGUI_StricklerTableDlg*>( 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<HYDROGUI_StricklerTableDlg*>( 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 );
+  }
+}
index a6ed378205e1560d09e7d183b6a2651dc5502480..a3b40e2fdbedba0aca77d293746b92cdb0fe7c28 100644 (file)
@@ -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;
index 02f0bf9c9766eaa18ef333390afc85c26cc143d5..fa95456b031b37ee85889ea168715dbb63337291 100644 (file)
@@ -253,6 +253,10 @@ All supported formats (*.brep *.iges *.igs *.step *.stp)</translation>
       <source>PREF_VIEWER_AUTO_FITALL</source>
       <translation>Make automatic fit all after show object operation</translation>
     </message>
+    <message>
+      <source>STRICKLER_TABLE_FILTER</source>
+      <translation>Strickler table files (*.txt);;All files (*.* *)</translation>
+    </message>
   </context>
 
   <context>
@@ -2261,6 +2265,26 @@ Polyline should consist from one not closed curve.</translation>
       <source>STRICKLER_TABLE_NAME</source>
       <translation>Strickler table name</translation>
     </message>
+    <message>
+      <source>IMPORT_STRICKLER_TABLE_FROM_FILE</source>
+      <translation>Import Strickler table from file</translation>
+    </message>
+    <message>
+      <source>FILE_NAME</source>
+      <translation>File name</translation>
+    </message>
+    <message>
+      <source>STRICKLER_TABLE_NAME</source>
+      <translation>Strickler table name</translation>
+    </message>
+    <message>
+      <source>NAME</source>
+      <translation>Name</translation>
+    </message>
+    <message>
+      <source>DEFAULT_STRICKLER_TABLE_NAME</source>
+      <translation>Strickler table</translation>
+    </message>
   </context>
 
   <context>
@@ -2277,6 +2301,10 @@ Polyline should consist from one not closed curve.</translation>
       <source>EDIT_STRICKLER_TABLE</source>
       <translation>Edit Strickler table</translation>
     </message>
+    <message>
+      <source>SELECT_STRICKLER_TABLE_FILE</source>
+      <translation>The Strickler table file is not chosen</translation>
+    </message>
   </context>
 
   <context>