From 5ba15d9e3af1ec62b62c3d5d7a68be20885039b0 Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 16 Oct 2015 11:22:09 +0300 Subject: [PATCH] #673: draft version of the export to Telemac --- src/HYDROData/HYDROData_LandCoverMap.cxx | 92 +++++++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index c7064889..9405b144 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -31,12 +31,20 @@ #include #include #include +#include #include #include #include +#include #include +#include #include +#include + +const char TELEMAC_FORMAT = 'f'; +const int TELEMAC_PRECISION = 3; + IMPLEMENT_STANDARD_HANDLE(HYDROData_LandCoverMap, HYDROData_Entity) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity) @@ -179,6 +187,13 @@ bool HYDROData_LandCoverMap::ExportQGIS( const QString& theFileName ) const return false; } +void EdgeDiscretization( const TopoDS_Edge& theEdge, + NCollection_IndexedMap& theVerticesMap, + QList& theVerticesIds ) +{ + //TODO +} + /** Export the land cover map for the solver (Telemac) @param theFileName the name of file @@ -186,8 +201,81 @@ bool HYDROData_LandCoverMap::ExportQGIS( const QString& theFileName ) const */ bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName ) const { - //TODO - return false; + TopoDS_Shell aShell; //TODO: unite all the faces of land covers into the shell + + NCollection_IndexedMap aVerticesMap; + NCollection_IndexedDataMap< TopoDS_Edge, QList > anEdgesMap; + NCollection_IndexedDataMap< TopoDS_Face, QList > aFacesMap; + + // add into the map all edges existing in the shell + TopExp_Explorer anExp1( aShell, TopAbs_EDGE ); + for( ; anExp1.More(); anExp1.Next() ) + { + TopoDS_Edge anEdge = TopoDS::Edge( anExp1.Current() ); + QList aVerticesIdsList; + EdgeDiscretization( anEdge, aVerticesMap, aVerticesIdsList ); + anEdgesMap.Add( anEdge, aVerticesIdsList ); + } + + // add into the map all faces existing in the shell and correspondence between face and edges ids + TopExp_Explorer anExp2( aShell, TopAbs_FACE ); + for( ; anExp2.More(); anExp2.Next() ) + { + TopoDS_Face aFace = TopoDS::Face( anExp2.Current() ); + TopExp_Explorer anExp3( aFace, TopAbs_EDGE ); + QList anEdgesIdsList; + for( ; anExp3.More(); anExp3.Next() ) + { + TopoDS_Edge anEdge = TopoDS::Edge( anExp3.Current() ); + int anEdgeId = anEdgesMap.FindIndex( anEdge ); + anEdgesIdsList.append( anEdgeId ); + } + aFacesMap.Add( aFace, anEdgesIdsList ); + } + + QFile aFile( theFileName ); + if( !aFile.open( QFile::WriteOnly | QFile::Text ) ) + return false; + + QTextStream aStream( &aFile ); + aStream << "# nodes\n"; + NCollection_IndexedMap::Iterator anIt1( aVerticesMap ); + for( ; anIt1.More(); anIt1.Next() ) + { + gp_Pnt aPnt = anIt1.Value(); + aStream << QString::number( aPnt.X(), TELEMAC_FORMAT, TELEMAC_PRECISION ); + aStream << " "; + aStream << QString::number( aPnt.Y(), TELEMAC_FORMAT, TELEMAC_PRECISION ); + aStream << " "; + aStream << QString::number( aPnt.Z(), TELEMAC_FORMAT, TELEMAC_PRECISION ); + aStream << "\n"; + } + aStream << "\n"; + + aStream << "# edges\n"; + NCollection_IndexedDataMap< TopoDS_Edge, QList >::Iterator anIt2( anEdgesMap ); + for( ; anIt2.More(); anIt2.Next() ) + { + QList aVerticesIds = anIt2.Value(); + foreach( int anId, aVerticesIds ) + aStream << anId << " "; + aStream << "\n"; + } + aStream << "\n"; + + aStream << "# faces\n"; + NCollection_IndexedDataMap< TopoDS_Face, QList >::Iterator anIt3( aFacesMap ); + for( ; anIt3.More(); anIt3.Next() ) + { + QList anEdgesIds = anIt3.Value(); + foreach( int anId, anEdgesIds ) + aStream << anId << " "; + aStream << "\n"; + } + aStream << "\n"; + + aFile.close(); + return true; } /** -- 2.39.2