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