1 | // |
---|
2 | // sector.cpp |
---|
3 | // PSPA |
---|
4 | // |
---|
5 | // Created by Garnier Laurent on 10/12/13. |
---|
6 | // Copyright (c) 2013 Garnier Laurent. All rights reserved. |
---|
7 | // |
---|
8 | |
---|
9 | #include "sector.h" |
---|
10 | |
---|
11 | #include "sectionToExecute.h" |
---|
12 | #include "dataManager.h" |
---|
13 | #include "elementDrift.h" |
---|
14 | #include "elementRfgun.h" |
---|
15 | #include "elementCell.h" |
---|
16 | #include "elementSoleno.h" |
---|
17 | #include "elementBend.h" |
---|
18 | #include "elementBeam.h" |
---|
19 | #include "elementFit.h" |
---|
20 | #include "elementSnapshot.h" |
---|
21 | #include "elementMultipole.h" |
---|
22 | |
---|
23 | sector::sector(dataManager* data, std::string name): |
---|
24 | reflected_(false), |
---|
25 | duplicatedFrom_(NULL), |
---|
26 | repetitionNumber_(1), |
---|
27 | currentBeam_(NULL), |
---|
28 | name_(name), |
---|
29 | dataManager_(data), |
---|
30 | sectorParam_(this) |
---|
31 | { |
---|
32 | |
---|
33 | } |
---|
34 | |
---|
35 | sector::~sector() { |
---|
36 | } |
---|
37 | |
---|
38 | abstractElement* sector::addElementAfter(nomdElements::typedElement eType ,abstractElement* previousElement){ |
---|
39 | |
---|
40 | // create a new abstractElement |
---|
41 | // FIXME : To be move in an abstractFactory in the controler !! |
---|
42 | abstractElement* currentElement = NULL; |
---|
43 | switch ( eType ) { |
---|
44 | case nomdElements::RFgun : |
---|
45 | currentElement = new elementRfgun(); |
---|
46 | break; |
---|
47 | case nomdElements::drift : |
---|
48 | currentElement = new elementDrift(); |
---|
49 | break; |
---|
50 | case nomdElements::cell : |
---|
51 | currentElement = new elementCell(); |
---|
52 | break; |
---|
53 | case nomdElements::bend : |
---|
54 | currentElement = new elementBend(); |
---|
55 | break; |
---|
56 | case nomdElements::soleno : |
---|
57 | currentElement = new elementSoleno(); |
---|
58 | break; |
---|
59 | case nomdElements::beam : |
---|
60 | currentElement = new elementBeam(); |
---|
61 | break; |
---|
62 | case nomdElements::fit : |
---|
63 | currentElement = new elementFit(); |
---|
64 | break; |
---|
65 | case nomdElements::mpole : |
---|
66 | currentElement = new elementMultipole(); |
---|
67 | break; |
---|
68 | case nomdElements::snapshot : |
---|
69 | { |
---|
70 | // FIXME : Snapshot a gérér |
---|
71 | /* int incr = dataManager_->getPspaApplication()->getExtensionFile(); |
---|
72 | incr++; |
---|
73 | dataManager_->getPspaApplication()->setExtensionFile(incr); |
---|
74 | */ |
---|
75 | currentElement = new elementSnapshot(); |
---|
76 | break; |
---|
77 | } |
---|
78 | } |
---|
79 | if (!currentElement) { |
---|
80 | return NULL; |
---|
81 | } |
---|
82 | addElementAfter(currentElement,previousElement); |
---|
83 | return currentElement; |
---|
84 | |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | void sector::addElementAfter(abstractElement* currentElement ,abstractElement* previousElement){ |
---|
89 | // if the previous element is NULL, it will try to add at the beginning of the first section |
---|
90 | |
---|
91 | if (previousElement == NULL) { |
---|
92 | if (sectionToExecute_.size() == 0) { |
---|
93 | sectionToExecute_.push_back(new sectionToExecute(currentElement,NULL,dataManager_,this)); |
---|
94 | } else { |
---|
95 | sectionToExecute* section = sectionToExecute_.front(); |
---|
96 | section->insertAtFirst(currentElement); |
---|
97 | } |
---|
98 | } else { |
---|
99 | |
---|
100 | for (unsigned int i=0; i<sectionToExecute_.size(); i++) { |
---|
101 | sectionToExecute* section = sectionToExecute_[i]; |
---|
102 | if (section->insertAfter(previousElement,currentElement)) { |
---|
103 | return; |
---|
104 | } |
---|
105 | } |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | void sector::clearSectionToExecute() |
---|
110 | { |
---|
111 | unsigned k; |
---|
112 | for(k = 0; k < sectionToExecute_.size(); k++) |
---|
113 | { |
---|
114 | if ( sectionToExecute_[k] != NULL ) clearSectionToExecute(k); |
---|
115 | } |
---|
116 | sectionToExecute_.clear(); |
---|
117 | } |
---|
118 | |
---|
119 | void sector::clearSectionToExecute(int a) |
---|
120 | { |
---|
121 | cout << " dataManager::clearSectionToExecute : effacement de la section d'index = " << a << endl; |
---|
122 | if (a < 0) return; |
---|
123 | if (a >= (int)sectionToExecute_.size()) return; |
---|
124 | |
---|
125 | // lors de la creation de la section on a fait un 'new' d'un |
---|
126 | // softwareXXXX : on fait ici le 'delete' |
---|
127 | |
---|
128 | const abstractSoftware* soft = sectionToExecute_.at(a)->getSoftware(); |
---|
129 | if ( soft != NULL ) delete soft; |
---|
130 | delete sectionToExecute_[a]; |
---|
131 | sectionToExecute_.erase (sectionToExecute_.begin()+a); |
---|
132 | } |
---|