Salome HOME
Merge remote-tracking branch 'origin/BR_LAND_COVER' into BR_v14_rc
[modules/hydro.git] / src / HYDROData / HYDROData_StricklerTable.cxx
index 68995e824be7ab26e9824459bf25e8a1567d3a3c..564b65f17663ff834c03a37aef50e267ad0775a9 100644 (file)
@@ -81,7 +81,7 @@ bool HYDROData_StricklerTable::Import( const TCollection_AsciiString& theFileNam
             else
             {
                 Standard_Real aValue = TCollection_AsciiString( aValueStr ).RealValue();
-                Set( aStr, aValue );
+                Set( QString( (QChar*)aStr.ToExtString(), aStr.Length() ), aValue );
             }
         }
     }
@@ -115,33 +115,59 @@ bool HYDROData_StricklerTable::Export( const TCollection_AsciiString& theFileNam
     return aRes;
 }
 
-double HYDROData_StricklerTable::Get( const TCollection_ExtendedString& theType, double theDefault ) const
+double HYDROData_StricklerTable::Get( const QString& theType, double theDefault ) const
 {
     Handle( TDataStd_NamedData ) aMap = Map();
-    if( aMap->HasReal( theType ) )
-        return aMap->GetReal( theType );
+    TCollection_ExtendedString aType = toExtString( theType );
+    if( aMap->HasReal( aType ) )
+        return aMap->GetReal( aType );
     else
         return theDefault;
 }
 
-void HYDROData_StricklerTable::Set( const TCollection_ExtendedString& theType, double theCoefficient )
+void HYDROData_StricklerTable::Set( const QString& theType, double theCoefficient )
 {
     Handle(TDataStd_NamedData) aMap = Map();
-    aMap->SetReal( theType, theCoefficient );
+    aMap->SetReal( toExtString( theType ), theCoefficient );
 }
 
-TColStd_SequenceOfExtendedString HYDROData_StricklerTable::GetTypes() const
+void HYDROData_StricklerTable::GetCoefficientRange( double& theMin, double& theMax ) const
 {
-    TColStd_SequenceOfExtendedString aSeq;
+  theMin = 0;
+  theMax = 0;
+  
+  Handle(TDataStd_NamedData) aMap = Map();
+  Standard_Boolean isFirst = Standard_True;
+  for ( TDataStd_DataMapIteratorOfDataMapOfStringReal it( aMap->GetRealsContainer() ); it.More(); it.Next() ) {
+    Standard_Real aValue = it.Value();
+    if ( theMin == 0 || aValue < theMin ) {
+      theMin = aValue;
+    }
+    if ( theMax == 0 || aValue > theMax ) {
+      theMax = aValue;
+    }
+  }
+}
+
+QStringList HYDROData_StricklerTable::GetTypes() const
+{
+    QStringList aSeq;
     Handle(TDataStd_NamedData) aMap = Map();
     if ( !aMap.IsNull() )
     {
         for ( TDataStd_DataMapIteratorOfDataMapOfStringReal it( aMap->GetRealsContainer() ); it.More(); it.Next() )
-            aSeq.Append( it.Key() );
+            aSeq.append( toQString( it.Key() ) );
     }
     return aSeq;
 }
 
+bool HYDROData_StricklerTable::HasType( const TCollection_ExtendedString& theType ) const
+{
+  Handle(TDataStd_NamedData) aMap = Map();
+  
+  return !aMap.IsNull() && aMap->HasReal( theType );
+}
+
 void HYDROData_StricklerTable::Clear()
 {
     Handle(TDataStd_NamedData) aMap = Map();
@@ -179,3 +205,23 @@ Handle(TDataStd_NamedData) HYDROData_StricklerTable::Map() const
         aMap = TDataStd_NamedData::Set( aLabel );
     return aMap;
 }
+
+TCollection_ExtendedString HYDROData_StricklerTable::toExtString( const QString& theStr ) const
+{
+    TCollection_ExtendedString aRes;
+    if( !theStr.isEmpty() )
+    {
+           Standard_ExtString extStr = new Standard_ExtCharacter[ ( theStr.length() + 1 ) * 2 ];
+           memcpy( (void*)extStr, theStr.unicode(), theStr.length() * 2 );
+           ((short*)extStr)[theStr.length()] = '\0';
+
+           aRes = TCollection_ExtendedString( extStr );
+           delete [] extStr;
+    }
+    return aRes;
+}
+
+QString HYDROData_StricklerTable::toQString( const TCollection_ExtendedString& theStr ) const
+{
+    return QString( (QChar*)theStr.ToExtString(), theStr.Length() );
+}