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"
33 #include <HYDROData_Document.h>
34 #include <HYDROData_Entity.h>
35 #include <HYDROGUI_Zone.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 <SUIT_Desktop.h>
48 #include <SUIT_MessageBox.h>
54 #include <QListWidget>
56 #include <QPushButton>
57 #include <QToolButton>
58 #include <QWizardPage>
61 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
62 : HYDROGUI_Wizard( theModule, theTitle )
64 QWizard* aWizard = wizard();
65 aWizard->addPage( createObjectsPage() );
66 aWizard->addPage( createZonesPage() );
67 connect( aWizard->button( QWizard::NextButton ), SIGNAL( clicked() ), SIGNAL( splitZones() ) );
71 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
75 void HYDROGUI_CalculationDlg::reset()
77 myObjectName->clear();
78 myGeomObjects->clear();
81 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
82 QWizardPage* aPage = new QWizardPage( wizard() );
83 QFrame* aFrame = new QFrame( aPage );
86 myObjectName = new QLineEdit( aPage );
87 myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
88 myObjectName->setValidator( myValidator );
90 connect( myValidator, SIGNAL( emptyName() ), this, SLOT( onEmptyName() ) );
91 connect( myValidator, SIGNAL( alreadyExists( QString ) ), this, SLOT( onAlreadyExists( QString ) ) );
93 myGeomObjects = new QListWidget( aPage );
94 myGeomObjects->setSelectionMode( QListWidget::SingleSelection );
95 myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
96 myGeomObjects->setViewMode( QListWidget::ListMode );
97 myGeomObjects->setSortingEnabled( true );
99 QFrame* aBtnsFrame = new QFrame( aPage );
100 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
101 aBtnsLayout->setMargin( 5 );
102 aBtnsLayout->setSpacing( 5 );
103 aBtnsFrame->setLayout( aBtnsLayout );
104 QPushButton* anAddBtn = new QPushButton( tr("ADD"), aBtnsFrame );
105 QPushButton* aRemoveBtn = new QPushButton( tr("REMOVE"), aBtnsFrame );
106 aBtnsLayout->addWidget( anAddBtn );
107 aBtnsLayout->addWidget( aRemoveBtn );
108 aBtnsLayout->addStretch( 1 );
110 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
111 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), aPage );
113 QGridLayout* aZonesLayout = new QGridLayout( aPage );
114 aZonesLayout->setMargin( 5 );
115 aZonesLayout->setSpacing( 5 );
116 aZonesLayout->setVerticalSpacing( 10 );
117 aZonesLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
118 aZonesLayout->addWidget( myObjectName, 0, 1 );
119 aZonesLayout->addWidget( anObjectsLabel, 1, 0, Qt::AlignHCenter );
120 aZonesLayout->addWidget( myGeomObjects, 1, 1, 2, 1 );
121 aZonesLayout->addWidget( aBtnsFrame, 2, 0, Qt::AlignHCenter );
123 aPage->setLayout( aZonesLayout );
125 connect( anAddBtn, SIGNAL( clicked() ), this, SIGNAL( addObjects() ) );
126 connect( aRemoveBtn, SIGNAL( clicked() ), this, SIGNAL( removeObjects() ) );
131 void HYDROGUI_CalculationDlg::onEmptyName()
133 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
134 QString aMessage = QObject::tr( "INCORRECT_OBJECT_NAME" );
135 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
138 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
140 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
141 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
142 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
145 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
146 QWizardPage* aPage = new QWizardPage( wizard() );
147 QFrame* aFrame = new QFrame( aPage );
149 QGridLayout* aLayout = new QGridLayout( aPage );
151 myBrowser = new HYDROGUI_DataBrowser( module(), 0, aPage );
152 myBrowser->setAutoOpenLevel( 3 );
153 aLayout->setMargin( 5 );
154 aLayout->setSpacing( 5 );
156 aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
158 myBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
159 myBathymetryChoice = new QComboBox( aFrame );
161 myBathymetryChoice->setVisible( false );
162 myBatimetryLabel->setVisible( false );
164 aLayout->addWidget( myBatimetryLabel, 1, 0 );
165 aLayout->addWidget( myBathymetryChoice, 1, 1 );
167 aPage->setLayout( aLayout );
169 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
170 connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
175 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
177 int aType = myBathymetryChoice->itemData( theIndex ).toInt();
178 QString aText = myBathymetryChoice->itemText( theIndex );
179 emit setMergeType( aType, aText );
182 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
185 HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
188 doShow = aZone->isMergingNeed();
193 // Fill the merge type combo box
194 bool prevBlock = myBathymetryChoice->blockSignals( true );
195 myCurrentZone = aZone;
196 myBathymetryChoice->clear();
197 myBathymetryChoice->addItem( QObject::tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
198 myBathymetryChoice->addItem( QObject::tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
199 myBathymetryChoice->addItem( QObject::tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
200 QStringList aList = aZone->getBathymetries();
201 for ( int i = 0; i < aList.length(); i++ )
203 myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
205 // Select the current choice if any
207 switch ( aZone->getMergeType() )
209 case HYDROData_Zone::Merge_ZMIN:
212 case HYDROData_Zone::Merge_ZMAX:
215 case HYDROData_Zone::Merge_Object:
216 aCurIndex = aList.indexOf( aZone->text( HYDROGUI_DataObject::BathymetryId ) );
219 aCurIndex = 0; // Select unknown by default
221 myBathymetryChoice->setCurrentIndex( aCurIndex );
222 myBathymetryChoice->blockSignals( prevBlock );
225 myBathymetryChoice->setVisible( doShow );
226 myBatimetryLabel->setVisible( doShow );
229 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
231 myObjectName->setText( theName );
234 QString HYDROGUI_CalculationDlg::getObjectName() const
236 return myObjectName->text();
239 void HYDROGUI_CalculationDlg::setGeomObjects( const QStringList& theObjects )
243 void HYDROGUI_CalculationDlg::setSelectedGeomObjects( const QStringList& theObjects )
245 myGeomObjects->clear();
247 for ( int i = 0, n = theObjects.length(); i < n; ++i )
249 QString anObjName = theObjects.at( i );
251 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myGeomObjects );
252 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
256 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
258 QStringList aResList;
259 QList<QListWidgetItem*> aList = myGeomObjects->selectedItems();
260 for ( int i = 0, n = aList.length(); i < n; ++i )
262 aResList.append( aList.at( i )->text() );
267 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
269 myEditedObject = theCase;
270 myValidator->setEditedObject( theCase );
272 HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" );
273 myBrowser->setRoot(anobj);
275 LightApp_DataObject* aCaseItem = module()->getDataModel()->createObject( anobj,
276 myEditedObject, "", true );
277 myBrowser->updateTree();
278 myBrowser->openLevels();
281 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
283 return myCurrentZone;