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, bool IsComplete )
70 : HYDROGUI_Wizard( theModule, theTitle )
72 myIsComplete = IsComplete;
73 myAlreadyAddedGeomObjects = NULL;
74 myPolylineName = NULL;
75 myLandCoverMapName = NULL;
76 myStricklerTableName = NULL;
77 myAvailableGeomObjects = NULL;
78 addPage( createObjectsPage() );
81 addPage( createGroupsPage() );
82 addPage( createBoundaryPolygonsPage() );
83 addPage( createLandCoverMapPage() );
85 addPage( createZonesPage() );
88 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
92 void HYDROGUI_CalculationDlg::reset()
94 myObjectName->clear();
95 HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
96 myGeomObjects->setObjects(anObject2VisibleList);
97 if (myAlreadyAddedGeomObjects)
98 myAlreadyAddedGeomObjects->clear();
100 myPolylineName->clear();
101 if (myLandCoverMapName)
102 myLandCoverMapName->clear();
103 if (myStricklerTableName)
104 myStricklerTableName->clear();
105 if (myAvailableGeomObjects)
106 myAvailableGeomObjects->clear();
108 // Activate the automatic mode
109 setMode( HYDROData_CalculationCase::AUTOMATIC );
111 // Reset the priority widget state
112 QList<Handle(HYDROData_Entity)> anObjects;
113 myPriorityWidget->setObjects( anObjects );
116 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
117 QWizardPage* aPage = new QWizardPage( mainFrame() );
118 QFrame* aFrame = new QFrame( aPage );
121 mySplitter = new QSplitter(Qt::Vertical);
124 QWidget* aTopContainer = new QWidget;
127 myObjectName = new QLineEdit( aPage );
128 myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
129 myObjectName->setValidator( myValidator );
131 connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) );
132 connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) );
135 myPolylineName = new QComboBox( aPage );
136 connect( myPolylineName, SIGNAL( activated( const QString & ) ),
137 SIGNAL( boundarySelected( const QString & ) ) );
140 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
141 QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
143 // mode selector (auto/manual)
144 QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
146 QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
147 QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
149 myModeButtons = new QButtonGroup( mainFrame() );
150 myModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
151 myModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
153 QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
154 aModeSelectorLayout->setMargin( 5 );
155 aModeSelectorLayout->setSpacing( 5 );
156 aModeSelectorLayout->addWidget( anAutoRB );
157 aModeSelectorLayout->addWidget( aManualRB );
158 aModeGroup->setLayout( aModeSelectorLayout );
161 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ) );
162 myGeomObjects = new HYDROGUI_OrderedListWidget( aPage, 16 );
163 myGeomObjects->setHiddenObjectsShown(true);
164 myGeomObjects->setVisibilityIconShown(false);
165 myGeomObjects->setContentsMargins(QMargins());
169 myAlreadyAddedGeomObjects = new QListWidget( aPage );
170 myAlreadyAddedGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
171 myAlreadyAddedGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
172 myAlreadyAddedGeomObjects->setViewMode( QListWidget::ListMode );
176 myAlreadyAddedGeomObjects = NULL;
179 // included geometry objects
180 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ) );
181 myAvailableGeomObjects = new QListWidget( aPage );
182 myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
183 myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
184 myAvailableGeomObjects->setViewMode( QListWidget::ListMode );
185 myAvailableGeomObjects->setSortingEnabled( true );
188 QFrame* aBtnsFrame = new QFrame;
189 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
190 aBtnsLayout->setMargin( 5 );
191 aBtnsLayout->setSpacing( 5 );
192 aBtnsFrame->setLayout( aBtnsLayout );
193 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
194 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
196 // fill the butons frame with two buttons
197 aBtnsLayout->addWidget( anAddBtn );
198 aBtnsLayout->addWidget( aRemoveBtn );
199 aBtnsLayout->addStretch( 1 );
201 // top of the page layout
204 QFrame* anObjectsFrame = new QFrame( aPage );
205 anObjectsFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
206 QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
207 anObjsLayout->setMargin( 5 );
208 anObjsLayout->setSpacing( 5 );
209 anObjectsFrame->setLayout( anObjsLayout );
211 // fill the objects frame with two lists, two labels and with buttons frame
212 anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter );
213 anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
216 QLabel* anAlreadyIncludedLabel = new QLabel( tr( "ALREADY_INCLUDED_OBJECTS" ) );
217 anObjsLayout->addWidget( anAlreadyIncludedLabel, 2, 2, Qt::AlignHCenter );
218 anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0, 3, 1 );
221 anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0 );
223 anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
224 anObjsLayout->addWidget( myGeomObjects, 1, 2 );
227 anObjsLayout->addWidget( myAlreadyAddedGeomObjects, 3, 2 );
230 // fill the top of the page
231 QGridLayout* aTopLayout = new QGridLayout;
232 aTopLayout->setMargin( 5 );
233 aTopLayout->setSpacing( 5 );
234 aTopLayout->setVerticalSpacing( 10 );
235 aTopLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
236 aTopLayout->addWidget( myObjectName, 0, 1 );
237 aTopLayout->addWidget( aLimitsLabel, 1, 0, Qt::AlignHCenter );
238 aTopLayout->addWidget( myPolylineName, 1, 1 );
239 aTopLayout->addWidget( aModeGroup, 2, 0, 1, 2 );
240 aTopLayout->addWidget( anObjectsFrame, 3, 0, 1, 2 );
242 aTopContainer->setLayout( aTopLayout );
244 // add the top of the page to the splitter
245 mySplitter->insertWidget(0, aTopContainer);
246 mySplitter->setStretchFactor(0, 2);
248 // Bottom of the page
249 myPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
251 QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
252 QBoxLayout* aPriorityLayout = new QHBoxLayout;
253 aPriorityLayout->setMargin( 5 );
254 aPriorityLayout->setSpacing( 5 );
255 aPriorityLayout->addWidget( myPriorityWidget );
256 aPriorityGroup->setLayout( aPriorityLayout );
258 // add the bottom of the page to the splitter
259 mySplitter->insertWidget(1, aPriorityGroup);
260 mySplitter->setStretchFactor(1, 1);
263 QVBoxLayout* aPageLayout = new QVBoxLayout;
264 aPageLayout->setMargin( 5 );
265 aPageLayout->setSpacing( 5 );
266 aPageLayout->addWidget( mySplitter );
268 aPage->setLayout( aPageLayout );
272 aLimitsLabel->setEnabled(false);
273 myPolylineName->setEnabled(false);
274 aModeGroup->setEnabled(false);
275 myPriorityWidget->setEnabled(false);
280 HYDROGUI_ListSelector* aListSelector =
281 new HYDROGUI_ListSelector( myGeomObjects, module()->getApp()->selectionMgr() );
282 aListSelector->setAutoBlock( true );
286 connect( myModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeMode( int ) ) );
287 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) );
288 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) );
290 connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) );
292 connect( myPriorityWidget, SIGNAL( ruleChanged() ), SLOT( onRuleChanged() ) );
297 QWizardPage* HYDROGUI_CalculationDlg::createGroupsPage() {
298 QWizardPage* aPage = new QWizardPage( mainFrame() );
299 QFrame* aFrame = new QFrame( aPage );
301 myGroups = new QListWidget( aPage );
302 myGroups->setSelectionMode( QListWidget::ExtendedSelection );
303 myGroups->setEditTriggers( QListWidget::NoEditTriggers );
304 myGroups->setViewMode( QListWidget::ListMode );
305 myGroups->setSortingEnabled( true );
307 myAvailableGroups = new QListWidget( aPage );
308 myAvailableGroups->setSelectionMode( QListWidget::ExtendedSelection );
309 myAvailableGroups->setEditTriggers( QListWidget::NoEditTriggers );
310 myAvailableGroups->setViewMode( QListWidget::ListMode );
311 myAvailableGroups->setSortingEnabled( true );
313 connect( myGroups, SIGNAL( itemSelectionChanged() ),
314 SIGNAL( groupsSelected() ) );
316 QFrame* aGroupsFrame = new QFrame( aPage );
317 QGridLayout* aGroupsLayout = new QGridLayout( aGroupsFrame );
318 aGroupsLayout->setMargin( 5 );
319 aGroupsLayout->setSpacing( 5 );
320 aGroupsFrame->setLayout( aGroupsLayout );
322 QFrame* aBtnsFrame = new QFrame( aGroupsFrame );
323 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
324 aBtnsLayout->setMargin( 5 );
325 aBtnsLayout->setSpacing( 5 );
326 aBtnsFrame->setLayout( aBtnsLayout );
327 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
328 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
330 // Fill the butons frame with two buttons
331 aBtnsLayout->addWidget( anAddBtn );
332 aBtnsLayout->addWidget( aRemoveBtn );
333 aBtnsLayout->addStretch( 1 );
335 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_GROUPS" ), aGroupsFrame );
336 QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_GROUPS" ), aGroupsFrame );
338 // Fill the objects frame with two lists, two labels and with buttons frame
339 aGroupsLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
340 aGroupsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
341 aGroupsLayout->addWidget( myAvailableGroups, 1, 0 );
342 aGroupsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
343 aGroupsLayout->addWidget( myGroups, 1, 2 );
346 QGridLayout* aPageLayout = new QGridLayout( aPage );
347 aPageLayout->setMargin( 5 );
348 aPageLayout->setSpacing( 5 );
349 aPageLayout->setVerticalSpacing( 10 );
350 aPageLayout->addWidget( aGroupsFrame, 0, 0 );
352 aPage->setLayout( aPageLayout );
354 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addGroups() ) );
355 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeGroups() ) );
360 QWizardPage* HYDROGUI_CalculationDlg::createBoundaryPolygonsPage() {
361 QWizardPage* aPage = new QWizardPage( mainFrame() );
362 QFrame* aFrame = new QFrame( aPage );
364 myBoundaryPolygons = new QListWidget( aPage );
365 myBoundaryPolygons->setSelectionMode( QListWidget::ExtendedSelection );
366 myBoundaryPolygons->setEditTriggers( QListWidget::NoEditTriggers );
367 myBoundaryPolygons->setViewMode( QListWidget::ListMode );
368 myBoundaryPolygons->setSortingEnabled( true );
370 myISBoundaryPolygons = new QListWidget( aPage );
371 myISBoundaryPolygons->setSelectionMode( QListWidget::ExtendedSelection );
372 myISBoundaryPolygons->setEditTriggers( QListWidget::NoEditTriggers );
373 myISBoundaryPolygons->setViewMode( QListWidget::ListMode );
374 myISBoundaryPolygons->setSortingEnabled( true );
376 myAvailableBoundaryPolygons = new QListWidget( aPage );
377 myAvailableBoundaryPolygons->setSelectionMode( QListWidget::ExtendedSelection );
378 myAvailableBoundaryPolygons->setEditTriggers( QListWidget::NoEditTriggers );
379 myAvailableBoundaryPolygons->setViewMode( QListWidget::ListMode );
380 myAvailableBoundaryPolygons->setSortingEnabled( true );
382 //connect( myGroups, SIGNAL( itemSelectionChanged() ),
383 // SIGNAL( groupsSelected() ) ); //TODO
385 QFrame* aBPFrame = new QFrame( aPage );
386 QGridLayout* aBPLayout = new QGridLayout( aBPFrame );
387 aBPLayout->setMargin( 5 );
388 aBPLayout->setSpacing( 5 );
389 aBPFrame->setLayout( aBPLayout );
391 QFrame* aBtnsFrame = new QFrame( aBPFrame );
392 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
393 aBtnsLayout->setMargin( 5 );
394 aBtnsLayout->setSpacing( 5 );
395 aBtnsFrame->setLayout( aBtnsLayout );
396 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
397 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
399 // Fill the butons frame with two buttons
400 aBtnsLayout->addWidget( anAddBtn );
401 aBtnsLayout->addWidget( aRemoveBtn );
402 aBtnsLayout->addStretch( 1 );
404 QLabel* anIncludedLabelCut = new QLabel( tr( "INCLUDED_BOUNDARY_POLYGONS_CUT" ), aBPFrame );
406 QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_BOUNDARY_POLYGONS" ), aBPFrame );
408 QLabel* anIncludedLabelIS = new QLabel( tr( "INCLUDED_BOUNDARY_POLYGONS_INCSEL" ) );
410 // Fill the objects frame with two lists, two labels and with buttons frame
411 aBPLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
412 aBPLayout->addWidget( anIncludedLabelCut, 0, 2, Qt::AlignHCenter );
414 aBPLayout->addWidget( myAvailableBoundaryPolygons, 1, 0, 3, 1 );
415 aBPLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
416 aBPLayout->addWidget( myBoundaryPolygons, 1, 2 );
418 aBPLayout->addWidget( anIncludedLabelIS, 2, 2 );
420 aBPLayout->addWidget( myISBoundaryPolygons, 3, 2 );
424 QGridLayout* aPageLayout = new QGridLayout( aPage );
425 aPageLayout->setMargin( 5 );
426 aPageLayout->setSpacing( 5 );
427 aPageLayout->setVerticalSpacing( 10 );
428 aPageLayout->addWidget( aBPFrame, 0, 0 );
430 aPage->setLayout( aPageLayout );
432 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addBoundaryPolygons() ) );
433 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeBoundaryPolygons() ) );
439 QWizardPage* HYDROGUI_CalculationDlg::createLandCoverMapPage() {
440 QWizardPage* aPage = new QWizardPage( mainFrame() );
441 QFrame* aFrame = new QFrame( aPage );
444 QWidget* aTopContainer = new QWidget;
446 // Combo-box to choose land cover map object
447 QLabel* aLandCoverMapLabel = new QLabel( tr( "LAND_COVER_MAP" ), aPage );
448 myLandCoverMapName = new QComboBox( aPage );
449 myLandCoverMapName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
450 connect( myLandCoverMapName, SIGNAL( activated( const QString & ) ),
451 SIGNAL( landCoverMapSelected( const QString & ) ) );
452 // Combo-box to choose Strickler table name
453 QLabel* aStricklerTableLabel = new QLabel( tr( "STRICKLER_TABLE" ), aPage );
454 myStricklerTableName = new QComboBox( aPage );
455 myStricklerTableName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
456 connect( myStricklerTableName, SIGNAL( activated( const QString & ) ),
457 SIGNAL( StricklerTableSelected( const QString & ) ) );
459 // Fill the top layout of the page
460 QGridLayout* aGridLayout = new QGridLayout;
461 aGridLayout->setMargin( 5 );
462 aGridLayout->setSpacing( 5 );
463 aGridLayout->setVerticalSpacing( 10 );
464 aGridLayout->addWidget( aLandCoverMapLabel, 0, 0 );
465 aGridLayout->addWidget( myLandCoverMapName, 0, 1 );
466 aGridLayout->addWidget( aStricklerTableLabel, 1, 0 );
467 aGridLayout->addWidget( myStricklerTableName, 1, 1 );
469 QVBoxLayout* aTopLayout = new QVBoxLayout;
470 aTopLayout->setMargin( 5 );
471 aTopLayout->setSpacing( 5 );
472 aTopLayout->addLayout( aGridLayout );
473 aTopLayout->addStretch( 1 );
475 aTopContainer->setLayout( aTopLayout );
477 aPage->setLayout( aTopLayout );
482 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
483 QWizardPage* aPage = new QWizardPage( mainFrame() );
484 QFrame* aFrame = new QFrame( aPage );
486 QGridLayout* aLayout = new QGridLayout( aPage );
488 QLabel* aResultsOnGeomObjectsLabel = new QLabel( tr( "RESULTS_ON_GEOMETRY_OBJECTS" ), aFrame );
490 myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
491 myBrowser->setAutoOpenLevel( 3 );
492 aLayout->setMargin( 5 );
493 aLayout->setSpacing( 5 );
495 aLayout->addWidget( aResultsOnGeomObjectsLabel, 0, 0 );
496 aLayout->addWidget( myBrowser, 1, 0, 1, 2 );
498 myBathymetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
499 myBathymetryChoice = new QComboBox( aFrame );
501 myBathymetryChoice->setVisible( false );
502 myBathymetryLabel->setVisible( false );
504 aLayout->addWidget( myBathymetryLabel, 2, 0 );
505 aLayout->addWidget( myBathymetryChoice, 2, 1 );
507 QPushButton* aRegenerateBtn = new QPushButton( tr( "REGENERATE_COLORS" ), this );
508 aLayout->addWidget( aRegenerateBtn, 3, 0 );
510 aPage->setLayout( aLayout );
512 connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
513 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
514 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
515 connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
517 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
518 SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
519 connect( myBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewRegion() ) );
520 connect( aRegenerateBtn, SIGNAL( clicked() ), this, SIGNAL( regenerateColors() ) );
524 bool HYDROGUI_CalculationDlg::acceptCurrent() const
528 if ( false /*myGeomObjects->count() == 0*/ )
530 anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
533 if ( !anErrorMsg.isEmpty() )
535 anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
537 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
538 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
541 return anErrorMsg.isEmpty();
544 void HYDROGUI_CalculationDlg::onEmptyName()
546 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
547 QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
548 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
551 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
553 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
554 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
555 "\n" + tr( "INPUT_VALID_DATA" );
556 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
559 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList,
560 SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
562 QList<SUIT_DataObject*> aZonesList;
563 HYDROGUI_Zone* aZone;
564 // Get a list of dropped zones
565 for ( int i = 0; i < theList.length(); i++ )
567 aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
570 aZonesList.append( aZone );
573 if ( aZonesList.length() > 0 )
575 // Get the target region
576 HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
579 // Create a new region
580 emit createRegion( aZonesList );
584 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
587 emit moveZones( theTargetParent, aZonesList );
593 void HYDROGUI_CalculationDlg::OnNewRegion()
595 emit createRegion( myBrowser->getSelected() );
598 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
600 int aType = myBathymetryChoice->itemData( theIndex ).toInt();
601 QString aText = myBathymetryChoice->itemText( theIndex );
602 emit setMergeType( aType, aText );
605 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
608 HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
611 doShow = aZone->isMergingNeed();
616 // Fill the merge type combo box
617 bool prevBlock = myBathymetryChoice->blockSignals( true );
618 myCurrentZone = aZone;
619 myBathymetryChoice->clear();
620 myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
621 myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
622 myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
623 QStringList aList = aZone->getObjects();
624 for ( int i = 0; i < aList.length(); i++ )
626 myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
628 // Select the current choice if any
630 switch ( aZone->getMergeType() )
632 case HYDROData_Zone::Merge_ZMIN:
635 case HYDROData_Zone::Merge_ZMAX:
638 case HYDROData_Zone::Merge_Object:
639 aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
642 aCurIndex = 0; // Select unknown by default
644 myBathymetryChoice->setCurrentIndex( aCurIndex );
645 myBathymetryChoice->blockSignals( prevBlock );
648 myBathymetryChoice->setVisible( doShow );
649 myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
650 myBathymetryLabel->setVisible( doShow );
653 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
655 myObjectName->setText( theName );
658 QString HYDROGUI_CalculationDlg::getObjectName() const
660 return myObjectName->text();
663 void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& theObjects )
665 QList<QListWidgetItem*> aFoundItems;
667 QListWidgetItem* anItem;
669 for ( int i = 0, n = theObjects.length(); i < n; ++i )
671 QString anObjName = theObjects.at( i );
672 aFoundItems = theSource->findItems( anObjName, Qt::MatchExactly );
673 for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
675 anItem = aFoundItems.at( anIdx );
676 // Remove this object from available objects list
677 anItem = theSource->takeItem( theSource->row( anItem ) );
678 // Add the item to the included objects list
679 theDest->addItem( anItem );
684 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
686 QList<QListWidgetItem*> aFoundItems;
687 foreach ( const QString& anObjName, theObjects ) {
688 // Hide the object in the available objects list
689 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
690 foreach ( QListWidgetItem* anItem, aFoundItems ) {
691 anItem->setHidden( true );
694 // Add the object to the list of included objects
695 Handle(HYDROData_Entity) anObject =
696 HYDROGUI_Tool::FindObjectByName( module(), anObjName );
697 myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
701 myPriorityWidget->setObjects( getGeometryObjects() );
704 void HYDROGUI_CalculationDlg::hideAvailableGeomObjects( const QStringList& theObjects )
706 QList<QListWidgetItem*> aFoundItems;
707 foreach ( const QString& anObjName, theObjects )
709 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
710 foreach ( QListWidgetItem* anItem, aFoundItems )
711 anItem->setHidden( true );
715 void HYDROGUI_CalculationDlg::setAlreadyAddedGeomObjects( const QStringList& theObjects )
717 myAlreadyAddedGeomObjects->addItems(theObjects);
720 QStringList HYDROGUI_CalculationDlg::getAlreadyAddedGeomObjects()
723 for (int i = 0; i < myAlreadyAddedGeomObjects->count(); i++)
724 list << myAlreadyAddedGeomObjects->item(i)->text();
728 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
730 QList<QListWidgetItem*> aFoundItems;
731 foreach ( const QString& anObjName, theObjects ) {
732 // Set visible the object in the available objects list
733 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
734 foreach ( QListWidgetItem* anItem, aFoundItems ) {
735 anItem->setHidden( false );
738 // Remove the object from the list of included objects
739 myGeomObjects->removeObjectByName( anObjName );
742 myPriorityWidget->setObjects( getGeometryObjects() );
745 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
747 bool isBlocked = myPolylineName->blockSignals( true );
748 myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
749 myPolylineName->blockSignals( isBlocked );
752 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
754 myPolylineName->clear();
755 myPolylineName->addItem( "", "" ); // No boundary item
757 for ( int i = 0, n = theObjects.length(); i < n; ++i )
759 myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
763 void HYDROGUI_CalculationDlg::setLandCoverMapsNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
765 myLandCoverMapName->clear();
767 for ( int i = 0, n = theObjects.length(); i < n; ++i )
769 myLandCoverMapName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
773 void HYDROGUI_CalculationDlg::setStricklerTableNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
775 myStricklerTableName->clear();
777 for ( int i = 0, n = theObjects.length(); i < n; ++i )
779 myStricklerTableName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
783 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
785 myAvailableGeomObjects->clear();
787 for ( int i = 0, n = theObjects.length(); i < n; ++i )
789 QString anObjName = theObjects.at( i );
791 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
792 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
793 aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
797 QStringList getSelected( QListWidget* theWidget )
799 QStringList aResList;
800 QList<QListWidgetItem*> aList = theWidget->selectedItems();
801 for ( int i = 0, n = aList.length(); i < n; ++i )
803 aResList.append( aList.at( i )->text() );
808 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
810 return myGeomObjects->getSelectedNames();
813 QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
815 return myGeomObjects->getAllNames();
818 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
820 return getSelected( myAvailableGeomObjects );
823 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
825 myEditedObject = theCase;
826 myValidator->setEditedObject( myEditedObject );
828 // Build the calculation case subtree
829 module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject);
831 myBrowser->updateTree();
832 myBrowser->openLevels();
833 myBrowser->adjustColumnsWidth();
834 myBrowser->setAutoUpdate( true );
835 myBrowser->setUpdateModified( true );
838 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
840 return myCurrentZone;
843 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
845 SUIT_DataObject* aRoot = myBrowser->root();
846 module()->getDataModel()->updateObjectTree( myEditedObject );
847 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
848 myBrowser->updateTree( aRoot );
851 void HYDROGUI_CalculationDlg::onDataChanged()
853 SUIT_DataObject* aRoot = myBrowser->root();
854 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
855 myBrowser->updateTree( aRoot );
858 void HYDROGUI_CalculationDlg::setAvailableGroups( const QStringList& theGroups )
860 myAvailableGroups->clear();
862 foreach( QString aGroup, theGroups )
863 myAvailableGroups->addItem( aGroup );
866 QStringList HYDROGUI_CalculationDlg::getSelectedGroups() const
868 return getSelected( myGroups );
871 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGroups() const
873 return getSelected( myAvailableGroups );
876 void HYDROGUI_CalculationDlg::includeGroups( const QStringList& theObjects )
878 moveItems( myAvailableGroups, myGroups, theObjects );
881 void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
883 moveItems( myGroups, myAvailableGroups, theObjects );
888 void HYDROGUI_CalculationDlg::setAvailableBoundaryPolygons( const QStringList& theBoundaryPolygons,
889 const QVector<int>& theTypes )
891 myAvailableBoundaryPolygons->clear();
892 myBoundaryPolygons->clear();
893 myISBoundaryPolygons->clear();
895 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
897 foreach( QString aBP, theBoundaryPolygons )
899 int aBT = theTypes[i];
902 iconStr = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE1_ICO").toLatin1());
904 iconStr = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE2_ICO").toLatin1());
906 iconStr = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE3_ICO").toLatin1());
909 QPixmap aPM = aResMgr->loadPixmap( "HYDRO", iconStr );
910 QListWidgetItem* item = new QListWidgetItem(QIcon(aPM), aBP);
911 myAvailableBoundaryPolygons->addItem(item);
915 QStringList HYDROGUI_CalculationDlg::getSelectedBoundaryPolygons() const
917 return getSelected( myBoundaryPolygons );
920 QStringList HYDROGUI_CalculationDlg::getSelectedISBoundaryPolygons() const
922 return getSelected( myISBoundaryPolygons );
925 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableBoundaryPolygons() const
927 return getSelected( myAvailableBoundaryPolygons );
930 void HYDROGUI_CalculationDlg::includeBoundaryPolygons( const QStringList& theObjects )
932 moveItems( myAvailableBoundaryPolygons, myBoundaryPolygons, theObjects );
935 void HYDROGUI_CalculationDlg::includeISBoundaryPolygons( const QStringList& theObjects )
937 moveItems( myAvailableBoundaryPolygons, myISBoundaryPolygons, theObjects );
940 void HYDROGUI_CalculationDlg::excludeBoundaryPolygons( const QStringList& theObjects )
942 moveItems( myBoundaryPolygons, myAvailableBoundaryPolygons, theObjects );
945 void HYDROGUI_CalculationDlg::excludeISBoundaryPolygons( const QStringList& theObjects )
947 moveItems( myISBoundaryPolygons, myAvailableBoundaryPolygons, theObjects );
952 @param theMode the mode
954 int HYDROGUI_CalculationDlg::getMode() const
956 return myModeButtons->checkedId();
961 @param theMode the mode
963 void HYDROGUI_CalculationDlg::setMode( int theMode )
965 bool isBlocked = myModeButtons->blockSignals( true );
966 myModeButtons->button( theMode )->setChecked( true );
967 myModeButtons->blockSignals( isBlocked );
969 bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
971 myGeomObjects->setOrderingEnabled( isAuto );
972 QWidget* aWidget = mySplitter->widget( 1 );
974 aWidget->setVisible( isAuto );
978 void HYDROGUI_CalculationDlg::setGeomOrderingEnabled( int enabled )
980 myGeomObjects->setOrderingEnabled( enabled );
984 Enable/disable zones drag'n'drop and renaming.
985 @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
987 void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
989 myBrowser->setReadOnly( !theIsEnabled );
993 Get included geometry objects.
994 @return the list of geometry objects
996 QList<Handle(HYDROData_Entity)> HYDROGUI_CalculationDlg::getGeometryObjects(bool GeomObjOnly)
998 QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
999 QList<Handle(HYDROData_Entity)> anObjects;
1001 foreach ( Handle(HYDROData_Entity) anEntity, anEntities )
1005 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
1006 if ( anObj.IsNull() ) {
1012 anObjects << anEntity;
1020 @return the list of rules
1022 HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
1024 return myPriorityWidget->getRules();
1029 @param theRules the list of rules
1031 void HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
1033 myPriorityWidget->setRules( theRules );
1037 Slot called when objects order is changed.
1039 void HYDROGUI_CalculationDlg::onOrderChanged()
1041 bool isConfirmed = true;
1042 emit orderChanged( isConfirmed );
1044 myPriorityWidget->setObjects( getGeometryObjects() );
1046 myGeomObjects->undoLastMove();
1050 Slot called when priority rule for geometry objects is changed.
1052 void HYDROGUI_CalculationDlg::onRuleChanged()
1054 bool isConfirmed = true;
1055 emit ruleChanged( isConfirmed );
1057 myPriorityWidget->undoLastChange();
1060 void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals )
1063 if ( theBlockSignals )
1064 isBlocked = myStricklerTableName->blockSignals( true );
1066 myStricklerTableName->setCurrentIndex( myStricklerTableName->findText( theStricklerTableName ) );
1068 if ( theBlockSignals )
1069 myStricklerTableName->blockSignals( isBlocked );
1071 emit StricklerTableSelected( theStricklerTableName );
1074 void HYDROGUI_CalculationDlg::setLandCoverMap( const QString& theLandCoverMapName, bool theBlockSignals )
1077 if ( theBlockSignals )
1078 isBlocked = myLandCoverMapName->blockSignals( true );
1080 myLandCoverMapName->setCurrentIndex( myLandCoverMapName->findText( theLandCoverMapName ) );
1082 if ( theBlockSignals )
1083 myLandCoverMapName->blockSignals( isBlocked );
1085 emit landCoverMapSelected( theLandCoverMapName );