Back to index

salome-med  6.5.0
MEDGUIFileContentDial.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  MED MEDGUI : MED component GUI implemetation
00024 //  File   : MEDGUIFileContentDial.cxx
00025 //  Module : MED
00026 #include "MEDGUIFileContentDial.h"
00027 #include "ui_MEDGUIFileContentDial.h"
00028 
00029 #include <QString>
00030 #include <QFileDialog>
00031 #include <QLineEdit>
00032 #include <QMessageBox>
00033 #include <QMainWindow>
00034 
00035 #include "MEDCalculatorBrowserLiteStruct.hxx"
00036 #include "MEDCalculatorBrowserField.hxx"
00037 #include "MEDCalculatorBrowserStep.hxx"
00038 #include "MEDCalculatorBrowserMesh.hxx"
00039 
00040 #include "MEDGUISelectComponents.h"
00041 #include "MEDGUIDataBaseDockWidget.hxx"
00042 
00043 #include <sstream>
00044 #include <iostream>
00045 #include <algorithm>
00046 
00047 //  Default constructor
00048 //  Set Qt specific var (ui)
00049 //  Connect buttons to actions, close statement is already connect in the .ui file
00050 //  Set QTreeWidgets parameters : header labels, selection mode
00051 //  Connect QTreeWidget itemClicked signal to meshes and fieldsStateChange
00052 //  Put mouse tracking on, so this class received mouse positions informations when mouse is above treewidget
00053 //  Add contextual menu to treewidget's items with the call to selectCompoPopup and selStepPopup
00054 //  Connect those actions to corresponding signals
00055 MEDGUIFileContentDial::MEDGUIFileContentDial(MEDGUIDataBaseDockWidget* db, QWidget* parent):
00056   QDialog(parent, 0), ui(new Ui::MEDGUIFileContentDial), _db(db)
00057 {
00058   setModal( false );
00059   setSizeGripEnabled( true );
00060   setAttribute( Qt::WA_DeleteOnClose );
00061 
00062   QWidget* w = new QWidget( this );
00063   QHBoxLayout* l = new QHBoxLayout( this );
00064   l->setMargin( 0 );
00065   l->addWidget( w );
00066   ui->setupUi(w);
00067 
00068   connect(ui->importMedFileButton, SIGNAL(clicked()), this, SLOT(openFile()));
00069   connect(ui->addSelectionButton, SIGNAL(clicked()), this, SLOT(sendSelectionToDB()));
00070   connect(ui->unselectAllButton, SIGNAL(clicked()), this, SLOT(unselectAll()));
00071   connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close()));
00072 
00073   ui->treeWidgetFields->setHeaderLabel("Available Field");
00074   ui->treeWidgetFields->setSelectionMode(QAbstractItemView::MultiSelection);
00075   ui->treeWidgetMeshes->setHeaderLabel("Available Meshes");
00076   ui->treeWidgetMeshes->setSelectionMode(QAbstractItemView::MultiSelection);
00077 
00078   connect(ui->treeWidgetMeshes, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(meshesStateChange(QTreeWidgetItem*, int)));
00079   connect(ui->treeWidgetFields, SIGNAL(itemSelectionChanged()), this, SLOT(fieldsStateChanges()));
00080   //connect(ui->treeWidgetFields, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(fieldsStateChange(QTreeWidgetItem*, int)));
00081 
00082   ui->treeWidgetFields->setMouseTracking(true);
00083   connect(ui->treeWidgetFields,SIGNAL(itemEntered(QTreeWidgetItem*,int)), this, SLOT(overfield(QTreeWidgetItem*,int)));
00084 
00085   ui->treeWidgetFields->setContextMenuPolicy(Qt::ActionsContextMenu);
00086   QAction* selcompo = new QAction("Select components",ui->treeWidgetFields);
00087   QAction* selsteps = new QAction("Select steps",ui->treeWidgetFields);
00088   ui->treeWidgetFields->addAction(selcompo);
00089   ui->treeWidgetFields->addAction(selsteps);
00090 
00091   connect(selcompo,SIGNAL(triggered(bool)),this,SLOT(selCompoPopup(bool)));
00092   connect(selsteps,SIGNAL(triggered(bool)),this,SLOT(selStepsPopup(bool)));
00093 
00094 }
00095 
00096 //  Destructor
00097 MEDGUIFileContentDial::~MEDGUIFileContentDial()
00098 {
00099   delete ui;
00100 }
00101 
00102 //  Qt specific
00103 void MEDGUIFileContentDial::changeEvent(QEvent *e)
00104 {
00105   QWidget::changeEvent(e);
00106   switch (e->type())
00107   {
00108     case QEvent::LanguageChange:
00109       ui->retranslateUi(this);
00110     break;
00111   default:
00112     break;
00113   }
00114 }
00115 
00116 //  OpenFile
00117 //  Create a new MEDGUILiteStruct with a file as parameter.
00118 //  First the file is selected using a QFileDialog
00119 //  Then, after checking if the name already exist
00120 //  - if yes, try to add "_#" where # begin at 2
00121 //  - if not, continue
00122 //  Create a new MEDGUILiteStruct with the complet file name and the simplified file name as parameters
00123 //  Add items to the two QTreeWidget get information from the new MEDGUILiteStruct
00124 void MEDGUIFileContentDial::openFile()
00125 {
00126   QString fileName = QFileDialog::getOpenFileName(this,tr("Open Med File"),QDir::homePath(),tr("Med File (*.med)"));
00127   if(fileName != QString("")){
00128     QString realname = fileName.split("/").last();
00129 
00130     int i = 2;
00131     std::string name = realname.toStdString();
00132     while(std::find(litestructs.begin(),litestructs.end(),name) != litestructs.end())
00133     {
00134       std::ostringstream oss;
00135       oss << realname.toStdString() << "_" << i++ ;
00136       name = oss.str();
00137     }
00138 
00139     ParaMEDMEM::MEDCalculatorBrowserLiteStruct ls(fileName.toStdString().c_str());
00140     litestructs.push_back(ls);
00141 
00142     QTreeWidgetItem* root = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str())));
00143     for (unsigned int i = 0; i < ls.getNumberOfFields(); i += 1)
00144     {
00145       QTreeWidgetItem* fieldname = new QTreeWidgetItem(root,QStringList(QString(tr(ls.getFieldName(i).c_str()))));
00146       ParaMEDMEM::MEDCalculatorBrowserField field = ls.getField(i);
00147       for (unsigned int j = 0; j < field.getStepsSize(); j += 1)
00148       {
00149         std::ostringstream input;
00150         input<<field.getSteps()[j].getTimeStep()<<" ( "<<field.getSteps()[j].getTimeValue()<<" )";
00151         new QTreeWidgetItem(fieldname,QStringList(QString(tr(input.str().c_str()))));
00152       }
00153     }
00154     ui->treeWidgetFields->addTopLevelItem(root);
00155 
00156     QTreeWidgetItem* root_2 = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str())));
00157     for (unsigned int i = 0; i < ls.getNumberOfMeshes(); i += 1)
00158     {
00159       new QTreeWidgetItem(root_2,QStringList(QString(tr(ls.getMeshName(i).c_str()))));
00160     }
00161     ui->treeWidgetMeshes->addTopLevelItem(root_2);
00162   }
00163 }
00164 
00165 //  Change the select flag of one or more meshes
00166 //  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)
00167 //  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
00168 void MEDGUIFileContentDial::meshesStateChange(QTreeWidgetItem* qtwi, int col)
00169 {
00170   QTreeWidgetItem *father = qtwi->parent();
00171   if(!father){
00172     if (qtwi->isSelected())
00173     {
00174       litestructs[ui->treeWidgetMeshes->indexOfTopLevelItem(qtwi)].selectAllMeshes();
00175       for ( int i = 0; i < qtwi->childCount(); i += 1)
00176       {
00177         qtwi->child(i)->setSelected(true);
00178       }
00179     }else{
00180       litestructs[ui->treeWidgetMeshes->indexOfTopLevelItem(qtwi)].unselectAllMeshes();
00181       for ( int i = 0; i < qtwi->childCount(); i += 1)
00182       {
00183         qtwi->child(i)->setSelected(false);
00184       }
00185     }
00186   }else{
00187     int lsInd =ui->treeWidgetMeshes->indexOfTopLevelItem(father);
00188     if (qtwi->isSelected())
00189     {
00190       litestructs[lsInd].selectMesh(litestructs[lsInd].getMeshName(father->indexOfChild(qtwi)));
00191       father->setSelected(true);
00192     }else{
00193       litestructs[lsInd].unselectMesh(litestructs[lsInd].getMeshName(father->indexOfChild(qtwi)));
00194       bool stillselection=false;
00195       for ( int i = 0; i < father->childCount(); i += 1)
00196       {
00197         if(father->child(i)->isSelected()){
00198           stillselection = true;
00199           break;
00200         }
00201       }
00202       father->setSelected(stillselection);
00203     }
00204   }
00205 }
00206 
00207 void MEDGUIFileContentDial::fieldsStateChanges()
00208 {
00209   disconnect(ui->treeWidgetFields, SIGNAL(itemSelectionChanged()), this, SLOT(fieldsStateChanges()));
00210   unselectAll();
00211   QList<QTreeWidgetItem *> l=ui->treeWidgetFields->selectedItems();
00212   for(QList<QTreeWidgetItem *>::iterator it=l.begin();it!=l.end();it++)
00213     fieldsStateChange(*it,0);
00214   connect(ui->treeWidgetFields, SIGNAL(itemSelectionChanged()), this, SLOT(fieldsStateChanges()));
00215 }
00216 
00217 //  Change the select flag of one or more fields
00218 //  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)
00219 //  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.
00220 //  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.
00221 void MEDGUIFileContentDial::fieldsStateChange(QTreeWidgetItem* qtwi, int col)
00222 {
00223   QTreeWidgetItem *father = qtwi->parent();
00224   if(!father)
00225     {//  File
00226       if(qtwi->isSelected())
00227         {
00228           litestructs[ui->treeWidgetFields->indexOfTopLevelItem(qtwi)].selectAllFields();
00229           for ( int i = 0; i < qtwi->childCount(); i += 1)
00230             {
00231               qtwi->child(i)->setSelected(true);
00232               for ( int j = 0; j < qtwi->child(i)->childCount(); j += 1)
00233                 qtwi->child(i)->child(j)->setSelected(true);
00234             }
00235         }
00236       else
00237         {
00238           litestructs[ui->treeWidgetFields->indexOfTopLevelItem(qtwi)].unselectAllFields();
00239           for ( int i = 0; i < qtwi->childCount(); i += 1)
00240             {
00241               qtwi->child(i)->setSelected(false);
00242               for ( int j = 0; j < qtwi->child(i)->childCount(); j += 1)
00243                 qtwi->child(i)->child(j)->setSelected(false);
00244             }
00245         }
00246     }
00247   else if(!father->parent())
00248     {//  Field
00249       int lsInd = ui->treeWidgetFields->indexOfTopLevelItem(father);
00250       int fieldInd = father->indexOfChild(qtwi);
00251       std::string fieldName = litestructs[lsInd].getFieldName(fieldInd);
00252       if(qtwi->isSelected())
00253         {
00254           litestructs[lsInd].selectField(fieldName);
00255           //father->setSelected(true);
00256           for ( int i = 0; i < qtwi->childCount(); i += 1)
00257             {
00258               qtwi->child(i)->setSelected(true);
00259             }
00260         }
00261       else
00262         {
00263           litestructs[lsInd].unselectField(fieldName);
00264           bool stillselection=false;
00265           for ( int i = 0; i < father->childCount(); i += 1)
00266             {
00267               if(father->child(i)->isSelected())
00268                 {
00269                   stillselection = true;
00270                   break;
00271                 }
00272             }
00273           //father->setSelected(stillselection);
00274           for ( int i = 0; i < qtwi->childCount(); i += 1)
00275             {
00276               qtwi->child(i)->setSelected(false);
00277             }
00278         }
00279     }
00280   else
00281     {//  Step
00282       int lsInd = ui->treeWidgetFields->indexOfTopLevelItem(father->parent());
00283       int fieldInd = father->parent()->indexOfChild(father);
00284       int stepInd = father->indexOfChild(qtwi);
00285       std::string fieldName = litestructs[lsInd].getFieldName(fieldInd);
00286       if(qtwi->isSelected())
00287         {
00288           litestructs[lsInd].getField(fieldName).selectStep(stepInd);
00289           litestructs[lsInd].setSelected(true);
00290           //father->setSelected(true);
00291           //father->parent()->setSelected(true);
00292         }
00293       else
00294         {
00295           litestructs[lsInd].getField(fieldName).unselectStep(stepInd);
00296           bool stillselection=false;
00297           for ( int i = 0; i < father->childCount(); i += 1)
00298             {
00299               if(father->child(i)->isSelected())
00300                 {
00301                   stillselection = true;
00302                   break;
00303                 }
00304             }
00305           father->setSelected(stillselection);
00306           stillselection=false;
00307           for ( int i = 0; i < father->parent()->childCount(); i += 1)
00308             {
00309               if(father->parent()->child(i)->isSelected())
00310                 {
00311                   stillselection = true;
00312                   break;
00313                 }
00314             }
00315           father->parent()->setSelected(stillselection);
00316           litestructs[lsInd].setSelected(stillselection);
00317         }
00318     }
00319 }
00320 
00321 //  Show the selection on standart output using std::cout and str methods from MEDGUILiteStruct
00322 void MEDGUIFileContentDial::sendSelectionToDB()
00323 {
00324   std::vector<ParaMEDMEM::MEDCalculatorBrowserLiteStruct> lt2send2db;
00325   for (unsigned int i=0;i<litestructs.size();i++)
00326     {
00327       unsigned int nbOfFiels=litestructs[i].getNumberOfFields();
00328       const ParaMEDMEM::MEDCalculatorBrowserLiteStruct& myStruct=litestructs[i];
00329       for(unsigned int j=0;j<nbOfFiels;j++)
00330         {
00331           if(myStruct.getField(j).isAnySelection())
00332             try
00333               {
00334                 //lt2send2db.push_back(myStruct.getField(j).getSelectedTimeSteps());
00335               }
00336             catch(INTERP_KERNEL::Exception& e)
00337               {
00338               }
00339         }
00340     }
00341   _db->appendFieldLT(lt2send2db);
00342   /*std::cout<<"Current Selection"<<std::endl;
00343   for (unsigned int i = 0; i < litestructs.size(); i += 1)
00344   {
00345     std::cout<<"Lite Struct n°"<<i<<std::endl;
00346     std::cout<<litestructs[i].str()<<std::endl;
00347     std::cout<<"--------------------------------"<<std::endl;
00348     }*/
00349 }
00350 
00351 //  Unselec all fields and meshes
00352 void MEDGUIFileContentDial::unselectAll()
00353 {
00354    for (unsigned int i = 0; i < litestructs.size(); i += 1)
00355       {
00356         litestructs[i].unselectAll();
00357       }
00358 }
00359 
00360 //  Show in red the corresponding meshes from a field or a step or a field hoovered by mouse
00361 //  First clean alrady colored meshes list (color back in black and empty coloredMeshes vector)
00362 //  Then, get the id of the MEDGUILiteStruct corresponding to the currently hovered item
00363 //  Get corresponding meshes as string from the currently hovered item
00364 //  Get the corresponding root of the meshes QTreeWidget from the root of the fields QTreeWidget
00365 //  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
00366 void MEDGUIFileContentDial::overfield(QTreeWidgetItem* qtwi,int col)
00367 {
00368 
00369   for (unsigned int i = 0; i < coloredMeshes.size(); i += 1)
00370   {
00371     coloredMeshes[i]->setForeground(0,QBrush(Qt::black));
00372   }
00373   coloredMeshes = std::vector<QTreeWidgetItem*>();
00374 
00375   int lsInd = -1;
00376   if(qtwi->parent()){
00377     if(qtwi->parent()->parent()) lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent()->parent());
00378     else  lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent());
00379   }else lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi);
00380 
00381   std::vector<std::string> meshesNames;
00382   if(qtwi->parent()){
00383     if(qtwi->childCount()) meshesNames = litestructs[lsInd].getCorrespondingMeshesFromField(qtwi->parent()->indexOfChild(qtwi));
00384     else meshesNames.push_back(litestructs[lsInd].getField(qtwi->parent()->parent()->indexOfChild(qtwi->parent())).getCorrespondingMeshFromStep(qtwi->parent()->indexOfChild(qtwi)));
00385   }else meshesNames = litestructs[lsInd].getCorrespondingMeshesFromLS();
00386 
00387   QTreeWidgetItem *lsroot;
00388   for ( int i = 0; i < ui->treeWidgetMeshes->topLevelItemCount(); i += 1)
00389   {
00390     if(ui->treeWidgetMeshes->topLevelItem(i)->text(0).toStdString() == litestructs[lsInd].getName())
00391       lsroot = ui->treeWidgetMeshes->topLevelItem(i);
00392   }
00393 
00394   for ( int i = 0; i < lsroot->childCount(); i += 1)
00395   {
00396     if(std::find(meshesNames.begin(),meshesNames.end(),lsroot->child(i)->text(0).toStdString()) != meshesNames.end()){
00397       lsroot->child(i)->setForeground(0,QBrush(Qt::red));
00398       coloredMeshes.push_back(lsroot->child(i));
00399     }
00400   }
00401 }
00402 
00403 //  Show the QLineEdit for selecting steps
00404 //  Get the current selected item
00405 //  Create a QLineEdit inside a QDialog without borders
00406 //  Connect editingFinished signal from QLineEdit to close slot from QDialog
00407 //  Move the QDialog so it will appear next to the current selected item
00408 //  Show the dialog
00409 //  Call the correct select method according to the fact that the current select item is a file, a field or a step
00410 void MEDGUIFileContentDial::selStepsPopup(bool checkable)
00411 {
00412 
00413   QTreeWidgetItem* qtwi = ui->treeWidgetFields->currentItem();
00414 
00415   QDialog *qd = new QDialog(this,Qt::ToolTip);
00416   QLineEdit *ql = new QLineEdit(qd);
00417 
00418   connect(ql,SIGNAL(editingFinished()),qd,SLOT(close()));
00419 
00420   qd->resize(120,20);
00421   qd->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
00422 
00423   QRect currentItemRec = ui->treeWidgetFields->visualItemRect(qtwi);
00424   QPoint topLeft = currentItemRec.topLeft();
00425   QPoint realPos = ui->treeWidgetFields->mapToGlobal(topLeft);
00426 
00427   qd->move(realPos);
00428 
00429   qd->exec();
00430 
00431   QString sel = ql->text();
00432   if(ql) delete ql;
00433   if(qd) delete qd;
00434 
00435   if(!qtwi->parent()) selFromFile(qtwi,sel);
00436   else if(!qtwi->parent()->parent()) selFromField(qtwi,sel);
00437   else selFromStep(qtwi,sel);
00438 
00439 }
00440 
00441 //  Methode to set all elements of a MEDGUILiteStruct to (un)selected according to a string (such as "all", "none", ...)
00442 //  3 cases :
00443 //  - you want to select all time steps of all fields, the selection is made directly
00444 //  - you want to unselect all time steps of all fields, the unselection is made directly
00445 //  - the string is neither "all" nor "none", selFromField method is called for each field with the string as second argument
00446 //  Empty string means no change at all
00447 void MEDGUIFileContentDial::selFromFile(QTreeWidgetItem* qtwi, QString sel)
00448 {
00449   if(sel != QString("")){
00450     if(sel == QString("all")){
00451       qtwi->setSelected(true);
00452       litestructs[ui->treeWidgetFields->indexOfTopLevelItem(qtwi)].selectAllFields();
00453       for ( int i = 0; i < qtwi->childCount(); i += 1)
00454       {
00455         qtwi->child(i)->setSelected(true);
00456         for ( int j = 0; j < qtwi->child(i)->childCount(); j += 1)
00457         {
00458           qtwi->child(i)->child(j)->setSelected(true);
00459         }
00460       }
00461     }else if(sel == QString("none")){
00462       qtwi->setSelected(false);
00463       litestructs[ui->treeWidgetFields->indexOfTopLevelItem(qtwi)].unselectAllFields();
00464       for ( int i = 0; i < qtwi->childCount(); i += 1)
00465       {
00466         qtwi->child(i)->setSelected(false);
00467         for ( int j = 0; j < qtwi->child(i)->childCount(); j += 1)
00468         {
00469           qtwi->child(i)->child(j)->setSelected(false);
00470         }
00471       }
00472     }else{
00473         for ( int j = 0; j < qtwi->childCount(); j += 1)
00474         {
00475           selFromField(qtwi->child(j),sel);
00476         }
00477     }
00478   }
00479 }
00480 
00481 //  Methode to set all elements of a MEDGUIField to (un)selected according to a string (such as "all", "none", ...)
00482 //  If empty string, no change are made
00483 //  Else :
00484 //   First get the file and field id
00485 //   Then if statement is all, select all steps, set father to selected
00486 //   If statement is none, unselect all steps, if father get no more child selected, set father to unselected
00487 //   Else
00488 //    Remove all spaces from the string
00489 //    split the string using ";" char (";" means end of command)
00490 //     For each element, split the string with ":" ("a-b" means interval between a and b)
00491 //      If juste one element, select step with this id;
00492 //      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()
00493 //      Set field to selected
00494 //    Set file to selected
00495 void MEDGUIFileContentDial::selFromField(QTreeWidgetItem* qtwi, QString sel)
00496 {
00497   if(sel != QString("")){
00498 
00499     int lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent());
00500     int fieldInd = qtwi->parent()->indexOfChild(qtwi);
00501     std::string fieldName = litestructs[lsInd].getFieldName(fieldInd);
00502 
00503     if(sel == QString("all")){
00504       qtwi->setSelected(true);
00505       litestructs[lsInd].selectField(fieldName);
00506       qtwi->parent()->setSelected(true);
00507       for ( int i = 0; i < qtwi->childCount(); i += 1)
00508         {
00509            qtwi->child(i)->setSelected(true);
00510         }
00511 
00512     }else if(sel == QString("none")){
00513       qtwi->setSelected(false);
00514       litestructs[lsInd].unselectField(fieldName);
00515       bool stillselection=false;
00516       for ( int i = 0; i < qtwi->parent()->childCount(); i += 1)
00517       {
00518         if(qtwi->parent()->child(i)->isSelected()){
00519           stillselection = true;
00520           break;
00521         }
00522       }
00523       qtwi->parent()->setSelected(stillselection);
00524       for ( int i = 0; i < qtwi->childCount(); i += 1)
00525       {
00526         qtwi->child(i)->setSelected(false);
00527       }
00528 
00529     }else{
00530       if(sel.size()!=0){
00531         sel = sel.simplified();
00532         QStringList listSel = sel.split(" ");
00533         sel = listSel.join("");
00534 
00535         listSel = sel.split(";");
00536         for (int i = 0; i < listSel.size(); i += 1)
00537         {
00538           QStringList totreat = listSel[i].split(":");
00539 
00540           if(totreat[0].toInt() >= qtwi->childCount() || totreat[0].toInt() < 0 || (totreat.size() == 2 && ( totreat[1].toInt() >= qtwi->childCount() ))){
00541             std::ostringstream oss;
00542             oss << "Input value incorrect, should be between 0 and ";
00543             oss << qtwi->childCount()-1;
00544             oss << ".";
00545             QMessageBox::warning(this,"Incorrect Input Value",oss.str().c_str());
00546             return;
00547           }//  Check values
00548           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))){
00549             std::ostringstream oss;
00550             oss << "Input values incorrect (";
00551             oss << listSel[i].toStdString().c_str();
00552             oss << ").";
00553             QMessageBox::warning(this,"Incorrect Input Value",oss.str().c_str());
00554             return;
00555           }//  Check type (to filter non-int characters)
00556 
00557           if(totreat.size() == 1){
00558             litestructs[lsInd].getField(fieldName).selectStep(totreat[0].toInt());
00559             litestructs[lsInd].setSelected(true);
00560             qtwi->child(totreat[0].toInt())->setSelected(true);
00561 
00562           }else if(totreat.size() == 2){
00563             int max = qtwi->childCount()-1;
00564             if(totreat[1] != QString("")) max = totreat[1].toInt();
00565             if(max < totreat[0].toInt()){
00566               std::ostringstream oss;
00567               oss << "Input values incorrect (";
00568               oss << listSel[i].toStdString().c_str();
00569               oss << ").";
00570               QMessageBox::warning(this,"Incorrect Input Value",oss.str().c_str());
00571               return;
00572             }//  Check if interval is correct
00573             for (int j = totreat[0].toInt(); j <= max; j += 1)
00574             {
00575               litestructs[lsInd].getField(fieldName).selectStep(j);
00576               litestructs[lsInd].setSelected(true);
00577               qtwi->child(j)->setSelected(true);
00578             }
00579           }
00580         }
00581         qtwi->setSelected(true);
00582         qtwi->parent()->setSelected(true);
00583       }
00584     }
00585   }
00586 }
00587 
00588 //  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", ...)
00589 //  Calling it on a step is the same as calling it from is father (the corresponding field)
00590 void MEDGUIFileContentDial::selFromStep(QTreeWidgetItem* qtwi,QString sel)
00591 {
00592   selFromField(qtwi->parent(), sel);
00593 }
00594 
00595 //  Show the dialog for selecting components and changing components names
00596 //  Get the current QTreeWidgetItem
00597 //  If its a field or a step, get the field id
00598 //  Call MEDGUISelectComponent dial with the MEDGUILiteStruct and the field id (-1 if none)
00599 void MEDGUIFileContentDial::selCompoPopup(bool checkable)
00600 {
00601   QTreeWidgetItem* qtwi = ui->treeWidgetFields->currentItem();
00602   int lsInd=0;
00603   int fieldInd = -1;
00604   if(!qtwi->parent()) lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi);
00605   else if(!qtwi->parent()->parent()){
00606     lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent());
00607     fieldInd = qtwi->parent()->indexOfChild(qtwi);
00608   }
00609   else{
00610     lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent()->parent());
00611     fieldInd = qtwi->parent()->parent()->indexOfChild(qtwi->parent());
00612   }
00613 
00614   MEDGUISelectComponents selcomp(litestructs[lsInd], this, fieldInd);
00615   selcomp.exec();
00616 }
00617