]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_CalculationDlg.cxx
Salome HOME
Disable merge type combobox in automatic mode.
[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 );
187   anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
188   anObjsLayout->addWidget( myGeomObjects, 1, 2 );
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 );
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 );
290   aGroupsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
291   aGroupsLayout->addWidget( myGroups, 1, 2 );
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 );
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   myBathymetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
322   myBathymetryChoice = new QComboBox( aFrame );
323
324   myBathymetryChoice->setVisible( false );
325   myBathymetryLabel->setVisible( false );
326
327   aLayout->addWidget( myBathymetryLabel, 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   myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
465   myBathymetryLabel->setVisible( doShow );
466 }
467
468 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
469 {
470   myObjectName->setText( theName );
471 }
472
473 QString HYDROGUI_CalculationDlg::getObjectName() const
474 {
475   return myObjectName->text();
476 }
477
478 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
479 {
480   QList<QListWidgetItem*> aFoundItems;
481   int anIdx;
482   QListWidgetItem* anItem;
483
484   for ( int i = 0, n = theObjects.length(); i < n; ++i )
485   {
486     QString anObjName = theObjects.at( i );
487     aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
488     for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
489     {
490       anItem = aFoundItems.at( anIdx );
491       // Remove this object from available objects list
492       anItem = theSource->takeItem( theSource->row( anItem ) );
493       // Add the item to the included objects list
494       theDest->addItem( anItem );
495     }
496   }
497 }
498
499 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
500 {
501   HYDROGUI_ListModel::Object2VisibleList anObjectsToInclude;
502   QList<QListWidgetItem*> aFoundItems;
503   foreach ( const QString& anObjName, theObjects ) {
504     // Hide the object in the available objects list
505     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
506     foreach ( QListWidgetItem* anItem, aFoundItems ) {
507       anItem->setHidden( true );
508     }
509
510     // Add the object to the list of included objects
511     Handle(HYDROData_Entity) anObject = 
512       HYDROGUI_Tool::FindObjectByName( module(), anObjName );
513     myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
514   }
515
516   myPriorityWidget->setObjects( getGeometryObjects() );
517 }
518
519 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
520 {
521   QList<QListWidgetItem*> aFoundItems;
522   foreach ( const QString& anObjName, theObjects ) {
523     // Set visible the object in the available objects list
524     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
525     foreach ( QListWidgetItem* anItem, aFoundItems ) {
526       anItem->setHidden( false );
527     }
528
529     // Remove the object from the list of included objects
530     myGeomObjects->removeObjectByName( anObjName );
531   }
532
533   myPriorityWidget->setObjects( getGeometryObjects() );
534 }
535
536 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
537 {
538   bool isBlocked = myPolylineName->blockSignals( true );
539   myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
540   myPolylineName->blockSignals( isBlocked );
541 }
542
543 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
544 {
545   myPolylineName->clear();
546   myPolylineName->addItem( "", "" ); // No boundary item
547
548   for ( int i = 0, n = theObjects.length(); i < n; ++i )
549   {
550     myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
551   }
552 }
553 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
554 {
555   myAvailableGeomObjects->clear();
556
557   for ( int i = 0, n = theObjects.length(); i < n; ++i )
558   {
559     QString anObjName = theObjects.at( i );
560
561     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
562     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
563     aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
564   }
565 }
566
567 QStringList getSelected( QListWidget* theWidget )
568 {
569   QStringList aResList;
570   QList<QListWidgetItem*> aList = theWidget->selectedItems();
571   for ( int i = 0, n = aList.length(); i < n; ++i )
572   {
573     aResList.append( aList.at( i )->text() );
574   }
575   return aResList;
576 }
577
578 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
579 {
580   return myGeomObjects->getSelectedNames();
581 }
582
583 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
584 {
585   return myGeomObjects->getAllNames();
586 }
587
588 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
589 {
590   return getSelected( myAvailableGeomObjects );
591 }
592
593 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
594 {
595   myEditedObject = theCase;
596   myValidator->setEditedObject( theCase );
597
598   // Build the calculation case subtree
599   module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject );
600
601   myBrowser->updateTree();
602   myBrowser->openLevels();
603   myBrowser->adjustColumnsWidth();
604   myBrowser->setAutoUpdate( true );
605   myBrowser->setUpdateModified( true );
606 }
607
608 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
609 {
610   return myCurrentZone;
611 }
612
613 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
614 {
615   SUIT_DataObject* aRoot = myBrowser->root();
616   module()->getDataModel()->updateObjectTree( myEditedObject );
617   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
618   myBrowser->updateTree( aRoot );
619 }
620
621 void HYDROGUI_CalculationDlg::onDataChanged()
622 {
623   SUIT_DataObject* aRoot = myBrowser->root();
624   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
625   myBrowser->updateTree( aRoot );
626 }
627
628 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
629 {
630   myAvailableGroups->clear();
631   myGroups->clear();
632   foreach( QString aGroup, theGroups )
633     myAvailableGroups->addItem( aGroup );
634 }
635
636 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
637 {
638   return getSelected( myGroups );
639 }
640
641 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
642 {
643   return getSelected( myAvailableGroups );
644 }
645
646 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
647 {
648   moveItems( myAvailableGroups, myGroups, theObjects );
649 }
650
651 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
652 {
653   moveItems( myGroups, myAvailableGroups, theObjects );
654 }
655
656 /**
657   Get creation mode.
658   @param theMode the mode
659 */
660 int HYDROGUI_CalculationDlg::getMode() const
661 {
662   return myModeButtons->checkedId();
663 }
664
665 /**
666   Set creation mode.
667   @param theMode the mode
668 */
669 void HYDROGUI_CalculationDlg::setMode( int theMode )
670 {
671   bool isBlocked = myModeButtons->blockSignals( true );
672   myModeButtons->button( theMode )->setChecked( true );
673   myModeButtons->blockSignals( isBlocked );
674
675   bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
676
677   myGeomObjects->setOrderingEnabled( isAuto );
678   QWidget* aWidget = mySplitter->widget( 1 );
679   if ( aWidget ) {
680     aWidget->setVisible( isAuto );
681   }
682 }
683
684 /**
685   Enable/disable zones drag'n'drop and renaming.
686   @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
687 */
688 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
689 {
690   myBrowser->setReadOnly( !theIsEnabled );
691 }
692
693 /**
694   Get included geometry objects.
695   @return the list of geometry objects
696  */
697 QList<Handle(HYDROData_Object)> HYDROGUI_CalculationDlg::getGeometryObjects()
698 {
699   QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
700   QList<Handle(HYDROData_Object)> anObjects;
701
702   foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
703     Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
704     if ( anObj.IsNull() ) {
705       continue;
706     }
707
708     anObjects << anObj;
709   }
710
711   return anObjects;
712 }
713
714 /**
715   Get rules.
716   @return the list of rules
717  */
718 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
719 {
720   return myPriorityWidget->getRules();
721 }
722
723 /**
724   Set rules.
725   @param theRules the list of rules
726 */
727 void  HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
728 {
729   myPriorityWidget->setRules( theRules );
730 }