Back to index

salome-med  6.5.0
Public Slots | Public Member Functions | Protected Member Functions | Private Attributes
MEDGUIFileContentDial Class Reference

#include <MEDGUIFileContentDial.h>

Collaboration diagram for MEDGUIFileContentDial:
Collaboration graph
[legend]

List of all members.

Public Slots

void openFile ()
void meshesStateChange (QTreeWidgetItem *, int)
void fieldsStateChange (QTreeWidgetItem *, int)
void fieldsStateChanges ()
void sendSelectionToDB ()
void unselectAll ()
void overfield (QTreeWidgetItem *, int)
void selCompoPopup (bool)
void selStepsPopup (bool)

Public Member Functions

 MEDGUIFileContentDial (MEDGUIDataBaseDockWidget *, QWidget *=0)
 ~MEDGUIFileContentDial ()

Protected Member Functions

void changeEvent (QEvent *e)
void selFromFile (QTreeWidgetItem *, QString)
void selFromField (QTreeWidgetItem *, QString)
void selFromStep (QTreeWidgetItem *, QString)

Private Attributes

Ui::MEDGUIFileContentDial * ui
MEDGUIDataBaseDockWidget_db
std::vector
< ParaMEDMEM::MEDCalculatorBrowserLiteStruct > 
litestructs
std::vector< QTreeWidgetItem * > coloredMeshes

Detailed Description

Definition at line 42 of file MEDGUIFileContentDial.h.


Constructor & Destructor Documentation

Definition at line 55 of file MEDGUIFileContentDial.cxx.

                                                                                         :
  QDialog(parent, 0), ui(new Ui::MEDGUIFileContentDial), _db(db)
{
  setModal( false );
  setSizeGripEnabled( true );
  setAttribute( Qt::WA_DeleteOnClose );

  QWidget* w = new QWidget( this );
  QHBoxLayout* l = new QHBoxLayout( this );
  l->setMargin( 0 );
  l->addWidget( w );
  ui->setupUi(w);

  connect(ui->importMedFileButton, SIGNAL(clicked()), this, SLOT(openFile()));
  connect(ui->addSelectionButton, SIGNAL(clicked()), this, SLOT(sendSelectionToDB()));
  connect(ui->unselectAllButton, SIGNAL(clicked()), this, SLOT(unselectAll()));
  connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close()));

  ui->treeWidgetFields->setHeaderLabel("Available Field");
  ui->treeWidgetFields->setSelectionMode(QAbstractItemView::MultiSelection);
  ui->treeWidgetMeshes->setHeaderLabel("Available Meshes");
  ui->treeWidgetMeshes->setSelectionMode(QAbstractItemView::MultiSelection);

  connect(ui->treeWidgetMeshes, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(meshesStateChange(QTreeWidgetItem*, int)));
  connect(ui->treeWidgetFields, SIGNAL(itemSelectionChanged()), this, SLOT(fieldsStateChanges()));
  //connect(ui->treeWidgetFields, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(fieldsStateChange(QTreeWidgetItem*, int)));

  ui->treeWidgetFields->setMouseTracking(true);
  connect(ui->treeWidgetFields,SIGNAL(itemEntered(QTreeWidgetItem*,int)), this, SLOT(overfield(QTreeWidgetItem*,int)));

  ui->treeWidgetFields->setContextMenuPolicy(Qt::ActionsContextMenu);
  QAction* selcompo = new QAction("Select components",ui->treeWidgetFields);
  QAction* selsteps = new QAction("Select steps",ui->treeWidgetFields);
  ui->treeWidgetFields->addAction(selcompo);
  ui->treeWidgetFields->addAction(selsteps);

  connect(selcompo,SIGNAL(triggered(bool)),this,SLOT(selCompoPopup(bool)));
  connect(selsteps,SIGNAL(triggered(bool)),this,SLOT(selStepsPopup(bool)));

}

Here is the call graph for this function:

Definition at line 97 of file MEDGUIFileContentDial.cxx.

{
  delete ui;
}

Member Function Documentation

void MEDGUIFileContentDial::changeEvent ( QEvent *  e) [protected]

Definition at line 103 of file MEDGUIFileContentDial.cxx.

{
  QWidget::changeEvent(e);
  switch (e->type())
  {
    case QEvent::LanguageChange:
      ui->retranslateUi(this);
    break;
  default:
    break;
  }
}
void MEDGUIFileContentDial::fieldsStateChange ( QTreeWidgetItem *  qtwi,
int  col 
) [slot]

