[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();
|
---|
[d3a5ea] | 70 | if(checkAll()){
|
---|
| 71 | setAll();
|
---|
| 72 | return true;
|
---|
| 73 | }
|
---|
| 74 | else{
|
---|
| 75 | return false;
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[852ea3] | 79 | void Dialog::handleAll(){
|
---|
[45f5d6] | 80 | list<Query*>::iterator iter;
|
---|
| 81 | for(iter=queries.begin(); iter!=queries.end(); iter++){
|
---|
[852ea3] | 82 | try{
|
---|
| 83 | (*iter)->handle();
|
---|
| 84 | }catch(...){
|
---|
| 85 | // if any query fails (is canceled), we can end the handling process
|
---|
| 86 | ELOG(1, "The following query failed: " << (**iter).getTitle() << ".");
|
---|
[e45c1d] | 87 | break;
|
---|
| 88 | }
|
---|
[852ea3] | 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | bool Dialog::checkAll(){
|
---|
| 93 | list<Query*>::iterator iter;
|
---|
| 94 | bool retval = true;
|
---|
| 95 | for(iter=queries.begin(); iter!=queries.end(); iter++){
|
---|
| 96 | retval &= (*iter)->isValid();
|
---|
[45f5d6] | 97 | // if any query fails (is canceled), we can end the handling process
|
---|
[94d131] | 98 | if(!retval) {
|
---|
[47d041] | 99 | ELOG(1, "The following query failed: " << (**iter).getTitle() << ".");
|
---|
[45f5d6] | 100 | break;
|
---|
[94d131] | 101 | }
|
---|
[45f5d6] | 102 | }
|
---|
| 103 | return retval;
|
---|
[f5a86a] | 104 | }
|
---|
| 105 |
|
---|
[d3a5ea] | 106 | void Dialog::setAll(){
|
---|
| 107 | list<Query*>::iterator iter;
|
---|
| 108 | for(iter=queries.begin(); iter!=queries.end(); iter++) {
|
---|
[e45c1d] | 109 | try {
|
---|
| 110 | (*iter)->setResult();
|
---|
| 111 | } catch (ParameterException &e) {
|
---|
| 112 | if( const std::string *name=boost::get_error_info<ParameterName>(e) )
|
---|
| 113 | ELOG(1, "The following parameter value is not valid: " << *name << ".");
|
---|
| 114 | break;
|
---|
| 115 | }
|
---|
[d3a5ea] | 116 | }
|
---|
| 117 | }
|
---|
| 118 |
|
---|
[c508ef5] | 119 | bool Dialog::hasQueries(){
|
---|
| 120 | return queries.size();
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[1c55b8] | 123 | /*template <> void Dialog::query<Dialog::EmptyType>(Parameter<Dialog::EmptyType> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 124 | {
|
---|
[1c55b8] | 125 | queryEmpty(param, token, description);
|
---|
| 126 | }*/
|
---|
[9ee38b] | 127 |
|
---|
[f10b0c] | 128 | template <> void Dialog::query<bool>(Parameter<bool> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 129 | {
|
---|
[f10b0c] | 130 | queryBoolean(param, token, description);
|
---|
[9ee38b] | 131 | }
|
---|
| 132 |
|
---|
[f10b0c] | 133 | template <> void Dialog::query<int>(Parameter<int> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 134 | {
|
---|
[f10b0c] | 135 | queryInt(param, token, description);
|
---|
[9ee38b] | 136 | }
|
---|
| 137 |
|
---|
[f10b0c] | 138 | template <> void Dialog::query< std::vector<int> >(Parameter<std::vector<int> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 139 | {
|
---|
[f10b0c] | 140 | queryInts(param, token, description);
|
---|
[9ee38b] | 141 | }
|
---|
| 142 |
|
---|
[f10b0c] | 143 | template <> void Dialog::query<unsigned int>(Parameter<unsigned int> ¶m, const char *token, std::string description)
|
---|
[838cd0] | 144 | {
|
---|
[f10b0c] | 145 | queryUnsignedInt(param, token, description);
|
---|
[838cd0] | 146 | }
|
---|
| 147 |
|
---|
[f10b0c] | 148 | template <> void Dialog::query< std::vector<unsigned int> >(Parameter<std::vector<unsigned int> > ¶m, const char *token, std::string description)
|
---|
[12948c] | 149 | {
|
---|
[f10b0c] | 150 | queryUnsignedInts(param, token, description);
|
---|
[12948c] | 151 | }
|
---|
| 152 |
|
---|
[f10b0c] | 153 | template <> void Dialog::query<double>(Parameter<double> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 154 | {
|
---|
[f10b0c] | 155 | queryDouble(param, token, description);
|
---|
[9ee38b] | 156 | }
|
---|
| 157 |
|
---|
[f10b0c] | 158 | template <> void Dialog::query< std::vector<double> >(Parameter<std::vector<double> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 159 | {
|
---|
[f10b0c] | 160 | queryDoubles(param, token, description);
|
---|
[9ee38b] | 161 | }
|
---|
| 162 |
|
---|
[f10b0c] | 163 | template <> void Dialog::query<std::string>(Parameter<std::string> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 164 | {
|
---|
[f10b0c] | 165 | queryString(param, token, description);
|
---|
[9ee38b] | 166 | }
|
---|
| 167 |
|
---|
[f10b0c] | 168 | template <> void Dialog::query< std::vector<std::string> >(Parameter<std::vector<std::string> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 169 | {
|
---|
[f10b0c] | 170 | queryStrings(param, token, description);
|
---|
[9ee38b] | 171 | }
|
---|
| 172 |
|
---|
[f10b0c] | 173 | template <> void Dialog::query<const atom *>(Parameter<const atom *> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 174 | {
|
---|
[f10b0c] | 175 | queryAtom(param, token, description);
|
---|
[9ee38b] | 176 | }
|
---|
| 177 |
|
---|
[f10b0c] | 178 | template <> void Dialog::query< std::vector<const atom *> >(Parameter<std::vector<const atom *> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 179 | {
|
---|
[f10b0c] | 180 | queryAtoms(param, token, description);
|
---|
[9ee38b] | 181 | }
|
---|
| 182 |
|
---|
[f10b0c] | 183 | template <> void Dialog::query<const molecule *>(Parameter<const molecule *> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 184 | {
|
---|
[f10b0c] | 185 | queryMolecule(param, token, description);
|
---|
[9ee38b] | 186 | }
|
---|
| 187 |
|
---|
[f10b0c] | 188 | template <> void Dialog::query< std::vector<const molecule *> >(Parameter<std::vector<const molecule *> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 189 | {
|
---|
[f10b0c] | 190 | queryMolecules(param, token, description);
|
---|
[9ee38b] | 191 | }
|
---|
| 192 |
|
---|
[f10b0c] | 193 | template <> void Dialog::query<Vector>(Parameter<Vector> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 194 | {
|
---|
[9d5531] | 195 | queryVector(param, token, description);
|
---|
[9ee38b] | 196 | }
|
---|
| 197 |
|
---|
[f10b0c] | 198 | template <> void Dialog::query< std::vector<Vector> >(Parameter<std::vector<Vector> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 199 | {
|
---|
[9d5531] | 200 | queryVectors(param, token, description);
|
---|
[72f611] | 201 | }
|
---|
| 202 |
|
---|
[7d9416] | 203 | template <> void Dialog::query<RealSpaceMatrix>(Parameter<RealSpaceMatrix> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 204 | {
|
---|
[7d9416] | 205 | queryRealSpaceMatrix(param, token, description);
|
---|
[9ee38b] | 206 | }
|
---|
| 207 |
|
---|
[f10b0c] | 208 | template <> void Dialog::query<const element *>(Parameter<const element *> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 209 | {
|
---|
[f10b0c] | 210 | queryElement(param, token, description);
|
---|
[9ee38b] | 211 | }
|
---|
| 212 |
|
---|
[f10b0c] | 213 | template <> void Dialog::query< std::vector<const element *> >(Parameter<std::vector<const element *> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 214 | {
|
---|
[f10b0c] | 215 | queryElements(param, token, description);
|
---|
[9ee38b] | 216 | }
|
---|
| 217 |
|
---|
[f10b0c] | 218 | template <> void Dialog::query< boost::filesystem::path >(Parameter<boost::filesystem::path> ¶m, const char *token, std::string description)
|
---|
[6f5dfe] | 219 | {
|
---|
[f10b0c] | 220 | queryFile(param, token, description);
|
---|
[6f5dfe] | 221 | }
|
---|
| 222 |
|
---|
[bd81f9] | 223 | template <> void Dialog::query< std::vector<boost::filesystem::path> >(Parameter<std::vector< boost::filesystem::path> > ¶m, const char *token, std::string description)
|
---|
[2c5765] | 224 | {
|
---|
[bd81f9] | 225 | queryFiles(param, token, description);
|
---|
[2c5765] | 226 | }
|
---|
| 227 |
|
---|
[f10b0c] | 228 | template <> void Dialog::query< RandomNumberDistribution_Parameters >(Parameter<RandomNumberDistribution_Parameters> ¶m, const char *token, std::string description)
|
---|
[0275ad] | 229 | {
|
---|
[f10b0c] | 230 | queryRandomNumberDistribution_Parameters(param, token, description);
|
---|
[0275ad] | 231 | }
|
---|
| 232 |
|
---|
[8df74d] | 233 | /************************** Query Infrastructure ************************/
|
---|
| 234 | /* ---> shifted to folder Query */
|
---|
| 235 | /************************************************************************/
|
---|