[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 |
|
---|
| 28 | class Atom;
|
---|
| 29 | class Box;
|
---|
| 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(){
|
---|
[d3a5ea] | 54 | if(checkAll()){
|
---|
| 55 | setAll();
|
---|
| 56 | return true;
|
---|
| 57 | }
|
---|
| 58 | else{
|
---|
| 59 | return false;
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | bool Dialog::checkAll(){
|
---|
[45f5d6] | 64 | list<Query*>::iterator iter;
|
---|
| 65 | bool retval = true;
|
---|
| 66 | for(iter=queries.begin(); iter!=queries.end(); iter++){
|
---|
| 67 | retval &= (*iter)->handle();
|
---|
| 68 | // if any query fails (is canceled), we can end the handling process
|
---|
[94d131] | 69 | if(!retval) {
|
---|
[47d041] | 70 | ELOG(1, "The following query failed: " << (**iter).getTitle() << ".");
|
---|
[45f5d6] | 71 | break;
|
---|
[94d131] | 72 | }
|
---|
[45f5d6] | 73 | }
|
---|
| 74 | return retval;
|
---|
[f5a86a] | 75 | }
|
---|
| 76 |
|
---|
[d3a5ea] | 77 | void Dialog::setAll(){
|
---|
| 78 | list<Query*>::iterator iter;
|
---|
| 79 | for(iter=queries.begin(); iter!=queries.end(); iter++) {
|
---|
| 80 | (*iter)->setResult();
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[c508ef5] | 84 | bool Dialog::hasQueries(){
|
---|
| 85 | return queries.size();
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[f10b0c] | 88 | template <> void Dialog::query<void *>(Parameter<void *> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 89 | {
|
---|
| 90 | queryEmpty(token, description);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[f10b0c] | 93 | template <> void Dialog::query<bool>(Parameter<bool> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 94 | {
|
---|
[f10b0c] | 95 | queryBoolean(param, token, description);
|
---|
[9ee38b] | 96 | }
|
---|
| 97 |
|
---|
[f10b0c] | 98 | template <> void Dialog::query<int>(Parameter<int> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 99 | {
|
---|
[f10b0c] | 100 | queryInt(param, token, description);
|
---|
[9ee38b] | 101 | }
|
---|
| 102 |
|
---|
[f10b0c] | 103 | template <> void Dialog::query< std::vector<int> >(Parameter<std::vector<int> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 104 | {
|
---|
[f10b0c] | 105 | queryInts(param, token, description);
|
---|
[9ee38b] | 106 | }
|
---|
| 107 |
|
---|
[f10b0c] | 108 | template <> void Dialog::query<unsigned int>(Parameter<unsigned int> ¶m, const char *token, std::string description)
|
---|
[838cd0] | 109 | {
|
---|
[f10b0c] | 110 | queryUnsignedInt(param, token, description);
|
---|
[838cd0] | 111 | }
|
---|
| 112 |
|
---|
[f10b0c] | 113 | template <> void Dialog::query< std::vector<unsigned int> >(Parameter<std::vector<unsigned int> > ¶m, const char *token, std::string description)
|
---|
[12948c] | 114 | {
|
---|
[f10b0c] | 115 | queryUnsignedInts(param, token, description);
|
---|
[12948c] | 116 | }
|
---|
| 117 |
|
---|
[f10b0c] | 118 | template <> void Dialog::query<double>(Parameter<double> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 119 | {
|
---|
[f10b0c] | 120 | queryDouble(param, token, description);
|
---|
[9ee38b] | 121 | }
|
---|
| 122 |
|
---|
[f10b0c] | 123 | template <> void Dialog::query< std::vector<double> >(Parameter<std::vector<double> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 124 | {
|
---|
[f10b0c] | 125 | queryDoubles(param, token, description);
|
---|
[9ee38b] | 126 | }
|
---|
| 127 |
|
---|
[f10b0c] | 128 | template <> void Dialog::query<std::string>(Parameter<std::string> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 129 | {
|
---|
[f10b0c] | 130 | queryString(param, token, description);
|
---|
[9ee38b] | 131 | }
|
---|
| 132 |
|
---|
[f10b0c] | 133 | template <> void Dialog::query< std::vector<std::string> >(Parameter<std::vector<std::string> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 134 | {
|
---|
[f10b0c] | 135 | queryStrings(param, token, description);
|
---|
[9ee38b] | 136 | }
|
---|
| 137 |
|
---|
[f10b0c] | 138 | template <> void Dialog::query<const atom *>(Parameter<const atom *> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 139 | {
|
---|
[f10b0c] | 140 | queryAtom(param, token, description);
|
---|
[9ee38b] | 141 | }
|
---|
| 142 |
|
---|
[f10b0c] | 143 | template <> void Dialog::query< std::vector<const atom *> >(Parameter<std::vector<const atom *> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 144 | {
|
---|
[f10b0c] | 145 | queryAtoms(param, token, description);
|
---|
[9ee38b] | 146 | }
|
---|
| 147 |
|
---|
[f10b0c] | 148 | template <> void Dialog::query<const molecule *>(Parameter<const molecule *> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 149 | {
|
---|
[f10b0c] | 150 | queryMolecule(param, token, description);
|
---|
[9ee38b] | 151 | }
|
---|
| 152 |
|
---|
[f10b0c] | 153 | template <> void Dialog::query< std::vector<const molecule *> >(Parameter<std::vector<const molecule *> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 154 | {
|
---|
[f10b0c] | 155 | queryMolecules(param, token, description);
|
---|
[9ee38b] | 156 | }
|
---|
| 157 |
|
---|
[f10b0c] | 158 | template <> void Dialog::query<Vector>(Parameter<Vector> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 159 | {
|
---|
[f10b0c] | 160 | queryVector(param, token, false, description);
|
---|
[9ee38b] | 161 | }
|
---|
| 162 |
|
---|
[f10b0c] | 163 | template <> void Dialog::query< std::vector<Vector> >(Parameter<std::vector<Vector> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 164 | {
|
---|
[f10b0c] | 165 | queryVectors(param, token, false, description);
|
---|
[9ee38b] | 166 | }
|
---|
| 167 |
|
---|
[f10b0c] | 168 | template <> void Dialog::query<BoxVector>(Parameter<BoxVector> ¶m, const char *token, std::string description)
|
---|
[72f611] | 169 | {
|
---|
[f10b0c] | 170 | ASSERT(0, "TODO: query<BoxVector>");
|
---|
| 171 | //queryVector(param, token, true, description);
|
---|
[72f611] | 172 | }
|
---|
| 173 |
|
---|
[f10b0c] | 174 | template <> void Dialog::query< std::vector<BoxVector> >(Parameter<std::vector<BoxVector> > ¶m, const char *token, std::string description)
|
---|
[72f611] | 175 | {
|
---|
[f10b0c] | 176 | ASSERT(0, "TODO: query<vector<BoxVector> >");
|
---|
| 177 | //queryVectors(param, token, true, description);
|
---|
[72f611] | 178 | }
|
---|
| 179 |
|
---|
[f10b0c] | 180 | template <> void Dialog::query<Box>(Parameter<Box> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 181 | {
|
---|
[f10b0c] | 182 | queryBox(param, token, description);
|
---|
[9ee38b] | 183 | }
|
---|
| 184 |
|
---|
[f10b0c] | 185 | template <> void Dialog::query<const element *>(Parameter<const element *> ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 186 | {
|
---|
[f10b0c] | 187 | queryElement(param, token, description);
|
---|
[9ee38b] | 188 | }
|
---|
| 189 |
|
---|
[f10b0c] | 190 | template <> void Dialog::query< std::vector<const element *> >(Parameter<std::vector<const element *> > ¶m, const char *token, std::string description)
|
---|
[9ee38b] | 191 | {
|
---|
[f10b0c] | 192 | queryElements(param, token, description);
|
---|
[9ee38b] | 193 | }
|
---|
| 194 |
|
---|
[f10b0c] | 195 | template <> void Dialog::query< boost::filesystem::path >(Parameter<boost::filesystem::path> ¶m, const char *token, std::string description)
|
---|
[6f5dfe] | 196 | {
|
---|
[f10b0c] | 197 | queryFile(param, token, description);
|
---|
[6f5dfe] | 198 | }
|
---|
| 199 |
|
---|
[f10b0c] | 200 | template <> void Dialog::query< RandomNumberDistribution_Parameters >(Parameter<RandomNumberDistribution_Parameters> ¶m, const char *token, std::string description)
|
---|
[0275ad] | 201 | {
|
---|
[f10b0c] | 202 | queryRandomNumberDistribution_Parameters(param, token, description);
|
---|
[0275ad] | 203 | }
|
---|
| 204 |
|
---|
[8df74d] | 205 | /************************** Query Infrastructure ************************/
|
---|
| 206 | /* ---> shifted to folder Query */
|
---|
| 207 | /************************************************************************/
|
---|