]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #560: Strickler table: import/export
authorstv <stv@opencascade.com>
Wed, 10 Jun 2015 11:09:30 +0000 (14:09 +0300)
committerstv <stv@opencascade.com>
Wed, 10 Jun 2015 11:10:59 +0000 (14:10 +0300)
src/HYDROData/HYDROData_Document.cxx
src/HYDROData/HYDROData_StricklerTable.cxx
src/HYDROData/HYDROData_StricklerTable.h
src/HYDROGUI/HYDROGUI_DataModel.cxx
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 cf515aa8d8c22d73caa6bc82d893f99019bfba52..44b9fb605e4fa29962c2f86230e4410a67b32dae 100644 (file)
@@ -229,6 +229,7 @@ bool HYDROData_Document::DumpToPython( const QString& theFileName,
 
   // Dump all model objects to Python script
   aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_IMAGE );
+  aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_STRICKLER_TABLE );
   aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_POLYLINEXY );
   aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_BATHYMETRY );
   aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_PROFILE );
index 903b915a4ad1621a8613987e4ee88c4517302e9d..68995e824be7ab26e9824459bf25e8a1567d3a3c 100644 (file)
 //
 
 #include <HYDROData_StricklerTable.h>
+
 #include <TDataStd_NamedData.hxx>
 
+#include <TDataStd_DataMapOfStringReal.hxx>
+#include <TDataStd_DataMapIteratorOfDataMapOfStringReal.hxx>
+
+#include <TCollection_AsciiString.hxx>
+#include <TCollection_ExtendedString.hxx>
+
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+
 IMPLEMENT_STANDARD_HANDLE( HYDROData_StricklerTable, HYDROData_Entity )
-IMPLEMENT_STANDARD_RTTIEXT( HYDROData_StricklerTable, HYDROData_Entity )
+    IMPLEMENT_STANDARD_RTTIEXT( HYDROData_StricklerTable, HYDROData_Entity )
 
-HYDROData_StricklerTable::HYDROData_StricklerTable()
+    HYDROData_StricklerTable::HYDROData_StricklerTable()
 {
 }
 
