Salome HOME
cleaning some comments
[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 <HYDROGUI_Operations.h>
26 #include <OCCViewer_ViewManager.h>
27 #include <LightApp_Application.h>
28 #include <SUIT_Selector.h>
29 #include <QAction>
30 #include <QApplication>
31 #include <QString>
32 #include <QList>
33 #include <LightApp_SelectionMgr.h>
34
35 //#define _DEVDEBUG_
36 #include "HYDRO_trace.hxx"
37
38 HYDROGUI_BathymetrySelectionOp::HYDROGUI_BathymetrySelectionOp( HYDROGUI_Module* theModule )
39 : HYDROGUI_Operation( theModule ), myIsActive( false )
40 {
41   DEBTRACE("HYDROGUI_BathymetrySelectionOp");
42 }
43
44 HYDROGUI_BathymetrySelectionOp::~HYDROGUI_BathymetrySelectionOp()
45 {
46 }
47
48 void HYDROGUI_BathymetrySelectionOp::startOperation()
49 {
50   DEBTRACE("startOperation");
51   activateSelection( true );
52 }
53
54 void HYDROGUI_BathymetrySelectionOp::abortOperation()
55 {
56   DEBTRACE("abortOperation");
57   activateSelection( false );
58
59   module()->action( BathymetrySelectionId )->setChecked( false );
60   module()->action( BathymetryTextId )->setChecked( false );
61 }
62
63 bool HYDROGUI_BathymetrySelectionOp::isValid( SUIT_Operation* theOtherOp ) const
64 {
65   DEBTRACE("isValid");
66   HYDROGUI_BathymetryOp* aBathOp = dynamic_cast<HYDROGUI_BathymetryOp*>( theOtherOp );
67   return ( aBathOp != 0 );
68 }
69
70 OCCViewer_Viewer* getViewer( HYDROGUI_Module* theModule )
71 {
72   LightApp_Application* app = theModule->getApp();
73   OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>
74     ( app->getViewManager( OCCViewer_Viewer::Type(), true ) );
75   return mgr->getOCCViewer();
76 }
77
78 Handle(AIS_InteractiveContext) getContext( HYDROGUI_Module* theModule )
79 {
80   return getViewer( theModule )->getAISContext();
81 }
82
83 QList<Handle(HYDROGUI_BathymetryPrs)> getShownBathymetries( HYDROGUI_Module* theModule )
84 {
85   QList<Handle(HYDROGUI_BathymetryPrs)> baths;
86   Handle(AIS_InteractiveContext) ctx = getContext( theModule );
87
88   AIS_ListOfInteractive objs;
89   ctx->DisplayedObjects( objs );
90   AIS_ListIteratorOfListOfInteractive it( objs );
91   for( ; it.More(); it.Next() )
92   {
93     Handle(HYDROGUI_BathymetryPrs) bath = Handle(HYDROGUI_BathymetryPrs)::DownCast( it.Value() );
94     if( !bath.IsNull() )
95       baths.append( bath );
96   }
97   return baths;
98 }
99
100 void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive )
101 {
102   DEBTRACE("activateSelection " << isActive);
103   if( myIsActive==isActive )
104     return;
105
106   getContext( module() )->ClearSelected(true);
107   qApp->setOverrideCursor( Qt::WaitCursor );
108   getContext( module() )->ClearSelected(true);
109   Handle(AIS_InteractiveContext) ctx = getContext( module() );
110   QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
111   if( isActive )
112   {
113     const int aSelectionMode = 1;  // Cf. AIS_PointCloud 0=selection by points ?
114     foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
115     {
116       DEBTRACE("bathy name: " << bath->GetShape()->getObject()->GetName().toStdString());
117       ctx->Deactivate(bath);
118       ctx->RemoveFilters();
119       ctx->SetSelectionModeActive (bath, aSelectionMode, Standard_True, AIS_SelectionModesConcurrency_Multiple, Standard_False);
120       bath->SetAutoHilight( Standard_False ); // True bloque le passage dans hilightSelected...
121     }
122     ctx->UpdateCurrentViewer();
123   }
124   else
125   {
126     foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
127     {
128       bath->ClearSelected();
129       bath->ClearSelectedPoints();
130       bath->SetAutoHilight( Standard_True );
131       bath->GetShape()->TextLabels( false );
132       ctx->Deactivate( bath );
133       ctx->SetSelectionModeActive (bath, 2, Standard_True, AIS_SelectionModesConcurrency_Multiple, Standard_False);
134     }
135   }
136
137   myIsActive = isActive;
138
139   qApp->restoreOverrideCursor();
140 }