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