Salome HOME
Fix for the bug #42: point C is not activated, but point C is shown in preview in...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataModel.cxx
index 392dfef5bd9b6d1262e77ccb1097ef0e28c8366d..97ec16079ae1c5b00aca7e54d2057fdf79135634 100644 (file)
 #include "HYDROGUI_DataObject.h"
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_Tool.h"
+#include "HYDROGUI_Zone.h"
+#include "HYDROGUI_Region.h"
 
 #include <HYDROData_Bathymetry.h>
-#include <HYDROData_Calculation.h>
+#include <HYDROData_CalculationCase.h>
 #include <HYDROData_Document.h>
 #include <HYDROData_Image.h>
+#include <HYDROData_ImmersibleZone.h>
 #include <HYDROData_Iterator.h>
 #include <HYDROData_Polyline.h>
 #include <HYDROData_VisualState.h>
+#include <HYDROData_Region.h>
+#include <HYDROData_Zone.h>
 
 #include <CAM_Application.h>
 #include <CAM_DataObject.h>
@@ -219,7 +224,7 @@ void HYDROGUI_DataModel::update( const int theStudyId )
   if( aDocument.IsNull() )
     return;
 
-  LightApp_DataObject* anImageRootObj = createObject( aRootObj, partitionName( KIND_IMAGE ) );
+  LightApp_DataObject* anImageRootObj = createObject( aRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
 
   HYDROData_Iterator anIterator( aDocument, KIND_IMAGE );
   for( ; anIterator.More(); anIterator.Next() )
@@ -227,20 +232,10 @@ void HYDROGUI_DataModel::update( const int theStudyId )
     Handle(HYDROData_Image) anImageObj =
       Handle(HYDROData_Image)::DownCast( anIterator.Current() );
     if( !anImageObj.IsNull() )
-    {
-      if( LightApp_DataObject* anImageDataObj = createObject( anImageRootObj, anImageObj ) )
-      {
-        for( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
-        {
-          Handle(HYDROData_Object) aRefObj = anImageObj->Reference( anIndex );
-          if( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
-            createObject( anImageDataObj, aRefObj, anImageDataObj->entry() );
-        }
-      }
-    }
+      createObject( anImageRootObj, anImageObj );
   }
 
-  LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, partitionName( KIND_BATHYMETRY ) );
+  LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
 
   anIterator = HYDROData_Iterator( aDocument, KIND_BATHYMETRY );
   for( ; anIterator.More(); anIterator.Next() )
@@ -251,18 +246,7 @@ void HYDROGUI_DataModel::update( const int theStudyId )
       createObject( aBathymetryRootObj, aBathymetryObj );
   }
 
-  LightApp_DataObject* aCalculRootObj = createObject( aRootObj, partitionName( KIND_CALCULATION ) );
-
-  anIterator = HYDROData_Iterator( aDocument, KIND_CALCULATION );
-  for( ; anIterator.More(); anIterator.Next() )
-  {
-    Handle(HYDROData_Calculation) aCalculObj =
-      Handle(HYDROData_Calculation)::DownCast( anIterator.Current() );
-    if( !aCalculObj.IsNull() )
-      createObject( aCalculRootObj, aCalculObj );
-  }
-
-  LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, partitionName( KIND_POLYLINE ) );
+  LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
 
   anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE );
   for( ; anIterator.More(); anIterator.Next() )
@@ -273,7 +257,29 @@ void HYDROGUI_DataModel::update( const int theStudyId )
       createObject( aPolylineRootObj, aPolylineObj );
   }
 
-  LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, partitionName( KIND_VISUAL_STATE ) );
+  LightApp_DataObject* aZonesRootObj = createObject( aRootObj, tr( partitionName( KIND_IMMERSIBLE_ZONE ).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 );
+  }
+
+  LightApp_DataObject* aCalculRootObj = createObject( aRootObj, tr( partitionName( KIND_CALCULATION ).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 );
+  }
+
+  LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
 
   anIterator = HYDROData_Iterator( aDocument, KIND_VISUAL_STATE );
   for( ; anIterator.More(); anIterator.Next() )
@@ -291,7 +297,7 @@ void HYDROGUI_DataModel::update( const int theStudyId )
   }
 }
 
-HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Object)& theModelObject )
+HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
 {
   return NULL; // to do if necessary
 }
@@ -330,7 +336,7 @@ void HYDROGUI_DataModel::updateModel()
     update( aModule->getStudyId() );
 }
 
-Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
+Handle(HYDROData_Entity) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
                                                             const ObjectKind theObjectKind )
 {
   QString anEntry = theEntry;
@@ -343,7 +349,7 @@ Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEn
     HYDROData_Iterator anIterator( aDocument, theObjectKind );
     for( ; anIterator.More(); anIterator.Next() )
     {
-      Handle(HYDROData_Object) anObject = anIterator.Current();
+      Handle(HYDROData_Entity) anObject = anIterator.Current();
       if( !anObject.IsNull() )
       {
         QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
@@ -423,7 +429,7 @@ bool HYDROGUI_DataModel::canCopy()
   if( aSeq.Length() != 1 )
     return false;
 
-  Handle(HYDROData_Object) anObject = aSeq.First();
+  Handle(HYDROData_Entity) anObject = aSeq.First();
   if( anObject.IsNull() )
     return false;
 
@@ -440,7 +446,7 @@ bool HYDROGUI_DataModel::canPaste()
 {
   for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
   {
-    Handle(HYDROData_Object) anObject = myCopyingObjects.Value( anIndex );
+    Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
     if( !anObject.IsNull() && !anObject->IsRemoved() )
       return true;
   }
@@ -459,11 +465,11 @@ bool HYDROGUI_DataModel::paste()
   bool anIsChanged = false;
   for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
   {
-    Handle(HYDROData_Object) anObject = myCopyingObjects.Value( anIndex );
+    Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
     if( !anObject.IsNull() && !anObject->IsRemoved() )
     {
       ObjectKind aKind = anObject->GetKind();
-      Handle(HYDROData_Object) aClone = getDocument()->CreateObject( aKind );
+      Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind );
       if( !aClone.IsNull() )
       {
         anObject->CopyTo( aClone );
@@ -501,11 +507,12 @@ 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_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";
     default: break;
   }
   return QString();
@@ -517,17 +524,151 @@ Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
   return HYDROData_Document::Document( aStudyId );
 }
 
-LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
-                                                       Handle(HYDROData_Object) theModelObject,
-                                                       const QString& theParentEntry )
+LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject*         theParent,
+                                                       Handle(HYDROData_Entity) theModelObject,
+                                                       const QString&           theParentEntry,
+                                                       const bool               theIsBuildTree )
 {
-  return new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
+  HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
+  
+  if ( theIsBuildTree )
+  {
+    buildObjectTree( theParent, aResObj, theParentEntry );
+  }
+
+  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&   theName,
+                                                       const QString&   theParentEntry )
+{
+  return new HYDROGUI_NamedObject( theParent, theName, theParentEntry );
+}
+
+void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
+                                          SUIT_DataObject* theObject,
+                                          const QString&   theParentEntry )
+{
+  HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
+  if ( !aGuiObj )
+    return;
+
+  Handle(HYDROData_Entity) aDataObj = aGuiObj->modelObject();
+  if ( aDataObj.IsNull() )
+    return;
+
+  ObjectKind anObjectKind = aDataObj->GetKind();
+
+  if ( anObjectKind == KIND_IMAGE )
+  {
+    Handle(HYDROData_Image) anImageObj =
+      Handle(HYDROData_Image)::DownCast( aDataObj );
+    for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
+    {
+      Handle(HYDROData_Entity) aRefObj = anImageObj->Reference( anIndex );
+      if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
+        createObject( aGuiObj, aRefObj, aGuiObj->entry(), false );
+    }
+  }
+  else if ( anObjectKind == KIND_IMMERSIBLE_ZONE )
+  {
+    Handle(HYDROData_ImmersibleZone) aZoneObj =
+      Handle(HYDROData_ImmersibleZone)::DownCast( aDataObj );
+
+    LightApp_DataObject* aPolylineSect = 
+      createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
+
+    Handle(HYDROData_Polyline) aPolyline = aZoneObj->GetPolyline();
+    if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
+      createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
+
+    LightApp_DataObject* aBathSect = 
+      createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() );
+
+    Handle(HYDROData_Bathymetry) aBathymetry = aZoneObj->GetBathymetry();
+    if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() )
+      createObject( aBathSect, aBathymetry, aGuiObj->entry(), false );
+  }
+  else if ( anObjectKind == KIND_CALCULATION )
+  {
+    Handle(HYDROData_CalculationCase) aCaseObj =
+      Handle(HYDROData_CalculationCase)::DownCast( aDataObj );
+
+    LightApp_DataObject* aCaseRegionsSect = 
+      createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() );
+
+    HYDROData_SequenceOfObjects aCaseRegions = aCaseObj->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( aCaseRegionsSect, aCaseRegion, "", true );
+    }
+  }
+  else if ( anObjectKind == KIND_REGION )
+  {
+    Handle(HYDROData_Region) aRegionObj =
+      Handle(HYDROData_Region)::DownCast( aDataObj );
+
+    HYDROData_SequenceOfObjects aRegionZones = aRegionObj->GetZones();
+    HYDROData_SequenceOfObjects::Iterator anIter( aRegionZones );
+    for ( ; anIter.More(); anIter.Next() )
+    {
+      Handle(HYDROData_Zone) aRegionZone =
+        Handle(HYDROData_Zone)::DownCast( anIter.Value() );
+      if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
+        createZone( aGuiObj, aRegionZone, "", true );
+    }
+  }
+}
+
+void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
 {
-  return new HYDROGUI_NamedObject( theParent, theName );
+  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 );
+    }
+  }
 }
 
 void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent,
@@ -551,3 +692,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;
+}