Salome HOME
Merge branch 'BR_LCM_COMP' into HEAD
[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     {
225       // Fill in aFacesSelectedInViewer list
226       Handle(AIS_InteractiveContext) aCtx;
227       getSelectedShapes( aFacesSelectedInViewer, aCtx );
228     }
229   }
230
231   // Get selected Strickler type
232   QString aSelectedStricklerType;
233   if ( myOperationId == CreateLandCoverMapId || 
234        myOperationId == AddLandCoverId || 
235        myOperationId == MergeLandCoverId ||
236        myOperationId == ChangeLandCoverTypeId )
237   {
238     aSelectedStricklerType = aPanel->getSelectedStricklerTypeName();
239     if ( aSelectedStricklerType.isEmpty() )
240     {
241       theErrorMsg = tr( "STRICKLER_TYPE_NOT_DEFINED" );
242       return false;
243     }
244   }
245
246   // Create / find the new / edited land cover map object
247   Handle(HYDROData_LandCoverMap) aLandCoverMapObj = myOperationId != CreateLandCoverMapId ? myEditedObject :
248     Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
249   if ( aLandCoverMapObj.IsNull() )
250   {
251     theErrorMsg = tr( "LAND_COVER_MAP_UNDEFINED" );
252     return false;
253   }
254
255   // Set land cover map name
256   aLandCoverMapObj->SetName( anObjectName );
257   
258   // Add land cover to new / edited land cover map
259   if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId )
260   {
261     bool aLandCoverAdded = false;
262     if ( !aPolyline.IsNull() )
263       aLandCoverAdded = aLandCoverMapObj->Add( aPolyline, aSelectedStricklerType );
264     else if ( !aFace.IsNull() )
265       aLandCoverAdded = aLandCoverMapObj->Add( aFace, aSelectedStricklerType );
266     if ( !aLandCoverAdded )
267     {
268       theErrorMsg = tr( "LAND_COVER_NOT_ADDED" );
269       return false;
270     }
271   }
272
273   // Remove land cover from edited land cover map
274   if ( myOperationId == RemoveLandCoverId )
275   {
276     bool aLandCoverRemoved = false;
277     if ( !aFacesSelectedInViewer.IsEmpty() )
278     {
279       aLandCoverRemoved = aLandCoverMapObj->Remove( aFacesSelectedInViewer );
280       if ( !aLandCoverRemoved )
281       {
282         theErrorMsg = tr( "LAND_COVER_NOT_REMOVED" );
283         return false;
284       }
285     }
286   }
287
288   // Split land cover(s) inside edited land cover map
289   if ( myOperationId == SplitLandCoverId )
290   {
291     bool aLandCoverSplitted = false;
292     if ( !aPolyline.IsNull() )
293       aLandCoverSplitted = aLandCoverMapObj->Split( aPolyline );
294     else if ( !aFace.IsNull() )
295     {
296       // Get the complete boundary of the object face as the splitting polyline
297       QList<TopoDS_Shape> aBoundShapes;
298       QStringList aBoundNames;
299       aFace->GetBoundaries( aBoundShapes, aBoundNames );
300
301       for( int i=0, n=aBoundShapes.size(); i<n; i++ )
302       {
303         TopoDS_Shape aShape = aBoundShapes[i];
304         if( aShape.IsNull() )
305           continue;
306
307         bool aSplitResult = aLandCoverMapObj->Split( aShape );
308         aLandCoverSplitted = ( i==0 ? aSplitResult : aLandCoverSplitted && aSplitResult );
309       }
310     }
311     if ( !aLandCoverSplitted )
312     {
313       theErrorMsg = tr( "LAND_COVER_NOT_SPLITTED" );
314       return false;
315     }
316   }
317
318   // Merge land covers inside edited land cover map
319   if ( myOperationId == MergeLandCoverId )
320   {
321     bool aLandCoverMerged = false;
322     if ( !aFacesSelectedInViewer.IsEmpty() )
323     {
324       aLandCoverMerged = aLandCoverMapObj->Merge( aFacesSelectedInViewer, aSelectedStricklerType );
325       if ( !aLandCoverMerged )
326       {
327         theErrorMsg = tr( "LAND_COVER_NOT_MERGED" );
328         return false;
329       }
330     }
331   }
332
333   // Change Strickler type for land cover(s) inside edited land cover map
334   if ( myOperationId == ChangeLandCoverTypeId )
335   {
336     bool aLandCoverChangeType = false;
337     if ( !aFacesSelectedInViewer.IsEmpty() )
338     {
339       aLandCoverChangeType = aLandCoverMapObj->ChangeType( aFacesSelectedInViewer, aSelectedStricklerType );
340       if ( !aLandCoverChangeType )
341       {
342         theErrorMsg = tr( "LAND_COVER_TYPE_NOT_CHANGED" );
343         return false;
344       }
345     }
346   }
347     
348   // Update land cover map object and close preview
349   aLandCoverMapObj->Update();
350
351   closePreview();
352
353   // Publish the newly created land cover map in the Object Browser
354   module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aLandCoverMapObj, true );
355   if ( myOperationId == CreateLandCoverMapId )
356   {
357     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aLandCoverMapObj );
358     theBrowseObjectsEntries.append( anEntry );
359   }
360
361   // Update presentation of land cover object in the 3d viewer
362   module()->setIsToUpdate( aLandCoverMapObj );
363   module()->getOCCDisplayer()->SetToUpdateColorScale();
364
365   theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
366
367   if ( myOperationId == CreateLandCoverMapId )
368     module()->enableLCMActions();
369
370   return true;
371 }
372
373 void HYDROGUI_LandCoverMapOp::onLandCoverMapChanged( const QString& theName )
374 {
375   // If the edited land cover map was changed in the combo-box, update myEditedObject
376   if ( myOperationId != CreateLandCoverMapId )
377   {
378     myEditedObject = Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theName ) );
379     if ( !myEditedObject.IsNull() )
380     {
381       // Show preview of the newly selected land cover map
382       closePreview();
383       onCreatePreview();
384     }
385   }
386 }
387
388 void HYDROGUI_LandCoverMapOp::onCreatePreview()
389 {
390   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
391   if ( !aPanel )
392     return;
393
394   QApplication::setOverrideCursor( Qt::WaitCursor );  
395
396   LightApp_Application* anApp = module()->getApp();
397   if ( !getPreviewManager() )
398     setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>( 
399                        anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
400   OCCViewer_ViewManager* aViewManager = getPreviewManager();
401   if ( aViewManager && !myPreviewPrs )
402   {
403     if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
404     {
405       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
406       if ( !aCtx.IsNull() )
407       {
408         disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
409           aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
410         disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
411           aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));        
412
413         connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
414             this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
415         connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
416           this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
417
418         LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
419         if( aSelectionMgr )
420         {
421           QList<SUIT_Selector*> aSelectorList;
422           aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
423           QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
424           for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
425           {
426             HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
427             if ( aHydroSelector )
428             {
429               disconnect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
430               connect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
431             }
432           }
433         }
434         
435         connect( this, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
436         myPreviewPrs = new HYDROGUI_ShapeLandCoverMap( module()->getOCCDisplayer(), aCtx, myEditedObject, getPreviewZLayer()/*, theIsScalarMapMode*/ );
437       }
438     }
439   }
440
441   if ( aViewManager && myPreviewPrs && !myEditedObject.IsNull() )
442   {
443     TopoDS_Shape aLandCoverMapShape = myEditedObject->GetShape();
444     if( !aLandCoverMapShape.IsNull() )
445     {
446       if ( myOperationId == RemoveLandCoverId ||
447            myOperationId == MergeLandCoverId ||
448            myOperationId == ChangeLandCoverTypeId )
449         myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) ); 
450       myPreviewPrs->setShape( aLandCoverMapShape );      
451     }
452   }
453   
454   module()->update( UF_OCCViewer | UF_FitAll );
455
456   QApplication::restoreOverrideCursor();  
457 }
458
459 void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged()
460 {
461   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
462   if ( !aPanel )
463     return;
464
465   Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
466   if ( !aCtx.IsNull() )
467   {
468     int aNbSelected = aCtx->NbSelected();
469
470     if ( myOperationId == RemoveLandCoverId || myOperationId == ChangeLandCoverTypeId )
471       // Enable Apply, Apply and Close buttons only if at least one face (land cover) is selected in the 3d viewer
472       aPanel->setApplyEnabled( aNbSelected > 0 );
473     else if ( myOperationId == MergeLandCoverId )
474       // Enable Apply, Apply and Close buttons only if at least two faces (land covers) are selected in the 3d viewer
475       aPanel->setApplyEnabled( aNbSelected > 1 );
476
477     if ( myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
478     {
479       if ( aNbSelected == 1 && !myEditedObject.IsNull() )
480       {
481         TopTools_ListOfShape aFacesSelectedInViewer;
482         getSelectedShapes( aFacesSelectedInViewer, aCtx );
483         if ( aFacesSelectedInViewer.Extent() == 1 )
484         {
485           QString aType = myEditedObject->StricklerType( TopoDS::Face( aFacesSelectedInViewer.First() ) );
486           if ( !aType.isEmpty() )
487             aPanel->setSelectedStricklerTypeName( aType );
488         }
489       }
490     }
491   }
492 }
493
494 void HYDROGUI_LandCoverMapOp::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
495 {
496   myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
497 }
498
499 void HYDROGUI_LandCoverMapOp::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
500 {
501   if (theEvent->button() != Qt::LeftButton) return;
502   if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
503
504   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
505   if (!aView )
506     return;
507
508   OCCViewer_ViewManager* aViewManager = getPreviewManager();
509   if ( !aViewManager )
510     return;
511   
512   OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer();
513   if ( !aViewer )
514     return;
515
516   Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
517   if ( aCtx.IsNull() )
518     return;
519
520   myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
521
522   if (myStartPnt == myEndPnt)
523   {
524     if ( !aViewer->isPreselectionEnabled() ) {
525       Handle(V3d_View) aView3d = aView->getViewPort()->getView();
526       if ( !aView3d.IsNull() ) {
527         aCtx->MoveTo(myEndPnt.x(), myEndPnt.y(), aView3d);
528       }
529     }
530
531     Handle(StdSelect_ViewerSelector3d) aMainSelector = aCtx->MainSelector();
532     if ( aMainSelector.IsNull() )
533       return;
534     const Standard_Integer aDetectedNb = aMainSelector->NbPicked();
535     if ( aDetectedNb == 0 )
536     {
537       aCtx->ClearSelected( false );
538       emit deselection();
539     }
540
541     for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
542     {
543       Handle(SelectMgr_EntityOwner) anOwner = aMainSelector->Picked (aDetIter);
544       aCtx->AddOrRemoveSelected( anOwner, Standard_False );
545     }
546   }
547   else
548   {
549     aCtx->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
550                       myEndPnt.x(), myEndPnt.y(),
551                       aView->getViewPort()->getView(), Standard_False );
552   }
553
554   aCtx->UpdateCurrentViewer();
555   emit selectionChanged();  
556 }
557
558 void HYDROGUI_LandCoverMapOp::closePreview()
559 {
560   if( myPreviewPrs )
561   {
562     delete myPreviewPrs;
563     myPreviewPrs = 0;
564   }
565
566   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
567   if ( !aPanel )
568     return;
569
570   if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
571     aPanel->setApplyEnabled( false );
572
573   OCCViewer_ViewManager* aViewManager = getPreviewManager();
574   if ( aViewManager )
575   {
576     if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
577     {
578       disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
579         this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
580       disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
581         this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
582       connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
583         aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
584       connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
585         aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));  
586
587       LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
588       if( aSelectionMgr )
589       {
590         QList<SUIT_Selector*> aSelectorList;
591         aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
592         QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
593         for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
594         {
595           HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
596           if ( aHydroSelector )
597           {
598             disconnect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
599             connect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );            
600           }
601         }
602       }
603     }
604   }
605 }
606
607 Handle(AIS_InteractiveContext) HYDROGUI_LandCoverMapOp::getInteractiveContext()
608 {
609   OCCViewer_ViewManager* aViewManager = getPreviewManager();
610   Handle(AIS_InteractiveContext) aCtx = NULL;
611   if ( aViewManager ) {
612     if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
613       aCtx = aViewer->getAISContext();
614     }
615   }
616   return aCtx;
617 }
618
619 void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelectedShapes,
620                                                  Handle(AIS_InteractiveContext)& theCtx )
621 {
622   if ( theCtx.IsNull() )
623     theCtx = getInteractiveContext();
624
625   if ( !theCtx.IsNull() && theCtx->NbSelected() > 0 )
626   {
627     for ( theCtx->InitSelected(); theCtx->MoreSelected(); theCtx->NextSelected() )
628     {
629       TopoDS_Shape aSelectedShape = theCtx->SelectedShape();
630       if ( aSelectedShape.IsNull() )
631         continue;
632
633       theSelectedShapes.Append( aSelectedShape );
634     }
635   }
636 }