@@ -32,51 +42,140 @@ HYDROData_StricklerTable::~HYDROData_StricklerTable()
 
 const ObjectKind HYDROData_StricklerTable::GetKind() const
 {
-  return KIND_STRICKLER_TABLE;
+    return KIND_STRICKLER_TABLE;
 }
 
 bool HYDROData_StricklerTable::Import( const TCollection_AsciiString& theFileName )
 {
-  FILE* aFile = fopen( theFileName.ToCString(), "r" );
-  if( !aFile )
-    return false;
-
-  const int aBufLen = 256;
-  char aBuf[aBufLen];
-  while( !feof( aFile ) )
-  {
-    fgets( aBuf, aBufLen, aFile );
-    std::string aStr = aBuf;
-  }
-  return false;
+    std::ifstream aStream( theFileName.ToCString(), std::ios::in | std::ios::binary );
+    if ( !aStream )
+        return false;
+
+    bool aRes = true;
+
+    const int aBufLen = 512;
+    char aBuf[aBufLen];
+    while( !aStream.eof() && aRes )
+    {
+        aStream.getline( aBuf, aBufLen );
+        TCollection_ExtendedString aStr( aBuf, Standard_True );
+
+        Standard_Integer aPos = aStr.SearchFromEnd( " " );
+        if ( aPos < 0 )
+            aRes = false;
+        else
+        {
+            TCollection_ExtendedString aValueStr = aStr.Split( aPos );
+            while ( aStr.Length() > 0 && ( aStr.Value( aStr.Length() ) == ' ' || aStr.Value( aStr.Length() ) == '\t' ) )
+                aStr.Remove( aStr.Length() );
+            while ( aStr.Length() > 0 && ( aStr.Value( 1 ) == ' ' || aStr.Value( 1 ) == '\t' ) || aStr.Value( 1 ) < 0 )
+                aStr.Remove( 1 );
+
+            if ( aStr.Length() > 0 && aStr.Value( aStr.Length() ) == '\"' )
+                aStr.Remove( aStr.Length() );
+            if ( aStr.Length() > 0 && aStr.Value( 1 ) == '\"' )
+                aStr.Remove( 1 );
+
+            if ( aValueStr.IsEmpty() || aStr.IsEmpty() )
+                aRes = false;
+            else
+            {
+                Standard_Real aValue = TCollection_AsciiString( aValueStr ).RealValue();
+                Set( aStr, aValue );
+            }
+        }
+    }
+
+    aStream.close();
+    return aRes;
 }
 
 bool HYDROData_StricklerTable::Export( const TCollection_AsciiString& theFileName )
 {
-  //TODO
-  return false;
+    Handle(TDataStd_NamedData) aMap = Map();
+    if ( aMap.IsNull() )
+        return false;
+
+    std::ofstream aStream( theFileName.ToCString(), std::ios::out | std::ios::binary );
+    if ( !aStream )
+        return false;
+
+    bool aRes = true;
+    for ( TDataStd_DataMapIteratorOfDataMapOfStringReal it( aMap->GetRealsContainer() ); it.More() && aRes; it.Next() )
+    {
+        TCollection_ExtendedString aLine = TCollection_ExtendedString( '\"' ) + it.Key() + TCollection_ExtendedString( '\"' ) +
+            TCollection_ExtendedString( ' ' ) + TCollection_ExtendedString( it.Value() );
+        Standard_PCharacter aBuf = (Standard_PCharacter)malloc( aLine.LengthOfCString() + 1 );
+        aStream.write( aBuf, aLine.ToUTF8CString( aBuf ) );
+        aStream.write( "\r\n", 2 );
+        free( aBuf );
+    }
+
+    aStream.close();
+    return aRes;
 }
 
 double HYDROData_StricklerTable::Get( const TCollection_ExtendedString& theType, double theDefault ) const
 {
-  Handle( TDataStd_NamedData ) aMap = Map();
-  if( aMap->HasReal( theType ) )
-    return aMap->GetReal( theType );
-  else
-    return theDefault;
+    Handle( TDataStd_NamedData ) aMap = Map();
+    if( aMap->HasReal( theType ) )
+        return aMap->GetReal( theType );
+    else
+        return theDefault;
 }
 
 void HYDROData_StricklerTable::Set( const TCollection_ExtendedString& theType, double theCoefficient )
 {
-  Handle( TDataStd_NamedData ) aMap = Map();
-  aMap->SetReal( theType, theCoefficient );
+    Handle(TDataStd_NamedData) aMap = Map();
+    aMap->SetReal( theType, theCoefficient );
+}
+
+TColStd_SequenceOfExtendedString HYDROData_StricklerTable::GetTypes() const
+{
+    TColStd_SequenceOfExtendedString aSeq;
+    Handle(TDataStd_NamedData) aMap = Map();
+    if ( !aMap.IsNull() )
+    {
+        for ( TDataStd_DataMapIteratorOfDataMapOfStringReal it( aMap->GetRealsContainer() ); it.More(); it.Next() )
+            aSeq.Append( it.Key() );
+    }
+    return aSeq;
+}
+
+void HYDROData_StricklerTable::Clear()
+{
+    Handle(TDataStd_NamedData) aMap = Map();
+    if ( !aMap.IsNull() )
+        aMap->ChangeReals( TDataStd_DataMapOfStringReal() );
+}
+
+QStringList HYDROData_StricklerTable::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+{
+    QStringList aResList = dumpObjectCreation( theTreatedObjects );
+    QString aPyName = GetObjPyName();
+
+    aResList << QString( "" );
+    Handle(TDataStd_NamedData) aMap = Map();
+    if ( !aMap.IsNull() )
+    {
+        for ( TDataStd_DataMapIteratorOfDataMapOfStringReal it( aMap->GetRealsContainer() ); it.More(); it.Next() )
+        {
+            TCollection_ExtendedString aType = it.Key();
+            Standard_Real aValue = it.Value();
+            aResList << QString( "%1.Set( \"%2\", %3 );" ).arg( aPyName ).arg( QString( (QChar*)aType.ToExtString(), aType.Length() ) ).arg( aValue );
+        }
+    }
+    aResList << QString( "" );
+    aResList << QString( "%1.Update();" ).arg( aPyName );
+
+    return aResList;
 }
 
-Handle( TDataStd_NamedData ) HYDROData_StricklerTable::Map() const
+Handle(TDataStd_NamedData) HYDROData_StricklerTable::Map() const
 {
-  TDF_Label aLabel = myLab.FindChild( DataTag_Table );
-  Handle( TDataStd_NamedData ) aMap;
-  if( !aLabel.FindAttribute( TDataStd_NamedData::GetID(), aMap ) )
-    aMap = TDataStd_NamedData::Set( aLabel );
-  return aMap;
+    TDF_Label aLabel = myLab.FindChild( DataTag_Table );
+    Handle( TDataStd_NamedData ) aMap;
+    if( !aLabel.FindAttribute( TDataStd_NamedData::GetID(), aMap ) )
+        aMap = TDataStd_NamedData::Set( aLabel );
+    return aMap;
 }
index eae46e33b90f50198b51ffb418c2a6d5ac881438..bbc553bec135c93187bd1ffeaf9fd418205d750a 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <HYDROData_Entity.h>
 
+#include <TColStd_SequenceOfExtendedString.hxx>
+
 class Handle( TDataStd_NamedData );
 
 DEFINE_STANDARD_HANDLE( HYDROData_StricklerTable, HYDROData_Entity )
@@ -46,11 +48,17 @@ public:
   HYDRODATA_EXPORT bool Import( const TCollection_AsciiString& theFileName );
   HYDRODATA_EXPORT bool Export( const TCollection_AsciiString& theFileName );
 
-  double Get( const TCollection_ExtendedString& theType, double theDefault ) const;
-  void Set( const TCollection_ExtendedString& theType, double theCoefficient );
+  HYDRODATA_EXPORT double Get( const TCollection_ExtendedString& theType, double theDefault ) const;
+  HYDRODATA_EXPORT void Set( const TCollection_ExtendedString& theType, double theCoefficient );
+
+  HYDRODATA_EXPORT TColStd_SequenceOfExtendedString GetTypes() const;
+
+  HYDRODATA_EXPORT void Clear();
+
+  HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
 
 private:
