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_Tool2.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( createBoundaryPolygonsPage() );
76 addPage( createLandCoverMapPage() );
77 addPage( createZonesPage() );
80 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
84 void HYDROGUI_CalculationDlg::reset()
86 myObjectName->clear();
87 HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
88 myGeomObjects->setObjects(anObject2VisibleList);
89 myPolylineName->clear();
90 myLandCoverMapName->clear();
91 myStricklerTableName->clear();
92 myAvailableGeomObjects->clear();
94 // Activate the automatic mode
95 setMode( HYDROData_CalculationCase::AUTOMATIC );
97 // Reset the priority widget state
98 QList<Handle(HYDROData_Entity)> anObjects;
99 myPriorityWidget->setObjects( anObjects );
102 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
103 QWizardPage* aPage = new QWizardPage( mainFrame() );
104 QFrame* aFrame = new QFrame( aPage );
107 mySplitter = new QSplitter(Qt::Vertical);
110 QWidget* aTopContainer = new QWidget;
113 myObjectName = new QLineEdit( aPage );
114 myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
115 myObjectName->setValidator( myValidator );
117 connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) );
118 connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) );
121 myPolylineName = new QComboBox( aPage );
122 connect( myPolylineName, SIGNAL( activated( const QString & ) ),
123 SIGNAL( boundarySelected( const QString & ) ) );
126 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
127 QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
129 // mode selector (auto/manual)
130 QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
132 QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
133 QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
135 myModeButtons = new QButtonGroup( mainFrame() );
136 myModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
137 myModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
139 QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
140 aModeSelectorLayout->setMargin( 5 );
141 aModeSelectorLayout->setSpacing( 5 );
142 aModeSelectorLayout->addWidget( anAutoRB );
143 aModeSelectorLayout->addWidget( aManualRB );
144 aModeGroup->setLayout( aModeSelectorLayout );
147 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ) );
148 myGeomObjects = new HYDROGUI_OrderedListWidget( aPage, 16 );
149 myGeomObjects->setHiddenObjectsShown(true);
150 myGeomObjects->setVisibilityIconShown(false);
151 myGeomObjects->setContentsMargins(QMargins());
153 // included geometry objects
154 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ) );
155 myAvailableGeomObjects = new QListWidget( aPage );
156 myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
157 myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
158 myAvailableGeomObjects->setViewMode( QListWidget::ListMode );
159 myAvailableGeomObjects->setSortingEnabled( true );
162 QFrame* aBtnsFrame = new QFrame;
163 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
164 aBtnsLayout->setMargin( 5 );
165 aBtnsLayout->setSpacing( 5 );
166 aBtnsFrame->setLayout( aBtnsLayout );
167 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
168 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
170 // fill the butons frame with two buttons
171 aBtnsLayout->addWidget( anAddBtn );
172 aBtnsLayout->addWidget( aRemoveBtn );
173 aBtnsLayout->addStretch( 1 );
175 // top of the page layout
178 QFrame* anObjectsFrame = new QFrame( aPage );
179 anObjectsFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
180 QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
181 anObjsLayout->setMargin( 5 );
182 anObjsLayout->setSpacing( 5 );
183 anObjectsFrame->setLayout( anObjsLayout );
185 // fill the objects frame with two lists, two labels and with buttons frame
186 anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter );
187 anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
188 anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0 );
189 anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
190 anObjsLayout->addWidget( myGeomObjects, 1, 2 );
192 // fill the top of the page
193 QGridLayout* aTopLayout = new QGridLayout;
194 aTopLayout->setMargin( 5 );
195 aTopLayout->setSpacing( 5 );
196 aTopLayout->setVerticalSpacing( 10 );
197 aTopLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
198 aTopLayout->addWidget( myObjectName, 0, 1 );
199 aTopLayout->addWidget( aLimitsLabel, 1, 0, Qt::AlignHCenter );
200 aTopLayout->addWidget( myPolylineName, 1, 1 );
201 aTopLayout->addWidget( aModeGroup, 2, 0, 1, 2 );
202 aTopLayout->addWidget( anObjectsFrame, 3, 0, 1, 2 );
204 aTopContainer->setLayout( aTopLayout );
206 // add the top of the page to the splitter
207 mySplitter->insertWidget(0, aTopContainer);
208 mySplitter->setStretchFactor(0, 2);
210 // Bottom of the page
211 myPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
213 QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
214 QBoxLayout* aPriorityLayout = new QHBoxLayout;
215 aPriorityLayout->setMargin( 5 );
216 aPriorityLayout->setSpacing( 5 );
217 aPriorityLayout->addWidget( myPriorityWidget );
218 aPriorityGroup->setLayout( aPriorityLayout );
220 // add the bottom of the page to the splitter
221 mySplitter->insertWidget(1, aPriorityGroup);
222 mySplitter->setStretchFactor(1, 1);
225 QVBoxLayout* aPageLayout = new QVBoxLayout;
226 aPageLayout->setMargin( 5 );
227 aPageLayout->setSpacing( 5 );
228 aPageLayout->addWidget( mySplitter );
230 aPage->setLayout( aPageLayout );
234 HYDROGUI_ListSelector* aListSelector =
235 new HYDROGUI_ListSelector( myGeomObjects, module()->getApp()->selectionMgr() );
236 aListSelector->setAutoBlock( true );
240 connect( myModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeMode( int ) ) );
241 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) );
242 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) );
244 connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) );
246 connect( myPriorityWidget, SIGNAL( ruleChanged() ), SLOT( onRuleChanged() ) );
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::createBoundaryPolygonsPage() {
315 QWizardPage* aPage = new QWizardPage( mainFrame() );
316 QFrame* aFrame = new QFrame( aPage );
318 myBoundaryPolygons = new QListWidget( aPage );
319 myBoundaryPolygons->setSelectionMode( QListWidget::ExtendedSelection );
320 myBoundaryPolygons->setEditTriggers( QListWidget::NoEditTriggers );
321 myBoundaryPolygons->setViewMode( QListWidget::ListMode );
322 myBoundaryPolygons->setSortingEnabled( true );
324 myISBoundaryPolygons = new QListWidget( aPage );
325 myISBoundaryPolygons->setSelectionMode( QListWidget::ExtendedSelection );
326 myISBoundaryPolygons->setEditTriggers( QListWidget::NoEditTriggers );
327 myISBoundaryPolygons->setViewMode( QListWidget::ListMode );
328 myISBoundaryPolygons->setSortingEnabled( true );
330 myAvailableBoundaryPolygons = new QListWidget( aPage );
331 myAvailableBoundaryPolygons->setSelectionMode( QListWidget::ExtendedSelection );
332 myAvailableBoundaryPolygons->setEditTriggers( QListWidget::NoEditTriggers );
333 myAvailableBoundaryPolygons->setViewMode( QListWidget::ListMode );
334 myAvailableBoundaryPolygons->setSortingEnabled( true );
336 //connect( myGroups, SIGNAL( itemSelectionChanged() ),
337 // SIGNAL( groupsSelected() ) ); //TODO
339 QFrame* aBPFrame = new QFrame( aPage );
340 QGridLayout* aBPLayout = new QGridLayout( aBPFrame );
341 aBPLayout->setMargin( 5 );
342 aBPLayout->setSpacing( 5 );
343 aBPFrame->setLayout( aBPLayout );
345 QFrame* aBtnsFrame = new QFrame( aBPFrame );
346 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
347 aBtnsLayout->setMargin( 5 );
348 aBtnsLayout->setSpacing( 5 );
349 aBtnsFrame->setLayout( aBtnsLayout );
350 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
351 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
353 // Fill the butons frame with two buttons
354 aBtnsLayout->addWidget( anAddBtn );
355 aBtnsLayout->addWidget( aRemoveBtn );
356 aBtnsLayout->addStretch( 1 );
358 QLabel* anIncludedLabelCut = new QLabel( tr( "INCLUDED_BOUNDARY_POLYGONS_CUT" ), aBPFrame );
360 QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_BOUNDARY_POLYGONS" ), aBPFrame );
362 QLabel* anIncludedLabelIS = new QLabel( tr( "INCLUDED_BOUNDARY_POLYGONS_INCSEL" ) );
364 // Fill the objects frame with two lists, two labels and with buttons frame
365 aBPLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
366 aBPLayout->addWidget( anIncludedLabelCut, 0, 2, Qt::AlignHCenter );
368 aBPLayout->addWidget( myAvailableBoundaryPolygons, 1, 0, 3, 1 );
369 aBPLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
370 aBPLayout->addWidget( myBoundaryPolygons, 1, 2 );
372 aBPLayout->addWidget( anIncludedLabelIS, 2, 2 );
374 aBPLayout->addWidget( myISBoundaryPolygons, 3, 2 );
378 QGridLayout* aPageLayout = new QGridLayout( aPage );
379 aPageLayout->setMargin( 5 );
380 aPageLayout->setSpacing( 5 );
381 aPageLayout->setVerticalSpacing( 10 );
382 aPageLayout->addWidget( aBPFrame, 0, 0 );
384 aPage->setLayout( aPageLayout );
386 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addBoundaryPolygons() ) );
387 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeBoundaryPolygons() ) );
393 QWizardPage* HYDROGUI_CalculationDlg::createLandCoverMapPage() {
394 QWizardPage* aPage = new QWizardPage( mainFrame() );
395 QFrame* aFrame = new QFrame( aPage );
398 QWidget* aTopContainer = new QWidget;
400 // Combo-box to choose land cover map object
401 QLabel* aLandCoverMapLabel = new QLabel( tr( "LAND_COVER_MAP" ), aPage );
402 myLandCoverMapName = new QComboBox( aPage );
403 myLandCoverMapName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
404 connect( myLandCoverMapName, SIGNAL( activated( const QString & ) ),
405 SIGNAL( landCoverMapSelected( const QString & ) ) );
406 // Combo-box to choose Strickler table name
407 QLabel* aStricklerTableLabel = new QLabel( tr( "STRICKLER_TABLE" ), aPage );
408 myStricklerTableName = new QComboBox( aPage );
409 myStricklerTableName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
410 connect( myStricklerTableName, SIGNAL( activated( const QString & ) ),
411 SIGNAL( StricklerTableSelected( const QString & ) ) );
413 // Fill the top layout of the page
414 QGridLayout* aGridLayout = new QGridLayout;
415 aGridLayout->setMargin( 5 );
416 aGridLayout->setSpacing( 5 );
417 aGridLayout->setVerticalSpacing( 10 );
418 aGridLayout->addWidget( aLandCoverMapLabel, 0, 0 );
419 aGridLayout->addWidget( myLandCoverMapName, 0, 1 );
420 aGridLayout->addWidget( aStricklerTableLabel, 1, 0 );
421 aGridLayout->addWidget( myStricklerTableName, 1, 1 );
423 QVBoxLayout* aTopLayout = new QVBoxLayout;
424 aTopLayout->setMargin( 5 );
425 aTopLayout->setSpacing( 5 );
426 aTopLayout->addLayout( aGridLayout );
427 aTopLayout->addStretch( 1 );
429 aTopContainer->setLayout( aTopLayout );
431 aPage->setLayout( aTopLayout );
436 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
437 QWizardPage* aPage = new QWizardPage( mainFrame() );
438 QFrame* aFrame = new QFrame( aPage );
440 QGridLayout* aLayout = new QGridLayout( aPage );
442 QLabel* aResultsOnGeomObjectsLabel = new QLabel( tr( "RESULTS_ON_GEOMETRY_OBJECTS" ), aFrame );
444 myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
445 myBrowser->setAutoOpenLevel( 3 );
446 aLayout->setMargin( 5 );
447 aLayout->setSpacing( 5 );
449 aLayout->addWidget( aResultsOnGeomObjectsLabel, 0, 0 );
450 aLayout->addWidget( myBrowser, 1, 0, 1, 2 );
452 myBathymetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
453 myBathymetryChoice = new QComboBox( aFrame );
455 myBathymetryChoice->setVisible( false );
456 myBathymetryLabel->setVisible( false );
458 aLayout->addWidget( myBathymetryLabel, 2, 0 );
459 aLayout->addWidget( myBathymetryChoice, 2, 1 );
461 QPushButton* aRegenerateBtn = new QPushButton( tr( "REGENERATE_COLORS" ), this );
462 aLayout->addWidget( aRegenerateBtn, 3, 0 );
464 aPage->setLayout( aLayout );
466 connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
467 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
468 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
469 connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
471 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
472 SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
473 connect( myBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewRegion() ) );
474 connect( aRegenerateBtn, SIGNAL( clicked() ), this, SIGNAL( regenerateColors() ) );
478 bool HYDROGUI_CalculationDlg::acceptCurrent() const
482 if ( false /*myGeomObjects->count() == 0*/ )
484 anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
487 if ( !anErrorMsg.isEmpty() )
489 anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
491 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
492 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
495 return anErrorMsg.isEmpty();
498 void HYDROGUI_CalculationDlg::onEmptyName()
500 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
501 QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
502 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
505 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
507 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
508 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
509 "\n" + tr( "INPUT_VALID_DATA" );
510 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
513 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList,
514 SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
516 QList<SUIT_DataObject*> aZonesList;
517 HYDROGUI_Zone* aZone;
518 // Get a list of dropped zones
519 for ( int i = 0; i < theList.length(); i++ )
521 aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
524 aZonesList.append( aZone );
527 if ( aZonesList.length() > 0 )
529 // Get the target region
530 HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
533 // Create a new region
534 emit createRegion( aZonesList );
538 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
541 emit moveZones( theTargetParent, aZonesList );
547 void HYDROGUI_CalculationDlg::OnNewRegion()
549 emit createRegion( myBrowser->getSelected() );
552 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
554 int aType = myBathymetryChoice->itemData( theIndex ).toInt();
555 QString aText = myBathymetryChoice->itemText( theIndex );
556 emit setMergeType( aType, aText );
559 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
562 HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
565 doShow = aZone->isMergingNeed();
570 // Fill the merge type combo box
571 bool prevBlock = myBathymetryChoice->blockSignals( true );
572 myCurrentZone = aZone;
573 myBathymetryChoice->clear();
574 myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
575 myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
576 myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
577 QStringList aList = aZone->getObjects();
578 for ( int i = 0; i < aList.length(); i++ )
580 myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
582 // Select the current choice if any
584 switch ( aZone->getMergeType() )
586 case HYDROData_Zone::Merge_ZMIN:
589 case HYDROData_Zone::Merge_ZMAX:
592 case HYDROData_Zone::Merge_Object:
593 aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
596 aCurIndex = 0; // Select unknown by default
598 myBathymetryChoice->setCurrentIndex( aCurIndex );
599 myBathymetryChoice->blockSignals( prevBlock );
602 myBathymetryChoice->setVisible( doShow );
603 myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
604 myBathymetryLabel->setVisible( doShow );
607 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
609 myObjectName->setText( theName );
612 QString HYDROGUI_CalculationDlg::getObjectName() const
614 return myObjectName->text();
617 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
619 QList<QListWidgetItem*> aFoundItems;
621 QListWidgetItem* anItem;
623 for ( int i = 0, n = theObjects.length(); i < n; ++i )
625 QString anObjName = theObjects.at( i );
626 aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
627 for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
629 anItem = aFoundItems.at( anIdx );
630 // Remove this object from available objects list
631 anItem = theSource->takeItem( theSource->row( anItem ) );
632 // Add the item to the included objects list
633 theDest->addItem( anItem );
638 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
640 QList<QListWidgetItem*> aFoundItems;
641 foreach ( const QString& anObjName, theObjects ) {
642 // Hide the object in the available objects list
643 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
644 foreach ( QListWidgetItem* anItem, aFoundItems ) {
645 anItem->setHidden( true );
648 // Add the object to the list of included objects
649 Handle(HYDROData_Entity) anObject =
650 HYDROGUI_Tool::FindObjectByName( module(), anObjName );
651 myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
654 myPriorityWidget->setObjects( getGeometryObjects() );
657 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
659 QList<QListWidgetItem*> aFoundItems;
660 foreach ( const QString& anObjName, theObjects ) {
661 // Set visible the object in the available objects list
662 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
663 foreach ( QListWidgetItem* anItem, aFoundItems ) {
664 anItem->setHidden( false );
667 // Remove the object from the list of included objects
668 myGeomObjects->removeObjectByName( anObjName );
671 myPriorityWidget->setObjects( getGeometryObjects() );
674 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
676 bool isBlocked = myPolylineName->blockSignals( true );
677 myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
678 myPolylineName->blockSignals( isBlocked );
681 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
683 myPolylineName->clear();
684 myPolylineName->addItem( "", "" ); // No boundary item
686 for ( int i = 0, n = theObjects.length(); i < n; ++i )
688 myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
692 void HYDROGUI_CalculationDlg::setLandCoverMapsNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
694 myLandCoverMapName->clear();
696 for ( int i = 0, n = theObjects.length(); i < n; ++i )
698 myLandCoverMapName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
702 void HYDROGUI_CalculationDlg::setStricklerTableNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
704 myStricklerTableName->clear();
706 for ( int i = 0, n = theObjects.length(); i < n; ++i )
708 myStricklerTableName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
712 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
714 myAvailableGeomObjects->clear();
716 for ( int i = 0, n = theObjects.length(); i < n; ++i )
718 QString anObjName = theObjects.at( i );
720 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
721 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
722 aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
726 QStringList getSelected( QListWidget* theWidget )
728 QStringList aResList;
729 QList<QListWidgetItem*> aList = theWidget->selectedItems();
730 for ( int i = 0, n = aList.length(); i < n; ++i )
732 aResList.append( aList.at( i )->text() );
737 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
739 return myGeomObjects->getSelectedNames();
742 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
744 return myGeomObjects->getAllNames();
747 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
749 return getSelected( myAvailableGeomObjects );
752 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
754 myEditedObject = theCase;
755 myValidator->setEditedObject( myEditedObject );
757 // Build the calculation case subtree
758 module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject);
760 myBrowser->updateTree();
761 myBrowser->openLevels();
762 myBrowser->adjustColumnsWidth();
763 myBrowser->setAutoUpdate( true );
764 myBrowser->setUpdateModified( true );
767 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
769 return myCurrentZone;
772 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
774 SUIT_DataObject* aRoot = myBrowser->root();
775 module()->getDataModel()->updateObjectTree( myEditedObject );
776 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
777 myBrowser->updateTree( aRoot );
780 void HYDROGUI_CalculationDlg::onDataChanged()
782 SUIT_DataObject* aRoot = myBrowser->root();
783 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
784 myBrowser->updateTree( aRoot );
787 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
789 myAvailableGroups->clear();
791 foreach( QString aGroup, theGroups )
792 myAvailableGroups->addItem( aGroup );
795 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
797 return getSelected( myGroups );
800 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
802 return getSelected( myAvailableGroups );
805 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
807 moveItems( myAvailableGroups, myGroups, theObjects );
810 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
812 moveItems( myGroups, myAvailableGroups, theObjects );
817 void HYDROGUI_CalculationDlg::setAvailableBoundaryPolygons( const QStringList& theBoundaryPolygons,
818 const QVector<int>& theTypes )
820 myAvailableBoundaryPolygons->clear();
821 myBoundaryPolygons->clear();
822 myISBoundaryPolygons->clear();
824 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
826 foreach( QString aBP, theBoundaryPolygons )
828 int aBT = theTypes[i];
831 iconStr = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE1_ICO").toLatin1());
833 iconStr = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE2_ICO").toLatin1());
835 iconStr = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE3_ICO").toLatin1());
838 QPixmap aPM = aResMgr->loadPixmap( "HYDRO", iconStr );
839 QListWidgetItem* item = new QListWidgetItem(QIcon(aPM), aBP);
840 myAvailableBoundaryPolygons->addItem(item);
844 QStringList HYDROGUI_CalculationDlg::getSelectedBoundaryPolygons() const
846 return getSelected( myBoundaryPolygons );
849 QStringList HYDROGUI_CalculationDlg::getSelectedISBoundaryPolygons() const
851 return getSelected( myISBoundaryPolygons );
854 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableBoundaryPolygons() const
856 return getSelected( myAvailableBoundaryPolygons );
859 void HYDROGUI_CalculationDlg::includeBoundaryPolygons( const QStringList& theObjects )
861 moveItems( myAvailableBoundaryPolygons, myBoundaryPolygons, theObjects );
864 void HYDROGUI_CalculationDlg::includeISBoundaryPolygons( const QStringList& theObjects )
866 moveItems( myAvailableBoundaryPolygons, myISBoundaryPolygons, theObjects );
869 void HYDROGUI_CalculationDlg::excludeBoundaryPolygons( const QStringList& theObjects )
871 moveItems( myBoundaryPolygons, myAvailableBoundaryPolygons, theObjects );
874 void HYDROGUI_CalculationDlg::excludeISBoundaryPolygons( const QStringList& theObjects )
876 moveItems( myISBoundaryPolygons, myAvailableBoundaryPolygons, theObjects );
881 @param theMode the mode
883 int HYDROGUI_CalculationDlg::getMode() const
885 return myModeButtons->checkedId();
890 @param theMode the mode
892 void HYDROGUI_CalculationDlg::setMode( int theMode )
894 bool isBlocked = myModeButtons->blockSignals( true );
895 myModeButtons->button( theMode )->setChecked( true );
896 myModeButtons->blockSignals( isBlocked );
898 bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
900 myGeomObjects->setOrderingEnabled( isAuto );
901 QWidget* aWidget = mySplitter->widget( 1 );
903 aWidget->setVisible( isAuto );
908 Enable/disable zones drag'n'drop and renaming.
909 @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
911 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
913 myBrowser->setReadOnly( !theIsEnabled );
917 Get included geometry objects.
918 @return the list of geometry objects
920 QList<Handle(HYDROData_Entity)> HYDROGUI_CalculationDlg::getGeometryObjects(bool GeomObjOnly)
922 QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
923 QList<Handle(HYDROData_Entity)> anObjects;
925 foreach ( Handle(HYDROData_Entity) anEntity, anEntities )
929 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
930 if ( anObj.IsNull() ) {
936 anObjects << anEntity;
944 @return the list of rules
946 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
948 return myPriorityWidget->getRules();
953 @param theRules the list of rules
955 void HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
957 myPriorityWidget->setRules( theRules );
961 Slot called when objects order is changed.
963 void HYDROGUI_CalculationDlg::onOrderChanged()
965 bool isConfirmed = true;
966 emit orderChanged( isConfirmed );
968 myPriorityWidget->setObjects( getGeometryObjects() );
970 myGeomObjects->undoLastMove();
974 Slot called when priority rule for geometry objects is changed.
976 void HYDROGUI_CalculationDlg::onRuleChanged()
978 bool isConfirmed = true;
979 emit ruleChanged( isConfirmed );
981 myPriorityWidget->undoLastChange();
984 void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals )
987 if ( theBlockSignals )
988 isBlocked = myStricklerTableName->blockSignals( true );
990 myStricklerTableName->setCurrentIndex( myStricklerTableName->findText( theStricklerTableName ) );
992 if ( theBlockSignals )
993 myStricklerTableName->blockSignals( isBlocked );
995 emit StricklerTableSelected( theStricklerTableName );
998 void HYDROGUI_CalculationDlg::setLandCoverMap( const QString& theLandCoverMapName, bool theBlockSignals )
1001 if ( theBlockSignals )
1002 isBlocked = myLandCoverMapName->blockSignals( true );
1004 myLandCoverMapName->setCurrentIndex( myLandCoverMapName->findText( theLandCoverMapName ) );
1006 if ( theBlockSignals )
1007 myLandCoverMapName->blockSignals( isBlocked );
1009 emit landCoverMapSelected( theLandCoverMapName );