Salome HOME
8bd9bfa84248ece8d63e536b2916f8b2c5f0902f
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationDlg.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_CalculationDlg.h"
20
21 #include "HYDROGUI_ObjSelector.h"
22 #include "HYDROGUI_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
338   return aPage;
339 }
340
341
342 bool HYDROGUI_CalculationDlg::acceptCurrent() const
343 {
344   QString anErrorMsg;
345
346   if ( false /*myGeomObjects->count() == 0*/ )
347   {
348     anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
349   }
350
351   if ( !anErrorMsg.isEmpty() )
352   {
353     anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
354     
355     QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
356     SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
357   }
358
359   return anErrorMsg.isEmpty();
360 }
361
362 void HYDROGUI_CalculationDlg::onEmptyName()
363 {
364   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
365   QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
366   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
367 }
368
369 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
370 {
371   QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
372   QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
373                      "\n" + tr( "INPUT_VALID_DATA" );
374   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
375 }
376
377 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList, 
378     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
379 {
380   QList<SUIT_DataObject*> aZonesList;
381   HYDROGUI_Zone* aZone;
382   // Get a list of dropped zones
383   for ( int i = 0; i < theList.length(); i++ )
384   {
385     aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
386     if ( aZone )
387     {
388       aZonesList.append( aZone );
389     }
390   }
391   if ( aZonesList.length() > 0 )
392   {
393     // Get the target region
394     HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
395     if ( aRegionsRoot )
396     {
397       // Create a new region
398       emit createRegion( aZonesList );
399     }
400     else
401     {
402       HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
403       if ( aRegion )
404       {
405         emit moveZones( theTargetParent, aZonesList );
406       }
407     }
408   }
409 }
410
411 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
412 {
413   int aType = myBathymetryChoice->itemData( theIndex ).toInt();
414   QString aText = myBathymetryChoice->itemText( theIndex );
415   emit setMergeType( aType, aText );
416 }
417
418 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
419 {
420   bool doShow = false;
421   HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
422   if ( aZone )
423   {
424     doShow = aZone->isMergingNeed();
425   }
426
427   if ( doShow )
428   {
429     // Fill the merge type combo box
430     bool prevBlock = myBathymetryChoice->blockSignals( true );
431     myCurrentZone = aZone;
432     myBathymetryChoice->clear();
433     myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
434     myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
435     myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
436     QStringList aList = aZone->getAltitudes();
437     for ( int i = 0; i < aList.length(); i++ )
438     {
439       myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
440     }
441     // Select the current choice if any
442     int aCurIndex = 0;
443     switch ( aZone->getMergeType() )
444     {
445       case HYDROData_Zone::Merge_ZMIN:
446         aCurIndex = 1;
447         break;
448       case HYDROData_Zone::Merge_ZMAX:
449         aCurIndex = 2;
450         break;
451       case HYDROData_Zone::Merge_Object:
452         aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
453         break;
454       default:
455         aCurIndex = 0; // Select unknown by default
456     }
457     myBathymetryChoice->setCurrentIndex( aCurIndex );
458     myBathymetryChoice->blockSignals( prevBlock );
459   }
460
461   myBathymetryChoice->setVisible( doShow );
462   myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
463   myBathymetryLabel->setVisible( doShow );
464 }
465
466 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
467 {
468   myObjectName->setText( theName );
469 }
470
471 QString HYDROGUI_CalculationDlg::getObjectName() const
472 {
473   return myObjectName->text();
474 }
475
476 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
477 {
478   QList<QListWidgetItem*> aFoundItems;
479   int anIdx;
480   QListWidgetItem* anItem;
481
482   for ( int i = 0, n = theObjects.length(); i < n; ++i )
483   {
484     QString anObjName = theObjects.at( i );
485     aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
486     for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
487     {
488       anItem = aFoundItems.at( anIdx );
489       // Remove this object from available objects list
490       anItem = theSource->takeItem( theSource->row( anItem ) );
491       // Add the item to the included objects list
492       theDest->addItem( anItem );
493     }
494   }
495 }
496
497 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
498 {
499   HYDROGUI_ListModel::Object2VisibleList anObjectsToInclude;
500   QList<QListWidgetItem*> aFoundItems;
501   foreach ( const QString& anObjName, theObjects ) {
502     // Hide the object in the available objects list
503     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
504     foreach ( QListWidgetItem* anItem, aFoundItems ) {
505       anItem->setHidden( true );
506     }
507
508     // Add the object to the list of included objects
509     Handle(HYDROData_Entity) anObject = 
510       HYDROGUI_Tool::FindObjectByName( module(), anObjName );
511     myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
512   }
513
514   myPriorityWidget->setObjects( getGeometryObjects() );
515 }
516
517 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
518 {
519   QList<QListWidgetItem*> aFoundItems;
520   foreach ( const QString& anObjName, theObjects ) {
521     // Set visible the object in the available objects list
522     aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
523     foreach ( QListWidgetItem* anItem, aFoundItems ) {
524       anItem->setHidden( false );
525     }
526
527     // Remove the object from the list of included objects
528     myGeomObjects->removeObjectByName( anObjName );
529   }
530
531   myPriorityWidget->setObjects( getGeometryObjects() );
532 }
533
534 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
535 {
536   bool isBlocked = myPolylineName->blockSignals( true );
537   myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
538   myPolylineName->blockSignals( isBlocked );
539 }
540
541 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
542 {
543   myPolylineName->clear();
544   myPolylineName->addItem( "", "" ); // No boundary item
545
546   for ( int i = 0, n = theObjects.length(); i < n; ++i )
547   {
548     myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
549   }
550 }
551 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
552 {
553   myAvailableGeomObjects->clear();
554
555   for ( int i = 0, n = theObjects.length(); i < n; ++i )
556   {
557     QString anObjName = theObjects.at( i );
558
559     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
560     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
561     aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
562   }
563 }
564
565 QStringList getSelected( QListWidget* theWidget )
566 {
567   QStringList aResList;
568   QList<QListWidgetItem*> aList = theWidget->selectedItems();
569   for ( int i = 0, n = aList.length(); i < n; ++i )
570   {
571     aResList.append( aList.at( i )->text() );
572   }
573   return aResList;
574 }
575
576 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
577 {
578   return myGeomObjects->getSelectedNames();
579 }
580
581 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
582 {
583   return myGeomObjects->getAllNames();
584 }
585
586 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
587 {
588   return getSelected( myAvailableGeomObjects );
589 }
590
591 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
592 {
593   myEditedObject = theCase;
594   myValidator->setEditedObject( theCase );
595
596   // Build the calculation case subtree
597   module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject );
598
599   myBrowser->updateTree();
600   myBrowser->openLevels();
601   myBrowser->adjustColumnsWidth();
602   myBrowser->setAutoUpdate( true );
603   myBrowser->setUpdateModified( true );
604 }
605
606 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
607 {
608   return myCurrentZone;
609 }
610
611 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
612 {
613   SUIT_DataObject* aRoot = myBrowser->root();
614   module()->getDataModel()->updateObjectTree( myEditedObject );
615   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
616   myBrowser->updateTree( aRoot );
617 }
618
619 void HYDROGUI_CalculationDlg::onDataChanged()
620 {
621   SUIT_DataObject* aRoot = myBrowser->root();
622   module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
623   myBrowser->updateTree( aRoot );
624 }
625
626 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
627 {
628   myAvailableGroups->clear();
629   myGroups->clear();
630   foreach( QString aGroup, theGroups )
631     myAvailableGroups->addItem( aGroup );
632 }
633
634 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
635 {
636   return getSelected( myGroups );
637 }
638
639 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
640 {
641   return getSelected( myAvailableGroups );
642 }
643
644 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
645 {
646   moveItems( myAvailableGroups, myGroups, theObjects );
647 }
648
649 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
650 {
651   moveItems( myGroups, myAvailableGroups, theObjects );
652 }
653
654 /**
655   Get creation mode.
656   @param theMode the mode
657 */
658 int HYDROGUI_CalculationDlg::getMode() const
659 {
660   return myModeButtons->checkedId();
661 }
662
663 /**
664   Set creation mode.
665   @param theMode the mode
666 */
667 void HYDROGUI_CalculationDlg::setMode( int theMode )
668 {
669   bool isBlocked = myModeButtons->blockSignals( true );
670   myModeButtons->button( theMode )->setChecked( true );
671   myModeButtons->blockSignals( isBlocked );
672
673   bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
674
675   myGeomObjects->setOrderingEnabled( isAuto );
676   QWidget* aWidget = mySplitter->widget( 1 );
677   if ( aWidget ) {
678     aWidget->setVisible( isAuto );
679   }
680 }
681
682 /**
683   Enable/disable zones drag'n'drop and renaming.
684   @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
685 */
686 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
687 {
688   myBrowser->setReadOnly( !theIsEnabled );
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 }
729
730 /**
731   Slot called when objects order is changed.
732  */
733 void HYDROGUI_CalculationDlg::onOrderChanged()
734 {
735   myPriorityWidget->setObjects( getGeometryObjects() );
736 }