Definition at line 221 of file MEDGUIFileContentDial.cxx.

{
  QTreeWidgetItem *father = qtwi->parent();
  if(!father)
    {//  File
      if(qtwi->isSelected())
        {
          litestructs[ui->treeWidgetFields->indexOfTopLevelItem(qtwi)].selectAllFields();
          for ( int i = 0; i < qtwi->childCount(); i += 1)
            {
              qtwi->child(i)->setSelected(true);
              for ( int j = 0; j < qtwi->child(i)->childCount(); j += 1)
                qtwi->child(i)->child(j)->setSelected(true);
            }
        }
      else
        {
          litestructs[ui->treeWidgetFields->indexOfTopLevelItem(qtwi)].unselectAllFields();
          for ( int i = 0; i < qtwi->childCount(); i += 1)
            {
              qtwi->child(i)->setSelected(false);
              for ( int j = 0; j < qtwi->child(i)->childCount(); j += 1)
                qtwi->child(i)->child(j)->setSelected(false);
            }
        }
    }
  else if(!father->parent())
    {//  Field
      int lsInd = ui->treeWidgetFields->indexOfTopLevelItem(father);
      int fieldInd = father->indexOfChild(qtwi);
      std::string fieldName = litestructs[lsInd].getFieldName(fieldInd);
      if(qtwi->isSelected())
        {
          litestructs[lsInd].selectField(fieldName);
          //father->setSelected(true);
          for ( int i = 0; i < qtwi->childCount(); i += 1)
            {
              qtwi->child(i)->setSelected(true);
            }
        }
      else
        {
          litestructs[lsInd].unselectField(fieldName);
          bool stillselection=false;
          for ( int i = 0; i < father->childCount(); i += 1)
            {
              if(father->child(i)->isSelected())
                {
                  stillselection = true;
                  break;
                }
            }
          //father->setSelected(stillselection);
          for ( int i = 0; i < qtwi->childCount(); i += 1)
            {
              qtwi->child(i)->setSelected(false);
            }
        }
    }
  else
    {//  Step
      int lsInd = ui->treeWidgetFields->indexOfTopLevelItem(father->parent());
      int fieldInd = father->parent()->indexOfChild(father);
      int stepInd = father->indexOfChild(qtwi);
      std::string fieldName = litestructs[lsInd].getFieldName(fieldInd);
      if(qtwi->isSelected())
        {
          litestructs[lsInd].getField(fieldName).selectStep(stepInd);
          litestructs[lsInd].setSelected(true);
          //father->setSelected(true);
          //father->parent()->setSelected(true);
        }
      else
        {
          litestructs[lsInd].getField(fieldName).unselectStep(stepInd);
          bool stillselection=false;
          for ( int i = 0; i < father->childCount(); i += 1)
            {
              if(father->child(i)->isSelected())
                {
                  stillselection = true;
                  break;
                }
            }
          father->setSelected(stillselection);
          stillselection=false;
          for ( int i = 0; i < father->parent()->childCount(); i += 1)
            {
              if(father->parent()->child(i)->isSelected())
                {
                  stillselection = true;
                  break;
                }
            }
          father->parent()->setSelected(stillselection);
          litestructs[lsInd].setSelected(stillselection);
        }
    }
}

Here is the caller graph for this function:

Definition at line 207 of file MEDGUIFileContentDial.cxx.

