Salome HOME
refs #1326: debug of the selection on bathymetry
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_BathymetrySelectionOp.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 //See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <HYDROGUI_BathymetrySelectionOp.h>
21 #include <HYDROGUI_Module.h>
22 #include <HYDROGUI_BathymetryPrs.h>
23 #include <OCCViewer_ViewManager.h>
24 #include <LightApp_Application.h>
25
26 HYDROGUI_BathymetrySelectionOp::HYDROGUI_BathymetrySelectionOp( HYDROGUI_Module* theModule )
27 : HYDROGUI_Operation( theModule ), myIsActive( false )
28 {
29 }
30
31 HYDROGUI_BathymetrySelectionOp::~HYDROGUI_BathymetrySelectionOp()
32 {
33 }
34
35 void HYDROGUI_BathymetrySelectionOp::startOperation()
36 {
37   activateSelection( true );
38 }
39
40 void HYDROGUI_BathymetrySelectionOp::abortOperation()
41 {
42   activateSelection( false );
43 }
44
45 void HYDROGUI_BathymetrySelectionOp::commitOperation()
46 {
47   activateSelection( false );
48 }
49
50 void HYDROGUI_BathymetrySelectionOp::stopOperation()
51 {
52   activateSelection( false );
53 }
54
55 void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive )
56 {
57   if( myIsActive==isActive )
58     return;
59
60   LightApp_Application* app = module()->getApp();
61   OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>
62     ( app->getViewManager( OCCViewer_Viewer::Type(), true ) );
63   Handle(AIS_InteractiveContext) ctx = mgr->getOCCViewer()->getAISContext();
64
65
66   QList<Handle(HYDROGUI_BathymetryPrs)> baths;
67
68   AIS_ListOfInteractive objs;
69   ctx->DisplayedObjects( objs );
70   AIS_ListIteratorOfListOfInteractive it( objs );
71   for( ; it.More(); it.Next() )
72   {
73     Handle(HYDROGUI_BathymetryPrs) bath = Handle(HYDROGUI_BathymetryPrs)::DownCast( it.Value() );
74     if( !bath.IsNull() )
75       baths.append( bath );
76   }
77
78   if( isActive )
79   {
80     const int aSelectionMode = 1;
81     ctx->OpenLocalContext( Standard_True );
82     foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
83       ctx->Activate( bath, aSelectionMode, Standard_True );
84     ctx->UpdateCurrentViewer();
85   }
86   else
87   {
88     foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
89     {
90       bath->ClearSelected();
91       ctx->Deactivate( bath );
92     }
93     ctx->CloseLocalContext( -1, Standard_True );
94   }
95
96   myIsActive = isActive;
97 }