Salome HOME
test Strickler
[modules/hydro.git] / src / HYDROData / HYDROData_LandCoverMap.cxx
index 7afb3132cdb25b1224543faf1a4c08cd5adc8872..18eaeee8f584d2a19cb444de85aa5a08529895a2 100644 (file)
 #include <BRepCheck_Shell.hxx>
 #include <BRepCheck_ListOfStatus.hxx>
 #include <TopTools_SequenceOfShape.hxx>
-#include <Handle_Geom_Curve.hxx>
-#include <Handle_Geom_Line.hxx>
-#include <Handle_Geom_TrimmedCurve.hxx>
+#include <Geom_Curve.hxx>
+#include <Geom_Line.hxx>
+#include <Geom_TrimmedCurve.hxx>
 #include <Geom_TrimmedCurve.hxx>
 #include <TopTools_DataMapOfShapeListOfShape.hxx>
 #include <NCollection_DoubleMap.hxx>
 #include <HYDROData_LCM_FaceClassifier.h>
+#include <QDir>
 
 #include <stdexcept>
 
@@ -77,7 +78,6 @@ const char TELEMAC_FORMAT = 'f';
 const int TELEMAC_PRECISION = 3;
 
 
-IMPLEMENT_STANDARD_HANDLE(HYDROData_LandCoverMap, HYDROData_Entity)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity)
 
 /**
@@ -367,7 +367,8 @@ bool EdgeDiscretization( const TopoDS_Edge& theEdge,
 */
 bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName,
                                             double theDeflection,
