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