| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [94d5ac6] | 5 |  * 
 | 
|---|
 | 6 |  *
 | 
|---|
 | 7 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 8 |  *
 | 
|---|
 | 9 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 10 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 11 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 12 |  *    (at your option) any later version.
 | 
|---|
 | 13 |  *
 | 
|---|
 | 14 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 15 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 16 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 17 |  *    GNU General Public License for more details.
 | 
|---|
 | 18 |  *
 | 
|---|
 | 19 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 20 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| [bcf653] | 21 |  */
 | 
|---|
 | 22 | 
 | 
|---|
| [f5a86a] | 23 | /*
 | 
|---|
 | 24 |  * Dialog.cpp
 | 
|---|
 | 25 |  *
 | 
|---|
 | 26 |  *  Created on: Jan 5, 2010
 | 
|---|
 | 27 |  *      Author: crueger
 | 
|---|
 | 28 |  */
 | 
|---|
 | 29 | 
 | 
|---|
| [bf3817] | 30 | // include config.h
 | 
|---|
 | 31 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 32 | #include <config.h>
 | 
|---|
 | 33 | #endif
 | 
|---|
 | 34 | 
 | 
|---|
| [ad011c] | 35 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [112b09] | 36 | 
 | 
|---|
| [5079a0] | 37 | #include "Dialog.hpp"
 | 
|---|
| [f5a86a] | 38 | 
 | 
|---|
| [ad011c] | 39 | #include "CodePatterns/Log.hpp"
 | 
|---|
 | 40 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| [8df74d] | 41 | 
 | 
|---|
| [e45c1d] | 42 | #include "Parameters/ParameterExceptions.hpp"
 | 
|---|
 | 43 | 
 | 
|---|
| [8df74d] | 44 | class Atom;
 | 
|---|
 | 45 | class element;
 | 
|---|
| [cca9ef] | 46 | class RealSpaceMatrix;
 | 
|---|
| [8df74d] | 47 | class molecule;
 | 
|---|
 | 48 | class Vector;
 | 
|---|
| [2ededc2] | 49 | 
 | 
|---|
| [f5a86a] | 50 | using namespace std;
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 | Dialog::Dialog()
 | 
|---|
 | 53 | {
 | 
|---|
 | 54 | }
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 | Dialog::~Dialog()
 | 
|---|
 | 57 | {
 | 
|---|
| [45f5d6] | 58 |   list<Query*>::iterator iter;
 | 
|---|
 | 59 |   for(iter=queries.begin();iter!=queries.end();iter++){
 | 
|---|
 | 60 |     delete (*iter);
 | 
|---|
 | 61 |   }
 | 
|---|
| [f5a86a] | 62 | }
 | 
|---|
 | 63 | 
 | 
|---|
| [45f5d6] | 64 | void Dialog::registerQuery(Query *query){
 | 
|---|
 | 65 |   queries.push_back(query);
 | 
|---|
 | 66 | }
 | 
|---|
| [f5a86a] | 67 | 
 | 
|---|
| [45f5d6] | 68 | bool Dialog::display(){
 | 
|---|
| [852ea3] | 69 |   handleAll();
 | 
|---|
| [0d4168] | 70 |   setAll();
 | 
|---|
 | 71 |   return true;
 | 
|---|
 | 72 | //  if(checkAll()){
 | 
|---|
 | 73 | //    setAll();
 | 
|---|
 | 74 | //    return true;
 | 
|---|
 | 75 | //  }
 | 
|---|
 | 76 | //  else{
 | 
|---|
 | 77 | //    return false;
 | 
|---|
 | 78 | //  }
 | 
|---|
| [d3a5ea] | 79 | }
 | 
|---|
 | 80 | 
 | 
|---|
| [852ea3] | 81 | void Dialog::handleAll(){
 | 
|---|
| [45f5d6] | 82 |   list<Query*>::iterator iter;
 | 
|---|
 | 83 |   for(iter=queries.begin(); iter!=queries.end(); iter++){
 | 
|---|
| [852ea3] | 84 |     try{
 | 
|---|
 | 85 |       (*iter)->handle();
 | 
|---|
 | 86 |     }catch(...){
 | 
|---|
 | 87 |     // if any query fails (is canceled), we can end the handling process
 | 
|---|
 | 88 |       ELOG(1, "The following query failed: " << (**iter).getTitle() << ".");
 | 
|---|
| [e45c1d] | 89 |       break;
 | 
|---|
 | 90 |     }
 | 
|---|
| [852ea3] | 91 |   }
 | 
|---|
 | 92 | }
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 | bool Dialog::checkAll(){
 | 
|---|
 | 95 |   list<Query*>::iterator iter;
 | 
|---|
 | 96 |   bool retval = true;
 | 
|---|
 | 97 |   for(iter=queries.begin(); iter!=queries.end(); iter++){
 | 
|---|
 | 98 |     retval &= (*iter)->isValid();
 | 
|---|
| [45f5d6] | 99 |     // if any query fails (is canceled), we can end the handling process
 | 
|---|
| [94d131] | 100 |     if(!retval) {
 | 
|---|
| [47d041] | 101 |       ELOG(1, "The following query failed: " << (**iter).getTitle() << ".");
 | 
|---|
| [45f5d6] | 102 |       break;
 | 
|---|
| [94d131] | 103 |     }
 | 
|---|
| [45f5d6] | 104 |   }
 | 
|---|
 | 105 |   return retval;
 | 
|---|
| [f5a86a] | 106 | }
 | 
