]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_CalculationDlg.cxx
Salome HOME
refs #573, #574: fill in ordered list widget on Land Cover panel with land covers...
[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_Tool.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
34 #include <HYDROData_Document.h>
35 #include <HYDROData_Entity.h>
36
37 #include <CAM_Application.h>
38 #include <LightApp_DataObject.h>
39
40 #include <SUIT_DataObject.h>
41 #include <SUIT_FileDlg.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_Study.h>
45
46 #include <LightApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
48 #include <SUIT_Desktop.h>
49 #include <SUIT_MessageBox.h>
50
51 #include <QButtonGroup>
52 #include <QComboBox>
53 #include <QGroupBox>
54 #include <QLabel>
55 #include <QLayout>
56 #include <QLineEdit>
57 #include <QListWidget>
58 #include <QPicture>
59 #include <QPushButton>
60 #include <QRadioButton>
61 #include <QSplitter>
62 #include <QTableWidget>
63 #include <QToolButton>
64 #include <QTreeView>
65 #include <QWizardPage>
66
67
68 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
69 : HYDROGUI_Wizard( theModule, theTitle )
70 {
71   addPage( createObjectsPage() );
72   addPage( createGroupsPage() );
73   addPage( createLandCoversPage() );
74   addPage( createZonesPage() );
75   addPage( createLandCoversPartitionPage() );
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   myLandCovers->setObjects(anObject2VisibleList);
88   myPolylineName->clear();
89   myStricklerTableName->clear();
90   myAvailableGeomObjects->clear();
91   myAvailableLandCovers->clear();
92
93   // Activate the automatic mode
94   setMode( HYDROData_CalculationCase::AUTOMATIC );
95   setLandCoverMode( HYDROData_CalculationCase::AUTOMATIC );
96
97   // Reset the priority widget state
98   QList<Handle(HYDROData_Object)> anObjects;
99   myPriorityWidget->setObjects( anObjects );
100 }
101
102 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
103   QWizardPage* aPage = new QWizardPage( mainFrame() );
104   QFrame* aFrame = new QFrame( aPage );
105
106   // Splitter
107   mySplitter = new QSplitter(Qt::Vertical);
108
109   // Top of the page
110   QWidget* aTopContainer = new QWidget;
111    
112   // calculation name
113   myObjectName = new QLineEdit( aPage );
114   myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
115   myObjectName->setValidator( myValidator );
116
117   connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) );
118   connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) );
119
120   // polyline name
121   myPolylineName = new QComboBox( aPage );
122   connect( myPolylineName, SIGNAL( activated( const QString & ) ), 
123     SIGNAL( boundarySelected( const QString & ) ) );
124
125   // names labels
126   QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
127   QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
128
129   // mode selector (auto/manual)
130   QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
131
132   QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
133   QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
134
135   myModeButtons = new QButtonGroup( mainFrame() );
136   myModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
137   myModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
138   
139   QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
140   aModeSelectorLayout->setMargin( 5 );
141   aModeSelectorLayout->setSpacing( 5 );
142   aModeSelectorLayout->addWidget( anAutoRB );
143   aModeSelectorLayout->addWidget( aManualRB );
144   aModeGroup->setLayout( aModeSelectorLayout );
145
146   // geometry objects
147   QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ) );
148   myGeomObjects = new HYDROGUI_OrderedListWidget( aPage, 16 );
149   myGeomObjects->setHiddenObjectsShown(true);
150   myGeomObjects->setVisibilityIconShown(false);
151   myGeomObjects->setContentsMargins(QMargins());
152  
153   // included geometry objects
154   QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ) );
155   myAvailableGeomObjects = new QListWidget( aPage );
156   myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
157   myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
158   myAvailableGeomObjects->setViewMode( QListWidget::ListMode );
159   myAvailableGeomObjects->setSortingEnabled( true );
160
161   // buttons
162   QFrame* aBtnsFrame = new QFrame;
163   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
164   aBtnsLayout->setMargin( 5 );
165   aBtnsLayout->setSpacing( 5 );
166   aBtnsFrame->setLayout( aBtnsLayout );
167   QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
168   QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
169
170   // fill the butons frame with two buttons
171   aBtnsLayout->addWidget( anAddBtn );
172   aBtnsLayout->addWidget( aRemoveBtn );
173   aBtnsLayout->addStretch( 1 );
174   
175   // top of the page layout
176   
177   // objects frame
178   QFrame* anObjectsFrame = new QFrame( aPage );
179   anObjectsFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
180   QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
181   anObjsLayout->setMargin( 5 );
182   anObjsLayout->setSpacing( 5 );
183   anObjectsFrame->setLayout( anObjsLayout );
184   
185   // fill the objects frame with two lists, two labels and with buttons frame
186   anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter );
187   anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
188   anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0 );
189   anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
190   anObjsLayout->addWidget( myGeomObjects, 1, 2 );
191   
192   // fill the top of the page
193   QGridLayout* aTopLayout = new QGridLayout;
194   aTopLayout->setMargin( 5 );
195   aTopLayout->setSpacing( 5 );
196   aTopLayout->setVerticalSpacing( 10 );
197   aTopLayout->addWidget( aNameLabel,     0, 0, Qt::AlignHCenter );
198   aTopLayout->addWidget( myObjectName,   0, 1 );
199   aTopLayout->addWidget( aLimitsLabel,   1, 0, Qt::AlignHCenter );
200   aTopLayout->addWidget( myPolylineName, 1, 1 );
201   aTopLayout->addWidget( aModeGroup, 2, 0, 1, 2 );
202   aTopLayout->addWidget( anObjectsFrame, 3, 0, 1, 2 );
203
204   aTopContainer->setLayout( aTopLayout );
205
206   // add the top of the page to the splitter
207   mySplitter->insertWidget(0, aTopContainer);
208   mySplitter->setStretchFactor(0, 2);
209
210   // Bottom of the page
211   myPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
212
213   QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
214   QBoxLayout* aPriorityLayout = new QHBoxLayout;
215   aPriorityLayout->setMargin( 5 );
216   aPriorityLayout->setSpacing( 5 );
217   aPriorityLayout->addWidget( myPriorityWidget );
218   aPriorityGroup->setLayout( aPriorityLayout );
219
220   // add the bottom of the page to the splitter
221   mySplitter->insertWidget(1, aPriorityGroup);
222   mySplitter->setStretchFactor(1, 1);
223
224   // Page layout
225   QVBoxLayout* aPageLayout = new QVBoxLayout;
226   aPageLayout->setMargin( 5 );
227   aPageLayout->setSpacing( 5 );
228   aPageLayout->addWidget( mySplitter );
229
230   aPage->setLayout( aPageLayout );
231
232   // Create selector
233   if ( module() ) {
234     HYDROGUI_ListSelector* aListSelector = 
235       new HYDROGUI_ListSelector( myGeomObjects, module()->getApp()->selectionMgr() );
236     aListSelector->setAutoBlock( true );
237   }
238
239   // Connections
240   connect( myModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeMode( int ) ) );
241   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) );
242   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) );
243
244   connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) );
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::createLandCoversPage() {
313   QWizardPage* aPage = new QWizardPage( mainFrame() );
314   QFrame* aFrame = new QFrame( aPage );
315
316   // Splitter
317   myLandCoverSplitter = new QSplitter(Qt::Vertical);
318
319   // Top of the page
320   QWidget* aTopContainer = new QWidget;
321    
322   // Combo-box to choose Strickler table name
323   QLabel* aStricklerTableLabel = new QLabel( tr( "STRICKLER_TABLE" ), aPage );
324   myStricklerTableName = new QComboBox( aPage );
325   myStricklerTableName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
326   connect( myStricklerTableName, SIGNAL( activated( const QString & ) ), 
327                                  SIGNAL( StricklerTableSelected( const QString & ) ) );
328
329   // Mode selector (auto/manual)
330   QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
331
332   QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
333   QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
334
335   myLandCoverModeButtons = new QButtonGroup( mainFrame() );
336   myLandCoverModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
337   myLandCoverModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
338   
339   QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
340   aModeSelectorLayout->setMargin( 5 );
341   aModeSelectorLayout->setSpacing( 5 );
342   aModeSelectorLayout->addWidget( anAutoRB );
343   aModeSelectorLayout->addWidget( aManualRB );
344   aModeGroup->setLayout( aModeSelectorLayout );
345
346   // Available land covers
347   QLabel* aLandCoversLabel = new QLabel( tr( "CALCULATION_REFERENCE_LAND_COVERS" ) );
348   myAvailableLandCovers = new QListWidget( aPage );
349   myAvailableLandCovers->setSelectionMode( QListWidget::ExtendedSelection );
350   myAvailableLandCovers->setEditTriggers( QListWidget::NoEditTriggers );
351   myAvailableLandCovers->setViewMode( QListWidget::ListMode );
352   myAvailableLandCovers->setSortingEnabled( true );
353  
354   // Included land covers
355   QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_LAND_COVERS" ) );
356   myLandCovers = new HYDROGUI_OrderedListWidget( aPage, 16 );
357   myLandCovers->setHiddenObjectsShown(true);
358   myLandCovers->setVisibilityIconShown(false);
359   myLandCovers->setContentsMargins(QMargins()); 
360
361   // Include/Exclude buttons
362   QFrame* aBtnsFrame = new QFrame;
363   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
364   aBtnsLayout->setMargin( 5 );
365   aBtnsLayout->setSpacing( 5 );
366   aBtnsFrame->setLayout( aBtnsLayout );
367   QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
368   QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
369
370   // Fill the butons frame with two buttons
371   aBtnsLayout->addWidget( anAddBtn );
372   aBtnsLayout->addWidget( aRemoveBtn );
373   aBtnsLayout->addStretch( 1 );
374   
375   // Land covers frame
376   QFrame* aLandCoversFrame = new QFrame( aPage );
377   aLandCoversFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
378   QGridLayout* aLandCoversLayout = new QGridLayout( aLandCoversFrame );
379   aLandCoversLayout->setMargin( 5 );
380   aLandCoversLayout->setSpacing( 5 );
381   aLandCoversFrame->setLayout( aLandCoversLayout );
382   
383   // Fill the land covers frame with two lists, two labels and with buttons frame
384   aLandCoversLayout->addWidget( aLandCoversLabel, 0, 0, Qt::AlignHCenter );
385   aLandCoversLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
386   aLandCoversLayout->addWidget( myAvailableLandCovers, 1, 0 );
387   aLandCoversLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
388   aLandCoversLayout->addWidget( myLandCovers, 1, 2 );
389   
390   // Fill the top layout of the page
391   QGridLayout* aTopLayout = new QGridLayout;
392   aTopLayout->setMargin( 5 );
393   aTopLayout->setSpacing( 5 );
394   aTopLayout->setVerticalSpacing( 10 );
395   aTopLayout->addWidget( aStricklerTableLabel, 0, 0, Qt::AlignHCenter );
396   aTopLayout->addWidget( myStricklerTableName, 0, 1 );
397   aTopLayout->addWidget( aModeGroup, 1, 0, 1, 2 );
398   aTopLayout->addWidget( aLandCoversFrame, 2, 0, 1, 2 );
399
400   aTopContainer->setLayout( aTopLayout );
401
402   // Add the top of the page to the splitter
403   myLandCoverSplitter->insertWidget(0, aTopContainer);
404   myLandCoverSplitter->setStretchFactor(0, 2);
405
406   // Bottom of the page
407   myLandCoverPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
408
409   QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
410   QBoxLayout* aPriorityLayout = new QHBoxLayout;
411   aPriorityLayout->setMargin( 5 );
412   aPriorityLayout->setSpacing( 5 );
413   aPriorityLayout->addWidget( myLandCoverPriorityWidget );
414   aPriorityGroup->setLayout( aPriorityLayout );
415
416   // Add the bottom of the page to the splitter
417   myLandCoverSplitter->insertWidget(1, aPriorityGroup);
418   myLandCoverSplitter->setStretchFactor(1, 1);
419
420   // Page layout
421   QVBoxLayout* aPageLayout = new QVBoxLayout;
422   aPageLayout->setMargin( 5 );
423   aPageLayout->setSpacing( 5 );
424   aPageLayout->addWidget( myLandCoverSplitter );
425
426   aPage->setLayout( aPageLayout );
427
428   // Create selector
429   if ( module() ) {
430     HYDROGUI_ListSelector* aListSelector = 
431       new HYDROGUI_ListSelector( myLandCovers, module()->getApp()->selectionMgr() );
432     aListSelector->setAutoBlock( true );
433   }
434
435   // Connections
436   connect( myLandCoverModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeLandCoverMode( int ) ) );
437   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addLandCovers() ) );
438   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeLandCovers() ) );
439
440   connect( myLandCovers, SIGNAL( orderLandCoverChanged() ), SLOT( onOrderLandCoverChanged() ) );
441
442   return aPage;
443 }
444
445 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
446   QWizardPage* aPage = new QWizardPage( mainFrame() );
447   QFrame* aFrame = new QFrame( aPage );
448
449   QGridLayout* aLayout = new QGridLayout( aPage );
450   
451   myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
452   myBrowser->setAutoOpenLevel( 3 );
453   aLayout->setMargin( 5 );
454   aLayout->setSpacing( 5 );
455
456   aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
457
458   myBathymetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
459   myBathymetryChoice = new QComboBox( aFrame );
460
461   myBathymetryChoice->setVisible( false );
462   myBathymetryLabel->setVisible( false );
463
464   aLayout->addWidget( myBathymetryLabel, 1, 0 );
465   aLayout->addWidget( myBathymetryChoice, 1, 1 );
466
467   aPage->setLayout( aLayout );
468
469   connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
470   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
471   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
472   connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
473   connect( myBrowser, 
474       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
475       SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
476   connect( myBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewRegion() ) );
477
478   return aPage;
479 }
480
481 QWizardPage* HYDROGUI_CalculationDlg::createLandCoversPartitionPage() {
482   QWizardPage* aPage = new QWizardPage( mainFrame() );
483   QFrame* aFrame = new QFrame( aPage );
484
485   QGridLayout* aLayout = new QGridLayout( aPage );
486   
487   myLandCoverBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
488   myLandCoverBrowser->setAutoOpenLevel( 3 );
489   aLayout->setMargin( 5 );
490   aLayout->setSpacing( 5 );
491
492   aLayout->addWidget( myLandCoverBrowser, 0, 0, 1, 2 );
493
494   aPage->setLayout( aLayout );
495
496   // Connections
497   //...
498
499   return aPage;
500 }
501
502
503 bool HYDROGUI_CalculationDlg::acceptCurrent() const
504 {
505   QString anErrorMsg;
506
507   if ( false /*myGeomObjects->count() == 0*/ )
508   {
509     anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
510   }
511
512   if ( !anErrorMsg.isEmpty() )
513   {
514     anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
515     
516     QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
517     SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
518   }
519
520   return anErrorMsg.isEmpty();
521 }
522
523 void HYDROGUI_CalculationDlg::onEmptyName()
524 {
525   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
526   QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
527   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
528 }
529
530 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
531 {
532   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
533   QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
534                      "\n" + tr( "INPUT_VALID_DATA" );
535   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
536 }
537
538 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList, 
539     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
540 {
541   QList<SUIT_DataObject*> aZonesList;
542   HYDROGUI_Zone* aZone;
543   // Get a list of dropped zones
544   for ( int i = 0; i < theList.length(); i++ )
545   {
546     aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
547     if ( aZone )
548     {
549       aZonesList.append( aZone );
550     }
551   }
552   if ( aZonesList.length() > 0 )
553   {
554     // Get the target region
555     HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
556     if ( aRegionsRoot )
557     {
558       // Create a new region
559       emit createRegion( aZonesList );
560     }
561     else
562     {
563       HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
564       if ( aRegion )
565       {
566         emit moveZones( theTargetParent, aZonesList );
567       }
568     }
569   }
570 }
571
572 void HYDROGUI_CalculationDlg::OnNewRegion()
573 {
574   emit createRegion( myBrowser->getSelected() );
575 }
576
577 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
578 {
579   int aType = myBathymetryChoice->itemData( theIndex ).toInt();
580   QString aText = myBathymetryChoice->itemText( theIndex );
581   emit setMergeType( aType, aText );
582 }
583
584 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
585 {
586   bool doShow = false;
587   HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
588   if ( aZone )
589   {
590     doShow = aZone->isMergingNeed();
591   }
592
593   if ( doShow )
594   {
595     // Fill the merge type combo box
596     bool prevBlock = myBathymetryChoice->blockSignals( true );
597     myCurrentZone = aZone;
598     myBathymetryChoice->clear();
599     myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
600     myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
601     myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
602     QStringList aList = aZone->getAltitudes();
603     for ( int i = 0; i < aList.length(); i++ )
604     {
605       myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
606     }
607     // Select the current choice if any
608     int aCurIndex = 0;
609     switch ( aZone->getMergeType() )
610     {
611       case HYDROData_Zone::Merge_ZMIN:
612         aCurIndex = 1;
613         break;
614       case HYDROData_Zone::Merge_ZMAX:
615         aCurIndex = 2;
616         break;
617       case HYDROData_Zone::Merge_Object:
618         aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
619         break;
620       default:
621         aCurIndex = 0; // Select unknown by default
622     }
623     myBathymetryChoice->setCurrentIndex( aCurIndex );
624     myBathymetryChoice->blockSignals( prevBlock );
625   }
626
627   myBathymetryChoice->setVisible( doShow );
628   myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
629   myBathymetryLabel->setVisible( doShow );
630 }
631
632 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
633 {
634   myObjectName->setText( theName );
635 }
636
637 QString HYDROGUI_CalculationDlg::getObjectName() const
638 {
639   return myObjectName->text();
640 }
641
642 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
643 {
644   QList<QListWidgetItem*> aFoundItems;
645   int anIdx;
646   QListWidgetItem* anItem;
647
648   for ( int i = 0, n = theObjects.length(); i < n; ++i )
649   {
650     QString anObjName = theObjects.at( i );
651     aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
652     for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
653     {
654       anItem = aFoundItems.at( anIdx );
655       // Remove this object from available objects list
656       anItem = theSource->takeItem( theSource->row( anItem ) );
657       // Add the item to the included objects list
658       theDest->addItem( anItem );
659     }
660   }
661 }
662
663 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
664 {
665   HYDROGUI_ListModel::Object2VisibleList anObjectsToInclude;
666   QList<QListWidgetItem*> aFoundItems;
667   foreach ( const QString& anObjName, theObjects ) {
668     // Hide the object in the available objects list
669     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
670     foreach ( QListWidgetItem* anItem, aFoundItems ) {
671       anItem->setHidden( true );
672     }
673
674     // Add the object to the list of included objects
675     Handle(HYDROData_Entity) anObject = 
676       HYDROGUI_Tool::FindObjectByName( module(), anObjName );
677     myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
678   }
679
680   myPriorityWidget->setObjects( getGeometryObjects() );
681 }
682
683 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
684 {
685   QList<QListWidgetItem*> aFoundItems;
686   foreach ( const QString& anObjName, theObjects ) {
687     // Set visible the object in the available objects list
688     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
689     foreach ( QListWidgetItem* anItem, aFoundItems ) {
690       anItem->setHidden( false );
691     }
692
693     // Remove the object from the list of included objects
694     myGeomObjects->removeObjectByName( anObjName );
695   }
696
697   myPriorityWidget->setObjects( getGeometryObjects() );
698 }
699
700 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
701 {
702   bool isBlocked = myPolylineName->blockSignals( true );
703   myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
704   myPolylineName->blockSignals( isBlocked );
705 }
706
707 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
708 {
709   myPolylineName->clear();
710   myPolylineName->addItem( "", "" ); // No boundary item
711
712   for ( int i = 0, n = theObjects.length(); i < n; ++i )
713   {
714     myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
715   }
716 }
717
718 void HYDROGUI_CalculationDlg::setStricklerTableNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
719 {
720   myStricklerTableName->clear();
721
722   for ( int i = 0, n = theObjects.length(); i < n; ++i )
723   {
724     myStricklerTableName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
725   }
726 }
727
728 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
729 {
730   myAvailableGeomObjects->clear();
731
732   for ( int i = 0, n = theObjects.length(); i < n; ++i )
733   {
734     QString anObjName = theObjects.at( i );
735
736     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
737     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
738     aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
739   }
740 }
741
742 void HYDROGUI_CalculationDlg::setAllLandCovers( const QStringList& theObjects, const QStringList& theObjectsEntries )
743 {
744   myAvailableLandCovers->clear();
745
746   for ( int i = 0, n = theObjects.length(); i < n; ++i )
747   {
748     QString anObjName = theObjects.at( i );
749
750     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableLandCovers );
751     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
752     aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
753   }
754 }
755
756 QStringList getSelected( QListWidget* theWidget )
757 {
758   QStringList aResList;
759   QList<QListWidgetItem*> aList = theWidget->selectedItems();
760   for ( int i = 0, n = aList.length(); i < n; ++i )
761   {
762     aResList.append( aList.at( i )->text() );
763   }
764   return aResList;
765 }
766
767 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
768 {
769   return myGeomObjects->getSelectedNames();
770 }
771
772 QStringList HYDROGUI_CalculationDlg::getSelectedLandCovers() const
773 {
774   return myLandCovers->getSelectedNames();
775 }
776
777 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
778 {
779   return myGeomObjects->getAllNames();
780 }
781
782 QStringList HYDROGUI_CalculationDlg::getAllLandCovers() const
783 {
784   return myLandCovers->getAllNames();
785 }
786
787 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
788 {
789   return getSelected( myAvailableGeomObjects );
790 }
791
792 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableLandCovers() const
793 {
794   return getSelected( myAvailableLandCovers );
795 }
796
797 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
798 {
799   myEditedObject = theCase;
800   myValidator->setEditedObject( theCase );
801
802   // Build the calculation case subtree
803   module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject );
804
805   myBrowser->updateTree();
806   myBrowser->openLevels();
807   myBrowser->adjustColumnsWidth();
808   myBrowser->setAutoUpdate( true );
809   myBrowser->setUpdateModified( true );
810 }
811
812 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
813 {
814   return myCurrentZone;
815 }
816
817 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
818 {
819   SUIT_DataObject* aRoot = myBrowser->root();
820   module()->getDataModel()->updateObjectTree( myEditedObject );
821   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
822   myBrowser->updateTree( aRoot );
823 }
824
825 void HYDROGUI_CalculationDlg::onDataChanged()
826 {
827   SUIT_DataObject* aRoot = myBrowser->root();
828   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
829   myBrowser->updateTree( aRoot );
830 }
831
832 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
833 {
834   myAvailableGroups->clear();
835   myGroups->clear();
836   foreach( QString aGroup, theGroups )
837     myAvailableGroups->addItem( aGroup );
838 }
839
840 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
841 {
842   return getSelected( myGroups );
843 }
844
845 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
846 {
847   return getSelected( myAvailableGroups );
848 }
849
850 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
851 {
852   moveItems( myAvailableGroups, myGroups, theObjects );
853 }
854
855 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
856 {
857   moveItems( myGroups, myAvailableGroups, theObjects );
858 }
859
860 /**
861   Get creation mode.
862   @param theMode the mode
863 */
864 int HYDROGUI_CalculationDlg::getMode() const
865 {
866   return myModeButtons->checkedId();
867 }
868
869 /**
870   Set creation mode.
871   @param theMode the mode
872 */
873 void HYDROGUI_CalculationDlg::setMode( int theMode )
874 {
875   bool isBlocked = myModeButtons->blockSignals( true );
876   myModeButtons->button( theMode )->setChecked( true );
877   myModeButtons->blockSignals( isBlocked );
878
879   bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
880
881   myGeomObjects->setOrderingEnabled( isAuto );
882   QWidget* aWidget = mySplitter->widget( 1 );
883   if ( aWidget ) {
884     aWidget->setVisible( isAuto );
885   }
886 }
887
888 /**
889   Get creation mode for land covers panel.
890   @param theMode the mode
891 */
892 int HYDROGUI_CalculationDlg::getLandCoverMode() const
893 {
894   return myLandCoverModeButtons->checkedId();
895 }
896
897 /**
898   Set creation mode for land cover panel.
899   @param theMode the mode
900 */
901 void HYDROGUI_CalculationDlg::setLandCoverMode( int theMode )
902 {
903   bool isBlocked = myLandCoverModeButtons->blockSignals( true );
904   myLandCoverModeButtons->button( theMode )->setChecked( true );
905   myLandCoverModeButtons->blockSignals( isBlocked );
906
907   bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
908
909   myLandCovers->setOrderingEnabled( isAuto );
910   QWidget* aWidget = myLandCoverSplitter->widget( 1 );
911   if ( aWidget ) {
912     aWidget->setVisible( isAuto );
913   }
914 }
915
916 /**
917   Enable/disable zones drag'n'drop and renaming.
918   @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
919 */
920 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
921 {
922   myBrowser->setReadOnly( !theIsEnabled );
923 }
924
925 /**
926   Enable/disable land covers drag'n'drop and renaming.
927   @param theIsEnabled if true - land covers drag'n'drop and renaming will be enabled
928 */
929 void HYDROGUI_CalculationDlg::setEditLandCoversEnabled( const bool theIsEnabled )
930 {
931   myLandCoverBrowser->setReadOnly( !theIsEnabled );
932 }
933
934 /**
935   Get included geometry objects.
936   @return the list of geometry objects
937  */
938 QList<Handle(HYDROData_Object)> HYDROGUI_CalculationDlg::getGeometryObjects()
939 {
940   QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
941   QList<Handle(HYDROData_Object)> anObjects;
942
943   foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
944     Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
945     if ( anObj.IsNull() ) {
946       continue;
947     }
948
949     anObjects << anObj;
950   }
951
952   return anObjects;
953 }
954
955 /**
956   Get included land covers.
957   @return the list of land covers
958  */
959 QList<Handle(HYDROData_LandCover)> HYDROGUI_CalculationDlg::getLandCovers()
960 {
961   QList<Handle(HYDROData_Entity)> anEntities = myLandCovers->getObjects();
962   QList<Handle(HYDROData_LandCover)> aLandCovers;
963
964   foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
965     Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
966     if ( aLandCover.IsNull() ) {
967       continue;
968     }
969
970     aLandCovers << aLandCover;
971   }
972
973   return aLandCovers;
974 }
975
976 /**
977   Get rules.
978   @return the list of rules
979  */
980 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
981 {
982   return myPriorityWidget->getRules();
983 }
984
985 /**
986   Set rules.
987   @param theRules the list of rules
988  */
989 void  HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
990 {
991   myPriorityWidget->setRules( theRules );
992 }
993
994 /**
995   Slot called when objects order is changed.
996  */
997 void HYDROGUI_CalculationDlg::onOrderChanged()
998 {
999   bool isConfirmed = true;
1000   emit orderChanged( isConfirmed );
1001   if( isConfirmed )
1002     myPriorityWidget->setObjects( getGeometryObjects() );
1003   else
1004     myGeomObjects->undoLastMove();
1005 }
1006
1007 void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName )
1008 {
1009   bool isBlocked = myStricklerTableName->blockSignals( true );
1010   myStricklerTableName->setCurrentIndex( myStricklerTableName->findText( theStricklerTableName ) );
1011   myStricklerTableName->blockSignals( isBlocked );
1012 }
1013
1014 void HYDROGUI_CalculationDlg::includeLandCovers( const QStringList& theLandCovers )
1015 {
1016   HYDROGUI_ListModel::Object2VisibleList anObjectsToInclude;
1017   QList<QListWidgetItem*> aFoundItems;
1018   foreach ( const QString& anObjName, theLandCovers ) {
1019     // Hide the land cover in the available land covers list
1020     aFoundItems = myAvailableLandCovers->findItems( anObjName, Qt::MatchExactly );
1021     foreach ( QListWidgetItem* anItem, aFoundItems ) {
1022       anItem->setHidden( true );
1023     }
1024
1025     // Add the land cover to the list of included objects
1026     Handle(HYDROData_Entity) anObject = 
1027       HYDROGUI_Tool::FindObjectByName( module(), anObjName );
1028     myLandCovers->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
1029   }
1030
1031   // TODO: adapt HYDROGUI_PriorityWidget to process land covers
1032   //myLandCoverPriorityWidget->setObjects( getLandCovers() );
1033 }
1034
1035 void HYDROGUI_CalculationDlg::excludeLandCovers( const QStringList& theLandCovers )
1036 {
1037   QList<QListWidgetItem*> aFoundItems;
1038   foreach ( const QString& anObjName, theLandCovers ) {
1039     // Set visible the land cover in the available objects list
1040     aFoundItems = myAvailableLandCovers->findItems( anObjName, Qt::MatchExactly );
1041     foreach ( QListWidgetItem* anItem, aFoundItems ) {
1042       anItem->setHidden( false );
1043     }
1044
1045     // Remove the land cover from the list of included objects
1046     myLandCovers->removeObjectByName( anObjName );
1047   }
1048
1049   // TODO: adapt HYDROGUI_PriorityWidget to process land covers
1050   //myLandCoverPriorityWidget->setObjects( getLandCovers() );
1051 }
1052
1053 /**
1054   Slot called when land covers order is changed.
1055  */
1056 void HYDROGUI_CalculationDlg::onOrderLandCoverChanged()
1057 {
1058   bool isConfirmed = true;
1059   emit orderLandCoverChanged( isConfirmed );
1060   // TODO: adapt HYDROGUI_PriorityWidget to process land covers
1061   /*if( isConfirmed )
1062     myLandCoverPriorityWidget->setObjects( getLandCovers() );
1063   else*/
1064     myLandCovers->undoLastMove();  
1065 }