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