|---|
 | 107 | 
 | 
|---|
| [d3a5ea] | 108 | void Dialog::setAll(){
 | 
|---|
 | 109 |   list<Query*>::iterator iter;
 | 
|---|
 | 110 |   for(iter=queries.begin(); iter!=queries.end(); iter++) {
 | 
|---|
| [0d4168] | 111 | //    try {
 | 
|---|
| [e45c1d] | 112 |       (*iter)->setResult();
 | 
|---|
| [0d4168] | 113 | //    } catch (ParameterException &e) {
 | 
|---|
 | 114 | //      if( const std::string *name=boost::get_error_info<ParameterName>(e) )
 | 
|---|
 | 115 | //        ELOG(1, "The following parameter value is not valid: " << *name << ".");
 | 
|---|
 | 116 | //      break;
 | 
|---|
 | 117 | //    }
 | 
|---|
| [d3a5ea] | 118 |   }
 | 
|---|
 | 119 | }
 | 
|---|
 | 120 | 
 | 
|---|
| [c508ef5] | 121 | bool Dialog::hasQueries(){
 | 
|---|
 | 122 |   return queries.size();
 | 
|---|
 | 123 | }
 | 
|---|
 | 124 | 
 | 
|---|
| [f130d4] | 125 | /*template <> void Dialog::query<Dialog::EmptyType>(Parameter<Dialog::EmptyType> ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 126 | {
 | 
|---|
| [f130d4] | 127 |   queryEmpty(param, title, description);
 | 
|---|
| [1c55b8] | 128 | }*/
 | 
|---|
| [9ee38b] | 129 | 
 | 
