Salome HOME
Merge branch 'BR_v14_rc' into BR_quadtree
[modules/hydro.git] / src / HYDROData / HYDROData_CalculationCase.cxx
index 1bd1057d6dd42ccc548a86640b9901e5ff4e2f9b..c2430aff628070636b3b5e24677f046da7ed3381 100644 (file)
 
 #define EXPORT_NAME "HYDRO_" + GetName()
 
+#include <SALOME_NamingService.hxx>
+#include <SALOME_LifeCycleCORBA.hxx>
+
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
 
@@ -116,10 +122,14 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre
 
   QString aCalculName = GetObjPyName();
 
-  AssignmentMode aMode = GetAssignmentMode();
+  AssignmentMode aMode = GetAssignmentMode();  
   QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
   aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
 
+  AssignmentMode aModeLC = GetAssignmentLandCoverMode();
+  QString aModeLCStr = aModeLC==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
+  aResList << QString( "%0.SetAssignmentLandCoverMode( %1 )" ).arg( aCalculName ).arg( aModeLCStr );
+
   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
   HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
   for ( ; anIter.More(); anIter.Next() )
@@ -158,6 +168,8 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre
 
   if( aMode==AUTOMATIC )
     DumpRulesToPython( aCalculName, aResList );
+  if( aModeLC==AUTOMATIC )
+    DumpLandCoverRulesToPython( aCalculName, aResList );
 
   aResList << QString( "" );
   aResList << "# Start the algorithm of the partition and assignment";
@@ -167,7 +179,12 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre
   {
     // Now we restore the
     // - regions and zones order
-    DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( false ) );
+    DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( false ) );   
+  }
+
+  if( aModeLC==MANUAL )
+  {
+    // Now we restore the
     // - land cover regions and zones order
     DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( true ) );
   }
@@ -308,14 +325,23 @@ void HYDROData_CalculationCase::Update()
   switch( GetAssignmentMode() )
   {
   case MANUAL:
-    CreateRegionsDef( aDocument, aZonesList, false );
+    CreateRegionsDef( aDocument, aZonesList, false );    
+    break;
+  case AUTOMATIC:
+    CreateRegionsAuto( aDocument, aZonesList, false );    
+    break;
+  }
+
+  switch( GetAssignmentLandCoverMode() )
+  {
+  case MANUAL:
     CreateRegionsDef( aDocument, aLandCoverZonesList, true );
     break;
   case AUTOMATIC:
-    CreateRegionsAuto( aDocument, aZonesList, false );
     CreateRegionsAuto( aDocument, aLandCoverZonesList, true );
     break;
   }
+
   CreateEdgeGroupsDef( aDocument, anEdgesList );
 }
 
@@ -690,7 +716,8 @@ void HYDROData_CalculationCase::UpdateRegionsOrder()
     return;
 
   HYDROData_SequenceOfObjects aRegions = GetRegions( false );
-  aRegions.Append( GetRegions( true ) );
+  HYDROData_SequenceOfObjects aRegionsLC = GetRegions( true );
+  aRegions.Append( aRegionsLC );
 
   HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
   for ( ; anIter.More(); anIter.Next() )
@@ -764,10 +791,20 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY&
   Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
   if ( !aZone.IsNull() )
   {
+    //DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
     Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
     if ( IsEqual( aRefRegion, theRegion ) )
       aResAltitude = GetAltitudeForPoint( thePoint, aZone );
+    else
+      {
+        DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
+        aResAltitude = GetAltitudeForPoint( thePoint, aZone );
+      }
   }
+  else
+    {
+      DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
+    }
 
   return aResAltitude;
 }
@@ -775,6 +812,7 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY&
 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY&                  thePoint,
                                                        const Handle(HYDROData_Zone)& theZone ) const
 {
+  //DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
   double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
   if ( theZone.IsNull() )
     return aResAltitude;
@@ -863,6 +901,7 @@ NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
   const NCollection_Sequence<gp_XY>& thePoints,
   const Handle(HYDROData_Region)&    theRegion ) const
 {
+  //DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
   NCollection_Sequence<double> aResSeq;
 
   for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
@@ -1006,14 +1045,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;
 
@@ -1038,6 +1078,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 );
@@ -1047,12 +1088,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,
@@ -1241,6 +1295,12 @@ QString HYDROData_CalculationCase::DumpRules() const
   return HYDROData_PriorityQueue::DumpRules( aRulesLab );
 }
 
+QString HYDROData_CalculationCase::DumpLandCoverRules() const
+{
+  TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
+  return HYDROData_PriorityQueue::DumpRules( aRulesLab );
+}
+
 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
 {
   TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
@@ -1267,6 +1327,13 @@ void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseNam
   HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
 }
 
+void HYDROData_CalculationCase::DumpLandCoverRulesToPython( const QString& theCalcCaseName,
+                                                            QStringList& theScript ) const
+{
+  TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
+  HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
+}
+
 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
 {
   return myLastWarning;