| [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 | 
 | 
|---|
| [9ee38b] | 88 | template <> void Dialog::query<void *>(const char *token, std::string description)
 | 
|---|
 | 89 | {
 | 
|---|
 | 90 |   queryEmpty(token, description);
 | 
|---|
 | 91 | }
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 | template <> void Dialog::query<bool>(const char *token, std::string description)
 | 
|---|
 | 94 | {
 | 
|---|
 | 95 |   queryBoolean(token, description);
 | 
|---|
 | 96 | }
 | 
|---|
 | 97 | 
 | 
|---|
 | 98 | template <> void Dialog::query<int>(const char *token, std::string description)
 | 
|---|
 | 99 | {
 | 
|---|
 | 100 |   queryInt(token, description);
 | 
|---|
 | 101 | }
 | 
|---|
 | 102 | 
 | 
|---|
 | 103 | template <> void Dialog::query< std::vector<int> >(const char *token, std::string description)
 | 
|---|
 | 104 | {
 | 
|---|
 | 105 |   queryInts(token, description);
 | 
|---|
 | 106 | }
 | 
|---|
 | 107 | 
 | 
|---|
| [838cd0] | 108 | template <> void Dialog::query<unsigned int>(const char *token, std::string description)
 | 
|---|
 | 109 | {
 | 
|---|
 | 110 |   queryUnsignedInt(token, description);
 | 
|---|
 | 111 | }
 | 
|---|
 | 112 | 
 | 
|---|
| [12948c] | 113 | template <> void Dialog::query< std::vector<unsigned int> >(const char *token, std::string description)
 | 
|---|
 | 114 | {
 | 
|---|
 | 115 |   queryUnsignedInts(token, description);
 | 
|---|
 | 116 | }
 | 
|---|
 | 117 | 
 | 
|---|
| [9ee38b] | 118 | template <> void Dialog::query<double>(const char *token, std::string description)
 | 
|---|
 | 119 | {
 | 
|---|
 | 120 |   queryDouble(token, description);
 | 
|---|
 | 121 | }
 | 
|---|
 | 122 | 
 | 
|---|
 | 123 | template <> void Dialog::query< std::vector<double> >(const char *token, std::string description)
 | 
|---|
 | 124 | {
 | 
|---|
 | 125 |   queryDoubles(token, description);
 | 
|---|
 | 126 | }
 | 
|---|
 | 127 | 
 | 
|---|
 | 128 | template <> void Dialog::query<std::string>(const char *token, std::string description)
 | 
|---|
 | 129 | {
 | 
|---|
 | 130 |   queryString(token, description);
 | 
|---|
 | 131 | }
 | 
|---|
 | 132 | 
 | 
|---|
 | 133 | template <> void Dialog::query< std::vector<std::string> >(const char *token, std::string description)
 | 
|---|
 | 134 | {
 | 
|---|
 | 135 |   queryStrings(token, description);
 | 
|---|
 | 136 | }
 | 
|---|
 | 137 | 
 | 
|---|
| [e4afb4] | 138 | template <> void Dialog::query<const atom *>(const char *token, std::string description)
 | 
|---|
| [9ee38b] | 139 | {
 | 
|---|
 | 140 |   queryAtom(token, description);
 | 
|---|
 | 141 | }
 | 
|---|
 | 142 | 
 | 
|---|
| [e4afb4] | 143 | template <> void Dialog::query< std::vector<const atom *> >(const char *token, std::string description)
 | 
|---|
| [9ee38b] | 144 | {
 | 
|---|
 | 145 |   queryAtoms(token, description);
 | 
|---|
 | 146 | }
 | 
|---|
 | 147 | 
 | 
|---|
| [e4afb4] | 148 | template <> void Dialog::query<const molecule *>(const char *token, std::string description)
 | 
|---|
| [9ee38b] | 149 | {
 | 
|---|
 | 150 |   queryMolecule(token, description);
 | 
|---|
 | 151 | }
 | 
|---|
 | 152 | 
 | 
|---|
| [e4afb4] | 153 | template <> void Dialog::query< std::vector<const molecule *> >(const char *token, std::string description)
 | 
|---|
| [9ee38b] | 154 | {
 | 
|---|
 | 155 |   queryMolecules(token, description);
 | 
|---|
 | 156 | }
 | 
|---|
 | 157 | 
 | 
|---|
 | 158 | template <> void Dialog::query<Vector>(const char *token, std::string description)
 | 
|---|
 | 159 | {
 | 
|---|
 | 160 |   queryVector(token, false, description);
 | 
|---|
 | 161 | }
 | 
|---|
 | 162 | 
 | 
|---|
 | 163 | template <> void Dialog::query< std::vector<Vector> >(const char *token, std::string description)
 | 
|---|
 | 164 | {
 | 
|---|
 | 165 |   queryVectors(token, false, description);
 | 
|---|
 | 166 | }
 | 
|---|
 | 167 | 
 | 
|---|
| [72f611] | 168 | template <> void Dialog::query<BoxVector>(const char *token, std::string description)
 | 
|---|
 | 169 | {
 | 
|---|
 | 170 |   queryVector(token, true, description);
 | 
|---|
 | 171 | }
 | 
|---|
 | 172 | 
 | 
|---|
 | 173 | template <> void Dialog::query< std::vector<BoxVector> >(const char *token, std::string description)
 | 
|---|
 | 174 | {
 | 
|---|
 | 175 |   queryVectors(token, true, description);
 | 
|---|
 | 176 | }
 | 
|---|
 | 177 | 
 | 
|---|
| [9ee38b] | 178 | template <> void Dialog::query<Box>(const char *token, std::string description)
 | 
|---|
 | 179 | {
 | 
|---|
 | 180 |   queryBox(token, description);
 | 
|---|
 | 181 | }
 | 
|---|
 | 182 | 
 | 
|---|
 | 183 | template <> void Dialog::query<const element *>(const char *token, std::string description)
 | 
|---|
 | 184 | {
 | 
|---|
 | 185 |   queryElement(token, description);
 | 
|---|
 | 186 | }
 | 
|---|
 | 187 | 
 | 
|---|
 | 188 | template <> void Dialog::query< std::vector<const element *> >(const char *token, std::string description)
 | 
|---|
 | 189 | {
 | 
|---|
 | 190 |   queryElements(token, description);
 | 
|---|
 | 191 | }
 | 
|---|
 | 192 | 
 | 
|---|
| [6f5dfe] | 193 | template <> void Dialog::query< boost::filesystem::path >(const char *token, std::string description)
 | 
|---|
 | 194 | {
 | 
|---|
 | 195 |   queryFile(token, description);
 | 
|---|
 | 196 | }
 | 
|---|
 | 197 | 
 | 
|---|
| [0275ad] | 198 | template <> void Dialog::query< RandomNumberDistribution_Parameters >(const char *token, std::string description)
 | 
|---|
 | 199 | {
 | 
|---|
 | 200 |   queryRandomNumberDistribution_Parameters(token, description);
 | 
|---|
 | 201 | }
 | 
|---|
 | 202 | 
 | 
|---|
| [8df74d] | 203 | /************************** Query Infrastructure ************************/
 | 
|---|
 | 204 | /*       ---> shifted to folder Query                                   */
 | 
|---|
 | 205 | /************************************************************************/
 | 
|---|