Salome HOME
Merge branch 'BR_MULTI_BATHS' into HEAD
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_LandCoverMapOp.cxx
index 777ebf39782efe16c250ac0db4ed4d962ec2da7c..16162cfbc943f4302de60bbe10895303f2cf1ca0 100644 (file)
@@ -22,7 +22,7 @@
 #include "HYDROGUI_OCCDisplayer.h"
 #include "HYDROGUI_Operations.h"
 #include "HYDROGUI_LandCoverMapDlg.h"
-#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_Tool2.h"
 #include "HYDROGUI_UpdateFlags.h"
 #include "HYDROGUI_DataObject.h"
 #include "HYDROGUI_ShapeLandCoverMap.h"
 #include <OCCViewer_ViewWindow.h>
 #include <OCCViewer_ViewPort3d.h>
 
+#include <OCCViewer_ViewManager.h>
+
+#include <SalomeApp_Study.h>
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
+#include <LightApp_DataOwner.h>
 #include <SUIT_ViewWindow.h>
+#include <SUIT_DataObject.h>
 
 #include <TopoDS.hxx>
 #include <TopoDS_Face.hxx>
@@ -54,7 +59,8 @@
 HYDROGUI_LandCoverMapOp::HYDROGUI_LandCoverMapOp( HYDROGUI_Module* theModule, const int theOperationId )
 : HYDROGUI_Operation( theModule ),
   myOperationId( theOperationId ),
-  myPreviewPrs( 0 )
+  myPreviewPrs( 0 ),
+  myPolylineFacePreviewPrs( 0 )
 {
   switch( myOperationId )
   {
@@ -149,9 +155,13 @@ void HYDROGUI_LandCoverMapOp::abortOperation()
 {
   closePreview();
 
+  bool aNoActiveOps = module()->getActiveOperations().isEmpty();
+
   HYDROGUI_Operation::abortOperation();
 
-  module()->update( UF_OCCViewer | UF_FitAll );
+  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
+  if ( aStudy && !aNoActiveOps )
+    module()->update( UF_OCCViewer | UF_FitAll );
 }
 
 void HYDROGUI_LandCoverMapOp::commitOperation()
@@ -168,6 +178,8 @@ HYDROGUI_InputPanel* HYDROGUI_LandCoverMapOp::createInputPanel() const
   HYDROGUI_LandCoverMapDlg* aPanel = new HYDROGUI_LandCoverMapDlg( module(), getName(), myOperationId );
   connect( aPanel, SIGNAL( landCoverMapChanged( const QString& ) ),
            this, SLOT( onLandCoverMapChanged( const QString& ) ) );
+  connect( aPanel, SIGNAL( polylineFaceChanged() ),
+           this, SLOT( onPolylineFaceChanged() ) );
   return aPanel;
 }
 
@@ -221,11 +233,8 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
             myOperationId == ChangeLandCoverTypeId )
   {
     if ( myPreviewPrs )
-    {
       // Fill in aFacesSelectedInViewer list
-      Handle(AIS_InteractiveContext) aCtx;
-      getSelectedShapes( aFacesSelectedInViewer, aCtx );
-    }
+      getSelectedShapes( aFacesSelectedInViewer );
   }
 
   // Get selected Strickler type
@@ -288,9 +297,9 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
   // Split land cover(s) inside edited land cover map
   if ( myOperationId == SplitLandCoverId )
   {
-    bool aLandCoverSplitted = false;
+    bool aLandCoverSplit = false;
     if ( !aPolyline.IsNull() )
-      aLandCoverSplitted = aLandCoverMapObj->Split( aPolyline );
+      aLandCoverSplit = aLandCoverMapObj->Split( aPolyline );
     else if ( !aFace.IsNull() )
     {
       // Get the complete boundary of the object face as the splitting polyline
@@ -305,12 +314,12 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
           continue;
 
         bool aSplitResult = aLandCoverMapObj->Split( aShape );
-        aLandCoverSplitted = ( i==0 ? aSplitResult : aLandCoverSplitted && aSplitResult );
+        aLandCoverSplit = ( i==0 ? aSplitResult : aLandCoverSplit && aSplitResult );
       }
     }
-    if ( !aLandCoverSplitted )
+    if ( !aLandCoverSplit )
     {
-      theErrorMsg = tr( "LAND_COVER_NOT_SPLITTED" );
+      theErrorMsg = tr( "LAND_COVER_NOT_SPLIT" );
       return false;
     }
   }
