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