[493] | 1 | #include "dataManager.h" |
---|
| 2 | #include "expandedMachine.h" |
---|
| 3 | #include "softwareUnknown.h" |
---|
| 4 | #include "softwareParmela.h" |
---|
| 5 | #include "softwareTransport.h" |
---|
| 6 | #include "softwareGenerator.h" |
---|
| 7 | #include "softwareGenerator.h" |
---|
| 8 | #include "softwareUsersprogram.h" |
---|
| 9 | #include "softwareTest.h" |
---|
| 10 | #include "softwareMadx.h" //xx |
---|
| 11 | |
---|
| 12 | void expandedMachine::clearComputingBlock(int a) |
---|
| 13 | { |
---|
| 14 | cout << " expandedMachine::clearComputingBlock : effacement du bloc d'index = " << a << endl; |
---|
| 15 | if (a < 0) return; |
---|
| 16 | if (a >= (int)computingBlocks_.size()) return; |
---|
| 17 | |
---|
| 18 | // lors de la creation de la section on a fait un 'new' d'un |
---|
| 19 | // softwareXXXX : on fait ici le 'delete' |
---|
| 20 | |
---|
| 21 | // const abstractSoftware* soft = computingBlocks_.at(a)->getSoftware(); |
---|
| 22 | // if ( soft != NULL ) delete soft; |
---|
| 23 | computingBlocks_.at(a)->clearAll(); |
---|
| 24 | delete computingBlocks_[a]; |
---|
| 25 | computingBlocks_.erase (computingBlocks_.begin()+a); |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | bool expandedMachine::eraseComputingBlock(computingBlock* cpbl) { |
---|
| 29 | for ( unsigned k=0; k < computingBlocks_.size(); k++) { |
---|
| 30 | if ( cpbl == computingBlocks_.at(k) ) { |
---|
| 31 | cout << " expandedMachine::eraseComputingBlock : J'AI TROUVE LE BLOC A DETRUIRE " << endl; |
---|
| 32 | unsigned nbElem = computingBlocks_.at(k)->getNumberOfElements(); |
---|
| 33 | if ( k != 0 ) { |
---|
| 34 | computingBlocks_.at(k-1)->extendByTheEnd(nbElem); |
---|
| 35 | } else { |
---|
| 36 | if ( computingBlocks_.size() == 1 ) return false; |
---|
| 37 | computingBlocks_.at(k+1)->reinitialiseElements(computingBlocks_.at(k)->getRankOfFirstElement(), |
---|
| 38 | computingBlocks_.at(k+1)->getNumberOfElements() + nbElem); |
---|
| 39 | } |
---|
| 40 | clearComputingBlock(int(k) ); |
---|
| 41 | return true; |
---|
| 42 | } |
---|
| 43 | } |
---|
| 44 | return false; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | abstractSoftware* expandedMachine::getSoftwarePointer(std::string logiciel, computingBlock* cpblk) { |
---|
| 48 | |
---|
| 49 | cout << " expandedMachine::getSoftwarePointer .... logiciel " << logiciel << endl; |
---|
| 50 | |
---|
| 51 | abstractSoftware* prog; |
---|
| 52 | |
---|
| 53 | string inputFileName; |
---|
| 54 | if(logiciel == "parmela") { |
---|
| 55 | inputFileName = "parmin"; |
---|
| 56 | prog = new softwareParmela(inputFileName, cpblk,dataManager_ ); |
---|
| 57 | } else if (logiciel == "transport") { |
---|
| 58 | inputFileName = "transport.input"; |
---|
| 59 | prog = new softwareTransport(inputFileName, cpblk,dataManager_ ); |
---|
| 60 | } else if (logiciel == "generator") { |
---|
| 61 | inputFileName = "generator.in"; |
---|
| 62 | prog = new softwareGenerator(inputFileName, cpblk,dataManager_ ); |
---|
| 63 | } else if (logiciel == "madx") { |
---|
| 64 | inputFileName = "madx.input"; |
---|
| 65 | prog = new softwareMadx(inputFileName,cpblk,dataManager_ ); |
---|
| 66 | } else if (logiciel == "usersprogram") { |
---|
| 67 | inputFileName = "dummy"; |
---|
| 68 | prog = new softwareUsersprogram(inputFileName, cpblk,dataManager_ ); |
---|
| 69 | } else if (logiciel == "test") { |
---|
| 70 | prog = new softwareTest(inputFileName, cpblk,dataManager_ ); |
---|
| 71 | } else { |
---|
| 72 | prog = new softwareUnknown(); |
---|
| 73 | } |
---|
| 74 | return prog; |
---|
| 75 | |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | void expandedMachine::setSoftware(std::string logiciel, computingBlock* cpblk) { |
---|
| 80 | int a = -1; |
---|
| 81 | for (unsigned k=0; k < computingBlocks_.size(); k++ ) { |
---|
| 82 | if ( cpblk == computingBlocks_.at(k) ) a = k; |
---|
| 83 | } |
---|
| 84 | if ( a < 0) return; |
---|
| 85 | |
---|
| 86 | abstractSoftware* prog = getSoftwarePointer(logiciel, computingBlocks_.at(a)); |
---|
| 87 | |
---|
| 88 | // string inputFileName; |
---|
| 89 | // if(logiciel == "parmela") { |
---|
| 90 | // inputFileName = "parmin"; |
---|
| 91 | // prog = new softwareParmela(inputFileName, computingBlocks_.at(a),dataManager_ ); |
---|
| 92 | // } else if (logiciel == "transport") { |
---|
| 93 | // inputFileName = "transport.input"; |
---|
| 94 | // prog = new softwareTransport(inputFileName, computingBlocks_.at(a),dataManager_ ); |
---|
| 95 | // } else if (logiciel == "generator") { |
---|
| 96 | // inputFileName = "generator.in"; |
---|
| 97 | // prog = new softwareGenerator(inputFileName, computingBlocks_.at(a),dataManager_ ); |
---|
| 98 | // } else if (logiciel == "madx") { |
---|
| 99 | // inputFileName = "madx.input"; |
---|
| 100 | // prog = new softwareMadx(inputFileName,computingBlocks_.at(a),dataManager_ ); |
---|
| 101 | // } else if (logiciel == "usersprogram") { |
---|
| 102 | // inputFileName = "dummy"; |
---|
| 103 | // prog = new softwareUsersprogram(inputFileName, computingBlocks_.at(a),dataManager_ ); |
---|
| 104 | // } else if (logiciel == "test") { |
---|
| 105 | // prog = new softwareTest(inputFileName, computingBlocks_.at(a),dataManager_ ); |
---|
| 106 | // } else { |
---|
| 107 | // prog = new softwareUnknown(); |
---|
| 108 | // } |
---|
| 109 | |
---|
| 110 | computingBlocks_.at(a)->setSoftware(prog); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | // methode provisoire |
---|
[495] | 114 | void expandedMachine::fromSectors( const vector<sector*>& secteurs ) |
---|
[493] | 115 | { |
---|
| 116 | cout << " methode expandedMachine::fromSectors " << endl; |
---|
| 117 | unsigned k,j,m; |
---|
| 118 | elements_.clear(); |
---|
| 119 | for (k=0; k < secteurs.size() ; k++) { |
---|
| 120 | |
---|
| 121 | sector* sect = secteurs.at(k); |
---|
| 122 | // vector<sectionToExecute*> vecsec = sect->getSectionsToExecute(); |
---|
| 123 | // for (j=0; j < vecsec.size() ; j++) { |
---|
| 124 | vector< abstractElement* > lesElements = sect->getElements(); |
---|
| 125 | for ( m=0; m < lesElements.size(); m++) elements_.push_back(lesElements.at(m)); |
---|
| 126 | // } |
---|
| 127 | } |
---|
| 128 | cout << " expandedMachine::fromSectors la machine a " << elements_.size() << " elements " << endl; |
---|
| 129 | computingBlocks_.clear(); |
---|
| 130 | computingBlocks_.push_back(new computingBlock(0, elements_.size(),NULL, this)); |
---|
| 131 | } |
---|
| 132 | |
---|
[495] | 133 | |
---|
[493] | 134 | bool expandedMachine::openNewLastBlock() { |
---|
| 135 | cout << " expandedMachine::openNewLastBlock() " << endl; |
---|
| 136 | abstractElement* s = computingBlocks_.back()->getLastElement(); |
---|
| 137 | if ( !s ) { |
---|
| 138 | cout << " expandedMachine::openNewLastBlock() dernier element non reconnu " << endl; |
---|
| 139 | return false; |
---|
| 140 | } |
---|
| 141 | computingBlocks_.back()->removeLastElement(); |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | computingBlocks_.push_back(new computingBlock(getElementRankFromPointer(s), 1,NULL, this)); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | bool expandedMachine::openNewBlockAfter(computingBlock* cpbl) { |
---|
| 148 | cout << " expandedMachine::openNewBlockAfter() " << endl; |
---|
| 149 | int preceedingIndex = -1; |
---|
| 150 | int compteur=0; |
---|
| 151 | vector<computingBlock*>::iterator iter; |
---|
| 152 | vector<computingBlock*>::iterator iterFound; |
---|
| 153 | for ( iter = computingBlocks_.begin(); iter != computingBlocks_.end(); iter++, compteur++) { |
---|
| 154 | |
---|
| 155 | if ( cpbl == *iter ) { |
---|
| 156 | cout << " expandedMachine::openNewBlockAfter : J'AI TROUVE LE BLOC APRES LEQUEL INSERER " << endl; |
---|
| 157 | iterFound = iter; |
---|
| 158 | preceedingIndex = compteur; |
---|
| 159 | break; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | if ( preceedingIndex < 0 ) return false; |
---|
| 163 | unsigned dernierPrecedent = computingBlocks_.at(preceedingIndex)->getRankOfLastElement(); |
---|
| 164 | computingBlocks_.at(preceedingIndex)->removeLastElement(); |
---|
| 165 | unsigned nbElemNew; |
---|
| 166 | if ( preceedingIndex < computingBlocks_.size() - 1 ) { |
---|
| 167 | computingBlocks_.at(preceedingIndex+1)->removeFirstElement(); |
---|
| 168 | nbElemNew = 2; |
---|
| 169 | } else { |
---|
| 170 | nbElemNew = 1; |
---|
| 171 | } |
---|
| 172 | computingBlocks_.insert(iter + 1, new computingBlock(dernierPrecedent, nbElemNew,NULL, this)); |
---|
| 173 | cout << " expandedMachine::openNewBlockAfter il y a maintenant " << computingBlocks_.size() << " blocs " << endl; |
---|
| 174 | for ( unsigned j=0; j < computingBlocks_.size(); j++) { |
---|
| 175 | cout << " bloc " << j << " : " << endl; |
---|
| 176 | for ( unsigned k=0; k < computingBlocks_.at(j)->getNumberOfElements(); k++) { |
---|
| 177 | cout << computingBlocks_.at(j)->getElement(k)->getLabel() << endl; |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | void expandedMachine::FileAMLOutput(UAPNode* root) |
---|
| 183 | { |
---|
| 184 | UAPNode* node = root->addChild("machine"); |
---|
| 185 | node->addAttribute("name",machineName_); |
---|
| 186 | UAPNode* lesElements = node->addChild("machineElements"); |
---|
| 187 | for ( unsigned k=0; k < elements_.size(); k++) { |
---|
| 188 | lesElements->addChild("melement")->addAttribute("name",elements_.at(k)->getLabel()); |
---|
| 189 | } |
---|
| 190 | UAPNode* lesBlocs = node->addChild("mcomputingBlocks"); |
---|
| 191 | for ( unsigned k=0; k < computingBlocks_.size(); k++) { |
---|
| 192 | computingBlocks_.at(k)->FileAMLOutput(lesBlocs ); |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | bool expandedMachine::FileAMLInput( UAPNode* entree) { |
---|
| 197 | if ( !entree ) return false; |
---|
| 198 | |
---|
| 199 | elements_.clear(); |
---|
| 200 | computingBlocks_.clear(); |
---|
| 201 | UAPNode* listElem = entree->getChildByName("machineElements"); |
---|
| 202 | if ( !listElem ) { |
---|
| 203 | cout << " expandedMachine::FileAMLInput PAS D'ELEMENTS DANS LA MACHINE " << endl; |
---|
| 204 | } else { |
---|
| 205 | NodeVec lesElements = listElem->getSubNodesByName("melement"); |
---|
| 206 | for (unsigned k=0; k < lesElements.size(); k++ ) { |
---|
| 207 | abstractElement* elem = dataManager_->getElementInSectorsByLabel(lesElements.at(k)->getAttribute("name")->getValue()); |
---|
| 208 | if ( elem ) elements_.push_back(elem); |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | UAPNode* lesBlocks = entree->getChildByName("mcomputingBlocks"); |
---|
| 212 | if ( !lesBlocks ) { |
---|
| 213 | cout << " expandedMachine::FileAMLInput PAS DE BLOCS DANS LA MACHINE " << endl; |
---|
| 214 | } else { |
---|
| 215 | NodeVec listBlocks = lesBlocks->getSubNodesByName("computingBlock"); |
---|
| 216 | for ( unsigned k=0; k < listBlocks.size(); k++ ) { |
---|
| 217 | computingBlocks_.push_back(new computingBlock(this)); |
---|
| 218 | computingBlocks_.back()->FileAMLInput( listBlocks.at(k)); |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | abstractElement* expandedMachine::getElementFromLabel(string lab) { |
---|
| 225 | abstractElement* resultat = NULL; |
---|
| 226 | for ( unsigned k=0; k < elements_.size(); k++) { |
---|
| 227 | if ( elements_.at(k)->getLabel() == lab ) { |
---|
| 228 | resultat = elements_.at(k); |
---|
| 229 | break; |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | return resultat; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | int expandedMachine::getElementRankFromLabel(string lab) { |
---|
| 236 | for ( unsigned k=0; k < elements_.size(); k++) { |
---|
| 237 | if ( elements_.at(k)->getLabel() == lab ) { |
---|
| 238 | return k; |
---|
| 239 | } |
---|
| 240 | } |
---|
| 241 | return -1; |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | int expandedMachine::getElementRankFromPointer(abstractElement* ptr) { |
---|
| 245 | for ( unsigned k=0; k < elements_.size(); k++) { |
---|
| 246 | if ( elements_.at(k) == ptr ) { |
---|
| 247 | return k; |
---|
| 248 | } |
---|
| 249 | } |
---|
| 250 | return -1; |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | |
---|
| 254 | void expandedMachine::setFirstElementOfBlock(computingBlock* bclk, int index) { |
---|
| 255 | // This will set the beginning of a block to the element with the given name |
---|
| 256 | |
---|
| 257 | // Possible cases : |
---|
| 258 | // |
---|
| 259 | // | section 1 | section 2 | section 3 | section 4 | section 5 | |
---|
| 260 | // | a b c d | e f g h | i j k l | m n o p | q r | Before (example) |
---|
| 261 | |
---|
| 262 | // Moved in a previous section : |
---|
| 263 | // | 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" |
---|
| 264 | // | 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 ! |
---|
| 265 | // => all elements from "d"/"g" to "l" will be moved in the 3rd section |
---|
| 266 | |
---|
| 267 | // Moved in the same section : |
---|
| 268 | // | 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" |
---|
| 269 | // => all elements from "i"(begin of 3rd section) to before "k" will be moved in the 2nd (3-1) section |
---|
| 270 | |
---|
| 271 | // Moved in a next section : |
---|
| 272 | // | 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" |
---|
| 273 | // | 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 ! |
---|
| 274 | // => all elements from "i"(begin of 3rd section) to before "n"/"q" will be moved in the 2nd (3-1) section |
---|
| 275 | // => "n"/"q" element is set to be alone in 3rd section |
---|
| 276 | |
---|
| 277 | // std::vector <computingBlock* >& mchVect = machine_->getComputingBlocks(); |
---|
| 278 | |
---|
| 279 | cout << " expandedMachine::setFirstElementOfBlock ENTREE " << endl; |
---|
| 280 | |
---|
| 281 | if ( index < 0 || index >= elements_.size() ) { |
---|
| 282 | cout << " expandedMachine::setFirstElementOfBlock index out of range " << index << endl; |
---|
| 283 | return; |
---|
| 284 | } |
---|
| 285 | unsigned int blockNumber = 0; |
---|
| 286 | int blockNumberOfNewBegin = 0; |
---|
| 287 | |
---|
| 288 | // get this block number |
---|
| 289 | // get the block number of the new begin element |
---|
| 290 | unsigned int curseur = 0; |
---|
| 291 | if ( computingBlocks_.size() ) curseur = computingBlocks_[0]->getRankOfFirstElement(); |
---|
| 292 | bool newFoundInBlocks = false; |
---|
| 293 | bool newFoundBeforeBlocks = false; |
---|
| 294 | |
---|
| 295 | if ( curseur > index ) { |
---|
| 296 | newFoundBeforeBlocks = true; |
---|
| 297 | } else { |
---|
| 298 | for (unsigned int a=0; a< computingBlocks_.size(); a++) { |
---|
| 299 | if (computingBlocks_[a] == bclk) blockNumber = a; |
---|
| 300 | curseur += computingBlocks_[a]->getNumberOfElements(); |
---|
| 301 | if ((curseur >index ) && (!newFoundInBlocks)) { |
---|
| 302 | blockNumberOfNewBegin = a; |
---|
| 303 | newFoundInBlocks = true; |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | if (!newFoundInBlocks ) { |
---|
| 309 | if ( newFoundBeforeBlocks ) { |
---|
| 310 | unsigned nombre = computingBlocks_[blockNumber]->getRankOfLastElement() - index + 1; |
---|
| 311 | computingBlocks_[blockNumber]->reinitialiseElements(index, nombre); |
---|
| 312 | // on vide les blocs initiaux. |
---|
| 313 | for (int a = 0 ; a < blockNumber; a++) computingBlocks_[a]->clearElements(); |
---|
| 314 | } else { |
---|
| 315 | // le nouveau debut est apres les blocks presents |
---|
| 316 | |
---|
| 317 | if ( blockNumber > 0 ) { |
---|
| 318 | unsigned debutPrecedent = computingBlocks_[blockNumber-1]->getRankOfFirstElement(); |
---|
| 319 | unsigned nombre = index - debutPrecedent; |
---|
| 320 | computingBlocks_[blockNumber-1]->reinitialiseElements(debutPrecedent, nombre); |
---|
| 321 | } |
---|
| 322 | unsigned nombre = elements_.size() - index; |
---|
| 323 | computingBlocks_[blockNumber]->reinitialiseElements(index, nombre); |
---|
| 324 | // on vide les blocs finaux |
---|
| 325 | for (int a = blockNumber + 1 ; a < computingBlocks_.size(); a++) computingBlocks_[a]->clearElements(); |
---|
| 326 | } |
---|
| 327 | } else if ( blockNumberOfNewBegin < blockNumber ) { // index trouve dans les blocs |
---|
| 328 | // Moved in a previous section |
---|
| 329 | cout << " expandedMachine::setFirstElementOfBlock Moved in a previous section new bloc = " << blockNumberOfNewBegin << endl; |
---|
| 330 | unsigned debutPrecedent = computingBlocks_[blockNumberOfNewBegin]->getRankOfFirstElement(); |
---|
| 331 | unsigned nombre = index - debutPrecedent; |
---|
| 332 | computingBlocks_[blockNumberOfNewBegin]->reinitialiseElements(debutPrecedent, nombre); |
---|
| 333 | unsigned lastIndex = computingBlocks_[blockNumber]->getRankOfLastElement(); |
---|
| 334 | computingBlocks_[blockNumber]->reinitialiseElements(index, lastIndex - index +1); |
---|
| 335 | // on vide les blocs intermediaires. |
---|
| 336 | for (int a = blockNumber-1 ; a > blockNumberOfNewBegin; a--) computingBlocks_[a]->clearElements(); |
---|
| 337 | } else if ( blockNumberOfNewBegin == blockNumber ) { |
---|
| 338 | // Moved in the same block : |
---|
| 339 | cout << " expandedMachine::setFirstElementOfBlock Moved in the same block new bloc = " << blockNumberOfNewBegin << endl; |
---|
| 340 | |
---|
| 341 | // les elements precedant index sont affectes au bloc precedent |
---|
| 342 | if ( blockNumber ) { |
---|
| 343 | unsigned debutPrecedent = computingBlocks_[blockNumber-1]->getRankOfFirstElement(); |
---|
| 344 | unsigned nombre = index - debutPrecedent; |
---|
| 345 | computingBlocks_[blockNumber-1]->reinitialiseElements(debutPrecedent, nombre); |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | unsigned ancienDebut = computingBlocks_[blockNumber]->getRankOfFirstElement(); |
---|
| 349 | unsigned offset = index - ancienDebut; |
---|
| 350 | computingBlocks_[blockNumber]->reinitialiseElements(index, computingBlocks_[blockNumber]->getNumberOfElements() - offset); |
---|
| 351 | |
---|
| 352 | } else if ( blockNumberOfNewBegin > blockNumber ) { |
---|
| 353 | // Moved in a next section : |
---|
| 354 | if ( blockNumber > 0 ) { |
---|
| 355 | unsigned debutPrecedent = computingBlocks_[blockNumber-1]->getRankOfFirstElement(); |
---|
| 356 | unsigned nombre = index - computingBlocks_[blockNumberOfNewBegin]->getRankOfFirstElement(); |
---|
| 357 | computingBlocks_[blockNumber-1]->reinitialiseElements(debutPrecedent, nombre); |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | unsigned offset = index - computingBlocks_[blockNumberOfNewBegin]->getRankOfFirstElement(); |
---|
| 361 | unsigned nombre = computingBlocks_[blockNumberOfNewBegin]->getNumberOfElements() - offset; |
---|
| 362 | computingBlocks_[blockNumberOfNewBegin]->reinitialiseElements(index, nombre); |
---|
| 363 | // on vide les blocs intermediaires. |
---|
| 364 | for (int a = blockNumber ; a < blockNumberOfNewBegin; a++) computingBlocks_[a]->clearElements(); |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | // Suppress the empty blocs |
---|
| 368 | for (unsigned int a=0; a< computingBlocks_.size(); a++) { |
---|
| 369 | if ( computingBlocks_[a]->isEmpty() ) { |
---|
| 370 | clearComputingBlock(a); |
---|
| 371 | } |
---|
| 372 | } |
---|
| 373 | cout << " expandedMachine::setFirstElementOfBlock Apres nettoyage, il reste " << computingBlocks_.size() << " blocs " << endl; |
---|
| 374 | for ( unsigned j=0; j < computingBlocks_.size(); j++) { |
---|
| 375 | cout << " bloc " << j << " : " << endl; |
---|
| 376 | for ( unsigned k=0; k < computingBlocks_.at(j)->getNumberOfElements(); k++) { |
---|
| 377 | cout << computingBlocks_.at(j)->getElement(k)->getLabel() << endl; |
---|
| 378 | } |
---|
| 379 | } |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | void expandedMachine::setLastElementOfBlock(computingBlock* bclk, int index) { |
---|
| 383 | // This will set the end of a block to the element with the given name |
---|
| 384 | |
---|
| 385 | if ( index < 0 || index >= elements_.size() ) { |
---|
| 386 | cout << " expandedMachine::setLastElementOfBlock index out of range " << index << endl; |
---|
| 387 | return; |
---|
| 388 | } |
---|
| 389 | unsigned int blockNumber = 0; |
---|
| 390 | int blockNumberOfNewEnd = 0; |
---|
| 391 | |
---|
| 392 | // get this block number |
---|
| 393 | // get the block number of the new begin element |
---|
| 394 | unsigned int curseur = 0; |
---|
| 395 | if ( computingBlocks_.size() ) curseur = computingBlocks_.back()->getRankOfLastElement(); |
---|
| 396 | bool newFoundInBlocks = false; |
---|
| 397 | bool newFoundAfterBlocks = false; |
---|
| 398 | |
---|
| 399 | if ( curseur < index ) { |
---|
| 400 | newFoundAfterBlocks = true; |
---|
| 401 | } else { |
---|
| 402 | // for ( int a = computingBlocks_.size() -1; a >= 0; a--) { |
---|
| 403 | // pour l'instant on ne peut que la fin du DERNIER BLOC |
---|
| 404 | // a revoir si necessaire |
---|
| 405 | if (computingBlocks_.back() != bclk) { |
---|
| 406 | cout << " expandedMachine::setLastElementOfBlock, le bloc a modifer n'est pas le dernier : revoir la programmation du module " << endl; |
---|
| 407 | return; |
---|
| 408 | } |
---|
| 409 | blockNumber = computingBlocks_.size() - 1; |
---|
| 410 | for ( int a = computingBlocks_.size() -1; a >= 0 ; a--) { |
---|
| 411 | |
---|
| 412 | curseur -= computingBlocks_[a]->getNumberOfElements(); |
---|
| 413 | if ((curseur < index ) && (!newFoundInBlocks)) { |
---|
| 414 | blockNumberOfNewEnd = a; |
---|
| 415 | newFoundInBlocks = true; |
---|
| 416 | } |
---|
| 417 | } |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | if (!newFoundInBlocks ) { |
---|
| 421 | if ( newFoundAfterBlocks ) { |
---|
| 422 | unsigned nombre = index - computingBlocks_.back()->getRankOfLastElement(); |
---|
| 423 | computingBlocks_.back()->extendByTheEnd(nombre); |
---|
| 424 | } else { |
---|
| 425 | // le nouveau debut est avant les blocks presents |
---|
| 426 | computingBlocks_[0]->reinitialiseElements(0, index + 1); |
---|
| 427 | // on vide les blocs restants |
---|
| 428 | for (int a = 1 ; a < computingBlocks_.size(); a++) computingBlocks_[a]->clearElements(); |
---|
| 429 | } |
---|
| 430 | } else { // index trouve dans les blocs |
---|
| 431 | unsigned nombre = computingBlocks_[blockNumberOfNewEnd]->getRankOfLastElement() - index; |
---|
| 432 | computingBlocks_[blockNumberOfNewEnd]->suppressByTheEnd(nombre); |
---|
| 433 | // on vide les blocs restants |
---|
| 434 | for (int a = blockNumberOfNewEnd + 1 ; a < computingBlocks_.size(); a++) computingBlocks_[a]->clearElements(); |
---|
| 435 | } |
---|
| 436 | // Suppress the empty blocs |
---|
| 437 | for (unsigned int a=0; a< computingBlocks_.size(); a++) { |
---|
| 438 | if ( computingBlocks_[a]->isEmpty() ) { |
---|
| 439 | clearComputingBlock(a); |
---|
| 440 | } |
---|
| 441 | } |
---|
| 442 | cout << " expandedMachine::setLastElementOfBlock Apres nettoyage, il reste " << computingBlocks_.size() << " blocs " << endl; |
---|
| 443 | for ( unsigned j=0; j < computingBlocks_.size(); j++) { |
---|
| 444 | cout << " bloc " << j << " : " << endl; |
---|
| 445 | for ( unsigned k=0; k < computingBlocks_.at(j)->getNumberOfElements(); k++) { |
---|
| 446 | cout << computingBlocks_.at(j)->getElement(k)->getLabel() << endl; |
---|
| 447 | } |
---|
| 448 | } |
---|
| 449 | } |
---|
| 450 | |
---|
| 451 | bool expandedMachine::areDataCoherent() |
---|
| 452 | { |
---|
| 453 | cout << "***********************************" << endl; |
---|
| 454 | cout << "** expandedMachine::areDataCoherent() **" << endl; |
---|
| 455 | cout << "***********************************" << endl; |
---|
| 456 | |
---|
| 457 | bool caMarche = true; |
---|
| 458 | |
---|
| 459 | |
---|
| 460 | string diagnosticErrors; |
---|
| 461 | string diagnosticWarnings; |
---|
| 462 | for (int a = 0; a < computingBlocks_.size(); a++) |
---|
| 463 | { |
---|
| 464 | if ( !computingBlocks_.at(a)->checkCoherence(diagnosticErrors, diagnosticWarnings) ) caMarche = false; |
---|
| 465 | }//a |
---|
| 466 | cout << " erreurs : " << diagnosticErrors << endl; |
---|
| 467 | if ( !diagnosticErrors.empty() ) dataManager_->messageEcran("ERROR", diagnosticErrors); |
---|
| 468 | if ( !diagnosticWarnings.empty() ) { |
---|
| 469 | cout << " y a des warnings " << diagnosticWarnings << endl; |
---|
| 470 | dataManager_->messageEcran("WARNING",diagnosticWarnings); |
---|
| 471 | } |
---|
| 472 | return caMarche; |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | abstractElement* expandedMachine::getElementPointer( unsigned rang) { |
---|
| 476 | if ( rang > elements_.size() ) return NULL; |
---|
| 477 | return elements_.at(rang); |
---|
| 478 | } |
---|
| 479 | |
---|