Salome HOME
213256f6de8af9fe61ebff680711517cf5dc53fa
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_LandCoverMapOp.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_LandCoverMapOp.h"
20
21 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_OCCDisplayer.h"
23 #include "HYDROGUI_Operations.h"
24 #include "HYDROGUI_LandCoverMapDlg.h"
25 #include "HYDROGUI_Tool.h"
26 #include "HYDROGUI_UpdateFlags.h"
27 #include "HYDROGUI_DataObject.h"
28 #include "HYDROGUI_ShapeLandCoverMap.h"
29 #include "HYDROGUI_OCCSelector.h"
30
31 #include <HYDROData_Iterator.h>
32 #include <HYDROData_StricklerTable.h>
33 #include <HYDROData_PolylineXY.h>
34 #include <HYDROData_Object.h>
35
36 #include <OCCViewer_ViewManager.h>
37 #include <OCCViewer_ViewModel.h>
38 #include <OCCViewer_ViewWindow.h>
39 #include <OCCViewer_ViewPort3d.h>
40
41 #include <LightApp_Application.h>
42 #include <LightApp_SelectionMgr.h>
43 #include <SUIT_ViewWindow.h>
44
45 #include <TopoDS.hxx>
46 #include <TopoDS_Face.hxx>
47 #include <TopTools_ListOfShape.hxx>
48 #include <TopTools_ListIteratorOfListOfShape.hxx>
49 #include <AIS_Shape.hxx>
50
51 #include <QApplication>
52 #include <QMouseEvent>
53
54 HYDROGUI_LandCoverMapOp::HYDROGUI_LandCoverMapOp( HYDROGUI_Module* theModule, const int theOperationId )
55 : HYDROGUI_Operation( theModule ),
56   myOperationId( theOperationId ),
57   myPreviewPrs( 0 )
58 {
59   switch( myOperationId )
60   {
61     case CreateLandCoverMapId:
62       setName( tr( "CREATE_LAND_COVER_MAP" ) );
63       break;
64     case AddLandCoverId:
65       setName( tr( "ADD_LAND_COVER" ) );
66       break;
67     case RemoveLandCoverId:
68       setName( tr( "REMOVE_LAND_COVER" ) );
69       break;
70     case SplitLandCoverId:
71       setName( tr( "SPLIT_LAND_COVER" ) );
72       break;
73     case MergeLandCoverId:
74       setName( tr( "MERGE_LAND_COVER" ) );
75       break;
76     case ChangeLandCoverTypeId:
77       setName( tr( "CHANGE_LAND_COVER_TYPE" ) );
78       break;
79   }  
80 }
81
82 HYDROGUI_LandCoverMapOp::~HYDROGUI_LandCoverMapOp()
83 {
84   closePreview();
85 }
86
87 void HYDROGUI_LandCoverMapOp::startOperation()
88 {
89   HYDROGUI_Operation::startOperation();
90
91   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
92   if ( !aPanel )
93     return;
94
95   aPanel->blockSignals( true );
96
97   aPanel->reset();
98
99   // Set name of the created/edited land cover map object
100   QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_LAND_COVER_MAP_NAME" ) );
101   if ( myOperationId != CreateLandCoverMapId )
102   {
103     if ( isApplyAndClose() )
104       myEditedObject = Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
105     
106     // Construct a list of names of all land cover map objects defined within the data model
107     QStringList aLandCoverMapNames;
108     HYDROData_Iterator anIterator( doc(), KIND_LAND_COVER_MAP );
109     for( ; anIterator.More(); anIterator.Next() )
110     {
111       Handle(HYDROData_LandCoverMap) aLandCoverObj =
112         Handle(HYDROData_LandCoverMap)::DownCast( anIterator.Current() );       
113       if ( !aLandCoverObj.IsNull() )
114         aLandCoverMapNames.append( aLandCoverObj->GetName() );
115     }
116     
117     //aLandCoverMapNames.sort();
118     aPanel->setObjectNames( aLandCoverMapNames );
119
120     if ( myEditedObject.IsNull() )
121     {
122       if ( !aLandCoverMapNames.empty() )
123       {
124         anObjectName = aLandCoverMapNames.first();
125         if ( !anObjectName.isEmpty())
126         {
127           Handle(HYDROData_LandCoverMap) anObject =
128             Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), anObjectName ) );
129           if( !anObject.IsNull() )
130             myEditedObject = anObject;
131         }
132       }
133     }
134     else
135       anObjectName = myEditedObject->GetName();
136   }  
137   aPanel->setObjectName( anObjectName );
138
139   closePreview();
140   if ( myOperationId != CreateLandCoverMapId )
141     onCreatePreview();
142
143   aPanel->blockSignals( false );
144
145   module()->update( UF_OCCViewer | UF_FitAll );
146 }
147
148 void HYDROGUI_LandCoverMapOp::abortOperation()
149 {
150   closePreview();
151
152   HYDROGUI_Operation::abortOperation();
153
154   module()->update( UF_OCCViewer | UF_FitAll );
155 }
156
157 void HYDROGUI_LandCoverMapOp::commitOperation()
158 {
159   closePreview();
160
161   HYDROGUI_Operation::commitOperation();
162
163   module()->update( UF_OCCViewer | UF_FitAll );
164 }
165
166 HYDROGUI_InputPanel* HYDROGUI_LandCoverMapOp::createInputPanel() const
167 {
168   HYDROGUI_LandCoverMapDlg* aPanel = new HYDROGUI_LandCoverMapDlg( module(), getName(), myOperationId );
169   connect( aPanel, SIGNAL( landCoverMapChanged( const QString& ) ),
170            this, SLOT( onLandCoverMapChanged( const QString& ) ) );
171   return aPanel;
172 }
173
174 bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
175                                             QString& theErrorMsg,
176                                             QStringList& theBrowseObjectsEntries )
177 {
178   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
179   if ( !aPanel )
180     return false;
181
182   // Check name of the created/edited object
183   QString anObjectName = aPanel->getObjectName().simplified();
184   if ( anObjectName.isEmpty() )
185   {
186     theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
187     return false;
188   }
189
190   if ( myOperationId == CreateLandCoverMapId || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
191   {
192     // check that there are no other objects with the same name in the document
193     Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
194     if( !anObject.IsNull() )
195     {
196       theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
197       return false;
198     }
199   }
200
201   Handle(HYDROData_PolylineXY) aPolyline;
202   Handle(HYDROData_Object) aFace;
203
204   TopTools_ListOfShape aFacesSelectedInViewer;
205
206   // Get polyline/face selected in combo-box
207   if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId || myOperationId == SplitLandCoverId )
208   {
209     Handle(HYDROData_Entity) aPolylineFace = aPanel->getPolylineFace();
210     aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aPolylineFace );
211     aFace = Handle(HYDROData_Object)::DownCast( aPolylineFace );
212     if ( aPolyline.IsNull() && aFace.IsNull() )
213     {
214       theErrorMsg = tr( "POLYLINE_FACE_NOT_DEFINED" );
215       return false;
216     }
217   }
218   // Get face(s) selected in the 3d viewer
219   else if ( myOperationId == RemoveLandCoverId || 
220             myOperationId == MergeLandCoverId || 
221             myOperationId == ChangeLandCoverTypeId )
222   {
223     if ( myPreviewPrs )
224       // Fill in aFacesSelectedInViewer list
225       getSelectedShapes( aFacesSelectedInViewer );
226   }
227
228   // Get selected Strickler type
229   QString aSelectedStricklerType;
230   if ( myOperationId == CreateLandCoverMapId || 
231        myOperationId == AddLandCoverId || 
232        myOperationId == MergeLandCoverId ||
233        myOperationId == ChangeLandCoverTypeId )
234   {
235     aSelectedStricklerType = aPanel->getSelectedStricklerTypeName();
236     if ( aSelectedStricklerType.isEmpty() )
237     {
238       theErrorMsg = tr( "STRICKLER_TYPE_NOT_DEFINED" );
239       return false;
240     }
241   }
242
243   // Create / find the new / edited land cover map object
244   Handle(HYDROData_LandCoverMap) aLandCoverMapObj = myOperationId != CreateLandCoverMapId ? myEditedObject :
245     Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
246   if ( aLandCoverMapObj.IsNull() )
247   {
248     theErrorMsg = tr( "LAND_COVER_MAP_UNDEFINED" );
249     return false;
250   }
251
252   // Set land cover map name
253   aLandCoverMapObj->SetName( anObjectName );
254   
255   // Add land cover to new / edited land cover map
256   if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId )
257   {
258     bool aLandCoverAdded = false;
259     if ( !aPolyline.IsNull() )
260       aLandCoverAdded = aLandCoverMapObj->Add( aPolyline, aSelectedStricklerType );
261     else if ( !aFace.IsNull() )
262       aLandCoverAdded = aLandCoverMapObj->Add( aFace, aSelectedStricklerType );
263     if ( !aLandCoverAdded )
264     {
265       theErrorMsg = tr( "LAND_COVER_NOT_ADDED" );
266       return false;
267     }
268   }
269
270   // Remove land cover from edited land cover map
271   if ( myOperationId == RemoveLandCoverId )
272   {
273     bool aLandCoverRemoved = false;
274     if ( !aFacesSelectedInViewer.IsEmpty() )
275     {
276       aLandCoverRemoved = aLandCoverMapObj->Remove( aFacesSelectedInViewer );
277       if ( !aLandCoverRemoved )
278       {
279         theErrorMsg = tr( "LAND_COVER_NOT_REMOVED" );
280         return false;
281       }
282     }
283   }
284
285   // Split land cover(s) inside edited land cover map
286   if ( myOperationId == SplitLandCoverId )
287   {
288     bool aLandCoverSplitted = false;
289     if ( !aPolyline.IsNull() )
290       aLandCoverSplitted = aLandCoverMapObj->Split( aPolyline );
291     else if ( !aFace.IsNull() )
292     {
293       // Get the complete boundary of the object face as the splitting polyline
294       QList<TopoDS_Shape> aBoundShapes;
295       QStringList aBoundNames;
296       aFace->GetBoundaries( aBoundShapes, aBoundNames );
297
298       for( int i=0, n=aBoundShapes.size(); i<n; i++ )
299       {
300         TopoDS_Shape aShape = aBoundShapes[i];
301         if( aShape.IsNull() )
302           continue;
303
304         bool aSplitResult = aLandCoverMapObj->Split( aShape );
305         aLandCoverSplitted = ( i==0 ? aSplitResult : aLandCoverSplitted && aSplitResult );
306       }
307     }
308     if ( !aLandCoverSplitted )
309     {
310       theErrorMsg = tr( "LAND_COVER_NOT_SPLITTED" );
311       return false;
312     }
313   }
314
315   // Merge land covers inside edited land cover map
316   if ( myOperationId == MergeLandCoverId )
317   {
318     bool aLandCoverMerged = false;
319     if ( !aFacesSelectedInViewer.IsEmpty() )
320     {
321       aLandCoverMerged = aLandCoverMapObj->Merge( aFacesSelectedInViewer, aSelectedStricklerType );
322       if ( !aLandCoverMerged )
323       {
324         theErrorMsg = tr( "LAND_COVER_NOT_MERGED" );
325         return false;
326       }
327     }
328   }
329
330   // Change Strickler type for land cover(s) inside edited land cover map
331   if ( myOperationId == ChangeLandCoverTypeId )
332   {
333     bool aLandCoverChangeType = false;
334     if ( !aFacesSelectedInViewer.IsEmpty() )
335     {
336       aLandCoverChangeType = aLandCoverMapObj->ChangeType( aFacesSelectedInViewer, aSelectedStricklerType );
337       if ( !aLandCoverChangeType )
338       {
339         theErrorMsg = tr( "LAND_COVER_TYPE_NOT_CHANGED" );
340         return false;
341       }
342     }
343   }
344     
345   // Update land cover map object and close preview
346   aLandCoverMapObj->Update();
347
348   closePreview();
349
350   // Publish the newly created land cover map in the Object Browser
351   module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aLandCoverMapObj, true );
352   if ( myOperationId == CreateLandCoverMapId )
353   {
354     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aLandCoverMapObj );
355     theBrowseObjectsEntries.append( anEntry );
356   }
357
358   // Update presentation of land cover object in the 3d viewer
359   module()->setIsToUpdate( aLandCoverMapObj );
360   module()->getOCCDisplayer()->SetToUpdateColorScale();
361
362   theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
363
364   if ( myOperationId == CreateLandCoverMapId )
365     module()->enableLCMActions();
366
367   return true;
368 }
369
370 void HYDROGUI_LandCoverMapOp::onLandCoverMapChanged( const QString& theName )
371 {
372   // If the edited land cover map was changed in the combo-box, update myEditedObject
373   if ( myOperationId != CreateLandCoverMapId )
374   {
375     myEditedObject = Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theName ) );
376     if ( !myEditedObject.IsNull() )
377     {
378       // Show preview of the newly selected land cover map
379       closePreview();
380       onCreatePreview();
381     }
382   }
383 }
384
385 void HYDROGUI_LandCoverMapOp::onCreatePreview()
386 {
387   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
388   if ( !aPanel )
389     return;
390
391   QApplication::setOverrideCursor( Qt::WaitCursor );  
392
393   LightApp_Application* anApp = module()->getApp();
394   if ( !getPreviewManager() )
395     setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>( 
396                        anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
397   OCCViewer_ViewManager* aViewManager = getPreviewManager();
398   if ( aViewManager && !myPreviewPrs )
399   {
400     if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
401     {
402       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
403       if ( !aCtx.IsNull() )
404       {
405         disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
406           aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
407         disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
408           aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));        
409
410         connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
411             this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
412         connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
413           this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
414
415         LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
416         if( aSelectionMgr )
417         {
418           QList<SUIT_Selector*> aSelectorList;
419           aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
420           QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
421           for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
422           {
423             HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
424             if ( aHydroSelector )
425             {
426               disconnect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
427               connect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
428             }
429           }
430         }
431         
432         connect( this, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
433         myPreviewPrs = new HYDROGUI_ShapeLandCoverMap( module()->getOCCDisplayer(), aCtx, myEditedObject, getPreviewZLayer()/*, theIsScalarMapMode*/ );
434       }
435     }
436   }
437
438   if ( aViewManager && myPreviewPrs && !myEditedObject.IsNull() )
439   {
440     if ( myOperationId == RemoveLandCoverId || 
441          myOperationId == MergeLandCoverId ||
442          myOperationId == ChangeLandCoverTypeId )
443       myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) ); 
444     myPreviewPrs->update( false, false );
445     
446     if ( myOperationId == ChangeLandCoverTypeId )
447       selectLandCoverInPreview();
448   }
449   
450   module()->update( UF_OCCViewer | UF_FitAll );
451
452   QApplication::restoreOverrideCursor();  
453 }
454
455 void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged()
456 {
457   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
458   if ( !aPanel )
459     return;
460
461   int aNbSelected = getNbSelected();
462
463   if ( myOperationId == RemoveLandCoverId || myOperationId == ChangeLandCoverTypeId )
464     // Enable Apply, Apply and Close buttons only if at least one face (land cover) is selected in the 3d viewer
465     aPanel->setApplyEnabled( aNbSelected > 0 );
466   else if ( myOperationId == MergeLandCoverId )
467     // Enable Apply, Apply and Close buttons only if at least two faces (land covers) are selected in the 3d viewer
468     aPanel->setApplyEnabled( aNbSelected > 1 );
469
470   if ( myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
471   {
472     if ( aNbSelected == 1 && !myEditedObject.IsNull() )
473     {
474       TopTools_ListOfShape aFacesSelectedInViewer;
475       getSelectedShapes( aFacesSelectedInViewer );
476       if ( aFacesSelectedInViewer.Extent() == 1 )
477       {
478         QString aType = myEditedObject->StricklerType( TopoDS::Face( aFacesSelectedInViewer.First() ) );
479         if ( !aType.isEmpty() )
480           aPanel->setSelectedStricklerTypeName( aType );
481       }
482     }
483   }
484
485   if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
486     aPanel->updateSelectedLandCoversLabel( aNbSelected );
487 }
488
489 void HYDROGUI_LandCoverMapOp::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
490 {
491   myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
492 }
493
494 void HYDROGUI_LandCoverMapOp::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
495 {
496   if (theEvent->button() != Qt::LeftButton) return;
497   if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
498
499   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
500   if (!aView )
501     return;
502
503   OCCViewer_ViewManager* aViewManager = getPreviewManager();
504   if ( !aViewManager )
505     return;
506   
507   OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer();
508   if ( !aViewer )
509     return;
510
511   Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
512   if ( aCtx.IsNull() )
513     return;
514
515   myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
516
517   if (myStartPnt == myEndPnt)
518   {
519     if ( !aViewer->isPreselectionEnabled() ) {
520       Handle(V3d_View) aView3d = aView->getViewPort()->getView();
521       if ( !aView3d.IsNull() ) {
522         aCtx->MoveTo(myEndPnt.x(), myEndPnt.y(), aView3d);
523       }
524     }
525
526     Handle(StdSelect_ViewerSelector3d) aMainSelector = aCtx->MainSelector();
527     if ( aMainSelector.IsNull() )
528       return;
529     const Standard_Integer aDetectedNb = aMainSelector->NbPicked();
530     if ( aDetectedNb == 0 )
531     {
532       aCtx->ClearSelected( false );
533       emit deselection();
534     }
535
536     for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
537     {
538       Handle(SelectMgr_EntityOwner) anOwner = aMainSelector->Picked (aDetIter);
539       aCtx->AddOrRemoveSelected( anOwner, Standard_False );
540     }
541   }
542   else
543   {
544     aCtx->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
545                       myEndPnt.x(), myEndPnt.y(),
546                       aView->getViewPort()->getView(), Standard_False );
547   }
548
549   aCtx->UpdateCurrentViewer();
550   emit selectionChanged();  
551 }
552
553 void HYDROGUI_LandCoverMapOp::closePreview()
554 {
555   if( myPreviewPrs )
556   {
557     delete myPreviewPrs;
558     myPreviewPrs = 0;
559   }
560
561   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
562   if ( !aPanel )
563     return;
564
565   if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
566     aPanel->setApplyEnabled( false );
567
568   OCCViewer_ViewManager* aViewManager = getPreviewManager();
569   if ( aViewManager )
570   {
571     if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
572     {
573       disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
574         this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
575       disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
576         this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
577       connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
578         aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
579       connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
580         aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));  
581
582       LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
583       if( aSelectionMgr )
584       {
585         QList<SUIT_Selector*> aSelectorList;
586         aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
587         QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
588         for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
589         {
590           HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
591           if ( aHydroSelector )
592           {
593             disconnect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
594             connect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );            
595           }
596         }
597       }
598     }
599   }
600 }
601
602 Handle(AIS_InteractiveContext) HYDROGUI_LandCoverMapOp::getInteractiveContext()
603 {
604   OCCViewer_ViewManager* aViewManager = getPreviewManager();
605   Handle(AIS_InteractiveContext) aCtx = NULL;
606   if ( aViewManager ) {
607     if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
608       aCtx = aViewer->getAISContext();
609     }
610   }
611   return aCtx;
612 }
613
614 void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelectedShapes )
615 {
616   Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
617   if ( !aCtx.IsNull() )
618   {
619     for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() )
620     {
621       TopoDS_Shape aSelectedShape = aCtx->SelectedShape();
622       if ( aSelectedShape.IsNull() )
623         continue;
624
625       theSelectedShapes.Append( aSelectedShape );
626     }
627   }
628 }
629
630 int HYDROGUI_LandCoverMapOp::getNbSelected()
631 {
632   int aNbSelected = 0;
633
634   Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
635   if ( !aCtx.IsNull() )
636   {
637     for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() )
638     {
639       TopoDS_Shape aSelectedShape = aCtx->SelectedShape();
640       if ( aSelectedShape.IsNull() )
641         continue;
642       aNbSelected++;
643     }
644   }
645
646   return aNbSelected;
647 }
648
649 void HYDROGUI_LandCoverMapOp::selectLandCoverInPreview()
650 {
651   if ( myPreviewPrs && !myEditedObject.IsNull() && myEditedObject->GetLCCount() == 1 )
652   {
653     OCCViewer_ViewManager* aViewManager = getPreviewManager();
654     if ( !aViewManager )
655       return;
656     
657     Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
658     if ( aCtx.IsNull() )
659       return;
660     
661     OCCViewer_ViewWindow* aViewWindow = (OCCViewer_ViewWindow*)aViewManager->getActiveView();
662     if ( !aViewWindow )
663       return;
664
665     OCCViewer_ViewPort3d* aViewPort = aViewWindow->getViewPort();
666     if ( !aViewPort )
667       return;
668
669     Handle(V3d_View) aView = aViewPort->getView();
670     if ( aView.IsNull() )
671       return;
672
673     aCtx->ShiftSelect( 0, 0, aViewPort->width(), aViewPort->height(), aView, Standard_False );
674     aCtx->UpdateCurrentViewer();
675     emit selectionChanged();
676   }
677 }