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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_CalculationDlg.h"
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 #include "HYDROGUI_PriorityTableModel.h"
35 #include <HYDROData_Document.h>
36 #include <HYDROData_Entity.h>
38 #include <CAM_Application.h>
39 #include <LightApp_DataObject.h>
41 #include <SUIT_DataObject.h>
42 #include <SUIT_FileDlg.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_Study.h>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_MessageBox.h>
52 #include <QButtonGroup>
58 #include <QListWidget>
60 #include <QPushButton>
61 #include <QRadioButton>
63 #include <QTableWidget>
64 #include <QToolButton>
66 #include <QWizardPage>
69 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
70 : HYDROGUI_Wizard( theModule, theTitle )
72 addPage( createObjectsPage() );
73 addPage( createGroupsPage() );
74 addPage( createLandCoverMapPage() );
75 addPage( createZonesPage() );
78 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
82 void HYDROGUI_CalculationDlg::reset()
84 myObjectName->clear();
85 HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
86 myGeomObjects->setObjects(anObject2VisibleList);
87 myPolylineName->clear();
88 myStricklerTableName->clear();
89 myAvailableGeomObjects->clear();
91 // Activate the automatic mode
92 setMode( HYDROData_CalculationCase::AUTOMATIC );
94 // Reset the priority widget state
95 QList<Handle(HYDROData_Entity)> anObjects;
96 myPriorityWidget->setObjects( anObjects );
99 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
100 QWizardPage* aPage = new QWizardPage( mainFrame() );
101 QFrame* aFrame = new QFrame( aPage );
104 mySplitter = new QSplitter(Qt::Vertical);
107 QWidget* aTopContainer = new QWidget;
110 myObjectName = new QLineEdit( aPage );
111 myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
112 myObjectName->setValidator( myValidator );
114 connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) );
115 connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) );
118 myPolylineName = new QComboBox( aPage );
119 connect( myPolylineName, SIGNAL( activated( const QString & ) ),
120 SIGNAL( boundarySelected( const QString & ) ) );
123 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
124 QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
126 // mode selector (auto/manual)
127 QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
129 QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
130 QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
132 myModeButtons = new QButtonGroup( mainFrame() );
133 myModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
134 myModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
136 QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
137 aModeSelectorLayout->setMargin( 5 );
138 aModeSelectorLayout->setSpacing( 5 );
139 aModeSelectorLayout->addWidget( anAutoRB );
140 aModeSelectorLayout->addWidget( aManualRB );
141 aModeGroup->setLayout( aModeSelectorLayout );
144 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ) );
145 myGeomObjects = new HYDROGUI_OrderedListWidget( aPage, 16 );
146 myGeomObjects->setHiddenObjectsShown(true);
147 myGeomObjects->setVisibilityIconShown(false);
148 myGeomObjects->setContentsMargins(QMargins());
150 // included geometry objects
151 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ) );
152 myAvailableGeomObjects = new QListWidget( aPage );
153 myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
154 myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
155 myAvailableGeomObjects->setViewMode( QListWidget::ListMode );
156 myAvailableGeomObjects->setSortingEnabled( true );
159 QFrame* aBtnsFrame = new QFrame;
160 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
161 aBtnsLayout->setMargin( 5 );
162 aBtnsLayout->setSpacing( 5 );
163 aBtnsFrame->setLayout( aBtnsLayout );
164 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
165 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
167 // fill the butons frame with two buttons
168 aBtnsLayout->addWidget( anAddBtn );
169 aBtnsLayout->addWidget( aRemoveBtn );
170 aBtnsLayout->addStretch( 1 );
172 // top of the page layout
175 QFrame* anObjectsFrame = new QFrame( aPage );
176 anObjectsFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
177 QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
178 anObjsLayout->setMargin( 5 );
179 anObjsLayout->setSpacing( 5 );
180 anObjectsFrame->setLayout( anObjsLayout );
182 // fill the objects frame with two lists, two labels and with buttons frame
183 anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter );
184 anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
185 anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0 );
186 anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
187 anObjsLayout->addWidget( myGeomObjects, 1, 2 );
189 // fill the top of the page
190 QGridLayout* aTopLayout = new QGridLayout;
191 aTopLayout->setMargin( 5 );
192 aTopLayout->setSpacing( 5 );
193 aTopLayout->setVerticalSpacing( 10 );
194 aTopLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
195 aTopLayout->addWidget( myObjectName, 0, 1 );
196 aTopLayout->addWidget( aLimitsLabel, 1, 0, Qt::AlignHCenter );
197 aTopLayout->addWidget( myPolylineName, 1, 1 );
198 aTopLayout->addWidget( aModeGroup, 2, 0, 1, 2 );
199 aTopLayout->addWidget( anObjectsFrame, 3, 0, 1, 2 );
201 aTopContainer->setLayout( aTopLayout );
203 // add the top of the page to the splitter
204 mySplitter->insertWidget(0, aTopContainer);
205 mySplitter->setStretchFactor(0, 2);
207 // Bottom of the page
208 myPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
210 QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
211 QBoxLayout* aPriorityLayout = new QHBoxLayout;
212 aPriorityLayout->setMargin( 5 );
213 aPriorityLayout->setSpacing( 5 );
214 aPriorityLayout->addWidget( myPriorityWidget );
215 aPriorityGroup->setLayout( aPriorityLayout );
217 // add the bottom of the page to the splitter
218 mySplitter->insertWidget(1, aPriorityGroup);
219 mySplitter->setStretchFactor(1, 1);
222 QVBoxLayout* aPageLayout = new QVBoxLayout;
223 aPageLayout->setMargin( 5 );
224 aPageLayout->setSpacing( 5 );
225 aPageLayout->addWidget( mySplitter );
227 aPage->setLayout( aPageLayout );
231 HYDROGUI_ListSelector* aListSelector =
232 new HYDROGUI_ListSelector( myGeomObjects, module()->getApp()->selectionMgr() );
233 aListSelector->setAutoBlock( true );
237 connect( myModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeMode( int ) ) );
238 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) );
239 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) );
241 connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) );
243 connect( myPriorityWidget, SIGNAL( ruleChanged() ), SLOT( onRuleChanged() ) );
248 QWizardPage* HYDROGUI_CalculationDlg::createGroupsPage() {
249 QWizardPage* aPage = new QWizardPage( mainFrame() );
250 QFrame* aFrame = new QFrame( aPage );
252 myGroups = new QListWidget( aPage );
253 myGroups->setSelectionMode( QListWidget::ExtendedSelection );
254 myGroups->setEditTriggers( QListWidget::NoEditTriggers );
255 myGroups->setViewMode( QListWidget::ListMode );
256 myGroups->setSortingEnabled( true );
258 myAvailableGroups = new QListWidget( aPage );
259 myAvailableGroups->setSelectionMode( QListWidget::ExtendedSelection );
260 myAvailableGroups->setEditTriggers( QListWidget::NoEditTriggers );
261 myAvailableGroups->setViewMode( QListWidget::ListMode );
262 myAvailableGroups->setSortingEnabled( true );
264 connect( myGroups, SIGNAL( itemSelectionChanged() ),
265 SIGNAL( groupsSelected() ) );
267 QFrame* aGroupsFrame = new QFrame( aPage );
268 QGridLayout* aGroupsLayout = new QGridLayout( aGroupsFrame );
269 aGroupsLayout->setMargin( 5 );
270 aGroupsLayout->setSpacing( 5 );
271 aGroupsFrame->setLayout( aGroupsLayout );
273 QFrame* aBtnsFrame = new QFrame( aGroupsFrame );
274 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
275 aBtnsLayout->setMargin( 5 );
276 aBtnsLayout->setSpacing( 5 );
277 aBtnsFrame->setLayout( aBtnsLayout );
278 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
279 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
281 // Fill the butons frame with two buttons
282 aBtnsLayout->addWidget( anAddBtn );
283 aBtnsLayout->addWidget( aRemoveBtn );
284 aBtnsLayout->addStretch( 1 );
286 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_GROUPS" ), aGroupsFrame );
287 QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_GROUPS" ), aGroupsFrame );
289 // Fill the objects frame with two lists, two labels and with buttons frame
290 aGroupsLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
291 aGroupsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
292 aGroupsLayout->addWidget( myAvailableGroups, 1, 0 );
293 aGroupsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
294 aGroupsLayout->addWidget( myGroups, 1, 2 );
297 QGridLayout* aPageLayout = new QGridLayout( aPage );
298 aPageLayout->setMargin( 5 );
299 aPageLayout->setSpacing( 5 );
300 aPageLayout->setVerticalSpacing( 10 );
301 aPageLayout->addWidget( aGroupsFrame, 0, 0 );
303 aPage->setLayout( aPageLayout );
305 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addGroups() ) );
306 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeGroups() ) );
311 QWizardPage* HYDROGUI_CalculationDlg::createLandCoverMapPage() {
312 QWizardPage* aPage = new QWizardPage( mainFrame() );
313 QFrame* aFrame = new QFrame( aPage );
316 QWidget* aTopContainer = new QWidget;
318 // TODO: add combo-box to choose land cover map object
319 // Combo-box to choose Strickler table name
320 QLabel* aStricklerTableLabel = new QLabel( tr( "STRICKLER_TABLE" ), aPage );
321 myStricklerTableName = new QComboBox( aPage );
322 myStricklerTableName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
323 connect( myStricklerTableName, SIGNAL( activated( const QString & ) ),
324 SIGNAL( StricklerTableSelected( const QString & ) ) );
326 // Fill the top layout of the page
327 QGridLayout* aTopLayout = new QGridLayout;
328 aTopLayout->setMargin( 5 );
329 aTopLayout->setSpacing( 5 );
330 aTopLayout->setVerticalSpacing( 10 );
331 // TODO: add land cover map combo-box to the layout
332 aTopLayout->addWidget( aStricklerTableLabel, 0, 0, Qt::AlignHCenter );
333 aTopLayout->addWidget( myStricklerTableName, 0, 1 );
335 aTopContainer->setLayout( aTopLayout );
338 QVBoxLayout* aPageLayout = new QVBoxLayout;
339 aPageLayout->setMargin( 5 );
340 aPageLayout->setSpacing( 5 );
342 aPage->setLayout( aPageLayout );
350 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
351 QWizardPage* aPage = new QWizardPage( mainFrame() );
352 QFrame* aFrame = new QFrame( aPage );
354 QGridLayout* aLayout = new QGridLayout( aPage );
356 QLabel* aResultsOnGeomObjectsLabel = new QLabel( tr( "RESULTS_ON_GEOMETRY_OBJECTS" ), aFrame );
358 myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
359 myBrowser->setAutoOpenLevel( 3 );
360 aLayout->setMargin( 5 );
361 aLayout->setSpacing( 5 );
363 aLayout->addWidget( aResultsOnGeomObjectsLabel, 0, 0 );
364 aLayout->addWidget( myBrowser, 1, 0, 1, 2 );
366 myBathymetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
367 myBathymetryChoice = new QComboBox( aFrame );
369 myBathymetryChoice->setVisible( false );
370 myBathymetryLabel->setVisible( false );
372 aLayout->addWidget( myBathymetryLabel, 2, 0 );
373 aLayout->addWidget( myBathymetryChoice, 2, 1 );
375 QPushButton* aRegenerateBtn = new QPushButton( tr( "REGENERATE_COLORS" ), this );
376 aLayout->addWidget( aRegenerateBtn, 3, 0 );
378 aPage->setLayout( aLayout );
380 connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
381 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
382 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
383 connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
385 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
386 SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
387 connect( myBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewRegion() ) );
388 connect( aRegenerateBtn, SIGNAL( clicked() ), this, SIGNAL( regenerateColors() ) );
392 bool HYDROGUI_CalculationDlg::acceptCurrent() const
396 if ( false /*myGeomObjects->count() == 0*/ )
398 anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
401 if ( !anErrorMsg.isEmpty() )
403 anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
405 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
406 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
409 return anErrorMsg.isEmpty();
412 void HYDROGUI_CalculationDlg::onEmptyName()
414 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
415 QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
416 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
419 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
421 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
422 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
423 "\n" + tr( "INPUT_VALID_DATA" );
424 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
427 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList,
428 SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
430 QList<SUIT_DataObject*> aZonesList;
431 HYDROGUI_Zone* aZone;
432 // Get a list of dropped zones
433 for ( int i = 0; i < theList.length(); i++ )
435 aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
438 aZonesList.append( aZone );
441 if ( aZonesList.length() > 0 )
443 // Get the target region
444 HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
447 // Create a new region
448 emit createRegion( aZonesList );
452 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
455 emit moveZones( theTargetParent, aZonesList );
461 void HYDROGUI_CalculationDlg::OnNewRegion()
463 emit createRegion( myBrowser->getSelected() );
466 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
468 int aType = myBathymetryChoice->itemData( theIndex ).toInt();
469 QString aText = myBathymetryChoice->itemText( theIndex );
470 emit setMergeType( aType, aText );
473 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
476 HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
479 doShow = aZone->isMergingNeed();
484 // Fill the merge type combo box
485 bool prevBlock = myBathymetryChoice->blockSignals( true );
486 myCurrentZone = aZone;
487 myBathymetryChoice->clear();
488 myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
489 myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
490 myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
491 QStringList aList = aZone->getObjects();
492 for ( int i = 0; i < aList.length(); i++ )
494 myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
496 // Select the current choice if any
498 switch ( aZone->getMergeType() )
500 case HYDROData_Zone::Merge_ZMIN:
503 case HYDROData_Zone::Merge_ZMAX:
506 case HYDROData_Zone::Merge_Object:
507 aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
510 aCurIndex = 0; // Select unknown by default
512 myBathymetryChoice->setCurrentIndex( aCurIndex );
513 myBathymetryChoice->blockSignals( prevBlock );
516 myBathymetryChoice->setVisible( doShow );
517 myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
518 myBathymetryLabel->setVisible( doShow );
521 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
523 myObjectName->setText( theName );
526 QString HYDROGUI_CalculationDlg::getObjectName() const
528 return myObjectName->text();
531 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
533 QList<QListWidgetItem*> aFoundItems;
535 QListWidgetItem* anItem;
537 for ( int i = 0, n = theObjects.length(); i < n; ++i )
539 QString anObjName = theObjects.at( i );
540 aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
541 for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
543 anItem = aFoundItems.at( anIdx );
544 // Remove this object from available objects list
545 anItem = theSource->takeItem( theSource->row( anItem ) );
546 // Add the item to the included objects list
547 theDest->addItem( anItem );
552 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
554 QList<QListWidgetItem*> aFoundItems;
555 foreach ( const QString& anObjName, theObjects ) {
556 // Hide the object in the available objects list
557 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
558 foreach ( QListWidgetItem* anItem, aFoundItems ) {
559 anItem->setHidden( true );
562 // Add the object to the list of included objects
563 Handle(HYDROData_Entity) anObject =
564 HYDROGUI_Tool::FindObjectByName( module(), anObjName );
565 myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
568 myPriorityWidget->setObjects( getGeometryObjects() );
571 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
573 QList<QListWidgetItem*> aFoundItems;
574 foreach ( const QString& anObjName, theObjects ) {
575 // Set visible the object in the available objects list
576 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
577 foreach ( QListWidgetItem* anItem, aFoundItems ) {
578 anItem->setHidden( false );
581 // Remove the object from the list of included objects
582 myGeomObjects->removeObjectByName( anObjName );
585 myPriorityWidget->setObjects( getGeometryObjects() );
588 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
590 bool isBlocked = myPolylineName->blockSignals( true );
591 myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
592 myPolylineName->blockSignals( isBlocked );
595 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
597 myPolylineName->clear();
598 myPolylineName->addItem( "", "" ); // No boundary item
600 for ( int i = 0, n = theObjects.length(); i < n; ++i )
602 myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
606 void HYDROGUI_CalculationDlg::setStricklerTableNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
608 myStricklerTableName->clear();
610 for ( int i = 0, n = theObjects.length(); i < n; ++i )
612 myStricklerTableName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
616 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
618 myAvailableGeomObjects->clear();
620 for ( int i = 0, n = theObjects.length(); i < n; ++i )
622 QString anObjName = theObjects.at( i );
624 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
625 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
626 aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
630 QStringList getSelected( QListWidget* theWidget )
632 QStringList aResList;
633 QList<QListWidgetItem*> aList = theWidget->selectedItems();
634 for ( int i = 0, n = aList.length(); i < n; ++i )
636 aResList.append( aList.at( i )->text() );
641 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
643 return myGeomObjects->getSelectedNames();
646 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
648 return myGeomObjects->getAllNames();
651 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
653 return getSelected( myAvailableGeomObjects );
656 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
658 myEditedObject = theCase;
659 myValidator->setEditedObject( theCase );
661 // Build the calculation case subtree
662 module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject);
664 myBrowser->updateTree();
665 myBrowser->openLevels();
666 myBrowser->adjustColumnsWidth();
667 myBrowser->setAutoUpdate( true );
668 myBrowser->setUpdateModified( true );
671 // Build the calculation case subtree for Land Cover regions
672 module()->getDataModel()->buildCaseTree( myLandCoverBrowser->root(), myEditedObject, true );
674 myLandCoverBrowser->updateTree();
675 myLandCoverBrowser->openLevels();
676 myLandCoverBrowser->adjustColumnsWidth();
677 myLandCoverBrowser->setAutoUpdate( true );
678 myLandCoverBrowser->setUpdateModified( true );
682 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
684 return myCurrentZone;
687 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
689 SUIT_DataObject* aRoot = myBrowser->root();
690 module()->getDataModel()->updateObjectTree( myEditedObject );
691 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
692 myBrowser->updateTree( aRoot );
695 void HYDROGUI_CalculationDlg::onDataChanged()
697 SUIT_DataObject* aRoot = myBrowser->root();
698 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
699 myBrowser->updateTree( aRoot );
702 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
704 myAvailableGroups->clear();
706 foreach( QString aGroup, theGroups )
707 myAvailableGroups->addItem( aGroup );
710 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
712 return getSelected( myGroups );
715 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
717 return getSelected( myAvailableGroups );
720 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
722 moveItems( myAvailableGroups, myGroups, theObjects );
725 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
727 moveItems( myGroups, myAvailableGroups, theObjects );
732 @param theMode the mode
734 int HYDROGUI_CalculationDlg::getMode() const
736 return myModeButtons->checkedId();
741 @param theMode the mode
743 void HYDROGUI_CalculationDlg::setMode( int theMode )
745 bool isBlocked = myModeButtons->blockSignals( true );
746 myModeButtons->button( theMode )->setChecked( true );
747 myModeButtons->blockSignals( isBlocked );
749 bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
751 myGeomObjects->setOrderingEnabled( isAuto );
752 QWidget* aWidget = mySplitter->widget( 1 );
754 aWidget->setVisible( isAuto );
759 Enable/disable zones drag'n'drop and renaming.
760 @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
762 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
764 myBrowser->setReadOnly( !theIsEnabled );
768 Get included geometry objects.
769 @return the list of geometry objects
771 QList<Handle(HYDROData_Entity)> HYDROGUI_CalculationDlg::getGeometryObjects()
773 QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
774 QList<Handle(HYDROData_Entity)> anObjects;
776 foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
777 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
778 if ( anObj.IsNull() ) {
789 Get chosen land cover map.
790 @return the land cover map object
792 Handle(HYDROData_LandCoverMap) HYDROGUI_CalculationDlg::getLandCoverMap()
795 QList<Handle(HYDROData_Entity)> anEntities = myLandCovers->getObjects();
796 QList<Handle(HYDROData_Entity)> aLandCovers;
798 foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
799 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
800 if ( aLandCover.IsNull() ) {
804 aLandCovers << aLandCover;
809 Handle(HYDROData_LandCoverMap) aLandCoverMap = NULL;
810 return aLandCoverMap;
815 @return the list of rules
817 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
819 return myPriorityWidget->getRules();
824 @param theRules the list of rules
826 void HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
828 myPriorityWidget->setRules( theRules );
832 Slot called when objects order is changed.
834 void HYDROGUI_CalculationDlg::onOrderChanged()
836 bool isConfirmed = true;
837 emit orderChanged( isConfirmed );
839 myPriorityWidget->setObjects( getGeometryObjects() );
841 myGeomObjects->undoLastMove();
845 Slot called when priority rule for geometry objects is changed.
847 void HYDROGUI_CalculationDlg::onRuleChanged()
849 bool isConfirmed = true;
850 emit ruleChanged( isConfirmed );
852 myPriorityWidget->undoLastChange();
855 // TODO: setLandCoverMap(...)
856 void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals )
859 if ( theBlockSignals )
860 isBlocked = myStricklerTableName->blockSignals( true );
862 myStricklerTableName->setCurrentIndex( myStricklerTableName->findText( theStricklerTableName ) );
864 if ( theBlockSignals )
865 myStricklerTableName->blockSignals( isBlocked );
867 emit StricklerTableSelected( theStricklerTableName );