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 | #include "elementQuadrupole.h" |
---|
23 | #include "elementSextupole.h" |
---|
24 | |
---|
25 | sector::sector(dataManager* data, std::string name): |
---|
26 | reflected_(false), |
---|
27 | duplicatedFrom_(NULL), |
---|
28 | repetitionNumber_(1), |
---|
29 | currentBeam_(NULL), |
---|
30 | name_(name), |
---|
31 | dataManager_(data), |
---|
32 | sectorParam_(this) |
---|
33 | { |
---|
34 | |
---|
35 | } |
---|
36 | |
---|
37 | sector::~sector() { |
---|
38 | } |
---|
39 | |
---|
40 | abstractElement* sector::addElementAfter(nomdElements::typedElement eType ,abstractElement* previousElement) |
---|
41 | { |
---|
42 | |
---|
43 | // create a new abstractElement |
---|
44 | // FIXME : To be move in an abstractFactory in the controler !! |
---|
45 | abstractElement* currentElement = NULL; |
---|
46 | switch ( eType ) |
---|
47 | { |
---|
48 | case nomdElements::RFgun : |
---|
49 | currentElement = new elementRfgun(); |
---|
50 | break; |
---|
51 | case nomdElements::drift : |
---|
52 | currentElement = new elementDrift(); |
---|
53 | break; |
---|
54 | case nomdElements::cell : |
---|
55 | currentElement = new elementCell(); |
---|
56 | break; |
---|
57 | case nomdElements::bend : |
---|
58 | currentElement = new elementBend(); |
---|
59 | break; |
---|
60 | case nomdElements::soleno : |
---|
61 | currentElement = new elementSoleno(); |
---|
62 | break; |
---|
63 | case nomdElements::beam : |
---|
64 | currentElement = new elementBeam(); |
---|
65 | break; |
---|
66 | case nomdElements::fit : |
---|
67 | currentElement = new elementFit(); |
---|
68 | break; |
---|
69 | case nomdElements::mpole : |
---|
70 | currentElement = new elementMultipole(); |
---|
71 | break; |
---|
72 | case nomdElements::qpole : |
---|
73 | currentElement = new elementQuadrupole(); |
---|
74 | break; |
---|
75 | case nomdElements::spole : |
---|
76 | currentElement = new elementSextupole(); |
---|
77 | break; |
---|
78 | case nomdElements::snapshot : |
---|
79 | { |
---|
80 | // FIXME : Snapshot a gérér |
---|
81 | /* int incr = dataManager_->getPspaApplication()->getExtensionFile(); |
---|
82 | incr++; |
---|
83 | dataManager_->getPspaApplication()->setExtensionFile(incr); |
---|
84 | */ |
---|
85 | currentElement = new elementSnapshot(); |
---|
86 | break; |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | if (!currentElement) { |
---|
91 | return NULL; |
---|
92 | } |
---|
93 | addElementAfter(currentElement,previousElement); |
---|
94 | return currentElement; |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | void sector::addElementAfter(abstractElement* currentElement ,abstractElement* previousElement){ |
---|
99 | // if the previous element is NULL, it will try to add at the beginning of the first section |
---|
100 | |
---|
101 | if (previousElement == NULL) { |
---|
102 | elements_.insert ( elements_.begin() ,currentElement); |
---|
103 | // if (sectionToExecute_.size() == 0) { |
---|
104 | // sectionToExecute_.push_back(new sectionToExecute(currentElement,NULL,dataManager_,this)); |
---|
105 | // } else { |
---|
106 | // sectionToExecute* section = sectionToExecute_.front(); |
---|
107 | // section->insertAtFirst(currentElement); |
---|
108 | // } |
---|
109 | } else { |
---|
110 | insertAfter(previousElement,currentElement); |
---|
111 | // for (unsigned int i=0; i<sectionToExecute_.size(); i++) { |
---|
112 | // sectionToExecute* section = sectionToExecute_[i]; |
---|
113 | // if (section->insertAfter(previousElement,currentElement)) { |
---|
114 | // return; |
---|
115 | // } |
---|
116 | // } |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | bool sector::insertAfter(abstractElement* previousElement,abstractElement* currentElement) { |
---|
122 | |
---|
123 | std::vector<abstractElement*>::iterator it; |
---|
124 | for (it = elements_.begin(); it < elements_.end(); it++) { |
---|
125 | if (*it == previousElement ) { |
---|
126 | elements_.insert (it+1,currentElement); |
---|
127 | return true; |
---|
128 | } |
---|
129 | } |
---|
130 | return false; |
---|
131 | } |
---|
132 | |
---|
133 | bool sector::isInside(abstractElement* previousElement) { |
---|
134 | for (unsigned int a=0; a< elements_.size(); a++) { |
---|
135 | if (elements_[a] == previousElement ) { |
---|
136 | return true; |
---|
137 | } |
---|
138 | } |
---|
139 | return false; |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | |
---|
144 | void sector::removeElement(abstractElement* currentElement) { |
---|
145 | if (currentElement == NULL) return; |
---|
146 | std::vector<abstractElement*>::iterator it; |
---|
147 | for (it = elements_.begin(); it < elements_.end(); it++) { |
---|
148 | if (*it == currentElement ) { |
---|
149 | elements_.erase(it); |
---|
150 | return; |
---|
151 | } |
---|
152 | } |
---|
153 | // for (unsigned int i=0; i<sectionToExecute_.size(); i++) { |
---|
154 | // sectionToExecute* section = sectionToExecute_[i]; |
---|
155 | |
---|
156 | // if (section->isInside(currentElement)) { |
---|
157 | // section->removeElement(currentElement); |
---|
158 | // } |
---|
159 | // } |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | // void sector::clearSectionToExecute() |
---|
164 | // { |
---|
165 | // unsigned k; |
---|
166 | // for(k = 0; k < sectionToExecute_.size(); k++) |
---|
167 | // { |
---|
168 | // if ( sectionToExecute_[k] != NULL ) clearSectionToExecute(k); |
---|
169 | // } |
---|
170 | // sectionToExecute_.clear(); |
---|
171 | // } |
---|
172 | |
---|
173 | // void sector::clearSectionToExecute(int a) |
---|
174 | // { |
---|
175 | // cout << " dataManager::clearSectionToExecute : effacement de la section d'index = " << a << endl; |
---|
176 | // if (a < 0) return; |
---|
177 | // if (a >= (int)sectionToExecute_.size()) return; |
---|
178 | |
---|
179 | // // lors de la creation de la section on a fait un 'new' d'un |
---|
180 | // // softwareXXXX : on fait ici le 'delete' |
---|
181 | |
---|
182 | // const abstractSoftware* soft = sectionToExecute_.at(a)->getSoftware(); |
---|
183 | // if ( soft != NULL ) delete soft; |
---|
184 | // delete sectionToExecute_[a]; |
---|
185 | // sectionToExecute_.erase (sectionToExecute_.begin()+a); |
---|
186 | // } |
---|