[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 |
|
---|
[7aa000] | 182 | /****************** Query types Infrastructure **************************/
|
---|
| 183 |
|
---|
| 184 | // Base class
|
---|
[a2ab15] | 185 | Dialog::Query::Query(string _title, string _description) :
|
---|
| 186 | title(_title),
|
---|
| 187 | description(_description)
|
---|
[45f5d6] | 188 | {}
|
---|
[f5a86a] | 189 |
|
---|
[45f5d6] | 190 | Dialog::Query::~Query() {}
|
---|
| 191 |
|
---|
| 192 | const std::string Dialog::Query::getTitle() const{
|
---|
| 193 | return title;
|
---|
[f5a86a] | 194 | }
|
---|
| 195 |
|
---|
[a2ab15] | 196 | const std::string Dialog::Query::getDescription() const{
|
---|
| 197 | return description;
|
---|
| 198 | }
|
---|
[86466e] | 199 | // empty Queries
|
---|
| 200 |
|
---|
| 201 | Dialog::EmptyQuery::EmptyQuery(string title, std::string description) :
|
---|
| 202 | Query(title, description)
|
---|
| 203 | {}
|
---|
| 204 |
|
---|
| 205 | Dialog::EmptyQuery::~EmptyQuery() {}
|
---|
| 206 |
|
---|
| 207 | void Dialog::EmptyQuery::setResult() {
|
---|
| 208 | }
|
---|
| 209 |
|
---|
[7aa000] | 210 | // Int Queries
|
---|
| 211 |
|
---|
[75dc28] | 212 | Dialog::IntQuery::IntQuery(string title, std::string description) :
|
---|
| 213 | Query(title, description)
|
---|
[45f5d6] | 214 | {}
|
---|
| 215 |
|
---|
| 216 | Dialog::IntQuery::~IntQuery() {}
|
---|
| 217 |
|
---|
| 218 | void Dialog::IntQuery::setResult() {
|
---|
[3731b4] | 219 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[f5a86a] | 220 | }
|
---|
[45f5d6] | 221 |
|
---|
[7cd6e7] | 222 | // Ints Queries
|
---|
| 223 |
|
---|
| 224 | Dialog::IntsQuery::IntsQuery(string title, std::string description) :
|
---|
| 225 | Query(title, description)
|
---|
| 226 | {}
|
---|
| 227 |
|
---|
| 228 | Dialog::IntsQuery::~IntsQuery() {}
|
---|
| 229 |
|
---|
| 230 | void Dialog::IntsQuery::setResult() {
|
---|
| 231 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | // Bool Queries
|
---|
[97ebf8] | 235 |
|
---|
[75dc28] | 236 | Dialog::BooleanQuery::BooleanQuery(string title,std::string description) :
|
---|
| 237 | Query(title, description)
|
---|
[97ebf8] | 238 | {}
|
---|
| 239 |
|
---|
| 240 | Dialog::BooleanQuery::~BooleanQuery() {}
|
---|
| 241 |
|
---|
| 242 | void Dialog::BooleanQuery::setResult() {
|
---|
[3731b4] | 243 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[97ebf8] | 244 | }
|
---|
| 245 |
|
---|
[7aa000] | 246 | // String Queries
|
---|
| 247 |
|
---|
[75dc28] | 248 | Dialog::StringQuery::StringQuery(string title,std::string _description) :
|
---|
| 249 | Query(title, _description)
|
---|
[45f5d6] | 250 | {}
|
---|
| 251 |
|
---|
| 252 | Dialog::StringQuery::~StringQuery() {};
|
---|
| 253 |
|
---|
| 254 | void Dialog::StringQuery::setResult() {
|
---|
[3731b4] | 255 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[45f5d6] | 256 | }
|
---|
| 257 |
|
---|
[cd8e55] | 258 | // Strings Queries
|
---|
| 259 |
|
---|
[75dc28] | 260 | Dialog::StringsQuery::StringsQuery(string title,std::string _description) :
|
---|
| 261 | Query(title, _description)
|
---|
[cd8e55] | 262 | {}
|
---|
| 263 |
|
---|
| 264 | Dialog::StringsQuery::~StringsQuery() {};
|
---|
| 265 |
|
---|
| 266 | void Dialog::StringsQuery::setResult() {
|
---|
[3731b4] | 267 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[cd8e55] | 268 | }
|
---|
| 269 |
|
---|
[2ededc2] | 270 | // Double Queries
|
---|
| 271 |
|
---|
[75dc28] | 272 | Dialog::DoubleQuery::DoubleQuery(string title, std::string _description) :
|
---|
| 273 | Query(title, _description)
|
---|
[2ededc2] | 274 | {}
|
---|
| 275 |
|
---|
| 276 | Dialog::DoubleQuery::~DoubleQuery() {};
|
---|
| 277 |
|
---|
| 278 | void Dialog::DoubleQuery::setResult() {
|
---|
[3731b4] | 279 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[2ededc2] | 280 | }
|
---|
| 281 |
|
---|
[7cd6e7] | 282 | // Doubles Queries
|
---|
| 283 |
|
---|
| 284 | Dialog::DoublesQuery::DoublesQuery(string title, std::string _description) :
|
---|
| 285 | Query(title, _description)
|
---|
| 286 | {}
|
---|
| 287 |
|
---|
| 288 | Dialog::DoublesQuery::~DoublesQuery() {};
|
---|
| 289 |
|
---|
| 290 | void Dialog::DoublesQuery::setResult() {
|
---|
| 291 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 292 | }
|
---|
| 293 |
|
---|
[2ededc2] | 294 |
|
---|
[97ebf8] | 295 | // Atom Queries
|
---|
| 296 |
|
---|
[75dc28] | 297 | Dialog::AtomQuery::AtomQuery(string title, std::string _description) :
|
---|
[97ebf8] | 298 | Query(title, _description),
|
---|
[75dc28] | 299 | tmp(0)
|
---|
[97ebf8] | 300 | {}
|
---|
| 301 |
|
---|
| 302 | Dialog::AtomQuery::~AtomQuery() {}
|
---|
| 303 |
|
---|
| 304 | void Dialog::AtomQuery::setResult() {
|
---|
[3731b4] | 305 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[97ebf8] | 306 | }
|
---|
| 307 |
|
---|
[7cd6e7] | 308 | // Atoms Queries
|
---|
| 309 |
|
---|
| 310 | Dialog::AtomsQuery::AtomsQuery(string title, std::string _description) :
|
---|
| 311 | Query(title, _description),
|
---|
| 312 | tmp(0)
|
---|
| 313 | {}
|
---|
| 314 |
|
---|
| 315 | Dialog::AtomsQuery::~AtomsQuery() {}
|
---|
| 316 |
|
---|
| 317 | void Dialog::AtomsQuery::setResult() {
|
---|
| 318 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 319 | }
|
---|
| 320 |
|
---|
[7aa000] | 321 | // Molecule Queries
|
---|
| 322 |
|
---|
[75dc28] | 323 | Dialog::MoleculeQuery::MoleculeQuery(string title, std::string _description) :
|
---|
[a2ab15] | 324 | Query(title, _description),
|
---|
[75dc28] | 325 | tmp(0)
|
---|
[7aa000] | 326 | {}
|
---|
| 327 |
|
---|
| 328 | Dialog::MoleculeQuery::~MoleculeQuery() {}
|
---|
| 329 |
|
---|
| 330 | void Dialog::MoleculeQuery::setResult() {
|
---|
[3731b4] | 331 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[7aa000] | 332 | }
|
---|
[2ededc2] | 333 |
|
---|
[7cd6e7] | 334 | // Molecules Queries
|
---|
| 335 |
|
---|
| 336 | Dialog::MoleculesQuery::MoleculesQuery(string title, std::string _description) :
|
---|
| 337 | Query(title, _description),
|
---|
| 338 | tmp(0)
|
---|
| 339 | {}
|
---|
| 340 |
|
---|
| 341 | Dialog::MoleculesQuery::~MoleculesQuery() {}
|
---|
| 342 |
|
---|
| 343 | void Dialog::MoleculesQuery::setResult() {
|
---|
| 344 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 345 | }
|
---|
| 346 |
|
---|
[2ededc2] | 347 | // Vector Queries
|
---|
| 348 |
|
---|
[75dc28] | 349 | Dialog::VectorQuery::VectorQuery(std::string title,bool _check, std::string _description) :
|
---|
[a2ab15] | 350 | Query(title, _description),
|
---|
[75dc28] | 351 | check(_check)
|
---|
[7cd6e7] | 352 | {}
|
---|
[2ededc2] | 353 |
|
---|
| 354 | Dialog::VectorQuery::~VectorQuery()
|
---|
[7cd6e7] | 355 | {}
|
---|
[2ededc2] | 356 |
|
---|
| 357 | void Dialog::VectorQuery::setResult() {
|
---|
[3731b4] | 358 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[2ededc2] | 359 | }
|
---|
[5a7243] | 360 |
|
---|
[7cd6e7] | 361 | // Vectors Queries
|
---|
| 362 |
|
---|
| 363 | Dialog::VectorsQuery::VectorsQuery(std::string title,bool _check, std::string _description) :
|
---|
| 364 | Query(title, _description),
|
---|
| 365 | check(_check)
|
---|
| 366 | {}
|
---|
| 367 |
|
---|
| 368 | Dialog::VectorsQuery::~VectorsQuery()
|
---|
| 369 | {}
|
---|
| 370 |
|
---|
| 371 | void Dialog::VectorsQuery::setResult() {
|
---|
| 372 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 373 | }
|
---|
| 374 |
|
---|
[97ebf8] | 375 | // Box Queries
|
---|
| 376 |
|
---|
[75dc28] | 377 | Dialog::BoxQuery::BoxQuery(std::string title, std::string _description) :
|
---|
| 378 | Query(title, _description)
|
---|
[8bc733] | 379 | {}
|
---|
[97ebf8] | 380 |
|
---|
| 381 | Dialog::BoxQuery::~BoxQuery()
|
---|
[8bc733] | 382 | {}
|
---|
[97ebf8] | 383 |
|
---|
| 384 | void Dialog::BoxQuery::setResult() {
|
---|
[3731b4] | 385 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[97ebf8] | 386 | }
|
---|
| 387 |
|
---|
[5a7243] | 388 | // Element Queries
|
---|
[75dc28] | 389 | Dialog::ElementQuery::ElementQuery(std::string title, std::string _description) :
|
---|
| 390 | Query(title, _description)
|
---|
[5a7243] | 391 | {}
|
---|
| 392 |
|
---|
| 393 | Dialog::ElementQuery::~ElementQuery(){}
|
---|
| 394 |
|
---|
| 395 | void Dialog::ElementQuery::setResult(){
|
---|
[3731b4] | 396 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
[5a7243] | 397 | }
|
---|
[7cd6e7] | 398 |
|
---|
| 399 | // Elements Queries
|
---|
| 400 | Dialog::ElementsQuery::ElementsQuery(std::string title, std::string _description) :
|
---|
| 401 | Query(title, _description)
|
---|
| 402 | {}
|
---|
| 403 |
|
---|
| 404 | Dialog::ElementsQuery::~ElementsQuery(){}
|
---|
| 405 |
|
---|
| 406 | void Dialog::ElementsQuery::setResult(){
|
---|
| 407 | ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
|
---|
| 408 | }
|
---|