]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_CalculationDlg.cxx
Salome HOME
Implement table of rules.
[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
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, Qt::AlignHCenter );
183   anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
184   anObjsLayout->addWidget( myGeomObjects, 1, 2, Qt::AlignHCenter );
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, Qt::AlignHCenter );
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   return aPage;
239 }
240
241 QWizardPage* HYDROGUI_CalculationDlg::createGroupsPage() {
242   QWizardPage* aPage = new QWizardPage( mainFrame() );
243   QFrame* aFrame = new QFrame( aPage );
244
245   myGroups = new QListWidget( aPage );
246   myGroups->setSelectionMode( QListWidget::ExtendedSelection );
247   myGroups->setEditTriggers( QListWidget::NoEditTriggers );
248   myGroups->setViewMode( QListWidget::ListMode );
249   myGroups->setSortingEnabled( true );
250
251   myAvailableGroups = new QListWidget( aPage );
252   myAvailableGroups->setSelectionMode( QListWidget::ExtendedSelection );
253   myAvailableGroups->setEditTriggers( QListWidget::NoEditTriggers );
254   myAvailableGroups->setViewMode( QListWidget::ListMode );
255   myAvailableGroups->setSortingEnabled( true );
256
257   connect( myGroups, SIGNAL( itemSelectionChanged() ), 
258     SIGNAL( groupsSelected() ) );
259
260   QFrame* aGroupsFrame = new QFrame( aPage );
261   QGridLayout* aGroupsLayout = new QGridLayout( aGroupsFrame );
262   aGroupsLayout->setMargin( 5 );
263   aGroupsLayout->setSpacing( 5 );
264   aGroupsFrame->setLayout( aGroupsLayout );
265
266   QFrame* aBtnsFrame = new QFrame( aGroupsFrame );
267   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
268   aBtnsLayout->setMargin( 5 );
269   aBtnsLayout->setSpacing( 5 );
270   aBtnsFrame->setLayout( aBtnsLayout );
271   QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
272   QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
273
274   // Fill the butons frame with two buttons
275   aBtnsLayout->addWidget( anAddBtn );
276   aBtnsLayout->addWidget( aRemoveBtn );
277   aBtnsLayout->addStretch( 1 );
278
279   QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_GROUPS" ), aGroupsFrame );
280   QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_GROUPS" ), aGroupsFrame );
281
282   // Fill the objects frame with two lists, two labels and with buttons frame
283   aGroupsLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
284   aGroupsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
285   aGroupsLayout->addWidget( myAvailableGroups, 1, 0, Qt::AlignHCenter );
286   aGroupsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
287   aGroupsLayout->addWidget( myGroups, 1, 2, Qt::AlignHCenter );
288
289   // Fill the page
290   QGridLayout* aPageLayout = new QGridLayout( aPage );
291   aPageLayout->setMargin( 5 );
292   aPageLayout->setSpacing( 5 );
293   aPageLayout->setVerticalSpacing( 10 );
294   aPageLayout->addWidget( aGroupsFrame, 0, 0, Qt::AlignHCenter );
295
296   aPage->setLayout( aPageLayout );
297
298   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addGroups() ) );
299   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeGroups() ) );
300
301   return aPage;
302 }
303
304 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
305   QWizardPage* aPage = new QWizardPage( mainFrame() );
306   QFrame* aFrame = new QFrame( aPage );
307
308   QGridLayout* aLayout = new QGridLayout( aPage );
309   
310   myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
311   myBrowser->setAutoOpenLevel( 3 );
312   aLayout->setMargin( 5 );
313   aLayout->setSpacing( 5 );
314
315   aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
316
317   myBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
318   myBathymetryChoice = new QComboBox( aFrame );
319
320   myBathymetryChoice->setVisible( false );
321   myBatimetryLabel->setVisible( false );
322
323   aLayout->addWidget( myBatimetryLabel, 1, 0 );
324   aLayout->addWidget( myBathymetryChoice, 1, 1 );
325
326   aPage->setLayout( aLayout );
327
328   connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
329   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
330   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
331   connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
332   connect( myBrowser, 
333       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
334       SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
335
336   return aPage;
337 }
338
339
340 bool HYDROGUI_CalculationDlg::acceptCurrent() const
341 {
342   QString anErrorMsg;
343
344   if ( false /*myGeomObjects->count() == 0*/ )
345   {
346     anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
347   }
348
349   if ( !anErrorMsg.isEmpty() )
350   {
351     anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
352     
353     QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
354     SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
355   }
356
357   return anErrorMsg.isEmpty();
358 }
359
360 void HYDROGUI_CalculationDlg::onEmptyName()
361 {
362   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
363   QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
364   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
365 }
366
367 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
368 {
369   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
370   QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
371                      "\n" + tr( "INPUT_VALID_DATA" );
372   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
373 }
374
375 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList, 
376     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
377 {
378   QList<SUIT_DataObject*> aZonesList;
379   HYDROGUI_Zone* aZone;
380   // Get a list of dropped zones
381   for ( int i = 0; i < theList.length(); i++ )
382   {
383     aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
384     if ( aZone )
385     {
386       aZonesList.append( aZone );
387     }
388   }
389   if ( aZonesList.length() > 0 )
390   {
391     // Get the target region
392     HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
393     if ( aRegionsRoot )
394     {
395       // Create a new region
396       emit createRegion( aZonesList );
397     }
398     else
399     {
400       HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
401       if ( aRegion )
402       {
403         emit moveZones( theTargetParent, aZonesList );
404       }
405     }
406   }
407 }
408
409 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
410 {
411   int aType = myBathymetryChoice->itemData( theIndex ).toInt();
412   QString aText = myBathymetryChoice->itemText( theIndex );
413   emit setMergeType( aType, aText );
414 }
415
416 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
417 {
418   bool doShow = false;
419   HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
420   if ( aZone )
421   {
422     doShow = aZone->isMergingNeed();
423   }
424
425   if ( doShow )
426   {
427     // Fill the merge type combo box
428     bool prevBlock = myBathymetryChoice->blockSignals( true );
429     myCurrentZone = aZone;
430     myBathymetryChoice->clear();
431     myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
432     myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
433     myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
434     QStringList aList = aZone->getAltitudes();
435     for ( int i = 0; i < aList.length(); i++ )
436     {
437       myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
438     }
439     // Select the current choice if any
440     int aCurIndex = 0;
441     switch ( aZone->getMergeType() )
442     {
443       case HYDROData_Zone::Merge_ZMIN:
444         aCurIndex = 1;
445         break;
446       case HYDROData_Zone::Merge_ZMAX:
447         aCurIndex = 2;
448         break;
449       case HYDROData_Zone::Merge_Object:
450         aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
451         break;
452       default:
453         aCurIndex = 0; // Select unknown by default
454     }
455     myBathymetryChoice->setCurrentIndex( aCurIndex );
456     myBathymetryChoice->blockSignals( prevBlock );
457   }
458
459   myBathymetryChoice->setVisible( doShow );
460   myBatimetryLabel->setVisible( doShow );
461 }
462
463 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
464 {
465   myObjectName->setText( theName );
466 }
467
468 QString HYDROGUI_CalculationDlg::getObjectName() const
469 {
470   return myObjectName->text();
471 }
472
473 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
474 {
475   QList<QListWidgetItem*> aFoundItems;
476   int anIdx;
477   QListWidgetItem* anItem;
478
479   for ( int i = 0, n = theObjects.length(); i < n; ++i )
480   {
481     QString anObjName = theObjects.at( i );
482     aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
483     for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
484     {
485       anItem = aFoundItems.at( anIdx );
486       // Remove this object from available objects list
487       anItem = theSource->takeItem( theSource->row( anItem ) );
488       // Add the item to the included objects list
489       theDest->addItem( anItem );
490     }
491   }
492 }
493
494 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
495 {
496   HYDROGUI_ListModel::Object2VisibleList anObjectsToInclude;
497   QList<QListWidgetItem*> aFoundItems;
498   foreach ( const QString& anObjName, theObjects ) {
499     // Hide the object in the available objects list
500     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
501     foreach ( QListWidgetItem* anItem, aFoundItems ) {
502       anItem->setHidden( true );
503     }
504
505     // Add the object to the list of included objects
506     Handle(HYDROData_Entity) anObject = 
507       HYDROGUI_Tool::FindObjectByName( module(), anObjName );
508     myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
509   }
510
511   myPriorityWidget->setObjects( getGeometryObjects() );
512 }
513
514 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
515 {
516   QList<QListWidgetItem*> aFoundItems;
517   foreach ( const QString& anObjName, theObjects ) {
518     // Set visible the object in the available objects list
519     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
520     foreach ( QListWidgetItem* anItem, aFoundItems ) {
521       anItem->setHidden( false );
522     }
523
524     // Remove the object from the list of included objects
525     myGeomObjects->removeObjectByName( anObjName );
526   }
527
528   myPriorityWidget->setObjects( getGeometryObjects() );
529 }
530
531 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
532 {
533   bool isBlocked = myPolylineName->blockSignals( true );
534   myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
535   myPolylineName->blockSignals( isBlocked );
536 }
537
538 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
539 {
540   myPolylineName->clear();
541   myPolylineName->addItem( "", "" ); // No boundary item
542
543   for ( int i = 0, n = theObjects.length(); i < n; ++i )
544   {
545     myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
546   }
547 }
548 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
549 {
550   myAvailableGeomObjects->clear();
551
552   for ( int i = 0, n = theObjects.length(); i < n; ++i )
553   {
554     QString anObjName = theObjects.at( i );
555
556     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
557     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
558     aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
559   }
560 }
561
562 QStringList getSelected( QListWidget* theWidget )
563 {
564   QStringList aResList;
565   QList<QListWidgetItem*> aList = theWidget->selectedItems();
566   for ( int i = 0, n = aList.length(); i < n; ++i )
567   {
568     aResList.append( aList.at( i )->text() );
569   }
570   return aResList;
571 }
572
573 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
574 {
575   return myGeomObjects->getSelectedNames();
576 }
577
578 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
579 {
580   return myGeomObjects->getAllNames();
581 }
582
583 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
584 {
585   return getSelected( myAvailableGeomObjects );
586 }
587
588 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
589 {
590   myEditedObject = theCase;
591   myValidator->setEditedObject( theCase );
592
593   // Build the calculation case subtree
594   module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject );
595
596   myBrowser->updateTree();
597   myBrowser->openLevels();
598   myBrowser->adjustColumnsWidth();
599   myBrowser->setAutoUpdate( true );
600   myBrowser->setUpdateModified( true );
601 }
602
603 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
604 {
605   return myCurrentZone;
606 }
607
608 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
609 {
610   SUIT_DataObject* aRoot = myBrowser->root();
611   module()->getDataModel()->updateObjectTree( myEditedObject );
612   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
613   myBrowser->updateTree( aRoot );
614 }
615
616 void HYDROGUI_CalculationDlg::onDataChanged()
617 {
618   SUIT_DataObject* aRoot = myBrowser->root();
619   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
620   myBrowser->updateTree( aRoot );
621 }
622
623 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
624 {
625   myAvailableGroups->clear();
626   myGroups->clear();
627   foreach( QString aGroup, theGroups )
628     myAvailableGroups->addItem( aGroup );
629 }
630
631 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
632 {
633   return getSelected( myGroups );
634 }
635
636 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
637 {
638   return getSelected( myAvailableGroups );
639 }
640
641 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
642 {
643   moveItems( myAvailableGroups, myGroups, theObjects );
644 }
645
646 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
647 {
648   moveItems( myGroups, myAvailableGroups, theObjects );
649 }
650
651 /**
652   Get creation mode.
653   @param theMode the mode
654 */
655 int HYDROGUI_CalculationDlg::getMode() const
656 {
657   return myModeButtons->checkedId();
658 }
659
660 /**
661   Set creation mode.
662   @param theMode the mode
663 */
664 void HYDROGUI_CalculationDlg::setMode( int theMode )
665 {
666   bool isBlocked = myModeButtons->blockSignals( true );
667   myModeButtons->button( theMode )->setChecked( true );
668   myModeButtons->blockSignals( isBlocked );
669
670   bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
671
672   myGeomObjects->setOrderingEnabled( isAuto );
673   QWidget* aWidget = mySplitter->widget( 1 );
674   if ( aWidget ) {
675     aWidget->setVisible( isAuto );
676   }
677 }
678
679 /**
680   Enable/disable zones drag and drop.
681   @param theIsEnabled if true - zones drag and drop will be enabled
682 */
683 void HYDROGUI_CalculationDlg::setMoveZonesEnabled( const bool theIsEnabled )
684 {
685   //TODO: to be reimplemented
686   foreach ( QTreeView* aView, myBrowser->findChildren<QTreeView*>() ) {
687     aView->setDragEnabled ( theIsEnabled );
688   }
689 }
690
691 /**
692   Get included geometry objects.
693   @return the list of geometry objects
694  */
695 QList<Handle(HYDROData_Object)> HYDROGUI_CalculationDlg::getGeometryObjects()
696 {
697   QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
698   QList<Handle(HYDROData_Object)> anObjects;
699
700   foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
701     Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
702     if ( anObj.IsNull() ) {
703       continue;
704     }
705
706     anObjects << anObj;
707   }
708
709   return anObjects;
710 }
711
712 /**
713   Get rules.
714   @return the list of rules
715  */
716 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
717 {
718   return myPriorityWidget->getRules();
719 }
720
721 /**
722   Set rules.
723   @param theRules the list of rules
724 */
725 void  HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
726 {
727   myPriorityWidget->setRules( theRules );
728 }