-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneral.cpp
More file actions
228 lines (199 loc) · 5.64 KB
/
general.cpp
File metadata and controls
228 lines (199 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include "general.h"
General::General()
{
aleatoire = new QRandomGenerator(QDateTime::currentSecsSinceEpoch()); //Seed choisi en fonction de la date
pH = false;
changementRecent = true;
indexH3O = -1;
indexHO = -1;
possedeUnFichier = false;
nom = "";
nomDeFichier = "";
description = "";
}
void General::setTout(General change)
{
possedeUnFichier = change.getPossedeUnFichier();
nomDeFichier = change.getNomDeFichier();
nom = change.getNom();
description = change.getDescription();
setPH(change.getPH());
qDeleteAll(particules);
particules.clear();
qDeleteAll(reactions);
reactions.clear();
for (int IDp(0); IDp < change.nombreParticule(); IDp++) {
particules.append(change.getParticule(IDp));
}
for (int IDp(0); IDp < change.nombreReaction(); IDp++) {
reactions.append(change.getReaction(IDp));
for (int IDr(0); IDr < reactions[IDp]->getReactifs().size(); IDr++) {
reactions[IDp]->setReactif(IDr, particules[reactions[IDp]->getReactifsID()[IDr]]);
}
for (int IDr(0); IDr < reactions[IDp]->getProduits().size(); IDr++) {
reactions[IDp]->setProduit(IDr, particules[reactions[IDp]->getProduitsID()[IDr]]);
}
for (int IDr(0); IDr < reactions[IDp]->getCatalyseurs().size(); IDr++) {
reactions[IDp]->setCatalyseur(IDr, particules[reactions[IDp]->getCatalyseursID()[IDr]]);
}
}
indexHO = change.getIndexHO();
indexH3O = change.getIndexH3O();
changementRecent = true;
}
General* General::creerCopie()
{
General* returned(new General);
returned->setPossedeUnFichier(possedeUnFichier);
returned->setNomDeFichier(nomDeFichier);
returned->setNom(nom);
returned->setDescription(description);
returned->setPH(pH);
returned->setChangementRecent(true);
QList<DonneeParticule*> nouvellesParticules;
for (int IDp(0); IDp < nombreParticule(); IDp++) {
returned->addParticule(*particules[IDp]);
nouvellesParticules.append(returned->getParticule(IDp));
}
for (int IDp(0); IDp < nombreReaction(); IDp++) {
returned->addReaction(*reactions[IDp]);
for (int IDr(0); IDr < returned->getReaction(IDp)->getReactifs().size(); IDr++) {
returned->getReaction(IDp)->setReactif(IDr, nouvellesParticules[returned->getReaction(IDp)->getReactifs()[IDr]->getID()]);
}
for (int IDr(0); IDr < returned->getReaction(IDp)->getProduits().size(); IDr++) {
returned->getReaction(IDp)->setProduit(IDr, nouvellesParticules[returned->getReaction(IDp)->getProduits()[IDr]->getID()]);
}
for (int IDr(0); IDr < returned->getReaction(IDp)->getCatalyseurs().size(); IDr++) {
returned->getReaction(IDp)->setCatalyseur(IDr, nouvellesParticules[returned->getReaction(IDp)->getCatalyseurs()[IDr]->getID()]);
}
}
return returned;
}
void General::vider()
{
qDeleteAll(particules);
qDeleteAll(reactions);
}
bool General::getPH() const
{
return pH;
}
void General::setPH(bool value)
{
pH = value;
}
DonneeParticule* General::getParticule(int index) const
{
return particules[index];
}
void General::setParticule(int index, const DonneeParticule &value)
{
delete particules[index];
particules[index] = new DonneeParticule(value);
changementRecent = true;
switch (value.getPHValeur()) {
case -1:
indexHO = index;
break;
case 1:
indexH3O = index;
break;
}
}
void General::addParticule(const DonneeParticule &value)
{
particules.append(new DonneeParticule(value));
changementRecent = true;
switch (value.getPHValeur()) {
case -1:
indexHO = particules.size() - 1;
break;
case 1:
indexH3O = particules.size() - 1;
break;
}
}
int General::nombreParticule() const
{
return particules.size();
}
DonneeReaction *General::getReaction(int index) const
{
return reactions[index];
}
void General::setReaction(int index, const DonneeReaction &value)
{
DonneeReaction* suppression(reactions[index]);
reactions[index] = new DonneeReaction(value);
changementRecent = true;
delete suppression;
}
void General::addReaction(const DonneeReaction &value)
{
reactions.append(new DonneeReaction(value));
changementRecent = true;
}
int General::nombreReaction() const
{
return reactions.size();
}
QRandomGenerator* General::getAleatoire() const
{
return aleatoire;
}
bool General::getChangementRecent() const
{
return changementRecent;
}
void General::setChangementRecent(bool value)
{
changementRecent = value;
}
int General::getIndexH3O() const
{
return indexH3O;
}
int General::getIndexHO() const
{
return indexHO;
}
QList<DonneeParticule *> General::getParticules() const
{
return particules;
}
QList<DonneeReaction *> General::getReactions() const
{
return reactions;
}
QString General::getNomDeFichier() const
{
return nomDeFichier;
}
void General::setNomDeFichier(const QString &value)
{
nomDeFichier = value;
}
bool General::getPossedeUnFichier() const
{
return possedeUnFichier;
}
void General::setPossedeUnFichier(bool value)
{
possedeUnFichier = value;
}
QString General::getNom() const
{
return nom;
}
void General::setNom(const QString &value)
{
nom = value;
}
QString General::getDescription() const
{
return description;
}
void General::setDescription(const QString &value)
{
description = value;
}