source: PSPA/Interface_Web/trunk/pspaWT/sources/controler/src/sectionToExecute.cc @ 483

Last change on this file since 483 was 483, checked in by garnier, 10 years ago

Correction d'un bug. La suppression d'un

élément est désormais effective

File size: 5.6 KB
RevLine 
[385]1#include "sectionToExecute.h"
[469]2#include "softwareUnknown.h"
3#include "softwareParmela.h"
4#include "softwareTransport.h"
5#include "softwareGenerator.h"
6#include "softwareGenerator.h"
7#include "softwareUsersprogram.h"
8#include "softwareTest.h"
9#include "softwareMadx.h" //xx
[385]10
11
[474]12sectionToExecute::sectionToExecute(abstractElement* f, abstractSoftware* s,dataManager* data,sector* sect) {
[472]13  dataManager_ = data;
[474]14  sector_ = sect;
[472]15 
[455]16  elements_.push_back(f);
[469]17  if (s == NULL) {
18    software_ = new softwareUnknown();
19  } else {
[455]20    software_ = s;
[469]21  }
[455]22}
[385]23
24
[455]25bool sectionToExecute::insertAfter(abstractElement* previousElement,abstractElement* currentElement) {
26
27  std::vector<abstractElement*>::iterator it;
28  for (it = elements_.begin(); it < elements_.end(); it++) {
29    if (*it == previousElement ) {
30      elements_.insert (it+1,currentElement);
31      return true;
32    }
33  }
34  return false;
[385]35}
[419]36
[469]37
38void sectionToExecute::setSoftware(std::string logiciel) {
39 
[455]40  abstractSoftware* prog;
41  string inputFileName;
[469]42  if(logiciel == "parmela") {
[455]43    inputFileName = "parmin";
[472]44    prog = new softwareParmela(inputFileName, this,dataManager_ );
[469]45  } else if (logiciel  == "transport") {
[455]46    inputFileName = "transport.input";
[472]47    prog =  new softwareTransport(inputFileName, this,dataManager_ );
[469]48  } else if (logiciel == "generator") {
[455]49    inputFileName = "generator.in";
[472]50    prog = new softwareGenerator(inputFileName, this,dataManager_ );
[469]51  } else if (logiciel  == "madx") {
[455]52    inputFileName = "madx.input";
[472]53    prog = new softwareMadx(inputFileName,this,dataManager_ );
[469]54  } else if (logiciel  == "usersprogram") {
[455]55    inputFileName = "dummy";
[472]56    prog = new softwareUsersprogram(inputFileName, this,dataManager_ );
[469]57  } else if (logiciel  == "test") {
[472]58    prog = new softwareTest(inputFileName, this,dataManager_ );
[455]59  } else {
[469]60    prog = new softwareUnknown();
[455]61  }
62 
[469]63  setSoftware(prog);
[455]64}
[469]65
[474]66
[476]67void sectionToExecute::setFirstElement(int index) {
68// This will set the beginning of this section to the element with the given name
69 
70  // Possible cases :
71  //
72  // | section 1 | section 2 | section 3   |  section 4 | section 5 |
73  // |  a b c d  |  e f g h  |  i j k l    |  m n o p   |  q r  | Before (example)
[474]74
[476]75  // Moved in a previous section :
76  // |  a b c d  |  e f      |  _g_ h i j k l  |  m n o p |  q r  |  Case 1 : move beginning of section 3 to "g"
77  // |  a b c    |           |  _d_ e f g h i j k l  |  m n o p  |  q r  |  Case 2 : move beginning of section 3 to "d" => section 2 will be removed !
78  // => all elements from "d"/"g" to "l" will be moved in the 3rd section
[474]79 
[476]80  // Moved in the same section :
81  // |  a b c d  |  e f g h i j  | _k_ l  |  m n o p   |  q r  | Case 3 : move beginning of section 3 to "k"
82  // => all elements from "i"(begin of 3rd section) to before "k" will be moved in the 2nd (3-1) section
83 
84  // Moved in a next section :
85  // |  a b c d  |  e f g h i j k l m |  _n_ | o p  |  q r  | Case 4 : move beginning of section 3 to "n"
86  // |  a b c d  |  e f g h i j k l m  n o p  |  _q_ |   | r  | Case 5 : move beginning of section 3 to "q" => remove section 4 !
87  // => all elements from "i"(begin of 3rd section) to before "n"/"q" will be moved in the 2nd (3-1) section
88  // => "n"/"q" element is set to be alone in 3rd section
89 
[474]90  std::vector <sectionToExecute*> sectVect = sector_->getSectionsToExecute();
[476]91  unsigned int sectionNumber = 0;
92  int newBeginSectionNumber = 0;
93  unsigned long indexOfNewBeginSectionNumber = 0;
94 
95  // get this section number
96  // get the section number of the new begin element
97  unsigned int n = 0;
98  bool newFound = false;
[474]99
100  for (unsigned int a=0; a< sectVect.size(); a++) {
101    if (sectVect[a] == this) {
[476]102      sectionNumber = a;
103    }
104    n += sectVect[a]->getElements().size();
105    if ((n >index ) && (!newFound)) {
106      newBeginSectionNumber = a;
107      indexOfNewBeginSectionNumber = index - (n-sectVect[a]->getElements().size());
108      newFound = true;
109    }
110  }
111 
112  if (!newFound ) {
113    return;  // Impossible to find this index
114  }
115 
116  // Moved in a previous section
117  if ( newBeginSectionNumber < sectionNumber ) {
118    for (int a = sectionNumber-1 ; a >= newBeginSectionNumber; a--) {
119      std::vector< abstractElement* > elemsVect = sectVect[a]->getElements();
120      long stop = 0;
[480]121      long start = elemsVect.size();
[476]122      if (a == newBeginSectionNumber) {
123        stop = indexOfNewBeginSectionNumber;
[474]124      }
[480]125      for (long elemIndex = start; elemIndex > stop; elemIndex--) {
[476]126        insertAtFirst(elemsVect.back());
127        elemsVect.pop_back();
128
129        // remove elements
130        sectVect[a]->removeLastElement();
131      }
[474]132    }
[476]133   
134    // Moved in the same section :
[480]135  } else if (( newBeginSectionNumber == sectionNumber ) && (sectionNumber > 0)){
136    for (long elemIndex = 0; elemIndex < indexOfNewBeginSectionNumber; elemIndex++) {
137      sectVect[sectionNumber-1]->insertAtLast(elements_.front());
138      removeFirstElement();
139    }
[476]140   
141   
142    // Moved in a next section :
143  } else if ( newBeginSectionNumber > sectionNumber ) {
144   
145   
[474]146  }
[476]147 
148  // Suppress the empty sections
149  for (unsigned int a=0; a< sectVect.size(); a++) {
150    if (sectVect[a]->getElements().size() == 0  ) {
151      sector_->clearSectionToExecute(a);
152    }
[474]153  }
154}
[483]155
156
157bool sectionToExecute::isInside(abstractElement* previousElement) {
158  for (unsigned int a=0; a< elements_.size(); a++) {
159    if (elements_[a] == previousElement ) {
160      return true;
161    }
162  }
163  return false;
164}
165
166
167void sectionToExecute::removeElement(abstractElement* previousElement){
168  std::vector<abstractElement*>::iterator it;
169  for (it = elements_.begin(); it < elements_.end(); it++) {
170    if (*it == previousElement ) {
171      elements_.erase(it);
172      return;
173    }
174  }
175}
Note: See TracBrowser for help on using the repository browser.