| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2010 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 "Helpers/MemDebug.hpp" | 
|---|
| 21 |  | 
|---|
| 22 | #include "Dialog.hpp" | 
|---|
| 23 | #include "Actions/ValueStorage.hpp" | 
|---|
| 24 |  | 
|---|
| 25 | #include "Helpers/Verbose.hpp" | 
|---|
| 26 | #include "atom.hpp" | 
|---|
| 27 | #include "element.hpp" | 
|---|
| 28 | #include "molecule.hpp" | 
|---|
| 29 | #include "LinearAlgebra/Vector.hpp" | 
|---|
| 30 | #include "LinearAlgebra/Matrix.hpp" | 
|---|
| 31 | #include "Box.hpp" | 
|---|
| 32 |  | 
|---|
| 33 | using namespace std; | 
|---|
| 34 |  | 
|---|
| 35 | Dialog::Dialog() | 
|---|
| 36 | { | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | Dialog::~Dialog() | 
|---|
| 40 | { | 
|---|
| 41 | list<Query*>::iterator iter; | 
|---|
| 42 | for(iter=queries.begin();iter!=queries.end();iter++){ | 
|---|
| 43 | delete (*iter); | 
|---|
| 44 | } | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 | void Dialog::registerQuery(Query *query){ | 
|---|
| 48 | queries.push_back(query); | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | bool Dialog::display(){ | 
|---|
| 52 | if(checkAll()){ | 
|---|
| 53 | setAll(); | 
|---|
| 54 | return true; | 
|---|
| 55 | } | 
|---|
| 56 | else{ | 
|---|
| 57 | return false; | 
|---|
| 58 | } | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | bool Dialog::checkAll(){ | 
|---|
| 62 | list<Query*>::iterator iter; | 
|---|
| 63 | bool retval = true; | 
|---|
| 64 | for(iter=queries.begin(); iter!=queries.end(); iter++){ | 
|---|
| 65 | retval &= (*iter)->handle(); | 
|---|
| 66 | // if any query fails (is canceled), we can end the handling process | 
|---|
| 67 | if(!retval) { | 
|---|
| 68 | DoeLog(1) && (eLog() << Verbose(1) << "The following query failed: " << (**iter).getTitle() << "." << endl); | 
|---|
| 69 | break; | 
|---|
| 70 | } | 
|---|
| 71 | } | 
|---|
| 72 | return retval; | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | void Dialog::setAll(){ | 
|---|
| 76 | list<Query*>::iterator iter; | 
|---|
| 77 | for(iter=queries.begin(); iter!=queries.end(); iter++) { | 
|---|
| 78 | (*iter)->setResult(); | 
|---|
| 79 | } | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 | bool Dialog::hasQueries(){ | 
|---|
| 83 | return queries.size(); | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | /****************** Query types Infrastructure **************************/ | 
|---|
| 87 |  | 
|---|
| 88 | // Base class | 
|---|
| 89 | Dialog::Query::Query(string _title, string _description) : | 
|---|
| 90 | title(_title), | 
|---|
| 91 | description(_description) | 
|---|
| 92 | {} | 
|---|
| 93 |  | 
|---|
| 94 | Dialog::Query::~Query() {} | 
|---|
| 95 |  | 
|---|
| 96 | const std::string Dialog::Query::getTitle() const{ | 
|---|
| 97 | return title; | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | const std::string Dialog::Query::getDescription() const{ | 
|---|
| 101 | return description; | 
|---|
| 102 | } | 
|---|
| 103 | // empty Queries | 
|---|
| 104 |  | 
|---|
| 105 | Dialog::EmptyQuery::EmptyQuery(string title, std::string description) : | 
|---|
| 106 | Query(title, description) | 
|---|
| 107 | {} | 
|---|
| 108 |  | 
|---|
| 109 | Dialog::EmptyQuery::~EmptyQuery() {} | 
|---|
| 110 |  | 
|---|
| 111 | void Dialog::EmptyQuery::setResult() { | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | // Int Queries | 
|---|
| 115 |  | 
|---|
| 116 | Dialog::IntQuery::IntQuery(string title, std::string description) : | 
|---|
| 117 | Query(title, description) | 
|---|
| 118 | {} | 
|---|
| 119 |  | 
|---|
| 120 | Dialog::IntQuery::~IntQuery() {} | 
|---|
| 121 |  | 
|---|
| 122 | void Dialog::IntQuery::setResult() { | 
|---|
| 123 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 124 | } | 
|---|
| 125 |  | 
|---|
| 126 | // Ints Queries | 
|---|
| 127 |  | 
|---|
| 128 | Dialog::IntsQuery::IntsQuery(string title, std::string description) : | 
|---|
| 129 | Query(title, description) | 
|---|
| 130 | {} | 
|---|
| 131 |  | 
|---|
| 132 | Dialog::IntsQuery::~IntsQuery() {} | 
|---|
| 133 |  | 
|---|
| 134 | void Dialog::IntsQuery::setResult() { | 
|---|
| 135 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 136 | } | 
|---|
| 137 |  | 
|---|
| 138 | // Bool Queries | 
|---|
| 139 |  | 
|---|
| 140 | Dialog::BooleanQuery::BooleanQuery(string title,std::string description) : | 
|---|
| 141 | Query(title, description) | 
|---|
| 142 | {} | 
|---|
| 143 |  | 
|---|
| 144 | Dialog::BooleanQuery::~BooleanQuery() {} | 
|---|
| 145 |  | 
|---|
| 146 | void Dialog::BooleanQuery::setResult() { | 
|---|
| 147 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 148 | } | 
|---|
| 149 |  | 
|---|
| 150 | // String Queries | 
|---|
| 151 |  | 
|---|
| 152 | Dialog::StringQuery::StringQuery(string title,std::string _description) : | 
|---|
| 153 | Query(title, _description) | 
|---|
| 154 | {} | 
|---|
| 155 |  | 
|---|
| 156 | Dialog::StringQuery::~StringQuery() {}; | 
|---|
| 157 |  | 
|---|
| 158 | void Dialog::StringQuery::setResult() { | 
|---|
| 159 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 160 | } | 
|---|
| 161 |  | 
|---|
| 162 | // Strings Queries | 
|---|
| 163 |  | 
|---|
| 164 | Dialog::StringsQuery::StringsQuery(string title,std::string _description) : | 
|---|
| 165 | Query(title, _description) | 
|---|
| 166 | {} | 
|---|
| 167 |  | 
|---|
| 168 | Dialog::StringsQuery::~StringsQuery() {}; | 
|---|
| 169 |  | 
|---|
| 170 | void Dialog::StringsQuery::setResult() { | 
|---|
| 171 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 | // Double Queries | 
|---|
| 175 |  | 
|---|
| 176 | Dialog::DoubleQuery::DoubleQuery(string title, std::string _description) : | 
|---|
| 177 | Query(title, _description) | 
|---|
| 178 | {} | 
|---|
| 179 |  | 
|---|
| 180 | Dialog::DoubleQuery::~DoubleQuery() {}; | 
|---|
| 181 |  | 
|---|
| 182 | void Dialog::DoubleQuery::setResult() { | 
|---|
| 183 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 184 | } | 
|---|
| 185 |  | 
|---|
| 186 | // Doubles Queries | 
|---|
| 187 |  | 
|---|
| 188 | Dialog::DoublesQuery::DoublesQuery(string title, std::string _description) : | 
|---|
| 189 | Query(title, _description) | 
|---|
| 190 | {} | 
|---|
| 191 |  | 
|---|
| 192 | Dialog::DoublesQuery::~DoublesQuery() {}; | 
|---|
| 193 |  | 
|---|
| 194 | void Dialog::DoublesQuery::setResult() { | 
|---|
| 195 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 196 | } | 
|---|
| 197 |  | 
|---|
| 198 |  | 
|---|
| 199 | // Atom Queries | 
|---|
| 200 |  | 
|---|
| 201 | Dialog::AtomQuery::AtomQuery(string title, std::string _description) : | 
|---|
| 202 | Query(title, _description), | 
|---|
| 203 | tmp(0) | 
|---|
| 204 | {} | 
|---|
| 205 |  | 
|---|
| 206 | Dialog::AtomQuery::~AtomQuery() {} | 
|---|
| 207 |  | 
|---|
| 208 | void Dialog::AtomQuery::setResult() { | 
|---|
| 209 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 210 | } | 
|---|
| 211 |  | 
|---|
| 212 | // Atoms Queries | 
|---|
| 213 |  | 
|---|
| 214 | Dialog::AtomsQuery::AtomsQuery(string title, std::string _description) : | 
|---|
| 215 | Query(title, _description), | 
|---|
| 216 | tmp(0) | 
|---|
| 217 | {} | 
|---|
| 218 |  | 
|---|
| 219 | Dialog::AtomsQuery::~AtomsQuery() {} | 
|---|
| 220 |  | 
|---|
| 221 | void Dialog::AtomsQuery::setResult() { | 
|---|
| 222 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 223 | } | 
|---|
| 224 |  | 
|---|
| 225 | // Molecule Queries | 
|---|
| 226 |  | 
|---|
| 227 | Dialog::MoleculeQuery::MoleculeQuery(string title, std::string _description) : | 
|---|
| 228 | Query(title, _description), | 
|---|
| 229 | tmp(0) | 
|---|
| 230 | {} | 
|---|
| 231 |  | 
|---|
| 232 | Dialog::MoleculeQuery::~MoleculeQuery() {} | 
|---|
| 233 |  | 
|---|
| 234 | void Dialog::MoleculeQuery::setResult() { | 
|---|
| 235 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 236 | } | 
|---|
| 237 |  | 
|---|
| 238 | // Molecules Queries | 
|---|
| 239 |  | 
|---|
| 240 | Dialog::MoleculesQuery::MoleculesQuery(string title, std::string _description) : | 
|---|
| 241 | Query(title, _description), | 
|---|
| 242 | tmp(0) | 
|---|
| 243 | {} | 
|---|
| 244 |  | 
|---|
| 245 | Dialog::MoleculesQuery::~MoleculesQuery() {} | 
|---|
| 246 |  | 
|---|
| 247 | void Dialog::MoleculesQuery::setResult() { | 
|---|
| 248 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 249 | } | 
|---|
| 250 |  | 
|---|
| 251 | // Vector Queries | 
|---|
| 252 |  | 
|---|
| 253 | Dialog::VectorQuery::VectorQuery(std::string title,bool _check, std::string _description) : | 
|---|
| 254 | Query(title, _description), | 
|---|
| 255 | check(_check) | 
|---|
| 256 | {} | 
|---|
| 257 |  | 
|---|
| 258 | Dialog::VectorQuery::~VectorQuery() | 
|---|
| 259 | {} | 
|---|
| 260 |  | 
|---|
| 261 | void Dialog::VectorQuery::setResult() { | 
|---|
| 262 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 263 | } | 
|---|
| 264 |  | 
|---|
| 265 | // Vectors Queries | 
|---|
| 266 |  | 
|---|
| 267 | Dialog::VectorsQuery::VectorsQuery(std::string title,bool _check, std::string _description) : | 
|---|
| 268 | Query(title, _description), | 
|---|
| 269 | check(_check) | 
|---|
| 270 | {} | 
|---|
| 271 |  | 
|---|
| 272 | Dialog::VectorsQuery::~VectorsQuery() | 
|---|
| 273 | {} | 
|---|
| 274 |  | 
|---|
| 275 | void Dialog::VectorsQuery::setResult() { | 
|---|
| 276 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 277 | } | 
|---|
| 278 |  | 
|---|
| 279 | // Box Queries | 
|---|
| 280 |  | 
|---|
| 281 | Dialog::BoxQuery::BoxQuery(std::string title, std::string _description) : | 
|---|
| 282 | Query(title, _description) | 
|---|
| 283 | {} | 
|---|
| 284 |  | 
|---|
| 285 | Dialog::BoxQuery::~BoxQuery() | 
|---|
| 286 | {} | 
|---|
| 287 |  | 
|---|
| 288 | void Dialog::BoxQuery::setResult() { | 
|---|
| 289 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 290 | } | 
|---|
| 291 |  | 
|---|
| 292 | // Element Queries | 
|---|
| 293 | Dialog::ElementQuery::ElementQuery(std::string title, std::string _description) : | 
|---|
| 294 | Query(title, _description) | 
|---|
| 295 | {} | 
|---|
| 296 |  | 
|---|
| 297 | Dialog::ElementQuery::~ElementQuery(){} | 
|---|
| 298 |  | 
|---|
| 299 | void Dialog::ElementQuery::setResult(){ | 
|---|
| 300 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 301 | } | 
|---|
| 302 |  | 
|---|
| 303 | // Elements Queries | 
|---|
| 304 | Dialog::ElementsQuery::ElementsQuery(std::string title, std::string _description) : | 
|---|
| 305 | Query(title, _description) | 
|---|
| 306 | {} | 
|---|
| 307 |  | 
|---|
| 308 | Dialog::ElementsQuery::~ElementsQuery(){} | 
|---|
| 309 |  | 
|---|
| 310 | void Dialog::ElementsQuery::setResult(){ | 
|---|
| 311 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp); | 
|---|
| 312 | } | 
|---|