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