| [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 | {
 | 
|---|
| [9d5531] | 174 |   queryVector(param, token, 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 | {
 | 
|---|
| [9d5531] | 179 |   queryVectors(param, token, description);
 | 
|---|
| [72f611] | 180 | }
 | 
|---|
 | 181 | 
 | 
|---|
| [7d9416] | 182 | template <> void Dialog::query<RealSpaceMatrix>(Parameter<RealSpaceMatrix> ¶m, const char *token, std::string description)
 | 
|---|
| [9ee38b] | 183 | {
 | 
|---|
| [7d9416] | 184 |   queryRealSpaceMatrix(param, token, description);
 | 
|---|
| [9ee38b] | 185 | }
 | 
|---|
 | 186 | 
 | 
|---|
| [f10b0c] | 187 | template <> void Dialog::query<const element *>(Parameter<const element *> ¶m, const char *token, std::string description)
 | 
|---|
| [9ee38b] | 188 | {
 | 
|---|
| [f10b0c] | 189 |   queryElement(param, token, description);
 | 
|---|
| [9ee38b] | 190 | }
 | 
|---|
 | 191 | 
 | 
|---|
| [f10b0c] | 192 | template <> void Dialog::query< std::vector<const element *> >(Parameter<std::vector<const element *> > ¶m, const char *token, std::string description)
 | 
|---|
| [9ee38b] | 193 | {
 | 
|---|
| [f10b0c] | 194 |   queryElements(param, token, description);
 | 
|---|
| [9ee38b] | 195 | }
 | 
|---|
 | 196 | 
 | 
|---|
| [f10b0c] | 197 | template <> void Dialog::query< boost::filesystem::path >(Parameter<boost::filesystem::path> ¶m, const char *token, std::string description)
 | 
|---|
| [6f5dfe] | 198 | {
 | 
|---|
| [f10b0c] | 199 |   queryFile(param, token, description);
 | 
|---|
| [6f5dfe] | 200 | }
 | 
|---|
 | 201 | 
 | 
|---|
| [bd81f9] | 202 | template <> void Dialog::query< std::vector<boost::filesystem::path> >(Parameter<std::vector< boost::filesystem::path> > ¶m, const char *token, std::string description)
 | 
|---|
| [2c5765] | 203 | {
 | 
|---|
| [bd81f9] | 204 |   queryFiles(param, token, description);
 | 
|---|
| [2c5765] | 205 | }
 | 
|---|
 | 206 | 
 | 
|---|
| [f10b0c] | 207 | template <> void Dialog::query< RandomNumberDistribution_Parameters >(Parameter<RandomNumberDistribution_Parameters> ¶m, const char *token, std::string description)
 | 
|---|
| [0275ad] | 208 | {
 | 
|---|
| [f10b0c] | 209 |   queryRandomNumberDistribution_Parameters(param, token, description);
 | 
|---|
| [0275ad] | 210 | }
 | 
|---|
 | 211 | 
 | 
|---|
| [8df74d] | 212 | /************************** Query Infrastructure ************************/
 | 
|---|
 | 213 | /*       ---> shifted to folder Query                                   */
 | 
|---|
 | 214 | /************************************************************************/
 | 
|---|