1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 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 "CodePatterns/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include "Dialog.hpp"
|
---|
23 | #include "Actions/ValueStorage.hpp"
|
---|
24 |
|
---|
25 | #include "CodePatterns/Log.hpp"
|
---|
26 | #include "CodePatterns/Verbose.hpp"
|
---|
27 |
|
---|
28 | #include "Parameters/ParameterExceptions.hpp"
|
---|
29 |
|
---|
30 | class Atom;
|
---|
31 | class Box;
|
---|
32 | class element;
|
---|
33 | class RealSpaceMatrix;
|
---|
34 | class molecule;
|
---|
35 | class Vector;
|
---|
36 |
|
---|
37 | using namespace std;
|
---|
38 |
|
---|
39 | Dialog::Dialog()
|
---|
40 | {
|
---|
41 | }
|
---|
42 |
|
---|
43 | Dialog::~Dialog()
|
---|
44 | {
|
---|
45 | list<Query*>::iterator iter;
|
---|
46 | for(iter=queries.begin();iter!=queries.end();iter++){
|
---|
47 | delete (*iter);
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | void Dialog::registerQuery(Query *query){
|
---|
52 | queries.push_back(query);
|
---|
53 | }
|
---|
54 |
|
---|
55 | bool Dialog::display(){
|
---|
56 | if(checkAll()){
|
---|
57 | setAll();
|
---|
58 | return true;
|
---|
59 | }
|
---|
60 | else{
|
---|
61 | return false;
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | bool Dialog::checkAll(){
|
---|
66 | list<Query*>::iterator iter;
|
---|
67 | bool retval = true;
|
---|
68 | for(iter=queries.begin(); iter!=queries.end(); iter++){
|
---|
69 | try {
|
---|
70 | retval &= (*iter)->handle();
|
---|
71 | } catch (ParameterException &e) {
|
---|
72 | if( const std::string *name=boost::get_error_info<ParameterName>(e) )
|
---|
73 | ELOG(1, "The following parameter value is not valid: " << *name << ".");
|
---|
74 | retval = false;
|
---|
75 | break;
|
---|
76 | }
|
---|
77 | // if any query fails (is canceled), we can end the handling process
|
---|
78 | if(!retval) {
|
---|
79 | ELOG(1, "The following query failed: " << (**iter).getTitle() << ".");
|
---|
80 | break;
|
---|
81 | }
|
---|
82 | }
|
---|
83 | return retval;
|
---|
84 | }
|
---|
85 |
|
---|
86 | void Dialog::setAll(){
|
---|
87 | list<Query*>::iterator iter;
|
---|
88 | for(iter=queries.begin(); iter!=queries.end(); iter++) {
|
---|
89 | try {
|
---|
90 | (*iter)->setResult();
|
---|
91 | } catch (ParameterException &e) {
|
---|
92 | if( const std::string *name=boost::get_error_info<ParameterName>(e) )
|
---|
93 | ELOG(1, "The following parameter value is not valid: " << *name << ".");
|
---|
94 | break;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | bool Dialog::hasQueries(){
|
---|
100 | return queries.size();
|
---|
101 | }
|
---|
102 |
|
---|
103 | template <> void Dialog::query<void *>(Parameter<void *> ¶m, const char *token, std::string description)
|
---|
104 | {
|
---|
105 | queryEmpty(token, description);
|
---|
106 | }
|
---|
107 |
|
---|
108 | template <> void Dialog::query<bool>(Parameter<bool> ¶m, const char *token, std::string description)
|
---|
109 | {
|
---|
110 | queryBoolean(param, token, description);
|
---|
111 | }
|
---|
112 |
|
---|
113 | template <> void Dialog::query<int>(Parameter<int> ¶m, const char *token, std::string description)
|
---|
114 | {
|
---|
115 | queryInt(param, token, description);
|
---|
116 | }
|
---|
117 |
|
---|
118 | template <> void Dialog::query< std::vector<int> >(Parameter<std::vector<int> > ¶m, const char *token, std::string description)
|
---|
119 | {
|
---|
120 | queryInts(param, token, description);
|
---|
121 | }
|
---|
122 |
|
---|
123 | template <> void Dialog::query<unsigned int>(Parameter<unsigned int> ¶m, const char *token, std::string description)
|
---|
124 | {
|
---|
125 | queryUnsignedInt(param, token, description);
|
---|
126 | }
|
---|
127 |
|
---|
128 | template <> void Dialog::query< std::vector<unsigned int> >(Parameter<std::vector<unsigned int> > ¶m, const char *token, std::string description)
|
---|
129 | {
|
---|
130 | queryUnsignedInts(param, token, description);
|
---|
131 | }
|
---|
132 |
|
---|
133 | template <> void Dialog::query<double>(Parameter<double> ¶m, const char *token, std::string description)
|
---|
134 | {
|
---|
135 | queryDouble(param, token, description);
|
---|
136 | }
|
---|
137 |
|
---|
138 | template <> void Dialog::query< std::vector<double> >(Parameter<std::vector<double> > ¶m, const char *token, std::string description)
|
---|
139 | {
|
---|
140 | queryDoubles(param, token, description);
|
---|
141 | }
|
---|
142 |
|
---|
143 | template <> void Dialog::query<std::string>(Parameter<std::string> ¶m, const char *token, std::string description)
|
---|
144 | {
|
---|
145 | queryString(param, token, description);
|
---|
146 | }
|
---|
147 |
|
---|
148 | template <> void Dialog::query< std::vector<std::string> >(Parameter<std::vector<std::string> > ¶m, const char *token, std::string description)
|
---|
149 | {
|
---|
150 | queryStrings(param, token, description);
|
---|
151 | }
|
---|
152 |
|
---|
153 | template <> void Dialog::query<const atom *>(Parameter<const atom *> ¶m, const char *token, std::string description)
|
---|
154 | {
|
---|
155 | queryAtom(param, token, description);
|
---|
156 | }
|
---|
157 |
|
---|
158 | template <> void Dialog::query< std::vector<const atom *> >(Parameter<std::vector<const atom *> > ¶m, const char *token, std::string description)
|
---|
159 | {
|
---|
160 | queryAtoms(param, token, description);
|
---|
161 | }
|
---|
162 |
|
---|
163 | template <> void Dialog::query<const molecule *>(Parameter<const molecule *> ¶m, const char *token, std::string description)
|
---|
164 | {
|
---|
165 | queryMolecule(param, token, description);
|
---|
166 | }
|
---|
167 |
|
---|
168 | template <> void Dialog::query< std::vector<const molecule *> >(Parameter<std::vector<const molecule *> > ¶m, const char *token, std::string description)
|
---|
169 | {
|
---|
170 | queryMolecules(param, token, description);
|
---|
171 | }
|
---|
172 |
|
---|
173 | template <> void Dialog::query<Vector>(Parameter<Vector> ¶m, const char *token, std::string description)
|
---|
174 | {
|
---|
175 | queryVector(param, token, false, description);
|
---|
176 | }
|
---|
177 |
|
---|
178 | template <> void Dialog::query< std::vector<Vector> >(Parameter<std::vector<Vector> > ¶m, const char *token, std::string description)
|
---|
179 | {
|
---|
180 | queryVectors(param, token, false, description);
|
---|
181 | }
|
---|
182 |
|
---|
183 | template <> void Dialog::query<BoxVector>(Parameter<BoxVector> ¶m, const char *token, std::string description)
|
---|
184 | {
|
---|
185 | ASSERT(0, "TODO: query<BoxVector>");
|
---|
186 | //queryVector(param, token, true, description);
|
---|
187 | }
|
---|
188 |
|
---|
189 | template <> void Dialog::query< std::vector<BoxVector> >(Parameter<std::vector<BoxVector> > ¶m, const char *token, std::string description)
|
---|
190 | {
|
---|
191 | ASSERT(0, "TODO: query<vector<BoxVector> >");
|
---|
192 | //queryVectors(param, token, true, description);
|
---|
193 | }
|
---|
194 |
|
---|
195 | template <> void Dialog::query<Box>(Parameter<Box> ¶m, const char *token, std::string description)
|
---|
196 | {
|
---|
197 | queryBox(param, token, description);
|
---|
198 | }
|
---|
199 |
|
---|
200 | template <> void Dialog::query<const element *>(Parameter<const element *> ¶m, const char *token, std::string description)
|
---|
201 | {
|
---|
202 | queryElement(param, token, description);
|
---|
203 | }
|
---|
204 |
|
---|
205 | template <> void Dialog::query< std::vector<const element *> >(Parameter<std::vector<const element *> > ¶m, const char *token, std::string description)
|
---|
206 | {
|
---|
207 | queryElements(param, token, description);
|
---|
208 | }
|
---|
209 |
|
---|
210 | template <> void Dialog::query< boost::filesystem::path >(Parameter<boost::filesystem::path> ¶m, const char *token, std::string description)
|
---|
211 | {
|
---|
212 | queryFile(param, token, description);
|
---|
213 | }
|
---|
214 |
|
---|
215 | template <> void Dialog::query< RandomNumberDistribution_Parameters >(Parameter<RandomNumberDistribution_Parameters> ¶m, const char *token, std::string description)
|
---|
216 | {
|
---|
217 | queryRandomNumberDistribution_Parameters(param, token, description);
|
---|
218 | }
|
---|
219 |
|
---|
220 | /************************** Query Infrastructure ************************/
|
---|
221 | /* ---> shifted to folder Query */
|
---|
222 | /************************************************************************/
|
---|