| [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"
 | 
|---|
 | 27 | #include "element.hpp"
 | 
|---|
 | 28 | #include "molecule.hpp"
 | 
|---|
| [57f243] | 29 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
 | 30 | #include "LinearAlgebra/Matrix.hpp"
 | 
|---|
| [84c494] | 31 | #include "Box.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 | 
 | 
|---|
| [7aa000] | 86 | /****************** Query types Infrastructure **************************/
 | 
|---|
 | 87 | 
 | 
|---|
 | 88 | // Base class
 | 
|---|
| [a2ab15] | 89 | Dialog::Query::Query(string _title, string _description) :
 | 
|---|
 | 90 |     title(_title),
 | 
|---|
 | 91 |     description(_description)
 | 
|---|
| [45f5d6] | 92 | {}
 | 
|---|
| [f5a86a] | 93 | 
 | 
|---|
| [45f5d6] | 94 | Dialog::Query::~Query() {}
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | const std::string Dialog::Query::getTitle() const{
 | 
|---|
 | 97 |   return title;
 | 
|---|
| [f5a86a] | 98 | }
 | 
|---|
 | 99 | 
 | 
|---|
| [a2ab15] | 100 | const std::string Dialog::Query::getDescription() const{
 | 
|---|
 | 101 |   return description;
 | 
|---|
 | 102 | }
 | 
|---|
| [86466e] | 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 | 
 | 
|---|
| [7aa000] | 114 | // Int Queries
 | 
|---|
 | 115 | 
 | 
|---|
| [75dc28] | 116 | Dialog::IntQuery::IntQuery(string title, std::string description) :
 | 
|---|
 | 117 |     Query(title, description)
 | 
|---|
| [45f5d6] | 118 | {}
 | 
|---|
 | 119 | 
 | 
|---|
 | 120 | Dialog::IntQuery::~IntQuery() {}
 | 
|---|
 | 121 | 
 | 
|---|
 | 122 | void Dialog::IntQuery::setResult() {
 | 
|---|
| [3731b4] | 123 |   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
 | 
|---|
| [f5a86a] | 124 | }
 | 
|---|
| [45f5d6] | 125 | 
 | 
|---|
| [7cd6e7] | 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
 | 
|---|
| [97ebf8] | 139 | 
 | 
|---|
| [75dc28] | 140 | Dialog::BooleanQuery::BooleanQuery(string title,std::string description) :
 | 
|---|
 | 141 |     Query(title, description)
 | 
|---|
| [97ebf8] | 142 | {}
 | 
|---|
 | 143 | 
 | 
|---|
 | 144 | Dialog::BooleanQuery::~BooleanQuery() {}
 | 
|---|
 | 145 | 
 | 
|---|
 | 146 | void Dialog::BooleanQuery::setResult() {
 | 
|---|
| [3731b4] | 147 |   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
 | 
|---|
| [97ebf8] | 148 | }
 | 
|---|
 | 149 | 
 | 
|---|
| [7aa000] | 150 | // String Queries
 | 
|---|
 | 151 | 
 | 
|---|
| [75dc28] | 152 | Dialog::StringQuery::StringQuery(string title,std::string _description) :
 | 
|---|
 | 153 |     Query(title, _description)
 | 
|---|
| [45f5d6] | 154 | {}
 | 
|---|
 | 155 | 
 | 
|---|
 | 156 | Dialog::StringQuery::~StringQuery() {};
 | 
|---|
 | 157 | 
 | 
|---|
 | 158 | void Dialog::StringQuery::setResult() {
 | 
|---|
| [3731b4] | 159 |   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
 | 
|---|
| [45f5d6] | 160 | }
 | 
|---|
 | 161 | 
 | 
|---|
| [cd8e55] | 162 | // Strings Queries
 | 
|---|
 | 163 | 
 | 
|---|
| [75dc28] | 164 | Dialog::StringsQuery::StringsQuery(string title,std::string _description) :
 | 
|---|
 | 165 |     Query(title, _description)
 | 
|---|
| [cd8e55] | 166 | {}
 | 
|---|
 | 167 | 
 | 
|---|
 | 168 | Dialog::StringsQuery::~StringsQuery() {};
 | 
|---|
 | 169 | 
 | 
|---|
 | 170 | void Dialog::StringsQuery::setResult() {
 | 
|---|
| [3731b4] | 171 |   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
 | 
|---|
| [cd8e55] | 172 | }
 | 
|---|
 | 173 | 
 | 
|---|
| [2ededc2] | 174 | // Double Queries
 | 
|---|
 | 175 | 
 | 
|---|
| [75dc28] | 176 | Dialog::DoubleQuery::DoubleQuery(string title, std::string _description) :
 | 
|---|
 | 177 |     Query(title, _description)
 | 
|---|
| [2ededc2] | 178 | {}
 | 
|---|
 | 179 | 
 | 
|---|
 | 180 | Dialog::DoubleQuery::~DoubleQuery() {};
 | 
|---|
 | 181 | 
 | 
|---|
 | 182 | void Dialog::DoubleQuery::setResult() {
 | 
|---|
| [3731b4] | 183 |   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
 | 
|---|
| [2ededc2] | 184 | }
 | 
|---|
 | 185 | 
 | 
|---|
| [7cd6e7] | 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 | 
 | 
|---|
| [2ededc2] | 198 | 
 | 
|---|
| [97ebf8] | 199 | // Atom Queries
 | 
|---|
 | 200 | 
 | 
|---|
| [75dc28] | 201 | Dialog::AtomQuery::AtomQuery(string title, std::string _description) :
 | 
|---|
| [97ebf8] | 202 |     Query(title, _description),
 | 
|---|
| [75dc28] | 203 |     tmp(0)
 | 
|---|
| [97ebf8] | 204 | {}
 | 
|---|
 | 205 | 
 | 
|---|
 | 206 | Dialog::AtomQuery::~AtomQuery() {}
 | 
|---|
 | 207 | 
 | 
|---|
 | 208 | void Dialog::AtomQuery::setResult() {
 | 
|---|
| [3731b4] | 209 |   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
 | 
|---|
| [97ebf8] | 210 | }
 | 
|---|
 | 211 | 
 | 
|---|
| [7cd6e7] | 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 | 
 | 
|---|
| [7aa000] | 225 | // Molecule Queries
 | 
|---|
 | 226 | 
 | 
|---|
| [75dc28] | 227 | Dialog::MoleculeQuery::MoleculeQuery(string title, std::string _description) :
 | 
|---|
| [a2ab15] | 228 |     Query(title, _description),
 | 
|---|
| [75dc28] | 229 |     tmp(0)
 | 
|---|
| [7aa000] | 230 | {}
 | 
|---|
 | 231 | 
 | 
|---|
 | 232 | Dialog::MoleculeQuery::~MoleculeQuery() {}
 | 
|---|
 | 233 | 
 | 
|---|
 | 234 | void Dialog::MoleculeQuery::setResult() {
 | 
|---|
| [3731b4] | 235 |   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
 | 
|---|
| [7aa000] | 236 | }
 | 
|---|
| [2ededc2] | 237 | 
 | 
|---|
| [7cd6e7] | 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 | 
 | 
|---|
| [2ededc2] | 251 | // Vector Queries
 | 
|---|
 | 252 | 
 | 
|---|
| [75dc28] | 253 | Dialog::VectorQuery::VectorQuery(std::string title,bool _check, std::string _description) :
 | 
|---|
| [a2ab15] | 254 |   Query(title, _description),
 | 
|---|
| [75dc28] | 255 |   check(_check)
 | 
|---|
| [7cd6e7] | 256 | {}
 | 
|---|
| [2ededc2] | 257 | 
 | 
|---|
 | 258 | Dialog::VectorQuery::~VectorQuery()
 | 
|---|
| [7cd6e7] | 259 | {}
 | 
|---|
| [2ededc2] | 260 | 
 | 
|---|
 | 261 | void Dialog::VectorQuery::setResult() {
 | 
|---|
| [3731b4] | 262 |   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
 | 
|---|
| [2ededc2] | 263 | }
 | 
|---|
| [5a7243] | 264 | 
 | 
|---|
| [7cd6e7] | 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 | 
 | 
|---|
| [97ebf8] | 279 | // Box Queries
 | 
|---|
 | 280 | 
 | 
|---|
| [75dc28] | 281 | Dialog::BoxQuery::BoxQuery(std::string title, std::string _description) :
 | 
|---|
 | 282 |   Query(title, _description)
 | 
|---|
| [8bc733] | 283 | {}
 | 
|---|
| [97ebf8] | 284 | 
 | 
|---|
 | 285 | Dialog::BoxQuery::~BoxQuery()
 | 
|---|
| [8bc733] | 286 | {}
 | 
|---|
| [97ebf8] | 287 | 
 | 
|---|
 | 288 | void Dialog::BoxQuery::setResult() {
 | 
|---|
| [3731b4] | 289 |   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
 | 
|---|
| [97ebf8] | 290 | }
 | 
|---|
 | 291 | 
 | 
|---|
| [5a7243] | 292 | // Element Queries
 | 
|---|
| [75dc28] | 293 | Dialog::ElementQuery::ElementQuery(std::string title, std::string _description) :
 | 
|---|
 | 294 |   Query(title, _description)
 | 
|---|
| [5a7243] | 295 |   {}
 | 
|---|
 | 296 | 
 | 
|---|
 | 297 | Dialog::ElementQuery::~ElementQuery(){}
 | 
|---|
 | 298 | 
 | 
|---|
 | 299 | void Dialog::ElementQuery::setResult(){
 | 
|---|
| [3731b4] | 300 |   ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
 | 
|---|
| [5a7243] | 301 | }
 | 
|---|
| [7cd6e7] | 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 | }
 | 
|---|