Salome HOME
Merge remote-tracking branch 'origin/BR_LAND_COVER' into BR_v14_rc
[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 #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( createLandCoversPage() );
75   addPage( createZonesPage() );
76   addPage( createLandCoverZonesPage() );
77 }
78
79 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
80 {
81 }
82
83 void HYDROGUI_CalculationDlg::reset()
84 {
85   myObjectName->clear();
86   HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
87   myGeomObjects->setObjects(anObject2VisibleList);
88   myLandCovers->setObjects(anObject2VisibleList);
89   myPolylineName->clear();
90   myStricklerTableName->clear();
91   myAvailableGeomObjects->clear();
92   myAvailableLandCovers->clear();
93
94   // Activate the automatic mode
95   setMode( HYDROData_CalculationCase::AUTOMATIC );
96   setLandCoverMode( HYDROData_CalculationCase::AUTOMATIC );
97
98   // Reset the priority widget state
99   QList<Handle(HYDROData_Entity)> anObjects;
100   myPriorityWidget->setObjects( anObjects );
101   myLandCoverPriorityWidget->setObjects( anObjects );
102 }
103
104 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
105   QWizardPage* aPage = new QWizardPage( mainFrame() );
106   QFrame* aFrame = new QFrame( aPage );
107
108   // Splitter
109   mySplitter = new QSplitter(Qt::Vertical);
110
111   // Top of the page
112   QWidget* aTopContainer = new QWidget;
113    
114   // calculation name
115   myObjectName = new QLineEdit( aPage );
116   myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
117   myObjectName->setValidator( myValidator );
118
119   connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) );
120   connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) );
121
122   // polyline name
123   myPolylineName = new QComboBox( aPage );
124   connect( myPolylineName, SIGNAL( activated( const QString & ) ), 
125     SIGNAL( boundarySelected( const QString & ) ) );
126
127   // names labels
128   QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
129   QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
130
131   // mode selector (auto/manual)
132   QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
133
134   QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
135   QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
136
137   myModeButtons = new QButtonGroup( mainFrame() );
138   myModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
139   myModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
140   
141   QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
142   aModeSelectorLayout->setMargin( 5 );
143   aModeSelectorLayout->setSpacing( 5 );
144   aModeSelectorLayout->addWidget( anAutoRB );
145   aModeSelectorLayout->addWidget( aManualRB );
146   aModeGroup->setLayout( aModeSelectorLayout );
147
148   // geometry objects
149   QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ) );
150   myGeomObjects = new HYDROGUI_OrderedListWidget( aPage, 16 );
151   myGeomObjects->setHiddenObjectsShown(true);
152   myGeomObjects->setVisibilityIconShown(false);
153   myGeomObjects->setContentsMargins(QMargins());
154  
155   // included geometry objects
156   QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ) );
157   myAvailableGeomObjects = new QListWidget( aPage );
158   myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
159   myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
160   myAvailableGeomObjects->setViewMode( QListWidget::ListMode );
161   myAvailableGeomObjects->setSortingEnabled( true );
162
163   // buttons
164   QFrame* aBtnsFrame = new QFrame;
165   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
166   aBtnsLayout->setMargin( 5 );
167   aBtnsLayout->setSpacing( 5 );
168   aBtnsFrame->setLayout( aBtnsLayout );
169   QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
170   QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
171
172   // fill the butons frame with two buttons
173   aBtnsLayout->addWidget( anAddBtn );
174   aBtnsLayout->addWidget( aRemoveBtn );
175   aBtnsLayout->addStretch( 1 );
176   
177   // top of the page layout
178   
179   // objects frame
180   QFrame* anObjectsFrame = new QFrame( aPage );
181   anObjectsFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
182   QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
183   anObjsLayout->setMargin( 5 );
184   anObjsLayout->setSpacing( 5 );
185   anObjectsFrame->setLayout( anObjsLayout );
186   
187   // fill the objects frame with two lists, two labels and with buttons frame
188   anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter );
189   anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
190   anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0 );
191   anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
192   anObjsLayout->addWidget( myGeomObjects, 1, 2 );
193   
194   // fill the top of the page
195   QGridLayout* aTopLayout = new QGridLayout;
196   aTopLayout->setMargin( 5 );
197   aTopLayout->setSpacing( 5 );
198   aTopLayout->setVerticalSpacing( 10 );
199   aTopLayout->addWidget( aNameLabel,     0, 0, Qt::AlignHCenter );
200   aTopLayout->addWidget( myObjectName,   0, 1 );
201   aTopLayout->addWidget( aLimitsLabel,   1, 0, Qt::AlignHCenter );
202   aTopLayout->addWidget( myPolylineName, 1, 1 );
203   aTopLayout->addWidget( aModeGroup, 2, 0, 1, 2 );
204   aTopLayout->addWidget( anObjectsFrame, 3, 0, 1, 2 );
205
206   aTopContainer->setLayout( aTopLayout );
207
208   // add the top of the page to the splitter
209   mySplitter->insertWidget(0, aTopContainer);
210   mySplitter->setStretchFactor(0, 2);
211
212   // Bottom of the page
213   myPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
214
215   QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
216   QBoxLayout* aPriorityLayout = new QHBoxLayout;
217   aPriorityLayout->setMargin( 5 );
218   aPriorityLayout->setSpacing( 5 );
219   aPriorityLayout->addWidget( myPriorityWidget );
220   aPriorityGroup->setLayout( aPriorityLayout );
221
222   // add the bottom of the page to the splitter
223   mySplitter->insertWidget(1, aPriorityGroup);
224   mySplitter->setStretchFactor(1, 1);
225
226   // Page layout
227   QVBoxLayout* aPageLayout = new QVBoxLayout;
228   aPageLayout->setMargin( 5 );
229   aPageLayout->setSpacing( 5 );
230   aPageLayout->addWidget( mySplitter );
231
232   aPage->setLayout( aPageLayout );
233
234   // Create selector
235   if ( module() ) {
236     HYDROGUI_ListSelector* aListSelector = 
237       new HYDROGUI_ListSelector( myGeomObjects, module()->getApp()->selectionMgr() );
238     aListSelector->setAutoBlock( true );
239   }
240
241   // Connections
242   connect( myModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeMode( int ) ) );
243   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) );
244   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) );
245
246   connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) );
247
248   connect( myPriorityWidget, SIGNAL( ruleChanged() ), SLOT( onRuleChanged() ) );
249
250   return aPage;
251 }
252
253 QWizardPage* HYDROGUI_CalculationDlg::createGroupsPage() {
254   QWizardPage* aPage = new QWizardPage( mainFrame() );
255   QFrame* aFrame = new QFrame( aPage );
256
257   myGroups = new QListWidget( aPage );
258   myGroups->setSelectionMode( QListWidget::ExtendedSelection );
259   myGroups->setEditTriggers( QListWidget::NoEditTriggers );
260   myGroups->setViewMode( QListWidget::ListMode );
261   myGroups->setSortingEnabled( true );
262
263   myAvailableGroups = new QListWidget( aPage );
264   myAvailableGroups->setSelectionMode( QListWidget::ExtendedSelection );
265   myAvailableGroups->setEditTriggers( QListWidget::NoEditTriggers );
266   myAvailableGroups->setViewMode( QListWidget::ListMode );
267   myAvailableGroups->setSortingEnabled( true );
268
269   connect( myGroups, SIGNAL( itemSelectionChanged() ), 
270     SIGNAL( groupsSelected() ) );
271
272   QFrame* aGroupsFrame = new QFrame( aPage );
273   QGridLayout* aGroupsLayout = new QGridLayout( aGroupsFrame );
274   aGroupsLayout->setMargin( 5 );
275   aGroupsLayout->setSpacing( 5 );
276   aGroupsFrame->setLayout( aGroupsLayout );
277
278   QFrame* aBtnsFrame = new QFrame( aGroupsFrame );
279   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
280   aBtnsLayout->setMargin( 5 );
281   aBtnsLayout->setSpacing( 5 );
282   aBtnsFrame->setLayout( aBtnsLayout );
283   QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
284   QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
285
286   // Fill the butons frame with two buttons
287   aBtnsLayout->addWidget( anAddBtn );
288   aBtnsLayout->addWidget( aRemoveBtn );
289   aBtnsLayout->addStretch( 1 );
290
291   QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_GROUPS" ), aGroupsFrame );
292   QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_GROUPS" ), aGroupsFrame );
293
294   // Fill the objects frame with two lists, two labels and with buttons frame
295   aGroupsLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
296   aGroupsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
297   aGroupsLayout->addWidget( myAvailableGroups, 1, 0 );
298   aGroupsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
299   aGroupsLayout->addWidget( myGroups, 1, 2 );
300
301   // Fill the page
302   QGridLayout* aPageLayout = new QGridLayout( aPage );
303   aPageLayout->setMargin( 5 );
304   aPageLayout->setSpacing( 5 );
305   aPageLayout->setVerticalSpacing( 10 );
306   aPageLayout->addWidget( aGroupsFrame, 0, 0 );
307
308   aPage->setLayout( aPageLayout );
309
310   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addGroups() ) );
311   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeGroups() ) );
312
313   return aPage;
314 }
315
316 QWizardPage* HYDROGUI_CalculationDlg::createLandCoversPage() {
317   QWizardPage* aPage = new QWizardPage( mainFrame() );
318   QFrame* aFrame = new QFrame( aPage );
319
320   // Splitter
321   myLandCoverSplitter = new QSplitter(Qt::Vertical);
322
323   // Top of the page
324   QWidget* aTopContainer = new QWidget;
325    
326   // Combo-box to choose Strickler table name
327   QLabel* aStricklerTableLabel = new QLabel( tr( "STRICKLER_TABLE" ), aPage );
328   myStricklerTableName = new QComboBox( aPage );
329   myStricklerTableName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
330   connect( myStricklerTableName, SIGNAL( activated( const QString & ) ), 
331                                  SIGNAL( StricklerTableSelected( const QString & ) ) );
332
333   // Mode selector (auto/manual)
334   QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
335
336   QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
337   QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
338
339   myLandCoverModeButtons = new QButtonGroup( mainFrame() );
340   myLandCoverModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
341   myLandCoverModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
342   
343   QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
344   aModeSelectorLayout->setMargin( 5 );
345   aModeSelectorLayout->setSpacing( 5 );
346   aModeSelectorLayout->addWidget( anAutoRB );
347   aModeSelectorLayout->addWidget( aManualRB );
348   aModeGroup->setLayout( aModeSelectorLayout );
349
350   // Available land covers
351   QLabel* aLandCoversLabel = new QLabel( tr( "CALCULATION_REFERENCE_LAND_COVERS" ) );
352   myAvailableLandCovers = new QListWidget( aPage );
353   myAvailableLandCovers->setSelectionMode( QListWidget::ExtendedSelection );
354   myAvailableLandCovers->setEditTriggers( QListWidget::NoEditTriggers );
355   myAvailableLandCovers->setViewMode( QListWidget::ListMode );
356   myAvailableLandCovers->setSortingEnabled( true );
357  
358   // Included land covers
359   QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_LAND_COVERS" ) );
360   myLandCovers = new HYDROGUI_OrderedListWidget( aPage, 16 );
361   myLandCovers->setHiddenObjectsShown(true);
362   myLandCovers->setVisibilityIconShown(false);
363   myLandCovers->setContentsMargins(QMargins()); 
364
365   // Include/Exclude buttons
366   QFrame* aBtnsFrame = new QFrame;
367   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
368   aBtnsLayout->setMargin( 5 );
369   aBtnsLayout->setSpacing( 5 );
370   aBtnsFrame->setLayout( aBtnsLayout );
371   QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
372   QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
373
374   // Fill the butons frame with two buttons
375   aBtnsLayout->addWidget( anAddBtn );
376   aBtnsLayout->addWidget( aRemoveBtn );
377   aBtnsLayout->addStretch( 1 );
378   
379   // Land covers frame
380   QFrame* aLandCoversFrame = new QFrame( aPage );
381   aLandCoversFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
382   QGridLayout* aLandCoversLayout = new QGridLayout( aLandCoversFrame );
383   aLandCoversLayout->setMargin( 5 );
384   aLandCoversLayout->setSpacing( 5 );
385   aLandCoversFrame->setLayout( aLandCoversLayout );
386   
387   // Fill the land covers frame with two lists, two labels and with buttons frame
388   aLandCoversLayout->addWidget( aLandCoversLabel, 0, 0, Qt::AlignHCenter );
389   aLandCoversLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
390   aLandCoversLayout->addWidget( myAvailableLandCovers, 1, 0 );
391   aLandCoversLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
392   aLandCoversLayout->addWidget( myLandCovers, 1, 2 );
393   
394   // Fill the top layout of the page
395   QGridLayout* aTopLayout = new QGridLayout;
396   aTopLayout->setMargin( 5 );
397   aTopLayout->setSpacing( 5 );
398   aTopLayout->setVerticalSpacing( 10 );
399   aTopLayout->addWidget( aStricklerTableLabel, 0, 0, Qt::AlignHCenter );
400   aTopLayout->addWidget( myStricklerTableName, 0, 1 );
401   aTopLayout->addWidget( aModeGroup, 1, 0, 1, 2 );
402   aTopLayout->addWidget( aLandCoversFrame, 2, 0, 1, 2 );
403
404   aTopContainer->setLayout( aTopLayout );
405
406   // Add the top of the page to the splitter
407   myLandCoverSplitter->insertWidget(0, aTopContainer);
408   myLandCoverSplitter->setStretchFactor(0, 2);
409
410   // Bottom of the page
411   myLandCoverPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
412   HYDROGUI_PriorityTableModel* aModel = 
413     dynamic_cast<HYDROGUI_PriorityTableModel*>( myLandCoverPriorityWidget->getTable()->model() );
414   if ( aModel )
415     aModel->setColumnCount( 3 );
416
417   QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
418   QBoxLayout* aPriorityLayout = new QHBoxLayout;
419   aPriorityLayout->setMargin( 5 );
420   aPriorityLayout->setSpacing( 5 );
421   aPriorityLayout->addWidget( myLandCoverPriorityWidget );
422   aPriorityGroup->setLayout( aPriorityLayout );
423
424   // Add the bottom of the page to the splitter
425   myLandCoverSplitter->insertWidget(1, aPriorityGroup);
426   myLandCoverSplitter->setStretchFactor(1, 1);
427
428   // Page layout
429   QVBoxLayout* aPageLayout = new QVBoxLayout;
430   aPageLayout->setMargin( 5 );
431   aPageLayout->setSpacing( 5 );
432   aPageLayout->addWidget( myLandCoverSplitter );
433
434   aPage->setLayout( aPageLayout );
435
436   // Create selector
437   if ( module() ) {
438     HYDROGUI_ListSelector* aListSelector = 
439       new HYDROGUI_ListSelector( myLandCovers, module()->getApp()->selectionMgr() );
440     aListSelector->setAutoBlock( true );
441   }
442
443   // Connections
444   connect( myLandCoverModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeLandCoverMode( int ) ) );
445   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addLandCovers() ) );
446   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeLandCovers() ) );
447
448   connect( myLandCovers, SIGNAL( orderChanged() ), SLOT( onOrderLandCoverChanged() ) );
449
450   connect( myLandCoverPriorityWidget, SIGNAL( ruleChanged() ), SLOT( onLandCoverRuleChanged() ) );
451
452   return aPage;
453 }
454
455 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
456   QWizardPage* aPage = new QWizardPage( mainFrame() );
457   QFrame* aFrame = new QFrame( aPage );
458
459   QGridLayout* aLayout = new QGridLayout( aPage );
460
461   QLabel* aResultsOnGeomObjectsLabel = new QLabel( tr( "RESULTS_ON_GEOMETRY_OBJECTS" ), aFrame );
462   
463   myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
464   myBrowser->setAutoOpenLevel( 3 );
465   aLayout->setMargin( 5 );
466   aLayout->setSpacing( 5 );
467
468   aLayout->addWidget( aResultsOnGeomObjectsLabel, 0, 0 );
469   aLayout->addWidget( myBrowser, 1, 0, 1, 2 );
470
471   myBathymetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
472   myBathymetryChoice = new QComboBox( aFrame );
473
474   myBathymetryChoice->setVisible( false );
475   myBathymetryLabel->setVisible( false );
476
477   aLayout->addWidget( myBathymetryLabel, 2, 0 );
478   aLayout->addWidget( myBathymetryChoice, 2, 1 );
479
480   aPage->setLayout( aLayout );
481
482   connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
483   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
484   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
485   connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
486   connect( myBrowser, 
487       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
488       SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
489   connect( myBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewRegion() ) );
490
491   return aPage;
492 }
493
494 QWizardPage* HYDROGUI_CalculationDlg::createLandCoverZonesPage() {
495   QWizardPage* aPage = new QWizardPage( mainFrame() );
496   QFrame* aFrame = new QFrame( aPage );
497
498   QGridLayout* aLayout = new QGridLayout( aPage );
499   
500   QLabel* aResultsOnLandCoversLabel = new QLabel( tr( "RESULTS_ON_LAND_COVERS" ), aFrame );
501
502   myLandCoverBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage, true );
503   myLandCoverBrowser->setAutoOpenLevel( 3 );
504   aLayout->setMargin( 5 );
505   aLayout->setSpacing( 5 );
506
507   aLayout->addWidget( aResultsOnLandCoversLabel, 0, 0 );
508   aLayout->addWidget( myLandCoverBrowser, 1, 0, 1, 2 );
509
510   myStricklerTypeLabel = new QLabel( tr( "STRICKLER_TYPE" ), aFrame );
511   myStricklerTypeChoice = new QComboBox( aFrame );
512
513   myStricklerTypeLabel->setVisible( false );
514   myStricklerTypeChoice->setVisible( false );  
515
516   aLayout->addWidget( myStricklerTypeLabel, 2, 0 );
517   aLayout->addWidget( myStricklerTypeChoice, 2, 1 );
518
519   aPage->setLayout( aLayout );
520
521   // Connections
522   connect( myLandCoverBrowser, SIGNAL( dataChanged() ), SLOT( onDataLandCoverChanged() ) );
523   connect( myLandCoverBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
524   connect( myLandCoverBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onLandCoverZoneSelected( SUIT_DataObject* ) ) );
525   connect( myStricklerTypeChoice, SIGNAL( activated( int ) ), SLOT( onMergeStricklerTypeSelected( int ) ) );
526   connect( myLandCoverBrowser, 
527       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
528       SLOT( onLandCoverZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
529   connect( myLandCoverBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewLandCoverRegion() ) );
530
531   return aPage;
532 }
533
534
535 bool HYDROGUI_CalculationDlg::acceptCurrent() const
536 {
537   QString anErrorMsg;
538
539   if ( false /*myGeomObjects->count() == 0*/ )
540   {
541     anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
542   }
543
544   if ( !anErrorMsg.isEmpty() )
545   {
546     anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
547     
548     QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
549     SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
550   }
551
552   return anErrorMsg.isEmpty();
553 }
554
555 void HYDROGUI_CalculationDlg::onEmptyName()
556 {
557   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
558   QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
559   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
560 }
561
562 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
563 {
564   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
565   QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
566                      "\n" + tr( "INPUT_VALID_DATA" );
567   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
568 }
569
570 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList, 
571     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
572 {
573   QList<SUIT_DataObject*> aZonesList;
574   HYDROGUI_Zone* aZone;
575   // Get a list of dropped zones
576   for ( int i = 0; i < theList.length(); i++ )
577   {
578     aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
579     if ( aZone )
580     {
581       aZonesList.append( aZone );
582     }
583   }
584   if ( aZonesList.length() > 0 )
585   {
586     // Get the target region
587     HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
588     if ( aRegionsRoot )
589     {
590       // Create a new region
591       emit createRegion( aZonesList );
592     }
593     else
594     {
595       HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
596       if ( aRegion )
597       {
598         emit moveZones( theTargetParent, aZonesList, false );
599       }
600     }
601   }
602 }
603
604 void HYDROGUI_CalculationDlg::OnNewRegion()
605 {
606   emit createRegion( myBrowser->getSelected() );
607 }
608
609 void HYDROGUI_CalculationDlg::OnNewLandCoverRegion()
610 {
611   emit createLandCoverRegion( myLandCoverBrowser->getSelected() );
612 }
613
614 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
615 {
616   int aType = myBathymetryChoice->itemData( theIndex ).toInt();
617   QString aText = myBathymetryChoice->itemText( theIndex );
618   emit setMergeType( aType, aText );
619 }
620
621 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
622 {
623   bool doShow = false;
624   HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
625   if ( aZone )
626   {
627     doShow = aZone->isMergingNeed();
628   }
629
630   if ( doShow )
631   {
632     // Fill the merge type combo box
633     bool prevBlock = myBathymetryChoice->blockSignals( true );
634     myCurrentZone = aZone;
635     myBathymetryChoice->clear();
636     myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
637     myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
638     myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
639     QStringList aList = aZone->getObjects();
640     for ( int i = 0; i < aList.length(); i++ )
641     {
642       myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
643     }
644     // Select the current choice if any
645     int aCurIndex = 0;
646     switch ( aZone->getMergeType() )
647     {
648       case HYDROData_Zone::Merge_ZMIN:
649         aCurIndex = 1;
650         break;
651       case HYDROData_Zone::Merge_ZMAX:
652         aCurIndex = 2;
653         break;
654       case HYDROData_Zone::Merge_Object:
655         aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
656         break;
657       default:
658         aCurIndex = 0; // Select unknown by default
659     }
660     myBathymetryChoice->setCurrentIndex( aCurIndex );
661     myBathymetryChoice->blockSignals( prevBlock );
662   }
663
664   myBathymetryChoice->setVisible( doShow );
665   myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
666   myBathymetryLabel->setVisible( doShow );
667 }
668
669 void HYDROGUI_CalculationDlg::onLandCoverZoneSelected( SUIT_DataObject* theObject )
670 {
671   bool doShow = false;
672   HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
673   if ( aZone )
674   {
675     doShow = aZone->isMergingNeed();
676   }
677
678   if ( doShow )
679   {
680     // Fill the merge type combo box
681     bool prevBlock = myStricklerTypeChoice->blockSignals( true );
682     myCurrentZone = aZone;
683     myStricklerTypeChoice->clear();
684     myStricklerTypeChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
685     QStringList aList = aZone->getObjects();
686     for ( int i = 0; i < aList.length(); i++ )
687     {
688       myStricklerTypeChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
689     }
690     // Select the current choice if any
691     int aCurIndex = 0;
692     switch ( aZone->getMergeType() )
693     {
694       case HYDROData_Zone::Merge_Object:
695         aCurIndex = 1 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
696         break;
697       default:
698         aCurIndex = 0; // Select unknown by default
699     }
700     myStricklerTypeChoice->setCurrentIndex( aCurIndex );
701     myStricklerTypeChoice->blockSignals( prevBlock );
702   }
703
704   myStricklerTypeChoice->setVisible( doShow );
705   myStricklerTypeChoice->setEnabled( getLandCoverMode() == HYDROData_CalculationCase::MANUAL );
706   myStricklerTypeLabel->setVisible( doShow );
707 }
708
709 void HYDROGUI_CalculationDlg::onMergeStricklerTypeSelected( int theIndex )
710 {
711   int aType = myStricklerTypeChoice->itemData( theIndex ).toInt();
712   QString aText = myStricklerTypeChoice->itemText( theIndex );
713   emit setMergeStricklerType( aType, aText );
714 }
715
716 void HYDROGUI_CalculationDlg::onLandCoverZonesDropped( const QList<SUIT_DataObject*>& theList, 
717     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
718 {
719   QList<SUIT_DataObject*> aZonesList;
720   HYDROGUI_Zone* aZone;
721   // Get a list of dropped land cover zones
722   for ( int i = 0; i < theList.length(); i++ )
723   {
724     aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
725     if ( aZone )
726     {
727       aZonesList.append( aZone );
728     }
729   }
730   if ( aZonesList.length() > 0 )
731   {
732     // Get the target region
733     HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
734     if ( aRegionsRoot )
735     {
736       // Create a new region
737       emit createLandCoverRegion( aZonesList );
738     }
739     else
740     {
741       HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
742       if ( aRegion )
743       {
744         emit moveZones( theTargetParent, aZonesList, true );
745       }
746     }
747   }
748 }
749
750 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
751 {
752   myObjectName->setText( theName );
753 }
754
755 QString HYDROGUI_CalculationDlg::getObjectName() const
756 {
757   return myObjectName->text();
758 }
759
760 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
761 {
762   QList<QListWidgetItem*> aFoundItems;
763   int anIdx;
764   QListWidgetItem* anItem;
765
766   for ( int i = 0, n = theObjects.length(); i < n; ++i )
767   {
768     QString anObjName = theObjects.at( i );
769     aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
770     for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
771     {
772       anItem = aFoundItems.at( anIdx );
773       // Remove this object from available objects list
774       anItem = theSource->takeItem( theSource->row( anItem ) );
775       // Add the item to the included objects list
776       theDest->addItem( anItem );
777     }
778   }
779 }
780
781 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
782 {
783   QList<QListWidgetItem*> aFoundItems;
784   foreach ( const QString& anObjName, theObjects ) {
785     // Hide the object in the available objects list
786     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
787     foreach ( QListWidgetItem* anItem, aFoundItems ) {
788       anItem->setHidden( true );
789     }
790
791     // Add the object to the list of included objects
792     Handle(HYDROData_Entity) anObject = 
793       HYDROGUI_Tool::FindObjectByName( module(), anObjName );
794     myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
795   }
796
797   myPriorityWidget->setObjects( getGeometryObjects() );
798 }
799
800 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
801 {
802   QList<QListWidgetItem*> aFoundItems;
803   foreach ( const QString& anObjName, theObjects ) {
804     // Set visible the object in the available objects list
805     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
806     foreach ( QListWidgetItem* anItem, aFoundItems ) {
807       anItem->setHidden( false );
808     }
809
810     // Remove the object from the list of included objects
811     myGeomObjects->removeObjectByName( anObjName );
812   }
813
814   myPriorityWidget->setObjects( getGeometryObjects() );
815 }
816
817 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
818 {
819   bool isBlocked = myPolylineName->blockSignals( true );
820   myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
821   myPolylineName->blockSignals( isBlocked );
822 }
823
824 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
825 {
826   myPolylineName->clear();
827   myPolylineName->addItem( "", "" ); // No boundary item
828
829   for ( int i = 0, n = theObjects.length(); i < n; ++i )
830   {
831     myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
832   }
833 }
834
835 void HYDROGUI_CalculationDlg::setStricklerTableNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
836 {
837   myStricklerTableName->clear();
838
839   for ( int i = 0, n = theObjects.length(); i < n; ++i )
840   {
841     myStricklerTableName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
842   }
843 }
844
845 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
846 {
847   myAvailableGeomObjects->clear();
848
849   for ( int i = 0, n = theObjects.length(); i < n; ++i )
850   {
851     QString anObjName = theObjects.at( i );
852
853     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
854     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
855     aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
856   }
857 }
858
859 void HYDROGUI_CalculationDlg::setAllLandCovers( const QStringList& theObjects, const QStringList& theObjectsEntries )
860 {
861   myAvailableLandCovers->clear();
862
863   for ( int i = 0, n = theObjects.length(); i < n; ++i )
864   {
865     QString anObjName = theObjects.at( i );
866
867     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableLandCovers );
868     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
869     aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
870   }
871 }
872
873 QStringList getSelected( QListWidget* theWidget )
874 {
875   QStringList aResList;
876   QList<QListWidgetItem*> aList = theWidget->selectedItems();
877   for ( int i = 0, n = aList.length(); i < n; ++i )
878   {
879     aResList.append( aList.at( i )->text() );
880   }
881   return aResList;
882 }
883
884 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
885 {
886   return myGeomObjects->getSelectedNames();
887 }
888
889 QStringList HYDROGUI_CalculationDlg::getSelectedLandCovers() const
890 {
891   return myLandCovers->getSelectedNames();
892 }
893
894 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
895 {
896   return myGeomObjects->getAllNames();
897 }
898
899 QStringList HYDROGUI_CalculationDlg::getAllLandCovers() const
900 {
901   return myLandCovers->getAllNames();
902 }
903
904 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
905 {
906   return getSelected( myAvailableGeomObjects );
907 }
908
909 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableLandCovers() const
910 {
911   return getSelected( myAvailableLandCovers );
912 }
913
914 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
915 {
916   myEditedObject = theCase;
917   myValidator->setEditedObject( theCase );
918
919   // Build the calculation case subtree
920   module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject, false );
921
922   myBrowser->updateTree();
923   myBrowser->openLevels();
924   myBrowser->adjustColumnsWidth();
925   myBrowser->setAutoUpdate( true );
926   myBrowser->setUpdateModified( true );
927
928   // Build the calculation case subtree for Land Cover regions
929   module()->getDataModel()->buildCaseTree( myLandCoverBrowser->root(), myEditedObject, true );
930
931   myLandCoverBrowser->updateTree();
932   myLandCoverBrowser->openLevels();
933   myLandCoverBrowser->adjustColumnsWidth();
934   myLandCoverBrowser->setAutoUpdate( true );
935   myLandCoverBrowser->setUpdateModified( true );
936 }
937
938 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
939 {
940   return myCurrentZone;
941 }
942
943 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
944 {
945   SUIT_DataObject* aRoot = myBrowser->root();
946   module()->getDataModel()->updateObjectTree( myEditedObject );
947   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, false );
948   myBrowser->updateTree( aRoot );
949 }
950
951 void HYDROGUI_CalculationDlg::onDataChanged()
952 {
953   SUIT_DataObject* aRoot = myBrowser->root();
954   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, false );
955   myBrowser->updateTree( aRoot );
956 }
957
958 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
959 {
960   myAvailableGroups->clear();
961   myGroups->clear();
962   foreach( QString aGroup, theGroups )
963     myAvailableGroups->addItem( aGroup );
964 }
965
966 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
967 {
968   return getSelected( myGroups );
969 }
970
971 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
972 {
973   return getSelected( myAvailableGroups );
974 }
975
976 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
977 {
978   moveItems( myAvailableGroups, myGroups, theObjects );
979 }
980
981 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
982 {
983   moveItems( myGroups, myAvailableGroups, theObjects );
984 }
985
986 /**
987   Get creation mode.
988   @param theMode the mode
989 */
990 int HYDROGUI_CalculationDlg::getMode() const
991 {
992   return myModeButtons->checkedId();
993 }
994
995 /**
996   Set creation mode.
997   @param theMode the mode
998 */
999 void HYDROGUI_CalculationDlg::setMode( int theMode )
1000 {
1001   bool isBlocked = myModeButtons->blockSignals( true );
1002   myModeButtons->button( theMode )->setChecked( true );
1003   myModeButtons->blockSignals( isBlocked );
1004
1005   bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
1006
1007   myGeomObjects->setOrderingEnabled( isAuto );
1008   QWidget* aWidget = mySplitter->widget( 1 );
1009   if ( aWidget ) {
1010     aWidget->setVisible( isAuto );
1011   }
1012 }
1013
1014 /**
1015   Get creation mode for land covers panel.
1016   @param theMode the mode
1017 */
1018 int HYDROGUI_CalculationDlg::getLandCoverMode() const
1019 {
1020   return myLandCoverModeButtons->checkedId();
1021 }
1022
1023 /**
1024   Set creation mode for land cover panel.
1025   @param theMode the mode
1026 */
1027 void HYDROGUI_CalculationDlg::setLandCoverMode( int theMode )
1028 {
1029   bool isBlocked = myLandCoverModeButtons->blockSignals( true );
1030   myLandCoverModeButtons->button( theMode )->setChecked( true );
1031   myLandCoverModeButtons->blockSignals( isBlocked );
1032
1033   bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
1034
1035   myLandCovers->setOrderingEnabled( isAuto );
1036   QWidget* aWidget = myLandCoverSplitter->widget( 1 );
1037   if ( aWidget ) {
1038     aWidget->setVisible( isAuto );
1039   }
1040 }
1041
1042 /**
1043   Enable/disable zones drag'n'drop and renaming.
1044   @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
1045 */
1046 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
1047 {
1048   myBrowser->setReadOnly( !theIsEnabled );
1049 }
1050
1051 /**
1052   Enable/disable land covers drag'n'drop and renaming.
1053   @param theIsEnabled if true - land covers drag'n'drop and renaming will be enabled
1054 */
1055 void HYDROGUI_CalculationDlg::setEditLandCoverZonesEnabled( const bool theIsEnabled )
1056 {
1057   myLandCoverBrowser->setReadOnly( !theIsEnabled );
1058 }
1059
1060 /**
1061   Get included geometry objects.
1062   @return the list of geometry objects
1063  */
1064 QList<Handle(HYDROData_Entity)> HYDROGUI_CalculationDlg::getGeometryObjects()
1065 {
1066   QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
1067   QList<Handle(HYDROData_Entity)> anObjects;
1068
1069   foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
1070     Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
1071     if ( anObj.IsNull() ) {
1072       continue;
1073     }
1074
1075     anObjects << anObj;
1076   }
1077
1078   return anObjects;
1079 }
1080
1081 /**
1082   Get included land covers.
1083   @return the list of land covers
1084  */
1085 QList<Handle(HYDROData_Entity)> HYDROGUI_CalculationDlg::getLandCovers()
1086 {
1087   QList<Handle(HYDROData_Entity)> anEntities = myLandCovers->getObjects();
1088   QList<Handle(HYDROData_Entity)> aLandCovers;
1089
1090   foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
1091     Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
1092     if ( aLandCover.IsNull() ) {
1093       continue;
1094     }
1095
1096     aLandCovers << aLandCover;
1097   }
1098
1099   return aLandCovers;
1100 }
1101
1102 /**
1103   Get rules.
1104   @return the list of rules
1105  */
1106 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
1107 {
1108   return myPriorityWidget->getRules();
1109 }
1110
1111 /**
1112   Set rules.
1113   @param theRules the list of rules
1114  */
1115 void  HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
1116 {
1117   myPriorityWidget->setRules( theRules );
1118 }
1119
1120 /**
1121   Get rules defined for land covers.
1122   @return the list of rules
1123  */
1124 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getLandCoverRules() const
1125 {
1126   return myLandCoverPriorityWidget->getRules();
1127 }
1128
1129 /**
1130   Set rules for land covers.
1131   @param theRules the list of rules
1132  */
1133 void  HYDROGUI_CalculationDlg::setLandCoverRules( const HYDROData_ListOfRules& theRules ) const
1134 {
1135   myLandCoverPriorityWidget->setRules( theRules );
1136 }
1137
1138 /**
1139   Slot called when objects order is changed.
1140  */
1141 void HYDROGUI_CalculationDlg::onOrderChanged()
1142 {
1143   bool isConfirmed = true;
1144   emit orderChanged( isConfirmed );
1145   if( isConfirmed )
1146     myPriorityWidget->setObjects( getGeometryObjects() );
1147   else
1148     myGeomObjects->undoLastMove();
1149 }
1150
1151 /**
1152   Slot called when priority rule for geometry objects is changed.
1153  */
1154 void HYDROGUI_CalculationDlg::onRuleChanged()
1155 {
1156   bool isConfirmed = true;
1157   emit ruleChanged( isConfirmed );
1158   if( !isConfirmed )
1159     myPriorityWidget->undoLastChange();
1160 }
1161
1162 void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals )
1163 {
1164   bool isBlocked;
1165   if ( theBlockSignals )
1166     isBlocked = myStricklerTableName->blockSignals( true );
1167   
1168   myStricklerTableName->setCurrentIndex( myStricklerTableName->findText( theStricklerTableName ) );
1169
1170   if ( theBlockSignals )
1171     myStricklerTableName->blockSignals( isBlocked );
1172   else
1173     emit StricklerTableSelected( theStricklerTableName );
1174 }
1175
1176 void HYDROGUI_CalculationDlg::includeLandCovers( const QStringList& theLandCovers, bool theReset )
1177 {
1178   if ( theReset )
1179   {
1180     HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
1181     myLandCovers->setObjects(anObject2VisibleList);
1182   }
1183         
1184   QList<QListWidgetItem*> aFoundItems;
1185   foreach ( const QString& anObjName, theLandCovers ) {
1186     // Hide the land cover in the available land covers list
1187     aFoundItems = myAvailableLandCovers->findItems( anObjName, Qt::MatchExactly );
1188     foreach ( QListWidgetItem* anItem, aFoundItems ) {
1189       anItem->setHidden( true );
1190     }
1191
1192     // Add the land cover to the list of included objects
1193     Handle(HYDROData_Entity) anObject = 
1194       HYDROGUI_Tool::FindObjectByName( module(), anObjName );
1195     myLandCovers->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
1196   }
1197
1198   myLandCoverPriorityWidget->setObjects( getLandCovers() );
1199 }
1200
1201 void HYDROGUI_CalculationDlg::excludeLandCovers( const QStringList& theLandCovers )
1202 {
1203   QList<QListWidgetItem*> aFoundItems;
1204   foreach ( const QString& anObjName, theLandCovers ) {
1205     // Set visible the land cover in the available objects list
1206     aFoundItems = myAvailableLandCovers->findItems( anObjName, Qt::MatchExactly );
1207     foreach ( QListWidgetItem* anItem, aFoundItems ) {
1208       anItem->setHidden( false );
1209     }
1210
1211     // Remove the land cover from the list of included objects
1212     myLandCovers->removeObjectByName( anObjName );
1213   }
1214
1215   myLandCoverPriorityWidget->setObjects( getLandCovers() );
1216 }
1217
1218 void HYDROGUI_CalculationDlg::refreshLandCoverZonesBrowser()
1219 {
1220   SUIT_DataObject* aRoot = myLandCoverBrowser->root();
1221   module()->getDataModel()->updateObjectTree( myEditedObject );
1222   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, true );
1223   myLandCoverBrowser->updateTree( aRoot );
1224 }
1225
1226 /**
1227   Slot called when zones created on land covers are changed.
1228  */
1229 void HYDROGUI_CalculationDlg::onDataLandCoverChanged()
1230 {
1231   SUIT_DataObject* aRoot = myLandCoverBrowser->root();
1232   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, true );
1233   myLandCoverBrowser->updateTree( aRoot );
1234 }
1235
1236 /**
1237   Slot called when land covers order is changed.
1238  */
1239 void HYDROGUI_CalculationDlg::onOrderLandCoverChanged()
1240 {
1241   bool isConfirmed = true;
1242   emit orderLandCoverChanged( isConfirmed );
1243   if( isConfirmed )
1244     myLandCoverPriorityWidget->setObjects( getLandCovers() );
1245   else
1246     myLandCovers->undoLastMove();  
1247 }
1248
1249 /**
1250   Slot called when priority rule for land covers is changed.
1251  */
1252 void HYDROGUI_CalculationDlg::onLandCoverRuleChanged()
1253 {
1254   bool isConfirmed = true;
1255   emit ruleLandCoverChanged( isConfirmed );
1256   if( !isConfirmed )
1257     myLandCoverPriorityWidget->undoLastChange();
1258 }