Salome HOME
Feature #86: The hierarchy in the Object Browser (T 19).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataModel.cxx
index 6ea2d54aeab8160a183de0f6eccdffaf4a790359..9432c01c02f2cd996db52aad98d688073acce22c 100644 (file)
@@ -26,6 +26,7 @@
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_Zone.h"
+#include "HYDROGUI_Region.h"
 
 #include <HYDROData_Bathymetry.h>
 #include <HYDROData_CalculationCase.h>
 #include <HYDROData_ImmersibleZone.h>
 #include <HYDROData_Iterator.h>
 #include <HYDROData_Polyline.h>
+#include <HYDROData_Profile.h>
 #include <HYDROData_VisualState.h>
 #include <HYDROData_Region.h>
 #include <HYDROData_Zone.h>
+#include <HYDROData_Obstacle.h>
+#include <HYDROData_Channel.h>
+#include <HYDROData_Digue.h>
+#include <HYDROData_River.h>
 
 #include <CAM_Application.h>
 #include <CAM_DataObject.h>
@@ -223,70 +229,151 @@ void HYDROGUI_DataModel::update( const int theStudyId )
   if( aDocument.IsNull() )
     return;
 
-  LightApp_DataObject* anImageRootObj = createObject( aRootObj, partitionName( KIND_IMAGE ) );
+  // Create root objects:
 
-  HYDROData_Iterator anIterator( aDocument, KIND_IMAGE );
-  for( ; anIterator.More(); anIterator.Next() )
-  {
-    Handle(HYDROData_Image) anImageObj =
-      Handle(HYDROData_Image)::DownCast( anIterator.Current() );
-    if( !anImageObj.IsNull() )
-      createObject( anImageRootObj, anImageObj );
-  }
+  // IMAGES
+  LightApp_DataObject* anImageRootObj = createObject( aRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
 
-  LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, partitionName( KIND_BATHYMETRY ) );
+  // BATHYMETRY
+  LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
 
-  anIterator = HYDROData_Iterator( aDocument, KIND_BATHYMETRY );
-  for( ; anIterator.More(); anIterator.Next() )
-  {
-    Handle(HYDROData_Bathymetry) aBathymetryObj =
-      Handle(HYDROData_Bathymetry)::DownCast( anIterator.Current() );
-    if( !aBathymetryObj.IsNull() )
-      createObject( aBathymetryRootObj, aBathymetryObj );
-  }
+  // ARTIFICIAL OBJECTS
+  LightApp_DataObject* anArtificialObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
 
-  LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, partitionName( KIND_POLYLINE ) );
+  // NATURAL OBJECTS
+  LightApp_DataObject* aNaturalObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
 
