Salome HOME
refs #1327: implementation of the scaling operations
[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 <HYDROGUI_BathymetryOp.h>
24 #include <OCCViewer_ViewManager.h>
25 #include <LightApp_Application.h>
26
27 HYDROGUI_BathymetrySelectionOp::HYDROGUI_BathymetrySelectionOp( HYDROGUI_Module* theModule )
28 : HYDROGUI_Operation( theModule ), myIsActive( false )
29 {
30 }
31
32 HYDROGUI_BathymetrySelectionOp::~HYDROGUI_BathymetrySelectionOp()
33 {
34 }
35
36 void HYDROGUI_BathymetrySelectionOp::startOperation()
37 {
38   activateSelection( true );
39 }
40
41 void HYDROGUI_BathymetrySelectionOp::abortOperation()
42 {
43   activateSelection( false );
44 }
45
46 bool HYDROGUI_BathymetrySelectionOp::isValid( SUIT_Operation* theOtherOp ) const
47 {
48   HYDROGUI_BathymetryOp* aBathOp = dynamic_cast<HYDROGUI_BathymetryOp*>( theOtherOp );
49   return ( aBathOp != 0 );
50 }
51
52 Handle(AIS_InteractiveContext) getContext( HYDROGUI_Module* theModule )
53 {
54   LightApp_Application* app = theModule->getApp();
55   OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>
56     ( app->getViewManager( OCCViewer_Viewer::Type(), true ) );
57   Handle(AIS_InteractiveContext) ctx = mgr->getOCCViewer()->getAISContext();
58   return ctx;
59 }
60
61 QList<Handle(HYDROGUI_BathymetryPrs)> getShownBathymetries( HYDROGUI_Module* theModule )
62 {
63   QList<Handle(HYDROGUI_BathymetryPrs)> baths;
64   Handle(AIS_InteractiveContext) ctx = getContext( theModule );
65
66   AIS_ListOfInteractive objs;
67   ctx->DisplayedObjects( objs );
68   AIS_ListIteratorOfListOfInteractive it( objs );
69   for( ; it.More(); it.Next() )
70   {
71     Handle(HYDROGUI_BathymetryPrs) bath = Handle(HYDROGUI_BathymetryPrs)::DownCast( it.Value() );
72     if( !bath.IsNull() )
73       baths.append( bath );
74   }
75   return baths;
76 }
77
78 void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive )
79 {
80   if( myIsActive==isActive )
81     return;
82
83   Handle(AIS_InteractiveContext) ctx = getContext( module() );
84   QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
85   if( isActive )
86   {
87     const int aSelectionMode = 1;
88     ctx->OpenLocalContext( Standard_True );
89     foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
90     {
91       ctx->Activate( bath, aSelectionMode, Standard_True );
92       bath->SetAutoHilight( Standard_False );
93     }
94     ctx->UpdateCurrentViewer();
95   }
96   else
97   {
98     foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
99     {
100       bath->ClearSelected();
101       bath->SetAutoHilight( Standard_True );
102       ctx->Deactivate( bath );
103     }
104     ctx->CloseLocalContext( -1, Standard_True );
105   }
106
107   myIsActive = isActive;
108 }