Ignore:
Timestamp:
Mar 11, 2014, 11:21:43 AM (10 years ago)
Author:
lemeur
Message:

refection generale des secteurs et applications de softwares (suite)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_softwarePanel.cc

    r481 r493  
    22//  PSPA
    33//
    4 //  Created by Garnier Laurent on 30/01/13.
    5 //  Copyright (c) 2013 Garnier Laurent. All rights reserved.
     4//  Created by Garnier Laurent on 30/01/13.//  Copyright (c) 2013 Garnier Laurent. All rights reserved.
    65//
    76
     
    1716#include "GWt_dialog.h"
    1817#include "GWt_console.h"
    19 #include "GWt_sector.h"
     18#include "GWt_computingBlock.h"
    2019#include "GWt_globalParameters.h"
    2120#include "GWt_sectionToExecute.h"
    2221#include "GWt_pspaApplication.h"
    23 
    24 #define BAVARD 0
    25 
    26 GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,GWt_sector* sect)
     22#include "GWt_machine.h"
     23#define BAVARD 1
     24
     25GWt_softwarePanelBis::GWt_softwarePanelBis(dataManager* dataManager,GWt_machine* mach)
    2726  : WContainerWidget(),
    2827dtmanage_(dataManager),
    29 UIsector_(sect)
     28UImachine_(mach)
    3029{
    3130 
    3231  // le panel
    3332  WPanel *panelLogiciels = new WPanel(this);
    34   panelLogiciels->setTitle(" sections of beam line for executing softwares ");
     33  panelLogiciels->setTitle(" Computing blocks ");
    3534 
    3635  contenuSections_ = new WContainerWidget();
    3736  contenuSections_->addWidget(new WBreak());
    3837  contenuSections_->addWidget(new WBreak());
    39   displayFromControler();
     38  cout << " GWt_softwarePanelBis::GWt_softwarePanelBis DISPLAY SOFTWARE PANEL " << endl;
     39      displayFromControler();
    4040 
    4141  panelLogiciels->setCentralWidget(contenuSections_);
    4242}
    4343
    44 GWt_softwarePanel::~GWt_softwarePanel() {
    45 }
    46 
    47 void GWt_softwarePanel::displayFromControler()
     44GWt_softwarePanelBis::~GWt_softwarePanelBis() {
     45}
     46
     47void GWt_softwarePanelBis::displayFromControler()
    4848{     
    49 #if BAVARD > 0
    50   cout << "***********************************" << endl;
    51   cout << " GWt_softwarePanel::addSectionToExecuteW() " << endl<<endl;
    52 #endif
     49  cout << " GWt_softwarePanelBis::displayFromControler() " << endl<<endl;
    5350
    5451  // Clear all
    5552  contenuSections_->clear();
    56  
    57   // Get all sectionsToExecute from this sector
    58   if (!UIsector_->getSectorControler()) {
     53
     54
     55  // Get all sectionsToExecute from this machine
     56  if (!UImachine_->getMachineControler()) {
     57    cout << " GWt_softwarePanelBis::displayFromControler() PAS DE MACHINE " << endl;
    5958    return;
    60   }
    61  
    62   if (UIsector_->getSectorControler()->getSectionsToExecute().size() == 0) {
     59  } else {
     60    cout << " GWt_softwarePanelBis::displayFromControler() MACHINE TROUVEE " << endl;
     61  }
     62 
     63  if (UImachine_->getMachineControler()->getComputingBlocks().size() == 0) {
    6364    // FIXME : Add a message to tell the user to add first an element
     65    cout << " GWt_softwarePanelBis::displayFromControler() PAS DE BLOCK " << endl;
    6466  } else {
    65 
    66     unsigned int firstSectionToExecuteIndex = 0;
    67     for (unsigned int a=0; a<UIsector_->getSectorControler()->getSectionsToExecute().size(); a++) {
     67    cout << " GWt_softwarePanelBis::displayFromControler() NOMBRE DE BLOCK " << UImachine_->getMachineControler()->getComputingBlocks().size() << endl;
     68
     69    unsigned int firstElemeOfComputingBlockIndex = 0;
     70
     71    for (unsigned int a=0; a<UImachine_->getMachineControler()->getComputingBlocks().size(); a++) {
     72      cout << " GWt_softwarePanelBis::displayFromControler() BLOC No " << a+1 << endl;
    6873      abstractElement* premierElement = NULL;
    6974      abstractElement* dernierElement = NULL;
    70      
    7175      std::string premierElementLabel = "";
    7276      std::string dernierElementLabel = "";
    73       if (premierElement) {
    74         premierElementLabel = premierElement->getLabel();
     77
     78      if ( !UImachine_->getMachineControler()->getComputingBlocks()[a]->isEmpty() ) {
     79        premierElement = UImachine_->getMachineControler()->getComputingBlocks()[a]->getFirstElement();
     80        firstElemeOfComputingBlockIndex = UImachine_->getMachineControler()->getComputingBlocks()[a]->getRankOfFirstElement();
     81        dernierElement = UImachine_->getMachineControler()->getComputingBlocks()[a]->getLastElement();
    7582      }
    76       if (dernierElement) {
    77         dernierElementLabel = dernierElement->getLabel();
    78       }
     83
     84
     85      if (premierElement) premierElementLabel = premierElement->getLabel();
     86      if (dernierElement) dernierElementLabel = dernierElement->getLabel();
     87      cout << " GWt_softwarePanelBis::displayFromControler() dernier element a afficher " << dernierElementLabel << endl;
    7988     
    8089      WComboBox* lineFromCombo = new WComboBox();
     
    8493     
    8594      // set to first
    86       lineFromCombo->setCurrentIndex(firstSectionToExecuteIndex);
     95      lineFromCombo->setCurrentIndex(firstElemeOfComputingBlockIndex);
    8796      // set to last
    88       lineToCombo->setCurrentIndex(firstSectionToExecuteIndex + (unsigned int)UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size() - 1);
    89      
     97      lineToCombo->setCurrentIndex(UImachine_->getMachineControler()->getComputingBlocks()[a]->getRankOfLastElement());
    9098      WComboBox* softCombo = new WComboBox();
    9199     
    92       fillComboWithSoftwares(softCombo,UIsector_->getSectorControler()->getSectionsToExecute()[a]->getSoftware()->getName());
     100      fillComboWithSoftwares(softCombo,UImachine_->getMachineControler()->getComputingBlocks()[a]->getSoftware()->getName());
    93101
    94102      // disable the "to" comboBox
     
    96104
    97105      // disable the first "from" comboBox
    98       if (a==0) {
    99         lineFromCombo->disable();
     106      // if (a==0) {
     107      //   lineFromCombo->disable();
     108      // }
     109
     110      // enable the last "to" comboBox
     111      if (a==UImachine_->getMachineControler()->getComputingBlocks().size()-1) {
     112                lineToCombo->enable();
    100113      }
    101       // disable the last "to" comboBox
    102       if (a==UIsector_->getSectorControler()->getSectionsToExecute().size()-1) {
    103         lineToCombo->disable();
    104       }
    105      
    106       // Add the sectionToExecute Widget
    107       GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(a),UIsector_->getSectorControler()->getSectionsToExecute()[a],UIsector_);
    108      
    109       /*      // FIXME ?
    110        stringstream st;
    111        st << UIsectionsToExecute_deprecated_.size();
    112        
    113        // this is the mean to identify this section!
    114        newSection->setObjectName(st.str());
    115        
    116        // push back on sections vector
    117        UIsectionsToExecute_deprecated_.push_back(newSection);
    118        */
    119       contenuSections_->addWidget(newSection);
    120       //      updateSections();
    121      
    122       firstSectionToExecuteIndex += UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size();
     114     
     115      // // Add computingBlock Widget
     116     
     117      //      GWt_computingBlock* newBlock = new GWt_computingBlock(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(a),UImachine_->getMachineControler()->getComputingBlocks()[a],UImachine_);
     118      computingBlock* blocPtr = UImachine_->getMachineControler()->getComputingBlocks()[a];
     119      GWt_computingBlock* newBlock = new GWt_computingBlock(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(blocPtr),blocPtr,UImachine_);
     120
     121      cout << " GWt_softwarePanelBis::displayFromControler j'ajoute un bloc : " << newBlock << endl;
     122      cout << " GWt_softwarePanelBis::displayFromControler nb widget avant : " << contenuSections_->count() << endl;
     123      contenuSections_->addWidget(newBlock);
     124      cout << " GWt_softwarePanelBis::displayFromControler nb widget apres : " << contenuSections_->count() << endl;
     125     
    123126    }
    124127  }
    125  }
    126 
    127 void GWt_softwarePanel::updateSections()
    128 {
    129 #if BAVARD > 0
    130   cout << "***********************************" << endl;
    131   cout << " GWt_softwarePanel::updateSections() " << endl<<endl;
    132 #endif
    133 
    134   /*
    135   // update all sections in order to manage new/deleted items
    136   for (int a = 0; a < UIsectionsToExecute_deprecated_.size(); a++) {
    137     fillComboWithElements(UIsectionsToExecute_deprecated_[a]->getFirstElement());
    138     fillComboWithElements(UIsectionsToExecute_deprecated_[a]->getLastElement());
    139     UIsectionsToExecute_deprecated_[a]->getFirstElement()->setEnabled (true);
    140     UIsectionsToExecute_deprecated_[a]->getLastElement()->setEnabled (true);
    141   }
    142  
    143   if (UIsectionsToExecute_deprecated_;.size() == 0) {
     128}
     129
     130void GWt_softwarePanelBis::fillComboWithElements(Wt::WComboBox* cBox)
     131{
     132
     133  if (cBox == NULL) return;
     134
     135  if (!UImachine_->getMachineControler()) {
    144136    return;
    145137  }
    146  
    147   // the first element will always be the first element of the beamLine
    148   UIsectionsToExecute_deprecated_[0]->getFirstElement()->setCurrentIndex(0);
    149   UIsectionsToExecute_deprecated_[0]->getFirstElement()->setEnabled (false);
    150 
    151   // the last element will always be the last element of the beamLine
    152   UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_.size()-1]->getLastElement()->setCurrentIndex(UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_;.size()-1]->getLastElement()->count());
    153   UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_.size()-1]->getLastElement()->setEnabled(false);
    154 
    155   // set default values
    156   updateSectionSelection();
    157 */
    158 }
    159 
    160 bool GWt_softwarePanel::updateSectionSelection()
    161 {
    162 #if BAVARD > 0
    163   cout << "***********************************" << endl;
    164   cout << " GWt_softwarePanel::updateSectionSelection() " << endl<<endl;
    165 #endif
    166 
    167   if ( dtmanage_->getJobListSize() == 0 ) return false;
    168  
    169   // traitement de la premiere ligne
    170   // on impose le depart du calcul au premier element
    171   string premier = "";
    172   if (UIsector_->getSectorControler()) {
    173     if (UIsector_->getSectorControler()->getSectionsToExecute().size() > 0) {
    174       if (UIsector_->getSectorControler()->getSectionsToExecute()[0]->getElements().size() > 0) {
    175         premier = UIsector_->getSectorControler()->getSectionsToExecute()[0]->getElements()[0]->getLabel();
    176       }
    177     }
    178   }
    179  
    180   // FIXME :  A réécrire
    181   /*
    182   if (UIsectionsToExecute_deprecated_.size() > 0) {
    183     UIsectionsToExecute_deprecated_[0]->setFirstElementCurrentSelection(premier);
    184   }
    185  
    186   Wt::WString currentString =  UIsectionsToExecute_deprecated_[0]->getLastElementCurrentText();
    187   int current = dtmanage_->getNumeroFromElementLabel(currentString.toUTF8());
    188  
    189   // si la fin est mal definie on prend toute la config par defaut
    190   if ( current <= 0 || current > dtmanage_->getBeamLineSize() )
    191     {
    192       current = dtmanage_->getBeamLineSize();
    193       currentString =  dtmanage_->getLabelFromElementNumero(current);
    194       if (UIsectionsToExecute_deprecated_.size() > 0) {
    195         UIsectionsToExecute_deprecated_[0]->setLastElementCurrentSelection(currentString);
    196         //...
    197       }
    198     }
    199   current++;
    200   currentString = dtmanage_->getLabelFromElementNumero(current);
    201  
    202   // traitement des suivantes (on avance d'un cran dans la liste)
    203   for (int a = 1; a< UIsectionsToExecute_deprecated_;.size(); a++)
    204     {
    205       // debut
    206       if ( current > dtmanage_->getBeamLineSize() )
    207         {
    208           UIsectionsToExecute_deprecated_;[a]->setErrors("This section element could not be after previous session last element");
    209           exec_go_->disable();
    210           return false;
    211         }
    212      
    213       UIsectionsToExecute_deprecated_;[a]->setFirstElementCurrentSelection(currentString);
    214 
    215       // fin
    216       string finString =  UIsectionsToExecute_deprecated_;[a]->getLastElementCurrentText().toUTF8();
    217      
    218       int numeroFin = dtmanage_->getNumeroFromElementLabel( finString);
    219      
    220       if ( numeroFin < current)
    221       {
    222         UIsectionsToExecute_deprecated_;[a]->setErrors("Last section element should be after first section element");
    223         exec_go_->disable();
    224         return false;
    225       }
    226 
    227       if (numeroFin > dtmanage_->getBeamLineSize())
    228       {
    229         UIsectionsToExecute_deprecated_;[a]->setErrors("Last section element number is greater than the beam line size");
    230         exec_go_->disable();
    231         return false;
    232       }
    233      
    234       // preparation de la ligne suivante
    235       current = numeroFin +1;
    236       currentString = dtmanage_->getLabelFromElementNumero(current);
    237     }
    238   //  exec_go_->setDisabled(false);
    239 
    240   if (!areDataCoherent()) {
    241 #if BAVARD > 0
    242     cout << " GWt_softwarePanel::addSectionToExecuteW() DISABLE" << endl;
    243 #endif
    244     exec_go_->disable();
    245   } else {
    246 #if BAVARD > 0
    247     cout << " GWt_softwarePanel::addSectionToExecuteW() ENABLE" << endl;
    248 #endif
    249     exec_go_->enable();
    250   }
    251 */
    252   return true;
    253 }
    254 
    255 
    256 void GWt_softwarePanel::addSectionToExecute() {
    257   // We put the last element of the previous sectionToExecute inside
    258  
    259   // Get the last element from previous section
    260   if (!UIsector_->getSectorControler()) {
    261     return;
    262   }
    263   unsigned long s = UIsector_->getSectorControler()->getSectionsToExecute().size();
    264   if (s > 0) {
    265     abstractElement* abs = UIsector_->getSectorControler()->getSectionsToExecute()[s-1]->getLastElement();
    266     UIsector_->getSectorControler()->addSectionToExecute(new sectionToExecute(abs,NULL,dtmanage_,UIsector_->getSectorControler()));
    267     UIsector_->getSectorControler()->getSectionsToExecute()[s-1]->removeLastElement();
    268   }
    269 
    270  
    271   displayFromControler();
    272   UIsector_->getBeamLineWidget()->buildBeamLineWidget();
    273 }
    274 
    275 
    276 void GWt_softwarePanel::deleteSectionToExecute(int sectionLabel)
    277 {
    278 #if BAVARD > 0
    279   cout << "***********************************" << endl;
    280   cout << " GWt_softwarePanel::deleteSectionToExecuteW()" << endl<<endl;
    281 #endif
    282 
    283   stringstream st;
    284   st << sectionLabel;
    285   std::string sectionName = st.str();
    286   //FIXME
    287  
    288 /*  if ( dtmanage_->getJobListSize() == 0 ) return;
    289   for (unsigned int sectionIndex = 0; sectionIndex< UIsectionsToExecute_deprecated_.size(); sectionIndex++) {
    290     if (UIsectionsToExecute_deprecated_[sectionIndex]->objectName() == sectionName) {
    291 
    292       // delete from dataManager
    293       UIsector_->getSectorControler()->clearSectionToExecute(sectionIndex);
    294 
    295       // delete from User Interface
    296       contenuSections_->removeWidget(UIsectionsToExecute_deprecated_[sectionIndex]);
    297       delete UIsectionsToExecute_deprecated_[sectionIndex];
    298       UIsectionsToExecute_deprecated_.erase (UIsectionsToExecute_deprecated_.begin()+sectionIndex);
    299     }
    300   } 
    301 */
    302   displayFromControler();
    303 }
    304 
    305 
    306 void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox)
    307 {
    308 
    309   if (cBox == NULL) return;
    310 
    311   if (!UIsector_->getSectorControler()) {
    312     return;
    313   }
    314   for (unsigned int a=0; a < UIsector_->getSectorControler()->getSectionsToExecute().size(); a++) {
    315     for(unsigned int b=0; b < UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size(); b++) {
    316      
    317       abstractElement* abs = UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements()[b];
     138    for(unsigned int b=0; b < UImachine_->getMachineControler()->getElements().size(); b++) {
     139     
     140      abstractElement* abs = UImachine_->getMachineControler()->getElements()[b];
    318141      if (abs != NULL) {
    319142        cBox->addItem(abs->getLabel());
    320143      }
    321144    }
    322   }
    323 }
    324 
    325 void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox, std::string selected)
     145}
     146
     147void GWt_softwarePanelBis::fillComboWithSoftwares(Wt::WComboBox* cBox, std::string selected)
    326148{
    327149#if BAVARD > 0
     
    344166}
    345167
    346 Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(int sectionNumber)
     168
     169Wt::WContainerWidget* GWt_softwarePanelBis::createAddDeletePushButtons(computingBlock* cpbl)
    347170{
    348171  WContainerWidget* buttonContainer= new WContainerWidget();
     
    352175  // preparation du bouton add
    353176  WPushButton* exec_add = new WPushButton("+");
    354   exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecute);
     177  //  exec_add->clicked().connect(this, &GWt_softwarePanelBis::addComputingBlock);
     178  exec_add->clicked().connect(boost::bind(&GWt_softwarePanelBis::addComputingBlock, this, cpbl));
    355179  exec_add->setStyleClass("roundButton");
    356180  exec_add->setMaximumSize(20,20);
     
    361185  //  warningsContainer_->setStyleClass("warningsContainer");
    362186
    363   exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteSectionToExecute, this, sectionNumber));
     187  exec_delete->clicked().connect(boost::bind(&GWt_softwarePanelBis::deleteComputingBlock, this, cpbl));
    364188  exec_delete->setStyleClass("roundButton");
    365189  exec_delete->setMaximumSize(20,20);
     
    372196  return buttonContainer;
    373197}
     198
     199void GWt_softwarePanelBis::addComputingBlock(computingBlock* cpbl) {
     200  // We put the last element of the previous sectionToExecute inside
     201 
     202  if (!UImachine_->getMachineControler()) {
     203    return;
     204  }
     205  //  UImachine_->getMachineControler()->openNewLastBlock();
     206    UImachine_->getMachineControler()->openNewBlockAfter(cpbl);
     207  displayFromControler();
     208}
     209
     210
     211// void GWt_softwarePanelBis::deleteComputingBlock(int sectionLabel)
     212// {
     213//   cout << " GWt_softwarePanelBis::deleteComputingBlock()" << endl;
     214
     215//   stringstream st;
     216//   st << sectionLabel;
     217//   std::string sectionName = st.str();
     218//   //FIXME
     219//   vector<computingBlock*>& compBloc = UImachine_->getMachineControler()->getComputingBlocks();
     220//   cout << " GWt_softwarePanelBis::deleteComputingBlock() nb blocs = " << compBloc.size() << endl;
     221//   cout << " GWt_softwarePanelBis::deleteComputingBlock() nb widgets = " << sectionName << endl;
     222//   cout << " GWt_softwarePanelBis::deleteComputingBlock() nom bloc a detruire = " << contenuSections_->count() << endl;
     223
     224//   for ( unsigned k=0; k <  compBloc.size(); k++) {
     225
     226//   }
     227// /*  if ( dtmanage_->getJobListSize() == 0 ) return;
     228//   for (unsigned int sectionIndex = 0; sectionIndex< UIsectionsToExecute_deprecated_.size(); sectionIndex++) {
     229//     if (UIsectionsToExecute_deprecated_[sectionIndex]->objectName() == sectionName) {
     230
     231//       // delete from dataManager
     232//       UIsector_->getSectorControler()->clearSectionToExecute(sectionIndex);
     233
     234//       // delete from User Interface
     235//       contenuSections_->removeWidget(UIsectionsToExecute_deprecated_[sectionIndex]);
     236//       delete UIsectionsToExecute_deprecated_[sectionIndex];
     237//       UIsectionsToExecute_deprecated_.erase (UIsectionsToExecute_deprecated_.begin()+sectionIndex);
     238//     }
     239//   } 
     240// */
     241//   displayFromControler();
     242// }
     243
     244void GWt_softwarePanelBis::deleteComputingBlock(computingBlock* cpbl)
     245{
     246  cout << " GWt_softwarePanelBis::deleteComputingBlock(computingBlock*)" << endl;
     247
     248  UImachine_->getMachineControler()->eraseComputingBlock(cpbl);
     249  displayFromControler();
     250}
Note: See TracChangeset for help on using the changeset viewer.