-  anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE );
-  for( ; anIterator.More(); anIterator.Next() )
-  {
-    Handle(HYDROData_Polyline) aPolylineObj =
-      Handle(HYDROData_Polyline)::DownCast( anIterator.Current() );
-    if( !aPolylineObj.IsNull() )
-      createObject( aPolylineRootObj, aPolylineObj );
-  }
+  // OBSTACLES
+  LightApp_DataObject* anObstaclesRootObj = createObject( aRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
 
-  LightApp_DataObject* aZonesRootObj = createObject( aRootObj, partitionName( KIND_IMMERSIBLE_ZONE ) );
+  // CALCULATION CASES
+  LightApp_DataObject* aCalculRootObj = createObject( aRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
 
-  anIterator = HYDROData_Iterator( aDocument, KIND_IMMERSIBLE_ZONE );
-  for( ; anIterator.More(); anIterator.Next() )
-  {
-    Handle(HYDROData_ImmersibleZone) aZoneObj =
-      Handle(HYDROData_ImmersibleZone)::DownCast( anIterator.Current() );
-    if( !aZoneObj.IsNull() )
-      createObject( aZonesRootObj, aZoneObj );
-  }
+  // POLYLINES
+  LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
 
-  LightApp_DataObject* aCalculRootObj = createObject( aRootObj, partitionName( KIND_CALCULATION ) );
+  // PROFILES
+  LightApp_DataObject* aProfileRootObj = createObject( aRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
 
-  anIterator = HYDROData_Iterator( aDocument, KIND_CALCULATION );
-  for( ; anIterator.More(); anIterator.Next() )
-  {
-    Handle(HYDROData_CalculationCase) aCalculObj =
-      Handle(HYDROData_CalculationCase)::DownCast( anIterator.Current() );
-    if( !aCalculObj.IsNull() )
-      createObject( aCalculRootObj, aCalculObj );
-  }
+  // VISUAL STATES
+  LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
 
-  LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, partitionName( KIND_VISUAL_STATE ) );
+  HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
+  for( ; anIterator.More(); anIterator.Next() ) {
+    Handle(HYDROData_Entity) anObj = anIterator.Current();
 
-  anIterator = HYDROData_Iterator( aDocument, KIND_VISUAL_STATE );
-  for( ; anIterator.More(); anIterator.Next() )
-  {
-    Handle(HYDROData_VisualState) aVisualStateObj =
-      Handle(HYDROData_VisualState)::DownCast( anIterator.Current() );
-    if( !aVisualStateObj.IsNull() )
-      createObject( aVisualStateRootObj, aVisualStateObj );
+    switch ( anObj->GetKind() ) {
+      case KIND_IMAGE:
+      {
+        Handle(HYDROData_Image) anImageObj =
+          Handle(HYDROData_Image)::DownCast( anObj );
+        if( !anImageObj.IsNull() ) {
+          createObject( anImageRootObj, anImageObj );
+        }
+
+        break;
+      }
+      case KIND_BATHYMETRY:
+      {
+        Handle(HYDROData_Bathymetry) aBathymetryObj =
+          Handle(HYDROData_Bathymetry)::DownCast( anObj );
+        if( !aBathymetryObj.IsNull() ) {
+          createObject( aBathymetryRootObj, aBathymetryObj );
+        }
+
+        break;
+      }
+      case KIND_CHANNEL:
+      {
+        Handle(HYDROData_Channel) aChannelObj =
+          Handle(HYDROData_Channel)::DownCast( anObj );
+        if( !aChannelObj.IsNull() ) {
+          createObject( anArtificialObjectsRootObj, aChannelObj );
+        }
+
+        break;
+      }
+      case KIND_DIGUE:
+      {
+        Handle(HYDROData_Digue) aDigueObj =
+          Handle(HYDROData_Digue)::DownCast( anObj );
+        if( !aDigueObj.IsNull() ) {
+          createObject( anArtificialObjectsRootObj, aDigueObj );
+        }
+
+        break;
+      }
+      case KIND_IMMERSIBLE_ZONE:
+      {
+        Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj =
+          Handle(HYDROData_ImmersibleZone)::DownCast( anObj );
+        if( !anImmersibleZoneObj.IsNull() ) {
+          createObject( aNaturalObjectsRootObj, anImmersibleZoneObj );
+        }
+
+        break;
+      }
+      case KIND_RIVER:
+      {
+        Handle(HYDROData_River) aRiverObj =
+          Handle(HYDROData_River)::DownCast( anObj );
+        if( !aRiverObj.IsNull() ) {
+          createObject( aNaturalObjectsRootObj, aRiverObj );
+        }
+
+        break;
+      }
+      case KIND_OBSTACLE:
+      {
+        Handle(HYDROData_Obstacle) anObstacleObj =
+          Handle(HYDROData_Obstacle)::DownCast( anObj );
+        if( !anObstacleObj.IsNull() ) {
+          createObject( anObstaclesRootObj, anObstacleObj );
+        }
+
+        break;
+      }
+      case KIND_CALCULATION:
+      {
+        Handle(HYDROData_CalculationCase) aCalculObj =
+          Handle(HYDROData_CalculationCase)::DownCast( anObj );
+        if( !aCalculObj.IsNull() ) {
+          createObject( aCalculRootObj, aCalculObj );
+        }
+
+        break;
+      }
+      case KIND_POLYLINE:
+      {
+        Handle(HYDROData_Polyline) aPolylineObj =
+          Handle(HYDROData_Polyline)::DownCast( anObj );
+        if( !aPolylineObj.IsNull() ) {
+          createObject( aPolylineRootObj, aPolylineObj );
+        }
+
+        break;
+      }
+      case KIND_PROFILE:
+      {
+        Handle(HYDROData_Profile) aProfileObj =
+          Handle(HYDROData_Profile)::DownCast( anObj );
+        if( !aProfileObj.IsNull() ) {
+          createObject( aProfileRootObj, aProfileObj );
+        }
+
+        break;
+      }
+      case KIND_VISUAL_STATE:
+      {
+        Handle(HYDROData_VisualState) aVisualStateObj =
+          Handle(HYDROData_VisualState)::DownCast( anObj );
+        if( !aVisualStateObj.IsNull() ) {
+          createObject( aVisualStateRootObj, aVisualStateObj );
+        }
+
+        break;
+      }
+    }
   }
 
   if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
@@ -435,6 +522,7 @@ bool HYDROGUI_DataModel::canCopy()
   ObjectKind aKind = anObject->GetKind();
   if( aKind == KIND_IMAGE ||
       aKind == KIND_POLYLINE ||
+      aKind == KIND_PROFILE ||
       aKind == KIND_CALCULATION )
     return true;
 
@@ -506,12 +594,15 @@ QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind )
 {
   switch( theObjectKind )
   {
-    case KIND_IMAGE:           return "IMAGES";
-    case KIND_POLYLINE:        return "POLYLINES";
-    case KIND_VISUAL_STATE:    return "VISUAL_STATES";
-    case KIND_BATHYMETRY:      return "BATHYMETRIES";
-    case KIND_CALCULATION:     return "CALCULATION_CASES";
-    case KIND_IMMERSIBLE_ZONE: return "IMMERSIBLE_ZONES";
+    case KIND_IMAGE:             return "IMAGES";
+    case KIND_POLYLINE:          return "POLYLINES";
+    case KIND_PROFILE:           return "PROFILES";
+    case KIND_VISUAL_STATE:      return "VISUAL_STATES";
+    case KIND_BATHYMETRY:        return "BATHYMETRIES";
+    case KIND_CALCULATION:       return "CALCULATION_CASES";
+    case KIND_OBSTACLE:          return "OBSTACLES";
+    case KIND_ARTIFICIAL_OBJECT: return "ARTIFICIAL_OBJECTS";
+    case KIND_NATURAL_OBJECT:    return "NATURAL_OBJECTS";
     default: break;
   }
   return QString();
@@ -528,17 +619,7 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject*
                                                        const QString&           theParentEntry,
                                                        const bool               theIsBuildTree )
 {
-  HYDROGUI_DataObject* aResObj;
-  Handle(HYDROData_Zone) aRegionZone =
-    Handle(HYDROData_Zone)::DownCast( theModelObject );
-  if( !aRegionZone.IsNull() )
-  {
-    aResObj = new HYDROGUI_Zone( theParent, aRegionZone, theParentEntry );
-  }
-  else
-  {
-    aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
-  }
+  HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
   
   if ( theIsBuildTree )
   {
@@ -548,6 +629,34 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject*
   return aResObj;
 }
 
+LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject*     theParent,
+                                                      HYDROGUI_DataObject* theObject,
+                                                      const QString&       theParentEntry,
+                                                      const bool           theIsBuildTree )
+{
+  if ( theIsBuildTree )
+  {
+    buildObjectTree( theParent, theObject, theParentEntry );
+  }
+  return theObject;
+}
+
+LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject*       theParent,
+                                                     Handle(HYDROData_Zone) theModelObject,
+                                                     const QString&         theParentEntry,
+                                                     const bool             theIsBuildTree )
+{
+  return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
+}
+
+LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject*         theParent,
+                                                       Handle(HYDROData_Region) theModelObject,
+                                                       const QString&           theParentEntry,
+                                                       const bool               theIsBuildTree )
+{
+  return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
+}
+
 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
                                                        const QString&   theName,
                                                        const QString&   theParentEntry )