-  Handle( TDataStd_NamedData ) Map() const;
+  Handle(TDataStd_NamedData) Map() const;
 };
 
 #endif
index b6537bfed6dc4f6023aa1062d4b6683cb930ae64..061428eaa17ca8c4e9fdfe24d817f9c62476b0b3 100644 (file)
@@ -379,14 +379,14 @@ void HYDROGUI_DataModel::update( const int theStudyId )
 
           break;
         }
-        case KIND_STRICKLER_TABLE:
+               case KIND_STRICKLER_TABLE:
         {
           Handle(HYDROData_StricklerTable) aStricklerTableObj =
             Handle(HYDROData_StricklerTable)::DownCast( anObj );
           if( !aStricklerTableObj.IsNull() ) {
             obj = createObject( aStricklerTablesRootObj, aStricklerTableObj );
           }
-          aNoStricklerTableObj++;
+                 aNoStricklerTableObj++;
 
           break;
         }
@@ -798,8 +798,10 @@ void HYDROGUI_DataModel::createDefaultStricklerTable( const Handle(HYDROData_Doc
     Handle(HYDROData_StricklerTable)::DownCast( theDocument->CreateObject(KIND_STRICKLER_TABLE) );     
   if ( !aStricklerTableObj.IsNull() )
   {
-    aStricklerTableObj->Import( HYDROGUI_Tool::ToAsciiString( tr( "DEFAULT_STRICKLER_TABLE_FILE" ) ) );
-    // Set name
+    SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
+    QString defTablePath = resMgr->path( "resources", module()->name(), tr( "DEFAULT_STRICKLER_TABLE_FILE" ) );
+    aStricklerTableObj->Import( HYDROGUI_Tool::ToAsciiString( defTablePath ) );
+       // Set name
     QString aStricklerTableName;
     if ( aStricklerTableObj->GetName().isEmpty() )
     {
index 0a7b0157e72e77b2648704ab0fdb766f986729fb..0a96e7986f8f9afffa28f14b8c0a29c913bfe757 100644 (file)
@@ -494,8 +494,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
     anOp = new HYDROGUI_DigueOp( aModule, theId == EditDigueId );
     break;
   case ImportStricklerTableFromFileId:
+  case ExportStricklerTableFromFileId:
   case EditStricklerTableId:
-    anOp = new HYDROGUI_StricklerTableOp( aModule, theId == EditStricklerTableId );
+    anOp = new HYDROGUI_StricklerTableOp( aModule, theId );
     break;
   case CreateLandCoverId:
   case EditLandCoverId:
index 3bcab2d8feb5a359b51254e12dd948d7074aee74..40269457f68c683b12a6aa1259fd74c758cc1e9c 100644 (file)
 #include <QTableWidget>
 #include <QHeaderView>
 
-HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModule, const QString& theTitle )
-: HYDROGUI_InputPanel( theModule, theTitle ), myName(NULL)
+HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModule, const QString& theTitle, int theType )
+: HYDROGUI_InputPanel( theModule, theTitle ),
+  myType( theType )
 {
-  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
-  myTableGroup = new QGroupBox( tr( "STRICKLER_TABLE_TABLE" ), this );
-
-  // Main layout
-  QVBoxLayout* aTableLayout = new QVBoxLayout( myTableGroup );
-  aTableLayout->setMargin( 5 );
-  aTableLayout->setSpacing( 5 );
-
-  // Buttons
-  myAddBtn = new QToolButton;
-  myAddBtn->setText( tr( "ADD" ) );
-  myRemoveBtn = new QToolButton;
-  myRemoveBtn->setText( tr( "REMOVE" ) );
-  myClearBtn = new QToolButton;
-  myClearBtn->setText( tr( "CLEAR_ALL" ) );
-
-  // Table
-  myTable = new QTableWidget( mainFrame() );
-  myTable->setItemDelegate( new HYDROGUI_LineEditDoubleValidator( this ) );
-  myTable->setEditTriggers( QAbstractItemView::DoubleClicked |
-                            QAbstractItemView::SelectedClicked |
-                            QAbstractItemView::EditKeyPressed );
-
-  myTable->setColumnCount( 2 );
-  QStringList aColumnNames;
-  aColumnNames << tr( "STRICKLER_TYPE" ) << tr( "STRICKLER_COEFFICIENT" );
-  myTable->setHorizontalHeaderLabels( aColumnNames );
-
-  myTable->horizontalHeader()->setStretchLastSection( false);
-  myTable->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch );
-  myTable->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents );
-
-  myTable->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents );
-
-  // Layout
-  // buttons
-  QHBoxLayout* aButtonsLayout = new QHBoxLayout();
-  aButtonsLayout->addWidget( myAddBtn );
-  aButtonsLayout->addWidget( myRemoveBtn );
-  aButtonsLayout->addStretch( 1 );
-  aButtonsLayout->addWidget( myClearBtn );
-
-  // main
-  aTableLayout->addLayout( aButtonsLayout );
-  aTableLayout->addWidget( myTable );
-  
-  // Common
-  addWidget( myFileNameGroup );
-  addWidget( myNameGroup );
-  addWidget( myTableGroup );
-  
-  // Update controls
-  updateControls();
-
-  // Connections
-  connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
-  connect( myAddBtn, SIGNAL( clicked() ), this, SLOT( onAddCoefficient() ) );
-  connect( myRemoveBtn, SIGNAL( clicked() ), this, SLOT( onRemoveCoefficient() ) );
-  connect( myClearBtn, SIGNAL( clicked() ), this, SLOT( onClearCoefficients() ) );
-  connect( myTable->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), 
-           this, SLOT( onSelectionChanged() ) );  
-
-  setMinimumWidth( 350 );
-}
+    SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+
+    QString fileGroupTitle = theType == Export ? tr( "EXPORT_STRICKLER_TABLE_FILE" ) : tr( "IMPORT_STRICKLER_TABLE_FILE" );
+
+    // Import Strickler table from file
+    QGroupBox* aFileNameGroup = new QGroupBox( fileGroupTitle, this );
+    aFileNameGroup->setVisible( theType != Edit );
+
+    QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), aFileNameGroup );
+
+    myFileName = new QLineEdit( aFileNameGroup );
+    myFileName->setReadOnly( true );
+
+    QToolButton* aBrowseBtn = new QToolButton( aFileNameGroup );
+    aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
+
+    QBoxLayout* aFileNameLayout = new QHBoxLayout( aFileNameGroup );
+    aFileNameLayout->setMargin( 5 );
+    aFileNameLayout->setSpacing( 5 );
+    aFileNameLayout->addWidget( aFileNameLabel );
+    aFileNameLayout->addWidget( myFileName );
+    aFileNameLayout->addWidget( aBrowseBtn );
+
+    // Strickler table name
+    QGroupBox* aNameGroup = new QGroupBox( tr( "STRICKLER_TABLE_NAME" ), this );
+
+    QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), aNameGroup );
+    myName = new QLineEdit( aNameGroup );
+
+    QBoxLayout* anImageNameLayout = new QHBoxLayout( aNameGroup );
+    anImageNameLayout->setMargin( 5 );
+    anImageNameLayout->setSpacing( 5 );
+    anImageNameLayout->addWidget( anImageNameLabel );
+    anImageNameLayout->addWidget( myName );
+
+    // Strickler table
+    QGroupBox* aTableGroup = new QGroupBox( tr( "STRICKLER_TABLE_TABLE" ), this );
+    aTableGroup->setVisible( theType == Edit );
+
+    // Main layout
+    QVBoxLayout* aTableLayout = new QVBoxLayout( aTableGroup );
+    aTableLayout->setMargin( 5 );
+    aTableLayout->setSpacing( 5 );
+
+    // Buttons
+    myAddBtn = new QToolButton;
+    myAddBtn->setText( tr( "ADD" ) );
+    myRemoveBtn = new QToolButton;
+    myRemoveBtn->setText( tr( "REMOVE" ) );
+    myClearBtn = new QToolButton;
+    myClearBtn->setText( tr( "CLEAR_ALL" ) );
+
+    // Table
+    myTable = new QTableWidget( mainFrame() );
+    myTable->setItemDelegate( new HYDROGUI_LineEditDoubleValidator( this ) );
+    myTable->setEditTriggers( QAbstractItemView::DoubleClicked |
+        QAbstractItemView::SelectedClicked |
+        QAbstractItemView::EditKeyPressed );
+
+    myTable->setColumnCount( 2 );
+    QStringList aColumnNames;
+    aColumnNames << tr( "STRICKLER_TYPE" ) << tr( "STRICKLER_COEFFICIENT" );
+    myTable->setHorizontalHeaderLabels( aColumnNames );
+
+    myTable->horizontalHeader()->setStretchLastSection( false);
+    myTable->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch );
+    myTable->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents );
+
+    myTable->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents );
+
+    // Layout
+    // buttons
+    QHBoxLayout* aButtonsLayout = new QHBoxLayout();
+    aButtonsLayout->addWidget( myAddBtn );
+    aButtonsLayout->addWidget( myRemoveBtn );
+    aButtonsLayout->addStretch( 1 );
+    aButtonsLayout->addWidget( myClearBtn );
+
+    // main
+    aTableLayout->addLayout( aButtonsLayout );
+    aTableLayout->addWidget( myTable );
+
+    // Common
+    addWidget( aFileNameGroup );
+    addWidget( aNameGroup );
+    addWidget( aTableGroup );
+
+    // Update controls
+    updateControls();
 
