Salome HOME
bug #702
[modules/hydro.git] / src / HYDROData / HYDROData_LandCoverMap.cxx
index 79cd217567fce60f7e3316d702887a750b6bc57a..33a705cd434ca9dc6ba2940c3d3350c118eb910d 100644 (file)
@@ -54,6 +54,7 @@
 #include <ShapeFix_Shape.hxx>
 #include <BRepCheck_Shell.hxx>
 #include <BRepCheck_ListOfStatus.hxx>
+#include <TopTools_SequenceOfShape.hxx>
 
 
 #include <QFile>
@@ -228,34 +229,6 @@ bool HYDROData_LandCoverMap::IsEmpty() const
     return false;
 }
 
-bool HYDROData_LandCoverMap::ImportSHP( const QString& theSHPFileName )
-{
-  HYDROData_ShapeFile anImporter;
-  QStringList aPolygonsList;
-  TopTools_SequenceOfShape aPolygonFaces;
-  int aShapeTypeOfFile;
-  int aStatus = anImporter.ImportPolygons( theSHPFileName, aPolygonsList, aPolygonFaces, aShapeTypeOfFile);
-
-  bool isOK = ( aStatus == 1 );
-  if( isOK )
-  {
-    QString aDefaultStricklerType = "";
-
-    HYDROData_MapOfFaceToStricklerType aFaces;
-    for( int i=1, n=aPolygonFaces.Length(); i<=n; i++ )
-    {
-      TopoDS_Shape aShape = aPolygonFaces.Value( i );
-      if( aShape.ShapeType()==TopAbs_FACE )
-        aFaces.Add( TopoDS::Face( aShape ), aDefaultStricklerType );
-    }
-
-    StoreLandCovers( aFaces );
-  }
-
-  anImporter.Free();
-  return isOK;
-}
-
 /**
   Load attributes from DBF File
 ///
@@ -302,11 +275,6 @@ HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QStri
     return DBFStatus_NO_DBFVALUES_CORRESPONDENCE_WARNING;
 }
 
-void HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName ) const
-{
-  //TODO
-}
-
 /**
   Export attributes to DBF File
 ///
@@ -971,8 +939,7 @@ QStringList HYDROData_LandCoverMap::DumpToPython( const QString&       thePyScri
   QString aDbfFileName = thePyScriptPath;
   aDbfFileName.replace( ".py", ".dbf" );
 
-  //TODO: export shape file
-  ExportSHP( aShpFileName );
+  ExportSHP( aShpFileName, true, 0.1 );
 
   QString anAttr = "CODE_06"; //TODO: some custom choice
   QStringList anAttrValues, aTypes;
@@ -1036,3 +1003,59 @@ double HYDROData_LandCoverMap::GetTransparency() const
   return anAttr->Get();
   
 }
+
+bool HYDROData_LandCoverMap::ImportSHP( const QString& theSHPFileName,
+                                        const QList<int>& theIndices )
+{
+  HYDROData_ShapeFile anImporter;
+  QStringList aPolyList; 
+  TopTools_SequenceOfShape aFaces;
+  int aSHapeType = -1;
+  int Stat = anImporter.ImportPolygons(theSHPFileName, aPolyList, aFaces, aSHapeType);
+  //
+  if (Stat != 1)
+    return false;
+  //
+  HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+  int maxInd = *std::max_element(theIndices.begin(), theIndices.end());
+  if (maxInd > aPolyList.length())
+    return false;
+  //
+  if (theIndices.empty())
+  {
+    //import all shapes
+    for ( int i = 1; i <=aFaces.Length(); i++ )
+    {
+      TopoDS_Shape aShape = aFaces(i);
+      if ( aShape.IsNull() ) 
+        continue;
+      aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
+    }
+  }
+  else
+  {
+    //import given indices
+    foreach ( int Ind, theIndices )
+    {
+      TopoDS_Shape aShape = aFaces(Ind + 1);
+      if ( aShape.IsNull() ) 
+        continue;
+      aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
+    }
+  }
+  //
+  StoreLandCovers(aMapFace2ST);
+  return true;
+}
+
+bool HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName, bool bUseDiscr, double theDefl) const
+{
+  HYDROData_ShapeFile anExporter;
+  QStringList aList;
+  anExporter.Export(theSHPFileName, this, aList, bUseDiscr, theDefl );
+  if (aList.empty())
+    return true;
+  else 
+    return false;
+}
+