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