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 <HYDROData_Object.h>
37 #include <CAM_Application.h>
38 #include <LightApp_DataObject.h>
40 #include <SUIT_FileDlg.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_Study.h>
45 #include <LightApp_Application.h>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_MessageBox.h>
53 #include <QListWidget>
55 #include <QPushButton>
56 #include <QToolButton>
57 #include <QWizardPage>
60 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
61 : HYDROGUI_Wizard( theModule, theTitle )
63 QWizard* aWizard = wizard();
64 aWizard->addPage( createObjectsPage() );
65 aWizard->addPage( createZonesPage() );
69 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
73 void HYDROGUI_CalculationDlg::reset()
75 myObjectName->clear();
76 myGeomObjects->clear();
79 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
80 QWizardPage* aPage = new QWizardPage( wizard() );
81 QFrame* aFrame = new QFrame( aPage );
83 // myObjectNameGroup = new QGroupBox( tr( "CALCULATION_NAME" ), aFrame );
85 // myObjectName = new QLineEdit( myObjectNameGroup );
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 //QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
94 //aNameLayout->setMargin( 5 );
95 //aNameLayout->setSpacing( 5 );
96 //aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
97 //aNameLayout->addWidget( myObjectName );
100 //QFrame* anObjectsFrame = new QFrame( aFrame );
102 //myGeomObjects = new QListWidget( anObjectsFrame );
103 myGeomObjects = new QListWidget( aPage );
104 myGeomObjects->setSelectionMode( QListWidget::SingleSelection );
105 myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
106 myGeomObjects->setViewMode( QListWidget::ListMode );
108 QFrame* aBtnsFrame = new QFrame( aPage );
109 QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
110 aBtnsLayout->setMargin( 5 );
111 aBtnsLayout->setSpacing( 5 );
112 aBtnsFrame->setLayout( aBtnsLayout );
113 QPushButton* anAddBtn = new QPushButton( tr("ADD"), aBtnsFrame );
114 QPushButton* aRemoveBtn = new QPushButton( tr("REMOVE"), aBtnsFrame );
115 aBtnsLayout->addWidget( anAddBtn );
116 aBtnsLayout->addWidget( aRemoveBtn );
117 aBtnsLayout->addStretch( 1 );
119 QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
120 QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), aPage );
122 QGridLayout* aZonesLayout = new QGridLayout( aPage );
123 aZonesLayout->setMargin( 5 );
124 aZonesLayout->setSpacing( 5 );
125 aZonesLayout->setVerticalSpacing( 10 );
126 aZonesLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter );
127 aZonesLayout->addWidget( myObjectName, 0, 1 );
128 aZonesLayout->addWidget( anObjectsLabel, 1, 0, Qt::AlignHCenter );
129 aZonesLayout->addWidget( myGeomObjects, 1, 1, 2, 1 );
130 aZonesLayout->addWidget( aBtnsFrame, 2, 0, Qt::AlignHCenter );
132 aPage->setLayout( aZonesLayout );
134 connect( anAddBtn, SIGNAL( clicked() ), this, SIGNAL( addObjects() ) );
135 connect( aRemoveBtn, SIGNAL( clicked() ), this, SIGNAL( removeObjects() ) );
140 void HYDROGUI_CalculationDlg::onEmptyName()
142 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
143 QString aMessage = QObject::tr( "INCORRECT_OBJECT_NAME" );
144 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
147 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
149 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
150 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
151 SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
154 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
155 QWizardPage* aPage = new QWizardPage( wizard() );
156 QFrame* aFrame = new QFrame( aPage );
158 QGridLayout* aLayout = new QGridLayout( aPage );
159 //Handle(HYDROData_Entity) anEntity = module()->getDataModel()->getDocument()->CreateObject( KIND_CALCULATION );
161 myBrowser = new HYDROGUI_DataBrowser( module(), 0/*module()->application()->activeStudy()->root()*/, aPage );
162 myBrowser->setAutoOpenLevel( 3 );
163 aLayout->setMargin( 5 );
164 aLayout->setSpacing( 5 );
166 aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
168 QLabel* aBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
169 myBathymetryChoice = new QComboBox( aFrame );
170 myBathymetryChoice->addItem( tr( "ZMIN" ) );
171 myBathymetryChoice->addItem( tr( "ZMAX" ) );
173 aLayout->addWidget( aBatimetryLabel, 1, 0 );
174 aLayout->addWidget( myBathymetryChoice, 1, 1 );
176 aPage->setLayout( aLayout );
181 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
183 myObjectName->setText( theName );
186 QString HYDROGUI_CalculationDlg::getObjectName() const
188 return myObjectName->text();
191 void HYDROGUI_CalculationDlg::setGeomObjects( const QStringList& theObjects )
195 void HYDROGUI_CalculationDlg::setSelectedGeomObjects( const QStringList& theObjects )
197 myGeomObjects->clear();
199 for ( int i = 0, n = theObjects.length(); i < n; ++i )
201 QString anObjName = theObjects.at( i );
203 QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myGeomObjects );
204 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
208 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
210 QStringList aResList;
211 QList<QListWidgetItem*> aList = myGeomObjects->selectedItems();
212 for ( int i = 0, n = aList.length(); i < n; ++i )
214 aResList.append( aList.at( i )->text() );
219 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
221 myEditedObject = theCase;
222 myValidator->setEditedObject( theCase );
224 HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" );
225 myBrowser->setRoot(anobj);
227 LightApp_DataObject* aCaseItem = module()->getDataModel()->createObject( anobj,
228 myEditedObject, "", true );
229 myBrowser->updateTree();
230 myBrowser->openLevels();