Salome HOME
Merge branch 'abn/fix_intersec' into V7_main
[modules/med.git] / src / MEDGUI / MEDGUIFileContentDial.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  MED MEDGUI : MED component GUI implemetation
24 //  File   : MEDGUIFileContentDial.cxx
25 //  Module : MED
26 #include "MEDGUIFileContentDial.h"
27 #include "ui_MEDGUIFileContentDial.h"
28
29 #include <QString>
30 #include <QFileDialog>
31 #include <QLineEdit>
32 #include <QMessageBox>
33 #include <QMainWindow>
34
35 #include "MEDCalculatorBrowserLiteStruct.hxx"
36 #include "MEDCalculatorBrowserField.hxx"
37 #include "MEDCalculatorBrowserStep.hxx"
38 #include "MEDCalculatorBrowserMesh.hxx"
39
40 #include "MEDGUISelectComponents.h"
41 #include "MEDGUIDataBaseDockWidget.hxx"
42
43 #include <sstream>
44 #include <iostream>
45 #include <algorithm>
46
47 //  Default constructor
48 //  Set Qt specific var (ui)
49 //  Connect buttons to actions, close statement is already connect in the .ui file
50 //  Set QTreeWidgets parameters : header labels, selection mode
51 //  Connect QTreeWidget itemClicked signal to meshes and fieldsStateChange
52 //  Put mouse tracking on, so this class received mouse positions informations when mouse is above treewidget
53 //  Add contextual menu to treewidget's items with the call to selectCompoPopup and selStepPopup
54 //  Connect those actions to corresponding signals
55 MEDGUIFileContentDial::MEDGUIFileContentDial(MEDGUIDataBaseDockWidget* db, QWidget* parent):
56   QDialog(parent, 0), ui(new Ui::MEDGUIFileContentDial), _db(db)
57 {
58   setModal( false );
59   setSizeGripEnabled( true );
60   setAttribute( Qt::WA_DeleteOnClose );
61
62   QWidget* w = new QWidget( this );
63   QHBoxLayout* l = new QHBoxLayout( this );
64   l->setMargin( 0 );
65   l->addWidget( w );
66   ui->setupUi(w);
67
68   connect(ui->importMedFileButton, SIGNAL(clicked()), this, SLOT(openFile()));
69   connect(ui->addSelectionButton, SIGNAL(clicked()), this, SLOT(sendSelectionToDB()));
70   connect(ui->unselectAllButton, SIGNAL(clicked()), this, SLOT(unselectAll()));
71   connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close()));
72
73   ui->treeWidgetFields->setHeaderLabel("Available Field");
74   ui->treeWidgetFields->setSelectionMode(QAbstractItemView::MultiSelection);
75   ui->treeWidgetMeshes->setHeaderLabel("Available Meshes");
76   ui->treeWidgetMeshes->setSelectionMode(QAbstractItemView::MultiSelection);
77
78   connect(ui->treeWidgetMeshes, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(meshesStateChange(QTreeWidgetItem*, int)));
79   connect(ui->treeWidgetFields, SIGNAL(itemSelectionChanged()), this, SLOT(fieldsStateChanges()));
80   //connect(ui->treeWidgetFields, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(fieldsStateChange(QTreeWidgetItem*, int)));
81
82   ui->treeWidgetFields->setMouseTracking(true);
83   connect(ui->treeWidgetFields,SIGNAL(itemEntered(QTreeWidgetItem*,int)), this, SLOT(overfield(QTreeWidgetItem*,int)));
84
85   ui->treeWidgetFields->setContextMenuPolicy(Qt::ActionsContextMenu);
86   QAction* selcompo = new QAction("Select components",ui->treeWidgetFields);
87   QAction* selsteps = new QAction("Select steps",ui->treeWidgetFields);
88   ui->treeWidgetFields->addAction(selcompo);
89   ui->treeWidgetFields->addAction(selsteps);
90
91   connect(selcompo,SIGNAL(triggered(bool)),this,SLOT(selCompoPopup(bool)));
92   connect(selsteps,SIGNAL(triggered(bool)),this,SLOT(selStepsPopup(bool)));
93
94 }
95
96 //  Destructor
97 MEDGUIFileContentDial::~MEDGUIFileContentDial()
98 {
99   delete ui;
100 }
101
102 //  Qt specific
103 void MEDGUIFileContentDial::changeEvent(QEvent *e)
104 {
105   QWidget::changeEvent(e);
106   switch (e->type())
107   {
108     case QEvent::LanguageChange:
109       ui->retranslateUi(this);
110     break;
111   default:
112     break;
113   }
114 }
115
116 //  OpenFile
117 //  Create a new MEDGUILiteStruct with a file as parameter.
118 //  First the file is selected using a QFileDialog
119 //  Then, after checking if the name already exist
120 //  - if yes, try to add "_#" where # begin at 2
121 //  - if not, continue
122 //  Create a new MEDGUILiteStruct with the complet file name and the simplified file name as parameters
123 //  Add items to the two QTreeWidget get information from the new MEDGUILiteStruct
124 void MEDGUIFileContentDial::openFile()
125 {
126   QString fileName = QFileDialog::getOpenFileName(this,tr("Open Med File"),QDir::homePath(),tr("Med File (*.med)"));
127   if(fileName != QString("")){
128     QString realname = fileName.split("/").last();
129
130     int i = 2;
131     std::string name = realname.toStdString();
132     while(std::find(litestructs.begin(),litestructs.end(),name) != litestructs.end())
133     {
134       std::ostringstream oss;
135       oss << realname.toStdString() << "_" << i++ ;
136       name = oss.str();
137     }
138
139     ParaMEDMEM::MEDCalculatorBrowserLiteStruct ls(fileName.toStdString().c_str());
140     litestructs.push_back(ls);
141
142     QTreeWidgetItem* root = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str())));
143     for (unsigned int i = 0; i < ls.getNumberOfFields(); i += 1)
144     {
145       QTreeWidgetItem* fieldname = new QTreeWidgetItem(root,QStringList(QString(tr(ls.getFieldName(i).c_str()))));
146       ParaMEDMEM::MEDCalculatorBrowserField field = ls.getField(i);
147       for (unsigned int j = 0; j < field.getStepsSize(); j += 1)
148       {
149         std::ostringstream input;
150         input<<field.getSteps()[j].getTimeStep()<<" ( "<<field.getSteps()[j].getTimeValue()<<" )";
151         new QTreeWidgetItem(fieldname,QStringList(QString(tr(input.str().c_str()))));
152       }
153     }
154     ui->treeWidgetFields->addTopLevelItem(root);
155
156     QTreeWidgetItem* root_2 = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str())));
157     for (unsigned int i = 0; i < ls.getNumberOfMeshes(); i += 1)
158     {
159       new QTreeWidgetItem(root_2,QStringList(QString(tr(ls.getMeshName(i).c_str()))));
160     }
161     ui->treeWidgetMeshes->addTopLevelItem(root_2);
162   }
163 }
164
165 //  Change the select flag of one or more meshes
166 //  If the QTreeWidgetItem correspond to file (it has no QTreeWidgetItem above itself), it set the state of all meshes of this file according to it current state (if it's selected, all meshes will be selected)
167 //  If the QTreeWidgetItem is a mesh, juste the mesh state is changed. If the mesh is unselected, its father is checked, if it has no more selection inside, it's unselected, else, it stays selected
168 void MEDGUIFileContentDial::meshesStateChange(QTreeWidgetItem* qtwi, int col)
169 {
170   QTreeWidgetItem *father = qtwi->parent();
171   if(!father){
172     if (qtwi->isSelected())
173     {
174       litestructs[ui->treeWidgetMeshes->indexOfTopLevelItem(qtwi)].selectAllMeshes();
175       for ( int i = 0; i < qtwi->childCount(); i += 1)
176       {
177         qtwi->child(i)->setSelected(true);
178       }
179     }else{
180       litestructs[ui->treeWidgetMeshes->indexOfTopLevelItem(qtwi)].unselectAllMeshes();
181       for ( int i = 0; i < qtwi->childCount(); i += 1)
182       {
183         qtwi->child(i)->setSelected(false);
184       }
185     }
186   }else{
187     int lsInd =ui->treeWidgetMeshes->indexOfTopLevelItem(father);
188     if (qtwi->isSelected())
189     {
190       litestructs[lsInd].selectMesh(litestructs[lsInd].getMeshName(father->indexOfChild(qtwi)));
191       father->setSelected(true);
192     }else{
193       litestructs[lsInd].unselectMesh(litestructs[lsInd].getMeshName(father->indexOfChild(qtwi)));
194       bool stillselection=false;
195       for ( int i = 0; i < father->childCount(); i += 1)
196       {
197         if(father->child(i)->isSelected()){
198           stillselection = true;
199           break;
200         }
201       }
202       father->setSelected(stillselection);
203     }
204   }
205 }
206
207 void MEDGUIFileContentDial::fieldsStateChanges()
208 {
209   disconnect(ui->treeWidgetFields, SIGNAL(itemSelectionChanged()), this, SLOT(fieldsStateChanges()));
210   unselectAll();
211   QList<QTreeWidgetItem *> l=ui->treeWidgetFields->selectedItems();
212   for(QList<QTreeWidgetItem *>::iterator it=l.begin();it!=l.end();it++)
213     fieldsStateChange(*it,0);
214   connect(ui->treeWidgetFields, SIGNAL(itemSelectionChanged()), this, SLOT(fieldsStateChanges()));
215 }
216
217 //  Change the select flag of one or more fields
218 //  If the QTreeWidgetItem correspond to file (it has no QTreeWidgetItem above itself), it set the state of all fields, and all steps of this file according to it current state (if it's selected, all elements will be selected)
219 //  If the QTreeWidgetItem is a field (it has no QTreeWidgetItem above is "father"), juste the field and its steps state is changed. If the field is unselected , his father is checked, if it has no more selection inside, it's unselected, else, it stays selected.
220 //  If the QTreeWidgetItem is a step, juste the step state is changed. If the step is unselected , his father is checked and his grandfather are checked, if they have no more selection inside, they're unselected, else, they stays selected.
221 void MEDGUIFileContentDial::fieldsStateChange(QTreeWidgetItem* qtwi, int col)
222 {
223   QTreeWidgetItem *father = qtwi->parent();
224   if(!father)
225     {//  File
226       if(qtwi->isSelected())
227         {
228           litestructs[ui->treeWidgetFields->indexOfTopLevelItem(qtwi)].selectAllFields();
229           for ( int i = 0; i < qtwi->childCount(); i += 1)
230             {
231               qtwi->child(i)->setSelected(true);
232               for ( int j = 0; j < qtwi->child(i)->childCount(); j += 1)
233                 qtwi->child(i)->child(j)->setSelected(true);
234             }
235         }
236       else
237         {
238           litestructs[ui->treeWidgetFields->indexOfTopLevelItem(qtwi)].unselectAllFields();
239           for ( int i = 0; i < qtwi->childCount(); i += 1)
240             {
241               qtwi->child(i)->setSelected(false);
242               for ( int j = 0; j < qtwi->child(i)->childCount(); j += 1)
243                 qtwi->child(i)->child(j)->setSelected(false);
244             }
245         }
246     }
247   else if(!father->parent())
248     {//  Field
249       int lsInd = ui->treeWidgetFields->indexOfTopLevelItem(father);
250       int fieldInd = father->indexOfChild(qtwi);
251       std::string fieldName = litestructs[lsInd].getFieldName(fieldInd);
252       if(qtwi->isSelected())
253         {
254           litestructs[lsInd].selectField(fieldName);
255           //father->setSelected(true);
256           for ( int i = 0; i < qtwi->childCount(); i += 1)
257             {
258               qtwi->child(i)->setSelected(true);
259             }
260         }
261       else
262         {
263           litestructs[lsInd].unselectField(fieldName);
264           bool stillselection=false;
265           for ( int i = 0; i < father->childCount(); i += 1)
266             {
267               if(father->child(i)->isSelected())
268                 {
269                   stillselection = true;
270                   break;
271                 }
272             }
273           //father->setSelected(stillselection);
274           for ( int i = 0; i < qtwi->childCount(); i += 1)
275             {
276               qtwi->child(i)->setSelected(false);
277             }
278         }
279     }
280   else
281     {//  Step
282       int lsInd = ui->treeWidgetFields->indexOfTopLevelItem(father->parent());
283       int fieldInd = father->parent()->indexOfChild(father);
284       int stepInd = father->indexOfChild(qtwi);
285       std::string fieldName = litestructs[lsInd].getFieldName(fieldInd);
286       if(qtwi->isSelected())
287         {
288           litestructs[lsInd].getField(fieldName).selectStep(stepInd);
289           litestructs[lsInd].setSelected(true);
290           //father->setSelected(true);
291           //father->parent()->setSelected(true);
292         }
293       else
294         {
295           litestructs[lsInd].getField(fieldName).unselectStep(stepInd);
296           bool stillselection=false;
297           for ( int i = 0; i < father->childCount(); i += 1)
298             {
299               if(father->child(i)->isSelected())
300                 {
301                   stillselection = true;
302                   break;
303                 }
304             }
305           father->setSelected(stillselection);
306           stillselection=false;
307           for ( int i = 0; i < father->parent()->childCount(); i += 1)
308             {
309               if(father->parent()->child(i)->isSelected())
310                 {
311                   stillselection = true;
312                   break;
313                 }
314             }
315           father->parent()->setSelected(stillselection);
316           litestructs[lsInd].setSelected(stillselection);
317         }
318     }
319 }
320
321 //  Show the selection on standart output using std::cout and str methods from MEDGUILiteStruct
322 void MEDGUIFileContentDial::sendSelectionToDB()
323 {
324   std::vector<ParaMEDMEM::MEDCalculatorBrowserLiteStruct> lt2send2db;
325   for (unsigned int i=0;i<litestructs.size();i++)
326     {
327       unsigned int nbOfFiels=litestructs[i].getNumberOfFields();
328       const ParaMEDMEM::MEDCalculatorBrowserLiteStruct& myStruct=litestructs[i];
329       for(unsigned int j=0;j<nbOfFiels;j++)
330         {
331           if(myStruct.getField(j).isAnySelection())
332             try
333               {
334                 //lt2send2db.push_back(myStruct.getField(j).getSelectedTimeSteps());
335               }
336             catch(INTERP_KERNEL::Exception& e)
337               {
338               }
339         }
340     }
341   _db->appendFieldLT(lt2send2db);
342   /*std::cout<<"Current Selection"<<std::endl;
343   for (unsigned int i = 0; i < litestructs.size(); i += 1)
344   {
345     std::cout<<"Lite Struct n°"<<i<<std::endl;
346     std::cout<<litestructs[i].str()<<std::endl;
347     std::cout<<"--------------------------------"<<std::endl;
348     }*/
349 }
350
351 //  Unselec all fields and meshes
352 void MEDGUIFileContentDial::unselectAll()
353 {
354    for (unsigned int i = 0; i < litestructs.size(); i += 1)
355       {
356         litestructs[i].unselectAll();
357       }
358 }
359
360 //  Show in red the corresponding meshes from a field or a step or a field hoovered by mouse
361 //  First clean alrady colored meshes list (color back in black and empty coloredMeshes vector)
362 //  Then, get the id of the MEDGUILiteStruct corresponding to the currently hovered item
363 //  Get corresponding meshes as string from the currently hovered item
364 //  Get the corresponding root of the meshes QTreeWidget from the root of the fields QTreeWidget
365 //  Color in red meshes of the meshes QTreeWidget if they are from the same file than qtwi and are support of it or of one of its children
366 void MEDGUIFileContentDial::overfield(QTreeWidgetItem* qtwi,int col)
367 {
368
369   for (unsigned int i = 0; i < coloredMeshes.size(); i += 1)
370   {
371     coloredMeshes[i]->setForeground(0,QBrush(Qt::black));
372   }
373   coloredMeshes = std::vector<QTreeWidgetItem*>();
374
375   int lsInd = -1;
376   if(qtwi->parent()){
377     if(qtwi->parent()->parent()) lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent()->parent());
378     else  lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent());
379   }else lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi);
380
381   std::vector<std::string> meshesNames;
382   if(qtwi->parent()){
383     if(qtwi->childCount()) meshesNames = litestructs[lsInd].getCorrespondingMeshesFromField(qtwi->parent()->indexOfChild(qtwi));
384     else meshesNames.push_back(litestructs[lsInd].getField(qtwi->parent()->parent()->indexOfChild(qtwi->parent())).getCorrespondingMeshFromStep(qtwi->parent()->indexOfChild(qtwi)));
385   }else meshesNames = litestructs[lsInd].getCorrespondingMeshesFromLS();
386
387   QTreeWidgetItem *lsroot;
388   for ( int i = 0; i < ui->treeWidgetMeshes->topLevelItemCount(); i += 1)
389   {
390     if(ui->treeWidgetMeshes->topLevelItem(i)->text(0).toStdString() == litestructs[lsInd].getName())
391       lsroot = ui->treeWidgetMeshes->topLevelItem(i);
392   }
393
394   for ( int i = 0; i < lsroot->childCount(); i += 1)
395   {
396     if(std::find(meshesNames.begin(),meshesNames.end(),lsroot->child(i)->text(0).toStdString()) != meshesNames.end()){
397       lsroot->child(i)->setForeground(0,QBrush(Qt::red));
398       coloredMeshes.push_back(lsroot->child(i));
399     }
400   }
401 }
402
403 //  Show the QLineEdit for selecting steps
404 //  Get the current selected item
405 //  Create a QLineEdit inside a QDialog without borders
406 //  Connect editingFinished signal from QLineEdit to close slot from QDialog
407 //  Move the QDialog so it will appear next to the current selected item
408 //  Show the dialog
409 //  Call the correct select method according to the fact that the current select item is a file, a field or a step
410 void MEDGUIFileContentDial::selStepsPopup(bool checkable)
411 {
412
413   QTreeWidgetItem* qtwi = ui->treeWidgetFields->currentItem();
414
415   QDialog *qd = new QDialog(this,Qt::ToolTip);
416   QLineEdit *ql = new QLineEdit(qd);
417
418   connect(ql,SIGNAL(editingFinished()),qd,SLOT(close()));
419
420   qd->resize(120,20);
421   qd->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
422
423   QRect currentItemRec = ui->treeWidgetFields->visualItemRect(qtwi);
424   QPoint topLeft = currentItemRec.topLeft();
425   QPoint realPos = ui->treeWidgetFields->mapToGlobal(topLeft);
426
427   qd->move(realPos);
428
429   qd->exec();
430
431   QString sel = ql->text();
432   if(ql) delete ql;
433   if(qd) delete qd;
434
435   if(!qtwi->parent()) selFromFile(qtwi,sel);
436   else if(!qtwi->parent()->parent()) selFromField(qtwi,sel);
437   else selFromStep(qtwi,sel);
438
439 }
440
441 //  Methode to set all elements of a MEDGUILiteStruct to (un)selected according to a string (such as "all", "none", ...)
442 //  3 cases :
443 //  - you want to select all time steps of all fields, the selection is made directly
444 //  - you want to unselect all time steps of all fields, the unselection is made directly
445 //  - the string is neither "all" nor "none", selFromField method is called for each field with the string as second argument
446 //  Empty string means no change at all
447 void MEDGUIFileContentDial::selFromFile(QTreeWidgetItem* qtwi, QString sel)
448 {
449   if(sel != QString("")){
450     if(sel == QString("all")){
451       qtwi->setSelected(true);
452       litestructs[ui->treeWidgetFields->indexOfTopLevelItem(qtwi)].selectAllFields();
453       for ( int i = 0; i < qtwi->childCount(); i += 1)
454       {
455         qtwi->child(i)->setSelected(true);
456         for ( int j = 0; j < qtwi->child(i)->childCount(); j += 1)
457         {
458           qtwi->child(i)->child(j)->setSelected(true);
459         }
460       }
461     }else if(sel == QString("none")){
462       qtwi->setSelected(false);
463       litestructs[ui->treeWidgetFields->indexOfTopLevelItem(qtwi)].unselectAllFields();
464       for ( int i = 0; i < qtwi->childCount(); i += 1)
465       {
466         qtwi->child(i)->setSelected(false);
467         for ( int j = 0; j < qtwi->child(i)->childCount(); j += 1)
468         {
469           qtwi->child(i)->child(j)->setSelected(false);
470         }
471       }
472     }else{
473         for ( int j = 0; j < qtwi->childCount(); j += 1)
474         {
475           selFromField(qtwi->child(j),sel);
476         }
477     }
478   }
479 }
480
481 //  Methode to set all elements of a MEDGUIField to (un)selected according to a string (such as "all", "none", ...)
482 //  If empty string, no change are made
483 //  Else :
484 //   First get the file and field id
485 //   Then if statement is all, select all steps, set father to selected
486 //   If statement is none, unselect all steps, if father get no more child selected, set father to unselected
487 //   Else
488 //    Remove all spaces from the string
489 //    split the string using ";" char (";" means end of command)
490 //     For each element, split the string with ":" ("a-b" means interval between a and b)
491 //      If juste one element, select step with this id;
492 //      If two elements, select all step between the first and the second, if the first is none, min = 0, if the second is none, max = steps.size()
493 //      Set field to selected
494 //    Set file to selected
495 void MEDGUIFileContentDial::selFromField(QTreeWidgetItem* qtwi, QString sel)
496 {
497   if(sel != QString("")){
498
499     int lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent());
500     int fieldInd = qtwi->parent()->indexOfChild(qtwi);
501     std::string fieldName = litestructs[lsInd].getFieldName(fieldInd);
502
503     if(sel == QString("all")){
504       qtwi->setSelected(true);
505       litestructs[lsInd].selectField(fieldName);
506       qtwi->parent()->setSelected(true);
507       for ( int i = 0; i < qtwi->childCount(); i += 1)
508         {
509            qtwi->child(i)->setSelected(true);
510         }
511
512     }else if(sel == QString("none")){
513       qtwi->setSelected(false);
514       litestructs[lsInd].unselectField(fieldName);
515       bool stillselection=false;
516       for ( int i = 0; i < qtwi->parent()->childCount(); i += 1)
517       {
518         if(qtwi->parent()->child(i)->isSelected()){
519           stillselection = true;
520           break;
521         }
522       }
523       qtwi->parent()->setSelected(stillselection);
524       for ( int i = 0; i < qtwi->childCount(); i += 1)
525       {
526         qtwi->child(i)->setSelected(false);
527       }
528
529     }else{
530       if(sel.size()!=0){
531         sel = sel.simplified();
532         QStringList listSel = sel.split(" ");
533         sel = listSel.join("");
534
535         listSel = sel.split(";");
536         for (int i = 0; i < listSel.size(); i += 1)
537         {
538           QStringList totreat = listSel[i].split(":");
539
540           if(totreat[0].toInt() >= qtwi->childCount() || totreat[0].toInt() < 0 || (totreat.size() == 2 && ( totreat[1].toInt() >= qtwi->childCount() ))){
541             std::ostringstream oss;
542             oss << "Input value incorrect, should be between 0 and ";
543             oss << qtwi->childCount()-1;
544             oss << ".";
545             QMessageBox::warning(this,"Incorrect Input Value",oss.str().c_str());
546             return;
547           }//  Check values
548           if(totreat.size() > 2 || ((totreat[0] != QString("0") && totreat[0] != QString("")) && totreat[0].toInt()==0) || ( totreat.size() == 2 && (totreat[1] != QString("") && totreat[1].toInt()==0))){
549             std::ostringstream oss;
550             oss << "Input values incorrect (";
551             oss << listSel[i].toStdString().c_str();
552             oss << ").";
553             QMessageBox::warning(this,"Incorrect Input Value",oss.str().c_str());
554             return;
555           }//  Check type (to filter non-int characters)
556
557           if(totreat.size() == 1){
558             litestructs[lsInd].getField(fieldName).selectStep(totreat[0].toInt());
559             litestructs[lsInd].setSelected(true);
560             qtwi->child(totreat[0].toInt())->setSelected(true);
561
562           }else if(totreat.size() == 2){
563             int max = qtwi->childCount()-1;
564             if(totreat[1] != QString("")) max = totreat[1].toInt();
565             if(max < totreat[0].toInt()){
566               std::ostringstream oss;
567               oss << "Input values incorrect (";
568               oss << listSel[i].toStdString().c_str();
569               oss << ").";
570               QMessageBox::warning(this,"Incorrect Input Value",oss.str().c_str());
571               return;
572             }//  Check if interval is correct
573             for (int j = totreat[0].toInt(); j <= max; j += 1)
574             {
575               litestructs[lsInd].getField(fieldName).selectStep(j);
576               litestructs[lsInd].setSelected(true);
577               qtwi->child(j)->setSelected(true);
578             }
579           }
580         }
581         qtwi->setSelected(true);
582         qtwi->parent()->setSelected(true);
583       }
584     }
585   }
586 }
587
588 //  Methode to set all elements of a MEDGUIField when selection is made from a MEDGUIStep to (un)selected according to a string (such as "all", "none", ...)
589 //  Calling it on a step is the same as calling it from is father (the corresponding field)
590 void MEDGUIFileContentDial::selFromStep(QTreeWidgetItem* qtwi,QString sel)
591 {
592   selFromField(qtwi->parent(), sel);
593 }
594
595 //  Show the dialog for selecting components and changing components names
596 //  Get the current QTreeWidgetItem
597 //  If its a field or a step, get the field id
598 //  Call MEDGUISelectComponent dial with the MEDGUILiteStruct and the field id (-1 if none)
599 void MEDGUIFileContentDial::selCompoPopup(bool checkable)
600 {
601   QTreeWidgetItem* qtwi = ui->treeWidgetFields->currentItem();
602   int lsInd=0;
603   int fieldInd = -1;
604   if(!qtwi->parent()) lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi);
605   else if(!qtwi->parent()->parent()){
606     lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent());
607     fieldInd = qtwi->parent()->indexOfChild(qtwi);
608   }
609   else{
610     lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent()->parent());
611     fieldInd = qtwi->parent()->parent()->indexOfChild(qtwi->parent());
612   }
613
614   MEDGUISelectComponents selcomp(litestructs[lsInd], this, fieldInd);
615   selcomp.exec();
616 }
617