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