-HYDROGUI_StricklerTableDlg::~HYDROGUI_StricklerTableDlg()
-{
+    // Connections
+    connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
+    connect( myAddBtn, SIGNAL( clicked() ), this, SLOT( onAddCoefficient() ) );
+    connect( myRemoveBtn, SIGNAL( clicked() ), this, SLOT( onRemoveCoefficient() ) );
+    connect( myClearBtn, SIGNAL( clicked() ), this, SLOT( onClearCoefficients() ) );
+    connect( myTable->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), 
+        this, SLOT( onSelectionChanged() ) );  
+
+    setMinimumWidth( 350 );
+
+    if ( theType != Edit )
+        addStretch();
 }
 
-void HYDROGUI_StricklerTableDlg::setIsEdit( const bool theIsEdit )
+HYDROGUI_StricklerTableDlg::~HYDROGUI_StricklerTableDlg()
 {
-  myFileNameGroup->setVisible( !theIsEdit );
-  myNameGroup->setEnabled( theIsEdit );
-  myTableGroup->setVisible( theIsEdit );
-  if ( !theIsEdit )
-    addStretch();
 }
 
 void HYDROGUI_StricklerTableDlg::reset()
 {
-  myFileName->clear();
+    myFileName->clear();
 
-  myName->clear();
-  myNameGroup->setEnabled( false );
+    myName->clear();
 }
 
 QString HYDROGUI_StricklerTableDlg::getFileName() const
 {
-  return myFileName->text();
+    return myFileName->text();
 }
 
 void HYDROGUI_StricklerTableDlg::setFileName( const QString& theName )
 {
-  myFileName->setText( theName );
+    myFileName->setText( theName );
+}
 
