From: asl Date: Fri, 13 Nov 2015 10:57:46 +0000 (+0300) Subject: refs #673: test for export to Telemac X-Git-Tag: v1.5~47^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=03d52a4ea5316df6694a3cd4227565d5ac3da63d;p=modules%2Fhydro.git refs #673: test for export to Telemac --- diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 7e042950..e1e4c818 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -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 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 aVerticesMap; NCollection_IndexedDataMap< TopoDS_Edge, QList > anEdgesMap; - NCollection_IndexedDataMap< TopoDS_Face, QList > aFacesMap; + typedef QPair< QString, QList > 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 >::Iterator anIt3( aFacesMap ); + NCollection_IndexedDataMap< TopoDS_Face, FaceData >::Iterator anIt3( aFacesMap ); for( ; anIt3.More(); anIt3.Next() ) { - QList anEdgesIds = anIt3.Value(); + QString aType = anIt3.Value().first; + QList anEdgesIds = anIt3.Value().second; + aStream << "\"" << aType << "\" "; foreach( int anId, anEdgesIds ) aStream << anId << " "; aStream << "\n"; diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx index 737a6cb9..4ace8945 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx @@ -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() << 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() << 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() << 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(); +} diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.h b/src/HYDRO_tests/test_HYDROData_LandCoverMap.h index 8772f9db..36c8f6bd 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.h +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.h @@ -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 );