Salome HOME
merge master 2015/06/04
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImmersibleZoneDlg.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 //
18
19 #include "HYDROGUI_ImmersibleZoneDlg.h"
20
21 #include "HYDROGUI_Tool.h"
22
23 #include <QComboBox>
24 #include <QGroupBox>
25 #include <QLabel>
26 #include <QLayout>
27 #include <QLineEdit>
28
29 HYDROGUI_ImmersibleZoneDlg::HYDROGUI_ImmersibleZoneDlg( HYDROGUI_Module* theModule, const QString& theTitle )
30 : HYDROGUI_InputPanel( theModule, theTitle )
31 {
32   // Zone name
33   myObjectNameGroup = new QGroupBox( tr( "ZONE_NAME" ), mainFrame() );
34
35   myObjectName = new QLineEdit( myObjectNameGroup );
36
37   QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
38   aNameLayout->setMargin( 5 );
39   aNameLayout->setSpacing( 5 );
40   aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
41   aNameLayout->addWidget( myObjectName );
42
43
44   QGroupBox* aParamGroup = new QGroupBox( tr( "ZONE_PARAMETERS" ), mainFrame() );
45
46   QFrame* aPolylineFrame = new QFrame( aParamGroup );
47
48   myPolylines = new QComboBox( aPolylineFrame );
49   myPolylines->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
50
51   QBoxLayout* aPolyLayout = new QHBoxLayout( aPolylineFrame );
52   aPolyLayout->setMargin( 0 );
53   aPolyLayout->setSpacing( 5 );
54   aPolyLayout->addWidget( new QLabel( tr( "ZONE_POLYLINE" ), aPolylineFrame ) );
55   aPolyLayout->addWidget( myPolylines );
56   
57   QBoxLayout* aParamLayout = new QVBoxLayout( aParamGroup );
58   aParamLayout->setMargin( 5 );
59   aParamLayout->setSpacing( 5 );
60   aParamLayout->addWidget( aPolylineFrame );
61
62   QGroupBox* aBathGroup = new QGroupBox( tr( "ZONE_BATHYMETRY" ), mainFrame() );
63
64   myBathymetries = new QComboBox( aPolylineFrame );
65   myBathymetries->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
66
67   QBoxLayout* aBathLayout = new QHBoxLayout( aBathGroup );
68   aBathLayout->setMargin( 5 );
69   aBathLayout->setSpacing( 5 );
70   aBathLayout->addWidget( myBathymetries );
71
72
73   // Common
74   addWidget( myObjectNameGroup );
75   addWidget( aParamGroup );
76   addWidget( aBathGroup );
77
78   addStretch();
79
80
81   // Connect signals and slots
82   connect( myPolylines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onZoneDefChanged() ) );
83 }
84
85 HYDROGUI_ImmersibleZoneDlg::~HYDROGUI_ImmersibleZoneDlg()
86 {
87 }
88
89 void HYDROGUI_ImmersibleZoneDlg::reset()
90 {
91   bool isBlocked = blockSignals( true );
92
93   myObjectName->clear();
94
95   myPolylines->clear();
96   myBathymetries->clear();
97
98   blockSignals( isBlocked );
99
100   onZoneDefChanged();
101 }
102
103 void HYDROGUI_ImmersibleZoneDlg::setObjectName( const QString& theName )
104 {
105   myObjectName->setText( theName );
106 }
107
108 QString HYDROGUI_ImmersibleZoneDlg::getObjectName() const
109 {
110   return myObjectName->text();
111 }
112
113 void HYDROGUI_ImmersibleZoneDlg::setPolylineNames( const QStringList& thePolylines )
114 {
115   bool isBlocked = blockSignals( true );
116
117   myPolylines->clear();
118   myPolylines->addItems( thePolylines );
119
120   blockSignals( isBlocked );
121 }
122
123 void HYDROGUI_ImmersibleZoneDlg::setPolylineName( const QString& theName )
124 {
125   int aNewIdx = myPolylines->findText( theName );
126   if ( aNewIdx != myPolylines->currentIndex() )
127   {
128     myPolylines->setCurrentIndex( aNewIdx );
129   }
130   else
131   {
132     onZoneDefChanged();
133   }
134 }
135
136 QString HYDROGUI_ImmersibleZoneDlg::getPolylineName() const
137 {
138   return myPolylines->currentText();
139 }
140
141 void HYDROGUI_ImmersibleZoneDlg::setBathymetryNames( const QStringList& theBathymetries )
142 {
143   bool isBlocked = blockSignals( true );
144
145   myBathymetries->clear();
146   myBathymetries->addItems( theBathymetries );
147
148   blockSignals( isBlocked );
149 }
150
151 void HYDROGUI_ImmersibleZoneDlg::setBathymetryName( const QString& theName )
152 {
153   int aNewIdx = myBathymetries->findText( theName );
154   myBathymetries->setCurrentIndex( aNewIdx );
155 }
156
157 QString HYDROGUI_ImmersibleZoneDlg::getBathymetryName() const
158 {
159   return myBathymetries->currentText();
160 }
161
162 void HYDROGUI_ImmersibleZoneDlg::onZoneDefChanged()
163 {
164   if ( signalsBlocked() )
165     return;
166
167   QString aPolylineName = getPolylineName();
168   emit CreatePreview( aPolylineName );
169 }