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 6ea2d54aeab8160a183de0f6eccdffaf4a790359..97ec16079ae1c5b00aca7e54d2057fdf79135634 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>
@@ -223,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() )
@@ -234,7 +235,7 @@ void HYDROGUI_DataModel::update( const int theStudyId )
       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() )
@@ -245,7 +246,7 @@ void HYDROGUI_DataModel::update( const int theStudyId )
       createObject( aBathymetryRootObj, aBathymetryObj );
   }
 
-  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() )
@@ -256,7 +257,7 @@ void HYDROGUI_DataModel::update( const int theStudyId )
       createObject( aPolylineRootObj, aPolylineObj );
   }
 
-  LightApp_DataObject* aZonesRootObj = createObject( aRootObj, partitionName( KIND_IMMERSIBLE_ZONE ) );
+  LightApp_DataObject* aZonesRootObj = createObject( aRootObj, tr( partitionName( KIND_IMMERSIBLE_ZONE ).toAscii() ) );
 
   anIterator = HYDROData_Iterator( aDocument, KIND_IMMERSIBLE_ZONE );
   for( ; anIterator.More(); anIterator.Next() )
@@ -267,7 +268,7 @@ void HYDROGUI_DataModel::update( const int theStudyId )
       createObject( aZonesRootObj, aZoneObj );
   }
 
-  LightApp_DataObject* aCalculRootObj = createObject( aRootObj, partitionName( KIND_CALCULATION ) );
+  LightApp_DataObject* aCalculRootObj = createObject( aRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
 
   anIterator = HYDROData_Iterator( aDocument, KIND_CALCULATION );
   for( ; anIterator.More(); anIterator.Next() )
@@ -278,7 +279,7 @@ void HYDROGUI_DataModel::update( const int theStudyId )
       createObject( aCalculRootObj, aCalculObj );
   }
 
-  LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, partitionName( KIND_VISUAL_STATE ) );
+  LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
 
   anIterator = HYDROData_Iterator( aDocument, KIND_VISUAL_STATE );
   for( ; anIterator.More(); anIterator.Next() )
@@ -528,17 +529,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 +539,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 +633,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 +648,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 +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;
+}