-                                            const Handle(HYDROData_StricklerTable)& theTable ) const
+                                            const Handle(HYDROData_StricklerTable)& theTable,
+                                            QString& statMessage) const
 {
   TopoDS_Shape aLandCoverMapShape = GetShape();
   TopTools_ListOfShape aListOfFaces;
@@ -418,7 +419,19 @@ bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName,
 
   QFile aFile( theFileName );
   if( !aFile.open( QFile::WriteOnly | QFile::Text ) )
-    return false;
+  {
+    QString homeFilePath = QDir::home().absoluteFilePath( theFileName );
+    aFile.setFileName(homeFilePath);
+    if (aFile.open( QFile::WriteOnly | QFile::Text ) )
+      statMessage = "Telemac file have been exported to the home directory: " + homeFilePath;
+    else
+      return false;
+  }
+  else
+  {
+    QString absFilePath = QDir::current().absoluteFilePath( theFileName );
+    statMessage = "Telemac file have been exported to the current directory: " + absFilePath;
+  }
 
   QTextStream aStream( &aFile );
   aStream << "# nodes\n";
@@ -1071,7 +1084,7 @@ TopoDS_Face HYDROData_LandCoverMap::FindByPoint( const gp_Pnt2d& thePoint, QStri
 
 void Dump( const QString& theName, const QStringList& theList, QStringList& theLines )
 {
-  theLines.append( QString( "%1 = QStringList()" ).arg( theName ) );
+  theLines.append( QString( "%1 = []" ).arg( theName ) );
   foreach( QString anItem, theList )
     theLines.append( QString( "%1.append( u\"%2\" )" ).arg( theName ).arg( anItem ) );
 }
@@ -1098,13 +1111,15 @@ QStringList HYDROData_LandCoverMap::DumpToPython( const QString&       thePyScri
   HYDROData_Document::Document( myLab )->CollectQGISValues( anAttr, anAttrValues, aTypes );
   ExportDBF( aDbfFileName, anAttr, anAttrValues, aTypes );
 
-  aResList << QString( "%1.ImportSHP( '%2' )" ).
+  aResList << QString( "if not(%1.ImportSHP( '%2' )):" ).
     arg( aName ).arg( QFileInfo( aShpFileName ).fileName() );
+  aResList << QString( "  raise ValueError('problem while loading LandCoverMap shape')" );
 
   Dump( "attr_values", anAttrValues, aResList );
   Dump( "types", aTypes, aResList );
-  aResList << QString( "%1.ImportDBF( '%2', '%3', attr_values, types )" ).
+  aResList << QString( "if (%1.ImportDBF( '%2', '%3', attr_values, types ) != %1.DBFStatus_OK):" ).
     arg( aName ).arg( QFileInfo( aDbfFileName ).fileName() ).arg( anAttr );
+  aResList << QString( "  raise ValueError('problem while loading LandCoverMap data base')" );
 
   return aResList;
 }
@@ -1131,7 +1146,7 @@ void HYDROData_LandCoverMap::RemoveInternal(TopoDS_Shape& ShToRebuild, NCollecti
     //
     if (!anEdgesToRemove.IsEmpty())
     {
-      Handle_ShapeBuild_ReShape aReshape = new ShapeBuild_ReShape();
+      Handle(ShapeBuild_ReShape) aReshape = new ShapeBuild_ReShape();
       TopoDS_Shape OutF = aReshape->Apply(CurFace);
       TopTools_ListIteratorOfListOfShape aIt(anEdgesToRemove);
       for (; aIt.More(); aIt.Next()) 
@@ -1146,7 +1161,7 @@ void HYDROData_LandCoverMap::RemoveInternal(TopoDS_Shape& ShToRebuild, NCollecti
     }
   }
   //
-  Handle_ShapeBuild_ReShape anExtReshape = new ShapeBuild_ReShape();
+  Handle(ShapeBuild_ReShape) anExtReshape = new ShapeBuild_ReShape();
   for (int i = 1; i <= aF2FReplace->Extent(); i++)
   {
     TopoDS_Face aFK = aF2FReplace->FindKey(i);
@@ -1168,7 +1183,7 @@ void HYDROData_LandCoverMap::SetTransparency( double theTransparency )
 
 double HYDROData_LandCoverMap::GetTransparency() const
 {
-  return GetDouble( DataTag_Transparency, 0.5 );
+  return GetDouble( DataTag_Transparency, 0.25 );
 }
 
 bool HYDROData_LandCoverMap::ImportSHP( const QString& theSHPFileName,
@@ -1234,7 +1249,7 @@ bool HYDROData_LandCoverMap::CheckLinear()
   {
     TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current());
     double aFP, aLP;
-    Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP);
+    Handle(Geom_Curve) aCur = BRep_Tool::Curve(E, aFP, aLP);
     Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur);
     if (aLine.IsNull())
     {
@@ -1259,8 +1274,61 @@ void HYDROData_LandCoverMap::UpdateLocalCS( double theDx, double theDy )
   SetShape( aLocatedShape );
 }
 
-void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_Pnt2d>& thePoints, std::vector<std::set <QString> >& theTypes ) const
+void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints,
+                                             std::vector<std::set <QString> >& theTypes ) const
 {
   HYDROData_LCM_FaceClassifier FC(this);
   FC.Classify(thePoints, theTypes, NULL);
 }
+
+void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints,
+                                             const Handle(HYDROData_StricklerTable)& theTable,
+                                             std::vector<int>& theTypes ) const
+{
+  std::vector<std::set <QString> > types;
+  HYDROData_LCM_FaceClassifier FC(this);
+  FC.Classify(thePoints, types, NULL);
+
+  size_t n = types.size();
+  theTypes.resize( n );
+  for( size_t i=0; i<n; i++ )
+  {
+    const std::set<QString>& sub_types = types[i];
+    int aType = 0;
+    if( !sub_types.empty() )
+    {
+      const QString& aSType = *sub_types.begin();
+      aType = theTable->GetAttrValue( aSType ).toInt();
+    }
+    theTypes[i] = aType;
+  }
+}
+
+void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints,  
+  const Handle(HYDROData_StricklerTable)& theTable, 
+  std::vector<double>& theCoeffs, double DefValue, bool UseMax ) const
+{
+  std::vector<std::set <QString> > Types;
+  HYDROData_LCM_FaceClassifier FC(this);
+  FC.Classify(thePoints, Types, NULL);
+  theCoeffs.resize(thePoints.size());
+  for (size_t i = 0; i < Types.size(); i++)
+  {
+    const std::set<QString>& SStr = Types[i];
+    if (SStr.empty())
+      theCoeffs[i] = DefValue;
+    else
+    {
+      std::set<QString>::const_iterator it;
+      std::vector<double> C1;
+      for (it = SStr.begin(); it != SStr.end(); ++it)
+        C1.push_back(theTable->Get( *it, DefValue ));
+      double Val;
+      if (UseMax)
+        Val = *(std::max_element( C1.begin(), C1.end() ) );
+      else
+        Val = *(std::min_element( C1.begin(), C1.end() ) );
+      theCoeffs[i] = Val;
+    }
+  }
+}