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