@@ -367,6 +376,9 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
   if ( myOperationId == CreateLandCoverMapId )
     module()->enableLCMActions();
 
+  if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
+    aPanel->updateSelectedLandCoversLabel( getNbSelected() );
+
   return true;
 }
 
@@ -385,6 +397,88 @@ void HYDROGUI_LandCoverMapOp::onLandCoverMapChanged( const QString& theName )
   }
 }
 
+void HYDROGUI_LandCoverMapOp::onPolylineFaceChanged()
+{
+  HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
+  if ( !aPanel )
+    return;
+
+  LightApp_DataOwner* aPolylineFaceDataOwner = NULL;
+  Handle(HYDROData_Entity) aPolylineFace = aPanel->getPolylineFace();
+  if ( !aPolylineFace.IsNull() )
+  {
+    // Select chosen polyline/face in the Object Browser, if it is not selected yet
+    // (i.e. object was chosen not in the Object Browser or 3d Viewer, but in combo-box)
+    aPolylineFaceDataOwner = new LightApp_DataOwner( HYDROGUI_DataObject::dataObjectEntry( aPolylineFace ) );  
+    LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
+    if ( aSelectionMgr )
+    {
+      bool bIsAlreadySelected = false;
+      SUIT_DataOwnerPtrList aSelectedOwners;
+      aSelectionMgr->selected( aSelectedOwners );
+      foreach( SUIT_DataOwner* aSUITOwner, aSelectedOwners )
+      {
+        if ( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
+        {
+          if ( anOwner->entry() == aPolylineFaceDataOwner->entry() )
+          {
+            bIsAlreadySelected = true;
+            break;
+          }
+        }
+      }
+      if ( !bIsAlreadySelected )
+      {
+        SUIT_DataOwnerPtrList aList( true );
+        aList.append( SUIT_DataOwnerPtr( aPolylineFaceDataOwner ) );
+        aSelectionMgr->setSelected( aList );
+      }
+    }
+
+    // Show Preview of selected polyline/face
+    Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aPolylineFace );
+    Handle(HYDROData_Object) aFace = Handle(HYDROData_Object)::DownCast( aPolylineFace );
+    if ( !aPolyline.IsNull() || !aFace.IsNull() )
+    {
+      TopoDS_Shape aTopoDSShape;
+      if ( !aPolyline.IsNull() )
+        aTopoDSShape = aPolyline->GetShape();
+      else
+        aTopoDSShape = aFace->GetTopShape();
+
+      OCCViewer_ViewManager* aViewManager = ::qobject_cast<OCCViewer_ViewManager*>( 
+        module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) );
+      if ( aViewManager )
+      {
+        if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
+        {
+          if ( myPolylineFacePreviewPrs )
+          {
+            delete myPolylineFacePreviewPrs;
+            myPolylineFacePreviewPrs = 0;
+          }
+
+          int aViewerId = (size_t)aViewer;
+          if ( !module()->isObjectVisible( aViewerId, aPolylineFace ) )
+          {
+            Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+            if ( !aCtx.IsNull() )
+            {
+              myPolylineFacePreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
+              aCtx->ClearSelected();
+
+              myPolylineFacePreviewPrs->setBorderColor( Qt::white, false, false );
+              myPolylineFacePreviewPrs->setShape( aTopoDSShape, true, true, !aPolyline.IsNull() ? AIS_WireFrame : AIS_Shaded );
+
+              module()->update( UF_OCCViewer | UF_FitAll );
+            }       
+          }
+        }
+      }
+    }
+  }
+}
+
 void HYDROGUI_LandCoverMapOp::onCreatePreview()
 {
   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
@@ -405,34 +499,41 @@ void HYDROGUI_LandCoverMapOp::onCreatePreview()
       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
       if ( !aCtx.IsNull() )
       {
-        disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
-          aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
-        disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
-          aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));        
-
-        connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
-            this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
-        connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
-          this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
-
-        LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
-        if( aSelectionMgr )
+        if ( myOperationId == RemoveLandCoverId || 
+             myOperationId == MergeLandCoverId ||
+             myOperationId == ChangeLandCoverTypeId )
         {
-          QList<SUIT_Selector*> aSelectorList;
-          aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
-          QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
-          for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
+          disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+            aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+          disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
+            aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));        
+
+          connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+              this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+          connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
+            this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
+
+          LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
+          if ( aSelectionMgr )
           {
-            HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
-            if ( aHydroSelector )
+            QList<SUIT_Selector*> aSelectorList;
+            aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
+            QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
+            for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
             {
-              disconnect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
-              connect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
+              HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
+              if ( aHydroSelector )
+              {
+                disconnect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
+                connect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
+              }
             }
           }