-  if ( !myNameGroup->isEnabled() )
-    myNameGroup->setEnabled( true );
+void HYDROGUI_StricklerTableDlg::setTableName( const QString& theName )
+{
+    myName->setText(theName);
 }
 
-void HYDROGUI_StricklerTableDlg::setStricklerTableName( const QString& theName )
+QString HYDROGUI_StricklerTableDlg::getTableName() const
 {
-  myName->setText(theName);
+    return myName->text();
 }
 
-QString HYDROGUI_StricklerTableDlg::getStricklerTableName() const
+bool HYDROGUI_StricklerTableDlg::isTableNameReadOnly() const
 {
-  return myName->text();
+    return myName->isReadOnly();
 }
 
-void HYDROGUI_StricklerTableDlg::setData(const StricklerCoefficientList& theData)
+void HYDROGUI_StricklerTableDlg::setTableNameReadOnly( bool on )
 {
-  myTable->setRowCount( 0 );
+    myName->setReadOnly( on );
+}
 
-  foreach ( const StricklerCoefficient& aData, theData ) {
-    // Check the current Strickler type
-    if ( aData.myType.isEmpty() ) {
-      continue;
+HYDROGUI_StricklerTableDlg::StricklerCoefficientList HYDROGUI_StricklerTableDlg::getData() const
+{
+    StricklerCoefficientList aRes;
+    for ( int i = 0; i < myTable->rowCount(); i++ )
+    {
+        QTableWidgetItem* typeItem = myTable->item( i, 0 );
+        QTableWidgetItem* coeffItem = myTable->item( i, 1 );
+        aRes.append( StricklerCoefficient( typeItem->text(), coeffItem->text().toDouble() ) );
     }
+    return aRes;
+}
 
-    // Get Strickler coefficient value for the current Strickler type
-    QString aCoefficient = HYDROGUI_Tool::GetCoordinateString( aData.myCoefficient, false );
-    
-    // Insert row with the data
-    int aRow = myTable->rowCount();
-    myTable->insertRow( aRow );
+void HYDROGUI_StricklerTableDlg::setData(const StricklerCoefficientList& theData)
+{
+    myTable->setRowCount( 0 );
+
+    foreach ( const StricklerCoefficient& aData, theData ) {
+        // Check the current Strickler type
+        if ( aData.myType.isEmpty() ) {
+            continue;
+        }
+
+        // Get Strickler coefficient value for the current Strickler type
+        QString aCoefficient = HYDROGUI_Tool::GetCoordinateString( aData.myCoefficient, false );
+
+        // Insert row with the data
+        int aRow = myTable->rowCount();
+        myTable->insertRow( aRow );
 
-    // "Type" column
-    QTableWidgetItem* aTypeItem = new QTableWidgetItem( aData.myType );    
-    myTable->setItem( aRow, 0, aTypeItem );
+        // "Type" column
+        QTableWidgetItem* aTypeItem = new QTableWidgetItem( aData.myType );    
+        myTable->setItem( aRow, 0, aTypeItem );
 
-    // "Coefficient" column
-    myTable->setItem( aRow, 1, new QTableWidgetItem( aCoefficient ) );
-  }
+        // "Coefficient" column
+        myTable->setItem( aRow, 1, new QTableWidgetItem( aCoefficient ) );
+    }
 
-  myTable->resizeColumnToContents( 0 );
-  myTable->resizeRowsToContents();
+    myTable->resizeColumnToContents( 0 );
+    myTable->resizeRowsToContents();
 
-  updateControls();
+    updateControls();
 }
 
 void HYDROGUI_StricklerTableDlg::updateControls()
 {
-  bool isTableNotEmpty = myTable->rowCount() > 0;
-  myClearBtn->setEnabled( isTableNotEmpty );  
-  onSelectionChanged();
+    bool isTableNotEmpty = myTable->rowCount() > 0;
+    myClearBtn->setEnabled( isTableNotEmpty );  
+    onSelectionChanged();
 }
 
 void HYDROGUI_StricklerTableDlg::removeRows( const QList<int> theRows )
 {
-  QList<int> aSortedRows = theRows;
-  qSort( aSortedRows );
-
-  int aRowToRemove = -1;
-  int aNbRemoved = 0;
-  foreach ( int aRow, aSortedRows ) {
-    aRowToRemove = aRow - aNbRemoved;
-       if ( myTable->model()->removeRow( aRowToRemove ) ) {
-      aNbRemoved++;
+    QList<int> aSortedRows = theRows;
+    qSort( aSortedRows );
+
+    int aRowToRemove = -1;
+    int aNbRemoved = 0;
+    foreach ( int aRow, aSortedRows ) {
+        aRowToRemove = aRow - aNbRemoved;
+        if ( myTable->model()->removeRow( aRowToRemove ) ) {
+            aNbRemoved++;
+        }
     }
-  }
 
-  if ( aNbRemoved > 0 )
-    updateControls();
+    if ( aNbRemoved > 0 )
+        updateControls();
 }
 
 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 );
-  }
+    QString aFilter( tr( "STRICKLER_TABLE_FILTER" ) );
+    QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, myFileName->parent()->property( "title" ).toString(), myType == Import );
+    if ( !aFileName.isEmpty() )
+    {
+        setFileName( aFileName );
+        emit fileSelected( aFileName );
+    }
 }
 
 /**
-  Add the new default constructed Strickler coefficient.
- */
+Add the new default constructed Strickler coefficient.
+*/
 void HYDROGUI_StricklerTableDlg::onAddCoefficient()
 {
-  int aRow = myTable->rowCount();
-  myTable->insertRow( aRow );
+    int aRow = myTable->rowCount();
+    myTable->insertRow( aRow );
 
-  // Set default type (=> generate unique type name) and coefficient
-  //...
+    // Set default type (=> generate unique type name) and coefficient
+    //...
 
-  updateControls();  
+    updateControls();  
 }
 
 /**
-  Remove the selected Strickler coefficient.
- */
+Remove the selected Strickler coefficient.
+*/
 void HYDROGUI_StricklerTableDlg::onRemoveCoefficient()
 {
-  QList<int> aRows;
-  QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedRows();
-  foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
-    aRows << anIndex.row();
-  }
+    QList<int> aRows;
+    QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedRows();
+    foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
+        aRows << anIndex.row();
+    }
 
