]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #673: test for export to Telemac
authorasl <asl@opencascade.com>
Fri, 13 Nov 2015 10:57:46 +0000 (13:57 +0300)
committerasl <asl@opencascade.com>
Fri, 13 Nov 2015 10:58:24 +0000 (13:58 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx
src/HYDRO_tests/test_HYDROData_LandCoverMap.h

index 7e0429504fa534da86b78183979539ea6551256b..e1e4c818f22dc7c21b34348985bc2614a8982f20 100644 (file)
@@ -344,15 +344,20 @@ bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName, Standard
 {
   TopoDS_Shape aLandCoverMapShape = GetShape();
   TopTools_ListOfShape aListOfFaces;
-  TopExp_Explorer anExp( aLandCoverMapShape, TopAbs_FACE );
-  for( ; anExp.More(); anExp.Next() )
-    aListOfFaces.Append( anExp.Current() );
+  Iterator anIt( *this );
+  QMap<Handle(TopoDS_TShape), QString> aTypesMap;
+  for( ; anIt.More(); anIt.Next() )
+  {
+    aListOfFaces.Append( anIt.Face() );
+    aTypesMap.insert( anIt.Face().TShape(), anIt.StricklerType() );
+  }
 
   TopoDS_Shape aShape = MergeFaces( aListOfFaces, false );
 
   NCollection_IndexedMap<gp_Pnt> aVerticesMap;
   NCollection_IndexedDataMap< TopoDS_Edge, QList<int> > anEdgesMap;
-  NCollection_IndexedDataMap< TopoDS_Face, QList<int> > aFacesMap;
+  typedef QPair< QString, QList<int> > FaceData;
+  NCollection_IndexedDataMap< TopoDS_Face, FaceData > aFacesMap;
 
   // add into the map all edges existing in the shell
   TopExp_Explorer anExp1( aShape, TopAbs_EDGE );
@@ -377,7 +382,11 @@ bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName, Standard
       int anEdgeId = anEdgesMap.FindIndex( anEdge );
       anEdgesIdsList.append( anEdgeId );
     }
-    aFacesMap.Add( aFace, anEdgesIdsList );
+
+    FaceData aData;
+    aData.first = aTypesMap[aFace.TShape()];
+    aData.second = anEdgesIdsList;
+    aFacesMap.Add( aFace, aData );
   }
 
   QFile aFile( theFileName );
@@ -411,10 +420,12 @@ bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName, Standard
   aStream << "\n";
 
   aStream << "# faces\n";
-  NCollection_IndexedDataMap< TopoDS_Face, QList<int> >::Iterator anIt3( aFacesMap );
+  NCollection_IndexedDataMap< TopoDS_Face, FaceData >::Iterator anIt3( aFacesMap );
   for( ; anIt3.More(); anIt3.Next() )
   {
-    QList<int> anEdgesIds = anIt3.Value();
+    QString aType = anIt3.Value().first;
+    QList<int> anEdgesIds = anIt3.Value().second;
+    aStream << "\"" << aType << "\" ";
     foreach( int anId, anEdgesIds )
       aStream << anId << " ";
     aStream << "\n";
index 737a6cb97e8d0472a9797301684131f5e55b7d43..4ace894540802fcb20f3de883c2db2a4cdd2e4d3 100644 (file)
@@ -945,3 +945,35 @@ void test_HYDROData_LandCoverMap::test_split_2()
 
   aDoc->Close();
 }
+
+void test_HYDROData_LandCoverMap::test_export_telemac()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+  Handle(HYDROData_StricklerTable) aTable =
+    Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
+  CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
+
+  Handle(HYDROData_LandCoverMap) aMap =
+    Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+
+  TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
+  CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) );
+
+  TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37   << 37 << 40  << 61 <<
+                                              44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
+                                             128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
+                                              31 << 114 );
+  CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) );
+
+  TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1   << 47 << 51  << 45 <<
+                                            127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
+  CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) );
+
+  QString aTmpFileName = "test.telemac";
+  QString aTmpPath = QDir::tempPath() + "/" + aTmpFileName;
+  CPPUNIT_ASSERT_EQUAL( true, aMap->ExportTelemac( aTmpPath, 1E-4 ) );
+  CPPUNIT_ASSERT_SCRIPTS_EQUAL( aTmpFileName );
+
+  aDoc->Close();
+}
index 8772f9dbf6ad8de54a919a4ff9ac18c54355bf92..36c8f6bd8ca1cd81ff47233a18488baa67760fe4 100644 (file)
@@ -42,6 +42,7 @@ class test_HYDROData_LandCoverMap : public CppUnit::TestFixture
   CPPUNIT_TEST( test_dump_python );
   CPPUNIT_TEST( test_transparent_prs );
   CPPUNIT_TEST( test_assign_to_calc_case );
+  CPPUNIT_TEST( test_export_telemac );
 #ifdef SHP_TESTS
   CPPUNIT_TEST( test_shp_import_cyp );
   CPPUNIT_TEST( test_shp_import_clc_dec );
@@ -71,6 +72,7 @@ public:
   void test_shp_import_clc_dec();
   void test_shp_import_nld_areas();
   void test_shp_loop_back();
+  void test_export_telemac();
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_LandCoverMap );