1 | /*
|
---|
2 | * Dialog.cpp
|
---|
3 | *
|
---|
4 | * Created on: Jan 5, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | // include config.h
|
---|
9 | #ifdef HAVE_CONFIG_H
|
---|
10 | #include <config.h>
|
---|
11 | #endif
|
---|
12 |
|
---|
13 | #include "Helpers/MemDebug.hpp"
|
---|
14 |
|
---|
15 | #include "Dialog.hpp"
|
---|
16 | #include "Actions/ValueStorage.hpp"
|
---|
17 |
|
---|
18 | #include "Helpers/Verbose.hpp"
|
---|
19 | #include "atom.hpp"
|
---|
20 | #include "element.hpp"
|
---|
21 | #include "molecule.hpp"
|
---|
22 | #include "LinearAlgebra/Vector.hpp"
|
---|
23 | #include "LinearAlgebra/Matrix.hpp"
|
---|
24 | #include "Box.hpp"
|
---|
25 |
|
---|
26 | using namespace std;
|
---|
27 |
|
---|
28 | Dialog::Dialog()
|
---|
29 | {
|
---|
30 | }
|
---|
31 |
|
---|
32 | Dialog::~Dialog()
|
---|
33 | {
|
---|
34 | list<Query*>::iterator iter;
|
---|
35 | for(iter=queries.begin();iter!=queries.end();iter++){
|
---|
36 | delete (*iter);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | void Dialog::registerQuery(Query *query){
|
---|
41 | queries.push_back(query);
|
---|
42 | }
|
---|
43 |
|
---|
44 | bool Dialog::display(){
|
---|
45 | if(checkAll()){
|
---|
46 | setAll();
|
---|
47 | return true;
|
---|
48 | }
|
---|
49 | else{
|
---|
50 | return false;
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | bool Dialog::checkAll(){
|
---|
55 | list<Query*>::iterator iter;
|
---|
56 | bool retval = true;
|
---|
57 | for(iter=queries.begin(); iter!=queries.end(); iter++){
|
---|
58 | retval &= (*iter)->handle();
|
---|
59 | // if any query fails (is canceled), we can end the handling process
|
---|
60 | if(!retval) {
|
---|
61 | DoeLog(1) && (eLog() << Verbose(1) << "The following query failed: " << (**iter).getTitle() << "." << endl);
|
---|
62 | break;
|
---|
63 | }
|
---|
64 | }
|
---|
65 | return retval;
|
---|
66 | }
|
---|
67 |
|
---|
68 | void Dialog::setAll(){
|
---|
69 | list<Query*>::iterator iter;
|
---|
70 | for(iter=queries.begin(); iter!=queries.end(); iter++) {
|
---|
71 | (*iter)->setResult();
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | bool Dialog::hasQueries(){
|
---|
76 | return queries.size();
|
---|
77 | }
|
---|
78 |
|
---|
79 | /****************** Query types Infrastructure **************************/
|
---|
80 |
|
---|
81 | // Base class
|
---|
82 | Dialog::Query::Query(string _title, string _description) :
|
---|
83 | title(_title),
|
---|
84 | description(_description)
|
---|
85 | {}
|
---|
86 |
|
---|
87 | Dialog::Query::~Query() {}
|
---|
88 |
|
---|
89 | const std::string Dialog::Query::getTitle() const{
|
---|
90 | return title;
|
---|
91 | }
|
---|
92 |
|
---|
93 | const std::string Dialog::Query::getDescription() const{
|
---|
94 | return description;
|
---|
95 | }
|
---|
96 | // empty Queries
|
---|
97 |
|
---|
98 | Dialog::EmptyQuery::EmptyQuery(string title, std::string description) :
|
---|
99 | Query(title, description)
|
---|
100 | {}
|
---|
101 |
|
---|
102 | Dialog::EmptyQuery::~EmptyQuery() {}
|
---|
103 |
|
---|
104 | void Dialog::EmptyQuery::setResult() {
|
---|
105 | }
|
---|
106 |
|
---|
107 | // Int Queries
|
---|
108 |
|
---|
109 | Dialog::IntQuery::IntQuery(string title, std::string description) :
|
---|
110 | Query(title, description)
|
---|
111 | {}
|
---|
112 |
|
---|
113 | Dialog::IntQuery::~IntQuery() {}
|
---|
114 |
|
---|
115 | void Dialog::IntQuery::setResult() {
|
---|
116 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
117 | }
|
---|
118 |
|
---|
119 | // Ints Queries
|
---|
120 |
|
---|
121 | Dialog::IntsQuery::IntsQuery(string title, std::string description) :
|
---|
122 | Query(title, description)
|
---|
123 | {}
|
---|
124 |
|
---|
125 | Dialog::IntsQuery::~IntsQuery() {}
|
---|
126 |
|
---|
127 | void Dialog::IntsQuery::setResult() {
|
---|
128 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
129 | }
|
---|
130 |
|
---|
131 | // Bool Queries
|
---|
132 |
|
---|
133 | Dialog::BooleanQuery::BooleanQuery(string title,std::string description) :
|
---|
134 | Query(title, description)
|
---|
135 | {}
|
---|
136 |
|
---|
137 | Dialog::BooleanQuery::~BooleanQuery() {}
|
---|
138 |
|
---|
139 | void Dialog::BooleanQuery::setResult() {
|
---|
140 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
141 | }
|
---|
142 |
|
---|
143 | // String Queries
|
---|
144 |
|
---|
145 | Dialog::StringQuery::StringQuery(string title,std::string _description) :
|
---|
146 | Query(title, _description)
|
---|
147 | {}
|
---|
148 |
|
---|
149 | Dialog::StringQuery::~StringQuery() {};
|
---|
150 |
|
---|
151 | void Dialog::StringQuery::setResult() {
|
---|
152 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
153 | }
|
---|
154 |
|
---|
155 | // Strings Queries
|
---|
156 |
|
---|
157 | Dialog::StringsQuery::StringsQuery(string title,std::string _description) :
|
---|
158 | Query(title, _description)
|
---|
159 | {}
|
---|
160 |
|
---|
161 | Dialog::StringsQuery::~StringsQuery() {};
|
---|
162 |
|
---|
163 | void Dialog::StringsQuery::setResult() {
|
---|
164 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
165 | }
|
---|
166 |
|
---|
167 | // Double Queries
|
---|
168 |
|
---|
169 | Dialog::DoubleQuery::DoubleQuery(string title, std::string _description) :
|
---|
170 | Query(title, _description)
|
---|
171 | {}
|
---|
172 |
|
---|
173 | Dialog::DoubleQuery::~DoubleQuery() {};
|
---|
174 |
|
---|
175 | void Dialog::DoubleQuery::setResult() {
|
---|
176 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
177 | }
|
---|
178 |
|
---|
179 | // Doubles Queries
|
---|
180 |
|
---|
181 | Dialog::DoublesQuery::DoublesQuery(string title, std::string _description) :
|
---|
182 | Query(title, _description)
|
---|
183 | {}
|
---|
184 |
|
---|
185 | Dialog::DoublesQuery::~DoublesQuery() {};
|
---|
186 |
|
---|
187 | void Dialog::DoublesQuery::setResult() {
|
---|
188 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
189 | }
|
---|
190 |
|
---|
191 |
|
---|
192 | // Atom Queries
|
---|
193 |
|
---|
194 | Dialog::AtomQuery::AtomQuery(string title, std::string _description) :
|
---|
195 | Query(title, _description),
|
---|
196 | tmp(0)
|
---|
197 | {}
|
---|
198 |
|
---|
199 | Dialog::AtomQuery::~AtomQuery() {}
|
---|
200 |
|
---|
201 | void Dialog::AtomQuery::setResult() {
|
---|
202 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
203 | }
|
---|
204 |
|
---|
205 | // Atoms Queries
|
---|
206 |
|
---|
207 | Dialog::AtomsQuery::AtomsQuery(string title, std::string _description) :
|
---|
208 | Query(title, _description),
|
---|
209 | tmp(0)
|
---|
210 | {}
|
---|
211 |
|
---|
212 | Dialog::AtomsQuery::~AtomsQuery() {}
|
---|
213 |
|
---|
214 | void Dialog::AtomsQuery::setResult() {
|
---|
215 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
216 | }
|
---|
217 |
|
---|
218 | // Molecule Queries
|
---|
219 |
|
---|
220 | Dialog::MoleculeQuery::MoleculeQuery(string title, std::string _description) :
|
---|
221 | Query(title, _description),
|
---|
222 | tmp(0)
|
---|
223 | {}
|
---|
224 |
|
---|
225 | Dialog::MoleculeQuery::~MoleculeQuery() {}
|
---|
226 |
|
---|
227 | void Dialog::MoleculeQuery::setResult() {
|
---|
228 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
229 | }
|
---|
230 |
|
---|
231 | // Molecules Queries
|
---|
232 |
|
---|
233 | Dialog::MoleculesQuery::MoleculesQuery(string title, std::string _description) :
|
---|
234 | Query(title, _description),
|
---|
235 | tmp(0)
|
---|
236 | {}
|
---|
237 |
|
---|
238 | Dialog::MoleculesQuery::~MoleculesQuery() {}
|
---|
239 |
|
---|
240 | void Dialog::MoleculesQuery::setResult() {
|
---|
241 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
242 | }
|
---|
243 |
|
---|
244 | // Vector Queries
|
---|
245 |
|
---|
246 | Dialog::VectorQuery::VectorQuery(std::string title,bool _check, std::string _description) :
|
---|
247 | Query(title, _description),
|
---|
248 | check(_check)
|
---|
249 | {}
|
---|
250 |
|
---|
251 | Dialog::VectorQuery::~VectorQuery()
|
---|
252 | {}
|
---|
253 |
|
---|
254 | void Dialog::VectorQuery::setResult() {
|
---|
255 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
256 | }
|
---|
257 |
|
---|
258 | // Vectors Queries
|
---|
259 |
|
---|
260 | Dialog::VectorsQuery::VectorsQuery(std::string title,bool _check, std::string _description) :
|
---|
261 | Query(title, _description),
|
---|
262 | check(_check)
|
---|
263 | {}
|
---|
264 |
|
---|
265 | Dialog::VectorsQuery::~VectorsQuery()
|
---|
266 | {}
|
---|
267 |
|
---|
268 | void Dialog::VectorsQuery::setResult() {
|
---|
269 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
270 | }
|
---|
271 |
|
---|
272 | // Box Queries
|
---|
273 |
|
---|
274 | Dialog::BoxQuery::BoxQuery(std::string title, std::string _description) :
|
---|
275 | Query(title, _description)
|
---|
276 | {}
|
---|
277 |
|
---|
278 | Dialog::BoxQuery::~BoxQuery()
|
---|
279 | {}
|
---|
280 |
|
---|
281 | void Dialog::BoxQuery::setResult() {
|
---|
282 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
283 | }
|
---|
284 |
|
---|
285 | // Element Queries
|
---|
286 | Dialog::ElementQuery::ElementQuery(std::string title, std::string _description) :
|
---|
287 | Query(title, _description)
|
---|
288 | {}
|
---|
289 |
|
---|
290 | Dialog::ElementQuery::~ElementQuery(){}
|
---|
291 |
|
---|
292 | void Dialog::ElementQuery::setResult(){
|
---|
293 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
294 | }
|
---|
295 |
|
---|
296 | // Elements Queries
|
---|
297 | Dialog::ElementsQuery::ElementsQuery(std::string title, std::string _description) :
|
---|
298 | Query(title, _description)
|
---|
299 | {}
|
---|
300 |
|
---|
301 | Dialog::ElementsQuery::~ElementsQuery(){}
|
---|
302 |
|
---|
303 | void Dialog::ElementsQuery::setResult(){
|
---|
304 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
305 | }
|
---|