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