@@ -614,7 +723,7 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
       Handle(HYDROData_Region) aCaseRegion =
         Handle(HYDROData_Region)::DownCast( anIter.Value() );
       if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
-        createObject( aCaseRegionsSect, aCaseRegion, "", true );
+        createRegion( aCaseRegionsSect, aCaseRegion, "", true );
     }
   }
   else if ( anObjectKind == KIND_REGION )
@@ -629,7 +738,25 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
       Handle(HYDROData_Zone) aRegionZone =
         Handle(HYDROData_Zone)::DownCast( anIter.Value() );
       if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
-        createObject( aGuiObj, aRegionZone, "", true );
+        createZone( aGuiObj, aRegionZone, "", true );
+    }
+  }
+}
+
+void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
+{
+  if ( !theCase.IsNull() )
+  {
+    new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "" );
+
+    HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions();
+    HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
+    for ( ; anIter.More(); anIter.Next() )
+    {
+      Handle(HYDROData_Region) aCaseRegion =
+        Handle(HYDROData_Region)::DownCast( anIter.Value() );
+      if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
+        createRegion( theParent, aCaseRegion, "", true );
     }
   }
 }
@@ -655,3 +782,34 @@ SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* the
   }
   return NULL; // not found
 }
+
+bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase, 
+                                         const QList<HYDROGUI_Zone*>& theZonesList )
+{
+  bool isOk = !theCase.IsNull();
+  if ( isOk )
+  {
+    Handle(HYDROData_Region) aRegion;
+    Handle(HYDROData_Zone) aZone;
+    for (int i = 0; i < theZonesList.length(); i++ )
+    {
+      aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() );
+      if ( !aZone.IsNull() )
+      {
+        if ( aRegion.IsNull() )
+        {
+          aRegion = theCase->AddNewRegion( aZone );
+          isOk = !aRegion.IsNull();
+        }
+        else
+        {
+          if ( !( aRegion->AddZone( aZone ) ) )
+          {
+            isOk = false;
+          }
+        }
+      }
+    }
+  }
+  return isOk;
+}