1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_CalculationDlg.h"
25 #include "HYDROGUI_ObjSelector.h"
26 #include "HYDROGUI_Tool.h"
27 #include "HYDROGUI_DataBrowser.h"
28 #include "HYDROGUI_DataModel.h"
29 #include "HYDROGUI_Module.h"
30 #include "HYDROGUI_DataObject.h"
31 #include "HYDROGUI_NameValidator.h"
32 #include "HYDROGUI_Region.h"
33 #include "HYDROGUI_Zone.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 <SUIT_Desktop.h>
49 #include <SUIT_MessageBox.h>
55 #include <QListWidget>
57 #include <QPushButton>
58 #include <QToolButton>
59 #include <QWizardPage>
61 #include <QStackedWidget>
63 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
64 : HYDROGUI_Wizard( theModule, theTitle )
66 addPage( createObjectsPage() );
67 addPage( createZonesPage() );
70 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
74 void HYDROGUI_CalculationDlg::reset()
76 myObjectName->clear();
77 myGeomObjects->clear();
78 myPolylineName->clear();
79 myAvailableGeomObjects->clear();
82 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
83 QWizardPage* aPage = new QWizardPage( mainFrame() );
84 QFrame* aFrame = new QFrame( aPage );
87 myObjectName = new QLineEdit( aPage );
88 myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
89 myObjectName->setValidator( myValidator );
91 connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) );
92 connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) );
94 myPolylineName = new QComboBox( aPage );
95 connect( myPolylineName, SIGNAL( activated( const QString & ) ),
96 SIGNAL( boundarySelected( const QString & ) ) );
98 myGeomObjects = new QListWidget( aPage );
99 myGeomObjects->setSelectionMode( QListWidget::SingleSelection );
100 myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
101 myGeomObjects->setViewMode( QListWidget::ListMode );
102 myGeomObjects->setSortingEnabled( true );
104 myAvailableGeomObjects = new QListWidget( aPage );
105 myAvailableGeomObjects->setSelectionMode( QListWidget::SingleSelection );
106 myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
107 myAvailableGeomObjects->setViewMode( QListWidget::ListMode );
108 myAvailableGeomObjects->setSortingEnabled( true );
110 connect( myGeomObjects, SIGNAL( currentTextChanged( const QString & ) ),
111 SIGNAL( objectSelected( const QString & ) ) );
113 QFrame* anObjectsFrame = new QFrame( aPage );
114 QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
115 anObjsLayout->setMargin( 5 );
116 anObjsLayout->setSpacing( 5 );
117 anObjectsFrame->setLayout( anObjsLayout );
119 QFrame* aBtnsFrame = new QFrame( anObjectsFrame );
120 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
121 aBtnsLayout->setMargin( 5 );
122 aBtnsLayout->setSpacing( 5 );
123 aBtnsFrame->setLayout( aBtnsLayout );
124 QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
125 QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
127 // Fill the butons frame with two buttons
128 aBtnsLayout->addWidget( anAddBtn );
129 aBtnsLayout->addWidget( aRemoveBtn );
130 aBtnsLayout->addStretch( 1 );
132 QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ), anObjectsFrame );
133 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), anObjectsFrame );
135 // Fill the objects frame with two lists, two labels and with buttons frame
136 anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter );
137 anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
138 anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0, Qt::AlignHCenter );
139 anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
140 anObjsLayout->addWidget( myGeomObjects, 1, 2, Qt::AlignHCenter );
143 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
144 QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
147 QGridLayout* aPageLayout = new QGridLayout( aPage );
148 aPageLayout->setMargin( 5 );
149 aPageLayout->setSpacing( 5 );
150 aPageLayout->setVerticalSpacing( 10 );
151 aPageLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
152 aPageLayout->addWidget( myObjectName, 0, 1 );
153 aPageLayout->addWidget( aLimitsLabel, 1, 0, Qt::AlignHCenter );
154 aPageLayout->addWidget( myPolylineName, 1, 1 );
155 aPageLayout->addWidget( anObjectsFrame, 2, 0, 1, 2, Qt::AlignHCenter );
157 aPage->setLayout( aPageLayout );
159 connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) );
160 connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) );
165 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
166 QWizardPage* aPage = new QWizardPage( mainFrame() );
167 QFrame* aFrame = new QFrame( aPage );
169 QGridLayout* aLayout = new QGridLayout( aPage );
171 myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
172 myBrowser->setAutoOpenLevel( 3 );
173 aLayout->setMargin( 5 );
174 aLayout->setSpacing( 5 );
176 aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
178 myBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
179 myBathymetryChoice = new QComboBox( aFrame );
181 myBathymetryChoice->setVisible( false );
182 myBatimetryLabel->setVisible( false );
184 aLayout->addWidget( myBatimetryLabel, 1, 0 );
185 aLayout->addWidget( myBathymetryChoice, 1, 1 );
187 aPage->setLayout( aLayout );
189 connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
190 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
191 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
192 connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
194 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
195 SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
201 bool HYDROGUI_CalculationDlg::acceptCurrent() const
205 if ( myGeomObjects->count() == 0 )
207 anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
210 if ( !anErrorMsg.isEmpty() )
212 anErrorMsg += "\n" + tr( "INPUT_VALID_DATA" );
214 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
215 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, anErrorMsg );
218 return anErrorMsg.isEmpty();
221 void HYDROGUI_CalculationDlg::onEmptyName()
223 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
224 QString aMessage = tr( "INCORRECT_OBJECT_NAME" ) + "\n" + tr( "INPUT_VALID_DATA" );
225 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
228 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
230 QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" );
231 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ) +
232 "\n" + tr( "INPUT_VALID_DATA" );
233 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
236 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList,
237 SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
239 QList<SUIT_DataObject*> aZonesList;
240 HYDROGUI_Zone* aZone;
241 // Get a list of dropped zones
242 for ( int i = 0; i < theList.length(); i++ )
244 aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
247 aZonesList.append( aZone );
250 if ( aZonesList.length() > 0 )
252 // Get the target region
253 HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
256 // Create a new region
257 emit createRegion( aZonesList );
261 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
264 emit moveZones( theTargetParent, aZonesList );
270 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
272 int aType = myBathymetryChoice->itemData( theIndex ).toInt();
273 QString aText = myBathymetryChoice->itemText( theIndex );
274 emit setMergeType( aType, aText );
277 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
280 HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
283 doShow = aZone->isMergingNeed();
288 // Fill the merge type combo box
289 bool prevBlock = myBathymetryChoice->blockSignals( true );
290 myCurrentZone = aZone;
291 myBathymetryChoice->clear();
292 myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
293 myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
294 myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
295 QStringList aList = aZone->getBathymetries();
296 for ( int i = 0; i < aList.length(); i++ )
298 myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
300 // Select the current choice if any
302 switch ( aZone->getMergeType() )
304 case HYDROData_Zone::Merge_ZMIN:
307 case HYDROData_Zone::Merge_ZMAX:
310 case HYDROData_Zone::Merge_Object:
311 aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::BathymetryId ) );
314 aCurIndex = 0; // Select unknown by default
316 myBathymetryChoice->setCurrentIndex( aCurIndex );
317 myBathymetryChoice->blockSignals( prevBlock );
320 myBathymetryChoice->setVisible( doShow );
321 myBatimetryLabel->setVisible( doShow );
324 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
326 myObjectName->setText( theName );
329 QString HYDROGUI_CalculationDlg::getObjectName() const
331 return myObjectName->text();
334 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
336 QList<QListWidgetItem*> aFoundItems;
338 QListWidgetItem* anItem;
340 for ( int i = 0, n = theObjects.length(); i < n; ++i )
342 QString anObjName = theObjects.at( i );
343 aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
344 for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
346 anItem = aFoundItems.at( anIdx );
347 // Remove this object from available objects list
348 anItem = myAvailableGeomObjects->takeItem( myAvailableGeomObjects->row( anItem ) );
349 // Add the item to the included objects list
350 myGeomObjects->addItem( anItem );
355 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
357 QList<QListWidgetItem*> aFoundItems;
359 QListWidgetItem* anItem;
361 for ( int i = 0, n = theObjects.length(); i < n; ++i )
363 QString anObjName = theObjects.at( i );
364 aFoundItems = myGeomObjects->findItems( anObjName, Qt::MatchExactly );
365 for ( anIdx = 0; anIdx < aFoundItems.length(); anIdx++ )
367 anItem = aFoundItems.at( anIdx );
368 // Remove this object from included objects list
369 anItem = myGeomObjects->takeItem( myGeomObjects->row( anItem ) );
370 // Add the item to the excluded objects list
371 myAvailableGeomObjects->addItem( anItem );
376 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
378 bool isBlocked = myPolylineName->blockSignals( true );
379 myPolylineName->setCurrentIndex( myPolylineName->findText( theObjName ) );
380 myPolylineName->blockSignals( isBlocked );
383 void HYDROGUI_CalculationDlg::setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries )
385 myPolylineName->clear();
386 myPolylineName->addItem( "", "" ); // No boundary item
388 for ( int i = 0, n = theObjects.length(); i < n; ++i )
390 myPolylineName->addItem( theObjects.at( i ), theObjectsEntries.at( i ) );
393 void HYDROGUI_CalculationDlg::setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries )
395 myAvailableGeomObjects->clear();
397 for ( int i = 0, n = theObjects.length(); i < n; ++i )
399 QString anObjName = theObjects.at( i );
401 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myAvailableGeomObjects );
402 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
403 aListItem->setData( Qt::UserRole, theObjectsEntries.at( i ) );
407 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
409 QStringList aResList;
410 QList<QListWidgetItem*> aList = myGeomObjects->selectedItems();
411 for ( int i = 0, n = aList.length(); i < n; ++i )
413 aResList.append( aList.at( i )->text() );
418 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
420 QStringList aResList;
421 QList<QListWidgetItem*> aList = myAvailableGeomObjects->selectedItems();
422 for ( int i = 0, n = aList.length(); i < n; ++i )
424 aResList.append( aList.at( i )->text() );
429 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
431 myEditedObject = theCase;
432 myValidator->setEditedObject( theCase );
434 // Build the calculation case subtree
435 module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject );
437 myBrowser->updateTree();
438 myBrowser->openLevels();
439 myBrowser->adjustColumnsWidth();
440 myBrowser->setAutoUpdate( true );
441 myBrowser->setUpdateModified( true );
445 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
447 return myCurrentZone;
450 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
452 SUIT_DataObject* aRoot = myBrowser->root();
453 module()->getDataModel()->updateObjectTree( myEditedObject );
454 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
455 myBrowser->updateTree( aRoot );
458 void HYDROGUI_CalculationDlg::onDataChanged()
460 SUIT_DataObject* aRoot = myBrowser->root();
461 module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
462 myBrowser->updateTree( aRoot );