{
  disconnect(ui->treeWidgetFields, SIGNAL(itemSelectionChanged()), this, SLOT(fieldsStateChanges()));
  unselectAll();
  QList<QTreeWidgetItem *> l=ui->treeWidgetFields->selectedItems();
  for(QList<QTreeWidgetItem *>::iterator it=l.begin();it!=l.end();it++)
    fieldsStateChange(*it,0);
  connect(ui->treeWidgetFields, SIGNAL(itemSelectionChanged()), this, SLOT(fieldsStateChanges()));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MEDGUIFileContentDial::meshesStateChange ( QTreeWidgetItem *  qtwi,
int  col 
) [slot]

Definition at line 168 of file MEDGUIFileContentDial.cxx.

{
  QTreeWidgetItem *father = qtwi->parent();
  if(!father){
    if (qtwi->isSelected())
    {
      litestructs[ui->treeWidgetMeshes->indexOfTopLevelItem(qtwi)].selectAllMeshes();
      for ( int i = 0; i < qtwi->childCount(); i += 1)
      {
        qtwi->child(i)->setSelected(true);
      }
    }else{
      litestructs[ui->treeWidgetMeshes->indexOfTopLevelItem(qtwi)].unselectAllMeshes();
      for ( int i = 0; i < qtwi->childCount(); i += 1)
      {
        qtwi->child(i)->setSelected(false);
      }
    }
  }else{
    int lsInd =ui->treeWidgetMeshes->indexOfTopLevelItem(father);
    if (qtwi->isSelected())
    {
      litestructs[lsInd].selectMesh(litestructs[lsInd].getMeshName(father->indexOfChild(qtwi)));
      father->setSelected(true);
    }else{
      litestructs[lsInd].unselectMesh(litestructs[lsInd].getMeshName(father->indexOfChild(qtwi)));
      bool stillselection=false;
      for ( int i = 0; i < father->childCount(); i += 1)
      {
        if(father->child(i)->isSelected()){
          stillselection = true;
          break;
        }
      }
      father->setSelected(stillselection);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 124 of file MEDGUIFileContentDial.cxx.

{
  QString fileName = QFileDialog::getOpenFileName(this,tr("Open Med File"),QDir::homePath(),tr("Med File (*.med)"));
  if(fileName != QString("")){
    QString realname = fileName.split("/").last();

    int i = 2;
    std::string name = realname.toStdString();
    while(std::find(litestructs.begin(),litestructs.end(),name) != litestructs.end())
    {
      std::ostringstream oss;
      oss << realname.toStdString() << "_" << i++ ;
      name = oss.str();
    }

    ParaMEDMEM::MEDCalculatorBrowserLiteStruct ls(fileName.toStdString().c_str());
    litestructs.push_back(ls);

    QTreeWidgetItem* root = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str())));
    for (unsigned int i = 0; i < ls.getNumberOfFields(); i += 1)
    {
      QTreeWidgetItem* fieldname = new QTreeWidgetItem(root,QStringList(QString(tr(ls.getFieldName(i).c_str()))));
      ParaMEDMEM::MEDCalculatorBrowserField field = ls.getField(i);
      for (unsigned int j = 0; j < field.getStepsSize(); j += 1)
      {
        std::ostringstream input;
        input<<field.getSteps()[j].getTimeStep()<<" ( "<<field.getSteps()[j].getTimeValue()<<" )";
        new QTreeWidgetItem(fieldname,QStringList(QString(tr(input.str().c_str()))));
      }
    }
    ui->treeWidgetFields->addTopLevelItem(root);

    QTreeWidgetItem* root_2 = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str())));
    for (unsigned int i = 0; i < ls.getNumberOfMeshes(); i += 1)
    {
      new QTreeWidgetItem(root_2,QStringList(QString(tr(ls.getMeshName(i).c_str()))));
    }
    ui->treeWidgetMeshes->addTopLevelItem(root_2);
  }
}

Here is the caller graph for this function:

void MEDGUIFileContentDial::overfield ( QTreeWidgetItem *  qtwi,
int  col 
) [slot]

Definition at line 366 of file MEDGUIFileContentDial.cxx.

{

  for (unsigned int i = 0; i < coloredMeshes.size(); i += 1)
  {
    coloredMeshes[i]->setForeground(0,QBrush(Qt::black));
  }
  coloredMeshes = std::vector<QTreeWidgetItem*>();

  int lsInd = -1;
  if(qtwi->parent()){
    if(qtwi->parent()->parent()) lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent()->parent());
    else  lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent());
  }else lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi);

  std::vector<std::string> meshesNames;
  if(qtwi->parent()){
    if(qtwi->childCount()) meshesNames = litestructs[lsInd].getCorrespondingMeshesFromField(qtwi->parent()->indexOfChild(qtwi));
    else meshesNames.push_back(litestructs[lsInd].getField(qtwi->parent()->parent()->indexOfChild(qtwi->parent())).getCorrespondingMeshFromStep(qtwi->parent()->indexOfChild(qtwi)));
  }else meshesNames = litestructs[lsInd].getCorrespondingMeshesFromLS();

  QTreeWidgetItem *lsroot;
  for ( int i = 0; i < ui->treeWidgetMeshes->topLevelItemCount(); i += 1)
  {
    if(ui->treeWidgetMeshes->topLevelItem(i)->text(0).toStdString() == litestructs[lsInd].getName())
      lsroot = ui->treeWidgetMeshes->topLevelItem(i);
  }

  for ( int i = 0; i < lsroot->childCount(); i += 1)
  {
    if(std::find(meshesNames.begin(),meshesNames.end(),lsroot->child(i)->text(0).toStdString()) != meshesNames.end()){
      lsroot->child(i)->setForeground(0,QBrush(Qt::red));
      coloredMeshes.push_back(lsroot->child(i));
    }
  }
}

