Salome HOME
9d5265ac7cfb704bb8f89ebc708064fb25824a47
[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   connect( aWizard->button( QWizard::NextButton ), SIGNAL( clicked() ), SIGNAL( splitZones() ) );
67   aWizard->show();
68 }
69
70 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
71 {
72 }
73
74 void HYDROGUI_CalculationDlg::reset()
75 {
76   myObjectName->clear();
77   myGeomObjects->clear();
78 }
79
80 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
81   QWizardPage* aPage = new QWizardPage( wizard() );
82   QFrame* aFrame = new QFrame( aPage );
83   // Calculation name
84 //  myObjectNameGroup = new QGroupBox( tr( "CALCULATION_NAME" ), aFrame );
85
86 //  myObjectName = new QLineEdit( myObjectNameGroup );
87   myObjectName = new QLineEdit( aPage );
88   myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
89   myObjectName->setValidator( myValidator );
90
91   connect( myValidator, SIGNAL( emptyName() ), this, SLOT( onEmptyName() ) );
92   connect( myValidator, SIGNAL( alreadyExists( QString ) ), this, SLOT( onAlreadyExists( QString ) ) );
93
94   //QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
95   //aNameLayout->setMargin( 5 );
96   //aNameLayout->setSpacing( 5 );
97   //aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
98   //aNameLayout->addWidget( myObjectName );
99
100   // Calculation zones
101   //QFrame* anObjectsFrame = new QFrame( aFrame );
102
103   //myGeomObjects = new QListWidget( anObjectsFrame );
104   myGeomObjects = new QListWidget( aPage );
105   myGeomObjects->setSelectionMode( QListWidget::SingleSelection );
106   myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
107   myGeomObjects->setViewMode( QListWidget::ListMode );
108   myGeomObjects->setSortingEnabled( true );
109
110   QFrame* aBtnsFrame = new QFrame( aPage );
111   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
112   aBtnsLayout->setMargin( 5 );
113   aBtnsLayout->setSpacing( 5 );
114   aBtnsFrame->setLayout( aBtnsLayout );
115   QPushButton* anAddBtn = new QPushButton( tr("ADD"), aBtnsFrame );
116   QPushButton* aRemoveBtn = new QPushButton( tr("REMOVE"), aBtnsFrame );
117   aBtnsLayout->addWidget( anAddBtn );
118   aBtnsLayout->addWidget( aRemoveBtn );
119   aBtnsLayout->addStretch( 1 );
120
121   QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
122   QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), aPage );
123
124   QGridLayout* aZonesLayout = new QGridLayout( aPage );
125   aZonesLayout->setMargin( 5 );
126   aZonesLayout->setSpacing( 5 );
127   aZonesLayout->setVerticalSpacing( 10 );
128   aZonesLayout->addWidget( aNameLabel,     0, 0, Qt::AlignHCenter );
129   aZonesLayout->addWidget( myObjectName,   0, 1 );
130   aZonesLayout->addWidget( anObjectsLabel, 1, 0, Qt::AlignHCenter );
131   aZonesLayout->addWidget( myGeomObjects,  1, 1, 2, 1 );
132   aZonesLayout->addWidget( aBtnsFrame,     2, 0, Qt::AlignHCenter );
133
134   aPage->setLayout( aZonesLayout );
135
136   connect( anAddBtn, SIGNAL( clicked() ), this, SIGNAL( addObjects() ) );
137   connect( aRemoveBtn, SIGNAL( clicked() ), this, SIGNAL( removeObjects() ) );
138
139   return aPage;
140 }
141
142 void HYDROGUI_CalculationDlg::onEmptyName()
143 {
144   QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
145   QString aMessage = QObject::tr( "INCORRECT_OBJECT_NAME" );
146   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
147 }
148
149 void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName )
150 {
151   QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
152   QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
153   SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage );
154 }
155
156 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
157   QWizardPage* aPage = new QWizardPage( wizard() );
158   QFrame* aFrame = new QFrame( aPage );
159
160   QGridLayout* aLayout = new QGridLayout( aPage );
161   //Handle(HYDROData_Entity) anEntity = module()->getDataModel()->getDocument()->CreateObject( KIND_CALCULATION );
162   
163   myBrowser = new HYDROGUI_DataBrowser( module(), 0/*module()->application()->activeStudy()->root()*/, aPage );
164   myBrowser->setAutoOpenLevel( 3 );
165   aLayout->setMargin( 5 );
166   aLayout->setSpacing( 5 );
167
168   aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
169
170   QLabel* aBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
171   myBathymetryChoice = new QComboBox( aFrame );
172   myBathymetryChoice->addItem( tr( "ZMIN" ) );
173   myBathymetryChoice->addItem( tr( "ZMAX" ) );
174
175   aLayout->addWidget( aBatimetryLabel, 1, 0 );
176   aLayout->addWidget( myBathymetryChoice, 1, 1 );
177
178   aPage->setLayout( aLayout );
179
180   return aPage;
181 }
182
183 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
184 {
185   myObjectName->setText( theName );
186 }
187
188 QString HYDROGUI_CalculationDlg::getObjectName() const
189 {
190   return myObjectName->text();
191 }
192
193 void HYDROGUI_CalculationDlg::setGeomObjects( const QStringList& theObjects )
194 {
195 }
196
197 void HYDROGUI_CalculationDlg::setSelectedGeomObjects( const QStringList& theObjects )
198 {
199   myGeomObjects->clear();
200
201   for ( int i = 0, n = theObjects.length(); i < n; ++i )
202   {
203     QString anObjName = theObjects.at( i );
204
205     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myGeomObjects );
206     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
207   }
208 }
209
210 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
211 {
212   QStringList aResList;
213   QList<QListWidgetItem*> aList = myGeomObjects->selectedItems();
214   for ( int i = 0, n = aList.length(); i < n; ++i )
215   {
216     aResList.append( aList.at( i )->text() );
217   }
218   return aResList;
219 }
220
221 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_CalculationCase) theCase )
222 {
223   myEditedObject = theCase;
224   myValidator->setEditedObject( theCase );
225
226   HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" );
227   myBrowser->setRoot(anobj);
228
229   LightApp_DataObject* aCaseItem = module()->getDataModel()->createObject( anobj,
230                                      myEditedObject, "", true );
231   myBrowser->updateTree();
232   myBrowser->openLevels();
233 }