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