Salome HOME
land cover map icon
[modules/hydro.git] / src / HYDROData / HYDROData_StricklerTable.cxx
index 212f9543f51193b9919010ef3f4dc26ff63a3138..1c51cf1e49f3849312becdd6ba28145b8894bb8b 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <HYDROData_StricklerTable.h>
 #include <HYDROData_Tool.h>
+#include <HYDROData_Iterator.h>
 
 #include <TDataStd_NamedData.hxx>
 
 #include <QFile>
 #include <QTextStream>
 
-IMPLEMENT_STANDARD_HANDLE( HYDROData_StricklerTable, HYDROData_Entity )
 IMPLEMENT_STANDARD_RTTIEXT( HYDROData_StricklerTable, HYDROData_Entity )
 
 HYDROData_StricklerTable::HYDROData_StricklerTable()
+: HYDROData_Entity( Geom_No )
 {
 }
 
@@ -201,24 +202,36 @@ void HYDROData_StricklerTable::Clear()
     aMap->ChangeReals( TDataStd_DataMapOfStringReal() );
 }
 
-QStringList HYDROData_StricklerTable::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+QStringList HYDROData_StricklerTable::DumpToPython( const QString& thePyScriptPath,
+                                                    MapOfTreatedObjects& theTreatedObjects ) const
 {
   QStringList aResList = dumpObjectCreation( theTreatedObjects );
   QString aPyName = GetObjPyName();
 
+  QString anAttrName = GetAttrName();
+  aResList << QString( "%1.SetAttrName( \"%2\" )" ).arg( aPyName ).arg( anAttrName );
+
   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();
+      QString aType = HYDROData_Tool::toQString( 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( "%1.Set( u\"%2\", %3 )" ).arg( aPyName ).arg( aType ).arg( aValue );
+
+      QString anAttrValue = GetAttrValue( aType );
+      aResList << QString( "%1.SetAttrValue( u\"%2\", \"%3\" )" ).arg( aPyName ).arg( aType ).arg( anAttrValue );
+      
+      QColor aColor = GetColor( aType );
+      aResList << QString( "%1.SetColor( u\"%2\", QColor( %3, %4, %5 ) )" ).
+        arg( aPyName ).arg( aType ).arg( aColor.red() ).arg( aColor.green() ).arg( aColor.blue() );
+      aResList << QString();
     }
   }
   aResList << QString( "" );
-  aResList << QString( "%1.Update();" ).arg( aPyName );
+  aResList << QString( "%1.Update()" ).arg( aPyName );
 
   return aResList;
 }
@@ -241,9 +254,22 @@ QString HYDROData_StricklerTable::GetAttrName() const
   }
   return QString();}
 
-void HYDROData_StricklerTable::SetAttrName( const QString& theAttrName ) const
+bool HYDROData_StricklerTable::SetAttrName( const QString& theAttrName ) const
 {
+  HYDROData_Iterator anIt( HYDROData_Document::Document( myLab ), KIND_STRICKLER_TABLE );
+  for( ; anIt.More(); anIt.Next() )
+  {
+    Handle( HYDROData_StricklerTable ) aTable = 
+      Handle( HYDROData_StricklerTable )::DownCast( anIt.Current() );
+    if( aTable->Label()==myLab )
+      continue;
+
+    if( theAttrName==aTable->GetAttrName() )
+      return false;
+  }
+
   TDataStd_AsciiString::Set( myLab.FindChild( DataTag_AttrName ), HYDROData_Tool::toExtString( theAttrName ) );
+  return true;
 }
 
 QString HYDROData_StricklerTable::GetAttrValue( const QString& theType ) const
@@ -265,6 +291,9 @@ void HYDROData_StricklerTable::SetAttrValue( const QString& theType, const QStri
 
 QString HYDROData_StricklerTable::GetType( const QString& theAttrValue ) const
 {
+  if( theAttrValue.isEmpty() )
+    return "";
+
   Handle( TDataStd_NamedData ) aMap = Map();
   TCollection_ExtendedString anAttrValue = HYDROData_Tool::toExtString( theAttrValue );
   for( TDataStd_DataMapIteratorOfDataMapOfStringString it( aMap->GetStringsContainer() ); it.More(); it.Next() )
@@ -303,4 +332,17 @@ void HYDROData_StricklerTable::SetColor( const QString& theType, const QColor& t
   int b = theColor.blue();
   int aColorInt = ( r<<16 ) + ( g<<8 ) + b;
   aMap->SetInteger( aType, aColorInt );
+
+  // synchronize the color for the same type in other maps
+  HYDROData_Iterator anIt( HYDROData_Document::Document( myLab ), KIND_STRICKLER_TABLE );
+  for( ; anIt.More(); anIt.Next() )
+  {
+    Handle( HYDROData_StricklerTable ) aTable = 
+      Handle( HYDROData_StricklerTable )::DownCast( anIt.Current() );
+    if( aTable->Label()==myLab )
+      continue;
+
+    if( aTable->HasType( theType ) )
+      aTable->Map()->SetInteger( aType, aColorInt );
+  }
 }