-        }
         
-        connect( this, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
+          connect( this, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
+        }
+        else
+          connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
         myPreviewPrs = new HYDROGUI_ShapeLandCoverMap( module()->getOCCDisplayer(), aCtx, myEditedObject, getPreviewZLayer()/*, theIsScalarMapMode*/ );
       }
     }
@@ -440,15 +541,14 @@ void HYDROGUI_LandCoverMapOp::onCreatePreview()
 
   if ( aViewManager && myPreviewPrs && !myEditedObject.IsNull() )
   {
-    TopoDS_Shape aLandCoverMapShape = myEditedObject->GetShape();
-    if( !aLandCoverMapShape.IsNull() )
-    {
-      if ( myOperationId == RemoveLandCoverId ||
-           myOperationId == MergeLandCoverId ||
-           myOperationId == ChangeLandCoverTypeId )
-        myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) ); 
-      myPreviewPrs->setShape( aLandCoverMapShape );      
-    }
+    if ( myOperationId == RemoveLandCoverId || 
+         myOperationId == MergeLandCoverId ||
+         myOperationId == ChangeLandCoverTypeId )
+      myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) ); 
+    myPreviewPrs->update( false, false );
+    
+    if ( myOperationId == ChangeLandCoverTypeId )
+      selectLandCoverInPreview();
   }
   
   module()->update( UF_OCCViewer | UF_FitAll );
@@ -462,33 +562,32 @@ void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged()
   if ( !aPanel )
     return;
 
-  Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
-  if ( !aCtx.IsNull() )
-  {
-    int aNbSelected = aCtx->NbSelected();
+  int aNbSelected = getNbSelected();
 
-    if ( myOperationId == RemoveLandCoverId || myOperationId == ChangeLandCoverTypeId )
-      // Enable Apply, Apply and Close buttons only if at least one face (land cover) is selected in the 3d viewer
-      aPanel->setApplyEnabled( aNbSelected > 0 );
-    else if ( myOperationId == MergeLandCoverId )
-      // Enable Apply, Apply and Close buttons only if at least two faces (land covers) are selected in the 3d viewer
-      aPanel->setApplyEnabled( aNbSelected > 1 );
+  if ( myOperationId == RemoveLandCoverId || myOperationId == ChangeLandCoverTypeId )
+    // Enable Apply, Apply and Close buttons only if at least one face (land cover) is selected in the 3d viewer
+    aPanel->setApplyEnabled( aNbSelected > 0 );
+  else if ( myOperationId == MergeLandCoverId )
+    // Enable Apply, Apply and Close buttons only if at least two faces (land covers) are selected in the 3d viewer
+    aPanel->setApplyEnabled( aNbSelected > 1 );
 
-    if ( myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
+  if ( myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
+  {
+    if ( aNbSelected == 1 && !myEditedObject.IsNull() )
     {
-      if ( aNbSelected == 1 && !myEditedObject.IsNull() )
+      TopTools_ListOfShape aFacesSelectedInViewer;
+      getSelectedShapes( aFacesSelectedInViewer );
+      if ( aFacesSelectedInViewer.Extent() == 1 )
       {
-        TopTools_ListOfShape aFacesSelectedInViewer;
-        getSelectedShapes( aFacesSelectedInViewer, aCtx );
-        if ( aFacesSelectedInViewer.Extent() == 1 )
-        {
-          QString aType = myEditedObject->StricklerType( TopoDS::Face( aFacesSelectedInViewer.First() ) );
-          if ( !aType.isEmpty() )
-            aPanel->setSelectedStricklerTypeName( aType );
-        }
+        QString aType = myEditedObject->StricklerType( TopoDS::Face( aFacesSelectedInViewer.First() ) );
+        if ( !aType.isEmpty() )
+          aPanel->setSelectedStricklerTypeName( aType );
       }
     }
   }
+
+  if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
+    aPanel->updateSelectedLandCoversLabel( aNbSelected );
 }
 
 void HYDROGUI_LandCoverMapOp::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
@@ -557,12 +656,18 @@ void HYDROGUI_LandCoverMapOp::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseE
 
 void HYDROGUI_LandCoverMapOp::closePreview()
 {
-  if( myPreviewPrs )
+  if ( myPreviewPrs )
   {
     delete myPreviewPrs;
     myPreviewPrs = 0;
   }
 
+  if ( myPolylineFacePreviewPrs )
+  {
+    delete myPolylineFacePreviewPrs;
+    myPolylineFacePreviewPrs = 0;
+  }
+
   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
   if ( !aPanel )
     return;
@@ -570,33 +675,38 @@ void HYDROGUI_LandCoverMapOp::closePreview()
   if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
     aPanel->setApplyEnabled( false );
 
-  OCCViewer_ViewManager* aViewManager = getPreviewManager();
-  if ( aViewManager )
+  if ( myOperationId == RemoveLandCoverId || 
+       myOperationId == MergeLandCoverId ||
+       myOperationId == ChangeLandCoverTypeId )
   {
-    if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
+    OCCViewer_ViewManager* aViewManager = getPreviewManager();
+    if ( aViewManager )
     {
-      disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
-        this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
-      disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
-        this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
-      connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
-        aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
-      connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
-        aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));  
-
-      LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
-      if( aSelectionMgr )
+      if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
       {
-        QList<SUIT_Selector*> aSelectorList;
-        aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
-        QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
-        for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
+        disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+          this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+        disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
+          this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
+        connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+          aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+        connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
+          aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));  
+
+        LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
+        if ( aSelectionMgr )
         {
-          HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
-          if ( aHydroSelector )
+          QList<SUIT_Selector*> aSelectorList;
+          aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
+          QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
+          for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
           {
-            disconnect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
-            connect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );            
+            HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
+            if ( aHydroSelector )
+            {
+              disconnect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
+              connect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );            
+            }
           }
         }
       }
