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