1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SelectField.h"
22 #include <qgroupbox.h>
25 #include <qlistview.h>
28 #include <qpushbutton.h>
30 SelectField::SelectField(FilterGUI* theModule,const QString& file,
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 ),
40 QListViewItem *element;
43 _med = new ::MED(MED_DRIVER,_file);
44 deque<string> meshesNames = _med->getMeshNames();
45 int numberOfMeshes = meshesNames.size();
47 deque<string> fieldsNames = _med->getFieldNames();
48 int numberOfFields = fieldsNames.size();
50 QGridLayout* _lay = new QGridLayout( this, 1, 1 );
52 QGroupBox* _GroupC1 = new QGroupBox( this, "GroupC1" );
53 _lay->addWidget( _GroupC1,0,0 );
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 );
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"));
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);
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") );
91 element->setSelectable(false);
93 _myGroupLayout->addWidget( _myList, row, 0 );
96 // 1) label for time steps
97 _myLab = new QLabel(tr("FILTER_SEL_TS"),_GroupC1);
99 _myGroupLayout->addWidget( _myLab, row, 0 );
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 );
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 );
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()));
139 this->show(); /* displays Dialog */
142 SelectField::~SelectField()
144 // no need to delete child widgets, Qt does it all for us
145 cout << "SelectField: destructor called" << endl;
149 void SelectField::fieldSelected(QListViewItem *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);
172 void SelectField::tsSelected()
174 _ts = _mySlider->value();
175 MESSAGE("File " << _file );
176 MESSAGE("Mesh " << _mesh );
177 MESSAGE("Field " << _field );
178 MESSAGE("Time step " << _ts );
181 void SelectField::ClickOnClose()
183 MESSAGE("click on Cancel");
187 void SelectField::ClickOnHelp()
189 MESSAGE("click on Help");