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 #include "HYDRO_trace.hxx"
72 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle, bool IsComplete )
73 : HYDROGUI_Wizard( theModule, theTitle )
75 myIsComplete = IsComplete;
76 myAlreadyAddedGeomObjects = NULL;
77 myPolylineName = NULL;
78 myLandCoverMapName = NULL;
79 myStricklerTableName = NULL;
80 myAvailableGeomObjects = NULL;
81 addPage( createObjectsPage() );
84 addPage( createGroupsPage() );
85 addPage( createBoundaryPolygonsPage() );
86 addPage( createLandCoverMapPage() );
88 addPage( createZonesPage() );
91 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
95 void HYDROGUI_CalculationDlg::reset()
97 myObjectName->clear();
98 HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
99 myGeomObjects->setObjects(anObject2VisibleList);
100 if (myAlreadyAddedGeomObjects)
101 myAlreadyAddedGeomObjects->clear();
103 myPolylineName->clear();
104 if (myLandCoverMapName)
105 myLandCoverMapName->clear();
106 if (myStricklerTableName)
107 myStricklerTableName->clear();
108 if (myAvailableGeomObjects)
109 myAvailableGeomObjects->clear();
111 // Activate the automatic mode
112 setMode( HYDROData_CalculationCase::AUTOMATIC );
114 // Reset the priority widget state
115 QList<Handle(HYDROData_Entity)> anObjects;
116 myPriorityWidget->setObjects( anObjects );
119 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
120 QWizardPage* aPage = new QWizardPage( mainFrame() );
121 QFrame* aFrame = new QFrame( aPage );
124 mySplitter = new QSplitter(Qt::Vertical);
127 QWidget* aTopContainer = new QWidget;
130 myObjectName = new QLineEdit( aPage );
131 myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
132 myObjectName->setValidator( myValidator );
134 connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) );
135 connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) );
138 myPolylineName = new QComboBox( aPage );
139 connect( myPolylineName, SIGNAL( activated( const QString & ) ),
140 SIGNAL( boundarySelected( const QString & ) ) );
143 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
144 QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
146 // mode selector (auto/manual)
147 QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
149 QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
150 QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
152 myModeButtons = new QButtonGroup( mainFrame() );
153 myModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
154 myModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
156 QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
157 aModeSelectorLayout->setMargin( 5 );
158 aModeSelectorLayout->setSpacing( 5 );
159 aModeSelectorLayout->addWidget( anAutoRB );
160 aModeSelectorLayout->addWidget( aManualRB );
161 aModeGroup->setLayout( aModeSelectorLayout );
164 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ) );
165 myGeomObjects = new HYDROGUI_OrderedListWidget( aPage, 16 );
166 myGeomObjects->setHiddenObjectsShown(true);
167 myGeomObjects->setVisibilityIconShown(false);
168 myGeomObjects->setContentsMargins(QMargins());
172 myAlreadyAddedGeomObjects = new QListWidget( aPage );
173 myAlreadyAddedGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
174 myAlreadyAddedGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
175 myAlreadyAddedGeomObjects->setViewMode( QListWidget::ListMode );
179 myAlreadyAddedGeomObjects = NULL;
182 // included geometry objects
183 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ) );
184 myAvailableGeomObjects = new QListWidget( aPage );
185 myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
186 myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
187 myAvailableGeomObjects->setViewMode( QListWidget::ListMode );
188 myAvailableGeomObjects->setSortingEnabled( true );
191 QFrame* aBtnsFrame = new QFrame;
192 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
193 aBtnsLayout->setMargin( 5 );
194 aBtnsLayout->setSpacing( 5 );
195 aBtnsFrame->setLayout( aBtnsLayout );
196 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
197 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
199 // fill the butons frame with two buttons
200 aBtnsLayout->addWidget( anAddBtn );
201 aBtnsLayout->addWidget( aRemoveBtn );
202 aBtnsLayout->addStretch( 1 );
204 // top of the page layout
207 QFrame* anObjectsFrame = new QFrame( aPage );
208 anObjectsFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
209 QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
210 anObjsLayout->setMargin( 5 );
211 anObjsLayout->setSpacing( 5 );
212 anObjectsFrame->setLayout( anObjsLayout );
214 // fill the objects frame with two lists, two labels and with buttons frame
215 anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter );
216 anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
219 QLabel* anAlreadyIncludedLabel = new QLabel( tr( "ALREADY_INCLUDED_OBJECTS" ) );
220 anObjsLayout->addWidget( anAlreadyIncludedLabel, 2, 2, Qt::AlignHCenter );
221 anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0, 3, 1 );
224 anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0 );
226 anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
227 anObjsLayout->addWidget( myGeomObjects, 1, 2 );
230 anObjsLayout->addWidget( myAlreadyAddedGeomObjects, 3, 2 );
233 // fill the top of the page
234 QGridLayout* aTopLayout = new QGridLayout;
235 aTopLayout->setMargin( 5 );
236 aTopLayout->setSpacing( 5 );
237 aTopLayout->setVerticalSpacing( 10 );
238 aTopLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
239 aTopLayout->addWidget( myObjectName, 0, 1 );
240 aTopLayout->addWidget( aLimitsLabel, 1, 0, Qt::AlignHCenter );
241 aTopLayout->addWidget( myPolylineName, 1, 1 );
242 aTopLayout->addWidget( aModeGroup, 2, 0, 1, 2 );
243 aTopLayout->addWidget( anObjectsFrame, 3, 0, 1, 2 );
245 aTopContainer->setLayout( aTopLayout );
247 // add the top of the page to the splitter
248 mySplitter->insertWidget(0, aTopContainer);
249 mySplitter->setStretchFactor(0, 2);
251 // Bottom of the page
252 myPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
254 QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
255 QBoxLayout* aPriorityLayout = new QHBoxLayout;
256 aPriorityLayout->setMargin( 5 );
257 aPriorityLayout->setSpacing( 5 );
258 aPriorityLayout->addWidget( myPriorityWidget );
259 aPriorityGroup->setLayout( aPriorityLayout );
261 // add the bottom of the page to the splitter
262 mySplitter->insertWidget(1, aPriorityGroup);
263 mySplitter->setStretchFactor(1, 1);
266 QVBoxLayout* aPageLayout = new QVBoxLayout;
267 aPageLayout->setMargin( 5 );
268 aPageLayout->setSpacing( 5 );
269 aPageLayout->addWidget( mySplitter );
271 aPage->setLayout( aPageLayout );
275 aLimitsLabel->setEnabled(false);
276 myPolylineName->setEnabled(false);
277 aModeGroup->setEnabled(false);
278 myPriorityWidget->setEnabled(false);
283 HYDROGUI_ListSelector* aListSelector =
284 new HYDROGUI_ListSelector( myGeomObjects, module()->getApp()->selectionMgr() );
285 aListSelector->setAutoBlock( true );
289 connect( myModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeMode( int ) ) );
290 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) );
291 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) );
293 connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) );
295 connect( myPriorityWidget, SIGNAL( ruleChanged() ), SLOT( onRuleChanged() ) );
300 QWizardPage* HYDROGUI_CalculationDlg::createGroupsPage() {
301 QWizardPage* aPage = new QWizardPage( mainFrame() );
302 QFrame* aFrame = new QFrame( aPage );
304 myGroups = new QListWidget( aPage );
305 myGroups->setSelectionMode( QListWidget::ExtendedSelection );
306 myGroups->setEditTriggers( QListWidget::NoEditTriggers );
307 myGroups->setViewMode( QListWidget::ListMode );
308 myGroups->setSortingEnabled( true );
310 myAvailableGroups = new QListWidget( aPage );
311 myAvailableGroups->setSelectionMode( QListWidget::ExtendedSelection );
312 myAvailableGroups->setEditTriggers( QListWidget::NoEditTriggers );
313 myAvailableGroups->setViewMode( QListWidget::ListMode );
314 myAvailableGroups->setSortingEnabled( true );
316 connect( myGroups, SIGNAL( itemSelectionChanged() ),
317 SIGNAL( groupsSelected() ) );
319 QFrame* aGroupsFrame = new QFrame( aPage );
320 QGridLayout* aGroupsLayout = new QGridLayout( aGroupsFrame );
321 aGroupsLayout->setMargin( 5 );
322 aGroupsLayout->setSpacing( 5 );
323 aGroupsFrame->setLayout( aGroupsLayout );
325 QFrame* aBtnsFrame = new QFrame( aGroupsFrame );
326 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
327 aBtnsLayout->setMargin( 5 );
328 aBtnsLayout->setSpacing( 5 );
329 aBtnsFrame->setLayout( aBtnsLayout );
330 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
331 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
333 // Fill the butons frame with two buttons
334 aBtnsLayout->addWidget( anAddBtn );
335 aBtnsLayout->addWidget( aRemoveBtn );
336 aBtnsLayout->addStretch( 1 );
338 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_GROUPS" ), aGroupsFrame );
339 QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_GROUPS" ), aGroupsFrame );
341 // Fill the objects frame with two lists, two labels and with buttons frame
342 aGroupsLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
343 aGroupsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
344 aGroupsLayout->addWidget( myAvailableGroups, 1, 0 );
345 aGroupsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
346 aGroupsLayout->addWidget( myGroups, 1, 2 );
349 QGridLayout* aPageLayout = new QGridLayout( aPage );
350 aPageLayout->setMargin( 5 );
351 aPageLayout->setSpacing( 5 );
352 aPageLayout->setVerticalSpacing( 10 );
353 aPageLayout->addWidget( aGroupsFrame, 0, 0 );
355 aPage->setLayout( aPageLayout );
357 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addGroups() ) );
358 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeGroups() ) );
363 QWizardPage* HYDROGUI_CalculationDlg::createBoundaryPolygonsPage() {
364 QWizardPage* aPage = new QWizardPage( mainFrame() );
365 QFrame* aFrame = new QFrame( aPage );
367 myBoundaryPolygons = new QListWidget( aPage );
368 myBoundaryPolygons->setSelectionMode( QListWidget::ExtendedSelection );
369 myBoundaryPolygons->setEditTriggers( QListWidget::NoEditTriggers );
370 myBoundaryPolygons->setViewMode( QListWidget::ListMode );
371 myBoundaryPolygons->setSortingEnabled( true );
373 myISBoundaryPolygons = new QListWidget( aPage );
374 myISBoundaryPolygons->setSelectionMode( QListWidget::ExtendedSelection );
375 myISBoundaryPolygons->setEditTriggers( QListWidget::NoEditTriggers );
376 myISBoundaryPolygons->setViewMode( QListWidget::ListMode );
377 myISBoundaryPolygons->setSortingEnabled( true );
379 myAvailableBoundaryPolygons = new QListWidget( aPage );
380 myAvailableBoundaryPolygons->setSelectionMode( QListWidget::ExtendedSelection );
381 myAvailableBoundaryPolygons->setEditTriggers( QListWidget::NoEditTriggers );
382 myAvailableBoundaryPolygons->setViewMode( QListWidget::ListMode );
383 myAvailableBoundaryPolygons->setSortingEnabled( true );
385 //connect( myGroups, SIGNAL( itemSelectionChanged() ),
386 // SIGNAL( groupsSelected() ) ); //TODO
388 QFrame* aBPFrame = new QFrame( aPage );
389 QGridLayout* aBPLayout = new QGridLayout( aBPFrame );
390 aBPLayout->setMargin( 5 );
391 aBPLayout->setSpacing( 5 );
392 aBPFrame->setLayout( aBPLayout );
394 QFrame* aBtnsFrame = new QFrame( aBPFrame );
395 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
396 aBtnsLayout->setMargin( 5 );
397 aBtnsLayout->setSpacing( 5 );
398 aBtnsFrame->setLayout( aBtnsLayout );
399 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
400 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
402 // Fill the butons frame with two buttons
403 aBtnsLayout->addWidget( anAddBtn );
404 aBtnsLayout->addWidget( aRemoveBtn );
405 aBtnsLayout->addStretch( 1 );
407 QLabel* anIncludedLabelCut = new QLabel( tr( "INCLUDED_BOUNDARY_POLYGONS_CUT" ), aBPFrame );
409 QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_BOUNDARY_POLYGONS" ), aBPFrame );
411 QLabel* anIncludedLabelIS = new QLabel( tr( "INCLUDED_BOUNDARY_POLYGONS_INCSEL" ) );
413 // Fill the objects frame with two lists, two labels and with buttons frame
414 aBPLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
415 aBPLayout->addWidget( anIncludedLabelCut, 0, 2, Qt::AlignHCenter );
417 aBPLayout->addWidget( myAvailableBoundaryPolygons, 1, 0, 3, 1 );
418 aBPLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
419 aBPLayout->addWidget( myBoundaryPolygons, 1, 2 );
421 aBPLayout->addWidget( anIncludedLabelIS, 2, 2 );
423 aBPLayout->addWidget( myISBoundaryPolygons, 3, 2 );
427 QGridLayout* aPageLayout = new QGridLayout( aPage );
428 aPageLayout->setMargin( 5 );
429 aPageLayout->setSpacing( 5 );
430 aPageLayout->setVerticalSpacing( 10 );
431 aPageLayout->addWidget( aBPFrame, 0, 0 );
433 aPage->setLayout( aPageLayout );
435 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addBoundaryPolygons() ) );
436 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeBoundaryPolygons() ) );
442 QWizardPage* HYDROGUI_CalculationDlg::createLandCoverMapPage() {
443 QWizardPage* aPage = new QWizardPage( mainFrame() );
444 QFrame* aFrame = new QFrame( aPage );
447 QWidget* aTopContainer = new QWidget;
449 // Combo-box to choose land cover map object
450 QLabel* aLandCoverMapLabel = new QLabel( tr( "LAND_COVER_MAP" ), aPage );
451 myLandCoverMapName = new QComboBox( aPage );
452 myLandCoverMapName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
453 connect( myLandCoverMapName, SIGNAL( activated( const QString & ) ),
454 SIGNAL( landCoverMapSelected( const QString & ) ) );
455 // Combo-box to choose Strickler table name
456 QLabel* aStricklerTableLabel = new QLabel( tr( "STRICKLER_TABLE" ), aPage );
457 myStricklerTableName = new QComboBox( aPage );
458 myStricklerTableName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
459 connect( myStricklerTableName, SIGNAL( activated( const QString & ) ),
460 SIGNAL( StricklerTableSelected( const QString & ) ) );
462 // Fill the top layout of the page
463 QGridLayout* aGridLayout = new QGridLayout;
464 aGridLayout->setMargin( 5 );
465 aGridLayout->setSpacing( 5 );
466 aGridLayout->setVerticalSpacing( 10 );
467 aGridLayout->addWidget( aLandCoverMapLabel, 0, 0 );
468 aGridLayout->addWidget( myLandCoverMapName, 0, 1 );
469 aGridLayout->addWidget( aStricklerTableLabel, 1, 0 );
470 aGridLayout->addWidget( myStricklerTableName, 1, 1 );
472 QVBoxLayout* aTopLayout = new QVBoxLayout;
473 aTopLayout->setMargin( 5 );
474 aTopLayout->setSpacing( 5 );
475 aTopLayout->addLayout( aGridLayout );
476 aTopLayout->addStretch( 1 );
478 aTopContainer->setLayout( aTopLayout );
480 aPage->setLayout( aTopLayout );
485 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
486 QWizardPage* aPage = new QWizardPage( mainFrame() );
487 QFrame* aFrame = new QFrame( aPage );
489 QGridLayout* aLayout = new QGridLayout( aPage );
491 QLabel* aResultsOnGeomObjectsLabel = new QLabel( tr( "RESULTS_ON_GEOMETRY_OBJECTS" ), aFrame );
493 myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
494 myBrowser->setAutoOpenLevel( 3 );
495 aLayout->setMargin( 5 );
496 aLayout->setSpacing( 5 );
498 aLayout->addWidget( aResultsOnGeomObjectsLabel, 0, 0 );
499 aLayout->addWidget( myBrowser, 1, 0, 1, 2 );
501 myBathymetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
502 myBathymetryChoice = new QComboBox( aFrame );
504 myBathymetryChoice->setVisible( false );
505 myBathymetryLabel->setVisible( false );
507 aLayout->addWidget( myBathymetryLabel, 2, 0 );
508 aLayout->addWidget( myBathymetryChoice, 2, 1 );
510 QPushButton* aRegenerateBtn = new QPushButton( tr( "REGENERATE_COLORS" ), this );
511 aLayout->addWidget( aRegenerateBtn, 3, 0 );
513 aPage->setLayout( aLayout );
515 connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
516 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
517 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
518 connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
520 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
521 SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
522 connect( myBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewRegion() ) );
523 connect( aRegenerateBtn, SIGNAL( clicked() ), this, SIGNAL( regenerateColors() ) );
527 bool HYDROGUI_CalculationDlg::acceptCurrent() const
531 if ( false /*myGeomObjects->count() == 0*/ )
533 anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
536 if ( !anErrorMsg.isEmpty() )
538 anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
540 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
541 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
544 return anErrorMsg.isEmpty();
547 void HYDROGUI_CalculationDlg::onEmptyName()
549 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
550 QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
551 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
554 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
556 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
557 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
558 "\n" + tr( "INPUT_VALID_DATA" );
559 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
562 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList,
563 SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
565 QList<SUIT_DataObject*> aZonesList;
566 HYDROGUI_Zone* aZone;
567 // Get a list of dropped zones
568 for ( int i = 0; i < theList.length(); i++ )
570 aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
573 aZonesList.append( aZone );
576 if ( aZonesList.length() > 0 )
578 // Get the target region
579 HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
582 // Create a new region
583 emit createRegion( aZonesList );
587 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
590 emit moveZones( theTargetParent, aZonesList );
596 void HYDROGUI_CalculationDlg::OnNewRegion()
598 emit createRegion( myBrowser->getSelected() );
601 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
603 int aType = myBathymetryChoice->itemData( theIndex ).toInt();
604 QString aText = myBathymetryChoice->itemText( theIndex );
605 emit setMergeType( aType, aText );
608 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
610 DEBTRACE("onSelected");
612 HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
615 doShow = aZone->isMergingNeed();
620 // Fill the merge type combo box
621 bool prevBlock = myBathymetryChoice->blockSignals( true );
622 myCurrentZone = aZone;
623 myBathymetryChoice->clear();
624 myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
625 myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
626 myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
627 QStringList aList = aZone->getObjects();
628 for ( int i = 0; i < aList.length(); i++ )
630 myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
632 // Select the current choice if any
634 switch ( aZone->getMergeType() )
636 case HYDROData_Zone::Merge_ZMIN:
639 case HYDROData_Zone::Merge_ZMAX:
642 case HYDROData_Zone::Merge_Object:
643 aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
646 aCurIndex = 0; // Select unknown by default
648 myBathymetryChoice->setCurrentIndex( aCurIndex );
649 myBathymetryChoice->blockSignals( prevBlock );
652 myBathymetryChoice->setVisible( doShow );
653 myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
654 myBathymetryLabel->setVisible( doShow );
657 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
659 myObjectName->setText( theName );
662 QString HYDROGUI_CalculationDlg::getObjectName() const
664 return myObjectName->text();
667 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
669 QList<QListWidgetItem*> aFoundItems;
671 QListWidgetItem* anItem;
673 for ( int i = 0, n = theObjects.length(); i < n; ++i )
675 QString anObjName = theObjects.at( i );
676 aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
677 for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
679 anItem = aFoundItems.at( anIdx );
680 // Remove this object from available objects list
681 anItem = theSource->takeItem( theSource->row( anItem ) );
682 // Add the item to the included objects list
683 theDest->addItem( anItem );
688 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
690 QList<QListWidgetItem*> aFoundItems;
691 foreach ( const QString& anObjName, theObjects ) {
692 // Hide the object in the available objects list
693 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
694 foreach ( QListWidgetItem* anItem, aFoundItems ) {
695 anItem->setHidden( true );
698 // Add the object to the list of included objects
699 Handle(HYDROData_Entity) anObject =
700 HYDROGUI_Tool::FindObjectByName( module(), anObjName );
701 myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
705 myPriorityWidget->setObjects( getGeometryObjects() );
708 void HYDROGUI_CalculationDlg::hideAvailableGeomObjects( const QStringList& theObjects )
710 QList<QListWidgetItem*> aFoundItems;
711 foreach ( const QString& anObjName, theObjects )
713 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
714 foreach ( QListWidgetItem* anItem, aFoundItems )
715 anItem->setHidden( true );
719 void HYDROGUI_CalculationDlg::setAlreadyAddedGeomObjects( const QStringList& theObjects )
721 myAlreadyAddedGeomObjects->addItems(theObjects);
724 QStringList HYDROGUI_CalculationDlg::getAlreadyAddedGeomObjects()
727 for (int i = 0; i < myAlreadyAddedGeomObjects->count(); i++)
728 list << myAlreadyAddedGeomObjects->item(i)->text();
732 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
734 QList<QListWidgetItem*> aFoundItems;
735 foreach ( const QString& anObjName, theObjects ) {
736 // Set visible the object in the available objects list
737 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
738 foreach ( QListWidgetItem* anItem, aFoundItems ) {
739 anItem->setHidden( false );
742 // Remove the object from the list of included objects
743 myGeomObjects->removeObjectByName( anObjName );
746 myPriorityWidget->setObjects( getGeometryObjects() );
749 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
751 bool isBlocked = myPolylineName->blockSignals( true );
752 myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
753 myPolylineName->blockSignals( isBlocked );
756 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
758 myPolylineName->clear();
759 myPolylineName->addItem( "", "" ); // No boundary item
761 for ( int i = 0, n = theObjects.length(); i < n; ++i )
763 myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
767 void HYDROGUI_CalculationDlg::setLandCoverMapsNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
769 myLandCoverMapName->clear();
771 for ( int i = 0, n = theObjects.length(); i < n; ++i )
773 myLandCoverMapName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
777 void HYDROGUI_CalculationDlg::setStricklerTableNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
779 myStricklerTableName->clear();
781 for ( int i = 0, n = theObjects.length(); i < n; ++i )
783 myStricklerTableName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
787 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
789 myAvailableGeomObjects->clear();
791 for ( int i = 0, n = theObjects.length(); i < n; ++i )
793 QString anObjName = theObjects.at( i );
795 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
796 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
797 aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
801 QStringList getSelected( QListWidget* theWidget )
803 QStringList aResList;
804 QList<QListWidgetItem*> aList = theWidget->selectedItems();
805 for ( int i = 0, n = aList.length(); i < n; ++i )
807 aResList.append( aList.at( i )->text() );
812 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
814 return myGeomObjects->getSelectedNames();
817 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
819 return myGeomObjects->getAllNames();
822 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
824 return getSelected( myAvailableGeomObjects );
827 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
829 myEditedObject = theCase;
830 myValidator->setEditedObject( myEditedObject );
832 // Build the calculation case subtree
833 module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject);
835 myBrowser->updateTree();
836 myBrowser->openLevels();
837 myBrowser->adjustColumnsWidth();
838 myBrowser->setAutoUpdate( true );
839 myBrowser->setUpdateModified( true );
842 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
844 return myCurrentZone;
847 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
849 SUIT_DataObject* aRoot = myBrowser->root();
850 module()->getDataModel()->updateObjectTree( myEditedObject );
851 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
852 myBrowser->updateTree( aRoot );
855 void HYDROGUI_CalculationDlg::onDataChanged()
857 SUIT_DataObject* aRoot = myBrowser->root();
858 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
859 myBrowser->updateTree( aRoot );
862 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
864 myAvailableGroups->clear();
866 foreach( QString aGroup, theGroups )
867 myAvailableGroups->addItem( aGroup );
870 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
872 return getSelected( myGroups );
875 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
877 return getSelected( myAvailableGroups );
880 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
882 moveItems( myAvailableGroups, myGroups, theObjects );
885 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
887 moveItems( myGroups, myAvailableGroups, theObjects );
892 void HYDROGUI_CalculationDlg::setAvailableBoundaryPolygons( const QStringList& theBoundaryPolygons,
893 const QVector<int>& theTypes )
895 myAvailableBoundaryPolygons->clear();
896 myBoundaryPolygons->clear();
897 myISBoundaryPolygons->clear();
899 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
901 foreach( QString aBP, theBoundaryPolygons )
903 int aBT = theTypes[i];
906 iconStr = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE1_ICO").toLatin1());
908 iconStr = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE2_ICO").toLatin1());
910 iconStr = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE3_ICO").toLatin1());
913 QPixmap aPM = aResMgr->loadPixmap( "HYDRO", iconStr );
914 QListWidgetItem* item = new QListWidgetItem(QIcon(aPM), aBP);
915 myAvailableBoundaryPolygons->addItem(item);
919 QStringList HYDROGUI_CalculationDlg::getSelectedBoundaryPolygons() const
921 return getSelected( myBoundaryPolygons );
924 QStringList HYDROGUI_CalculationDlg::getSelectedISBoundaryPolygons() const
926 return getSelected( myISBoundaryPolygons );
929 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableBoundaryPolygons() const
931 return getSelected( myAvailableBoundaryPolygons );
934 void HYDROGUI_CalculationDlg::includeBoundaryPolygons( const QStringList& theObjects )
936 moveItems( myAvailableBoundaryPolygons, myBoundaryPolygons, theObjects );
939 void HYDROGUI_CalculationDlg::includeISBoundaryPolygons( const QStringList& theObjects )
941 moveItems( myAvailableBoundaryPolygons, myISBoundaryPolygons, theObjects );
944 void HYDROGUI_CalculationDlg::excludeBoundaryPolygons( const QStringList& theObjects )
946 moveItems( myBoundaryPolygons, myAvailableBoundaryPolygons, theObjects );
949 void HYDROGUI_CalculationDlg::excludeISBoundaryPolygons( const QStringList& theObjects )
951 moveItems( myISBoundaryPolygons, myAvailableBoundaryPolygons, theObjects );
956 @param theMode the mode
958 int HYDROGUI_CalculationDlg::getMode() const
960 return myModeButtons->checkedId();
965 @param theMode the mode
967 void HYDROGUI_CalculationDlg::setMode( int theMode )
969 bool isBlocked = myModeButtons->blockSignals( true );
970 myModeButtons->button( theMode )->setChecked( true );
971 myModeButtons->blockSignals( isBlocked );
973 bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
975 myGeomObjects->setOrderingEnabled( isAuto );
976 QWidget* aWidget = mySplitter->widget( 1 );
978 aWidget->setVisible( isAuto );
982 void HYDROGUI_CalculationDlg::setGeomOrderingEnabled( int enabled )
984 myGeomObjects->setOrderingEnabled( enabled );
988 Enable/disable zones drag'n'drop and renaming.
989 @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
991 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
993 myBrowser->setReadOnly( !theIsEnabled );
997 Get included geometry objects.
998 @return the list of geometry objects
1000 QList<Handle(HYDROData_Entity)> HYDROGUI_CalculationDlg::getGeometryObjects(bool GeomObjOnly)
1002 QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
1003 QList<Handle(HYDROData_Entity)> anObjects;
1005 foreach ( Handle(HYDROData_Entity) anEntity, anEntities )
1009 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
1010 if ( anObj.IsNull() ) {
1016 anObjects << anEntity;
1024 @return the list of rules
1026 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
1028 return myPriorityWidget->getRules();
1033 @param theRules the list of rules
1035 void HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
1037 myPriorityWidget->setRules( theRules );
1041 Slot called when objects order is changed.
1043 void HYDROGUI_CalculationDlg::onOrderChanged()
1045 bool isConfirmed = true;
1046 emit orderChanged( isConfirmed );
1048 myPriorityWidget->setObjects( getGeometryObjects() );
1050 myGeomObjects->undoLastMove();
1054 Slot called when priority rule for geometry objects is changed.
1056 void HYDROGUI_CalculationDlg::onRuleChanged()
1058 bool isConfirmed = true;
1059 emit ruleChanged( isConfirmed );
1061 myPriorityWidget->undoLastChange();
1064 void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals )
1067 if ( theBlockSignals )
1068 isBlocked = myStricklerTableName->blockSignals( true );
1070 myStricklerTableName->setCurrentIndex( myStricklerTableName->findText( theStricklerTableName ) );
1072 if ( theBlockSignals )
1073 myStricklerTableName->blockSignals( isBlocked );
1075 emit StricklerTableSelected( theStricklerTableName );
1078 void HYDROGUI_CalculationDlg::setLandCoverMap( const QString& theLandCoverMapName, bool theBlockSignals )
1081 if ( theBlockSignals )
1082 isBlocked = myLandCoverMapName->blockSignals( true );
1084 myLandCoverMapName->setCurrentIndex( myLandCoverMapName->findText( theLandCoverMapName ) );
1086 if ( theBlockSignals )
1087 myLandCoverMapName->blockSignals( isBlocked );
1089 emit landCoverMapSelected( theLandCoverMapName );