Salome HOME
Doubled update of preview corrected.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImmersibleZoneDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_ImmersibleZoneDlg.h"
24
25 #include "HYDROGUI_ColorWidget.h"
26 #include "HYDROGUI_Tool.h"
27
28 #include <QComboBox>
29 #include <QGroupBox>
30 #include <QLabel>
31 #include <QLayout>
32 #include <QLineEdit>
33 #include <QListWidget>
34 #include <QRadioButton>
35
36 HYDROGUI_ImmersibleZoneDlg::HYDROGUI_ImmersibleZoneDlg( HYDROGUI_Module* theModule, const QString& theTitle )
37 : HYDROGUI_InputPanel( theModule, theTitle )
38 {
39   // Zone name
40   myObjectNameGroup = new QGroupBox( tr( "ZONE_NAME" ), mainFrame() );
41
42   myObjectName = new QLineEdit( myObjectNameGroup );
43
44   QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
45   aNameLayout->setMargin( 5 );
46   aNameLayout->setSpacing( 5 );
47   aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
48   aNameLayout->addWidget( myObjectName );
49
50
51   QGroupBox* aParamGroup = new QGroupBox( tr( "ZONE_PARAMETERS" ), mainFrame() );
52
53   QFrame* aPolylineFrame = new QFrame( aParamGroup );
54
55   myPolylines = new QComboBox( aPolylineFrame );
56   myPolylines->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
57
58   QBoxLayout* aPolyLayout = new QHBoxLayout( aPolylineFrame );
59   aPolyLayout->setMargin( 0 );
60   aPolyLayout->setSpacing( 5 );
61   aPolyLayout->addWidget( new QLabel( tr( "ZONE_POLYLINE" ), aPolylineFrame ) );
62   aPolyLayout->addWidget( myPolylines );
63
64
65   QFrame* aFillingFrame = new QFrame( aParamGroup );
66   QLabel* aFillingLabel = new QLabel( tr( "FILLING_COLOR" ), aFillingFrame );
67   myFillingTransparent = new QRadioButton( tr( "TRANSPARENT" ), aFillingFrame );
68   myFillingTransparent->setChecked( true );
69   myFillingColor = new QRadioButton( tr( "COLOR" ), aFillingFrame );
70   myFillingColorBox = new HYDROGUI_ColorWidget( aFillingFrame );
71
72   QGridLayout* aFillingLayout = new QGridLayout( aFillingFrame );
73   aFillingLayout->setMargin( 0 );
74   aFillingLayout->setSpacing( 5 );
75   aFillingLayout->addWidget( aFillingLabel, 0, 0, 2, 1 );
76   aFillingLayout->addWidget( myFillingTransparent, 0, 1 );
77   aFillingLayout->addWidget( myFillingColor,       1, 1 );
78   aFillingLayout->addWidget( myFillingColorBox,    1, 2 );
79
80
81   myBorderColorGroup = new QGroupBox( tr( "BORDER_COLOR" ), mainFrame() );
82   myBorderColorGroup->setCheckable( true );
83
84   myBorderColorBox = new HYDROGUI_ColorWidget( myBorderColorGroup );
85
86   QBoxLayout* aBorderColorLayout = new QHBoxLayout( myBorderColorGroup );
87   aBorderColorLayout->setMargin( 5 );
88   aBorderColorLayout->setSpacing( 5 );
89   aBorderColorLayout->addWidget( new QLabel( tr( "COLOR" ), myBorderColorGroup ) );
90   aBorderColorLayout->addWidget( myBorderColorBox );
91
92
93   QBoxLayout* aParamLayout = new QVBoxLayout( aParamGroup );
94   aParamLayout->setMargin( 5 );
95   aParamLayout->setSpacing( 5 );
96   aParamLayout->addWidget( aPolylineFrame );
97   aParamLayout->addWidget( aFillingFrame );
98   aParamLayout->addWidget( myBorderColorGroup );
99
100
101   QGroupBox* aBathGroup = new QGroupBox( tr( "ZONE_BATHYMETRY" ), mainFrame() );
102
103   myBathymetries = new QComboBox( aPolylineFrame );
104   myBathymetries->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
105
106   QBoxLayout* aBathLayout = new QHBoxLayout( aBathGroup );
107   aBathLayout->setMargin( 5 );
108   aBathLayout->setSpacing( 5 );
109   aBathLayout->addWidget( myBathymetries );
110
111
112   // Common
113   addWidget( myObjectNameGroup );
114   addWidget( aParamGroup );
115   addWidget( aBathGroup );
116
117   addStretch();
118
119
120   // Connect signals and slots
121   connect( myPolylines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onZoneDefChanged() ) );
122   connect( myFillingTransparent, SIGNAL( toggled( bool ) ), this, SLOT( onFillingColorChanged( const bool ) ) );
123   connect( myFillingColor, SIGNAL( toggled( bool ) ), this, SLOT( onFillingColorChanged( const bool ) ) );
124   connect( myFillingColorBox, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( onFillingColorChanged() ) );
125   connect( myBorderColorGroup, SIGNAL( toggled( bool ) ), this, SLOT( onZoneDefChanged() ) );
126   connect( myBorderColorBox, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( onZoneDefChanged() ) );
127 }
128
129 HYDROGUI_ImmersibleZoneDlg::~HYDROGUI_ImmersibleZoneDlg()
130 {
131 }
132
133 void HYDROGUI_ImmersibleZoneDlg::reset()
134 {
135   bool isBlocked = blockSignals( true );
136
137   myObjectName->clear();
138
139   myPolylines->clear();
140   myBathymetries->clear();
141
142   myFillingTransparent->setChecked( true );
143   myFillingColorBox->resetColor();
144
145   myBorderColorGroup->setChecked( false );
146   myBorderColorBox->resetColor();
147
148   blockSignals( isBlocked );
149
150   onZoneDefChanged();
151 }
152
153 void HYDROGUI_ImmersibleZoneDlg::setObjectName( const QString& theName )
154 {
155   myObjectName->setText( theName );
156 }
157
158 QString HYDROGUI_ImmersibleZoneDlg::getObjectName() const
159 {
160   return myObjectName->text();
161 }
162
163 void HYDROGUI_ImmersibleZoneDlg::setPolylineNames( const QStringList& thePolylines )
164 {
165   bool isBlocked = blockSignals( true );
166
167   myPolylines->clear();
168   myPolylines->addItems( thePolylines );
169
170   blockSignals( isBlocked );
171 }
172
173 void HYDROGUI_ImmersibleZoneDlg::setPolylineName( const QString& theName )
174 {
175   int aNewIdx = myPolylines->findText( theName );
176   if ( aNewIdx != myPolylines->currentIndex() )
177   {
178     myPolylines->setCurrentIndex( aNewIdx );
179   }
180   else
181   {
182     onZoneDefChanged();
183   }
184 }
185
186 QString HYDROGUI_ImmersibleZoneDlg::getPolylineName() const
187 {
188   return myPolylines->currentText();
189 }
190
191 void HYDROGUI_ImmersibleZoneDlg::setBathymetryNames( const QStringList& theBathymetries )
192 {
193   bool isBlocked = blockSignals( true );
194
195   myBathymetries->clear();
196   myBathymetries->addItems( theBathymetries );
197
198   blockSignals( isBlocked );
199 }
200
201 void HYDROGUI_ImmersibleZoneDlg::setBathymetryName( const QString& theName )
202 {
203   int aNewIdx = myBathymetries->findText( theName );
204   myBathymetries->setCurrentIndex( aNewIdx );
205 }
206
207 QString HYDROGUI_ImmersibleZoneDlg::getBathymetryName() const
208 {
209   return myBathymetries->currentText();
210 }
211
212 void HYDROGUI_ImmersibleZoneDlg::setFillingColor( const QColor& theColor )
213 {
214   bool isBlocked = blockSignals( true );
215
216   if( theColor.alpha() == 0 ) // transparent
217     myFillingTransparent->setChecked( true );
218   else
219     myFillingColor->setChecked( true );
220
221   myFillingColorBox->setColor( theColor );
222
223   blockSignals( isBlocked );
224
225   onZoneDefChanged();
226 }
227
228 QColor HYDROGUI_ImmersibleZoneDlg::getFillingColor() const
229 {
230   QColor aColor( 255, 255, 255, 0 ); // transparent
231   if( myFillingColor->isChecked() )
232     aColor = myFillingColorBox->color();
233   return aColor;
234 }
235
236 void HYDROGUI_ImmersibleZoneDlg::setBorderColor( const QColor& theColor )
237 {
238   bool isBlocked = blockSignals( true );
239
240   bool isTransparent = theColor.alpha() == 0;
241   myBorderColorGroup->setChecked( !isTransparent );
242   myBorderColorBox->setColor( !isTransparent ? theColor : QColor( Qt::black ) );
243
244   blockSignals( isBlocked );
245
246   onZoneDefChanged();
247 }
248
249 QColor HYDROGUI_ImmersibleZoneDlg::getBorderColor() const
250 {
251   QColor aColor( Qt::transparent ); // transparent
252   if( myBorderColorGroup->isChecked() )
253     aColor = myBorderColorBox->color();
254   return aColor;
255 }
256
257 void HYDROGUI_ImmersibleZoneDlg::onFillingColorChanged()
258 {
259   if ( !myFillingColor->isChecked() )
260     return;
261
262   onZoneDefChanged();
263 }
264
265 void HYDROGUI_ImmersibleZoneDlg::onFillingColorChanged( const bool theIsChecked )
266 {
267   if ( !theIsChecked )
268     return;
269
270   onZoneDefChanged();
271 }
272
273 void HYDROGUI_ImmersibleZoneDlg::onZoneDefChanged()
274 {
275   if ( signalsBlocked() )
276     return;
277
278   QString aPolylineName = getPolylineName();
279   emit CreatePreview( aPolylineName );
280 }
281
282