[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[bcf653] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[f5a86a] | 8 | /*
|
---|
| 9 | * Dialog.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Jan 5, 2010
|
---|
| 12 | * Author: crueger
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
|
---|
[112b09] | 21 |
|
---|
[5079a0] | 22 | #include "Dialog.hpp"
|
---|
[861874] | 23 | #include "Actions/ValueStorage.hpp"
|
---|
[f5a86a] | 24 |
|
---|
[ad011c] | 25 | #include "CodePatterns/Log.hpp"
|
---|
| 26 | #include "CodePatterns/Verbose.hpp"
|
---|
[8df74d] | 27 |
|
---|
[e45c1d] | 28 | #include "Parameters/ParameterExceptions.hpp"
|
---|
| 29 |
|
---|
[8df74d] | 30 | class Atom;
|
---|
| 31 | class element;
|
---|
[cca9ef] | 32 | class RealSpaceMatrix;
|
---|
[8df74d] | 33 | class molecule;
|
---|
| 34 | class Vector;
|
---|
[2ededc2] | 35 |
|
---|
[f5a86a] | 36 | using namespace std;
|
---|
| 37 |
|
---|
| 38 | Dialog::Dialog()
|
---|
| 39 | {
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | Dialog::~Dialog()
|
---|
| 43 | {
|
---|
[45f5d6] | 44 | list<Query*>::iterator iter;
|
---|
| 45 | for(iter=queries.begin();iter!=queries.end();iter++){
|
---|
| 46 | delete (*iter);
|
---|
| 47 | }
|
---|
[f5a86a] | 48 | }
|
---|
| 49 |
|
---|
[45f5d6] | 50 | void Dialog::registerQuery(Query *query){
|
---|
| 51 | queries.push_back(query);
|
---|
| 52 | }
|
---|
[f5a86a] | 53 |
|
---|
[45f5d6] | 54 | bool Dialog::display(){
|
---|
[d3a5ea] | 55 | if(checkAll()){
|
---|
| 56 | setAll();
|
---|
| 57 | return true;
|
---|
| 58 | }
|
---|
| 59 | else{
|
---|
| 60 | return false;
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | bool Dialog::checkAll(){
|
---|
[45f5d6] | 65 | list<Query*>::iterator iter;
|
---|
| 66 | bool retval = true;
|
---|
| 67 | for(iter=queries.begin(); iter!=queries.end(); iter++){
|
---|
[e45c1d] | 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 | }
|
---|
[45f5d6] | 76 | // if any query fails (is canceled), we can end the handling process
|
---|
[94d131] | 77 | if(!retval) {
|
---|
[47d041] | 78 | ELOG(1, "The following query failed: " << (**iter).getTitle() << ".");
|
---|
[45f5d6] | 79 | break;
|
---|
[94d131] | 80 | }
|
---|
[45f5d6] | 81 | }
|
---|
| 82 | return retval;
|
---|
[f5a86a] | 83 | }
|
---|
| 84 |
|
---|
[d3a5ea] | 85 | void Dialog::setAll(){
|
---|
| 86 | list<Query*>::iterator iter;
|
---|
| 87 | for(iter=queries.begin(); iter!=queries.end(); iter++) {
|
---|
[e45c1d] | 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 | }
|
---|
[d3a5ea] | 95 | }
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[c508ef5] | 98 | bool Dialog::hasQueries(){
|
---|
| 99 | return queries.size();
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[f10b0c] | 102 | template <> void Dialog::query<void *>(Parameter<void *> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 103 | {
|
---|
| 104 | queryEmpty(token, description);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[f10b0c] | 107 | template <> void Dialog::query<bool>(Parameter<bool> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 108 | {
|
---|
[f10b0c] | 109 | queryBoolean(param, token, description);
|
---|
[9ee38b] | 110 | }
|
---|
| 111 |
|
---|
[f10b0c] | 112 | template <> void Dialog::query<int>(Parameter<int> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 113 | {
|
---|
[f10b0c] | 114 | queryInt(param, token, description);
|
---|
[9ee38b] | 115 | }
|
---|
| 116 |
|
---|
[f10b0c] | 117 | template <> void Dialog::query< std::vector<int> >(Parameter<std::vector<int> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 118 | {
|
---|
[f10b0c] | 119 | queryInts(param, token, description);
|
---|
[9ee38b] | 120 | }
|
---|
| 121 |
|
---|
[f10b0c] | 122 | template <> void Dialog::query<unsigned int>(Parameter<unsigned int> ¶m, const char *token, std::string description)
|
---|
[838cd0] | 123 | {
|
---|
[f10b0c] | 124 | queryUnsignedInt(param, token, description);
|
---|
[838cd0] | 125 | }
|
---|
| 126 |
|
---|
[f10b0c] | 127 | template <> void Dialog::query< std::vector<unsigned int> >(Parameter<std::vector<unsigned int> > ¶m, const char *token, std::string description)
|
---|
[12948c] | 128 | {
|
---|
[f10b0c] | 129 | queryUnsignedInts(param, token, description);
|
---|
[12948c] | 130 | }
|
---|
| 131 |
|
---|
[f10b0c] | 132 | template <> void Dialog::query<double>(Parameter<double> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 133 | {
|
---|
[f10b0c] | 134 | queryDouble(param, token, description);
|
---|
[9ee38b] | 135 | }
|
---|
| 136 |
|
---|
[f10b0c] | 137 | template <> void Dialog::query< std::vector<double> >(Parameter<std::vector<double> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 138 | {
|
---|
[f10b0c] | 139 | queryDoubles(param, token, description);
|
---|
[9ee38b] | 140 | }
|
---|
| 141 |
|
---|
[f10b0c] | 142 | template <> void Dialog::query<std::string>(Parameter<std::string> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 143 | {
|
---|
[f10b0c] | 144 | queryString(param, token, description);
|
---|
[9ee38b] | 145 | }
|
---|
| 146 |
|
---|
[f10b0c] | 147 | template <> void Dialog::query< std::vector<std::string> >(Parameter<std::vector<std::string> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 148 | {
|
---|
[f10b0c] | 149 | queryStrings(param, token, description);
|
---|
[9ee38b] | 150 | }
|
---|
| 151 |
|
---|
[f10b0c] | 152 | template <> void Dialog::query<const atom *>(Parameter<const atom *> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 153 | {
|
---|
[f10b0c] | 154 | queryAtom(param, token, description);
|
---|
[9ee38b] | 155 | }
|
---|
| 156 |
|
---|
[f10b0c] | 157 | template <> void Dialog::query< std::vector<const atom *> >(Parameter<std::vector<const atom *> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 158 | {
|
---|
[f10b0c] | 159 | queryAtoms(param, token, description);
|
---|
[9ee38b] | 160 | }
|
---|
| 161 |
|
---|
[f10b0c] | 162 | template <> void Dialog::query<const molecule *>(Parameter<const molecule *> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 163 | {
|
---|
[f10b0c] | 164 | queryMolecule(param, token, description);
|
---|
[9ee38b] | 165 | }
|
---|
| 166 |
|
---|
[f10b0c] | 167 | template <> void Dialog::query< std::vector<const molecule *> >(Parameter<std::vector<const molecule *> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 168 | {
|
---|
[f10b0c] | 169 | queryMolecules(param, token, description);
|
---|
[9ee38b] | 170 | }
|
---|
| 171 |
|
---|
[f10b0c] | 172 | template <> void Dialog::query<Vector>(Parameter<Vector> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 173 | {
|
---|
[f10b0c] | 174 | queryVector(param, token, false, description);
|
---|
[9ee38b] | 175 | }
|
---|
| 176 |
|
---|
[f10b0c] | 177 | template <> void Dialog::query< std::vector<Vector> >(Parameter<std::vector<Vector> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 178 | {
|
---|
[f10b0c] | 179 | queryVectors(param, token, false, description);
|
---|
[9ee38b] | 180 | }
|
---|
| 181 |
|
---|
[f10b0c] | 182 | template <> void Dialog::query<BoxVector>(Parameter<BoxVector> ¶m, const char *token, std::string description)
|
---|
[72f611] | 183 | {
|
---|
[f10b0c] | 184 | ASSERT(0, "TODO: query<BoxVector>");
|
---|
| 185 | //queryVector(param, token, true, description);
|
---|
[72f611] | 186 | }
|
---|
| 187 |
|
---|
[f10b0c] | 188 | template <> void Dialog::query< std::vector<BoxVector> >(Parameter<std::vector<BoxVector> > ¶m, const char *token, std::string description)
|
---|
[72f611] | 189 | {
|
---|
[f10b0c] | 190 | ASSERT(0, "TODO: query<vector<BoxVector> >");
|
---|
| 191 | //queryVectors(param, token, true, description);
|
---|
[72f611] | 192 | }
|
---|
| 193 |
|
---|
[7d9416] | 194 | template <> void Dialog::query<RealSpaceMatrix>(Parameter<RealSpaceMatrix> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 195 | {
|
---|
[7d9416] | 196 | queryRealSpaceMatrix(param, token, description);
|
---|
[9ee38b] | 197 | }
|
---|
| 198 |
|
---|
[f10b0c] | 199 | template <> void Dialog::query<const element *>(Parameter<const element *> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 200 | {
|
---|
[f10b0c] | 201 | queryElement(param, token, description);
|
---|
[9ee38b] | 202 | }
|
---|
| 203 |
|
---|
[f10b0c] | 204 | template <> void Dialog::query< std::vector<const element *> >(Parameter<std::vector<const element *> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 205 | {
|
---|
[f10b0c] | 206 | queryElements(param, token, description);
|
---|
[9ee38b] | 207 | }
|
---|
| 208 |
|
---|
[f10b0c] | 209 | template <> void Dialog::query< boost::filesystem::path >(Parameter<boost::filesystem::path> ¶m, const char *token, std::string description)
|
---|
[6f5dfe] | 210 | {
|
---|
[f10b0c] | 211 | queryFile(param, token, description);
|
---|
[6f5dfe] | 212 | }
|
---|
| 213 |
|
---|
[f10b0c] | 214 | template <> void Dialog::query< RandomNumberDistribution_Parameters >(Parameter<RandomNumberDistribution_Parameters> ¶m, const char *token, std::string description)
|
---|
[0275ad] | 215 | {
|
---|
[f10b0c] | 216 | queryRandomNumberDistribution_Parameters(param, token, description);
|
---|
[0275ad] | 217 | }
|
---|
| 218 |
|
---|
[8df74d] | 219 | /************************** Query Infrastructure ************************/
|
---|
| 220 | /* ---> shifted to folder Query */
|
---|
| 221 | /************************************************************************/
|
---|