Salome HOME
b507a61a2dbea5815b431bf7d9340f8f5fec7772
[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
29 SelectField::SelectField(FilterGUI* theModule,const QString& file, 
30                          const char* name,
31                          bool modal, WFlags fl)
32   : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
33     myFilterGUI( theModule ),
34     _file(file),
35     _mesh(0),
36     _field(0),
37     _ts(0),
38     _myList( 0 ),
39     _myLab( 0 ),
40     _mySlider( 0 ),
41   _fr( 0 )
42 {
43   QListViewItem *element;
44
45   cout << "File: " << _file << endl;
46   SCRUTE(_file);
47   _med = new ::MED(MED_DRIVER,_file);
48   deque<string> meshesNames = _med->getMeshNames();
49   int numberOfMeshes = meshesNames.size();
50   
51   deque<string> fieldsNames = _med->getFieldNames();
52   int numberOfFields = fieldsNames.size();
53
54   QGridLayout* _lay = new QGridLayout( this, 1, 1 );
55
56   QGroupBox* _GroupC1 = new QGroupBox( this, "GroupC1" );
57   _lay->addWidget( _GroupC1,0,0 );
58
59   MESSAGE(basename(_file));
60   QString qs(tr("FILTER_FILE"));
61   qs.append(basename(_file));
62   _GroupC1->setTitle(qs);
63   _GroupC1->setColumnLayout(0, Qt::Vertical );
64   _GroupC1->layout()->setSpacing( 0 );
65   _GroupC1->layout()->setMargin( 0 );
66   _myGroupLayout = new QGridLayout( _GroupC1->layout() );
67   _myGroupLayout->setAlignment( Qt::AlignTop );
68   _myGroupLayout->setSpacing( 6 );
69   _myGroupLayout->setMargin( 11 );
70   _myGroupLayout->setColStretch( 0, 0 );
71   _myGroupLayout->setColStretch( 1, 1 );
72
73   int row = 0;
74
75   // 0)  tree to visualize meshes and fields
76   _myList = new QListView( _GroupC1, "List of fields" );
77   _myList->setMinimumSize( 400, 400 );
78   _myList->setMaximumSize( 400, 400 );
79   _myList->setRootIsDecorated(true);
80   _myList->addColumn(tr("FILTER_NAME"));
81   _myList->addColumn(tr("FILTER_TYPE"));
82
83   for(int i=0;i<numberOfMeshes;i++){
84     element = new QListViewItem( _myList, meshesNames[i], tr("FILTER_MESH") );
85     element->setExpandable(true);
86     _myList->setOpen(element,true);
87
88     for (int j=0; j<numberOfFields; j++){
89       deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[j]);
90       string meshName = _med->getField(fieldsNames[j],myIteration[0].dt,myIteration[0].it)->getSupport()->getMesh()->getName();
91       if( strcmp(meshName.c_str(),meshesNames[i].c_str()) == 0)
92         new QListViewItem( element, fieldsNames[j], tr("FILTER_FIELD") );
93     }
94
95     element->setSelectable(false);
96     _myGroupLayout->addWidget( _myList, row, 0 );
97   }
98   row++;
99
100   // 1)  label for time steps
101   _myLab = new QLabel(tr("FILTER_SEL_TS"),_GroupC1);
102   _myLab->hide();
103   _myGroupLayout->addWidget( _myLab, row, 0 );
104   row++;
105
106   // 2)  slider to visualize time steps
107   _mySlider = new QSlider(_GroupC1);
108   _mySlider->setOrientation(Qt::Horizontal);
109   _mySlider->setTickmarks(QSlider::Below);
110   _myGroupLayout->addWidget( _mySlider, row, 0 );
111
112   _mySlider->hide();
113   row++;
114
115   connect( _myList, SIGNAL(clicked(QListViewItem *)), this, SLOT(fieldSelected(QListViewItem *)));
116   connect( _mySlider, SIGNAL(sliderReleased()), this, SLOT(tsSelected()));
117
118   this->show(); /* displays Dialog */
119 }
120
121 SelectField::~SelectField()
122 {
123   // no need to delete child widgets, Qt does it all for us
124   cout << "SelectField: destructor called" << endl;
125   delete _med;
126 }
127
128 void SelectField::fieldSelected(QListViewItem *lvi)
129 {
130   if(lvi){
131     if( strcmp(lvi->text(1),"Field") == 0){
132       _field = lvi->text(0);
133       _mesh = lvi->parent()->text(0);
134       deque<DT_IT_> myIteration = _med->getFieldIteration (lvi->text(0));
135       int numberOfIteration = myIteration.size();
136       if( numberOfIteration > 1 ){
137         _mySlider->setRange(myIteration[0].dt,
138                             myIteration[numberOfIteration-1].dt);
139         _myLab->show();
140         _mySlider->show();
141       }
142       else{
143         _ts = 0;
144         _myLab->hide();
145         _mySlider->hide();
146       }
147     }
148   }
149 }
150
151 void SelectField::tsSelected()
152 {
153   _ts = _mySlider->value();
154   MESSAGE("File " << _file );
155   MESSAGE("Mesh " << _mesh );
156   MESSAGE("Field " << _field );
157   MESSAGE("Time step " << _ts );
158 }