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() );
68 connect( button( QWizard::NextButton ), SIGNAL( clicked() ), SIGNAL( splitZones() ) );
69 connect( button( QWizard::BackButton ), SIGNAL( clicked() ), SIGNAL( hideZones() ) );
72 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
76 void HYDROGUI_CalculationDlg::reset()
78 myObjectName->clear();
79 myGeomObjects->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 myGeomObjects = new QListWidget( aPage );
95 myGeomObjects->setSelectionMode( QListWidget::SingleSelection );
96 myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
97 myGeomObjects->setViewMode( QListWidget::ListMode );
98 myGeomObjects->setSortingEnabled( true );
100 connect( myGeomObjects, SIGNAL( currentTextChanged( const QString & ) ),
101 SIGNAL( objectSelected( const QString & ) ) );
103 QFrame* aBtnsFrame = new QFrame( aPage );
104 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
105 aBtnsLayout->setMargin( 5 );
106 aBtnsLayout->setSpacing( 5 );
107 aBtnsFrame->setLayout( aBtnsLayout );
108 QPushButton* anAddBtn = new QPushButton( tr("ADD"), aBtnsFrame );
109 QPushButton* aRemoveBtn = new QPushButton( tr("REMOVE"), aBtnsFrame );
110 aBtnsLayout->addWidget( anAddBtn );
111 aBtnsLayout->addWidget( aRemoveBtn );
112 aBtnsLayout->addStretch( 1 );
114 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
115 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), aPage );
117 QGridLayout* aZonesLayout = new QGridLayout( aPage );
118 aZonesLayout->setMargin( 5 );
119 aZonesLayout->setSpacing( 5 );
120 aZonesLayout->setVerticalSpacing( 10 );
121 aZonesLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
122 aZonesLayout->addWidget( myObjectName, 0, 1 );
123 aZonesLayout->addWidget( anObjectsLabel, 1, 0, Qt::AlignHCenter );
124 aZonesLayout->addWidget( myGeomObjects, 1, 1, 2, 1 );
125 aZonesLayout->addWidget( aBtnsFrame, 2, 0, Qt::AlignHCenter );
127 aPage->setLayout( aZonesLayout );
129 connect( anAddBtn, SIGNAL( clicked() ), this, SIGNAL( addObjects() ) );
130 connect( aRemoveBtn, SIGNAL( clicked() ), this, SIGNAL( removeObjects() ) );
135 void HYDROGUI_CalculationDlg::onEmptyName()
137 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
138 QString aMessage = QObject::tr( "INCORRECT_OBJECT_NAME" );
139 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
142 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
144 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
145 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
146 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
149 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
150 QWizardPage* aPage = new QWizardPage( mainFrame() );
151 QFrame* aFrame = new QFrame( aPage );
153 QGridLayout* aLayout = new QGridLayout( aPage );
155 myBrowser = new HYDROGUI_DataBrowser( module(), 0, aPage );
156 myBrowser->setAutoOpenLevel( 3 );
157 aLayout->setMargin( 5 );
158 aLayout->setSpacing( 5 );
160 aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
162 myBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
163 myBathymetryChoice = new QComboBox( aFrame );
165 myBathymetryChoice->setVisible( false );
166 myBatimetryLabel->setVisible( false );
168 aLayout->addWidget( myBatimetryLabel, 1, 0 );
169 aLayout->addWidget( myBathymetryChoice, 1, 1 );
171 aPage->setLayout( aLayout );
173 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
174 connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
175 connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
177 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
178 SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
183 void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList,
184 SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
186 QList<SUIT_DataObject*> aZonesList;
187 HYDROGUI_Zone* aZone;
188 // Get a list of dropped zones
189 for ( int i = 0; i < theList.length(); i++ )
191 aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
194 aZonesList.append( aZone );
197 if ( aZonesList.length() > 0 )
199 // Get the target region
200 HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
203 // Create a new region
204 emit createRegion( aZonesList );
208 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
211 emit moveZones( theTargetParent, aZonesList );
217 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
219 int aType = myBathymetryChoice->itemData( theIndex ).toInt();
220 QString aText = myBathymetryChoice->itemText( theIndex );
221 emit setMergeType( aType, aText );
224 void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
227 HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
230 doShow = aZone->isMergingNeed();
235 // Fill the merge type combo box
236 bool prevBlock = myBathymetryChoice->blockSignals( true );
237 myCurrentZone = aZone;
238 myBathymetryChoice->clear();
239 myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
240 myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
241 myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
242 QStringList aList = aZone->getBathymetries();
243 for ( int i = 0; i < aList.length(); i++ )
245 myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
247 // Select the current choice if any
249 switch ( aZone->getMergeType() )
251 case HYDROData_Zone::Merge_ZMIN:
254 case HYDROData_Zone::Merge_ZMAX:
257 case HYDROData_Zone::Merge_Object:
258 aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::BathymetryId ) );
261 aCurIndex = 0; // Select unknown by default
263 myBathymetryChoice->setCurrentIndex( aCurIndex );
264 myBathymetryChoice->blockSignals( prevBlock );
267 myBathymetryChoice->setVisible( doShow );
268 myBatimetryLabel->setVisible( doShow );
271 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
273 myObjectName->setText( theName );
276 QString HYDROGUI_CalculationDlg::getObjectName() const
278 return myObjectName->text();
281 void HYDROGUI_CalculationDlg::setGeomObjects( const QStringList& theObjects )
283 myGeomObjects->clear();
285 for ( int i = 0, n = theObjects.length(); i < n; ++i )
287 QString anObjName = theObjects.at( i );
289 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myGeomObjects );
290 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
294 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
296 QStringList aResList;
297 QList<QListWidgetItem*> aList = myGeomObjects->selectedItems();
298 for ( int i = 0, n = aList.length(); i < n; ++i )
300 aResList.append( aList.at( i )->text() );
305 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
307 myEditedObject = theCase;
308 myValidator->setEditedObject( theCase );
310 HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" );
311 myBrowser->setRoot(anobj);
313 module()->getDataModel()->buildCaseTree( anobj, myEditedObject );
314 myBrowser->updateTree();
315 myBrowser->openLevels();
316 myBrowser->adjustColumnsWidth();
319 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
321 return myCurrentZone;
324 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
326 myBrowser->updateTree();