Salome HOME
302efd74631a5126b00fed7cd9b0e699d2695de4
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_CalculationDlg.h"
24
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
33 #include <HYDROData_Document.h>
34 #include <HYDROData_Entity.h>
35 #include <HYDROData_Object.h>
36
37 #include <CAM_Application.h>
38 #include <LightApp_DataObject.h>
39
40 #include <SUIT_FileDlg.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_Study.h>
44
45 #include <LightApp_Application.h>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_MessageBox.h>
48
49 #include <QGroupBox>
50 #include <QLabel>
51 #include <QLayout>
52 #include <QLineEdit>
53 #include <QListWidget>
54 #include <QPicture>
55 #include <QPushButton>
56 #include <QToolButton>
57 #include <QWizardPage>
58 #include <QComboBox>
59
60 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
61 : HYDROGUI_Wizard( theModule, theTitle )
62 {
63   QWizard* aWizard = wizard();
64   aWizard->addPage( createObjectsPage() );
65   aWizard->addPage( createZonesPage() );
66   aWizard->show();
67 }
68
69 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
70 {
71 }
72
73 void HYDROGUI_CalculationDlg::reset()
74 {
75   myObjectName->clear();
76   myGeomObjects->clear();
77 }
78
79 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
80   QWizardPage* aPage = new QWizardPage( wizard() );
81   QFrame* aFrame = new QFrame( aPage );
82   // Calculation name
83 //  myObjectNameGroup = new QGroupBox( tr( "CALCULATION_NAME" ), aFrame );
84
85 //  myObjectName = new QLineEdit( myObjectNameGroup );
86   myObjectName = new QLineEdit( aPage );
87   myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
88   myObjectName->setValidator( myValidator );
89
90   connect( myValidator, SIGNAL( emptyName() ), this, SLOT( onEmptyName() ) );
91   connect( myValidator, SIGNAL( alreadyExists( QString ) ), this, SLOT( onAlreadyExists( QString ) ) );
92
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 );
98
99   // Calculation zones
100   //QFrame* anObjectsFrame = new QFrame( aFrame );
101
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 );
107
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 );
118
119   QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
120   QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), aPage );
121
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 );
131
132   aPage->setLayout( aZonesLayout );
133
134   connect( anAddBtn, SIGNAL( clicked() ), this, SIGNAL( addObjects() ) );
135   connect( aRemoveBtn, SIGNAL( clicked() ), this, SIGNAL( removeObjects() ) );
136
137   return aPage;
138 }
139
140 void HYDROGUI_CalculationDlg::onEmptyName()
141 {
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 );
145 }
146
147 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
148 {
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 );
152 }
153
154 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
155   QWizardPage* aPage = new QWizardPage( wizard() );
156   QFrame* aFrame = new QFrame( aPage );
157
158   QGridLayout* aLayout = new QGridLayout( aPage );
159   //Handle(HYDROData_Entity) anEntity = module()->getDataModel()->getDocument()->CreateObject( KIND_CALCULATION );
160   
161   myBrowser = new HYDROGUI_DataBrowser( module(), 0/*module()->application()->activeStudy()->root()*/, aPage );
162   myBrowser->setAutoOpenLevel( 3 );
163   aLayout->setMargin( 5 );
164   aLayout->setSpacing( 5 );
165
166   aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
167
168   QLabel* aBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
169   myBathymetryChoice = new QComboBox( aFrame );
170   myBathymetryChoice->addItem( tr( "ZMIN" ) );
171   myBathymetryChoice->addItem( tr( "ZMAX" ) );
172
173   aLayout->addWidget( aBatimetryLabel, 1, 0 );
174   aLayout->addWidget( myBathymetryChoice, 1, 1 );
175
176   aPage->setLayout( aLayout );
177
178   return aPage;
179 }
180
181 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
182 {
183   myObjectName->setText( theName );
184 }
185
186 QString HYDROGUI_CalculationDlg::getObjectName() const
187 {
188   return myObjectName->text();
189 }
190
191 void HYDROGUI_CalculationDlg::setGeomObjects( const QStringList& theObjects )
192 {
193 }
194
195 void HYDROGUI_CalculationDlg::setSelectedGeomObjects( const QStringList& theObjects )
196 {
197   myGeomObjects->clear();
198
199   for ( int i = 0, n = theObjects.length(); i < n; ++i )
200   {
201     QString anObjName = theObjects.at( i );
202
203     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myGeomObjects );
204     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
205   }
206 }
207
208 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
209 {
210   QStringList aResList;
211   QList<QListWidgetItem*> aList = myGeomObjects->selectedItems();
212   for ( int i = 0, n = aList.length(); i < n; ++i )
213   {
214     aResList.append( aList.at( i )->text() );
215   }
216   return aResList;
217 }
218
219 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
220 {
221   myEditedObject = theCase;
222   myValidator->setEditedObject( theCase );
223
224   HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" );
225   myBrowser->setRoot(anobj);
226
227   LightApp_DataObject* aCaseItem = module()->getDataModel()->createObject( anobj,
228                                      myEditedObject, "", true );
229   myBrowser->updateTree();
230   myBrowser->openLevels();
231 }