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