Here is the caller graph for this function:

void MEDGUIFileContentDial::selCompoPopup ( bool  checkable) [slot]

Definition at line 599 of file MEDGUIFileContentDial.cxx.

{
  QTreeWidgetItem* qtwi = ui->treeWidgetFields->currentItem();
  int lsInd=0;
  int fieldInd = -1;
  if(!qtwi->parent()) lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi);
  else if(!qtwi->parent()->parent()){
    lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent());
    fieldInd = qtwi->parent()->indexOfChild(qtwi);
  }
  else{
    lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent()->parent());
    fieldInd = qtwi->parent()->parent()->indexOfChild(qtwi->parent());
  }

  MEDGUISelectComponents selcomp(litestructs[lsInd], this, fieldInd);
  selcomp.exec();
}

Here is the caller graph for this function:

void MEDGUIFileContentDial::selFromField ( QTreeWidgetItem *  qtwi,
QString  sel 
) [protected]

Definition at line 495 of file MEDGUIFileContentDial.cxx.

{
  if(sel != QString("")){

    int lsInd = ui->treeWidgetFields->indexOfTopLevelItem(qtwi->parent());
    int fieldInd = qtwi->parent()->indexOfChild(qtwi);
    std::string fieldName = litestructs[lsInd].getFieldName(fieldInd);

    if(sel == QString("all")){
      qtwi->setSelected(true);
      litestructs[lsInd].selectField(fieldName);
      qtwi->parent()->setSelected(true);
      for ( int i = 0; i < qtwi->childCount(); i += 1)
        {
           qtwi->child(i)->setSelected(true);
        }

    }else if(sel == QString("none")){
      qtwi->setSelected(false);
      litestructs[lsInd].unselectField(fieldName);
      bool stillselection=false;
      for ( int i = 0; i < qtwi->parent()->childCount(); i += 1)
      {
        if(qtwi->parent()->child(i)->isSelected()){
          stillselection = true;
          break;
        }
      }
      qtwi->parent()->setSelected(stillselection);
      for ( int i = 0; i < qtwi->childCount(); i += 1)
      {
        qtwi->child(i)->setSelected(false);
      }

    }else{
      if(sel.size()!=0){
        sel = sel.simplified();
        QStringList listSel = sel.split(" ");
        sel = listSel.join("");

        listSel = sel.split(";");
        for (int i = 0; i < listSel.size(); i += 1)
        {
          QStringList totreat = listSel[i].split(":");

          if(totreat[0].toInt() >= qtwi->childCount() || totreat[0].toInt() < 0 || (totreat.size() == 2 && ( totreat[1].toInt() >= qtwi->childCount() ))){
            std::ostringstream oss;
            oss << "Input value incorrect, should be between 0 and ";
            oss << qtwi->childCount()-1;
            oss << ".";
            QMessageBox::warning(this,"Incorrect Input Value",oss.str().c_str());
            return;
          }//  Check values
          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))){
            std::ostringstream oss;
            oss << "Input values incorrect (";
            oss << listSel[i].toStdString().c_str();
            oss << ").";
            QMessageBox::warning(this,"Incorrect Input Value",oss.str().c_str());
            return;
          }//  Check type (to filter non-int characters)

          if(totreat.size() == 1){
            litestructs[lsInd].getField(fieldName).selectStep(totreat[0].toInt());
            litestructs[lsInd].setSelected(true);
            qtwi->child(totreat[0].toInt())->setSelected(true);

          }else if(totreat.size() == 2){
            int max = qtwi->childCount()-1;
            if(totreat[1] != QString("")) max = totreat[1].toInt();
            if(max < totreat[0].toInt()){
              std::ostringstream oss;
              oss << "Input values incorrect (";
              oss << listSel[i].toStdString().c_str();
              oss << ").";
              QMessageBox::warning(this,"Incorrect Input Value",oss.str().c_str());
              return;
            }//  Check if interval is correct
            for (int j = totreat[0].toInt(); j <= max; j += 1)
            {
              litestructs[lsInd].getField(fieldName).selectStep(j);
              litestructs[lsInd].setSelected(true);
              qtwi->child(j)->setSelected(true);
            }
          }
        }
        qtwi->setSelected(true);
        qtwi->parent()->setSelected(true);
      }
    }
  }
}

Here is the caller graph for this function:

void MEDGUIFileContentDial::selFromFile ( QTreeWidgetItem *  qtwi,
QString  sel 
) [protected]

