Salome HOME
refs #585: flag in merge operations
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataModel.cxx
index 623920a0d7063e5d120fc1533587ea3b2e5e972c..6255c5e5a2548e9c10aff48adf998b887a11c9c2 100644 (file)
@@ -735,18 +735,7 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject*
 
   if ( visibility )
   {
-    SUIT_AbstractModel* treeModel = 0;
-    LightApp_Application* app = dynamic_cast<LightApp_Application*>( module()->application() );
-    if ( app )
-        treeModel = dynamic_cast<SUIT_AbstractModel*>( app->objectBrowser()->model() );
-
-    if ( treeModel )
-    {
-      HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
-      bool isVisible = aModule->isObjectVisible( -1, theModelObject );
-      Qtx::VisibilityState aVisState = isVisible ? Qtx::ShownState : Qtx::HiddenState;
-      treeModel->setVisibilityState( aResObj->text( aResObj->customData( Qtx::IdType ).toInt() ), aVisState, false );
-    }
+    setObjectVisibilityState( theModelObject, aResObj );
   }
 
   if ( theIsBuildTree )
@@ -776,8 +765,12 @@ LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject*       theP
                                                      const bool             theIsBuildTree,
                                                      const bool             theIsInOperation )
 {
-  return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation ), 
-    theParentEntry, theIsBuildTree, theIsInOperation );
+  HYDROGUI_Zone* aZone = new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation );
+  LightApp_DataObject* aDataObj = buildObject( theParent, aZone, theParentEntry, theIsBuildTree, theIsInOperation );
+
+  setObjectVisibilityState( theModelObject, aZone );
+
+  return aDataObj;
 }
 
 LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject*         theParent,
@@ -995,10 +988,19 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
         createRegion( aCaseRegionsSect, aCaseRegion, "", true, theIsInOperation );
     }
 
-    // TODO: Build object tree for land cover regions
-    //HYDROData_SequenceOfObjects aCaseLandCoverRegions = aCaseObj->GetRegions( true );
-    //...
+    LightApp_DataObject* aCaseLandCoverRegionsSect = 
+      createObject( aGuiObj, tr( "CASE_LAND_COVER_REGIONS" ), aGuiObj->entry() );
 
+    HYDROData_SequenceOfObjects aCaseLandCoverRegions = aCaseObj->GetRegions( true );
+    anIter.Init( aCaseLandCoverRegions );
+    for ( ; anIter.More(); anIter.Next() )
+    {
+      Handle(HYDROData_Region) aCaseLCRegion =
+        Handle(HYDROData_Region)::DownCast( anIter.Value() );
+      if( !aCaseLCRegion.IsNull() && !aCaseLCRegion->IsRemoved() )
+        createRegion( aCaseLandCoverRegionsSect, aCaseLCRegion, "", true, theIsInOperation );
+    }
+    
 #ifdef DEB_GROUPS
     HYDROData_SequenceOfObjects aCalcGroups = aCaseObj->GetGeometryGroups();
     buildObjectPartition( aGuiObj, aCalcGroups, tr( "OBJECT_GROUPS" ), false );
@@ -1069,9 +1071,19 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
       createObject( aGuiObj, aBottomPolyline, aGuiObj->entry(), false );
     }
   }
+  else if ( anObjectKind == KIND_LAND_COVER )
+  {
+    Handle(HYDROData_LandCover) aLandCoverObj =
+      Handle(HYDROData_LandCover)::DownCast( aDataObj );
+
+    HYDROData_SequenceOfObjects aPolylines = aLandCoverObj->GetPolylines();
+    buildObjectPartition( aGuiObj, aPolylines, tr( "LAND_COVER_POLYLINES" ), true );
+  }
+  
 }
 
-void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
+void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase,
+                                        const bool theLandCover )
 {
   if ( !theCase.IsNull() )
   {
@@ -1087,7 +1099,7 @@ void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDRO
 
     new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "", true );
 
-    HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions( false );
+    HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions( theLandCover );
     HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
     for ( ; anIter.More(); anIter.Next() )
     {
@@ -1096,10 +1108,6 @@ void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDRO
       if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
         createRegion( theParent, aCaseRegion, "", true, true );
     }
-
-    // TODO: Create land cover regions
-    //HYDROData_SequenceOfObjects aCaseLandCoverRegions = theCase->GetRegions( true );
-    //...
   }
 }
 
@@ -1212,3 +1220,20 @@ bool HYDROGUI_DataModel::rename( Handle(HYDROData_Entity) theEntity, const QStri
   }
   return true;
 }
+
+void HYDROGUI_DataModel::setObjectVisibilityState( Handle(HYDROData_Entity) theModelObject,
+                                                   HYDROGUI_DataObject* theObject )
+{
+  SUIT_AbstractModel* treeModel = 0;
+  LightApp_Application* app = dynamic_cast<LightApp_Application*>( module()->application() );
+  if ( app )
+    treeModel = dynamic_cast<SUIT_AbstractModel*>( app->objectBrowser()->model() );
+
+  if ( treeModel )
+  {
+    HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
+    bool isVisible = aModule->isObjectVisible( -1, theModelObject );
+    Qtx::VisibilityState aVisState = isVisible ? Qtx::ShownState : Qtx::HiddenState;
+    treeModel->setVisibilityState( theObject->text( theObject->customData( Qtx::IdType ).toInt() ), aVisState, false );
+  }
+}