@@ -616,17 +726,14 @@ Handle(AIS_InteractiveContext) HYDROGUI_LandCoverMapOp::getInteractiveContext()
   return aCtx;
 }
 
-void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelectedShapes,
-                                                 Handle(AIS_InteractiveContext)& theCtx )
+void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelectedShapes )
 {
-  if ( theCtx.IsNull() )
-    theCtx = getInteractiveContext();
-
-  if ( !theCtx.IsNull() && theCtx->NbSelected() > 0 )
+  Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
+  if ( !aCtx.IsNull() )
   {
-    for ( theCtx->InitSelected(); theCtx->MoreSelected(); theCtx->NextSelected() )
+    for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() )
     {
-      TopoDS_Shape aSelectedShape = theCtx->SelectedShape();
+      TopoDS_Shape aSelectedShape = aCtx->SelectedShape();
       if ( aSelectedShape.IsNull() )
         continue;
 
@@ -634,3 +741,52 @@ void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelect
     }
   }
 }
+
+int HYDROGUI_LandCoverMapOp::getNbSelected()
+{
+  int aNbSelected = 0;
+
+  Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
+  if ( !aCtx.IsNull() )
+  {
+    for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() )
+    {
+      TopoDS_Shape aSelectedShape = aCtx->SelectedShape();
+      if ( aSelectedShape.IsNull() )
+        continue;
+      aNbSelected++;
+    }
+  }
+
+  return aNbSelected;
+}
+
+void HYDROGUI_LandCoverMapOp::selectLandCoverInPreview()
+{
+  if ( myPreviewPrs && !myEditedObject.IsNull() && myEditedObject->GetLCCount() == 1 )
+  {
+    OCCViewer_ViewManager* aViewManager = getPreviewManager();
+    if ( !aViewManager )
+      return;
+    
+    Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
+    if ( aCtx.IsNull() )
+      return;
+    
+    OCCViewer_ViewWindow* aViewWindow = (OCCViewer_ViewWindow*)aViewManager->getActiveView();
+    if ( !aViewWindow )
+      return;
+
+    OCCViewer_ViewPort3d* aViewPort = aViewWindow->getViewPort();
+    if ( !aViewPort )
+      return;
+
+    Handle(V3d_View) aView = aViewPort->getView();
+    if ( aView.IsNull() )
+      return;
+
+    aCtx->ShiftSelect( 0, 0, aViewPort->width(), aViewPort->height(), aView, Standard_False );
+    aCtx->UpdateCurrentViewer();
+    emit selectionChanged();
+  }
+}