Salome HOME
Bug fix.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_CalculationDlg.h"
24
25 #include "HYDROGUI_ObjSelector.h"
26 #include "HYDROGUI_Tool.h"
27 #include "HYDROGUI_DataBrowser.h"
28 #include "HYDROGUI_DataModel.h"
29 #include "HYDROGUI_ListSelector.h"
30 #include "HYDROGUI_Module.h"
31 #include "HYDROGUI_DataObject.h"
32 #include "HYDROGUI_NameValidator.h"
33 #include "HYDROGUI_Region.h"
34 #include "HYDROGUI_Zone.h"
35 #include "HYDROGUI_OrderedListWidget.h"
36 #include "HYDROGUI_PriorityWidget.h"
37
38 #include <HYDROData_Document.h>
39 #include <HYDROData_Entity.h>
40
41 #include <CAM_Application.h>
42 #include <LightApp_DataObject.h>
43
44 #include <SUIT_DataObject.h>
45 #include <SUIT_FileDlg.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_Study.h>
49
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
52 #include <SUIT_Desktop.h>
53 #include <SUIT_MessageBox.h>
54
55 #include <QButtonGroup>
56 #include <QComboBox>
57 #include <QGroupBox>
58 #include <QLabel>
59 #include <QLayout>
60 #include <QLineEdit>
61 #include <QListWidget>
62 #include <QPicture>
63 #include <QPushButton>
64 #include <QRadioButton>
65 #include <QSplitter>
66 #include <QTableWidget>
67 #include <QToolButton>
68 #include <QTreeView>
69 #include <QWizardPage>
70
71
72 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
73 : HYDROGUI_Wizard( theModule, theTitle )
74 {
75   addPage( createObjectsPage() );
76   addPage( createGroupsPage() );
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   myAvailableGeomObjects->clear();
91
92   // Activate the automatic mode
93   setMode( HYDROData_CalculationCase::AUTOMATIC );
94
95   // Reset the priority widget state
96   QList<Handle(HYDROData_Object)> anObjects;
97   myPriorityWidget->setObjects( anObjects );
98 }
99
100 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
101   QWizardPage* aPage = new QWizardPage( mainFrame() );
102   QFrame* aFrame = new QFrame( aPage );
103
104   // Splitter
105   mySplitter = new QSplitter(Qt::Vertical);
106
107   // Top of the page
108   QWidget* aTopContainer = new QWidget;
109    
110   // calculation name
111   myObjectName = new QLineEdit( aPage );
112   myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
113   myObjectName->setValidator( myValidator );
114
115   connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) );
116   connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) );
117
118   // polyline name
119   myPolylineName = new QComboBox( aPage );
120   connect( myPolylineName, SIGNAL( activated( const QString & ) ), 
121     SIGNAL( boundarySelected( const QString & ) ) );
122
123   // names labels
124   QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
125   QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
126
127   // mode selector (auto/manual)
128   QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
129
130   QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
131   QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
132
133   myModeButtons = new QButtonGroup( mainFrame() );
134   myModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
135   myModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
136   
137   QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
138   aModeSelectorLayout->setMargin( 5 );
139   aModeSelectorLayout->setSpacing( 5 );
140   aModeSelectorLayout->addWidget( anAutoRB );
141   aModeSelectorLayout->addWidget( aManualRB );
142   aModeGroup->setLayout( aModeSelectorLayout );
143
144   // geometry objects
145   QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ) );
146   myGeomObjects = new HYDROGUI_OrderedListWidget( aPage, 16 );
147   myGeomObjects->setHiddenObjectsShown(true);
148   myGeomObjects->setVisibilityIconShown(false);
149   myGeomObjects->setContentsMargins(QMargins());
150  
151   // included geometry objects
152   QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ) );
153   myAvailableGeomObjects = new QListWidget( aPage );
154   myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
155   myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
156   myAvailableGeomObjects->setViewMode( QListWidget::ListMode );
157   myAvailableGeomObjects->setSortingEnabled( true );
158
159   // buttons
160   QFrame* aBtnsFrame = new QFrame;
161   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
162   aBtnsLayout->setMargin( 5 );
163   aBtnsLayout->setSpacing( 5 );
164   aBtnsFrame->setLayout( aBtnsLayout );
165   QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
166   QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
167
168   // fill the butons frame with two buttons
169   aBtnsLayout->addWidget( anAddBtn );
170   aBtnsLayout->addWidget( aRemoveBtn );
171   aBtnsLayout->addStretch( 1 );
172   
173   // top of the page layout
174   
175   // objects frame
176   QFrame* anObjectsFrame = new QFrame( aPage );
177   anObjectsFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
178   QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
179   anObjsLayout->setMargin( 5 );
180   anObjsLayout->setSpacing( 5 );
181   anObjectsFrame->setLayout( anObjsLayout );
182   
183   // fill the objects frame with two lists, two labels and with buttons frame
184   anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter );
185   anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
186   anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0, Qt::AlignHCenter );
187   anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
188   anObjsLayout->addWidget( myGeomObjects, 1, 2, Qt::AlignHCenter );
189   
190   // fill the top of the page
191   QGridLayout* aTopLayout = new QGridLayout;
192   aTopLayout->setMargin( 5 );
193   aTopLayout->setSpacing( 5 );
194   aTopLayout->setVerticalSpacing( 10 );
195   aTopLayout->addWidget( aNameLabel,     0, 0, Qt::AlignHCenter );
196   aTopLayout->addWidget( myObjectName,   0, 1 );
197   aTopLayout->addWidget( aLimitsLabel,   1, 0, Qt::AlignHCenter );
198   aTopLayout->addWidget( myPolylineName, 1, 1 );
199   aTopLayout->addWidget( aModeGroup, 2, 0, 1, 2 );
200   aTopLayout->addWidget( anObjectsFrame, 3, 0, 1, 2, Qt::AlignHCenter );
201
202   aTopContainer->setLayout( aTopLayout );
203
204   // add the top of the page to the splitter
205   mySplitter->insertWidget(0, aTopContainer);
206   mySplitter->setStretchFactor(0, 2);
207
208   // Bottom of the page
209   myPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
210
211   QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
212   QBoxLayout* aPriorityLayout = new QHBoxLayout;
213   aPriorityLayout->setMargin( 5 );
214   aPriorityLayout->setSpacing( 5 );
215   aPriorityLayout->addWidget( myPriorityWidget );
216   aPriorityGroup->setLayout( aPriorityLayout );
217
218   // add the bottom of the page to the splitter
219   mySplitter->insertWidget(1, aPriorityGroup);
220   mySplitter->setStretchFactor(1, 1);
221
222   // Page layout
223   QVBoxLayout* aPageLayout = new QVBoxLayout;
224   aPageLayout->setMargin( 5 );
225   aPageLayout->setSpacing( 5 );
226   aPageLayout->addWidget( mySplitter );
227
228   aPage->setLayout( aPageLayout );
229
230   // Create selector
231   if ( module() ) {
232     HYDROGUI_ListSelector* aListSelector = 
233       new HYDROGUI_ListSelector( myGeomObjects, module()->getApp()->selectionMgr() );
234     aListSelector->setAutoBlock( true );
235   }
236
237   // Connections
238   connect( myModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeMode( int ) ) );
239   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) );
240   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) );
241
242   return aPage;
243 }
244
245 QWizardPage* HYDROGUI_CalculationDlg::createGroupsPage() {
246   QWizardPage* aPage = new QWizardPage( mainFrame() );
247   QFrame* aFrame = new QFrame( aPage );
248
249   myGroups = new QListWidget( aPage );
250   myGroups->setSelectionMode( QListWidget::ExtendedSelection );
251   myGroups->setEditTriggers( QListWidget::NoEditTriggers );
252   myGroups->setViewMode( QListWidget::ListMode );
253   myGroups->setSortingEnabled( true );
254
255   myAvailableGroups = new QListWidget( aPage );
256   myAvailableGroups->setSelectionMode( QListWidget::ExtendedSelection );
257   myAvailableGroups->setEditTriggers( QListWidget::NoEditTriggers );
258   myAvailableGroups->setViewMode( QListWidget::ListMode );
259   myAvailableGroups->setSortingEnabled( true );
260
261   connect( myGroups, SIGNAL( itemSelectionChanged() ), 
262     SIGNAL( groupsSelected() ) );
263
264   QFrame* aGroupsFrame = new QFrame( aPage );
265   QGridLayout* aGroupsLayout = new QGridLayout( aGroupsFrame );
266   aGroupsLayout->setMargin( 5 );
267   aGroupsLayout->setSpacing( 5 );
268   aGroupsFrame->setLayout( aGroupsLayout );
269
270   QFrame* aBtnsFrame = new QFrame( aGroupsFrame );
271   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
272   aBtnsLayout->setMargin( 5 );
273   aBtnsLayout->setSpacing( 5 );
274   aBtnsFrame->setLayout( aBtnsLayout );
275   QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
276   QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
277
278   // Fill the butons frame with two buttons
279   aBtnsLayout->addWidget( anAddBtn );
280   aBtnsLayout->addWidget( aRemoveBtn );
281   aBtnsLayout->addStretch( 1 );
282
283   QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_GROUPS" ), aGroupsFrame );
284   QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_GROUPS" ), aGroupsFrame );
285
286   // Fill the objects frame with two lists, two labels and with buttons frame
287   aGroupsLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
288   aGroupsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
289   aGroupsLayout->addWidget( myAvailableGroups, 1, 0, Qt::AlignHCenter );
290   aGroupsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
291   aGroupsLayout->addWidget( myGroups, 1, 2, Qt::AlignHCenter );
292
293   // Fill the page
294   QGridLayout* aPageLayout = new QGridLayout( aPage );
295   aPageLayout->setMargin( 5 );
296   aPageLayout->setSpacing( 5 );
297   aPageLayout->setVerticalSpacing( 10 );
298   aPageLayout->addWidget( aGroupsFrame, 0, 0, Qt::AlignHCenter );
299
300   aPage->setLayout( aPageLayout );
301
302   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addGroups() ) );
303   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeGroups() ) );
304
305   return aPage;
306 }
307
308 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
309   QWizardPage* aPage = new QWizardPage( mainFrame() );
310   QFrame* aFrame = new QFrame( aPage );
311
312   QGridLayout* aLayout = new QGridLayout( aPage );
313   
314   myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
315   myBrowser->setAutoOpenLevel( 3 );
316   aLayout->setMargin( 5 );
317   aLayout->setSpacing( 5 );
318
319   aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
320
321   myBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
322   myBathymetryChoice = new QComboBox( aFrame );
323
324   myBathymetryChoice->setVisible( false );
325   myBatimetryLabel->setVisible( false );
326
327   aLayout->addWidget( myBatimetryLabel, 1, 0 );
328   aLayout->addWidget( myBathymetryChoice, 1, 1 );
329
330   aPage->setLayout( aLayout );
331
332   connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
333   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
334   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
335   connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
336   connect( myBrowser, 
337       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
338       SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
339
340   return aPage;
341 }
342
343
344 bool HYDROGUI_CalculationDlg::acceptCurrent() const
345 {
346   QString anErrorMsg;
347
348   if ( false /*myGeomObjects->count() == 0*/ )
349   {
350     anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
351   }
352
353   if ( !anErrorMsg.isEmpty() )
354   {
355     anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
356     
357     QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
358     SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
359   }
360
361   return anErrorMsg.isEmpty();
362 }
363
364 void HYDROGUI_CalculationDlg::onEmptyName()
365 {
366   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
367   QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
368   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
369 }
370
371 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
372 {
373   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
374   QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
375                      "\n" + tr( "INPUT_VALID_DATA" );
376   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
377 }
378
379 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList, 
380     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
381 {
382   QList<SUIT_DataObject*> aZonesList;
383   HYDROGUI_Zone* aZone;
384   // Get a list of dropped zones
385   for ( int i = 0; i < theList.length(); i++ )
386   {
387     aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
388     if ( aZone )
389     {
390       aZonesList.append( aZone );
391     }
392   }
393   if ( aZonesList.length() > 0 )
394   {
395     // Get the target region
396     HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
397     if ( aRegionsRoot )
398     {
399       // Create a new region
400       emit createRegion( aZonesList );
401     }
402     else
403     {
404       HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
405       if ( aRegion )
406       {
407         emit moveZones( theTargetParent, aZonesList );
408       }
409     }
410   }
411 }
412
413 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
414 {
415   int aType = myBathymetryChoice->itemData( theIndex ).toInt();
416   QString aText = myBathymetryChoice->itemText( theIndex );
417   emit setMergeType( aType, aText );
418 }
419
420 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
421 {
422   bool doShow = false;
423   HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
424   if ( aZone )
425   {
426     doShow = aZone->isMergingNeed();
427   }
428
429   if ( doShow )
430   {
431     // Fill the merge type combo box
432     bool prevBlock = myBathymetryChoice->blockSignals( true );
433     myCurrentZone = aZone;
434     myBathymetryChoice->clear();
435     myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
436     myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
437     myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
438     QStringList aList = aZone->getAltitudes();
439     for ( int i = 0; i < aList.length(); i++ )
440     {
441       myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
442     }
443     // Select the current choice if any
444     int aCurIndex = 0;
445     switch ( aZone->getMergeType() )
446     {
447       case HYDROData_Zone::Merge_ZMIN:
448         aCurIndex = 1;
449         break;
450       case HYDROData_Zone::Merge_ZMAX:
451         aCurIndex = 2;
452         break;
453       case HYDROData_Zone::Merge_Object:
454         aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
455         break;
456       default:
457         aCurIndex = 0; // Select unknown by default
458     }
459     myBathymetryChoice->setCurrentIndex( aCurIndex );
460     myBathymetryChoice->blockSignals( prevBlock );
461   }
462
463   myBathymetryChoice->setVisible( doShow );
464   myBatimetryLabel->setVisible( doShow );
465 }
466
467 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
468 {
469   myObjectName->setText( theName );
470 }
471
472 QString HYDROGUI_CalculationDlg::getObjectName() const
473 {
474   return myObjectName->text();
475 }
476
477 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
478 {
479   QList<QListWidgetItem*> aFoundItems;
480   int anIdx;
481   QListWidgetItem* anItem;
482
483   for ( int i = 0, n = theObjects.length(); i < n; ++i )
484   {
485     QString anObjName = theObjects.at( i );
486     aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
487     for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
488     {
489       anItem = aFoundItems.at( anIdx );
490       // Remove this object from available objects list
491       anItem = theSource->takeItem( theSource->row( anItem ) );
492       // Add the item to the included objects list
493       theDest->addItem( anItem );
494     }
495   }
496 }
497
498 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
499 {
500   HYDROGUI_ListModel::Object2VisibleList anObjectsToInclude;
501   QList<QListWidgetItem*> aFoundItems;
502   foreach ( const QString& anObjName, theObjects ) {
503     // Hide the object in the available objects list
504     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
505     foreach ( QListWidgetItem* anItem, aFoundItems ) {
506       anItem->setHidden( true );
507     }
508
509     // Add the object to the list of included objects
510     Handle(HYDROData_Entity) anObject = 
511       HYDROGUI_Tool::FindObjectByName( module(), anObjName );
512     myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
513   }
514
515   myPriorityWidget->setObjects( getGeometryObjects() );
516 }
517
518 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
519 {
520   QList<QListWidgetItem*> aFoundItems;
521   foreach ( const QString& anObjName, theObjects ) {
522     // Set visible the object in the available objects list
523     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
524     foreach ( QListWidgetItem* anItem, aFoundItems ) {
525       anItem->setHidden( false );
526     }
527
528     // Remove the object from the list of included objects
529     myGeomObjects->removeObjectByName( anObjName );
530   }
531
532   myPriorityWidget->setObjects( getGeometryObjects() );
533 }
534
535 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
536 {
537   bool isBlocked = myPolylineName->blockSignals( true );
538   myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
539   myPolylineName->blockSignals( isBlocked );
540 }
541
542 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
543 {
544   myPolylineName->clear();
545   myPolylineName->addItem( "", "" ); // No boundary item
546
547   for ( int i = 0, n = theObjects.length(); i < n; ++i )
548   {
549     myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
550   }
551 }
552 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
553 {
554   myAvailableGeomObjects->clear();
555
556   for ( int i = 0, n = theObjects.length(); i < n; ++i )
557   {
558     QString anObjName = theObjects.at( i );
559
560     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
561     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
562     aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
563   }
564 }
565
566 QStringList getSelected( QListWidget* theWidget )
567 {
568   QStringList aResList;
569   QList<QListWidgetItem*> aList = theWidget->selectedItems();
570   for ( int i = 0, n = aList.length(); i < n; ++i )
571   {
572     aResList.append( aList.at( i )->text() );
573   }
574   return aResList;
575 }
576
577 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
578 {
579   return myGeomObjects->getSelectedNames();
580 }
581
582 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
583 {
584   return myGeomObjects->getAllNames();
585 }
586
587 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
588 {
589   return getSelected( myAvailableGeomObjects );
590 }
591
592 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
593 {
594   myEditedObject = theCase;
595   myValidator->setEditedObject( theCase );
596
597   // Build the calculation case subtree
598   module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject );
599
600   myBrowser->updateTree();
601   myBrowser->openLevels();
602   myBrowser->adjustColumnsWidth();
603   myBrowser->setAutoUpdate( true );
604   myBrowser->setUpdateModified( true );
605 }
606
607 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
608 {
609   return myCurrentZone;
610 }
611
612 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
613 {
614   SUIT_DataObject* aRoot = myBrowser->root();
615   module()->getDataModel()->updateObjectTree( myEditedObject );
616   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
617   myBrowser->updateTree( aRoot );
618 }
619
620 void HYDROGUI_CalculationDlg::onDataChanged()
621 {
622   SUIT_DataObject* aRoot = myBrowser->root();
623   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
624   myBrowser->updateTree( aRoot );
625 }
626
627 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
628 {
629   myAvailableGroups->clear();
630   myGroups->clear();
631   foreach( QString aGroup, theGroups )
632     myAvailableGroups->addItem( aGroup );
633 }
634
635 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
636 {
637   return getSelected( myGroups );
638 }
639
640 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
641 {
642   return getSelected( myAvailableGroups );
643 }
644
645 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
646 {
647   moveItems( myAvailableGroups, myGroups, theObjects );
648 }
649
650 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
651 {
652   moveItems( myGroups, myAvailableGroups, theObjects );
653 }
654
655 /**
656   Get creation mode.
657   @param theMode the mode
658 */
659 int HYDROGUI_CalculationDlg::getMode() const
660 {
661   return myModeButtons->checkedId();
662 }
663
664 /**
665   Set creation mode.
666   @param theMode the mode
667 */
668 void HYDROGUI_CalculationDlg::setMode( int theMode )
669 {
670   bool isBlocked = myModeButtons->blockSignals( true );
671   myModeButtons->button( theMode )->setChecked( true );
672   myModeButtons->blockSignals( isBlocked );
673
674   bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
675
676   myGeomObjects->setOrderingEnabled( isAuto );
677   QWidget* aWidget = mySplitter->widget( 1 );
678   if ( aWidget ) {
679     aWidget->setVisible( isAuto );
680   }
681 }
682
683 /**
684   Enable/disable zones drag'n'drop and renaming.
685   @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
686 */
687 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
688 {
689   myBrowser->setReadOnly( !theIsEnabled );
690 }
691
692 /**
693   Get included geometry objects.
694   @return the list of geometry objects
695  */
696 QList<Handle(HYDROData_Object)> HYDROGUI_CalculationDlg::getGeometryObjects()
697 {
698   QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
699   QList<Handle(HYDROData_Object)> anObjects;
700
701   foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
702     Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
703     if ( anObj.IsNull() ) {
704       continue;
705     }
706
707     anObjects << anObj;
708   }
709
710   return anObjects;
711 }
712
713 /**
714   Get rules.
715   @return the list of rules
716  */
717 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
718 {
719   return myPriorityWidget->getRules();
720 }
721
722 /**
723   Set rules.
724   @param theRules the list of rules
725 */
726 void  HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
727 {
728   myPriorityWidget->setRules( theRules );
729 }