[bcf653] | 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 |
|
---|
[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 |
|
---|
[112b09] | 20 | #include "Helpers/MemDebug.hpp"
|
---|
| 21 |
|
---|
[5079a0] | 22 | #include "Dialog.hpp"
|
---|
[861874] | 23 | #include "Actions/ValueStorage.hpp"
|
---|
[f5a86a] | 24 |
|
---|
[952f38] | 25 | #include "Helpers/Verbose.hpp"
|
---|
[97ebf8] | 26 | #include "atom.hpp"
|
---|
[9ee38b] | 27 | #include "Box.hpp"
|
---|
[97ebf8] | 28 | #include "element.hpp"
|
---|
| 29 | #include "molecule.hpp"
|
---|
[72f611] | 30 | #include "LinearAlgebra/BoxVector.hpp"
|
---|
[57f243] | 31 | #include "LinearAlgebra/Vector.hpp"
|
---|
| 32 | #include "LinearAlgebra/Matrix.hpp"
|
---|
[2ededc2] | 33 |
|
---|
[f5a86a] | 34 | using namespace std;
|
---|
| 35 |
|
---|
| 36 | Dialog::Dialog()
|
---|
| 37 | {
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | Dialog::~Dialog()
|
---|
| 41 | {
|
---|
[45f5d6] | 42 | list<Query*>::iterator iter;
|
---|
| 43 | for(iter=queries.begin();iter!=queries.end();iter++){
|
---|
| 44 | delete (*iter);
|
---|
| 45 | }
|
---|
[f5a86a] | 46 | }
|
---|
| 47 |
|
---|
[45f5d6] | 48 | void Dialog::registerQuery(Query *query){
|
---|
| 49 | queries.push_back(query);
|
---|
| 50 | }
|
---|
[f5a86a] | 51 |
|
---|
[45f5d6] | 52 | bool Dialog::display(){
|
---|
[d3a5ea] | 53 | if(checkAll()){
|
---|
| 54 | setAll();
|
---|
| 55 | return true;
|
---|
| 56 | }
|
---|
| 57 | else{
|
---|
| 58 | return false;
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | bool Dialog::checkAll(){
|
---|
[45f5d6] | 63 | list<Query*>::iterator iter;
|
---|
| 64 | bool retval = true;
|
---|
| 65 | for(iter=queries.begin(); iter!=queries.end(); iter++){
|
---|
| 66 | retval &= (*iter)->handle();
|
---|
| 67 | // if any query fails (is canceled), we can end the handling process
|
---|
[94d131] | 68 | if(!retval) {
|
---|
| 69 | DoeLog(1) && (eLog() << Verbose(1) << "The following query failed: " << (**iter).getTitle() << "." << endl);
|
---|
[45f5d6] | 70 | break;
|
---|
[94d131] | 71 | }
|
---|
[45f5d6] | 72 | }
|
---|
| 73 | return retval;
|
---|
[f5a86a] | 74 | }
|
---|
| 75 |
|
---|
[d3a5ea] | 76 | void Dialog::setAll(){
|
---|
| 77 | list<Query*>::iterator iter;
|
---|
| 78 | for(iter=queries.begin(); iter!=queries.end(); iter++) {
|
---|
| 79 | (*iter)->setResult();
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[c508ef5] | 83 | bool Dialog::hasQueries(){
|
---|
| 84 | return queries.size();
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[9ee38b] | 87 | template <> void Dialog::query<void *>(const char *token, std::string description)
|
---|
| 88 | {
|
---|
| 89 | queryEmpty(token, description);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | template <> void Dialog::query<bool>(const char *token, std::string description)
|
---|
| 93 | {
|
---|
| 94 | queryBoolean(token, description);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | template <> void Dialog::query<int>(const char *token, std::string description)
|
---|
| 98 | {
|
---|
| 99 | queryInt(token, description);
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | template <> void Dialog::query< std::vector<int> >(const char *token, std::string description)
|
---|
| 103 | {
|
---|
| 104 | queryInts(token, description);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | template <> void Dialog::query<double>(const char *token, std::string description)
|
---|
| 108 | {
|
---|
| 109 | queryDouble(token, description);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | template <> void Dialog::query< std::vector<double> >(const char *token, std::string description)
|
---|
| 113 | {
|
---|
| 114 | queryDoubles(token, description);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | template <> void Dialog::query<std::string>(const char *token, std::string description)
|
---|
| 118 | {
|
---|
| 119 | queryString(token, description);
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | template <> void Dialog::query< std::vector<std::string> >(const char *token, std::string description)
|
---|
| 123 | {
|
---|
| 124 | queryStrings(token, description);
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | template <> void Dialog::query<atom *>(const char *token, std::string description)
|
---|
| 128 | {
|
---|
| 129 | queryAtom(token, description);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | template <> void Dialog::query< std::vector<atom *> >(const char *token, std::string description)
|
---|
| 133 | {
|
---|
| 134 | queryAtoms(token, description);
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | template <> void Dialog::query<molecule *>(const char *token, std::string description)
|
---|
| 138 | {
|
---|
| 139 | queryMolecule(token, description);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | template <> void Dialog::query< std::vector<molecule *> >(const char *token, std::string description)
|
---|
| 143 | {
|
---|
| 144 | queryMolecules(token, description);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | template <> void Dialog::query<Vector>(const char *token, std::string description)
|
---|
| 148 | {
|
---|
| 149 | queryVector(token, false, description);
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | template <> void Dialog::query< std::vector<Vector> >(const char *token, std::string description)
|
---|
| 153 | {
|
---|
| 154 | queryVectors(token, false, description);
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[72f611] | 157 | template <> void Dialog::query<BoxVector>(const char *token, std::string description)
|
---|
| 158 | {
|
---|
| 159 | queryVector(token, true, description);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | template <> void Dialog::query< std::vector<BoxVector> >(const char *token, std::string description)
|
---|
| 163 | {
|
---|
| 164 | queryVectors(token, true, description);
|
---|
| 165 | }
|
---|
| 166 |
|
---|
[9ee38b] | 167 | template <> void Dialog::query<Box>(const char *token, std::string description)
|
---|
| 168 | {
|
---|
| 169 | queryBox(token, description);
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | template <> void Dialog::query<const element *>(const char *token, std::string description)
|
---|
| 173 | {
|
---|
| 174 | queryElement(token, description);
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | template <> void Dialog::query< std::vector<const element *> >(const char *token, std::string description)
|
---|
| 178 | {
|
---|
| 179 | queryElements(token, description);
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[6f5dfe] | 182 | template <> void Dialog::query< boost::filesystem::path >(const char *token, std::string description)
|
---|
| 183 | {
|
---|
| 184 | queryFile(token, description);
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[7aa000] | 187 | /****************** Query types Infrastructure **************************/
|
---|
| 188 |
|
---|
| 189 | // Base class
|
---|
[a2ab15] | 190 | Dialog::Query::Query(string _title, string _description) :
|
---|
| 191 | title(_title),
|
---|
| 192 | description(_description)
|
---|
[45f5d6] | 193 | {}
|
---|
[f5a86a] | 194 |
|
---|
[45f5d6] | 195 | Dialog::Query::~Query() {}
|
---|
| 196 |
|
---|
| 197 | const std::string Dialog::Query::getTitle() const{
|
---|
| 198 | return title;
|
---|
[f5a86a] | 199 | }
|
---|
| 200 |
|
---|
[a2ab15] | 201 | const std::string Dialog::Query::getDescription() const{
|
---|
| 202 | return description;
|
---|
| 203 | }
|
---|
[86466e] | 204 | // empty Queries
|
---|
| 205 |
|
---|
| 206 | Dialog::EmptyQuery::EmptyQuery(string title, std::string description) :
|
---|
| 207 | Query(title, description)
|
---|
| 208 | {}
|
---|
| 209 |
|
---|
| 210 | Dialog::EmptyQuery::~EmptyQuery() {}
|
---|
| 211 |
|
---|
| 212 | void Dialog::EmptyQuery::setResult() {
|
---|
| 213 | }
|
---|
| 214 |
|
---|
[7aa000] | 215 | // Int Queries
|
---|
| 216 |
|
---|
[75dc28] | 217 | Dialog::IntQuery::IntQuery(string title, std::string description) :
|
---|
| 218 | Query(title, description)
|
---|
[45f5d6] | 219 | {}
|
---|
| 220 |
|
---|
| 221 | Dialog::IntQuery::~IntQuery() {}
|
---|
| 222 |
|
---|
| 223 | void Dialog::IntQuery::setResult() {
|
---|
[3731b4] | 224 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[f5a86a] | 225 | }
|
---|
[45f5d6] | 226 |
|
---|
[7cd6e7] | 227 | // Ints Queries
|
---|
| 228 |
|
---|
| 229 | Dialog::IntsQuery::IntsQuery(string title, std::string description) :
|
---|
| 230 | Query(title, description)
|
---|
| 231 | {}
|
---|
| 232 |
|
---|
| 233 | Dialog::IntsQuery::~IntsQuery() {}
|
---|
| 234 |
|
---|
| 235 | void Dialog::IntsQuery::setResult() {
|
---|
| 236 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | // Bool Queries
|
---|
[97ebf8] | 240 |
|
---|
[75dc28] | 241 | Dialog::BooleanQuery::BooleanQuery(string title,std::string description) :
|
---|
| 242 | Query(title, description)
|
---|
[97ebf8] | 243 | {}
|
---|
| 244 |
|
---|
| 245 | Dialog::BooleanQuery::~BooleanQuery() {}
|
---|
| 246 |
|
---|
| 247 | void Dialog::BooleanQuery::setResult() {
|
---|
[3731b4] | 248 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[97ebf8] | 249 | }
|
---|
| 250 |
|
---|
[7aa000] | 251 | // String Queries
|
---|
| 252 |
|
---|
[75dc28] | 253 | Dialog::StringQuery::StringQuery(string title,std::string _description) :
|
---|
| 254 | Query(title, _description)
|
---|
[45f5d6] | 255 | {}
|
---|
| 256 |
|
---|
| 257 | Dialog::StringQuery::~StringQuery() {};
|
---|
| 258 |
|
---|
| 259 | void Dialog::StringQuery::setResult() {
|
---|
[3731b4] | 260 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[45f5d6] | 261 | }
|
---|
| 262 |
|
---|
[cd8e55] | 263 | // Strings Queries
|
---|
| 264 |
|
---|
[75dc28] | 265 | Dialog::StringsQuery::StringsQuery(string title,std::string _description) :
|
---|
| 266 | Query(title, _description)
|
---|
[cd8e55] | 267 | {}
|
---|
| 268 |
|
---|
| 269 | Dialog::StringsQuery::~StringsQuery() {};
|
---|
| 270 |
|
---|
| 271 | void Dialog::StringsQuery::setResult() {
|
---|
[3731b4] | 272 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[cd8e55] | 273 | }
|
---|
| 274 |
|
---|
[2ededc2] | 275 | // Double Queries
|
---|
| 276 |
|
---|
[75dc28] | 277 | Dialog::DoubleQuery::DoubleQuery(string title, std::string _description) :
|
---|
| 278 | Query(title, _description)
|
---|
[2ededc2] | 279 | {}
|
---|
| 280 |
|
---|
| 281 | Dialog::DoubleQuery::~DoubleQuery() {};
|
---|
| 282 |
|
---|
| 283 | void Dialog::DoubleQuery::setResult() {
|
---|
[3731b4] | 284 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[2ededc2] | 285 | }
|
---|
| 286 |
|
---|
[7cd6e7] | 287 | // Doubles Queries
|
---|
| 288 |
|
---|
| 289 | Dialog::DoublesQuery::DoublesQuery(string title, std::string _description) :
|
---|
| 290 | Query(title, _description)
|
---|
| 291 | {}
|
---|
| 292 |
|
---|
| 293 | Dialog::DoublesQuery::~DoublesQuery() {};
|
---|
| 294 |
|
---|
| 295 | void Dialog::DoublesQuery::setResult() {
|
---|
| 296 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 297 | }
|
---|
| 298 |
|
---|
[2ededc2] | 299 |
|
---|
[97ebf8] | 300 | // Atom Queries
|
---|
| 301 |
|
---|
[75dc28] | 302 | Dialog::AtomQuery::AtomQuery(string title, std::string _description) :
|
---|
[97ebf8] | 303 | Query(title, _description),
|
---|
[75dc28] | 304 | tmp(0)
|
---|
[97ebf8] | 305 | {}
|
---|
| 306 |
|
---|
| 307 | Dialog::AtomQuery::~AtomQuery() {}
|
---|
| 308 |
|
---|
| 309 | void Dialog::AtomQuery::setResult() {
|
---|
[3731b4] | 310 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[97ebf8] | 311 | }
|
---|
| 312 |
|
---|
[7cd6e7] | 313 | // Atoms Queries
|
---|
| 314 |
|
---|
| 315 | Dialog::AtomsQuery::AtomsQuery(string title, std::string _description) :
|
---|
| 316 | Query(title, _description),
|
---|
| 317 | tmp(0)
|
---|
| 318 | {}
|
---|
| 319 |
|
---|
| 320 | Dialog::AtomsQuery::~AtomsQuery() {}
|
---|
| 321 |
|
---|
| 322 | void Dialog::AtomsQuery::setResult() {
|
---|
| 323 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 324 | }
|
---|
| 325 |
|
---|
[7aa000] | 326 | // Molecule Queries
|
---|
| 327 |
|
---|
[75dc28] | 328 | Dialog::MoleculeQuery::MoleculeQuery(string title, std::string _description) :
|
---|
[a2ab15] | 329 | Query(title, _description),
|
---|
[75dc28] | 330 | tmp(0)
|
---|
[7aa000] | 331 | {}
|
---|
| 332 |
|
---|
| 333 | Dialog::MoleculeQuery::~MoleculeQuery() {}
|
---|
| 334 |
|
---|
| 335 | void Dialog::MoleculeQuery::setResult() {
|
---|
[3731b4] | 336 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[7aa000] | 337 | }
|
---|
[2ededc2] | 338 |
|
---|
[7cd6e7] | 339 | // Molecules Queries
|
---|
| 340 |
|
---|
| 341 | Dialog::MoleculesQuery::MoleculesQuery(string title, std::string _description) :
|
---|
| 342 | Query(title, _description),
|
---|
| 343 | tmp(0)
|
---|
| 344 | {}
|
---|
| 345 |
|
---|
| 346 | Dialog::MoleculesQuery::~MoleculesQuery() {}
|
---|
| 347 |
|
---|
| 348 | void Dialog::MoleculesQuery::setResult() {
|
---|
| 349 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 350 | }
|
---|
| 351 |
|
---|
[2ededc2] | 352 | // Vector Queries
|
---|
| 353 |
|
---|
[75dc28] | 354 | Dialog::VectorQuery::VectorQuery(std::string title,bool _check, std::string _description) :
|
---|
[a2ab15] | 355 | Query(title, _description),
|
---|
[75dc28] | 356 | check(_check)
|
---|
[7cd6e7] | 357 | {}
|
---|
[2ededc2] | 358 |
|
---|
| 359 | Dialog::VectorQuery::~VectorQuery()
|
---|
[7cd6e7] | 360 | {}
|
---|
[2ededc2] | 361 |
|
---|
| 362 | void Dialog::VectorQuery::setResult() {
|
---|
[3731b4] | 363 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[2ededc2] | 364 | }
|
---|
[5a7243] | 365 |
|
---|
[7cd6e7] | 366 | // Vectors Queries
|
---|
| 367 |
|
---|
| 368 | Dialog::VectorsQuery::VectorsQuery(std::string title,bool _check, std::string _description) :
|
---|
| 369 | Query(title, _description),
|
---|
| 370 | check(_check)
|
---|
| 371 | {}
|
---|
| 372 |
|
---|
| 373 | Dialog::VectorsQuery::~VectorsQuery()
|
---|
| 374 | {}
|
---|
| 375 |
|
---|
| 376 | void Dialog::VectorsQuery::setResult() {
|
---|
| 377 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 378 | }
|
---|
| 379 |
|
---|
[97ebf8] | 380 | // Box Queries
|
---|
| 381 |
|
---|
[75dc28] | 382 | Dialog::BoxQuery::BoxQuery(std::string title, std::string _description) :
|
---|
| 383 | Query(title, _description)
|
---|
[8bc733] | 384 | {}
|
---|
[97ebf8] | 385 |
|
---|
| 386 | Dialog::BoxQuery::~BoxQuery()
|
---|
[8bc733] | 387 | {}
|
---|
[97ebf8] | 388 |
|
---|
| 389 | void Dialog::BoxQuery::setResult() {
|
---|
[3731b4] | 390 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[97ebf8] | 391 | }
|
---|
| 392 |
|
---|
[5a7243] | 393 | // Element Queries
|
---|
[75dc28] | 394 | Dialog::ElementQuery::ElementQuery(std::string title, std::string _description) :
|
---|
| 395 | Query(title, _description)
|
---|
[5a7243] | 396 | {}
|
---|
| 397 |
|
---|
| 398 | Dialog::ElementQuery::~ElementQuery(){}
|
---|
| 399 |
|
---|
| 400 | void Dialog::ElementQuery::setResult(){
|
---|
[3731b4] | 401 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[5a7243] | 402 | }
|
---|
[7cd6e7] | 403 |
|
---|
| 404 | // Elements Queries
|
---|
| 405 | Dialog::ElementsQuery::ElementsQuery(std::string title, std::string _description) :
|
---|
| 406 | Query(title, _description)
|
---|
| 407 | {}
|
---|
| 408 |
|
---|
| 409 | Dialog::ElementsQuery::~ElementsQuery(){}
|
---|
| 410 |
|
---|
| 411 | void Dialog::ElementsQuery::setResult(){
|
---|
| 412 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 413 | }
|
---|
[6f5dfe] | 414 |
|
---|
| 415 | // File Queries
|
---|
| 416 | Dialog::FileQuery::FileQuery(std::string title, std::string _description) :
|
---|
| 417 | Query(title, _description)
|
---|
| 418 | {}
|
---|
| 419 |
|
---|
| 420 | Dialog::FileQuery::~FileQuery(){}
|
---|
| 421 |
|
---|
| 422 | void Dialog::FileQuery::setResult(){
|
---|
| 423 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 424 | }
|
---|