Salome HOME
90869a487212396dfde99d19883baa2bdc5f00e5
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationDlg.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_CalculationDlg.h"
24
25 #include "HYDROGUI_ObjSelector.h"
26 #include "HYDROGUI_Tool.h"
27
28 #include <SUIT_FileDlg.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Session.h>
31
32 #include <QGroupBox>
33 #include <QLabel>
34 #include <QLayout>
35 #include <QLineEdit>
36 #include <QListWidget>
37 #include <QPicture>
38 #include <QPushButton>
39 #include <QToolButton>
40
41 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
42 : HYDROGUI_InputPanel( theModule, theTitle )
43 {
44   // Calculation name
45   myObjectNameGroup = new QGroupBox( tr( "CALCULATION_NAME" ), mainFrame() );
46
47   myObjectName = new QLineEdit( myObjectNameGroup );
48
49   QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
50   aNameLayout->setMargin( 5 );
51   aNameLayout->setSpacing( 5 );
52   aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
53   aNameLayout->addWidget( myObjectName );
54
55   
56   // Calculation boundary line
57   QGroupBox* aBndGroup = new QGroupBox( tr( "CALCULATION_BOUNDARY" ), mainFrame() );
58
59   myBndPolyline = new HYDROGUI_ObjSelector( theModule, KIND_POLYLINE, aBndGroup );
60
61   QBoxLayout* aBndLayout = new QHBoxLayout( aBndGroup );
62   aBndLayout->setMargin( 5 );
63   aBndLayout->setSpacing( 5 );
64   aBndLayout->addWidget( new QLabel( tr( "BOUNDARY_POLYLINE" ), aBndGroup ) );
65   aBndLayout->addWidget( myBndPolyline );
66
67
68   // Calculation zones
69   QGroupBox* aZonesGroup = new QGroupBox( tr( "CALCULATION_ZONES" ), mainFrame() );
70
71   myZones = new QListWidget( aZonesGroup );
72   myZones->setSelectionMode( QListWidget::SingleSelection );
73   myZones->setEditTriggers( QListWidget::NoEditTriggers );
74   myZones->setViewMode( QListWidget::ListMode );
75
76   mySplittedZones = new QListWidget( aZonesGroup );
77   mySplittedZones->setSelectionMode( QListWidget::SingleSelection );
78   mySplittedZones->setEditTriggers( QListWidget::NoEditTriggers );
79   mySplittedZones->setViewMode( QListWidget::ListMode );
80
81   mySplittedZonesPrefix = new QLineEdit( aZonesGroup );
82
83   QPushButton* aSplitBtn = new QPushButton( tr( "SPLIT_REFERENCE_ZONES" ), aZonesGroup );
84
85   QGridLayout* aZonesLayout = new QGridLayout( aZonesGroup );
86   aZonesLayout->setMargin( 5 );
87   aZonesLayout->setSpacing( 5 );
88   aZonesLayout->addWidget( new QLabel( tr( "CALCULATION_REFERENCE_ZONES" ), aZonesGroup ), 0, 0, 1, 2 );
89   aZonesLayout->addWidget( myZones, 1, 0, 1, 2 );
90   aZonesLayout->addWidget( new QLabel( tr( "CALCULATION_SPLITTED_ZONES" ), aZonesGroup ), 2, 0, 1, 2 );
91   aZonesLayout->addWidget( mySplittedZones, 3, 0, 1, 2 );
92   aZonesLayout->addWidget( new QLabel( tr( "PREFIX_SPLITTED_ZONES" ), aZonesGroup ), 4, 0 );
93   aZonesLayout->addWidget( mySplittedZonesPrefix, 4, 1 );
94   aZonesLayout->addWidget( aSplitBtn, 5, 0, 1, 2 );
95
96   // Common
97   addWidget( myObjectNameGroup );
98   addWidget( aBndGroup );
99   addWidget( aZonesGroup );
100   addStretch();
101
102
103   // Connect signals and slots
104   connect( aSplitBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( SplitZones() ) );
105 }
106
107 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
108 {
109 }
110
111 void HYDROGUI_CalculationDlg::reset()
112 {
113   myObjectName->clear();
114
115   myBndPolyline->Clear();
116
117   myZones->clear();
118   mySplittedZones->clear();
119
120   setSplitZonesPrefix( tr( "DEFAULT_PREFIX_SPLITTED_ZONES" ) );
121 }
122
123 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
124 {
125   myObjectName->setText( theName );
126 }
127
128 QString HYDROGUI_CalculationDlg::getObjectName() const
129 {
130   return myObjectName->text();
131 }
132
133 void HYDROGUI_CalculationDlg::setPolylineName( const QString& theName )
134 {
135   myBndPolyline->SetName( theName );
136 }
137
138 QString HYDROGUI_CalculationDlg::getPolylineName() const
139 {
140   return myBndPolyline->GetName();
141 }
142
143 void HYDROGUI_CalculationDlg::setZones( const QStringList& theZones )
144 {
145   myZones->clear();
146
147   for ( int i = 0, n = theZones.length(); i < n; ++i )
148   {
149     QString aZoneName = theZones.at( i );
150
151     QListWidgetItem* aListItem = new QListWidgetItem( aZoneName, myZones );
152     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable );
153     aListItem->setCheckState( Qt::Unchecked );
154   }
155 }
156
157 void HYDROGUI_CalculationDlg::setSelectedZones( const QStringList& theZones )
158 {
159   for ( int i = 0, n = theZones.length(); i < n; ++i )
160   {
161     QString aZoneName = theZones.at( i );
162
163     QList<QListWidgetItem *> anItems = 
164       myZones->findItems( aZoneName, Qt::MatchFixedString | Qt::MatchCaseSensitive );
165     if ( anItems.isEmpty() )
166       continue;
167
168     QListWidgetItem* aListItem = anItems.first();
169     if ( !aListItem )
170       continue;
171
172     aListItem->setCheckState( Qt::Checked );
173   }
174 }
175
176 QStringList HYDROGUI_CalculationDlg::getSelectedZones() const
177 {
178   QStringList aResList;
179
180   for ( int i = 0, n = myZones->count(); i < n; ++i )
181   {
182     QListWidgetItem* aListItem = myZones->item( i );
183     if ( !aListItem || aListItem->checkState() != Qt::Checked )
184       continue;
185
186     QString aSelZoneName = aListItem->text();
187     aResList.append( aSelZoneName );
188   }
189
190   return aResList;
191 }
192
193 void HYDROGUI_CalculationDlg::setSplittedZones( const QStringList& theZones )
194 {
195   mySplittedZones->clear();
196
197   for ( int i = 0, n = theZones.length(); i < n; ++i )
198   {
199     QString aZoneName = theZones.at( i );
200
201     QListWidgetItem* aListItem = new QListWidgetItem( aZoneName, mySplittedZones );
202     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
203   }
204 }
205
206 QStringList HYDROGUI_CalculationDlg::getSplittedZones() const
207 {
208   QStringList aResList;
209
210   for ( int i = 0, n = mySplittedZones->count(); i < n; ++i )
211   {
212     QListWidgetItem* aListItem = mySplittedZones->item( i );
213     if ( !aListItem )
214       continue;
215
216     QString aSplittedZoneName = aListItem->text();
217     aResList.append( aSplittedZoneName );
218   }
219
220   return aResList;
221 }
222
223 void HYDROGUI_CalculationDlg::setSplitZonesPrefix( const QString& theName )
224 {
225   mySplittedZonesPrefix->setText( theName );
226 }
227
228 QString HYDROGUI_CalculationDlg::getSplitZonesPrefix() const
229 {
230   QString aPrefix = mySplittedZonesPrefix->text();
231   if ( aPrefix.isEmpty() )
232     aPrefix = tr( "DEFAULT_PREFIX_SPLITTED_ZONES" );
233   return aPrefix;
234 }
235