| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | /*
|
|---|
| 9 | * Dialog.cpp
|
|---|
| 10 | *
|
|---|
| 11 | * Created on: Jan 5, 2010
|
|---|
| 12 | * Author: crueger
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | // include config.h
|
|---|
| 16 | #ifdef HAVE_CONFIG_H
|
|---|
| 17 | #include <config.h>
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| 21 |
|
|---|
| 22 | #include "Dialog.hpp"
|
|---|
| 23 | #include "Actions/ValueStorage.hpp"
|
|---|
| 24 |
|
|---|
| 25 | #include "CodePatterns/Log.hpp"
|
|---|
| 26 | #include "CodePatterns/Verbose.hpp"
|
|---|
| 27 |
|
|---|
| 28 | class Atom;
|
|---|
| 29 | class Box;
|
|---|
| 30 | class element;
|
|---|
| 31 | class RealSpaceMatrix;
|
|---|
| 32 | class molecule;
|
|---|
| 33 | class Vector;
|
|---|
| 34 |
|
|---|
| 35 | using namespace std;
|
|---|
| 36 |
|
|---|
| 37 | Dialog::Dialog()
|
|---|
| 38 | {
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | Dialog::~Dialog()
|
|---|
| 42 | {
|
|---|
| 43 | list<Query*>::iterator iter;
|
|---|
| 44 | for(iter=queries.begin();iter!=queries.end();iter++){
|
|---|
| 45 | delete (*iter);
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | void Dialog::registerQuery(Query *query){
|
|---|
| 50 | queries.push_back(query);
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | bool Dialog::display(){
|
|---|
| 54 | if(checkAll()){
|
|---|
| 55 | setAll();
|
|---|
| 56 | return true;
|
|---|
| 57 | }
|
|---|
| 58 | else{
|
|---|
| 59 | return false;
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | bool Dialog::checkAll(){
|
|---|
| 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
|
|---|
| 69 | if(!retval) {
|
|---|
| 70 | ELOG(1, "The following query failed: " << (**iter).getTitle() << ".");
|
|---|
| 71 | break;
|
|---|
| 72 | }
|
|---|
| 73 | }
|
|---|
| 74 | return retval;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | void Dialog::setAll(){
|
|---|
| 78 | list<Query*>::iterator iter;
|
|---|
| 79 | for(iter=queries.begin(); iter!=queries.end(); iter++) {
|
|---|
| 80 | (*iter)->setResult();
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | bool Dialog::hasQueries(){
|
|---|
| 85 | return queries.size();
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | template <> void Dialog::query<void *>(Parameter<void *> ¶m, const char *token, std::string description)
|
|---|
| 89 | {
|
|---|
| 90 | queryEmpty(token, description);
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | template <> void Dialog::query<bool>(Parameter<bool> ¶m, const char *token, std::string description)
|
|---|
| 94 | {
|
|---|
| 95 | queryBoolean(param, token, description);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | template <> void Dialog::query<int>(Parameter<int> ¶m, const char *token, std::string description)
|
|---|
| 99 | {
|
|---|
| 100 | queryInt(param, token, description);
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | template <> void Dialog::query< std::vector<int> >(Parameter<std::vector<int> > ¶m, const char *token, std::string description)
|
|---|
| 104 | {
|
|---|
| 105 | queryInts(param, token, description);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | template <> void Dialog::query<unsigned int>(Parameter<unsigned int> ¶m, const char *token, std::string description)
|
|---|
| 109 | {
|
|---|
| 110 | queryUnsignedInt(param, token, description);
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | template <> void Dialog::query< std::vector<unsigned int> >(Parameter<std::vector<unsigned int> > ¶m, const char *token, std::string description)
|
|---|
| 114 | {
|
|---|
| 115 | queryUnsignedInts(param, token, description);
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | template <> void Dialog::query<double>(Parameter<double> ¶m, const char *token, std::string description)
|
|---|
| 119 | {
|
|---|
| 120 | queryDouble(param, token, description);
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | template <> void Dialog::query< std::vector<double> >(Parameter<std::vector<double> > ¶m, const char *token, std::string description)
|
|---|
| 124 | {
|
|---|
| 125 | queryDoubles(param, token, description);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | template <> void Dialog::query<std::string>(Parameter<std::string> ¶m, const char *token, std::string description)
|
|---|
| 129 | {
|
|---|
| 130 | queryString(param, token, description);
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | template <> void Dialog::query< std::vector<std::string> >(Parameter<std::vector<std::string> > ¶m, const char *token, std::string description)
|
|---|
| 134 | {
|
|---|
| 135 | queryStrings(param, token, description);
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | template <> void Dialog::query<const atom *>(Parameter<const atom *> ¶m, const char *token, std::string description)
|
|---|
| 139 | {
|
|---|
| 140 | queryAtom(param, token, description);
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | template <> void Dialog::query< std::vector<const atom *> >(Parameter<std::vector<const atom *> > ¶m, const char *token, std::string description)
|
|---|
| 144 | {
|
|---|
| 145 | queryAtoms(param, token, description);
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | template <> void Dialog::query<const molecule *>(Parameter<const molecule *> ¶m, const char *token, std::string description)
|
|---|
| 149 | {
|
|---|
| 150 | queryMolecule(param, token, description);
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | template <> void Dialog::query< std::vector<const molecule *> >(Parameter<std::vector<const molecule *> > ¶m, const char *token, std::string description)
|
|---|
| 154 | {
|
|---|
| 155 | queryMolecules(param, token, description);
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | template <> void Dialog::query<Vector>(Parameter<Vector> ¶m, const char *token, std::string description)
|
|---|
| 159 | {
|
|---|
| 160 | queryVector(param, token, false, description);
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | template <> void Dialog::query< std::vector<Vector> >(Parameter<std::vector<Vector> > ¶m, const char *token, std::string description)
|
|---|
| 164 | {
|
|---|
| 165 | queryVectors(param, token, false, description);
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | template <> void Dialog::query<BoxVector>(Parameter<BoxVector> ¶m, const char *token, std::string description)
|
|---|
| 169 | {
|
|---|
| 170 | ASSERT(0, "TODO: query<BoxVector>");
|
|---|
| 171 | //queryVector(param, token, true, description);
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | template <> void Dialog::query< std::vector<BoxVector> >(Parameter<std::vector<BoxVector> > ¶m, const char *token, std::string description)
|
|---|
| 175 | {
|
|---|
| 176 | ASSERT(0, "TODO: query<vector<BoxVector> >");
|
|---|
| 177 | //queryVectors(param, token, true, description);
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | template <> void Dialog::query<Box>(Parameter<Box> ¶m, const char *token, std::string description)
|
|---|
| 181 | {
|
|---|
| 182 | queryBox(param, token, description);
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | template <> void Dialog::query<const element *>(Parameter<const element *> ¶m, const char *token, std::string description)
|
|---|
| 186 | {
|
|---|
| 187 | queryElement(param, token, description);
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | template <> void Dialog::query< std::vector<const element *> >(Parameter<std::vector<const element *> > ¶m, const char *token, std::string description)
|
|---|
| 191 | {
|
|---|
| 192 | queryElements(param, token, description);
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | template <> void Dialog::query< boost::filesystem::path >(Parameter<boost::filesystem::path> ¶m, const char *token, std::string description)
|
|---|
| 196 | {
|
|---|
| 197 | queryFile(param, token, description);
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | template <> void Dialog::query< RandomNumberDistribution_Parameters >(Parameter<RandomNumberDistribution_Parameters> ¶m, const char *token, std::string description)
|
|---|
| 201 | {
|
|---|
| 202 | queryRandomNumberDistribution_Parameters(param, token, description);
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | /************************** Query Infrastructure ************************/
|
|---|
| 206 | /* ---> shifted to folder Query */
|
|---|
| 207 | /************************************************************************/
|
|---|