Changeset 112 in PSPA for Interface_Web/trunk


Ignore:
Timestamp:
Nov 28, 2012, 4:24:04 PM (12 years ago)
Author:
touze
Message:

classe compteur pour creer les etiquettes

Location:
Interface_Web/trunk/pspaWT/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • Interface_Web/trunk/pspaWT/src/GWt_LigneFaisceau.cc

    r106 r112  
     1
     2#include <iostream>
    13
    24#include "GWt_LigneFaisceau.h"
     
    68#include "GWt_soleno.h"
    79#include "GWt_bend.h"
    8 #include <iostream>
    9 #include "nomdElements.h"
    10 
    1110
    1211#include <Wt/WComboBox>
    1312#include <Wt/WVBoxLayout>
    14 
    1513
    1614GWt_LigneFaisceau::GWt_LigneFaisceau(PspaApplication* ps) : pspa_(ps)
     
    1917  decorationStyle().setBackgroundColor (WColor("orange"));
    2018  setLayout(beamLayout_);
     19
     20  int k;
     21  for(k = 0; k < nElements; k++) nObjets_[k]= new Compteur();
    2122
    2223  acceptDrops("icons/beam.jpg");
     
    3637      abstractElement* newDrift = pspa_->getDataManager()->addElement(drift);
    3738      GWt_drift* gdrift = new GWt_drift(pspa_,newDrift, evt.mimeType());
     39      gdrift->setLabel(nObjets_[drift]->incr());
    3840      wc= gdrift->getWidget();
    3941    }
     
    4345      abstractElement* newInitialBeam = pspa_->getDataManager()->addElement(initialBeam);
    4446      GWt_initialBeam* gwInitialBeam = new GWt_initialBeam(pspa_,newInitialBeam, evt.mimeType());
     47      gwInitialBeam->setLabel(nObjets_[initialBeam]->incr());
    4548      wc= gwInitialBeam->getWidget();
    4649    }
     
    5053      abstractElement* newCell = pspa_->getDataManager()->addElement(cell);
    5154      GWt_cell* gwCell = new GWt_cell(pspa_,newCell, evt.mimeType());
     55      gwCell->setLabel(nObjets_[cell]->incr());
    5256      wc= gwCell->getWidget();
    5357    }
     
    5761      abstractElement* newSoleno = pspa_->getDataManager()->addElement(soleno);
    5862      GWt_soleno* gwSoleno = new GWt_soleno(pspa_,newSoleno, evt.mimeType());
     63      gwSoleno->setLabel(nObjets_[soleno]->incr());
    5964      wc= gwSoleno->getWidget();
    6065    }
     
    6469      abstractElement* newBend = pspa_->getDataManager()->addElement(bend);
    6570      GWt_bend* gwBend = new GWt_bend(pspa_,newBend, evt.mimeType());
     71      gwBend->setLabel(nObjets_[bend]->incr());
    6672      wc= gwBend->getWidget();
    6773    }
     
    7682  // pourVoir
    7783  int nElts= pspa_->getDataManager()->beamLineSize();
    78   cout << "pourVoir:: nElts= " << nElts << endl;
     84  cout << "GWt_LigneFaisceau:: nElts= " << nElts << endl;
    7985  unsigned int k;
    8086  for(k = 0; k < (unsigned)nElts; k++) {
    8187    abstractElement* ptr= pspa_->getDataManager()->getCollection()->getElementPointer(k);
    8288    string label= ptr->getLabel();
    83     cout << "pourVoir:: " << label << " a été ajouté" << endl;
     89    cout << "GWt_LigneFaisceau:: " << label << " dans la liste" << endl;
    8490  }
    8591
     
    8894void GWt_LigneFaisceau::restoreElementCollection()
    8995{
     96  beamLayout_->clear();
     97  unsigned int k;
     98  for(k = 0; k < nElements; k++) delete nObjets_[k];
     99  for(k = 0; k < nElements; k++) nObjets_[k]= new Compteur();
    90100  int nbElem = pspa_->getDataManager()->beamLineSize();
    91   unsigned int k;
    92   beamLayout_->clear();
    93   for ( k=0; k < (unsigned)nbElem; k++)
    94     {     
    95       abstractElement* ptr = pspa_->getDataManager()->getCollection()->getElementPointer(k);
    96       nomdElement nom = ptr->getName();
    97       switch (nom)
    98         {
    99         case initialBeam :
    100           {
    101             GWt_initialBeam* gwInitialBeam = new GWt_initialBeam(pspa_,ptr, string("icons/beam.jpg"));
    102             beamLayout_->addWidget(gwInitialBeam->getButton());
    103             break;
    104           }
    105         case drift :
    106           {
    107             GWt_drift* gdrift = new GWt_drift(pspa_,ptr, string("icons/drift.jpg"));     
    108             beamLayout_->addWidget(gdrift->getButton());
    109             break;
    110           }
    111         case cell :
    112           {
    113               GWt_cell* gwCell = new GWt_cell(pspa_,ptr, string("icons/cell.jpg"));
    114               beamLayout_->addWidget(gwCell->getButton());
    115               break;
    116           }
    117 
    118         case soleno :
    119           {
    120               GWt_soleno* gwSoleno = new GWt_soleno(pspa_,ptr, string("icons/lens.jpg"));
    121               beamLayout_->addWidget(gwSoleno->getButton());
    122               break;
    123           }
    124         case bend :
    125           {
    126               GWt_bend* gwBend = new GWt_bend(pspa_,ptr, string("icons/bend.jpg"));
    127               beamLayout_->addWidget(gwBend->getButton());
    128               break;
    129           }
    130         default :
    131           {
    132             cerr << "  GWt_LigneFaisceau element type " << nom << " inconnu " << endl;
    133             break;
    134           }
    135      }
    136 
    137     }
    138 
     101 
     102  for(k = 0; k < (unsigned)nbElem; k++) {     
     103    abstractElement* ptr = pspa_->getDataManager()->getCollection()->getElementPointer(k);
     104    nomdElement nom = ptr->getName();
     105    switch (nom) {
     106    case initialBeam :
     107      {
     108        GWt_initialBeam* gw = new GWt_initialBeam(pspa_,ptr,string("icons/beam.jpg"));
     109        gw->setLabel(nObjets_[initialBeam]->incr());
     110        beamLayout_->addWidget(gw->getWidget());
     111        break;
     112      }
     113    case drift :
     114      {
     115        GWt_drift* gw = new GWt_drift(pspa_,ptr,string("icons/drift.jpg"));
     116        gw->setLabel(nObjets_[drift]->incr());
     117        beamLayout_->addWidget(gw->getWidget());
     118        break;
     119      }
     120    case cell :
     121      {
     122        GWt_cell* gw = new GWt_cell(pspa_,ptr,string("icons/cell.jpg"));
     123        gw->setLabel(nObjets_[cell]->incr());
     124        beamLayout_->addWidget(gw->getWidget());
     125        break;
     126      }
     127    case soleno :
     128      {
     129        GWt_soleno* gw = new GWt_soleno(pspa_,ptr,string("icons/lens.jpg"));
     130        gw->setLabel(nObjets_[soleno]->incr());
     131        beamLayout_->addWidget(gw->getWidget());
     132        break;
     133      }
     134    case bend :
     135      {
     136        GWt_bend* gw = new GWt_bend(pspa_,ptr,string("icons/bend.jpg"));
     137        gw->setLabel(nObjets_[bend]->incr());
     138        beamLayout_->addWidget(gw->getWidget());
     139        break;
     140      }
     141    default :
     142      {
     143        cerr << "GWt_LigneFaisceau::restaure element type " << nom << " inconnu " << endl;
     144        break;
     145      }
     146    }   
     147  }
    139148}
  • Interface_Web/trunk/pspaWT/src/GWt_abstractElement.cc

    r106 r112  
    66GWt_abstractElement::GWt_abstractElement(PspaApplication* ps,abstractElement* elem,string image)
    77{
     8  cout << "GWt_abstractElement::GWt_abstractElement()" << endl;
     9
    810  pspa_ = ps;
    911  pspa_->updateSelections();
     
    2325}
    2426
    25 void GWt_abstractElement::setLabel(abstractElement* elem,int n)
     27void GWt_abstractElement::setLabel(int n)
    2628{
    2729  string str;
    2830  if(n < 10) {
    29     str= elem->getNameOfElement()+"0"+mixedTools::intToString(n);
     31    str= element_->getNameOfElement()+"0"+mixedTools::intToString(n);
    3032  } else {
    31     str= elem->getNameOfElement()+mixedTools::intToString(n);
     33    str= element_->getNameOfElement()+mixedTools::intToString(n);
    3234  }
    33   cout << "GWt_abstractElement::label= " << str << endl;
     35  cout << "2-GWt_abstractElement::label= " << str << endl;
    3436
    35   elem->setLabel(str);
     37  element_->setLabel(str);
    3638
    3739  WText *item = new WText(str);
     
    5254  cout << "GWt_abstractElement:: " << label << " a été supprimé" << endl;
    5355  pspa_->getDataManager()->getCollection()->eraseElement(label);
    54  
     56  pspa_->updateSelections(); 
    5557}
    5658
  • Interface_Web/trunk/pspaWT/src/GWt_bend.cc

    r106 r112  
    88#include <Wt/WPushButton>
    99
    10 int GWt_bend::nObjets_= 0;
    11 
    1210GWt_bend::GWt_bend(PspaApplication* ps,abstractElement* elem,string image) : GWt_abstractElement(ps,elem,image)
    1311{
    14   nObjets_++;
    15   setLabel(elem,nObjets_);
    16 
    1712  string* param = element_-> getParametersString();
    1813  if ( param == NULL )
  • Interface_Web/trunk/pspaWT/src/GWt_cell.cc

    r106 r112  
    99#include <Wt/WPanel>
    1010
    11 int GWt_cell::nObjets_= 0;
    12 
    1311GWt_cell::GWt_cell(PspaApplication* ps,abstractElement* elem,string image) : GWt_abstractElement(ps,elem,image)
    1412{
    15   nObjets_++;
    16   setLabel(elem,nObjets_);
    17 
    1813  string* param = element_-> getParametersString();
    1914  if ( param == NULL ) {
  • Interface_Web/trunk/pspaWT/src/GWt_drift.cc

    r106 r112  
    88#include <Wt/WPushButton>
    99
    10 int GWt_drift::nObjets_= 0;
    11 
    1210GWt_drift::GWt_drift(PspaApplication* ps,abstractElement* elem,string image) : GWt_abstractElement(ps,elem,image)
    1311{
    14   nObjets_++;
    15   setLabel(elem,nObjets_);
    16   //string str = elem->getNameOfElement()+mixedTools::intToString(nObjets_);
    17   //cout << "GWt_drift::label= " << str << endl;
    18   //WText *item = new WText(str);
    19   //wc_->addWidget(item);
    20 
    2112  string* param = element_-> getParametersString();
    2213  if ( param == NULL )
  • Interface_Web/trunk/pspaWT/src/GWt_initialBeam.cc

    r106 r112  
    77#include <Wt/WPushButton>
    88
    9 int GWt_initialBeam::nObjets_= 0;
    10 
    119GWt_initialBeam::GWt_initialBeam(PspaApplication* ps,abstractElement* elem,string image) : GWt_abstractElement(ps,elem,image)
    1210{
    13   nObjets_++;
    14   setLabel(elem,nObjets_);
    15 
    1611  string* param = element_-> getParametersString();
    1712  if ( param == NULL )
  • Interface_Web/trunk/pspaWT/src/GWt_pspaApplication.cc

    r111 r112  
    156156WWidget* PspaApplication::createExecuteWidget()
    157157{
     158  cout << "PspaApplication::createExecuteWidget()" << endl;
     159
    158160  WContainerWidget* executeW = new WContainerWidget();
    159161  executeW->setMaximumSize(600,150);
     
    165167  exec_go_->setDisabled(true);
    166168  exec_go_->clicked().connect(this, &PspaApplication::executer);
     169
    167170  // preparation du bouton add
    168171  WPushButton* exec_add = new WPushButton("add");
     
    186189  panelLogiciels->setTitle(" sections of beam Line for executing softwares ");
    187190
    188   contenuSections_ = new WContainerWidget();
    189  
    190   contenuSections_->addWidget( exec_add);
    191   contenuSections_->addWidget( exec_delete);
    192   contenuSections_->addWidget( exec_ok);
     191  contenuSections_ = new WContainerWidget(); 
     192  contenuSections_->addWidget(exec_add);
     193  contenuSections_->addWidget(exec_delete);
     194  contenuSections_->addWidget(exec_ok);
    193195  contenuSections_->addWidget(exec_go_);
    194196  contenuSections_->addWidget(probleme_);
     
    203205void PspaApplication::addSectionToExecuteW()
    204206{
    205   unsigned k;
     207  cout << "PspaApplication::addSectionToExecute() : " << selectedSections_.size() << endl;
     208
     209  disableSectionExecute();
     210
    206211  string premierText, dernierText;
    207 
    208   disableSectionExecute();
    209 
    210 
    211   if ( selectedSections_.size() == 0)
     212  if(selectedSections_.size() == 0)
    212213    {
    213214      premierText = "1";
     
    230231        }
    231232    }
    232 
     233 
     234  cout << "PspaApplication::addSectionToExecute() : " << premierText << ",à  " << dernierText << endl;
    233235
    234236  WContainerWidget* newSection = new WContainerWidget;
     
    238240  selectedSections_.back()->debut->setDisabled(true);
    239241  selectedSections_.back()->debut->setText(premierText);
    240 
    241242  selectedSections_.back()->fin = new WLineEdit();
    242   selectedSections_.back()->fin->changed().connect(this, &PspaApplication::disableSectionExecute);
    243 
     243  selectedSections_.back()->fin->changed().connect(this,&PspaApplication::disableSectionExecute);
    244244  selectedSections_.back()->fin->setText(dernierText);
    245245  selectedSections_.back()->selection = new WComboBox();
    246 
    247246  selectedSections_.back()->ligneDeWidget = newSection;
    248 
    249 
    250   // contenuSections_->addWidget(new WText(" from : "));
    251   // contenuSections_->addWidget(selectedSections_.back()->debut);
    252   // contenuSections_->addWidget(new WText(" to : "));
    253   // contenuSections_->addWidget(selectedSections_.back()->fin);
    254   // contenuSections_->addWidget(selectedSections_.back()->selection);
    255 
    256   //  newSection->addWidget(new WBreak());
    257247  newSection->addWidget(new WText(" from : "));
    258248  newSection->addWidget(selectedSections_.back()->debut);
     
    261251  newSection->addWidget(selectedSections_.back()->selection);
    262252
    263 
    264     contenuSections_->addWidget(newSection);
    265 
    266 
     253  contenuSections_->addWidget(newSection);
    267254  unsigned nb = nomDeLogiciel::getNumberOfSoftwares();
    268   for ( k=0; k < nb; k++) selectedSections_.back()->selection->addItem( nomDeLogiciel(k).getString() );
     255  unsigned k;
     256  for(k = 0; k < nb; k++) {
     257    selectedSections_.back()->selection->addItem(nomDeLogiciel(k).getString());
     258  }
    269259}
    270260
    271261void PspaApplication::disableSectionExecute()
    272262{
    273     exec_go_->setDisabled(true);
     263  exec_go_->setDisabled(true);
    274264}
    275265
     
    291281  currentString = mixedTools::intToString(current);
    292282   
    293 
    294283  // traitement des suivantes (on avance d'un cran dans la liste)
    295284  list<GWt_sectionToExecute*>::iterator itr, itr0;
    296   itr0= selectedSections_.begin();
     285  itr0 = selectedSections_.begin();
    297286  itr0++;
    298   for (itr= itr0; itr != selectedSections_.end(); itr++)
    299     {
    300       //      string debString = (*itr)->debut->text().toUTF8();
     287  for (itr = itr0; itr != selectedSections_.end(); itr++)
     288    {
    301289      // debut
    302       (*itr)->debut->setText(  currentString );
     290      (*itr)->debut->setText(currentString);
    303291      // fin
    304292      string finString =  (*itr)->fin->text().toUTF8();
    305293      if ( atoi(finString.c_str() ) < current)
    306294        {
    307           (*itr)->fin->setText(  currentString );
     295          (*itr)->fin->setText(currentString);
    308296        }
    309297
     
    314302      currentString = mixedTools::intToString(current);
    315303    }
     304
    316305  if (!areDataCoherent()) probleme_->setHidden(false);
    317306  else
     
    321310    }
    322311}
     312
    323313bool PspaApplication::areDataCoherent()
    324314{
    325 
    326   bool caMarche=true;
    327   int debut, fin;
    328   nomDeLogiciel prog;
    329 
     315  bool caMarche = true;
    330316  dtmanage_->initializeExecution();
     317 
    331318  list<GWt_sectionToExecute*>::iterator itr;
    332   for (itr= selectedSections_.begin(); itr != selectedSections_.end(); itr++)
     319  for(itr = selectedSections_.begin(); itr != selectedSections_.end(); itr++)
    333320    {
    334321      string debString = (*itr)->debut->text().toUTF8();
    335322      string finString = (*itr)->fin->text().toUTF8();
    336       debut = atoi( debString.c_str()  );
    337       fin = atoi(  finString.c_str() );
    338       prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
    339       dtmanage_->addSectionToExecute(debut, fin, prog);
    340     }
     323      int debut = atoi(debString.c_str());
     324      int fin = atoi(finString.c_str());
     325      nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
     326      dtmanage_->addSectionToExecute(debut,fin,prog);
     327    }
     328
    341329  string diagnostic = dtmanage_->checkExecute();
    342330  if ( !diagnostic.empty() )
     
    346334    }
    347335
    348 
    349 
    350   // int debut, fin;
    351   // nomDeLogiciel prog;
    352   // list<GWt_sectionToExecute*>::iterator itr;
    353   // for (itr= selectedSections_.begin(); itr != selectedSections_.end(); itr++)
    354   //   {
    355   //     string debString = (*itr)->debut->text().toUTF8();
    356   //     string finString = (*itr)->fin->text().toUTF8();
    357   //     debut = atoi( debString.c_str()  );
    358   //     fin = atoi(  finString.c_str() );
    359   //     prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
    360   //    if ( prog == nomDeLogiciel::parmela )
    361   //      {
    362   //      }
    363   //    else if ( prog == nomDeLogiciel::transport )
    364   //      {
    365   //        string diagnostic = dtmanage_->checkExecuteTransport( debut, fin);
    366   //        if ( !diagnostic.empty() )
    367   //          {
    368   //            caMarche = false;       
    369   //            addConsoleMessage(diagnostic.c_str());
    370   //          }
    371   //      }
    372   //    else
    373   //      {
    374   //        caMarche = false;   
    375   //        addConsoleMessage(" unknown software -- STOP  ");
    376   //      }
    377   //   }
    378336  return caMarche;
    379        
    380337}
    381338
     
    389346}
    390347
    391 
    392 
    393 
    394348void PspaApplication::executer()
    395349{
     
    397351  static_cast<GWt_globalParameters*>(globalParam_)->updateGlobals();
    398352
    399   // int debut, fin;
    400   // nomDeLogiciel prog;
    401   // //  dtmanage_->clearSectionToExecute();
    402   // dtmanage_->initializeExecution();
    403   // list<GWt_sectionToExecute*>::iterator itr;
    404   // for (itr= selectedSections_.begin(); itr != selectedSections_.end(); itr++)
    405   //   {
    406   //     string debString = (*itr)->debut->text().toUTF8();
    407   //     string finString = (*itr)->fin->text().toUTF8();
    408   //     debut = atoi( debString.c_str()  );
    409   //     fin = atoi(  finString.c_str() );
    410   //     prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
    411   //     dtmanage_->addSectionToExecute(debut, fin, prog);
    412   //   }
    413353  string resultat;
    414354  if ( !dtmanage_->executeAll(resultat)) probleme_->setHidden(false);
     
    419359}
    420360
    421 // void PspaApplication::executer()
    422 // {
    423 //   addConsoleMessage(string("on va peut etre y arriver"));
    424 //   static_cast<GWt_globalParameters*>(globalParam_)->updateGlobals();
    425 
    426 //   int debut, fin;
    427 //   nomDeLogiciel prog;
    428 //   list<GWt_sectionToExecute*>::iterator itr;
    429 //   dtmanage_->initializeExecution();
    430 //   for (itr= selectedSections_.begin(); itr != selectedSections_.end(); itr++)
    431 //     {
    432 //       string debString = (*itr)->debut->text().toUTF8();
    433 //       string finString = (*itr)->fin->text().toUTF8();
    434 //       debut = atoi( debString.c_str()  );
    435 //       fin = atoi(  finString.c_str() );
    436 //       prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
    437 //       cout << " PspaApplication::executer() on lance l'execution de : " << prog.getString() << endl;
    438 //       string resul;
    439 //      if ( prog == nomDeLogiciel::parmela )
    440 //        {
    441 //          resul = dtmanage_->executeParmela( debut, fin);
    442 //                  faireDessinParmela();
    443 //          addConsoleMessage(resul);
    444 //        }
    445 //      else if ( prog == nomDeLogiciel::transport )
    446 //        {
    447 
    448 //          // if ( !dtmanage_->getCurrentBeam().momentRepresentationOk() )
    449 //          //   {             
    450 //          //  addConsoleMessage(" the beam is not OK for transport");
    451 //          //  probleme_->setHidden(false);
    452 //          //  return;
    453 //          //   }
    454 
    455 
    456 //          resul = dtmanage_->executeTransport( debut, fin);
    457 //          faireDessinTransport();
    458 //          addConsoleMessage(resul);
    459 //        }
    460 //      else
    461 //        {
    462 //          resul =  " unknown software -- STOP \n ";   
    463 //          addConsoleMessage(resul);
    464 //          break;
    465 //        }
    466 //     }
    467 // }
    468 
    469 
    470361void PspaApplication::sauver()
    471362{
     
    480371void PspaApplication::restaurer()
    481372{
    482 
    483373  addConsoleMessage(string("restauration..."));
    484374
     
    489379
    490380  GWt_LigneFaisceau* bobo = static_cast<GWt_LigneFaisceau*>(beamLine_);
    491 
    492381  bobo->restoreElementCollection();
     382
    493383  addConsoleMessage(string("...terminee"));
    494384}
     
    609499      (*selectedSections_.begin())->fin->setText(dernierText);
    610500    }
     501
     502  cout << "PspaApplication::updateSelections(): " << premierText << ",à  " << dernierText << endl;
    611503}
    612504
  • Interface_Web/trunk/pspaWT/src/GWt_soleno.cc

    r106 r112  
    77#include <Wt/WPushButton>
    88
    9 int GWt_soleno::nObjets_= 0;
    10 
    119GWt_soleno::GWt_soleno(PspaApplication* ps,abstractElement* elem,string image) : GWt_abstractElement(ps,elem,image)
    1210{
    13   nObjets_++;
    14   setLabel(elem,nObjets_);
    15 
    1611  string* param = element_-> getParametersString();
    1712  if ( param == NULL )
  • Interface_Web/trunk/pspaWT/src/dataManager.cc

    r111 r112  
    55#include <fstream>
    66
    7 //using namespace std;
    8 
    97abstractElement* dataManager::addElement(nomdElement elemType)
    108{
     
    1210}
    1311
    14   void dataManager::addSectionToExecute(int debut, int fin, nomDeLogiciel prog)
    15   {
    16     jobList_.push_back(new sectionToExecute);
    17     jobList_.back()->firstElement = debut;
    18     jobList_.back()->lastElement = fin;
    19     jobList_.back()->software  = prog;
    20   }
     12void dataManager::addSectionToExecute(int debut, int fin, nomDeLogiciel prog)
     13{
     14  jobList_.push_back(new sectionToExecute);
     15  jobList_.back()->firstElement = debut;
     16  jobList_.back()->lastElement = fin;
     17  jobList_.back()->software  = prog;
     18}
    2119
    2220void dataManager::clearSectionToExecute()
    2321{
    2422  unsigned k;
    25   for (k=0; k < jobList_.size();k++)
     23  for(k = 0; k < jobList_.size(); k++)
    2624    {
    2725      if ( jobList_[k] != NULL ) delete jobList_[k];
     
    3230string dataManager::checkExecute()
    3331{
     32  cout << "dataManager::checkExecute()" << endl;
     33 
    3434  int k,j;
    3535  string diagnostic;
    3636  int indexDeb, indexFin;
    37   cout << " controle execution : " << endl;
    38     for ( k=0; k< jobList_.size(); k++)
     37  cout << "controle execution : " << endl;
     38  for(k = 0; k < jobList_.size(); k++) {
     39    indexDeb = jobList_[k]->firstElement;
     40    indexFin = jobList_[k]->lastElement;
     41    indexDeb--;
     42    indexFin--;
     43    abstractElement* elPtr;
     44    if(jobList_[k]->software == nomDeLogiciel::parmela )
    3945      {
    40         indexDeb = jobList_[k]->firstElement;
    41         indexFin = jobList_[k]->lastElement;
    42         indexDeb--;
    43         indexFin--;
    44         abstractElement* elPtr;
    45         if ( jobList_[k]->software == nomDeLogiciel::parmela )
    46           {
    47             for ( j=indexDeb; j <= indexFin; j++)
    48               {
    49                 elPtr = elementsGallery_.getElementPointer(j);
    50                 if ( !elPtr->is_parmela_element() )
    51                   {
    52                     diagnostic += " the element " + elPtr->getNameString() + " is not allowed for PARMELA \n";
    53                   }
    54               }     
     46        for(j = indexDeb; j <= indexFin; j++) {
     47          elPtr = elementsGallery_.getElementPointer(j);
     48
     49          cout << "elPtr parmela: " << elPtr->getLabel() << endl;
     50
     51          if(!elPtr->is_parmela_element()) {
     52            diagnostic += " the element " + elPtr->getNameString() + " is not allowed for PARMELA \n";
    5553          }
    56         else if ( jobList_[k]->software == nomDeLogiciel::transport )
    57           {
    58             for ( j=indexDeb; j <= indexFin; j++)
    59               {
    60                 elPtr = elementsGallery_.getElementPointer(j);
    61                 if ( !elPtr->is_transport_element() )
    62                   {
    63                     diagnostic += " the element " + elPtr->getNameString() + " is not allowed for TRANSPORT \n";
    64                   }
    65               }     
     54        }           
     55      }
     56    else if (jobList_[k]->software == nomDeLogiciel::transport)
     57      {
     58        for(j = indexDeb; j <= indexFin; j++) {
     59          elPtr = elementsGallery_.getElementPointer(j);
     60
     61          cout << "elPtr transp: " << elPtr->getLabel() << endl;
     62
     63          if (!elPtr->is_transport_element()) {
     64            diagnostic += " the element " + elPtr->getNameString() + " is not allowed for TRANSPORT \n";
    6665          }
    67         else
    68           {
    69             diagnostic += (jobList_[k]->software).getString() + " : unknown software \n ";     
    70           }
    71       }
     66        }           
     67      }
     68    else
     69      {
     70        diagnostic += (jobList_[k]->software).getString() + " : unknown software \n "; 
     71      }
     72  }
     73 
    7274  return diagnostic;
    7375}
     
    155157}
    156158
    157 
    158 bool  dataManager::executeParmela( unsigned int indexDeb, unsigned int indexFin, string& resul)
     159bool  dataManager::executeParmela(unsigned int indexDeb,unsigned int indexFin,string& resul)
    159160{
    160161  bool success = true;
    161162  resul.clear();
    162   createInputFileParmela(indexDeb, indexFin);
     163  createInputFileParmela(indexDeb,indexFin);
    163164
    164165  ostringstream sortie;
     
    171172  cout << " job parmela= " << parmelaJob << endl;
    172173  FILE* pp = popen(parmelaJob.c_str(), "r");
    173   if (pp != NULL)
    174     {
    175       cout << " execution parmela MARCHE " << endl;
    176       while (fgets(buf, sizeof buf, pp))
    177         {
    178           sortie << buf;
    179         }
    180 
    181       //     cout << " sortie parmela " << sortie.str() << endl;
    182       string::size_type nn = (sortie.str()).find("normal");
    183       if ( nn == string::npos )
    184         {
    185           sortie << " abnormal exit of parmela " << endl;
    186           resul =  sortie.str();
    187           success = false;
    188           return success;
    189         }
    190 
    191       currentBeam_.setFromParmela(globParam_.getFrequency());
    192       pclose(pp);
    193       resul =  sortie.str();
    194     }
    195   else
    196     {
    197       sortie << " launching of parmela failed " << endl;
    198       resul =  sortie.str();
    199       success = false;
    200     }
    201  
     174  if (pp != NULL) {
     175    cout << " execution parmela MARCHE " << endl;
     176    while (fgets(buf, sizeof buf, pp))
     177      {
     178        sortie << buf;
     179      }
     180
     181    //      cout << " sortie parmela " << sortie.str() << endl;
     182    string::size_type nn = (sortie.str()).find("normal");
     183    if ( nn == string::npos )
     184      {
     185        sortie << " abnormal exit of parmela " << endl;
     186        resul =  sortie.str();
     187        success = false;
     188        return success;
     189      }
     190
     191    currentBeam_.setFromParmela(globParam_.getFrequency());
     192    pclose(pp);
     193    resul =  sortie.str();
     194  } else {
     195    sortie << " launching of parmela failed " << endl;
     196    resul =  sortie.str();
     197    success = false;
     198  }
    202199  return success;
    203200}
    204 
    205201
    206202bool dataManager::createInputFileTransport( unsigned int indexDeb, unsigned int indexFin)
     
    273269  indexFin--;
    274270
    275  
    276 
    277 
    278271  ofstream outfile;
    279272  string name = WORKINGAREA + "parmin";
    280273  outfile.open(name.c_str(), ios::out);
    281       if (!outfile)
    282         {
    283           cerr << " error opening output stream " << name << endl;
    284         }
     274  if (!outfile) {
     275      cerr << " error opening output stream " << name << endl;
     276  }
     277
     278  abstractElement* elPtr;
     279  elPtr = elementsGallery_.getElementPointer(indexDeb);
     280  if ( elPtr->getName() != initialBeam ) {
     281      cerr << " dataManager::createInputFileParmela : the first element should be initialBeam" << endl;
     282    }
     283 
    285284  unsigned int k;
    286   abstractElement* elPtr;
    287 
    288   elPtr = elementsGallery_.getElementPointer(indexDeb);
    289   if ( elPtr->getName() != initialBeam )
    290     {
    291       cerr << " dataManager::createInputFileParmela : the first element should be initialBeam" << endl;
    292     }
    293  
    294 
    295285  double initalKineticEnergy = 0.0;
    296   for ( k=indexDeb; k <= indexFin; k++)
     286  for ( k = indexDeb; k <= indexFin; k++)
    297287    {
    298288      if ( elPtr->getName() == initialBeam )
     
    310300  outfile << "OUTPUT 0" << endl;
    311301   
    312   for ( k=indexDeb; k <= indexFin; k++)
     302  for ( k = indexDeb; k <= indexFin; k++)
    313303    {
    314304      elPtr = elementsGallery_.getElementPointer(k);
    315305      outfile << elPtr->parmelaOutputFlow() << endl;
    316306    }
     307
    317308  outfile << "ZOUT" << endl;
    318309  outfile << "START /wt=0.0 /dwt=" << globParam_.getIntegrationStep() << "  /nsteps=" << globParam_.getNbSteps() << "  nsc=" << globParam_.getScPeriod() << "  /nout=10" << endl;
     
    336327  string completeName = WORKINGAREA + nameOfFile;
    337328  fileExists.open(completeName.c_str(), ios::in);
    338   if (fileExists)
    339     {
    340       fileExists.close();
    341       remove(completeName.c_str());
    342     }
    343 }
    344 
    345   bool dataManager::executeAll(string &resul)
    346   {
    347     unsigned k;
    348     int debut, fin;
    349     bool success = true;
    350     string resultatPartiel;
    351     resul.clear();
    352     for ( k=0; k< jobList_.size(); k++)
    353       {
    354         debut = jobList_[k]->firstElement;
    355         fin = jobList_[k]->lastElement;
    356         resultatPartiel.clear();
    357         cout << " dataManager::executeAll je m'apprete a executer : " << (jobList_[k]->software).getString() << endl;
    358         if ( jobList_[k]->software == nomDeLogiciel::parmela )
    359           {
    360             success =  executeParmela( debut, fin, resultatPartiel);
    361           }
    362         else if ( jobList_[k]->software == nomDeLogiciel::transport )
    363           {
    364             success =  executeTransport( debut, fin, resultatPartiel);
    365             //      cout << " retour transport success = " << success << " listing= " << resul << endl;
    366           }
    367         else
    368           {
    369             success = false;
    370             resultatPartiel =  " unknown software -- STOP \n ";
    371             break;
    372           }
    373         resul += resultatPartiel;
    374         if ( !success ) break;;
    375       }
    376     return success;
    377   }
    378 
    379 
    380   void dataManager::saveAll()
    381   {
    382      ofstream outfile;
    383      string name = WORKINGAREA + "pspa.save";
     329  if (fileExists) {
     330    fileExists.close();
     331    remove(completeName.c_str());
     332  }
     333}
     334
     335bool dataManager::executeAll(string &resul)
     336{
     337  bool success = true;
     338  resul.clear();
     339  string resultatPartiel;
     340  unsigned k;
     341  for(k = 0; k < jobList_.size(); k++)
     342    {
     343      int debut = jobList_[k]->firstElement;
     344      int fin = jobList_[k]->lastElement;
     345      resultatPartiel.clear();
     346      cout << " dataManager::executeAll je m'apprete a executer : " << (jobList_[k]->software).getString() << endl;
     347
     348      if(jobList_[k]->software == nomDeLogiciel::parmela) {
     349        success = executeParmela( debut, fin, resultatPartiel);
     350      } else if (jobList_[k]->software == nomDeLogiciel::transport) {
     351        success = executeTransport( debut, fin, resultatPartiel);
     352      } else {
     353        success = false;
     354        resultatPartiel =  " unknown software -- STOP \n ";     
     355        break;
     356      }
     357      resul += resultatPartiel;
     358      if ( !success ) break;
     359    }
     360  return success;
     361}
     362
     363void dataManager::saveAll()
     364{
     365  ofstream outfile;
     366  string name = WORKINGAREA + "pspa.save";
    384367  outfile.open(name.c_str(), ios::out);
    385       if (!outfile)
    386         {
    387           cerr << " error opening output file for persistency " << name << endl;
    388         }
     368  if (!outfile) {
     369    cerr << " error opening output file for persistency " << name << endl;
     370  }
     371
    389372  outfile << globParam_.FileOutputFlow();
    390373  int k;
     
    395378      outfile << elPtr->FileOutputFlow();
    396379    }
    397     outfile.close();   
    398   }
    399 
    400   void dataManager::restoreElements()
    401   {
    402      ifstream infile;
    403      string name = WORKINGAREA + "pspa.save";
    404       infile.open(name.c_str(), ios::in);
    405       if (!infile)
    406         {
    407           cerr << " error opening input stream " << name << endl;
    408         }
    409       int ielem;
    410 
    411       string globalTitle;
    412       if ( infile >> globalTitle )
    413         {
    414           if ( globalTitle == string("globals") )
    415             {
    416               globParam_.raz();
    417               globParam_.FileInput(infile);
    418             }
    419           else
    420             {
    421               cerr << " dataManager::restoreAll ERROR : global parameters seems to be missing" << endl;
    422             }
    423         }
    424       else
    425         {
    426           cerr << " dataManager::restoreAll ERROR : reading data save file" << endl;
    427         }
    428       elementsGallery_.raz();
    429       nomdElement elem;
    430        while (infile >> ielem)
    431         {
    432           elem = (nomdElement)ielem;
    433           abstractElement* nouveau = addElement(elem);
    434           nouveau->FileInput(infile);
    435         }
    436 
    437 
    438       infile.close();
    439   }
     380  outfile.close();   
     381}
     382
     383void dataManager::restoreElements()
     384{
     385  cout << "dataManager::restoreElements()" << endl;
     386     
     387  ifstream infile;
     388  string name = WORKINGAREA + "pspa.save";
     389  infile.open(name.c_str(), ios::in);
     390  if (!infile) {
     391    cerr << " error opening input stream " << name << endl;
     392  }
     393 
     394  int ielem;
     395  string globalTitle;
     396  if ( infile >> globalTitle ) {
     397    if ( globalTitle == string("globals") ) {
     398      globParam_.raz();
     399      globParam_.FileInput(infile);
     400    } else {
     401      cerr << " dataManager::restoreAll ERROR : global parameters seems to be missing" << endl;
     402    }
     403  } else {
     404    cerr << " dataManager::restoreAll ERROR : reading data save file" << endl;
     405  }
     406
     407  elementsGallery_.raz();
     408  nomdElement elem;
     409  while (infile >> ielem) {
     410    elem = (nomdElement)ielem;
     411    abstractElement* nouveau = addElement(elem);
     412    nouveau->FileInput(infile);
     413  } 
     414  infile.close();
     415
     416  // debug
     417  int k;
     418  for(k = 0; k <  elementsGallery_.size(); k++) {
     419    abstractElement* ptr= elementsGallery_.getElementPointer(k);
     420    cout << "reupere " << ptr->getLabel() << endl;
     421  }
     422}
     423
Note: See TracChangeset for help on using the changeset viewer.