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