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_BathymetryOp.h>
21 #include <HYDROGUI_Operations.h>
22 #include <HYDROGUI_BathymetryPrs.h>
23 #include <HYDROGUI_ShapeBathymetry.h>
24 #include <HYDROGUI_Module.h>
25 #include <HYDROGUI_OCCDisplayer.h>
26 #include <LightApp_Application.h>
27 #include <OCCViewer_ViewManager.h>
28 #include <OCCViewer_ViewWindow.h>
29 #include <QtxDoubleSpinBox.h>
30 #include <SUIT_Desktop.h>
31 #include <SUIT_SelectionMgr.h>
33 #include <QPushButton>
34 #include <QApplication>
37 #include "HYDRO_trace.hxx"
39 HYDROGUI_BathymetryLimitsDlg::HYDROGUI_BathymetryLimitsDlg( QWidget* theParent )
40 : QDialog( theParent )
42 QGridLayout* layout = new QGridLayout();
45 layout->addWidget( new QLabel( tr( "Min value" ) ), 0, 0 );
46 layout->addWidget( new QLabel( tr( "Max value" ) ), 1, 0 );
48 myMin = new QtxDoubleSpinBox( this );
49 myMin->setRange( -1000, 1000 );
50 myMax = new QtxDoubleSpinBox( this );
51 myMax->setRange( -1000, 1000 );
53 layout->addWidget( myMin, 0, 1 );
54 layout->addWidget( myMax, 1, 1 );
56 QFrame* aBtnFrame = new QFrame( this );
57 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnFrame );
58 layout->addWidget( aBtnFrame, 2, 0, 1, 2 );
60 QPushButton* ok = new QPushButton( tr( "OK" ), this );
61 QPushButton* cancel = new QPushButton( tr( "Cancel" ), this );
62 aBtnLayout->addWidget( ok );
63 aBtnLayout->addWidget( cancel );
65 connect( ok, SIGNAL( clicked() ), this, SLOT( accept() ) );
66 connect( cancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
69 HYDROGUI_BathymetryLimitsDlg::~HYDROGUI_BathymetryLimitsDlg()
73 double HYDROGUI_BathymetryLimitsDlg::GetMin() const
75 return myMin->value();
78 double HYDROGUI_BathymetryLimitsDlg::GetMax() const
80 return myMax->value();
83 void HYDROGUI_BathymetryLimitsDlg::SetMinMax( double theMin, double theMax )
85 myMin->setValue( theMin );
86 myMax->setValue( theMax );
93 HYDROGUI_BathymetryOp::HYDROGUI_BathymetryOp( HYDROGUI_Module* theModule, int theMode )
94 : HYDROGUI_Operation( theModule ), myMode( theMode ), myIsActivate( false )
98 HYDROGUI_BathymetryOp::~HYDROGUI_BathymetryOp()
102 OCCViewer_Viewer* getViewer( HYDROGUI_Module* theModule );
103 Handle(AIS_InteractiveContext) getContext( HYDROGUI_Module* theModule );
104 QList<Handle(HYDROGUI_BathymetryPrs)> getShownBathymetries( HYDROGUI_Module* theModule );
106 void HYDROGUI_BathymetryOp::startOperation()
111 void HYDROGUI_BathymetryOp::commitOperation()
113 //if( myMode!=BathymetryTextId )
117 void HYDROGUI_BathymetryOp::abortOperation()
122 OCCViewer_ViewWindow* HYDROGUI_BathymetryOp::activeViewWindow() const
124 LightApp_Application* app = module()->getApp();
125 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>
126 ( app->getViewManager( OCCViewer_Viewer::Type(), true ) );
127 return dynamic_cast<OCCViewer_ViewWindow*>( mgr->getActiveView() );
130 void HYDROGUI_BathymetryOp::activate( bool isActivate )
132 DEBTRACE("activate " << isActivate);
133 if( myIsActivate==isActivate )
136 myIsActivate = isActivate;
137 QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
138 bool isUpdateCS = false;
140 if( myMode!=BathymetryRescaleUserId )
141 qApp->setOverrideCursor( Qt::WaitCursor );
145 case BathymetryTextId:
147 foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
148 bath->GetShape()->TextLabels( isActivate, bath==baths.last() );
151 connect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
153 disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
157 case BathymetryRescaleSelectionId:
161 foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
162 bath->GetShape()->RescaleBySelection();
169 case BathymetryRescaleVisibleId:
173 foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
174 bath->GetShape()->RescaleByVisible( activeViewWindow() );
181 case BathymetryRescaleUserId:
185 double min=0, max=0, lmin=0, lmax=0;
187 foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
189 bath->GetShape()->GetRange( lmin, lmax );
190 if( first || lmin < min )
192 if( first || lmax > max )
197 HYDROGUI_BathymetryLimitsDlg dlg( module()->getApp()->desktop() );
198 dlg.SetMinMax( min, max );
199 if( dlg.exec()==QDialog::Accepted )
201 qApp->setOverrideCursor( Qt::WaitCursor );
205 foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
206 bath->GetShape()->Rescale( min, max );
217 case BathymetryRescaleDefaultId:
221 foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
222 bath->GetShape()->RescaleDefault();
231 module()->getOCCDisplayer()->UpdateColorScale( getViewer( module() ) );
233 qApp->restoreOverrideCursor();
236 void HYDROGUI_BathymetryOp::onSelectionChanged()
238 DEBTRACE("onSelectionChanged");
239 QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
240 bool isUpdateCS = false;
242 qApp->setOverrideCursor( Qt::WaitCursor );
243 if( myMode==BathymetryTextId )
245 foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
246 bath->GetShape()->TextLabels( true, bath==baths.last() );
249 qApp->restoreOverrideCursor();