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