Salome HOME
Merge branch 'BR_LAND_COVER_MAP' of ssh://git.salome-platform.org/modules/hydro into...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationDlg.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_CalculationDlg.h"
20
21 #include "HYDROGUI_ObjSelector.h"
22 #include "HYDROGUI_Tool2.h"
23 #include "HYDROGUI_DataBrowser.h"
24 #include "HYDROGUI_DataModel.h"
25 #include "HYDROGUI_ListSelector.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_DataObject.h"
28 #include "HYDROGUI_NameValidator.h"
29 #include "HYDROGUI_Region.h"
30 #include "HYDROGUI_Zone.h"
31 #include "HYDROGUI_OrderedListWidget.h"
32 #include "HYDROGUI_PriorityWidget.h"
33 #include "HYDROGUI_PriorityTableModel.h"
34
35 #include <HYDROData_Document.h>
36 #include <HYDROData_Entity.h>
37
38 #include <CAM_Application.h>
39 #include <LightApp_DataObject.h>
40
41 #include <SUIT_DataObject.h>
42 #include <SUIT_FileDlg.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_Study.h>
46
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_MessageBox.h>
51
52 #include <QButtonGroup>
53 #include <QComboBox>
54 #include <QGroupBox>
55 #include <QLabel>
56 #include <QLayout>
57 #include <QLineEdit>
58 #include <QListWidget>
59 #include <QPicture>
60 #include <QPushButton>
61 #include <QRadioButton>
62 #include <QSplitter>
63 #include <QTableWidget>
64 #include <QToolButton>
65 #include <QTreeView>
66 #include <QWizardPage>
67
68
69 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
70 : HYDROGUI_Wizard( theModule, theTitle )
71 {
72   addPage( createObjectsPage() );
73   addPage( createGroupsPage() );
74   addPage( createLandCoverMapPage() );
75   addPage( createZonesPage() );
76 }
77
78 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
79 {
80 }
81
82 void HYDROGUI_CalculationDlg::reset()
83 {
84   myObjectName->clear();
85   HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
86   myGeomObjects->setObjects(anObject2VisibleList);
87   myPolylineName->clear();
88   myLandCoverMapName->clear();
89   myStricklerTableName->clear();
90   myAvailableGeomObjects->clear();
91
92   // Activate the automatic mode
93   setMode( HYDROData_CalculationCase::AUTOMATIC );
94
95   // Reset the priority widget state
96   QList<Handle(HYDROData_Entity)> anObjects;
97   myPriorityWidget->setObjects( anObjects );
98 }
99
100 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
101   QWizardPage* aPage = new QWizardPage( mainFrame() );
102   QFrame* aFrame = new QFrame( aPage );
103
104   // Splitter
105   mySplitter = new QSplitter(Qt::Vertical);
106
107   // Top of the page
108   QWidget* aTopContainer = new QWidget;
109    
110   // calculation name
111   myObjectName = new QLineEdit( aPage );
112   myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
113   myObjectName->setValidator( myValidator );
114
115   connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) );
116   connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) );
117
118   // polyline name
119   myPolylineName = new QComboBox( aPage );
120   connect( myPolylineName, SIGNAL( activated( const QString & ) ), 
121     SIGNAL( boundarySelected( const QString & ) ) );
122
123   // names labels
124   QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
125   QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
126
127   // mode selector (auto/manual)
128   QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
129
130   QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
131   QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
132
133   myModeButtons = new QButtonGroup( mainFrame() );
134   myModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
135   myModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
136   
137   QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
138   aModeSelectorLayout->setMargin( 5 );
139   aModeSelectorLayout->setSpacing( 5 );
140   aModeSelectorLayout->addWidget( anAutoRB );
141   aModeSelectorLayout->addWidget( aManualRB );
142   aModeGroup->setLayout( aModeSelectorLayout );
143
144   // geometry objects
145   QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ) );
146   myGeomObjects = new HYDROGUI_OrderedListWidget( aPage, 16 );
147   myGeomObjects->setHiddenObjectsShown(true);
148   myGeomObjects->setVisibilityIconShown(false);
149   myGeomObjects->setContentsMargins(QMargins());
150  
151   // included geometry objects
152   QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ) );
153   myAvailableGeomObjects = new QListWidget( aPage );
154   myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
155   myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
156   myAvailableGeomObjects->setViewMode( QListWidget::ListMode );
157   myAvailableGeomObjects->setSortingEnabled( true );
158
159   // buttons
160   QFrame* aBtnsFrame = new QFrame;
161   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
162   aBtnsLayout->setMargin( 5 );
163   aBtnsLayout->setSpacing( 5 );
164   aBtnsFrame->setLayout( aBtnsLayout );
165   QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
166   QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
167
168   // fill the butons frame with two buttons
169   aBtnsLayout->addWidget( anAddBtn );
170   aBtnsLayout->addWidget( aRemoveBtn );
171   aBtnsLayout->addStretch( 1 );
172   
173   // top of the page layout
174   
175   // objects frame
176   QFrame* anObjectsFrame = new QFrame( aPage );
177   anObjectsFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
178   QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
179   anObjsLayout->setMargin( 5 );
180   anObjsLayout->setSpacing( 5 );
181   anObjectsFrame->setLayout( anObjsLayout );
182   
183   // fill the objects frame with two lists, two labels and with buttons frame
184   anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter );
185   anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
186   anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0 );
187   anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
188   anObjsLayout->addWidget( myGeomObjects, 1, 2 );
189   
190   // fill the top of the page
191   QGridLayout* aTopLayout = new QGridLayout;
192   aTopLayout->setMargin( 5 );
193   aTopLayout->setSpacing( 5 );
194   aTopLayout->setVerticalSpacing( 10 );
195   aTopLayout->addWidget( aNameLabel,     0, 0, Qt::AlignHCenter );
196   aTopLayout->addWidget( myObjectName,   0, 1 );
197   aTopLayout->addWidget( aLimitsLabel,   1, 0, Qt::AlignHCenter );
198   aTopLayout->addWidget( myPolylineName, 1, 1 );
199   aTopLayout->addWidget( aModeGroup, 2, 0, 1, 2 );
200   aTopLayout->addWidget( anObjectsFrame, 3, 0, 1, 2 );
201
202   aTopContainer->setLayout( aTopLayout );
203
204   // add the top of the page to the splitter
205   mySplitter->insertWidget(0, aTopContainer);
206   mySplitter->setStretchFactor(0, 2);
207
208   // Bottom of the page
209   myPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
210
211   QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
212   QBoxLayout* aPriorityLayout = new QHBoxLayout;
213   aPriorityLayout->setMargin( 5 );
214   aPriorityLayout->setSpacing( 5 );
215   aPriorityLayout->addWidget( myPriorityWidget );
216   aPriorityGroup->setLayout( aPriorityLayout );
217
218   // add the bottom of the page to the splitter
219   mySplitter->insertWidget(1, aPriorityGroup);
220   mySplitter->setStretchFactor(1, 1);
221
222   // Page layout
223   QVBoxLayout* aPageLayout = new QVBoxLayout;
224   aPageLayout->setMargin( 5 );
225   aPageLayout->setSpacing( 5 );
226   aPageLayout->addWidget( mySplitter );
227
228   aPage->setLayout( aPageLayout );
229
230   // Create selector
231   if ( module() ) {
232     HYDROGUI_ListSelector* aListSelector = 
233       new HYDROGUI_ListSelector( myGeomObjects, module()->getApp()->selectionMgr() );
234     aListSelector->setAutoBlock( true );
235   }
236
237   // Connections
238   connect( myModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeMode( int ) ) );
239   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) );
240   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) );
241
242   connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) );
243
244   connect( myPriorityWidget, SIGNAL( ruleChanged() ), SLOT( onRuleChanged() ) );
245
246   return aPage;
247 }
248
249 QWizardPage* HYDROGUI_CalculationDlg::createGroupsPage() {
250   QWizardPage* aPage = new QWizardPage( mainFrame() );
251   QFrame* aFrame = new QFrame( aPage );
252
253   myGroups = new QListWidget( aPage );
254   myGroups->setSelectionMode( QListWidget::ExtendedSelection );
255   myGroups->setEditTriggers( QListWidget::NoEditTriggers );
256   myGroups->setViewMode( QListWidget::ListMode );
257   myGroups->setSortingEnabled( true );
258
259   myAvailableGroups = new QListWidget( aPage );
260   myAvailableGroups->setSelectionMode( QListWidget::ExtendedSelection );
261   myAvailableGroups->setEditTriggers( QListWidget::NoEditTriggers );
262   myAvailableGroups->setViewMode( QListWidget::ListMode );
263   myAvailableGroups->setSortingEnabled( true );
264
265   connect( myGroups, SIGNAL( itemSelectionChanged() ), 
266     SIGNAL( groupsSelected() ) );
267
268   QFrame* aGroupsFrame = new QFrame( aPage );
269   QGridLayout* aGroupsLayout = new QGridLayout( aGroupsFrame );
270   aGroupsLayout->setMargin( 5 );
271   aGroupsLayout->setSpacing( 5 );
272   aGroupsFrame->setLayout( aGroupsLayout );
273
274   QFrame* aBtnsFrame = new QFrame( aGroupsFrame );
275   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
276   aBtnsLayout->setMargin( 5 );
277   aBtnsLayout->setSpacing( 5 );
278   aBtnsFrame->setLayout( aBtnsLayout );
279   QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
280   QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
281
282   // Fill the butons frame with two buttons
283   aBtnsLayout->addWidget( anAddBtn );
284   aBtnsLayout->addWidget( aRemoveBtn );
285   aBtnsLayout->addStretch( 1 );
286
287   QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_GROUPS" ), aGroupsFrame );
288   QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_GROUPS" ), aGroupsFrame );
289
290   // Fill the objects frame with two lists, two labels and with buttons frame
291   aGroupsLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
292   aGroupsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
293   aGroupsLayout->addWidget( myAvailableGroups, 1, 0 );
294   aGroupsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
295   aGroupsLayout->addWidget( myGroups, 1, 2 );
296
297   // Fill the page
298   QGridLayout* aPageLayout = new QGridLayout( aPage );
299   aPageLayout->setMargin( 5 );
300   aPageLayout->setSpacing( 5 );
301   aPageLayout->setVerticalSpacing( 10 );
302   aPageLayout->addWidget( aGroupsFrame, 0, 0 );
303
304   aPage->setLayout( aPageLayout );
305
306   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addGroups() ) );
307   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeGroups() ) );
308
309   return aPage;
310 }
311
312 QWizardPage* HYDROGUI_CalculationDlg::createLandCoverMapPage() {
313   QWizardPage* aPage = new QWizardPage( mainFrame() );
314   QFrame* aFrame = new QFrame( aPage );
315
316   // Top of the page
317   QWidget* aTopContainer = new QWidget;
318
319   // Combo-box to choose land cover map object
320   QLabel* aLandCoverMapLabel = new QLabel( tr( "LAND_COVER_MAP" ), aPage );
321   myLandCoverMapName = new QComboBox( aPage );
322   myLandCoverMapName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
323   connect( myLandCoverMapName, SIGNAL( activated( const QString & ) ), 
324                                SIGNAL( landCoverMapSelected( const QString & ) ) );
325   // Combo-box to choose Strickler table name
326   QLabel* aStricklerTableLabel = new QLabel( tr( "STRICKLER_TABLE" ), aPage );
327   myStricklerTableName = new QComboBox( aPage );
328   myStricklerTableName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
329   connect( myStricklerTableName, SIGNAL( activated( const QString & ) ), 
330                                  SIGNAL( StricklerTableSelected( const QString & ) ) );
331
332   // Fill the top layout of the page
333   QGridLayout* aGridLayout = new QGridLayout;
334   aGridLayout->setMargin( 5 );
335   aGridLayout->setSpacing( 5 );
336   aGridLayout->setVerticalSpacing( 10 );
337   aGridLayout->addWidget( aLandCoverMapLabel,   0, 0 );
338   aGridLayout->addWidget( myLandCoverMapName,   0, 1 );
339   aGridLayout->addWidget( aStricklerTableLabel, 1, 0 );
340   aGridLayout->addWidget( myStricklerTableName, 1, 1 );
341
342   QVBoxLayout* aTopLayout = new QVBoxLayout;
343   aTopLayout->setMargin( 5 );
344   aTopLayout->setSpacing( 5 );
345   aTopLayout->addLayout( aGridLayout );
346   aTopLayout->addStretch( 1 );
347   
348   aTopContainer->setLayout( aTopLayout );
349
350   aPage->setLayout( aTopLayout );
351
352   return aPage;
353 }
354
355 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
356   QWizardPage* aPage = new QWizardPage( mainFrame() );
357   QFrame* aFrame = new QFrame( aPage );
358
359   QGridLayout* aLayout = new QGridLayout( aPage );
360
361   QLabel* aResultsOnGeomObjectsLabel = new QLabel( tr( "RESULTS_ON_GEOMETRY_OBJECTS" ), aFrame );
362   
363   myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
364   myBrowser->setAutoOpenLevel( 3 );
365   aLayout->setMargin( 5 );
366   aLayout->setSpacing( 5 );
367
368   aLayout->addWidget( aResultsOnGeomObjectsLabel, 0, 0 );
369   aLayout->addWidget( myBrowser, 1, 0, 1, 2 );
370
371   myBathymetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
372   myBathymetryChoice = new QComboBox( aFrame );
373
374   myBathymetryChoice->setVisible( false );
375   myBathymetryLabel->setVisible( false );
376
377   aLayout->addWidget( myBathymetryLabel, 2, 0 );
378   aLayout->addWidget( myBathymetryChoice, 2, 1 );
379
380   QPushButton* aRegenerateBtn = new QPushButton( tr( "REGENERATE_COLORS" ), this );
381   aLayout->addWidget( aRegenerateBtn, 3, 0 );
382
383   aPage->setLayout( aLayout );
384
385   connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
386   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
387   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
388   connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
389   connect( myBrowser, 
390       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
391       SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
392   connect( myBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewRegion() ) );
393   connect( aRegenerateBtn, SIGNAL( clicked() ), this, SIGNAL( regenerateColors() ) );
394   return aPage;
395 }
396
397 bool HYDROGUI_CalculationDlg::acceptCurrent() const
398 {
399   QString anErrorMsg;
400
401   if ( false /*myGeomObjects->count() == 0*/ )
402   {
403     anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
404   }
405
406   if ( !anErrorMsg.isEmpty() )
407   {
408     anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
409     
410     QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
411     SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
412   }
413
414   return anErrorMsg.isEmpty();
415 }
416
417 void HYDROGUI_CalculationDlg::onEmptyName()
418 {
419   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
420   QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
421   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
422 }
423
424 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
425 {
426   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
427   QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
428                      "\n" + tr( "INPUT_VALID_DATA" );
429   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
430 }
431
432 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList, 
433     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
434 {
435   QList<SUIT_DataObject*> aZonesList;
436   HYDROGUI_Zone* aZone;
437   // Get a list of dropped zones
438   for ( int i = 0; i < theList.length(); i++ )
439   {
440     aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
441     if ( aZone )
442     {
443       aZonesList.append( aZone );
444     }
445   }
446   if ( aZonesList.length() > 0 )
447   {
448     // Get the target region
449     HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
450     if ( aRegionsRoot )
451     {
452       // Create a new region
453       emit createRegion( aZonesList );
454     }
455     else
456     {
457       HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
458       if ( aRegion )
459       {
460         emit moveZones( theTargetParent, aZonesList );
461       }
462     }
463   }
464 }
465
466 void HYDROGUI_CalculationDlg::OnNewRegion()
467 {
468   emit createRegion( myBrowser->getSelected() );
469 }
470
471 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
472 {
473   int aType = myBathymetryChoice->itemData( theIndex ).toInt();
474   QString aText = myBathymetryChoice->itemText( theIndex );
475   emit setMergeType( aType, aText );
476 }
477
478 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
479 {
480   bool doShow = false;
481   HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
482   if ( aZone )
483   {
484     doShow = aZone->isMergingNeed();
485   }
486
487   if ( doShow )
488   {
489     // Fill the merge type combo box
490     bool prevBlock = myBathymetryChoice->blockSignals( true );
491     myCurrentZone = aZone;
492     myBathymetryChoice->clear();
493     myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
494     myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
495     myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
496     QStringList aList = aZone->getObjects();
497     for ( int i = 0; i < aList.length(); i++ )
498     {
499       myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
500     }
501     // Select the current choice if any
502     int aCurIndex = 0;
503     switch ( aZone->getMergeType() )
504     {
505       case HYDROData_Zone::Merge_ZMIN:
506         aCurIndex = 1;
507         break;
508       case HYDROData_Zone::Merge_ZMAX:
509         aCurIndex = 2;
510         break;
511       case HYDROData_Zone::Merge_Object:
512         aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
513         break;
514       default:
515         aCurIndex = 0; // Select unknown by default
516     }
517     myBathymetryChoice->setCurrentIndex( aCurIndex );
518     myBathymetryChoice->blockSignals( prevBlock );
519   }
520
521   myBathymetryChoice->setVisible( doShow );
522   myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
523   myBathymetryLabel->setVisible( doShow );
524 }
525
526 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
527 {
528   myObjectName->setText( theName );
529 }
530
531 QString HYDROGUI_CalculationDlg::getObjectName() const
532 {
533   return myObjectName->text();
534 }
535
536 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
537 {
538   QList<QListWidgetItem*> aFoundItems;
539   int anIdx;
540   QListWidgetItem* anItem;
541
542   for ( int i = 0, n = theObjects.length(); i < n; ++i )
543   {
544     QString anObjName = theObjects.at( i );
545     aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
546     for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
547     {
548       anItem = aFoundItems.at( anIdx );
549       // Remove this object from available objects list
550       anItem = theSource->takeItem( theSource->row( anItem ) );
551       // Add the item to the included objects list
552       theDest->addItem( anItem );
553     }
554   }
555 }
556
557 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
558 {
559   QList<QListWidgetItem*> aFoundItems;
560   foreach ( const QString& anObjName, theObjects ) {
561     // Hide the object in the available objects list
562     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
563     foreach ( QListWidgetItem* anItem, aFoundItems ) {
564       anItem->setHidden( true );
565     }
566
567     // Add the object to the list of included objects
568     Handle(HYDROData_Entity) anObject = 
569       HYDROGUI_Tool::FindObjectByName( module(), anObjName );
570     myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
571   }
572
573   myPriorityWidget->setObjects( getGeometryObjects() );
574 }
575
576 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
577 {
578   QList<QListWidgetItem*> aFoundItems;
579   foreach ( const QString& anObjName, theObjects ) {
580     // Set visible the object in the available objects list
581     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
582     foreach ( QListWidgetItem* anItem, aFoundItems ) {
583       anItem->setHidden( false );
584     }
585
586     // Remove the object from the list of included objects
587     myGeomObjects->removeObjectByName( anObjName );
588   }
589
590   myPriorityWidget->setObjects( getGeometryObjects() );
591 }
592
593 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
594 {
595   bool isBlocked = myPolylineName->blockSignals( true );
596   myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
597   myPolylineName->blockSignals( isBlocked );
598 }
599
600 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
601 {
602   myPolylineName->clear();
603   myPolylineName->addItem( "", "" ); // No boundary item
604
605   for ( int i = 0, n = theObjects.length(); i < n; ++i )
606   {
607     myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
608   }
609 }
610
611 void HYDROGUI_CalculationDlg::setLandCoverMapsNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
612 {
613   myLandCoverMapName->clear();
614
615   for ( int i = 0, n = theObjects.length(); i < n; ++i )
616   {
617     myLandCoverMapName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
618   }
619 }
620
621 void HYDROGUI_CalculationDlg::setStricklerTableNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
622 {
623   myStricklerTableName->clear();
624
625   for ( int i = 0, n = theObjects.length(); i < n; ++i )
626   {
627     myStricklerTableName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
628   }
629 }
630
631 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
632 {
633   myAvailableGeomObjects->clear();
634
635   for ( int i = 0, n = theObjects.length(); i < n; ++i )
636   {
637     QString anObjName = theObjects.at( i );
638
639     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
640     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
641     aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
642   }
643 }
644
645 QStringList getSelected( QListWidget* theWidget )
646 {
647   QStringList aResList;
648   QList<QListWidgetItem*> aList = theWidget->selectedItems();
649   for ( int i = 0, n = aList.length(); i < n; ++i )
650   {
651     aResList.append( aList.at( i )->text() );
652   }
653   return aResList;
654 }
655
656 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
657 {
658   return myGeomObjects->getSelectedNames();
659 }
660
661 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
662 {
663   return myGeomObjects->getAllNames();
664 }
665
666 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
667 {
668   return getSelected( myAvailableGeomObjects );
669 }
670
671 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
672 {
673   myEditedObject = theCase;
674   myValidator->setEditedObject( theCase );
675
676   // Build the calculation case subtree
677   module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject);
678
679   myBrowser->updateTree();
680   myBrowser->openLevels();
681   myBrowser->adjustColumnsWidth();
682   myBrowser->setAutoUpdate( true );
683   myBrowser->setUpdateModified( true );
684 }
685
686 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
687 {
688   return myCurrentZone;
689 }
690
691 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
692 {
693   SUIT_DataObject* aRoot = myBrowser->root();
694   module()->getDataModel()->updateObjectTree( myEditedObject );
695   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
696   myBrowser->updateTree( aRoot );
697 }
698
699 void HYDROGUI_CalculationDlg::onDataChanged()
700 {
701   SUIT_DataObject* aRoot = myBrowser->root();
702   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
703   myBrowser->updateTree( aRoot );
704 }
705
706 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
707 {
708   myAvailableGroups->clear();
709   myGroups->clear();
710   foreach( QString aGroup, theGroups )
711     myAvailableGroups->addItem( aGroup );
712 }
713
714 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
715 {
716   return getSelected( myGroups );
717 }
718
719 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
720 {
721   return getSelected( myAvailableGroups );
722 }
723
724 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
725 {
726   moveItems( myAvailableGroups, myGroups, theObjects );
727 }
728
729 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
730 {
731   moveItems( myGroups, myAvailableGroups, theObjects );
732 }
733
734 /**
735   Get creation mode.
736   @param theMode the mode
737 */
738 int HYDROGUI_CalculationDlg::getMode() const
739 {
740   return myModeButtons->checkedId();
741 }
742
743 /**
744   Set creation mode.
745   @param theMode the mode
746 */
747 void HYDROGUI_CalculationDlg::setMode( int theMode )
748 {
749   bool isBlocked = myModeButtons->blockSignals( true );
750   myModeButtons->button( theMode )->setChecked( true );
751   myModeButtons->blockSignals( isBlocked );
752
753   bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
754
755   myGeomObjects->setOrderingEnabled( isAuto );
756   QWidget* aWidget = mySplitter->widget( 1 );
757   if ( aWidget ) {
758     aWidget->setVisible( isAuto );
759   }
760 }
761
762 /**
763   Enable/disable zones drag'n'drop and renaming.
764   @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
765 */
766 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
767 {
768   myBrowser->setReadOnly( !theIsEnabled );
769 }
770
771 /**
772   Get included geometry objects.
773   @return the list of geometry objects
774  */
775 QList<Handle(HYDROData_Entity)> HYDROGUI_CalculationDlg::getGeometryObjects()
776 {
777   QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
778   QList<Handle(HYDROData_Entity)> anObjects;
779
780   foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
781     Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
782     if ( anObj.IsNull() ) {
783       continue;
784     }
785
786     anObjects << anObj;
787   }
788
789   return anObjects;
790 }
791
792 /**
793   Get rules.
794   @return the list of rules
795  */
796 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
797 {
798   return myPriorityWidget->getRules();
799 }
800
801 /**
802   Set rules.
803   @param theRules the list of rules
804  */
805 void  HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
806 {
807   myPriorityWidget->setRules( theRules );
808 }
809
810 /**
811   Slot called when objects order is changed.
812  */
813 void HYDROGUI_CalculationDlg::onOrderChanged()
814 {
815   bool isConfirmed = true;
816   emit orderChanged( isConfirmed );
817   if( isConfirmed )
818     myPriorityWidget->setObjects( getGeometryObjects() );
819   else
820     myGeomObjects->undoLastMove();
821 }
822
823 /**
824   Slot called when priority rule for geometry objects is changed.
825  */
826 void HYDROGUI_CalculationDlg::onRuleChanged()
827 {
828   bool isConfirmed = true;
829   emit ruleChanged( isConfirmed );
830   if( !isConfirmed )
831     myPriorityWidget->undoLastChange();
832 }
833
834 void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals )
835 {
836   bool isBlocked;
837   if ( theBlockSignals )
838     isBlocked = myStricklerTableName->blockSignals( true );
839   
840   myStricklerTableName->setCurrentIndex( myStricklerTableName->findText( theStricklerTableName ) );
841
842   if ( theBlockSignals )
843     myStricklerTableName->blockSignals( isBlocked );
844   else
845     emit StricklerTableSelected( theStricklerTableName );
846 }
847
848 void HYDROGUI_CalculationDlg::setLandCoverMap( const QString& theLandCoverMapName, bool theBlockSignals )
849 {
850   bool isBlocked;
851   if ( theBlockSignals )
852     isBlocked = myLandCoverMapName->blockSignals( true );
853   
854   myLandCoverMapName->setCurrentIndex( myLandCoverMapName->findText( theLandCoverMapName ) );
855
856   if ( theBlockSignals )
857     myLandCoverMapName->blockSignals( isBlocked );
858   else
859     emit landCoverMapSelected( theLandCoverMapName );
860 }