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