Salome HOME
refs #640: correct width for non-georeferenced profile
[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   QPushButton* aRegenerateBtn = new QPushButton( tr( "REGENERATE_COLORS" ), this );
481   aLayout->addWidget( aRegenerateBtn, 3, 0 );
482
483   aPage->setLayout( aLayout );
484
485   connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
486   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
487   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
488   connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
489   connect( myBrowser, 
490       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
491       SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
492   connect( myBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewRegion() ) );
493   connect( aRegenerateBtn, SIGNAL( clicked() ), this, SIGNAL( regenerateColors() ) );
494   return aPage;
495 }
496
497 QWizardPage* HYDROGUI_CalculationDlg::createLandCoverZonesPage() {
498   QWizardPage* aPage = new QWizardPage( mainFrame() );
499   QFrame* aFrame = new QFrame( aPage );
500
501   QGridLayout* aLayout = new QGridLayout( aPage );
502   
503   QLabel* aResultsOnLandCoversLabel = new QLabel( tr( "RESULTS_ON_LAND_COVERS" ), aFrame );
504
505   myLandCoverBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage, true );
506   myLandCoverBrowser->setAutoOpenLevel( 3 );
507   aLayout->setMargin( 5 );
508   aLayout->setSpacing( 5 );
509
510   aLayout->addWidget( aResultsOnLandCoversLabel, 0, 0 );
511   aLayout->addWidget( myLandCoverBrowser, 1, 0, 1, 2 );
512
513   myStricklerTypeLabel = new QLabel( tr( "STRICKLER_TYPE" ), aFrame );
514   myStricklerTypeChoice = new QComboBox( aFrame );
515
516   myStricklerTypeLabel->setVisible( false );
517   myStricklerTypeChoice->setVisible( false );  
518
519   aLayout->addWidget( myStricklerTypeLabel, 2, 0 );
520   aLayout->addWidget( myStricklerTypeChoice, 2, 1 );
521
522   aPage->setLayout( aLayout );
523
524   // Connections
525   connect( myLandCoverBrowser, SIGNAL( dataChanged() ), SLOT( onDataLandCoverChanged() ) );
526   connect( myLandCoverBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
527   connect( myLandCoverBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onLandCoverZoneSelected( SUIT_DataObject* ) ) );
528   connect( myStricklerTypeChoice, SIGNAL( activated( int ) ), SLOT( onMergeStricklerTypeSelected( int ) ) );
529   connect( myLandCoverBrowser, 
530       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
531       SLOT( onLandCoverZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
532   connect( myLandCoverBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewLandCoverRegion() ) );
533
534   return aPage;
535 }
536
537
538 bool HYDROGUI_CalculationDlg::acceptCurrent() const
539 {
540   QString anErrorMsg;
541
542   if ( false /*myGeomObjects->count() == 0*/ )
543   {
544     anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
545   }
546
547   if ( !anErrorMsg.isEmpty() )
548   {
549     anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
550     
551     QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
552     SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
553   }
554
555   return anErrorMsg.isEmpty();
556 }
557
558 void HYDROGUI_CalculationDlg::onEmptyName()
559 {
560   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
561   QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
562   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
563 }
564
565 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
566 {
567   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
568   QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
569                      "\n" + tr( "INPUT_VALID_DATA" );
570   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
571 }
572
573 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList, 
574     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
575 {
576   QList<SUIT_DataObject*> aZonesList;
577   HYDROGUI_Zone* aZone;
578   // Get a list of dropped zones
579   for ( int i = 0; i < theList.length(); i++ )
580   {
581     aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
582     if ( aZone )
583     {
584       aZonesList.append( aZone );
585     }
586   }
587   if ( aZonesList.length() > 0 )
588   {
589     // Get the target region
590     HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
591     if ( aRegionsRoot )
592     {
593       // Create a new region
594       emit createRegion( aZonesList );
595     }
596     else
597     {
598       HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
599       if ( aRegion )
600       {
601         emit moveZones( theTargetParent, aZonesList, false );
602       }
603     }
604   }
605 }
606
607 void HYDROGUI_CalculationDlg::OnNewRegion()
608 {
609   emit createRegion( myBrowser->getSelected() );
610 }
611
612 void HYDROGUI_CalculationDlg::OnNewLandCoverRegion()
613 {
614   emit createLandCoverRegion( myLandCoverBrowser->getSelected() );
615 }
616
617 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
618 {
619   int aType = myBathymetryChoice->itemData( theIndex ).toInt();
620   QString aText = myBathymetryChoice->itemText( theIndex );
621   emit setMergeType( aType, aText );
622 }
623
624 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
625 {
626   bool doShow = false;
627   HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
628   if ( aZone )
629   {
630     doShow = aZone->isMergingNeed();
631   }
632
633   if ( doShow )
634   {
635     // Fill the merge type combo box
636     bool prevBlock = myBathymetryChoice->blockSignals( true );
637     myCurrentZone = aZone;
638     myBathymetryChoice->clear();
639     myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
640     myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
641     myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
642     QStringList aList = aZone->getObjects();
643     for ( int i = 0; i < aList.length(); i++ )
644     {
645       myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
646     }
647     // Select the current choice if any
648     int aCurIndex = 0;
649     switch ( aZone->getMergeType() )
650     {
651       case HYDROData_Zone::Merge_ZMIN:
652         aCurIndex = 1;
653         break;
654       case HYDROData_Zone::Merge_ZMAX:
655         aCurIndex = 2;
656         break;
657       case HYDROData_Zone::Merge_Object:
658         aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
659         break;
660       default:
661         aCurIndex = 0; // Select unknown by default
662     }
663     myBathymetryChoice->setCurrentIndex( aCurIndex );
664     myBathymetryChoice->blockSignals( prevBlock );
665   }
666
667   myBathymetryChoice->setVisible( doShow );
668   myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
669   myBathymetryLabel->setVisible( doShow );
670 }
671
672 void HYDROGUI_CalculationDlg::onLandCoverZoneSelected( SUIT_DataObject* theObject )
673 {
674   bool doShow = false;
675   HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
676   if ( aZone )
677   {
678     doShow = aZone->isMergingNeed();
679   }
680
681   if ( doShow )
682   {
683     // Fill the merge type combo box
684     bool prevBlock = myStricklerTypeChoice->blockSignals( true );
685     myCurrentZone = aZone;
686     myStricklerTypeChoice->clear();
687     myStricklerTypeChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
688     QStringList aList = aZone->getObjects();
689     for ( int i = 0; i < aList.length(); i++ )
690     {
691       myStricklerTypeChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
692     }
693     // Select the current choice if any
694     int aCurIndex = 0;
695     switch ( aZone->getMergeType() )
696     {
697       case HYDROData_Zone::Merge_Object:
698         aCurIndex = 1 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
699         break;
700       default:
701         aCurIndex = 0; // Select unknown by default
702     }
703     myStricklerTypeChoice->setCurrentIndex( aCurIndex );
704     myStricklerTypeChoice->blockSignals( prevBlock );
705   }
706
707   myStricklerTypeChoice->setVisible( doShow );
708   myStricklerTypeChoice->setEnabled( getLandCoverMode() == HYDROData_CalculationCase::MANUAL );
709   myStricklerTypeLabel->setVisible( doShow );
710 }
711
712 void HYDROGUI_CalculationDlg::onMergeStricklerTypeSelected( int theIndex )
713 {
714   int aType = myStricklerTypeChoice->itemData( theIndex ).toInt();
715   QString aText = myStricklerTypeChoice->itemText( theIndex );
716   emit setMergeStricklerType( aType, aText );
717 }
718
719 void HYDROGUI_CalculationDlg::onLandCoverZonesDropped( const QList<SUIT_DataObject*>& theList, 
720     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
721 {
722   QList<SUIT_DataObject*> aZonesList;
723   HYDROGUI_Zone* aZone;
724   // Get a list of dropped land cover zones
725   for ( int i = 0; i < theList.length(); i++ )
726   {
727     aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
728     if ( aZone )
729     {
730       aZonesList.append( aZone );
731     }
732   }
733   if ( aZonesList.length() > 0 )
734   {
735     // Get the target region
736     HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
737     if ( aRegionsRoot )
738     {
739       // Create a new region
740       emit createLandCoverRegion( aZonesList );
741     }
742     else
743     {
744       HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
745       if ( aRegion )
746       {
747         emit moveZones( theTargetParent, aZonesList, true );
748       }
749     }
750   }
751 }
752
753 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
754 {
755   myObjectName->setText( theName );
756 }
757
758 QString HYDROGUI_CalculationDlg::getObjectName() const
759 {
760   return myObjectName->text();
761 }
762
763 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
764 {
765   QList<QListWidgetItem*> aFoundItems;
766   int anIdx;
767   QListWidgetItem* anItem;
768
769   for ( int i = 0, n = theObjects.length(); i < n; ++i )
770   {
771     QString anObjName = theObjects.at( i );
772     aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
773     for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
774     {
775       anItem = aFoundItems.at( anIdx );
776       // Remove this object from available objects list
777       anItem = theSource->takeItem( theSource->row( anItem ) );
778       // Add the item to the included objects list
779       theDest->addItem( anItem );
780     }
781   }
782 }
783
784 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
785 {
786   QList<QListWidgetItem*> aFoundItems;
787   foreach ( const QString& anObjName, theObjects ) {
788     // Hide the object in the available objects list
789     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
790     foreach ( QListWidgetItem* anItem, aFoundItems ) {
791       anItem->setHidden( true );
792     }
793
794     // Add the object to the list of included objects
795     Handle(HYDROData_Entity) anObject = 
796       HYDROGUI_Tool::FindObjectByName( module(), anObjName );
797     myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
798   }
799
800   myPriorityWidget->setObjects( getGeometryObjects() );
801 }
802
803 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
804 {
805   QList<QListWidgetItem*> aFoundItems;
806   foreach ( const QString& anObjName, theObjects ) {
807     // Set visible the object in the available objects list
808     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
809     foreach ( QListWidgetItem* anItem, aFoundItems ) {
810       anItem->setHidden( false );
811     }
812
813     // Remove the object from the list of included objects
814     myGeomObjects->removeObjectByName( anObjName );
815   }
816
817   myPriorityWidget->setObjects( getGeometryObjects() );
818 }
819
820 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
821 {
822   bool isBlocked = myPolylineName->blockSignals( true );
823   myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
824   myPolylineName->blockSignals( isBlocked );
825 }
826
827 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
828 {
829   myPolylineName->clear();
830   myPolylineName->addItem( "", "" ); // No boundary item
831
832   for ( int i = 0, n = theObjects.length(); i < n; ++i )
833   {
834     myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
835   }
836 }
837
838 void HYDROGUI_CalculationDlg::setStricklerTableNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
839 {
840   myStricklerTableName->clear();
841
842   for ( int i = 0, n = theObjects.length(); i < n; ++i )
843   {
844     myStricklerTableName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
845   }
846 }
847
848 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
849 {
850   myAvailableGeomObjects->clear();
851
852   for ( int i = 0, n = theObjects.length(); i < n; ++i )
853   {
854     QString anObjName = theObjects.at( i );
855
856     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
857     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
858     aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
859   }
860 }
861
862 void HYDROGUI_CalculationDlg::setAllLandCovers( const QStringList& theObjects, const QStringList& theObjectsEntries )
863 {
864   myAvailableLandCovers->clear();
865
866   for ( int i = 0, n = theObjects.length(); i < n; ++i )
867   {
868     QString anObjName = theObjects.at( i );
869
870     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableLandCovers );
871     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
872     aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
873   }
874 }
875
876 QStringList getSelected( QListWidget* theWidget )
877 {
878   QStringList aResList;
879   QList<QListWidgetItem*> aList = theWidget->selectedItems();
880   for ( int i = 0, n = aList.length(); i < n; ++i )
881   {
882     aResList.append( aList.at( i )->text() );
883   }
884   return aResList;
885 }
886
887 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
888 {
889   return myGeomObjects->getSelectedNames();
890 }
891
892 QStringList HYDROGUI_CalculationDlg::getSelectedLandCovers() const
893 {
894   return myLandCovers->getSelectedNames();
895 }
896
897 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
898 {
899   return myGeomObjects->getAllNames();
900 }
901
902 QStringList HYDROGUI_CalculationDlg::getAllLandCovers() const
903 {
904   return myLandCovers->getAllNames();
905 }
906
907 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
908 {
909   return getSelected( myAvailableGeomObjects );
910 }
911
912 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableLandCovers() const
913 {
914   return getSelected( myAvailableLandCovers );
915 }
916
917 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
918 {
919   myEditedObject = theCase;
920   myValidator->setEditedObject( theCase );
921
922   // Build the calculation case subtree
923   module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject, false );
924
925   myBrowser->updateTree();
926   myBrowser->openLevels();
927   myBrowser->adjustColumnsWidth();
928   myBrowser->setAutoUpdate( true );
929   myBrowser->setUpdateModified( true );
930
931   // Build the calculation case subtree for Land Cover regions
932   module()->getDataModel()->buildCaseTree( myLandCoverBrowser->root(), myEditedObject, true );
933
934   myLandCoverBrowser->updateTree();
935   myLandCoverBrowser->openLevels();
936   myLandCoverBrowser->adjustColumnsWidth();
937   myLandCoverBrowser->setAutoUpdate( true );
938   myLandCoverBrowser->setUpdateModified( true );
939 }
940
941 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
942 {
943   return myCurrentZone;
944 }
945
946 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
947 {
948   SUIT_DataObject* aRoot = myBrowser->root();
949   module()->getDataModel()->updateObjectTree( myEditedObject );
950   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, false );
951   myBrowser->updateTree( aRoot );
952 }
953
954 void HYDROGUI_CalculationDlg::onDataChanged()
955 {
956   SUIT_DataObject* aRoot = myBrowser->root();
957   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, false );
958   myBrowser->updateTree( aRoot );
959 }
960
961 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
962 {
963   myAvailableGroups->clear();
964   myGroups->clear();
965   foreach( QString aGroup, theGroups )
966     myAvailableGroups->addItem( aGroup );
967 }
968
969 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
970 {
971   return getSelected( myGroups );
972 }
973
974 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
975 {
976   return getSelected( myAvailableGroups );
977 }
978
979 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
980 {
981   moveItems( myAvailableGroups, myGroups, theObjects );
982 }
983
984 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
985 {
986   moveItems( myGroups, myAvailableGroups, theObjects );
987 }
988
989 /**
990   Get creation mode.
991   @param theMode the mode
992 */
993 int HYDROGUI_CalculationDlg::getMode() const
994 {
995   return myModeButtons->checkedId();
996 }
997
998 /**
999   Set creation mode.
1000   @param theMode the mode
1001 */
1002 void HYDROGUI_CalculationDlg::setMode( int theMode )
1003 {
1004   bool isBlocked = myModeButtons->blockSignals( true );
1005   myModeButtons->button( theMode )->setChecked( true );
1006   myModeButtons->blockSignals( isBlocked );
1007
1008   bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
1009
1010   myGeomObjects->setOrderingEnabled( isAuto );
1011   QWidget* aWidget = mySplitter->widget( 1 );
1012   if ( aWidget ) {
1013     aWidget->setVisible( isAuto );
1014   }
1015 }
1016
1017 /**
1018   Get creation mode for land covers panel.
1019   @param theMode the mode
1020 */
1021 int HYDROGUI_CalculationDlg::getLandCoverMode() const
1022 {
1023   return myLandCoverModeButtons->checkedId();
1024 }
1025
1026 /**
1027   Set creation mode for land cover panel.
1028   @param theMode the mode
1029 */
1030 void HYDROGUI_CalculationDlg::setLandCoverMode( int theMode )
1031 {
1032   bool isBlocked = myLandCoverModeButtons->blockSignals( true );
1033   myLandCoverModeButtons->button( theMode )->setChecked( true );
1034   myLandCoverModeButtons->blockSignals( isBlocked );
1035
1036   bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
1037
1038   myLandCovers->setOrderingEnabled( isAuto );
1039   QWidget* aWidget = myLandCoverSplitter->widget( 1 );
1040   if ( aWidget ) {
1041     aWidget->setVisible( isAuto );
1042   }
1043 }
1044
1045 /**
1046   Enable/disable zones drag'n'drop and renaming.
1047   @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
1048 */
1049 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
1050 {
1051   myBrowser->setReadOnly( !theIsEnabled );
1052 }
1053
1054 /**
1055   Enable/disable land covers drag'n'drop and renaming.
1056   @param theIsEnabled if true - land covers drag'n'drop and renaming will be enabled
1057 */
1058 void HYDROGUI_CalculationDlg::setEditLandCoverZonesEnabled( const bool theIsEnabled )
1059 {
1060   myLandCoverBrowser->setReadOnly( !theIsEnabled );
1061 }
1062
1063 /**
1064   Get included geometry objects.
1065   @return the list of geometry objects
1066  */
1067 QList<Handle(HYDROData_Entity)> HYDROGUI_CalculationDlg::getGeometryObjects()
1068 {
1069   QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
1070   QList<Handle(HYDROData_Entity)> anObjects;
1071
1072   foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
1073     Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
1074     if ( anObj.IsNull() ) {
1075       continue;
1076     }
1077
1078     anObjects << anObj;
1079   }
1080
1081   return anObjects;
1082 }
1083
1084 /**
1085   Get included land covers.
1086   @return the list of land covers
1087  */
1088 QList<Handle(HYDROData_Entity)> HYDROGUI_CalculationDlg::getLandCovers()
1089 {
1090   QList<Handle(HYDROData_Entity)> anEntities = myLandCovers->getObjects();
1091   QList<Handle(HYDROData_Entity)> aLandCovers;
1092
1093   foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
1094     Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
1095     if ( aLandCover.IsNull() ) {
1096       continue;
1097     }
1098
1099     aLandCovers << aLandCover;
1100   }
1101
1102   return aLandCovers;
1103 }
1104
1105 /**
1106   Get rules.
1107   @return the list of rules
1108  */
1109 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
1110 {
1111   return myPriorityWidget->getRules();
1112 }
1113
1114 /**
1115   Set rules.
1116   @param theRules the list of rules
1117  */
1118 void  HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
1119 {
1120   myPriorityWidget->setRules( theRules );
1121 }
1122
1123 /**
1124   Get rules defined for land covers.
1125   @return the list of rules
1126  */
1127 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getLandCoverRules() const
1128 {
1129   return myLandCoverPriorityWidget->getRules();
1130 }
1131
1132 /**
1133   Set rules for land covers.
1134   @param theRules the list of rules
1135  */
1136 void  HYDROGUI_CalculationDlg::setLandCoverRules( const HYDROData_ListOfRules& theRules ) const
1137 {
1138   myLandCoverPriorityWidget->setRules( theRules );
1139 }
1140
1141 /**
1142   Slot called when objects order is changed.
1143  */
1144 void HYDROGUI_CalculationDlg::onOrderChanged()
1145 {
1146   bool isConfirmed = true;
1147   emit orderChanged( isConfirmed );
1148   if( isConfirmed )
1149     myPriorityWidget->setObjects( getGeometryObjects() );
1150   else
1151     myGeomObjects->undoLastMove();
1152 }
1153
1154 /**
1155   Slot called when priority rule for geometry objects is changed.
1156  */
1157 void HYDROGUI_CalculationDlg::onRuleChanged()
1158 {
1159   bool isConfirmed = true;
1160   emit ruleChanged( isConfirmed );
1161   if( !isConfirmed )
1162     myPriorityWidget->undoLastChange();
1163 }
1164
1165 void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals )
1166 {
1167   bool isBlocked;
1168   if ( theBlockSignals )
1169     isBlocked = myStricklerTableName->blockSignals( true );
1170   
1171   myStricklerTableName->setCurrentIndex( myStricklerTableName->findText( theStricklerTableName ) );
1172
1173   if ( theBlockSignals )
1174     myStricklerTableName->blockSignals( isBlocked );
1175   else
1176     emit StricklerTableSelected( theStricklerTableName );
1177 }
1178
1179 void HYDROGUI_CalculationDlg::includeLandCovers( const QStringList& theLandCovers, bool theReset )
1180 {
1181   if ( theReset )
1182   {
1183     HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
1184     myLandCovers->setObjects(anObject2VisibleList);
1185   }
1186         
1187   QList<QListWidgetItem*> aFoundItems;
1188   foreach ( const QString& anObjName, theLandCovers ) {
1189     // Hide the land cover in the available land covers list
1190     aFoundItems = myAvailableLandCovers->findItems( anObjName, Qt::MatchExactly );
1191     foreach ( QListWidgetItem* anItem, aFoundItems ) {
1192       anItem->setHidden( true );
1193     }
1194
1195     // Add the land cover to the list of included objects
1196     Handle(HYDROData_Entity) anObject = 
1197       HYDROGUI_Tool::FindObjectByName( module(), anObjName );
1198     myLandCovers->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
1199   }
1200
1201   myLandCoverPriorityWidget->setObjects( getLandCovers() );
1202 }
1203
1204 void HYDROGUI_CalculationDlg::excludeLandCovers( const QStringList& theLandCovers )
1205 {
1206   QList<QListWidgetItem*> aFoundItems;
1207   foreach ( const QString& anObjName, theLandCovers ) {
1208     // Set visible the land cover in the available objects list
1209     aFoundItems = myAvailableLandCovers->findItems( anObjName, Qt::MatchExactly );
1210     foreach ( QListWidgetItem* anItem, aFoundItems ) {
1211       anItem->setHidden( false );
1212     }
1213
1214     // Remove the land cover from the list of included objects
1215     myLandCovers->removeObjectByName( anObjName );
1216   }
1217
1218   myLandCoverPriorityWidget->setObjects( getLandCovers() );
1219 }
1220
1221 void HYDROGUI_CalculationDlg::refreshLandCoverZonesBrowser()
1222 {
1223   SUIT_DataObject* aRoot = myLandCoverBrowser->root();
1224   module()->getDataModel()->updateObjectTree( myEditedObject );
1225   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, true );
1226   myLandCoverBrowser->updateTree( aRoot );
1227 }
1228
1229 /**
1230   Slot called when zones created on land covers are changed.
1231  */
1232 void HYDROGUI_CalculationDlg::onDataLandCoverChanged()
1233 {
1234   SUIT_DataObject* aRoot = myLandCoverBrowser->root();
1235   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, true );
1236   myLandCoverBrowser->updateTree( aRoot );
1237 }
1238
1239 /**
1240   Slot called when land covers order is changed.
1241  */
1242 void HYDROGUI_CalculationDlg::onOrderLandCoverChanged()
1243 {
1244   bool isConfirmed = true;
1245   emit orderLandCoverChanged( isConfirmed );
1246   if( isConfirmed )
1247     myLandCoverPriorityWidget->setObjects( getLandCovers() );
1248   else
1249     myLandCovers->undoLastMove();  
1250 }
1251
1252 /**
1253   Slot called when priority rule for land covers is changed.
1254  */
1255 void HYDROGUI_CalculationDlg::onLandCoverRuleChanged()
1256 {
1257   bool isConfirmed = true;
1258   emit ruleLandCoverChanged( isConfirmed );
1259   if( !isConfirmed )
1260     myLandCoverPriorityWidget->undoLastChange();
1261 }