Salome HOME
refs #562: basic logic for Strickler table operation and dialog.
[modules/hydro.git] / src / HYDROData / HYDROData_StricklerTable.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROData_StricklerTable.h>
20 #include <TDataStd_NamedData.hxx>
21
22 IMPLEMENT_STANDARD_HANDLE( HYDROData_StricklerTable, HYDROData_Entity )
23 IMPLEMENT_STANDARD_RTTIEXT( HYDROData_StricklerTable, HYDROData_Entity )
24
25 HYDROData_StricklerTable::HYDROData_StricklerTable()
26 {
27 }
28
29 HYDROData_StricklerTable::~HYDROData_StricklerTable()
30 {
31 }
32
33 const ObjectKind HYDROData_StricklerTable::GetKind() const
34 {
35   return KIND_STRICKLER_TABLE;
36 }
37
38 bool HYDROData_StricklerTable::Import( const TCollection_AsciiString& theFileName )
39 {
40   FILE* aFile = fopen( theFileName.ToCString(), "r" );
41   if( !aFile )
42     return false;
43
44   const int aBufLen = 256;
45   char aBuf[aBufLen];
46   while( !feof( aFile ) )
47   {
48     fgets( aBuf, aBufLen, aFile );
49     std::string aStr = aBuf;
50   }
51   return false;
52 }
53
54 bool HYDROData_StricklerTable::Export( const TCollection_AsciiString& theFileName )
55 {
56   //TODO
57   return false;
58 }
59
60 double HYDROData_StricklerTable::Get( const TCollection_ExtendedString& theType, double theDefault ) const
61 {
62   Handle( TDataStd_NamedData ) aMap = Map();
63   if( aMap->HasReal( theType ) )
64     return aMap->GetReal( theType );
65   else
66     return theDefault;
67 }
68
69 void HYDROData_StricklerTable::Set( const TCollection_ExtendedString& theType, double theCoefficient )
70 {
71   Handle( TDataStd_NamedData ) aMap = Map();
72   aMap->SetReal( theType, theCoefficient );
73 }
74
75 Handle( TDataStd_NamedData ) HYDROData_StricklerTable::Map() const
76 {
77   TDF_Label aLabel = myLab.FindChild( DataTag_Table );
78   Handle( TDataStd_NamedData ) aMap;
79   if( !aLabel.FindAttribute( TDataStd_NamedData::GetID(), aMap ) )
80     aMap = TDataStd_NamedData::Set( aLabel );
81   return aMap;
82 }