|---|
| [f130d4] | 130 | template <> void Dialog::query<bool>(Parameter<bool> ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 131 | {
 | 
|---|
| [f130d4] | 132 |   queryBoolean(param, title, description);
 | 
|---|
| [9ee38b] | 133 | }
 | 
|---|
 | 134 | 
 | 
|---|
| [f130d4] | 135 | template <> void Dialog::query<int>(Parameter<int> ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 136 | {
 | 
|---|
| [f130d4] | 137 |   queryInt(param, title, description);
 | 
|---|
| [9ee38b] | 138 | }
 | 
|---|
 | 139 | 
 | 
|---|
| [f130d4] | 140 | template <> void Dialog::query< std::vector<int> >(Parameter<std::vector<int> > ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 141 | {
 | 
|---|
| [f130d4] | 142 |   queryInts(param, title, description);
 | 
|---|
| [9ee38b] | 143 | }
 | 
|---|
 | 144 | 
 | 
|---|
| [f130d4] | 145 | template <> void Dialog::query<unsigned int>(Parameter<unsigned int> ¶m, const std::string title, const std::string description)
 | 
|---|
| [838cd0] | 146 | {
 | 
|---|
| [f130d4] | 147 |   queryUnsignedInt(param, title, description);
 | 
|---|
| [838cd0] | 148 | }
 | 
|---|
 | 149 | 
 | 
|---|
| [f130d4] | 150 | template <> void Dialog::query< std::vector<unsigned int> >(Parameter<std::vector<unsigned int> > ¶m, const std::string title, const std::string description)
 | 
|---|
| [12948c] | 151 | {
 | 
|---|
| [f130d4] | 152 |   queryUnsignedInts(param, title, description);
 | 
|---|
| [12948c] | 153 | }
 | 
|---|
 | 154 | 
 | 
|---|
| [f130d4] | 155 | template <> void Dialog::query<double>(Parameter<double> ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 156 | {
 | 
|---|
| [f130d4] | 157 |   queryDouble(param, title, description);
 | 
|---|
| [9ee38b] | 158 | }
 | 
|---|
 | 159 | 
 | 
|---|
| [f130d4] | 160 | template <> void Dialog::query< std::vector<double> >(Parameter<std::vector<double> > ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 161 | {
 | 
|---|
| [f130d4] | 162 |   queryDoubles(param, title, description);
 | 
|---|
| [9ee38b] | 163 | }
 | 
|---|
 | 164 | 
 | 
|---|
| [f130d4] | 165 | template <> void Dialog::query<std::string>(Parameter<std::string> ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 166 | {
 | 
|---|
| [f130d4] | 167 |   queryString(param, title, description);
 | 
|---|
| [9ee38b] | 168 | }
 | 
|---|
 | 169 | 
 | 
|---|
| [f130d4] | 170 | template <> void Dialog::query< std::vector<std::string> >(Parameter<std::vector<std::string> > ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 171 | {
 | 
|---|
| [f130d4] | 172 |   queryStrings(param, title, description);
 | 
|---|
| [9ee38b] | 173 | }
 | 
|---|
 | 174 | 
 | 
|---|
| [f130d4] | 175 | template <> void Dialog::query<const atom *>(Parameter<const atom *> ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 176 | {
 | 
|---|
| [f130d4] | 177 |   queryAtom(param, title, description);
 | 
|---|
| [9ee38b] | 178 | }
 | 
|---|
 | 179 | 
 | 
|---|
| [f130d4] | 180 | template <> void Dialog::query< std::vector<const atom *> >(Parameter<std::vector<const atom *> > ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 181 | {
 | 
|---|
| [f130d4] | 182 |   queryAtoms(param, title, description);
 | 
|---|
| [9ee38b] | 183 | }
 | 
|---|
 | 184 | 
 | 
|---|
| [f130d4] | 185 | template <> void Dialog::query<const molecule *>(Parameter<const molecule *> ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 186 | {
 | 
|---|
| [f130d4] | 187 |   queryMolecule(param, title, description);
 | 
|---|
| [9ee38b] | 188 | }
 | 
|---|
 | 189 | 
 | 
|---|
| [f130d4] | 190 | template <> void Dialog::query< std::vector<const molecule *> >(Parameter<std::vector<const molecule *> > ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 191 | {
 | 
|---|
| [f130d4] | 192 |   queryMolecules(param, title, description);
 | 
|---|
| [9ee38b] | 193 | }
 | 
|---|
 | 194 | 
 | 
|---|
| [f130d4] | 195 | template <> void Dialog::query<Vector>(Parameter<Vector> ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 196 | {
 | 
|---|
| [f130d4] | 197 |   queryVector(param, title, description);
 | 
|---|
| [9ee38b] | 198 | }
 | 
|---|
 | 199 | 
 | 
|---|
| [f130d4] | 200 | template <> void Dialog::query< std::vector<Vector> >(Parameter<std::vector<Vector> > ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 201 | {
 | 
|---|
| [f130d4] | 202 |   queryVectors(param, title, description);
 | 
|---|
| [72f611] | 203 | }
 | 
|---|
 | 204 | 
 | 
|---|
| [f130d4] | 205 | template <> void Dialog::query<RealSpaceMatrix>(Parameter<RealSpaceMatrix> ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 206 | {
 | 
|---|
| [f130d4] | 207 |   queryRealSpaceMatrix(param, title, description);
 | 
|---|
| [9ee38b] | 208 | }
 | 
|---|
 | 209 | 
 | 
|---|
| [f130d4] | 210 | template <> void Dialog::query<const element *>(Parameter<const element *> ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 211 | {
 | 
|---|
| [f130d4] | 212 |   queryElement(param, title, description);
 | 
|---|
| [9ee38b] | 213 | }
 | 
|---|
 | 214 | 
 | 
|---|
| [f130d4] | 215 | template <> void Dialog::query< std::vector<const element *> >(Parameter<std::vector<const element *> > ¶m, const std::string title, const std::string description)
 | 
|---|
| [9ee38b] | 216 | {
 | 
|---|
| [f130d4] | 217 |   queryElements(param, title, description);
 | 
|---|
| [9ee38b] | 218 | }
 | 
|---|
 | 219 | 
 | 
|---|
| [f130d4] | 220 | template <> void Dialog::query< boost::filesystem::path >(Parameter<boost::filesystem::path> ¶m, const std::string title, const std::string description)
 | 
|---|
| [6f5dfe] | 221 | {
 | 
|---|
| [f130d4] | 222 |   queryFile(param, title, description);
 | 
|---|
| [6f5dfe] | 223 | }
 | 
|---|
 | 224 | 
 | 
|---|
| [f130d4] | 225 | template <> void Dialog::query< std::vector<boost::filesystem::path> >(Parameter<std::vector< boost::filesystem::path> > ¶m, const std::string title, const std::string description)
 | 
|---|
| [2c5765] | 226 | {
 | 
|---|
| [f130d4] | 227 |   queryFiles(param, title, description);
 | 
|---|
| [2c5765] | 228 | }
 | 
|---|
 | 229 | 
 | 
|---|
| [f130d4] | 230 | template <> void Dialog::query< RandomNumberDistribution_Parameters >(Parameter<RandomNumberDistribution_Parameters> ¶m, const std::string title, const std::string description)
 | 
|---|
| [0275ad] | 231 | {
 | 
|---|
| [f130d4] | 232 |   queryRandomNumberDistribution_Parameters(param, title, description);
 | 
|---|
| [0275ad] | 233 | }
 | 
|---|
 | 234 | 
 | 
|---|
| [8df74d] | 235 | /************************** Query Infrastructure ************************/
 | 
|---|
 | 236 | /*       ---> shifted to folder Query                                   */
 | 
|---|
 | 237 | /************************************************************************/
 | 
|---|