-  removeRows( aRows );
+    removeRows( aRows );
 }
 
 /**
-  Clear all Strickler coefficients.
- */
+Clear all Strickler coefficients.
+*/
 void HYDROGUI_StricklerTableDlg::onClearCoefficients()
 {
-  QList<int> aRows;
-  for ( int i=0; i< myTable->rowCount(); i++ ) {
-    aRows << i;
-  }
+    QList<int> aRows;
+    for ( int i=0; i< myTable->rowCount(); i++ ) {
+        aRows << i;
+    }
 
-  removeRows( aRows );
+    removeRows( aRows );
 }
 
 /**
- Slot called on table selection change.
+Slot called on table selection change.
 */
 void HYDROGUI_StricklerTableDlg::onSelectionChanged()
 {
-  QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedRows();
-  myRemoveBtn->setEnabled( aSelectedIndexes.count() > 0 );
+    QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedRows();
+    myRemoveBtn->setEnabled( aSelectedIndexes.count() > 0 );
 }
index fef70326d6f887f42ab82dee11f99874eee8ddb7..0fa872b2d18fd1e27e35e48b70b5af70031a28bd 100644 (file)
@@ -27,67 +27,68 @@ class QGroupBox;
 class QLineEdit;
 class QToolButton;
 class QTableWidget;
+class QtxFilePath;
 
 class HYDROGUI_StricklerTableDlg : public HYDROGUI_InputPanel
 {
-  Q_OBJECT
+    Q_OBJECT
 
 public:
-  struct StricklerCoefficient
-  {
-    QString myType;
-       double  myCoefficient;
+    struct StricklerCoefficient
+    {
+        QString myType;
+        double  myCoefficient;
 
-    StricklerCoefficient(  const QString& theType,
-                           double theCoefficient )
-      : myType( theType ), myCoefficient( theCoefficient ) {}
-  };
-  typedef QList<StricklerCoefficient> StricklerCoefficientList;
+        StricklerCoefficient(  const QString& theType,
+            double theCoefficient )
+            : myType( theType ), myCoefficient( theCoefficient ) {}
+    };
+    typedef QList<StricklerCoefficient> StricklerCoefficientList;
+
+    enum { Edit, Import, Export };
 
 public:
-  HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModule, const QString& theTitle );
-  virtual ~HYDROGUI_StricklerTableDlg();
+    HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModule, const QString& theTitle, int theType );
+    virtual ~HYDROGUI_StricklerTableDlg();
+
+    void                       reset();
 
-  void                       setIsEdit( const bool theIsEdit );
-  void                       reset();
+    QString                    getFileName() const;
+    void                       setFileName( const QString& theName );
 
