Salome HOME
- Bathymetry names are shown in the browser in Calculation Case dialog;
[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
32 #include <HYDROData_Document.h>
33 #include <HYDROData_Entity.h>
34 #include <HYDROData_Object.h>
35
36 #include <CAM_Application.h>
37 #include <LightApp_DataObject.h>
38
39 #include <SUIT_FileDlg.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_Study.h>
43
44 #include <QGroupBox>
45 #include <QLabel>
46 #include <QLayout>
47 #include <QLineEdit>
48 #include <QListWidget>
49 #include <QPicture>
50 #include <QPushButton>
51 #include <QToolButton>
52 #include <QWizardPage>
53 #include <QComboBox>
54
55 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
56 : HYDROGUI_Wizard( theModule, theTitle )
57 {
58   QWizard* aWizard = wizard();
59   aWizard->addPage( createObjectsPage() );
60   aWizard->addPage( createZonesPage() );
61   aWizard->show();
62 }
63
64 HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
65 {
66 }
67
68 void HYDROGUI_CalculationDlg::reset()
69 {
70   myObjectName->clear();
71   myGeomObjects->clear();
72 }
73
74 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
75   QWizardPage* aPage = new QWizardPage( wizard() );
76   QFrame* aFrame = new QFrame( aPage );
77   // Calculation name
78 //  myObjectNameGroup = new QGroupBox( tr( "CALCULATION_NAME" ), aFrame );
79
80 //  myObjectName = new QLineEdit( myObjectNameGroup );
81   myObjectName = new QLineEdit( aPage );
82
83   //QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
84   //aNameLayout->setMargin( 5 );
85   //aNameLayout->setSpacing( 5 );
86   //aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
87   //aNameLayout->addWidget( myObjectName );
88
89   // Calculation zones
90   //QFrame* anObjectsFrame = new QFrame( aFrame );
91
92   //myGeomObjects = new QListWidget( anObjectsFrame );
93   myGeomObjects = new QListWidget( aPage );
94   myGeomObjects->setSelectionMode( QListWidget::SingleSelection );
95   myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
96   myGeomObjects->setViewMode( QListWidget::ListMode );
97
98   QFrame* aBtnsFrame = new QFrame( aPage );
99   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
100   aBtnsLayout->setMargin( 5 );
101   aBtnsLayout->setSpacing( 5 );
102   aBtnsFrame->setLayout( aBtnsLayout );
103   QPushButton* anAddBtn = new QPushButton( tr("ADD"), aBtnsFrame );
104   QPushButton* aRemoveBtn = new QPushButton( tr("REMOVE"), aBtnsFrame );
105   aBtnsLayout->addWidget( anAddBtn );
106   aBtnsLayout->addWidget( aRemoveBtn );
107   aBtnsLayout->addStretch( 1 );
108
109   QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
110   QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), aPage );
111
112   QGridLayout* aZonesLayout = new QGridLayout( aPage );
113   aZonesLayout->setMargin( 5 );
114   aZonesLayout->setSpacing( 5 );
115   aZonesLayout->setVerticalSpacing( 10 );
116   aZonesLayout->addWidget( aNameLabel,     0, 0, Qt::AlignHCenter );
117   aZonesLayout->addWidget( myObjectName,   0, 1 );
118   aZonesLayout->addWidget( anObjectsLabel, 1, 0, Qt::AlignHCenter );
119   aZonesLayout->addWidget( myGeomObjects,  1, 1, 2, 1 );
120   aZonesLayout->addWidget( aBtnsFrame,     2, 0, Qt::AlignHCenter );
121
122   //QBoxLayout* aMainLayout = new QVBoxLayout( aFrame );
123   //aMainLayout->setMargin( 0 );
124   //aMainLayout->setSpacing( 5 );
125   //aMainLayout->addWidget( myObjectNameGroup );
126   //aMainLayout->addWidget( anObjectsFrame );
127   //aMainLayout->addStretch();
128
129   //aPage->setLayout( aMainLayout );
130   aPage->setLayout( aZonesLayout );
131
132   return aPage;
133 }
134
135 QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
136   QWizardPage* aPage = new QWizardPage( wizard() );
137   QFrame* aFrame = new QFrame( aPage );
138
139   QGridLayout* aLayout = new QGridLayout( aPage );
140   //Handle(HYDROData_Entity) anEntity = module()->getDataModel()->getDocument()->CreateObject( KIND_CALCULATION );
141   
142   myBrowser = new HYDROGUI_DataBrowser( module(), 0/*module()->application()->activeStudy()->root()*/, aPage );
143   myBrowser->setAutoOpenLevel( 3 );
144   aLayout->setMargin( 5 );
145   aLayout->setSpacing( 5 );
146
147   aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
148
149   QLabel* aBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
150   myBathymetryChoice = new QComboBox( aFrame );
151   myBathymetryChoice->addItem( tr( "ZMIN" ) );
152   myBathymetryChoice->addItem( tr( "ZMAX" ) );
153
154   aLayout->addWidget( aBatimetryLabel, 1, 0 );
155   aLayout->addWidget( myBathymetryChoice, 1, 1 );
156
157   aPage->setLayout( aLayout );
158
159   return aPage;
160 }
161
162 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
163 {
164   myObjectName->setText( theName );
165 }
166
167 QString HYDROGUI_CalculationDlg::getObjectName() const
168 {
169   return myObjectName->text();
170 }
171
172 void HYDROGUI_CalculationDlg::setGeomObjects( const QStringList& theObjects )
173 {
174 }
175
176 void HYDROGUI_CalculationDlg::setSelectedGeomObjects( const QStringList& theObjects )
177 {
178   myGeomObjects->clear();
179
180   for ( int i = 0, n = theObjects.length(); i < n; ++i )
181   {
182     QString anObjName = theObjects.at( i );
183
184     QListWidgetItem* aListItem = new QListWidgetItem( anObjName, myGeomObjects );
185     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
186   }
187 }
188
189 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
190 {
191   QStringList aResList;
192
193   for ( int i = 0, n = myGeomObjects->count(); i < n; ++i )
194   {
195     QListWidgetItem* aListItem = myGeomObjects->item( i );
196     if ( !aListItem )
197       continue;
198
199     QString aSelObjName = aListItem->text();
200     aResList.append( aSelObjName );
201   }
202
203   return aResList;
204 }
205
206 void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_Calculation) theCase )
207 {
208   myEditedObject = theCase;
209
210   HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" );
211   myBrowser->setRoot(anobj);
212
213   LightApp_DataObject* aCaseItem = module()->getDataModel()->createObject( anobj,
214                                      myEditedObject, "", true );
215   
216   myBrowser->updateTree();
217   myBrowser->openLevels();
218 }