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