-  QString                    getFileName() const;
-  void                       setFileName( const QString& theName );
+    void                       setTableName( const QString& theName );
+    QString                    getTableName() const;
 
-  void                       setStricklerTableName( const QString& theName );
-  QString                    getStricklerTableName() const;
+    bool                       isTableNameReadOnly() const;
+    void                       setTableNameReadOnly( bool );
 
-  void                       setData(const StricklerCoefficientList& theData);
+    StricklerCoefficientList   getData() const;
+    void                       setData(const StricklerCoefficientList& theData);
 
 protected:
-  void                       updateControls();
-  void                       removeRows( const QList<int> theRows );
+    void                       updateControls();
+    void                       removeRows( const QList<int> theRows );
 
-protected slots:
-  void                       onBrowse();
+protected Q_SLOTS:
+    void                       onBrowse();
 
-  void                       onAddCoefficient();
-  void                       onRemoveCoefficient();
-  void                       onClearCoefficients();
+    void                       onAddCoefficient();
+    void                       onRemoveCoefficient();
+    void                       onClearCoefficients();
 
-  void                       onSelectionChanged();
+    void                       onSelectionChanged();
 
-signals:
-  void                       fileSelected( const QString& theFileName );
+Q_SIGNALS:
+    void                       fileSelected( const QString& theFileName );
 
 private:
-  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
-
-  QGroupBox*                 myTableGroup; //!< The group for the Strickler table table control and buttons
-  QTableWidget*              myTable;      //!< The table of Strickler coefficients
-  QToolButton*               myAddBtn;     //!< The add Strickler coefficient button
-  QToolButton*               myRemoveBtn;  //!< The remove Strickler coefficient button
-  QToolButton*               myClearBtn;   //!< The clear all Strickler coefficients button
+    int                        myType;
+    QLineEdit*                 myFileName;   //!< Source Strickler table file name input field
+    QLineEdit*                 myName;       //!< The Strickler table name input field
+    QTableWidget*              myTable;      //!< The table of Strickler coefficients
+    QToolButton*               myAddBtn;     //!< The add Strickler coefficient button
+    QToolButton*               myRemoveBtn;  //!< The remove Strickler coefficient button
+    QToolButton*               myClearBtn;   //!< The clear all Strickler coefficients button
 };
 
 #endif
index 464b74854a8da9ce893e9a72461bf31b6564cb10..7cecf388b79803958b5126490607b04b0eb3d59d 100644 (file)
@@ -19,8 +19,9 @@
 #include "HYDROGUI_StricklerTableOp.h"
 
 #include "HYDROGUI_StricklerTableDlg.h"
-#include "HYDROGUI_Tool.h"
 #include "HYDROGUI_DataObject.h"
+#include "HYDROGUI_Operations.h"
+#include "HYDROGUI_Tool.h"
 
 #include <HYDROData_Document.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" ) : tr( "IMPORT_STRICKLER_TABLE" ) );
 }
 