Definition at line 447 of file MEDGUIFileContentDial.cxx.

{
  if(sel != QString("")){
    if(sel == QString("all")){
      qtwi->setSelected(true);
      litestructs[ui->treeWidgetFields->indexOfTopLevelItem(qtwi)].selectAllFields();
      for ( int i = 0; i < qtwi->childCount(); i += 1)
      {
        qtwi->child(i)->setSelected(true);
        for ( int j = 0; j < qtwi->child(i)->childCount(); j += 1)
        {
          qtwi->child(i)->child(j)->setSelected(true);
        }
      }
    }else if(sel == QString("none")){
      qtwi->setSelected(false);
      litestructs[ui->treeWidgetFields->indexOfTopLevelItem(qtwi)].unselectAllFields();
      for ( int i = 0; i < qtwi->childCount(); i += 1)
      {
        qtwi->child(i)->setSelected(false);
        for ( int j = 0; j < qtwi->child(i)->childCount(); j += 1)
        {
          qtwi->child(i)->child(j)->setSelected(false);
        }
      }
    }else{
        for ( int j = 0; j < qtwi->childCount(); j += 1)
        {
          selFromField(qtwi->child(j),sel);
        }
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MEDGUIFileContentDial::selFromStep ( QTreeWidgetItem *  qtwi,
QString  sel 
) [protected]

Definition at line 590 of file MEDGUIFileContentDial.cxx.

{
  selFromField(qtwi->parent(), sel);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MEDGUIFileContentDial::selStepsPopup ( bool  checkable) [slot]

Definition at line 410 of file MEDGUIFileContentDial.cxx.

{

  QTreeWidgetItem* qtwi = ui->treeWidgetFields->currentItem();

  QDialog *qd = new QDialog(this,Qt::ToolTip);
  QLineEdit *ql = new QLineEdit(qd);

  connect(ql,SIGNAL(editingFinished()),qd,SLOT(close()));

  qd->resize(120,20);
  qd->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);

  QRect currentItemRec = ui->treeWidgetFields->visualItemRect(qtwi);
  QPoint topLeft = currentItemRec.topLeft();
  QPoint realPos = ui->treeWidgetFields->mapToGlobal(topLeft);

  qd->move(realPos);

  qd->exec();

  QString sel = ql->text();
  if(ql) delete ql;
  if(qd) delete qd;

  if(!qtwi->parent()) selFromFile(qtwi,sel);
  else if(!qtwi->parent()->parent()) selFromField(qtwi,sel);
  else selFromStep(qtwi,sel);

}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 322 of file MEDGUIFileContentDial.cxx.

{
  std::vector<ParaMEDMEM::MEDCalculatorBrowserLiteStruct> lt2send2db;
  for (unsigned int i=0;i<litestructs.size();i++)
    {
      unsigned int nbOfFiels=litestructs[i].getNumberOfFields();
      const ParaMEDMEM::MEDCalculatorBrowserLiteStruct& myStruct=litestructs[i];
      for(unsigned int j=0;j<nbOfFiels;j++)
        {
          if(myStruct.getField(j).isAnySelection())
            try
              {
                //lt2send2db.push_back(myStruct.getField(j).getSelectedTimeSteps());
              }
            catch(INTERP_KERNEL::Exception& e)
              {
              }
        }
    }
  _db->appendFieldLT(lt2send2db);
  /*std::cout<<"Current Selection"<<std::endl;
  for (unsigned int i = 0; i < litestructs.size(); i += 1)
  {
    std::cout<<"Lite Struct n°"<<i<<std::endl;
    std::cout<<litestructs[i].str()<<std::endl;
    std::cout<<"--------------------------------"<<std::endl;
    }*/
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 352 of file MEDGUIFileContentDial.cxx.

{
   for (unsigned int i = 0; i < litestructs.size(); i += 1)
      {
        litestructs[i].unselectAll();
      }
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 68 of file MEDGUIFileContentDial.h.

std::vector<QTreeWidgetItem*> MEDGUIFileContentDial::coloredMeshes [private]

Definition at line 70 of file MEDGUIFileContentDial.h.

std::vector<ParaMEDMEM::MEDCalculatorBrowserLiteStruct> MEDGUIFileContentDial::litestructs [private]

Definition at line 69 of file MEDGUIFileContentDial.h.

Ui::MEDGUIFileContentDial* MEDGUIFileContentDial::ui [private]

Definition at line 67 of file MEDGUIFileContentDial.h.


The documentation for this class was generated from the following files: