Salome HOME
refs #639: the button to regenerate colors
[modules/hydro.git] / src / HYDROData / HYDROData_CalculationCase.cxx
index 8027835c4d46a1834b05e44e83a6b7366a9c8c41..be8f1a8bc754b1ae72501518a4222e840f5c55e3 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include "HYDROData_CalculationCase.h"
+#ifdef WIN32
+  #pragma warning ( disable: 4251 )
+#endif
 
+#include "HYDROData_CalculationCase.h"
 #include "HYDROData_ArtificialObject.h"
 #include "HYDROData_IAltitudeObject.h"
 #include "HYDROData_Document.h"
 #include <BRepBuilderAPI_MakeVertex.hxx>
 #endif
 
+#ifdef WIN32
+  #pragma warning ( default: 4251 )
+#endif
+
 #define EXPORT_NAME "HYDRO_" + GetName()
 
 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
@@ -914,6 +921,38 @@ NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
   return aResSeq;
 }
 
+double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
+{
+    double aCoeff = 0;
+    Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+    if ( !aDocument.IsNull() )
+        aCoeff = aDocument->GetDefaultStricklerCoefficient();
+
+    Handle(HYDROData_LandCover) aLandCover;
+    Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, Standard_True );
+    if ( !aZone.IsNull() )
+    {
+        HYDROData_SequenceOfObjects anObjList = aZone->GetObjects();
+        if ( anObjList.Length() == 1 )
+            aLandCover = Handle(HYDROData_LandCover)::DownCast( anObjList.First() );
+        else
+            aLandCover = Handle(HYDROData_LandCover)::DownCast( aZone->GetMergeObject() );
+    }
+
+    if ( !aLandCover.IsNull() )
+    {
+        QString aType = aLandCover->GetStricklerType();
+        Handle(HYDROData_StricklerTable) aTable = GetStricklerTable();
+        if ( !aTable.IsNull() )
+        {
+            if ( aTable->GetTypes().contains( aType ) )
+                aCoeff = aTable->Get( aType, aCoeff );
+        }
+    }
+
+    return aCoeff;
+}
+
 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint,
                                                                         const bool theLandCover ) const
 {
@@ -1027,14 +1066,15 @@ QString HYDROData_CalculationCase::Export( int theStudyId ) const
   GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
   SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
   
-  QString aGeomObjEntry;
-  bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry );
+  QString aGeomObjEntry, anErrorMsg;
+  bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg );
   return isOK ? aGeomObjEntry : QString();
 }
 
 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var  theGeomEngine,
                                         SALOMEDS::Study_ptr theStudy,
-                                        QString& theGeomObjEntry ) const
+                                        QString& theGeomObjEntry,
+                                        QString& theErrorMsg ) const
 {
   HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
 
@@ -1059,6 +1099,7 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var  theGeomEngine,
   }
   
   // Get faces
+  bool isAllNotSubmersible = true;
   TopTools_ListOfShape aFaces;
   HYDROData_SequenceOfObjects aCaseRegions = GetRegions( false );
   HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
@@ -1068,12 +1109,25 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var  theGeomEngine,
       Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
     if( aRegion.IsNull() || !aRegion->IsSubmersible() )
       continue;
+    
+    if ( isAllNotSubmersible )
+      isAllNotSubmersible = false;
 
     TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
     aFaces.Append( aRegionShape );
   }
 
-  return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );
+  bool aRes = false;
+
+  if ( aCaseRegions.IsEmpty() ) {
+    theErrorMsg = QString("the list of regions is empty.");
+  } else if ( isAllNotSubmersible ) {
+    theErrorMsg = QString("there are no submersible regions.");
+  } else {
+    aRes = Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );;
+  }
+
+  return aRes;
 }
 
 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var                            theGeomEngine,