-
 HYDROGUI_StricklerTableOp::~HYDROGUI_StricklerTableOp()
 {
 }
 
 void HYDROGUI_StricklerTableOp::startOperation()
 {   
-  HYDROGUI_Operation::startOperation();
+    HYDROGUI_Operation::startOperation();
 
-  HYDROGUI_StricklerTableDlg* aPanel = (HYDROGUI_StricklerTableDlg*)inputPanel();
-  aPanel->reset();
-  aPanel->setIsEdit( myIsEdit );
+    HYDROGUI_StricklerTableDlg* aPanel = (HYDROGUI_StricklerTableDlg*)inputPanel();
+    aPanel->reset();
 
-  if( myIsEdit )
-  {
-    if ( isApplyAndClose() )
-         myEditedObject = Handle(HYDROData_StricklerTable)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
-    if ( !myEditedObject.IsNull() )
+    if ( !isImport() && isApplyAndClose() )
+        myObject = Handle(HYDROData_StricklerTable)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+
+    if ( isEdit() )
     {
-      // Edit selected Strickler table
-
-      aPanel->setStricklerTableName( myEditedObject->GetName() );
-
-      // Get Strickler table data from the data model
-      // ...
-
-      // The code below is a sample of data filling Strickler table
-      HYDROGUI_StricklerTableDlg::StricklerCoefficientList aData;
-      HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef1( "Zones de champs, prairies, sans cultures", 20.0 );
-      HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef2( "Zones de champs cultivé à végétation basse", 17.5 );
-      HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef3( "Zones de champs cultivé à végétation haute", 12.5 );
-      HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef4( "Zones d'arbustes, de sous-bois", 10.0 );
-      HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef5( "Zones à faible urbanization (bourg)", 9.0 );
-      HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef6( "Zones à forte urbanization (agglomération)", 9.0 );
-      HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef7( "Canaux naturels", 35.0 );
-      HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef8( "Canaux artificiels en béton", 65.0 );
-      aData.append( aStricklerCoef1 );
-      aData.append( aStricklerCoef2 );
-      aData.append( aStricklerCoef3 );
-      aData.append( aStricklerCoef4 );
-      aData.append( aStricklerCoef5 );
-      aData.append( aStricklerCoef6 );
-      aData.append( aStricklerCoef7 );
-      aData.append( aStricklerCoef8 );
-      aPanel->setData(aData);
+        if ( !myObject.IsNull() )
+        {
+            // Edit selected Strickler table
+            aPanel->setTableName( myObject->GetName() );
+
+            // Get Strickler table data from the data model
+            HYDROGUI_StricklerTableDlg::StricklerCoefficientList aData;
+            TColStd_SequenceOfExtendedString aTypes = myObject->GetTypes();
+            for ( int i = 1; i <= aTypes.Length(); i++ )
+                aData.append( HYDROGUI_StricklerTableDlg::StricklerCoefficient( HYDROGUI_Tool::ToQString( aTypes.Value( i ) ),
+                myObject->Get( aTypes.Value( i ), 0 ) ) );
+
+            aPanel->setData( aData );
+        }
     }
-    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( "INCORRECT_OBJECT_NAME" );
+        return false;
+    }
+
+    if ( isImport() || ( isEdit() && !myObject.IsNull() && myObject->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 ( 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( HYDROGUI_Tool::ToAsciiString( aFilePath ) );
+        return res;
+    }
+
+    startDocOperation();
+
+    aStricklerTableObj->SetName( aStricklerTableName );
+
+    if( isEdit() )
+    {
+        // Get data from input panel's table and save it into data model object
+        aStricklerTableObj->Clear();
+        HYDROGUI_StricklerTableDlg::StricklerCoefficientList aData = aPanel->getData();
+        for ( HYDROGUI_StricklerTableDlg::StricklerCoefficientList::iterator it = aData.begin(); it != aData.end(); ++it )
+        {
+            const HYDROGUI_StricklerTableDlg::StricklerCoefficient& anInfo = *it;
+            aStricklerTableObj->Set( HYDROGUI_Tool::ToExtString( anInfo.myType ), anInfo.myCoefficient );
+        }
+    }
+    else
     {
-      theErrorMsg = tr( "SELECT_STRICKLER_TABLE_FILE" ).arg( aFilePath );
-      return false;
+        // Import data from Strickler table file into data model object
+        aStricklerTableObj->Import( HYDROGUI_Tool::ToAsciiString( aFilePath ) );
     }
-  }
-
-  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() )
+
+    aStricklerTableObj->Update();
+
+    commitDocOperation();
+
+    if( !isEdit() )
     {
-      theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aStricklerTableName );
-      return false;
+        QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj );
+        theBrowseObjectsEntries.append( anEntry );
     }
-  }
-
-  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
-    
-    // Check, that type names are unique within the current
-    // Strickler table and show error message, if needed
-
-    //...
-  }
-  else
-  {
-    // Import data from Strickler table file into data model object
-    aStricklerTableObj->Import( HYDROGUI_Tool::ToAsciiString( aFilePath ) );
-  }
-
-  aStricklerTableObj->Update();
-
-  if( !myIsEdit )
-  {
-    QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj );
-    theBrowseObjectsEntries.append( anEntry );
-  }
-
-  theUpdateFlags |= UF_ObjBrowser;
-
-  return true;
+
+    theUpdateFlags |= UF_ObjBrowser;
+
+    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;
 }
index a3b40e2fdbedba0aca77d293746b92cdb0fe7c28..3e2fc546c37d7b53f2571c21ffcd0eeda92042b5 100644 (file)
@@ -28,25 +28,30 @@ class HYDROGUI_StricklerTableOp : public HYDROGUI_Operation
     Q_OBJECT
 
 public:
-       HYDROGUI_StricklerTableOp( HYDROGUI_Module* theModule, bool isEdit );
-       virtual ~HYDROGUI_StricklerTableOp();
+    HYDROGUI_StricklerTableOp( HYDROGUI_Module*, int );
+    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 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();
+protected Q_SLOTS:
+    void                             onFileSelected();
 
 private:
-  bool                             myIsEdit;
-  Handle(HYDROData_StricklerTable) myEditedObject;
+    bool                             isEdit() const;
+    bool                             isImport() const;
+    bool                             isExport() const;
+
+private:
+    int                              myType;
+    Handle(HYDROData_StricklerTable) myObject;
 };
 
 #endif
index 0b6e4a6c095a7ebc3c27283c2a045f98c6f47fff..998b0f0137aeb1c5769e5ac868a88f95043ef542 100644 (file)
@@ -2355,8 +2355,12 @@ Polyline should consist from one not closed curve.</translation>
   <context>
     <name>HYDROGUI_StricklerTableDlg</name>
     <message>
-      <source>IMPORT_STRICKLER_TABLE_FROM_FILE</source>
-      <translation>Import Strickler table from file</translation>
+      <source>IMPORT_STRICKLER_TABLE_FILE</source>
+      <translation>Import Strickler table file</translation>
+    </message>
+    <message>
+      <source>EXPORT_STRICKLER_TABLE_FILE</source>
+      <translation>Export Strickler table file</translation>
     </message>
     <message>
       <source>FILE_NAME</source>