1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Dialog.cpp
|
---|
10 | *
|
---|
11 | * Created on: Jan 5, 2010
|
---|
12 | * Author: crueger
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "Helpers/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include "Dialog.hpp"
|
---|
23 | #include "Actions/ValueStorage.hpp"
|
---|
24 |
|
---|
25 | #include "Helpers/Verbose.hpp"
|
---|
26 | #include "atom.hpp"
|
---|
27 | #include "Box.hpp"
|
---|
28 | #include "element.hpp"
|
---|
29 | #include "molecule.hpp"
|
---|
30 | #include "LinearAlgebra/BoxVector.hpp"
|
---|
31 | #include "LinearAlgebra/Vector.hpp"
|
---|
32 | #include "LinearAlgebra/Matrix.hpp"
|
---|
33 |
|
---|
34 | using namespace std;
|
---|
35 |
|
---|
36 | Dialog::Dialog()
|
---|
37 | {
|
---|
38 | }
|
---|
39 |
|
---|
40 | Dialog::~Dialog()
|
---|
41 | {
|
---|
42 | list<Query*>::iterator iter;
|
---|
43 | for(iter=queries.begin();iter!=queries.end();iter++){
|
---|
44 | delete (*iter);
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | void Dialog::registerQuery(Query *query){
|
---|
49 | queries.push_back(query);
|
---|
50 | }
|
---|
51 |
|
---|
52 | bool Dialog::display(){
|
---|
53 | if(checkAll()){
|
---|
54 | setAll();
|
---|
55 | return true;
|
---|
56 | }
|
---|
57 | else{
|
---|
58 | return false;
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | bool Dialog::checkAll(){
|
---|
63 | list<Query*>::iterator iter;
|
---|
64 | bool retval = true;
|
---|
65 | for(iter=queries.begin(); iter!=queries.end(); iter++){
|
---|
66 | retval &= (*iter)->handle();
|
---|
67 | // if any query fails (is canceled), we can end the handling process
|
---|
68 | if(!retval) {
|
---|
69 | DoeLog(1) && (eLog() << Verbose(1) << "The following query failed: " << (**iter).getTitle() << "." << endl);
|
---|
70 | break;
|
---|
71 | }
|
---|
72 | }
|
---|
73 | return retval;
|
---|
74 | }
|
---|
75 |
|
---|
76 | void Dialog::setAll(){
|
---|
77 | list<Query*>::iterator iter;
|
---|
78 | for(iter=queries.begin(); iter!=queries.end(); iter++) {
|
---|
79 | (*iter)->setResult();
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | bool Dialog::hasQueries(){
|
---|
84 | return queries.size();
|
---|
85 | }
|
---|
86 |
|
---|
87 | template <> void Dialog::query<void *>(const char *token, std::string description)
|
---|
88 | {
|
---|
89 | queryEmpty(token, description);
|
---|
90 | }
|
---|
91 |
|
---|
92 | template <> void Dialog::query<bool>(const char *token, std::string description)
|
---|
93 | {
|
---|
94 | queryBoolean(token, description);
|
---|
95 | }
|
---|
96 |
|
---|
97 | template <> void Dialog::query<int>(const char *token, std::string description)
|
---|
98 | {
|
---|
99 | queryInt(token, description);
|
---|
100 | }
|
---|
101 |
|
---|
102 | template <> void Dialog::query< std::vector<int> >(const char *token, std::string description)
|
---|
103 | {
|
---|
104 | queryInts(token, description);
|
---|
105 | }
|
---|
106 |
|
---|
107 | template <> void Dialog::query<double>(const char *token, std::string description)
|
---|
108 | {
|
---|
109 | queryDouble(token, description);
|
---|
110 | }
|
---|
111 |
|
---|
112 | template <> void Dialog::query< std::vector<double> >(const char *token, std::string description)
|
---|
113 | {
|
---|
114 | queryDoubles(token, description);
|
---|
115 | }
|
---|
116 |
|
---|
117 | template <> void Dialog::query<std::string>(const char *token, std::string description)
|
---|
118 | {
|
---|
119 | queryString(token, description);
|
---|
120 | }
|
---|
121 |
|
---|
122 | template <> void Dialog::query< std::vector<std::string> >(const char *token, std::string description)
|
---|
123 | {
|
---|
124 | queryStrings(token, description);
|
---|
125 | }
|
---|
126 |
|
---|
127 | template <> void Dialog::query<atom *>(const char *token, std::string description)
|
---|
128 | {
|
---|
129 | queryAtom(token, description);
|
---|
130 | }
|
---|
131 |
|
---|
132 | template <> void Dialog::query< std::vector<atom *> >(const char *token, std::string description)
|
---|
133 | {
|
---|
134 | queryAtoms(token, description);
|
---|
135 | }
|
---|
136 |
|
---|
137 | template <> void Dialog::query<molecule *>(const char *token, std::string description)
|
---|
138 | {
|
---|
139 | queryMolecule(token, description);
|
---|
140 | }
|
---|
141 |
|
---|
142 | template <> void Dialog::query< std::vector<molecule *> >(const char *token, std::string description)
|
---|
143 | {
|
---|
144 | queryMolecules(token, description);
|
---|
145 | }
|
---|
146 |
|
---|
147 | template <> void Dialog::query<Vector>(const char *token, std::string description)
|
---|
148 | {
|
---|
149 | queryVector(token, false, description);
|
---|
150 | }
|
---|
151 |
|
---|
152 | template <> void Dialog::query< std::vector<Vector> >(const char *token, std::string description)
|
---|
153 | {
|
---|
154 | queryVectors(token, false, description);
|
---|
155 | }
|
---|
156 |
|
---|
157 | template <> void Dialog::query<BoxVector>(const char *token, std::string description)
|
---|
158 | {
|
---|
159 | queryVector(token, true, description);
|
---|
160 | }
|
---|
161 |
|
---|
162 | template <> void Dialog::query< std::vector<BoxVector> >(const char *token, std::string description)
|
---|
163 | {
|
---|
164 | queryVectors(token, true, description);
|
---|
165 | }
|
---|
166 |
|
---|
167 | template <> void Dialog::query<Box>(const char *token, std::string description)
|
---|
168 | {
|
---|
169 | queryBox(token, description);
|
---|
170 | }
|
---|
171 |
|
---|
172 | template <> void Dialog::query<const element *>(const char *token, std::string description)
|
---|
173 | {
|
---|
174 | queryElement(token, description);
|
---|
175 | }
|
---|
176 |
|
---|
177 | template <> void Dialog::query< std::vector<const element *> >(const char *token, std::string description)
|
---|
178 | {
|
---|
179 | queryElements(token, description);
|
---|
180 | }
|
---|
181 |
|
---|
182 | template <> void Dialog::query< boost::filesystem::path >(const char *token, std::string description)
|
---|
183 | {
|
---|
184 | queryFile(token, description);
|
---|
185 | }
|
---|
186 |
|
---|
187 | /****************** Query types Infrastructure **************************/
|
---|
188 |
|
---|
189 | // Base class
|
---|
190 | Dialog::Query::Query(string _title, string _description) :
|
---|
191 | title(_title),
|
---|
192 | description(_description)
|
---|
193 | {}
|
---|
194 |
|
---|
195 | Dialog::Query::~Query() {}
|
---|
196 |
|
---|
197 | const std::string Dialog::Query::getTitle() const{
|
---|
198 | return title;
|
---|
199 | }
|
---|
200 |
|
---|
201 | const std::string Dialog::Query::getDescription() const{
|
---|
202 | return description;
|
---|
203 | }
|
---|
204 | // empty Queries
|
---|
205 |
|
---|
206 | Dialog::EmptyQuery::EmptyQuery(string title, std::string description) :
|
---|
207 | Query(title, description)
|
---|
208 | {}
|
---|
209 |
|
---|
210 | Dialog::EmptyQuery::~EmptyQuery() {}
|
---|
211 |
|
---|
212 | void Dialog::EmptyQuery::setResult() {
|
---|
213 | }
|
---|
214 |
|
---|
215 | // Int Queries
|
---|
216 |
|
---|
217 | Dialog::IntQuery::IntQuery(string title, std::string description) :
|
---|
218 | Query(title, description)
|
---|
219 | {}
|
---|
220 |
|
---|
221 | Dialog::IntQuery::~IntQuery() {}
|
---|
222 |
|
---|
223 | void Dialog::IntQuery::setResult() {
|
---|
224 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
225 | }
|
---|
226 |
|
---|
227 | // Ints Queries
|
---|
228 |
|
---|
229 | Dialog::IntsQuery::IntsQuery(string title, std::string description) :
|
---|
230 | Query(title, description)
|
---|
231 | {}
|
---|
232 |
|
---|
233 | Dialog::IntsQuery::~IntsQuery() {}
|
---|
234 |
|
---|
235 | void Dialog::IntsQuery::setResult() {
|
---|
236 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
237 | }
|
---|
238 |
|
---|
239 | // Bool Queries
|
---|
240 |
|
---|
241 | Dialog::BooleanQuery::BooleanQuery(string title,std::string description) :
|
---|
242 | Query(title, description)
|
---|
243 | {}
|
---|
244 |
|
---|
245 | Dialog::BooleanQuery::~BooleanQuery() {}
|
---|
246 |
|
---|
247 | void Dialog::BooleanQuery::setResult() {
|
---|
248 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
249 | }
|
---|
250 |
|
---|
251 | // String Queries
|
---|
252 |
|
---|
253 | Dialog::StringQuery::StringQuery(string title,std::string _description) :
|
---|
254 | Query(title, _description)
|
---|
255 | {}
|
---|
256 |
|
---|
257 | Dialog::StringQuery::~StringQuery() {};
|
---|
258 |
|
---|
259 | void Dialog::StringQuery::setResult() {
|
---|
260 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
261 | }
|
---|
262 |
|
---|
263 | // Strings Queries
|
---|
264 |
|
---|
265 | Dialog::StringsQuery::StringsQuery(string title,std::string _description) :
|
---|
266 | Query(title, _description)
|
---|
267 | {}
|
---|
268 |
|
---|
269 | Dialog::StringsQuery::~StringsQuery() {};
|
---|
270 |
|
---|
271 | void Dialog::StringsQuery::setResult() {
|
---|
272 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
273 | }
|
---|
274 |
|
---|
275 | // Double Queries
|
---|
276 |
|
---|
277 | Dialog::DoubleQuery::DoubleQuery(string title, std::string _description) :
|
---|
278 | Query(title, _description)
|
---|
279 | {}
|
---|
280 |
|
---|
281 | Dialog::DoubleQuery::~DoubleQuery() {};
|
---|
282 |
|
---|
283 | void Dialog::DoubleQuery::setResult() {
|
---|
284 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
285 | }
|
---|
286 |
|
---|
287 | // Doubles Queries
|
---|
288 |
|
---|
289 | Dialog::DoublesQuery::DoublesQuery(string title, std::string _description) :
|
---|
290 | Query(title, _description)
|
---|
291 | {}
|
---|
292 |
|
---|
293 | Dialog::DoublesQuery::~DoublesQuery() {};
|
---|
294 |
|
---|
295 | void Dialog::DoublesQuery::setResult() {
|
---|
296 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
297 | }
|
---|
298 |
|
---|
299 |
|
---|
300 | // Atom Queries
|
---|
301 |
|
---|
302 | Dialog::AtomQuery::AtomQuery(string title, std::string _description) :
|
---|
303 | Query(title, _description),
|
---|
304 | tmp(0)
|
---|
305 | {}
|
---|
306 |
|
---|
307 | Dialog::AtomQuery::~AtomQuery() {}
|
---|
308 |
|
---|
309 | void Dialog::AtomQuery::setResult() {
|
---|
310 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
311 | }
|
---|
312 |
|
---|
313 | // Atoms Queries
|
---|
314 |
|
---|
315 | Dialog::AtomsQuery::AtomsQuery(string title, std::string _description) :
|
---|
316 | Query(title, _description),
|
---|
317 | tmp(0)
|
---|
318 | {}
|
---|
319 |
|
---|
320 | Dialog::AtomsQuery::~AtomsQuery() {}
|
---|
321 |
|
---|
322 | void Dialog::AtomsQuery::setResult() {
|
---|
323 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
324 | }
|
---|
325 |
|
---|
326 | // Molecule Queries
|
---|
327 |
|
---|
328 | Dialog::MoleculeQuery::MoleculeQuery(string title, std::string _description) :
|
---|
329 | Query(title, _description),
|
---|
330 | tmp(0)
|
---|
331 | {}
|
---|
332 |
|
---|
333 | Dialog::MoleculeQuery::~MoleculeQuery() {}
|
---|
334 |
|
---|
335 | void Dialog::MoleculeQuery::setResult() {
|
---|
336 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
337 | }
|
---|
338 |
|
---|
339 | // Molecules Queries
|
---|
340 |
|
---|
341 | Dialog::MoleculesQuery::MoleculesQuery(string title, std::string _description) :
|
---|
342 | Query(title, _description),
|
---|
343 | tmp(0)
|
---|
344 | {}
|
---|
345 |
|
---|
346 | Dialog::MoleculesQuery::~MoleculesQuery() {}
|
---|
347 |
|
---|
348 | void Dialog::MoleculesQuery::setResult() {
|
---|
349 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
350 | }
|
---|
351 |
|
---|
352 | // Vector Queries
|
---|
353 |
|
---|
354 | Dialog::VectorQuery::VectorQuery(std::string title,bool _check, std::string _description) :
|
---|
355 | Query(title, _description),
|
---|
356 | check(_check)
|
---|
357 | {}
|
---|
358 |
|
---|
359 | Dialog::VectorQuery::~VectorQuery()
|
---|
360 | {}
|
---|
361 |
|
---|
362 | void Dialog::VectorQuery::setResult() {
|
---|
363 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
364 | }
|
---|
365 |
|
---|
366 | // Vectors Queries
|
---|
367 |
|
---|
368 | Dialog::VectorsQuery::VectorsQuery(std::string title,bool _check, std::string _description) :
|
---|
369 | Query(title, _description),
|
---|
370 | check(_check)
|
---|
371 | {}
|
---|
372 |
|
---|
373 | Dialog::VectorsQuery::~VectorsQuery()
|
---|
374 | {}
|
---|
375 |
|
---|
376 | void Dialog::VectorsQuery::setResult() {
|
---|
377 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
378 | }
|
---|
379 |
|
---|
380 | // Box Queries
|
---|
381 |
|
---|
382 | Dialog::BoxQuery::BoxQuery(std::string title, std::string _description) :
|
---|
383 | Query(title, _description)
|
---|
384 | {}
|
---|
385 |
|
---|
386 | Dialog::BoxQuery::~BoxQuery()
|
---|
387 | {}
|
---|
388 |
|
---|
389 | void Dialog::BoxQuery::setResult() {
|
---|
390 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
391 | }
|
---|
392 |
|
---|
393 | // Element Queries
|
---|
394 | Dialog::ElementQuery::ElementQuery(std::string title, std::string _description) :
|
---|
395 | Query(title, _description)
|
---|
396 | {}
|
---|
397 |
|
---|
398 | Dialog::ElementQuery::~ElementQuery(){}
|
---|
399 |
|
---|
400 | void Dialog::ElementQuery::setResult(){
|
---|
401 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
402 | }
|
---|
403 |
|
---|
404 | // Elements Queries
|
---|
405 | Dialog::ElementsQuery::ElementsQuery(std::string title, std::string _description) :
|
---|
406 | Query(title, _description)
|
---|
407 | {}
|
---|
408 |
|
---|
409 | Dialog::ElementsQuery::~ElementsQuery(){}
|
---|
410 |
|
---|
411 | void Dialog::ElementsQuery::setResult(){
|
---|
412 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
413 | }
|
---|
414 |
|
---|
415 | // File Queries
|
---|
416 | Dialog::FileQuery::FileQuery(std::string title, std::string _description) :
|
---|
417 | Query(title, _description)
|
---|
418 | {}
|
---|
419 |
|
---|
420 | Dialog::FileQuery::~FileQuery(){}
|
---|
421 |
|
---|
422 | void Dialog::FileQuery::setResult(){
|
---|
423 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
424 | }
|
---|