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"
34 #include <HYDROData_Document.h>
35 #include <HYDROData_Entity.h>
37 #include <CAM_Application.h>
38 #include <LightApp_DataObject.h>
40 #include <SUIT_DataObject.h>
41 #include <SUIT_FileDlg.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_Study.h>
46 #include <LightApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
48 #include <SUIT_Desktop.h>
49 #include <SUIT_MessageBox.h>
51 #include <QButtonGroup>
57 #include <QListWidget>
59 #include <QPushButton>
60 #include <QRadioButton>
62 #include <QTableWidget>
63 #include <QToolButton>
65 #include <QWizardPage>
68 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
69 : HYDROGUI_Wizard( theModule, theTitle )
71 addPage( createObjectsPage() );
72 addPage( createGroupsPage() );
73 addPage( createLandCoversPage() );
74 addPage( createZonesPage() );
75 addPage( createLandCoversPartitionPage() );
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 );
93 setLandCoverMode( HYDROData_CalculationCase::AUTOMATIC );
95 // Reset the priority widget state
96 QList<Handle(HYDROData_Object)> anObjects;
97 myPriorityWidget->setObjects( anObjects );
100 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
101 QWizardPage* aPage = new QWizardPage( mainFrame() );
102 QFrame* aFrame = new QFrame( aPage );
105 mySplitter = new QSplitter(Qt::Vertical);
108 QWidget* aTopContainer = new QWidget;
111 myObjectName = new QLineEdit( aPage );
112 myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
113 myObjectName->setValidator( myValidator );
115 connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) );
116 connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) );
119 myPolylineName = new QComboBox( aPage );
120 connect( myPolylineName, SIGNAL( activated( const QString & ) ),
121 SIGNAL( boundarySelected( const QString & ) ) );
124 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
125 QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
127 // mode selector (auto/manual)
128 QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
130 QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
131 QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
133 myModeButtons = new QButtonGroup( mainFrame() );
134 myModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
135 myModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
137 QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
138 aModeSelectorLayout->setMargin( 5 );
139 aModeSelectorLayout->setSpacing( 5 );
140 aModeSelectorLayout->addWidget( anAutoRB );
141 aModeSelectorLayout->addWidget( aManualRB );
142 aModeGroup->setLayout( aModeSelectorLayout );
145 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ) );
146 myGeomObjects = new HYDROGUI_OrderedListWidget( aPage, 16 );
147 myGeomObjects->setHiddenObjectsShown(true);
148 myGeomObjects->setVisibilityIconShown(false);
149 myGeomObjects->setContentsMargins(QMargins());
151 // included geometry objects
152 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ) );
153 myAvailableGeomObjects = new QListWidget( aPage );
154 myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
155 myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
156 myAvailableGeomObjects->setViewMode( QListWidget::ListMode );
157 myAvailableGeomObjects->setSortingEnabled( true );
160 QFrame* aBtnsFrame = new QFrame;
161 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
162 aBtnsLayout->setMargin( 5 );
163 aBtnsLayout->setSpacing( 5 );
164 aBtnsFrame->setLayout( aBtnsLayout );
165 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
166 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
168 // fill the butons frame with two buttons
169 aBtnsLayout->addWidget( anAddBtn );
170 aBtnsLayout->addWidget( aRemoveBtn );
171 aBtnsLayout->addStretch( 1 );
173 // top of the page layout
176 QFrame* anObjectsFrame = new QFrame( aPage );
177 anObjectsFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
178 QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
179 anObjsLayout->setMargin( 5 );
180 anObjsLayout->setSpacing( 5 );
181 anObjectsFrame->setLayout( anObjsLayout );
183 // fill the objects frame with two lists, two labels and with buttons frame
184 anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter );
185 anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
186 anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0 );
187 anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
188 anObjsLayout->addWidget( myGeomObjects, 1, 2 );
190 // fill the top of the page
191 QGridLayout* aTopLayout = new QGridLayout;
192 aTopLayout->setMargin( 5 );
193 aTopLayout->setSpacing( 5 );
194 aTopLayout->setVerticalSpacing( 10 );
195 aTopLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
196 aTopLayout->addWidget( myObjectName, 0, 1 );
197 aTopLayout->addWidget( aLimitsLabel, 1, 0, Qt::AlignHCenter );
198 aTopLayout->addWidget( myPolylineName, 1, 1 );
199 aTopLayout->addWidget( aModeGroup, 2, 0, 1, 2 );
200 aTopLayout->addWidget( anObjectsFrame, 3, 0, 1, 2 );
202 aTopContainer->setLayout( aTopLayout );
204 // add the top of the page to the splitter
205 mySplitter->insertWidget(0, aTopContainer);
206 mySplitter->setStretchFactor(0, 2);
208 // Bottom of the page
209 myPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
211 QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
212 QBoxLayout* aPriorityLayout = new QHBoxLayout;
213 aPriorityLayout->setMargin( 5 );
214 aPriorityLayout->setSpacing( 5 );
215 aPriorityLayout->addWidget( myPriorityWidget );
216 aPriorityGroup->setLayout( aPriorityLayout );
218 // add the bottom of the page to the splitter
219 mySplitter->insertWidget(1, aPriorityGroup);
220 mySplitter->setStretchFactor(1, 1);
223 QVBoxLayout* aPageLayout = new QVBoxLayout;
224 aPageLayout->setMargin( 5 );
225 aPageLayout->setSpacing( 5 );
226 aPageLayout->addWidget( mySplitter );
228 aPage->setLayout( aPageLayout );
232 HYDROGUI_ListSelector* aListSelector =
233 new HYDROGUI_ListSelector( myGeomObjects, module()->getApp()->selectionMgr() );
234 aListSelector->setAutoBlock( true );
238 connect( myModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeMode( int ) ) );
239 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) );
240 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) );
242 connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) );
247 QWizardPage* HYDROGUI_CalculationDlg::createGroupsPage() {
248 QWizardPage* aPage = new QWizardPage( mainFrame() );
249 QFrame* aFrame = new QFrame( aPage );
251 myGroups = new QListWidget( aPage );
252 myGroups->setSelectionMode( QListWidget::ExtendedSelection );
253 myGroups->setEditTriggers( QListWidget::NoEditTriggers );
254 myGroups->setViewMode( QListWidget::ListMode );
255 myGroups->setSortingEnabled( true );
257 myAvailableGroups = new QListWidget( aPage );
258 myAvailableGroups->setSelectionMode( QListWidget::ExtendedSelection );
259 myAvailableGroups->setEditTriggers( QListWidget::NoEditTriggers );
260 myAvailableGroups->setViewMode( QListWidget::ListMode );
261 myAvailableGroups->setSortingEnabled( true );
263 connect( myGroups, SIGNAL( itemSelectionChanged() ),
264 SIGNAL( groupsSelected() ) );
266 QFrame* aGroupsFrame = new QFrame( aPage );
267 QGridLayout* aGroupsLayout = new QGridLayout( aGroupsFrame );
268 aGroupsLayout->setMargin( 5 );
269 aGroupsLayout->setSpacing( 5 );
270 aGroupsFrame->setLayout( aGroupsLayout );
272 QFrame* aBtnsFrame = new QFrame( aGroupsFrame );
273 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
274 aBtnsLayout->setMargin( 5 );
275 aBtnsLayout->setSpacing( 5 );
276 aBtnsFrame->setLayout( aBtnsLayout );
277 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
278 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
280 // Fill the butons frame with two buttons
281 aBtnsLayout->addWidget( anAddBtn );
282 aBtnsLayout->addWidget( aRemoveBtn );
283 aBtnsLayout->addStretch( 1 );
285 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_GROUPS" ), aGroupsFrame );
286 QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_GROUPS" ), aGroupsFrame );
288 // Fill the objects frame with two lists, two labels and with buttons frame
289 aGroupsLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
290 aGroupsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
291 aGroupsLayout->addWidget( myAvailableGroups, 1, 0 );
292 aGroupsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
293 aGroupsLayout->addWidget( myGroups, 1, 2 );
296 QGridLayout* aPageLayout = new QGridLayout( aPage );
297 aPageLayout->setMargin( 5 );
298 aPageLayout->setSpacing( 5 );
299 aPageLayout->setVerticalSpacing( 10 );
300 aPageLayout->addWidget( aGroupsFrame, 0, 0 );
302 aPage->setLayout( aPageLayout );
304 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addGroups() ) );
305 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeGroups() ) );
310 QWizardPage* HYDROGUI_CalculationDlg::createLandCoversPage() {
311 QWizardPage* aPage = new QWizardPage( mainFrame() );
312 QFrame* aFrame = new QFrame( aPage );
315 myLandCoverSplitter = new QSplitter(Qt::Vertical);
318 QWidget* aTopContainer = new QWidget;
320 // Combo-box to choose Strickler table name
321 QLabel* aStricklerTableLabel = new QLabel( tr( "STRICKLER_TABLE" ), aPage );
322 myStricklerTableName = new QComboBox( aPage );
323 myStricklerTableName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
324 connect( myStricklerTableName, SIGNAL( activated( const QString & ) ),
325 SIGNAL( StricklerTableSelected( const QString & ) ) );
327 // mode selector (auto/manual)
328 QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
330 QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
331 QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
333 myLandCoverModeButtons = new QButtonGroup( mainFrame() );
334 myLandCoverModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
335 myLandCoverModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
337 QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
338 aModeSelectorLayout->setMargin( 5 );
339 aModeSelectorLayout->setSpacing( 5 );
340 aModeSelectorLayout->addWidget( anAutoRB );
341 aModeSelectorLayout->addWidget( aManualRB );
342 aModeGroup->setLayout( aModeSelectorLayout );
345 QLabel* aLandCoversLabel = new QLabel( tr( "CALCULATION_REFERENCE_LAND_COVERS" ) );
346 myLandCovers = new HYDROGUI_OrderedListWidget( aPage, 16 );
347 myLandCovers->setHiddenObjectsShown(true);
348 myLandCovers->setVisibilityIconShown(false);
349 myLandCovers->setContentsMargins(QMargins());
351 // included land covers
352 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_LAND_COVERS" ) );
353 myAvailableLandCovers = new QListWidget( aPage );
354 myAvailableLandCovers->setSelectionMode( QListWidget::ExtendedSelection );
355 myAvailableLandCovers->setEditTriggers( QListWidget::NoEditTriggers );
356 myAvailableLandCovers->setViewMode( QListWidget::ListMode );
357 myAvailableLandCovers->setSortingEnabled( true );
360 QFrame* aBtnsFrame = new QFrame;
361 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
362 aBtnsLayout->setMargin( 5 );
363 aBtnsLayout->setSpacing( 5 );
364 aBtnsFrame->setLayout( aBtnsLayout );
365 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
366 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
368 // fill the butons frame with two buttons
369 aBtnsLayout->addWidget( anAddBtn );
370 aBtnsLayout->addWidget( aRemoveBtn );
371 aBtnsLayout->addStretch( 1 );
373 // top of the page layout
376 QFrame* aLandCoversFrame = new QFrame( aPage );
377 aLandCoversFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
378 QGridLayout* aLandCoversLayout = new QGridLayout( aLandCoversFrame );
379 aLandCoversLayout->setMargin( 5 );
380 aLandCoversLayout->setSpacing( 5 );
381 aLandCoversFrame->setLayout( aLandCoversLayout );
383 // fill the land covers frame with two lists, two labels and with buttons frame
384 aLandCoversLayout->addWidget( aLandCoversLabel, 0, 0, Qt::AlignHCenter );
385 aLandCoversLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
386 aLandCoversLayout->addWidget( myAvailableLandCovers, 1, 0 );
387 aLandCoversLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
388 aLandCoversLayout->addWidget( myLandCovers, 1, 2 );
390 // fill the top of the page
391 QGridLayout* aTopLayout = new QGridLayout;
392 aTopLayout->setMargin( 5 );
393 aTopLayout->setSpacing( 5 );
394 aTopLayout->setVerticalSpacing( 10 );
395 aTopLayout->addWidget( aStricklerTableLabel, 0, 0, Qt::AlignHCenter );
396 aTopLayout->addWidget( myStricklerTableName, 0, 1 );
397 aTopLayout->addWidget( aModeGroup, 1, 0, 1, 2 );
398 aTopLayout->addWidget( aLandCoversFrame, 2, 0, 1, 2 );
400 aTopContainer->setLayout( aTopLayout );
402 // add the top of the page to the splitter
403 myLandCoverSplitter->insertWidget(0, aTopContainer);
404 myLandCoverSplitter->setStretchFactor(0, 2);
406 // Bottom of the page
407 myLandCoverPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
409 QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
410 QBoxLayout* aPriorityLayout = new QHBoxLayout;
411 aPriorityLayout->setMargin( 5 );
412 aPriorityLayout->setSpacing( 5 );
413 aPriorityLayout->addWidget( myLandCoverPriorityWidget );
414 aPriorityGroup->setLayout( aPriorityLayout );
416 // add the bottom of the page to the splitter
417 myLandCoverSplitter->insertWidget(1, aPriorityGroup);
418 myLandCoverSplitter->setStretchFactor(1, 1);
421 QVBoxLayout* aPageLayout = new QVBoxLayout;
422 aPageLayout->setMargin( 5 );
423 aPageLayout->setSpacing( 5 );
424 aPageLayout->addWidget( myLandCoverSplitter );
426 aPage->setLayout( aPageLayout );
430 HYDROGUI_ListSelector* aListSelector =
431 new HYDROGUI_ListSelector( myLandCovers, module()->getApp()->selectionMgr() );
432 aListSelector->setAutoBlock( true );
436 connect( myLandCoverModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeLandCoverMode( int ) ) );
437 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addLandCovers() ) );
438 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeLandCovers() ) );
440 connect( myLandCovers, SIGNAL( orderLandCoverChanged() ), SLOT( onOrderLandCoverChanged() ) );
445 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
446 QWizardPage* aPage = new QWizardPage( mainFrame() );
447 QFrame* aFrame = new QFrame( aPage );
449 QGridLayout* aLayout = new QGridLayout( aPage );
451 myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
452 myBrowser->setAutoOpenLevel( 3 );
453 aLayout->setMargin( 5 );
454 aLayout->setSpacing( 5 );
456 aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
458 myBathymetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
459 myBathymetryChoice = new QComboBox( aFrame );
461 myBathymetryChoice->setVisible( false );
462 myBathymetryLabel->setVisible( false );
464 aLayout->addWidget( myBathymetryLabel, 1, 0 );
465 aLayout->addWidget( myBathymetryChoice, 1, 1 );
467 aPage->setLayout( aLayout );
469 connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
470 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
471 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
472 connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
474 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
475 SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
476 connect( myBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewRegion() ) );
481 QWizardPage* HYDROGUI_CalculationDlg::createLandCoversPartitionPage() {
482 QWizardPage* aPage = new QWizardPage( mainFrame() );
483 QFrame* aFrame = new QFrame( aPage );
485 QGridLayout* aLayout = new QGridLayout( aPage );
487 myLandCoverBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
488 myLandCoverBrowser->setAutoOpenLevel( 3 );
489 aLayout->setMargin( 5 );
490 aLayout->setSpacing( 5 );
492 aLayout->addWidget( myLandCoverBrowser, 0, 0, 1, 2 );
494 aPage->setLayout( aLayout );
503 bool HYDROGUI_CalculationDlg::acceptCurrent() const
507 if ( false /*myGeomObjects->count() == 0*/ )
509 anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
512 if ( !anErrorMsg.isEmpty() )
514 anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
516 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
517 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
520 return anErrorMsg.isEmpty();
523 void HYDROGUI_CalculationDlg::onEmptyName()
525 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
526 QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
527 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
530 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
532 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
533 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
534 "\n" + tr( "INPUT_VALID_DATA" );
535 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
538 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList,
539 SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
541 QList<SUIT_DataObject*> aZonesList;
542 HYDROGUI_Zone* aZone;
543 // Get a list of dropped zones
544 for ( int i = 0; i < theList.length(); i++ )
546 aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
549 aZonesList.append( aZone );
552 if ( aZonesList.length() > 0 )
554 // Get the target region
555 HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
558 // Create a new region
559 emit createRegion( aZonesList );
563 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
566 emit moveZones( theTargetParent, aZonesList );
572 void HYDROGUI_CalculationDlg::OnNewRegion()
574 emit createRegion( myBrowser->getSelected() );
577 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
579 int aType = myBathymetryChoice->itemData( theIndex ).toInt();
580 QString aText = myBathymetryChoice->itemText( theIndex );
581 emit setMergeType( aType, aText );
584 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
587 HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
590 doShow = aZone->isMergingNeed();
595 // Fill the merge type combo box
596 bool prevBlock = myBathymetryChoice->blockSignals( true );
597 myCurrentZone = aZone;
598 myBathymetryChoice->clear();
599 myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
600 myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
601 myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
602 QStringList aList = aZone->getAltitudes();
603 for ( int i = 0; i < aList.length(); i++ )
605 myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
607 // Select the current choice if any
609 switch ( aZone->getMergeType() )
611 case HYDROData_Zone::Merge_ZMIN:
614 case HYDROData_Zone::Merge_ZMAX:
617 case HYDROData_Zone::Merge_Object:
618 aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
621 aCurIndex = 0; // Select unknown by default
623 myBathymetryChoice->setCurrentIndex( aCurIndex );
624 myBathymetryChoice->blockSignals( prevBlock );
627 myBathymetryChoice->setVisible( doShow );
628 myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
629 myBathymetryLabel->setVisible( doShow );
632 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
634 myObjectName->setText( theName );
637 QString HYDROGUI_CalculationDlg::getObjectName() const
639 return myObjectName->text();
642 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
644 QList<QListWidgetItem*> aFoundItems;
646 QListWidgetItem* anItem;
648 for ( int i = 0, n = theObjects.length(); i < n; ++i )
650 QString anObjName = theObjects.at( i );
651 aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
652 for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
654 anItem = aFoundItems.at( anIdx );
655 // Remove this object from available objects list
656 anItem = theSource->takeItem( theSource->row( anItem ) );
657 // Add the item to the included objects list
658 theDest->addItem( anItem );
663 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
665 HYDROGUI_ListModel::Object2VisibleList anObjectsToInclude;
666 QList<QListWidgetItem*> aFoundItems;
667 foreach ( const QString& anObjName, theObjects ) {
668 // Hide the object in the available objects list
669 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
670 foreach ( QListWidgetItem* anItem, aFoundItems ) {
671 anItem->setHidden( true );
674 // Add the object to the list of included objects
675 Handle(HYDROData_Entity) anObject =
676 HYDROGUI_Tool::FindObjectByName( module(), anObjName );
677 myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
680 myPriorityWidget->setObjects( getGeometryObjects() );
683 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
685 QList<QListWidgetItem*> aFoundItems;
686 foreach ( const QString& anObjName, theObjects ) {
687 // Set visible the object in the available objects list
688 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
689 foreach ( QListWidgetItem* anItem, aFoundItems ) {
690 anItem->setHidden( false );
693 // Remove the object from the list of included objects
694 myGeomObjects->removeObjectByName( anObjName );
697 myPriorityWidget->setObjects( getGeometryObjects() );
700 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
702 bool isBlocked = myPolylineName->blockSignals( true );
703 myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
704 myPolylineName->blockSignals( isBlocked );
707 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
709 myPolylineName->clear();
710 myPolylineName->addItem( "", "" ); // No boundary item
712 for ( int i = 0, n = theObjects.length(); i < n; ++i )
714 myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
718 void HYDROGUI_CalculationDlg::setStricklerTableNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
720 myStricklerTableName->clear();
722 for ( int i = 0, n = theObjects.length(); i < n; ++i )
724 myStricklerTableName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
728 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
730 myAvailableGeomObjects->clear();
732 for ( int i = 0, n = theObjects.length(); i < n; ++i )
734 QString anObjName = theObjects.at( i );
736 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
737 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
738 aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
742 QStringList getSelected( QListWidget* theWidget )
744 QStringList aResList;
745 QList<QListWidgetItem*> aList = theWidget->selectedItems();
746 for ( int i = 0, n = aList.length(); i < n; ++i )
748 aResList.append( aList.at( i )->text() );
753 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
755 return myGeomObjects->getSelectedNames();
758 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
760 return myGeomObjects->getAllNames();
763 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
765 return getSelected( myAvailableGeomObjects );
768 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
770 myEditedObject = theCase;
771 myValidator->setEditedObject( theCase );
773 // Build the calculation case subtree
774 module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject );
776 myBrowser->updateTree();
777 myBrowser->openLevels();
778 myBrowser->adjustColumnsWidth();
779 myBrowser->setAutoUpdate( true );
780 myBrowser->setUpdateModified( true );
783 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
785 return myCurrentZone;
788 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
790 SUIT_DataObject* aRoot = myBrowser->root();
791 module()->getDataModel()->updateObjectTree( myEditedObject );
792 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
793 myBrowser->updateTree( aRoot );
796 void HYDROGUI_CalculationDlg::onDataChanged()
798 SUIT_DataObject* aRoot = myBrowser->root();
799 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
800 myBrowser->updateTree( aRoot );
803 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
805 myAvailableGroups->clear();
807 foreach( QString aGroup, theGroups )
808 myAvailableGroups->addItem( aGroup );
811 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
813 return getSelected( myGroups );
816 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
818 return getSelected( myAvailableGroups );
821 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
823 moveItems( myAvailableGroups, myGroups, theObjects );
826 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
828 moveItems( myGroups, myAvailableGroups, theObjects );
833 @param theMode the mode
835 int HYDROGUI_CalculationDlg::getMode() const
837 return myModeButtons->checkedId();
842 @param theMode the mode
844 void HYDROGUI_CalculationDlg::setMode( int theMode )
846 bool isBlocked = myModeButtons->blockSignals( true );
847 myModeButtons->button( theMode )->setChecked( true );
848 myModeButtons->blockSignals( isBlocked );
850 bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
852 myGeomObjects->setOrderingEnabled( isAuto );
853 QWidget* aWidget = mySplitter->widget( 1 );
855 aWidget->setVisible( isAuto );
860 Get creation mode for land covers panel.
861 @param theMode the mode
863 int HYDROGUI_CalculationDlg::getLandCoverMode() const
865 return myLandCoverModeButtons->checkedId();
869 Set creation mode for land cover panel.
870 @param theMode the mode
872 void HYDROGUI_CalculationDlg::setLandCoverMode( int theMode )
874 bool isBlocked = myLandCoverModeButtons->blockSignals( true );
875 myLandCoverModeButtons->button( theMode )->setChecked( true );
876 myLandCoverModeButtons->blockSignals( isBlocked );
878 bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
880 myLandCovers->setOrderingEnabled( isAuto );
881 QWidget* aWidget = myLandCoverSplitter->widget( 1 );
883 aWidget->setVisible( isAuto );
888 Enable/disable zones drag'n'drop and renaming.
889 @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
891 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
893 myBrowser->setReadOnly( !theIsEnabled );
897 Enable/disable land covers drag'n'drop and renaming.
898 @param theIsEnabled if true - land covers drag'n'drop and renaming will be enabled
900 void HYDROGUI_CalculationDlg::setEditLandCoversEnabled( const bool theIsEnabled )
902 myLandCoverBrowser->setReadOnly( !theIsEnabled );
906 Get included geometry objects.
907 @return the list of geometry objects
909 QList<Handle(HYDROData_Object)> HYDROGUI_CalculationDlg::getGeometryObjects()
911 QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
912 QList<Handle(HYDROData_Object)> anObjects;
914 foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
915 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
916 if ( anObj.IsNull() ) {
927 Get included land covers.
928 @return the list of land covers
930 QList<Handle(HYDROData_LandCover)> HYDROGUI_CalculationDlg::getLandCovers()
932 QList<Handle(HYDROData_Entity)> anEntities = myLandCovers->getObjects();
933 QList<Handle(HYDROData_LandCover)> aLandCovers;
935 foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
936 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
937 if ( aLandCover.IsNull() ) {
941 aLandCovers << aLandCover;
949 @return the list of rules
951 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
953 return myPriorityWidget->getRules();
958 @param theRules the list of rules
960 void HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
962 myPriorityWidget->setRules( theRules );
966 Slot called when objects order is changed.
968 void HYDROGUI_CalculationDlg::onOrderChanged()
970 bool isConfirmed = true;
971 emit orderChanged( isConfirmed );
973 myPriorityWidget->setObjects( getGeometryObjects() );
975 myGeomObjects->undoLastMove();
978 void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName )
980 bool isBlocked = myStricklerTableName->blockSignals( true );
981 myStricklerTableName->setCurrentIndex( myStricklerTableName->findText( theStricklerTableName ) );
982 myStricklerTableName->blockSignals( isBlocked );
986 Slot called when land covers order is changed.
988 void HYDROGUI_CalculationDlg::onOrderLandCoverChanged()
990 bool isConfirmed = true;
991 emit orderLandCoverChanged( isConfirmed );
993 myLandCoverPriorityWidget->setObjects( getLandCovers() );
995 myLandCovers->undoLastMove();