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( createLandCoversPage() );
75 addPage( createZonesPage() );
76 addPage( createLandCoverZonesPage() );
79 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
83 void HYDROGUI_CalculationDlg::reset()
85 myObjectName->clear();
86 HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
87 myGeomObjects->setObjects(anObject2VisibleList);
88 myLandCovers->setObjects(anObject2VisibleList);
89 myPolylineName->clear();
90 myStricklerTableName->clear();
91 myAvailableGeomObjects->clear();
92 myAvailableLandCovers->clear();
94 // Activate the automatic mode
95 setMode( HYDROData_CalculationCase::AUTOMATIC );
96 setLandCoverMode( HYDROData_CalculationCase::AUTOMATIC );
98 // Reset the priority widget state
99 QList<Handle(HYDROData_Entity)> anObjects;
100 myPriorityWidget->setObjects( anObjects );
101 myLandCoverPriorityWidget->setObjects( anObjects );
104 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
105 QWizardPage* aPage = new QWizardPage( mainFrame() );
106 QFrame* aFrame = new QFrame( aPage );
109 mySplitter = new QSplitter(Qt::Vertical);
112 QWidget* aTopContainer = new QWidget;
115 myObjectName = new QLineEdit( aPage );
116 myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
117 myObjectName->setValidator( myValidator );
119 connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) );
120 connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) );
123 myPolylineName = new QComboBox( aPage );
124 connect( myPolylineName, SIGNAL( activated( const QString & ) ),
125 SIGNAL( boundarySelected( const QString & ) ) );
128 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
129 QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
131 // mode selector (auto/manual)
132 QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
134 QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
135 QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
137 myModeButtons = new QButtonGroup( mainFrame() );
138 myModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
139 myModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
141 QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
142 aModeSelectorLayout->setMargin( 5 );
143 aModeSelectorLayout->setSpacing( 5 );
144 aModeSelectorLayout->addWidget( anAutoRB );
145 aModeSelectorLayout->addWidget( aManualRB );
146 aModeGroup->setLayout( aModeSelectorLayout );
149 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ) );
150 myGeomObjects = new HYDROGUI_OrderedListWidget( aPage, 16 );
151 myGeomObjects->setHiddenObjectsShown(true);
152 myGeomObjects->setVisibilityIconShown(false);
153 myGeomObjects->setContentsMargins(QMargins());
155 // included geometry objects
156 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ) );
157 myAvailableGeomObjects = new QListWidget( aPage );
158 myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
159 myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
160 myAvailableGeomObjects->setViewMode( QListWidget::ListMode );
161 myAvailableGeomObjects->setSortingEnabled( true );
164 QFrame* aBtnsFrame = new QFrame;
165 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
166 aBtnsLayout->setMargin( 5 );
167 aBtnsLayout->setSpacing( 5 );
168 aBtnsFrame->setLayout( aBtnsLayout );
169 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
170 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
172 // fill the butons frame with two buttons
173 aBtnsLayout->addWidget( anAddBtn );
174 aBtnsLayout->addWidget( aRemoveBtn );
175 aBtnsLayout->addStretch( 1 );
177 // top of the page layout
180 QFrame* anObjectsFrame = new QFrame( aPage );
181 anObjectsFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
182 QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
183 anObjsLayout->setMargin( 5 );
184 anObjsLayout->setSpacing( 5 );
185 anObjectsFrame->setLayout( anObjsLayout );
187 // fill the objects frame with two lists, two labels and with buttons frame
188 anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter );
189 anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
190 anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0 );
191 anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
192 anObjsLayout->addWidget( myGeomObjects, 1, 2 );
194 // fill the top of the page
195 QGridLayout* aTopLayout = new QGridLayout;
196 aTopLayout->setMargin( 5 );
197 aTopLayout->setSpacing( 5 );
198 aTopLayout->setVerticalSpacing( 10 );
199 aTopLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
200 aTopLayout->addWidget( myObjectName, 0, 1 );
201 aTopLayout->addWidget( aLimitsLabel, 1, 0, Qt::AlignHCenter );
202 aTopLayout->addWidget( myPolylineName, 1, 1 );
203 aTopLayout->addWidget( aModeGroup, 2, 0, 1, 2 );
204 aTopLayout->addWidget( anObjectsFrame, 3, 0, 1, 2 );
206 aTopContainer->setLayout( aTopLayout );
208 // add the top of the page to the splitter
209 mySplitter->insertWidget(0, aTopContainer);
210 mySplitter->setStretchFactor(0, 2);
212 // Bottom of the page
213 myPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
215 QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
216 QBoxLayout* aPriorityLayout = new QHBoxLayout;
217 aPriorityLayout->setMargin( 5 );
218 aPriorityLayout->setSpacing( 5 );
219 aPriorityLayout->addWidget( myPriorityWidget );
220 aPriorityGroup->setLayout( aPriorityLayout );
222 // add the bottom of the page to the splitter
223 mySplitter->insertWidget(1, aPriorityGroup);
224 mySplitter->setStretchFactor(1, 1);
227 QVBoxLayout* aPageLayout = new QVBoxLayout;
228 aPageLayout->setMargin( 5 );
229 aPageLayout->setSpacing( 5 );
230 aPageLayout->addWidget( mySplitter );
232 aPage->setLayout( aPageLayout );
236 HYDROGUI_ListSelector* aListSelector =
237 new HYDROGUI_ListSelector( myGeomObjects, module()->getApp()->selectionMgr() );
238 aListSelector->setAutoBlock( true );
242 connect( myModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeMode( int ) ) );
243 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) );
244 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) );
246 connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) );
251 QWizardPage* HYDROGUI_CalculationDlg::createGroupsPage() {
252 QWizardPage* aPage = new QWizardPage( mainFrame() );
253 QFrame* aFrame = new QFrame( aPage );
255 myGroups = new QListWidget( aPage );
256 myGroups->setSelectionMode( QListWidget::ExtendedSelection );
257 myGroups->setEditTriggers( QListWidget::NoEditTriggers );
258 myGroups->setViewMode( QListWidget::ListMode );
259 myGroups->setSortingEnabled( true );
261 myAvailableGroups = new QListWidget( aPage );
262 myAvailableGroups->setSelectionMode( QListWidget::ExtendedSelection );
263 myAvailableGroups->setEditTriggers( QListWidget::NoEditTriggers );
264 myAvailableGroups->setViewMode( QListWidget::ListMode );
265 myAvailableGroups->setSortingEnabled( true );
267 connect( myGroups, SIGNAL( itemSelectionChanged() ),
268 SIGNAL( groupsSelected() ) );
270 QFrame* aGroupsFrame = new QFrame( aPage );
271 QGridLayout* aGroupsLayout = new QGridLayout( aGroupsFrame );
272 aGroupsLayout->setMargin( 5 );
273 aGroupsLayout->setSpacing( 5 );
274 aGroupsFrame->setLayout( aGroupsLayout );
276 QFrame* aBtnsFrame = new QFrame( aGroupsFrame );
277 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
278 aBtnsLayout->setMargin( 5 );
279 aBtnsLayout->setSpacing( 5 );
280 aBtnsFrame->setLayout( aBtnsLayout );
281 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
282 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
284 // Fill the butons frame with two buttons
285 aBtnsLayout->addWidget( anAddBtn );
286 aBtnsLayout->addWidget( aRemoveBtn );
287 aBtnsLayout->addStretch( 1 );
289 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_GROUPS" ), aGroupsFrame );
290 QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_GROUPS" ), aGroupsFrame );
292 // Fill the objects frame with two lists, two labels and with buttons frame
293 aGroupsLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
294 aGroupsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
295 aGroupsLayout->addWidget( myAvailableGroups, 1, 0 );
296 aGroupsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
297 aGroupsLayout->addWidget( myGroups, 1, 2 );
300 QGridLayout* aPageLayout = new QGridLayout( aPage );
301 aPageLayout->setMargin( 5 );
302 aPageLayout->setSpacing( 5 );
303 aPageLayout->setVerticalSpacing( 10 );
304 aPageLayout->addWidget( aGroupsFrame, 0, 0 );
306 aPage->setLayout( aPageLayout );
308 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addGroups() ) );
309 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeGroups() ) );
314 QWizardPage* HYDROGUI_CalculationDlg::createLandCoversPage() {
315 QWizardPage* aPage = new QWizardPage( mainFrame() );
316 QFrame* aFrame = new QFrame( aPage );
319 myLandCoverSplitter = new QSplitter(Qt::Vertical);
322 QWidget* aTopContainer = new QWidget;
324 // Combo-box to choose Strickler table name
325 QLabel* aStricklerTableLabel = new QLabel( tr( "STRICKLER_TABLE" ), aPage );
326 myStricklerTableName = new QComboBox( aPage );
327 myStricklerTableName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
328 connect( myStricklerTableName, SIGNAL( activated( const QString & ) ),
329 SIGNAL( StricklerTableSelected( const QString & ) ) );
331 // Mode selector (auto/manual)
332 QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
334 QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
335 QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
337 myLandCoverModeButtons = new QButtonGroup( mainFrame() );
338 myLandCoverModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
339 myLandCoverModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
341 QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
342 aModeSelectorLayout->setMargin( 5 );
343 aModeSelectorLayout->setSpacing( 5 );
344 aModeSelectorLayout->addWidget( anAutoRB );
345 aModeSelectorLayout->addWidget( aManualRB );
346 aModeGroup->setLayout( aModeSelectorLayout );
348 // Available land covers
349 QLabel* aLandCoversLabel = new QLabel( tr( "CALCULATION_REFERENCE_LAND_COVERS" ) );
350 myAvailableLandCovers = new QListWidget( aPage );
351 myAvailableLandCovers->setSelectionMode( QListWidget::ExtendedSelection );
352 myAvailableLandCovers->setEditTriggers( QListWidget::NoEditTriggers );
353 myAvailableLandCovers->setViewMode( QListWidget::ListMode );
354 myAvailableLandCovers->setSortingEnabled( true );
356 // Included land covers
357 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_LAND_COVERS" ) );
358 myLandCovers = new HYDROGUI_OrderedListWidget( aPage, 16 );
359 myLandCovers->setHiddenObjectsShown(true);
360 myLandCovers->setVisibilityIconShown(false);
361 myLandCovers->setContentsMargins(QMargins());
363 // Include/Exclude buttons
364 QFrame* aBtnsFrame = new QFrame;
365 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
366 aBtnsLayout->setMargin( 5 );
367 aBtnsLayout->setSpacing( 5 );
368 aBtnsFrame->setLayout( aBtnsLayout );
369 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
370 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
372 // Fill the butons frame with two buttons
373 aBtnsLayout->addWidget( anAddBtn );
374 aBtnsLayout->addWidget( aRemoveBtn );
375 aBtnsLayout->addStretch( 1 );
378 QFrame* aLandCoversFrame = new QFrame( aPage );
379 aLandCoversFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
380 QGridLayout* aLandCoversLayout = new QGridLayout( aLandCoversFrame );
381 aLandCoversLayout->setMargin( 5 );
382 aLandCoversLayout->setSpacing( 5 );
383 aLandCoversFrame->setLayout( aLandCoversLayout );
385 // Fill the land covers frame with two lists, two labels and with buttons frame
386 aLandCoversLayout->addWidget( aLandCoversLabel, 0, 0, Qt::AlignHCenter );
387 aLandCoversLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
388 aLandCoversLayout->addWidget( myAvailableLandCovers, 1, 0 );
389 aLandCoversLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
390 aLandCoversLayout->addWidget( myLandCovers, 1, 2 );
392 // Fill the top layout of the page
393 QGridLayout* aTopLayout = new QGridLayout;
394 aTopLayout->setMargin( 5 );
395 aTopLayout->setSpacing( 5 );
396 aTopLayout->setVerticalSpacing( 10 );
397 aTopLayout->addWidget( aStricklerTableLabel, 0, 0, Qt::AlignHCenter );
398 aTopLayout->addWidget( myStricklerTableName, 0, 1 );
399 aTopLayout->addWidget( aModeGroup, 1, 0, 1, 2 );
400 aTopLayout->addWidget( aLandCoversFrame, 2, 0, 1, 2 );
402 aTopContainer->setLayout( aTopLayout );
404 // Add the top of the page to the splitter
405 myLandCoverSplitter->insertWidget(0, aTopContainer);
406 myLandCoverSplitter->setStretchFactor(0, 2);
408 // Bottom of the page
409 myLandCoverPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
410 HYDROGUI_PriorityTableModel* aModel =
411 dynamic_cast<HYDROGUI_PriorityTableModel*>( myLandCoverPriorityWidget->getTable()->model() );
413 aModel->setColumnCount( 3 );
415 QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
416 QBoxLayout* aPriorityLayout = new QHBoxLayout;
417 aPriorityLayout->setMargin( 5 );
418 aPriorityLayout->setSpacing( 5 );
419 aPriorityLayout->addWidget( myLandCoverPriorityWidget );
420 aPriorityGroup->setLayout( aPriorityLayout );
422 // Add the bottom of the page to the splitter
423 myLandCoverSplitter->insertWidget(1, aPriorityGroup);
424 myLandCoverSplitter->setStretchFactor(1, 1);
427 QVBoxLayout* aPageLayout = new QVBoxLayout;
428 aPageLayout->setMargin( 5 );
429 aPageLayout->setSpacing( 5 );
430 aPageLayout->addWidget( myLandCoverSplitter );
432 aPage->setLayout( aPageLayout );
436 HYDROGUI_ListSelector* aListSelector =
437 new HYDROGUI_ListSelector( myLandCovers, module()->getApp()->selectionMgr() );
438 aListSelector->setAutoBlock( true );
442 connect( myLandCoverModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeLandCoverMode( int ) ) );
443 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addLandCovers() ) );
444 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeLandCovers() ) );
446 connect( myLandCovers, SIGNAL( orderLandCoverChanged() ), SLOT( onOrderLandCoverChanged() ) );
451 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
452 QWizardPage* aPage = new QWizardPage( mainFrame() );
453 QFrame* aFrame = new QFrame( aPage );
455 QGridLayout* aLayout = new QGridLayout( aPage );
457 QLabel* aResultsOnGeomObjectsLabel = new QLabel( tr( "RESULTS_ON_GEOMETRY_OBJECTS" ), aFrame );
459 myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
460 myBrowser->setAutoOpenLevel( 3 );
461 aLayout->setMargin( 5 );
462 aLayout->setSpacing( 5 );
464 aLayout->addWidget( aResultsOnGeomObjectsLabel, 0, 0 );
465 aLayout->addWidget( myBrowser, 1, 0, 1, 2 );
467 myBathymetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
468 myBathymetryChoice = new QComboBox( aFrame );
470 myBathymetryChoice->setVisible( false );
471 myBathymetryLabel->setVisible( false );
473 aLayout->addWidget( myBathymetryLabel, 2, 0 );
474 aLayout->addWidget( myBathymetryChoice, 2, 1 );
476 aPage->setLayout( aLayout );
478 connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
479 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
480 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
481 connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
483 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
484 SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
485 connect( myBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewRegion() ) );
490 QWizardPage* HYDROGUI_CalculationDlg::createLandCoverZonesPage() {
491 QWizardPage* aPage = new QWizardPage( mainFrame() );
492 QFrame* aFrame = new QFrame( aPage );
494 QGridLayout* aLayout = new QGridLayout( aPage );
496 QLabel* aResultsOnLandCoversLabel = new QLabel( tr( "RESULTS_ON_LAND_COVERS" ), aFrame );
498 myLandCoverBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage, true );
499 myLandCoverBrowser->setAutoOpenLevel( 3 );
500 aLayout->setMargin( 5 );
501 aLayout->setSpacing( 5 );
503 aLayout->addWidget( aResultsOnLandCoversLabel, 0, 0 );
504 aLayout->addWidget( myLandCoverBrowser, 1, 0, 1, 2 );
506 myStricklerTypeLabel = new QLabel( tr( "STRICKLER_TYPE" ), aFrame );
507 myStricklerTypeChoice = new QComboBox( aFrame );
509 myStricklerTypeLabel->setVisible( false );
510 myStricklerTypeChoice->setVisible( false );
512 aLayout->addWidget( myStricklerTypeLabel, 2, 0 );
513 aLayout->addWidget( myStricklerTypeChoice, 2, 1 );
515 aPage->setLayout( aLayout );
518 connect( myLandCoverBrowser, SIGNAL( dataChanged() ), SLOT( onDataLandCoverChanged() ) );
519 connect( myLandCoverBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
520 connect( myLandCoverBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onLandCoverZoneSelected( SUIT_DataObject* ) ) );
521 connect( myStricklerTypeChoice, SIGNAL( activated( int ) ), SLOT( onMergeStricklerTypeSelected( int ) ) );
522 connect( myLandCoverBrowser,
523 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
524 SLOT( onLandCoverZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
525 connect( myLandCoverBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewLandCoverRegion() ) );
531 bool HYDROGUI_CalculationDlg::acceptCurrent() const
535 if ( false /*myGeomObjects->count() == 0*/ )
537 anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
540 if ( !anErrorMsg.isEmpty() )
542 anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
544 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
545 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
548 return anErrorMsg.isEmpty();
551 void HYDROGUI_CalculationDlg::onEmptyName()
553 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
554 QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
555 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
558 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
560 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
561 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
562 "\n" + tr( "INPUT_VALID_DATA" );
563 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
566 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList,
567 SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
569 QList<SUIT_DataObject*> aZonesList;
570 HYDROGUI_Zone* aZone;
571 // Get a list of dropped zones
572 for ( int i = 0; i < theList.length(); i++ )
574 aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
577 aZonesList.append( aZone );
580 if ( aZonesList.length() > 0 )
582 // Get the target region
583 HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
586 // Create a new region
587 emit createRegion( aZonesList );
591 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
594 emit moveZones( theTargetParent, aZonesList, false );
600 void HYDROGUI_CalculationDlg::OnNewRegion()
602 emit createRegion( myBrowser->getSelected() );
605 void HYDROGUI_CalculationDlg::OnNewLandCoverRegion()
607 emit createLandCoverRegion( myLandCoverBrowser->getSelected() );
610 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
612 int aType = myBathymetryChoice->itemData( theIndex ).toInt();
613 QString aText = myBathymetryChoice->itemText( theIndex );
614 emit setMergeType( aType, aText );
617 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
620 HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
623 doShow = aZone->isMergingNeed();
628 // Fill the merge type combo box
629 bool prevBlock = myBathymetryChoice->blockSignals( true );
630 myCurrentZone = aZone;
631 myBathymetryChoice->clear();
632 myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
633 myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
634 myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
635 QStringList aList = aZone->getObjects();
636 for ( int i = 0; i < aList.length(); i++ )
638 myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
640 // Select the current choice if any
642 switch ( aZone->getMergeType() )
644 case HYDROData_Zone::Merge_ZMIN:
647 case HYDROData_Zone::Merge_ZMAX:
650 case HYDROData_Zone::Merge_Object:
651 aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
654 aCurIndex = 0; // Select unknown by default
656 myBathymetryChoice->setCurrentIndex( aCurIndex );
657 myBathymetryChoice->blockSignals( prevBlock );
660 myBathymetryChoice->setVisible( doShow );
661 myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
662 myBathymetryLabel->setVisible( doShow );
665 void HYDROGUI_CalculationDlg::onLandCoverZoneSelected( SUIT_DataObject* theObject )
668 HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
671 doShow = aZone->isMergingNeed();
676 // Fill the merge type combo box
677 bool prevBlock = myStricklerTypeChoice->blockSignals( true );
678 myCurrentZone = aZone;
679 myStricklerTypeChoice->clear();
680 myStricklerTypeChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
681 QStringList aList = aZone->getObjects();
682 for ( int i = 0; i < aList.length(); i++ )
684 myStricklerTypeChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
686 // Select the current choice if any
688 switch ( aZone->getMergeType() )
690 case HYDROData_Zone::Merge_Object:
691 aCurIndex = 1 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
694 aCurIndex = 0; // Select unknown by default
696 myStricklerTypeChoice->setCurrentIndex( aCurIndex );
697 myStricklerTypeChoice->blockSignals( prevBlock );
700 myStricklerTypeChoice->setVisible( doShow );
701 myStricklerTypeChoice->setEnabled( getLandCoverMode() == HYDROData_CalculationCase::MANUAL );
702 myStricklerTypeLabel->setVisible( doShow );
705 void HYDROGUI_CalculationDlg::onMergeStricklerTypeSelected( int theIndex )
707 int aType = myStricklerTypeChoice->itemData( theIndex ).toInt();
708 QString aText = myStricklerTypeChoice->itemText( theIndex );
709 emit setMergeStricklerType( aType, aText );
712 void HYDROGUI_CalculationDlg::onLandCoverZonesDropped( const QList<SUIT_DataObject*>& theList,
713 SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
715 QList<SUIT_DataObject*> aZonesList;
716 HYDROGUI_Zone* aZone;
717 // Get a list of dropped land cover zones
718 for ( int i = 0; i < theList.length(); i++ )
720 aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
723 aZonesList.append( aZone );
726 if ( aZonesList.length() > 0 )
728 // Get the target region
729 HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
732 // Create a new region
733 emit createLandCoverRegion( aZonesList );
737 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
740 emit moveZones( theTargetParent, aZonesList, true );
746 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
748 myObjectName->setText( theName );
751 QString HYDROGUI_CalculationDlg::getObjectName() const
753 return myObjectName->text();
756 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
758 QList<QListWidgetItem*> aFoundItems;
760 QListWidgetItem* anItem;
762 for ( int i = 0, n = theObjects.length(); i < n; ++i )
764 QString anObjName = theObjects.at( i );
765 aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
766 for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
768 anItem = aFoundItems.at( anIdx );
769 // Remove this object from available objects list
770 anItem = theSource->takeItem( theSource->row( anItem ) );
771 // Add the item to the included objects list
772 theDest->addItem( anItem );
777 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
779 QList<QListWidgetItem*> aFoundItems;
780 foreach ( const QString& anObjName, theObjects ) {
781 // Hide the object in the available objects list
782 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
783 foreach ( QListWidgetItem* anItem, aFoundItems ) {
784 anItem->setHidden( true );
787 // Add the object to the list of included objects
788 Handle(HYDROData_Entity) anObject =
789 HYDROGUI_Tool::FindObjectByName( module(), anObjName );
790 myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
793 myPriorityWidget->setObjects( getGeometryObjects() );
796 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
798 QList<QListWidgetItem*> aFoundItems;
799 foreach ( const QString& anObjName, theObjects ) {
800 // Set visible the object in the available objects list
801 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
802 foreach ( QListWidgetItem* anItem, aFoundItems ) {
803 anItem->setHidden( false );
806 // Remove the object from the list of included objects
807 myGeomObjects->removeObjectByName( anObjName );
810 myPriorityWidget->setObjects( getGeometryObjects() );
813 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
815 bool isBlocked = myPolylineName->blockSignals( true );
816 myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
817 myPolylineName->blockSignals( isBlocked );
820 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
822 myPolylineName->clear();
823 myPolylineName->addItem( "", "" ); // No boundary item
825 for ( int i = 0, n = theObjects.length(); i < n; ++i )
827 myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
831 void HYDROGUI_CalculationDlg::setStricklerTableNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
833 myStricklerTableName->clear();
835 for ( int i = 0, n = theObjects.length(); i < n; ++i )
837 myStricklerTableName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
841 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
843 myAvailableGeomObjects->clear();
845 for ( int i = 0, n = theObjects.length(); i < n; ++i )
847 QString anObjName = theObjects.at( i );
849 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
850 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
851 aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
855 void HYDROGUI_CalculationDlg::setAllLandCovers( const QStringList& theObjects, const QStringList& theObjectsEntries )
857 myAvailableLandCovers->clear();
859 for ( int i = 0, n = theObjects.length(); i < n; ++i )
861 QString anObjName = theObjects.at( i );
863 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableLandCovers );
864 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
865 aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
869 QStringList getSelected( QListWidget* theWidget )
871 QStringList aResList;
872 QList<QListWidgetItem*> aList = theWidget->selectedItems();
873 for ( int i = 0, n = aList.length(); i < n; ++i )
875 aResList.append( aList.at( i )->text() );
880 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
882 return myGeomObjects->getSelectedNames();
885 QStringList HYDROGUI_CalculationDlg::getSelectedLandCovers() const
887 return myLandCovers->getSelectedNames();
890 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
892 return myGeomObjects->getAllNames();
895 QStringList HYDROGUI_CalculationDlg::getAllLandCovers() const
897 return myLandCovers->getAllNames();
900 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
902 return getSelected( myAvailableGeomObjects );
905 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableLandCovers() const
907 return getSelected( myAvailableLandCovers );
910 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
912 myEditedObject = theCase;
913 myValidator->setEditedObject( theCase );
915 // Build the calculation case subtree
916 module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject, false );
918 myBrowser->updateTree();
919 myBrowser->openLevels();
920 myBrowser->adjustColumnsWidth();
921 myBrowser->setAutoUpdate( true );
922 myBrowser->setUpdateModified( true );
924 // Build the calculation case subtree for Land Cover regions
925 module()->getDataModel()->buildCaseTree( myLandCoverBrowser->root(), myEditedObject, true );
927 myLandCoverBrowser->updateTree();
928 myLandCoverBrowser->openLevels();
929 myLandCoverBrowser->adjustColumnsWidth();
930 myLandCoverBrowser->setAutoUpdate( true );
931 myLandCoverBrowser->setUpdateModified( true );
934 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
936 return myCurrentZone;
939 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
941 SUIT_DataObject* aRoot = myBrowser->root();
942 module()->getDataModel()->updateObjectTree( myEditedObject );
943 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, false );
944 myBrowser->updateTree( aRoot );
947 void HYDROGUI_CalculationDlg::onDataChanged()
949 SUIT_DataObject* aRoot = myBrowser->root();
950 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, false );
951 myBrowser->updateTree( aRoot );
954 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
956 myAvailableGroups->clear();
958 foreach( QString aGroup, theGroups )
959 myAvailableGroups->addItem( aGroup );
962 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
964 return getSelected( myGroups );
967 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
969 return getSelected( myAvailableGroups );
972 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
974 moveItems( myAvailableGroups, myGroups, theObjects );
977 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
979 moveItems( myGroups, myAvailableGroups, theObjects );
984 @param theMode the mode
986 int HYDROGUI_CalculationDlg::getMode() const
988 return myModeButtons->checkedId();
993 @param theMode the mode
995 void HYDROGUI_CalculationDlg::setMode( int theMode )
997 bool isBlocked = myModeButtons->blockSignals( true );
998 myModeButtons->button( theMode )->setChecked( true );
999 myModeButtons->blockSignals( isBlocked );
1001 bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
1003 myGeomObjects->setOrderingEnabled( isAuto );
1004 QWidget* aWidget = mySplitter->widget( 1 );
1006 aWidget->setVisible( isAuto );
1011 Get creation mode for land covers panel.
1012 @param theMode the mode
1014 int HYDROGUI_CalculationDlg::getLandCoverMode() const
1016 return myLandCoverModeButtons->checkedId();
1020 Set creation mode for land cover panel.
1021 @param theMode the mode
1023 void HYDROGUI_CalculationDlg::setLandCoverMode( int theMode )
1025 bool isBlocked = myLandCoverModeButtons->blockSignals( true );
1026 myLandCoverModeButtons->button( theMode )->setChecked( true );
1027 myLandCoverModeButtons->blockSignals( isBlocked );
1029 bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
1031 myLandCovers->setOrderingEnabled( isAuto );
1032 QWidget* aWidget = myLandCoverSplitter->widget( 1 );
1034 aWidget->setVisible( isAuto );
1039 Enable/disable zones drag'n'drop and renaming.
1040 @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
1042 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
1044 myBrowser->setReadOnly( !theIsEnabled );
1048 Enable/disable land covers drag'n'drop and renaming.
1049 @param theIsEnabled if true - land covers drag'n'drop and renaming will be enabled
1051 void HYDROGUI_CalculationDlg::setEditLandCoverZonesEnabled( const bool theIsEnabled )
1053 myLandCoverBrowser->setReadOnly( !theIsEnabled );
1057 Get included geometry objects.
1058 @return the list of geometry objects
1060 QList<Handle(HYDROData_Entity)> HYDROGUI_CalculationDlg::getGeometryObjects()
1062 QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
1063 QList<Handle(HYDROData_Entity)> anObjects;
1065 foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
1066 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
1067 if ( anObj.IsNull() ) {
1078 Get included land covers.
1079 @return the list of land covers
1081 QList<Handle(HYDROData_Entity)> HYDROGUI_CalculationDlg::getLandCovers()
1083 QList<Handle(HYDROData_Entity)> anEntities = myLandCovers->getObjects();
1084 QList<Handle(HYDROData_Entity)> aLandCovers;
1086 foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
1087 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
1088 if ( aLandCover.IsNull() ) {
1092 aLandCovers << aLandCover;
1100 @return the list of rules
1102 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
1104 return myPriorityWidget->getRules();
1109 @param theRules the list of rules
1111 void HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
1113 myPriorityWidget->setRules( theRules );
1117 Get rules defined for land covers.
1118 @return the list of rules
1120 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getLandCoverRules() const
1122 return myLandCoverPriorityWidget->getRules();
1126 Set rules for land covers.
1127 @param theRules the list of rules
1129 void HYDROGUI_CalculationDlg::setLandCoverRules( const HYDROData_ListOfRules& theRules ) const
1131 myLandCoverPriorityWidget->setRules( theRules );
1135 Slot called when objects order is changed.
1137 void HYDROGUI_CalculationDlg::onOrderChanged()
1139 bool isConfirmed = true;
1140 emit orderChanged( isConfirmed );
1142 myPriorityWidget->setObjects( getGeometryObjects() );
1144 myGeomObjects->undoLastMove();
1147 void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals )
1150 if ( theBlockSignals )
1151 isBlocked = myStricklerTableName->blockSignals( true );
1153 myStricklerTableName->setCurrentIndex( myStricklerTableName->findText( theStricklerTableName ) );
1155 if ( theBlockSignals )
1156 myStricklerTableName->blockSignals( isBlocked );
1158 emit StricklerTableSelected( theStricklerTableName );
1161 void HYDROGUI_CalculationDlg::includeLandCovers( const QStringList& theLandCovers, bool theReset )
1165 HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
1166 myLandCovers->setObjects(anObject2VisibleList);
1169 QList<QListWidgetItem*> aFoundItems;
1170 foreach ( const QString& anObjName, theLandCovers ) {
1171 // Hide the land cover in the available land covers list
1172 aFoundItems = myAvailableLandCovers->findItems( anObjName, Qt::MatchExactly );
1173 foreach ( QListWidgetItem* anItem, aFoundItems ) {
1174 anItem->setHidden( true );
1177 // Add the land cover to the list of included objects
1178 Handle(HYDROData_Entity) anObject =
1179 HYDROGUI_Tool::FindObjectByName( module(), anObjName );
1180 myLandCovers->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
1183 myLandCoverPriorityWidget->setObjects( getLandCovers() );
1186 void HYDROGUI_CalculationDlg::excludeLandCovers( const QStringList& theLandCovers )
1188 QList<QListWidgetItem*> aFoundItems;
1189 foreach ( const QString& anObjName, theLandCovers ) {
1190 // Set visible the land cover in the available objects list
1191 aFoundItems = myAvailableLandCovers->findItems( anObjName, Qt::MatchExactly );
1192 foreach ( QListWidgetItem* anItem, aFoundItems ) {
1193 anItem->setHidden( false );
1196 // Remove the land cover from the list of included objects
1197 myLandCovers->removeObjectByName( anObjName );
1200 myLandCoverPriorityWidget->setObjects( getLandCovers() );
1203 void HYDROGUI_CalculationDlg::refreshLandCoverZonesBrowser()
1205 SUIT_DataObject* aRoot = myLandCoverBrowser->root();
1206 module()->getDataModel()->updateObjectTree( myEditedObject );
1207 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, true );
1208 myLandCoverBrowser->updateTree( aRoot );
1212 Slot called when zones created on land covers are changed.
1214 void HYDROGUI_CalculationDlg::onDataLandCoverChanged()
1216 SUIT_DataObject* aRoot = myLandCoverBrowser->root();
1217 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, true );
1218 myLandCoverBrowser->updateTree( aRoot );
1222 Slot called when land covers order is changed.
1224 void HYDROGUI_CalculationDlg::onOrderLandCoverChanged()
1226 bool isConfirmed = true;
1227 emit orderLandCoverChanged( isConfirmed );
1229 myLandCoverPriorityWidget->setObjects( getLandCovers() );
1231 myLandCovers->undoLastMove();