Salome HOME
add Close and Help buttons in dialog windows
[modules/filter.git] / src / FILTERGUI / SelectField.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
8 //
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include "SelectField.h"
21
22 #include <qgroupbox.h>
23 #include <qframe.h>
24 #include <qlayout.h>
25 #include <qlistview.h>
26 #include <qslider.h>
27 #include <qlabel.h>
28 #include <qpushbutton.h>
29
30 SelectField::SelectField(FilterGUI* theModule,const QString& file, 
31                          const char* name,
32                          bool modal, WFlags fl)
33   : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
34     myFilterGUI( theModule ),
35     _file(file),
36     _mesh(0),
37     _field(0),
38     _ts(0)
39 {
40   QListViewItem *element;
41
42   SCRUTE(_file);
43   _med = new ::MED(MED_DRIVER,_file);
44   deque<string> meshesNames = _med->getMeshNames();
45   int numberOfMeshes = meshesNames.size();
46   
47   deque<string> fieldsNames = _med->getFieldNames();
48   int numberOfFields = fieldsNames.size();
49
50   QGridLayout* _lay = new QGridLayout( this, 1, 1 );
51
52   QGroupBox* _GroupC1 = new QGroupBox( this, "GroupC1" );
53   _lay->addWidget( _GroupC1,0,0 );
54
55   MESSAGE(basename(_file));
56   QString qs(tr("FILTER_FILE"));
57   qs.append(basename(_file));
58   _GroupC1->setTitle(qs);
59   _GroupC1->setColumnLayout(0, Qt::Vertical );
60   _GroupC1->layout()->setSpacing( 0 );
61   _GroupC1->layout()->setMargin( 0 );
62   _myGroupLayout = new QGridLayout( _GroupC1->layout() );
63   _myGroupLayout->setAlignment( Qt::AlignTop );
64   _myGroupLayout->setSpacing( 6 );
65   _myGroupLayout->setMargin( 11 );
66   _myGroupLayout->setColStretch( 0, 0 );
67   _myGroupLayout->setColStretch( 1, 1 );
68
69   int row = 0;
70
71   // 0)  tree to visualize meshes and fields
72   _myList = new QListView( _GroupC1, "List of fields" );
73   _myList->setMinimumSize( 400, 400 );
74   _myList->setMaximumSize( 400, 400 );
75   _myList->setRootIsDecorated(true);
76   _myList->addColumn(tr("FILTER_NAME"));
77   _myList->addColumn(tr("FILTER_TYPE"));
78
79   for(int i=0;i<numberOfMeshes;i++){
80     element = new QListViewItem( _myList, meshesNames[i], tr("FILTER_MESH") );
81     element->setExpandable(true);
82     _myList->setOpen(element,true);
83
84     for (int j=0; j<numberOfFields; j++){
85       deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[j]);
86       string meshName = _med->getField(fieldsNames[j],myIteration[0].dt,myIteration[0].it)->getSupport()->getMesh()->getName();
87       if( strcmp(meshName.c_str(),meshesNames[i].c_str()) == 0)
88         new QListViewItem( element, fieldsNames[j], tr("FILTER_FIELD") );
89     }
90
91     element->setSelectable(false);
92   }
93   _myGroupLayout->addWidget( _myList, row, 0 );
94   row++;
95
96   // 1)  label for time steps
97   _myLab = new QLabel(tr("FILTER_SEL_TS"),_GroupC1);
98   _myLab->hide();
99   _myGroupLayout->addWidget( _myLab, row, 0 );
100   row++;
101
102   // 2)  slider to visualize time steps
103   _mySlider = new QSlider(_GroupC1);
104   _mySlider->setOrientation(Qt::Horizontal);
105   _mySlider->setTickmarks(QSlider::Below);
106   _myGroupLayout->addWidget( _mySlider, row, 0 );
107
108   _mySlider->hide();
109   row++;
110
111   // 3) buttons Close and Help
112   _GroupButtons = new QGroupBox(_GroupC1, "GroupButtons");
113   _GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, _GroupButtons->sizePolicy().hasHeightForWidth()));
114 //   _GroupButtons->setGeometry(QRect(10, 10, 281, 48));
115   _GroupButtons->setTitle(tr("" ));
116   _GroupButtons->setColumnLayout(0, Qt::Vertical);
117   _GroupButtons->layout()->setSpacing(0);
118   _GroupButtons->layout()->setMargin(0);
119   _GroupButtonsLayout = new QGridLayout(_GroupButtons->layout());
120   _GroupButtonsLayout->setAlignment(Qt::AlignTop);
121   _GroupButtonsLayout->setSpacing(6);
122   _GroupButtonsLayout->setMargin(11);
123   _buttonHelp = new QPushButton(_GroupButtons, "buttonHelp");
124   _buttonHelp->setText(tr("FILTER_BUT_HELP" ));
125   _buttonHelp->setAutoDefault(TRUE);
126   _GroupButtonsLayout->addWidget(_buttonHelp, 0, 1);
127   _buttonClose = new QPushButton(_GroupButtons, "buttonClose");
128   _buttonClose->setText(tr("FILTER_BUT_CLOSE" ));
129   _buttonClose->setAutoDefault(TRUE);
130   _GroupButtonsLayout->addWidget(_buttonClose, 0, 0);
131   _myGroupLayout->addWidget( _GroupButtons, row, 0 );
132   row++;
133
134   connect( _myList, SIGNAL(clicked(QListViewItem *)), this, SLOT(fieldSelected(QListViewItem *)));
135   connect( _mySlider, SIGNAL(sliderReleased()), this, SLOT(tsSelected()));
136   connect(_buttonClose, SIGNAL(clicked()), this, SLOT(ClickOnClose()));
137   connect(_buttonHelp, SIGNAL(clicked()),   this, SLOT(ClickOnHelp()));
138
139   this->show(); /* displays Dialog */
140 }
141
142 SelectField::~SelectField()
143 {
144   // no need to delete child widgets, Qt does it all for us
145   cout << "SelectField: destructor called" << endl;
146   delete _med;
147 }
148
149 void SelectField::fieldSelected(QListViewItem *lvi)
150 {
151   if(lvi){
152     if( strcmp(lvi->text(1),"Field") == 0){
153       _field = lvi->text(0);
154       _mesh = lvi->parent()->text(0);
155       deque<DT_IT_> myIteration = _med->getFieldIteration (lvi->text(0));
156       int numberOfIteration = myIteration.size();
157       if( numberOfIteration > 1 ){
158         _mySlider->setRange(myIteration[0].dt,
159                             myIteration[numberOfIteration-1].dt);
160         _myLab->show();
161         _mySlider->show();
162       }
163       else{
164         _ts = 0;
165         _myLab->hide();
166         _mySlider->hide();
167       }
168     }
169   }
170 }
171
172 void SelectField::tsSelected()
173 {
174   _ts = _mySlider->value();
175   MESSAGE("File " << _file );
176   MESSAGE("Mesh " << _mesh );
177   MESSAGE("Field " << _field );
178   MESSAGE("Time step " << _ts );
179 }
180
181 void SelectField::ClickOnClose()
182 {
183   MESSAGE("click on Cancel");
184   reject();
185 }
186
187 void SelectField::ClickOnHelp()
188 {
189   MESSAGE("click on Help");
190 }