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.
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.
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
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
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>
30 #include <QApplication>
33 #include <LightApp_SelectionMgr.h>
36 #include "HYDRO_trace.hxx"
38 HYDROGUI_BathymetrySelectionOp::HYDROGUI_BathymetrySelectionOp( HYDROGUI_Module* theModule )
39 : HYDROGUI_Operation( theModule ), myIsActive( false )
41 DEBTRACE("HYDROGUI_BathymetrySelectionOp");
44 HYDROGUI_BathymetrySelectionOp::~HYDROGUI_BathymetrySelectionOp()
48 void HYDROGUI_BathymetrySelectionOp::startOperation()
50 DEBTRACE("startOperation");
51 activateSelection( true );
54 void HYDROGUI_BathymetrySelectionOp::abortOperation()
56 DEBTRACE("abortOperation");
57 activateSelection( false );
59 module()->action( BathymetrySelectionId )->setChecked( false );
60 module()->action( BathymetryTextId )->setChecked( false );
63 bool HYDROGUI_BathymetrySelectionOp::isValid( SUIT_Operation* theOtherOp ) const
66 HYDROGUI_BathymetryOp* aBathOp = dynamic_cast<HYDROGUI_BathymetryOp*>( theOtherOp );
67 return ( aBathOp != 0 );
70 OCCViewer_Viewer* getViewer( HYDROGUI_Module* theModule )
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();
78 Handle(AIS_InteractiveContext) getContext( HYDROGUI_Module* theModule )
80 return getViewer( theModule )->getAISContext();
83 QList<Handle(HYDROGUI_BathymetryPrs)> getShownBathymetries( HYDROGUI_Module* theModule )
85 QList<Handle(HYDROGUI_BathymetryPrs)> baths;
86 Handle(AIS_InteractiveContext) ctx = getContext( theModule );
88 AIS_ListOfInteractive objs;
89 ctx->DisplayedObjects( objs );
90 AIS_ListIteratorOfListOfInteractive it( objs );
91 for( ; it.More(); it.Next() )
93 Handle(HYDROGUI_BathymetryPrs) bath = Handle(HYDROGUI_BathymetryPrs)::DownCast( it.Value() );
100 void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive )
102 DEBTRACE("activateSelection " << isActive);
103 if( myIsActive==isActive )
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() );
113 const int aSelectionMode = 1; // Cf. AIS_PointCloud 0=selection by points ?
114 foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
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...
122 ctx->UpdateCurrentViewer();
126 foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
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);
137 myIsActive = isActive;
139 qApp->restoreOverrideCursor();