Salome HOME
This commit was generated by cvs2git to create branch 'V4_1_0_maintainance'.
[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
21 using namespace std;
22
23 #include "SelectField.h"
24 #include "MEDMEM_define.hxx"
25
26 #include <qgroupbox.h>
27 #include <qframe.h>
28 #include <qlayout.h>
29 #include <qlistview.h>
30 #include <qslider.h>
31 #include <qlabel.h>
32 #include <qpushbutton.h>
33
34 SelectField::SelectField(FilterGUI* theModule,const QString& file, 
35                          const char* name,
36                          bool modal, WFlags fl)
37   : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
38     myFilterGUI( theModule ),
39     _file(file),
40     _mesh(NULL),
41     _field(NULL),
42     _ts(0),
43     _dimMesh(-1)
44 {
45   QListViewItem *element;
46
47   SCRUTE(_file);
48   _filter = myFilterGUI->InitFilterGen();
49   _filter->loadMED(_file);
50   SALOME_FILTER::StrSeq* meshesNames = _filter->getMeshNames();
51   int numberOfMeshes = (*meshesNames).length();
52
53   SALOME_FILTER::StrSeq* fieldsNames = _filter->getFieldNames();
54   int numberOfFields = (*fieldsNames).length();
55
56   QGridLayout* _lay = new QGridLayout( this, 1, 1 );
57
58   QGroupBox* _GroupC1 = new QGroupBox( this, "GroupC1" );
59   _lay->addWidget( _GroupC1,0,0 );
60
61   MESSAGE(basename((char*)(_file.ascii())));
62   QString qs(tr("FILTER_FILE"));
63   qs.append(basename((char*)(_file.ascii())));
64   _GroupC1->setTitle(qs);
65   _GroupC1->setColumnLayout(0, Qt::Vertical );
66   _GroupC1->layout()->setSpacing( 0 );
67   _GroupC1->layout()->setMargin( 0 );
68   _myGroupLayout = new QGridLayout( _GroupC1->layout() );
69   _myGroupLayout->setAlignment( Qt::AlignTop );
70   _myGroupLayout->setSpacing( 6 );
71   _myGroupLayout->setMargin( 11 );
72   _myGroupLayout->setColStretch( 0, 0 );
73   _myGroupLayout->setColStretch( 1, 1 );
74
75   int row = 0;
76
77   // 0)  label to select field on 3D mesh
78   _myGroupLayout->addWidget( new QLabel(tr("FILTER_SEL_3D"),_GroupC1), row, 0 );
79   row++;
80
81   // 1)  tree to visualize meshes and fields
82   _myList = new QListView( _GroupC1, "List of fields" );
83   _myList->setMinimumSize( 500, 500 );
84   _myList->setMaximumSize( 500, 500 );
85   _myList->setRootIsDecorated(true);
86   _myList->addColumn(tr("FILTER_NAME"));
87   _myList->addColumn(tr("FILTER_TYPE"));
88   _myList->addColumn(tr("FILTER_DIM"));
89
90   for(int i=0;i<numberOfMeshes;i++){
91     _dimMesh = _filter->getMeshDimension((*meshesNames)[i]);
92     char strd[4];
93     sprintf(strd,"%dD\0",_dimMesh);
94     element = new QListViewItem( _myList, QString((*meshesNames)[i]), tr("FILTER_MESH") ,strd);
95     element->setExpandable(true);
96     _myList->setOpen(element,true);
97
98     for (int j=0; j<numberOfFields; j++){
99       SALOME_FILTER::DTITSeq *myIteration = _filter->getFieldIteration((*fieldsNames)[j]);
100       string meshName = _filter->getMeshName((*fieldsNames)[j],(*myIteration)[0].dt,(*myIteration)[0].it);
101       if( strcmp(meshName.c_str(),(*meshesNames)[i]) == 0){
102         int ent = _filter->getFieldEntity((*fieldsNames)[j],(*myIteration)[0].dt,(*myIteration)[0].it);
103         bool isOnAllElements = _filter->fieldIsOnAllElements((*fieldsNames)[j],(*myIteration)[0].dt,(*myIteration)[0].it);
104
105         char stre[10];
106         switch(ent){
107         case MED_EN::MED_CELL:
108           strcpy(stre,"on cells");
109           break;
110         case MED_EN::MED_FACE:
111           strcpy(stre,"on faces");
112           break;
113         case MED_EN::MED_EDGE:
114           strcpy(stre,"on edges");
115           break;
116         case MED_EN::MED_NODE:
117           strcpy(stre,"on nodes");
118           break;
119         }
120         QListViewItem *elem = new QListViewItem( element, QString((*fieldsNames)[j]), tr("FILTER_FIELD"),stre );
121         if( (_dimMesh != 3) || (ent != MED_EN::MED_NODE) || !isOnAllElements )
122           elem->setSelectable(false);
123       }
124     }
125
126     element->setSelectable(false);
127   }
128   _myGroupLayout->addWidget( _myList, row, 0 );
129   row++;
130
131   // 2)  label for time steps
132   _myLab = new QLabel(tr("FILTER_SEL_TS"),_GroupC1);
133   _myLab->hide();
134   _myGroupLayout->addWidget( _myLab, row, 0 );
135   row++;
136
137   // 3)  slider to visualize time steps
138   _mySlider = new QSlider(_GroupC1);
139   _mySlider->setOrientation(Qt::Horizontal);
140   _mySlider->setTickmarks(QSlider::Below);
141   _myGroupLayout->addWidget( _mySlider, row, 0 );
142
143   _mySlider->hide();
144   row++;
145
146   // 4) buttons Ok, Cancel and Help
147   _GroupButtons = new QGroupBox(_GroupC1, "GroupButtons");
148   _GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, _GroupButtons->sizePolicy().hasHeightForWidth()));
149 //   _GroupButtons->setGeometry(QRect(10, 10, 281, 48));
150   _GroupButtons->setTitle(tr("" ));
151   _GroupButtons->setColumnLayout(0, Qt::Vertical);
152   _GroupButtons->layout()->setSpacing(0);
153   _GroupButtons->layout()->setMargin(0);
154   _GroupButtonsLayout = new QGridLayout(_GroupButtons->layout());
155   _GroupButtonsLayout->setAlignment(Qt::AlignTop);
156   _GroupButtonsLayout->setSpacing(6);
157   _GroupButtonsLayout->setMargin(11);
158   _buttonHelp = new QPushButton(_GroupButtons, "buttonHelp");
159   _buttonHelp->setText(tr("FILTER_BUT_HELP" ));
160   _buttonHelp->setAutoDefault(TRUE);
161   _GroupButtonsLayout->addWidget(_buttonHelp, 0, 2);
162   _buttonCancel = new QPushButton(_GroupButtons, "buttonClose");
163   _buttonCancel->setText(tr("FILTER_BUT_CANCEL" ));
164   _buttonCancel->setAutoDefault(TRUE);
165   _GroupButtonsLayout->addWidget(_buttonCancel, 0, 1);
166   _buttonOk = new QPushButton(_GroupButtons, "buttonOk");
167   _buttonOk->setText(tr("FILTER_BUT_OK" ));
168   _buttonOk->setAutoDefault(TRUE);
169   _GroupButtonsLayout->addWidget(_buttonOk, 0, 0);
170   _myGroupLayout->addWidget( _GroupButtons, row, 0 );
171   row++;
172
173   connect( _myList, SIGNAL(clicked(QListViewItem *)), this, SLOT(fieldSelected(QListViewItem *)));
174   connect( _mySlider, SIGNAL(sliderReleased()), this, SLOT(tsSelected()));
175   connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
176   connect(_buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
177   connect(_buttonHelp, SIGNAL(clicked()),   this, SLOT(ClickOnHelp()));
178
179 }
180
181 SelectField::~SelectField()
182 {
183   // no need to delete child widgets, Qt does it all for us
184   cout << "SelectField: destructor called" << endl;
185   _filter->unloadMED();
186 }
187
188 void SelectField::fieldSelected(QListViewItem *lvi)
189 {
190   if(lvi){
191     if( (strcmp(lvi->text(1),"Field") == 0) && (_dimMesh == 3) ){
192       _field = lvi->text(0);
193       _mesh = lvi->parent()->text(0);
194 //       deque<DT_IT_> myIteration = _filterMED->getFieldIteration(lvi->text(0));
195       SALOME_FILTER::DTITSeq *myIteration = _filter->getFieldIteration(lvi->text(0));
196       int numberOfIteration = (*myIteration).length();
197       if( numberOfIteration > 1 ){
198         _mySlider->setRange((*myIteration)[0].dt,
199                             (*myIteration)[numberOfIteration-1].dt);
200         _myLab->show();
201         _mySlider->show();
202       }
203       else{
204         _ts = 0;
205         _myLab->hide();
206         _mySlider->hide();
207       }
208     }
209   }
210 }
211
212 void SelectField::tsSelected()
213 {
214   _ts = _mySlider->value();
215   MESSAGE("File " << _file );
216   MESSAGE("Mesh " << _mesh );
217   MESSAGE("Field " << _field );
218   MESSAGE("Time step " << _ts );
219 }
220
221 void SelectField::ClickOnOk()
222 {
223   MESSAGE("click on Ok");
224   accept();
225 }
226
227 void SelectField::ClickOnCancel()
228 {
229   MESSAGE("click on Cancel");
230   reject();
231 }
232
233 void SelectField::ClickOnHelp()
234 {
235   MESSAGE("click on Help");
236 }