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