| 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 "ValueStorage.hpp" | 
|---|
| 12 |  | 
|---|
| 13 | #include "verbose.hpp" | 
|---|
| 14 | #include "atom.hpp" | 
|---|
| 15 | #include "element.hpp" | 
|---|
| 16 | #include "molecule.hpp" | 
|---|
| 17 | #include "vector.hpp" | 
|---|
| 18 | #include "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 | /****************** Query types Infrastructure **************************/ | 
|---|
| 71 |  | 
|---|
| 72 | // Base class | 
|---|
| 73 | Dialog::Query::Query(string _title, string _description) : | 
|---|
| 74 | title(_title), | 
|---|
| 75 | description(_description) | 
|---|
| 76 | {} | 
|---|
| 77 |  | 
|---|
| 78 | Dialog::Query::~Query() {} | 
|---|
| 79 |  | 
|---|
| 80 | const std::string Dialog::Query::getTitle() const{ | 
|---|
| 81 | return title; | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 | const std::string Dialog::Query::getDescription() const{ | 
|---|
| 85 | return description; | 
|---|
| 86 | } | 
|---|
| 87 | // empty Queries | 
|---|
| 88 |  | 
|---|
| 89 | Dialog::EmptyQuery::EmptyQuery(string title, std::string description) : | 
|---|
| 90 | Query(title, description) | 
|---|
| 91 | {} | 
|---|
| 92 |  | 
|---|
| 93 | Dialog::EmptyQuery::~EmptyQuery() {} | 
|---|
| 94 |  | 
|---|
| 95 | void Dialog::EmptyQuery::setResult() { | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | // Int Queries | 
|---|
| 99 |  | 
|---|
| 100 | Dialog::IntQuery::IntQuery(string title, std::string description) : | 
|---|
| 101 | Query(title, description) | 
|---|
| 102 | {} | 
|---|
| 103 |  | 
|---|
| 104 | Dialog::IntQuery::~IntQuery() {} | 
|---|
| 105 |  | 
|---|
| 106 | void Dialog::IntQuery::setResult() { | 
|---|
| 107 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | // Int Queries | 
|---|
| 111 |  | 
|---|
| 112 | Dialog::BooleanQuery::BooleanQuery(string title,std::string description) : | 
|---|
| 113 | Query(title, description) | 
|---|
| 114 | {} | 
|---|
| 115 |  | 
|---|
| 116 | Dialog::BooleanQuery::~BooleanQuery() {} | 
|---|
| 117 |  | 
|---|
| 118 | void Dialog::BooleanQuery::setResult() { | 
|---|
| 119 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | // String Queries | 
|---|
| 123 |  | 
|---|
| 124 | Dialog::StringQuery::StringQuery(string title,std::string _description) : | 
|---|
| 125 | Query(title, _description) | 
|---|
| 126 | {} | 
|---|
| 127 |  | 
|---|
| 128 | Dialog::StringQuery::~StringQuery() {}; | 
|---|
| 129 |  | 
|---|
| 130 | void Dialog::StringQuery::setResult() { | 
|---|
| 131 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | // Strings Queries | 
|---|
| 135 |  | 
|---|
| 136 | Dialog::StringsQuery::StringsQuery(string title,std::string _description) : | 
|---|
| 137 | Query(title, _description) | 
|---|
| 138 | {} | 
|---|
| 139 |  | 
|---|
| 140 | Dialog::StringsQuery::~StringsQuery() {}; | 
|---|
| 141 |  | 
|---|
| 142 | void Dialog::StringsQuery::setResult() { | 
|---|
| 143 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| 144 | } | 
|---|
| 145 |  | 
|---|
| 146 | // Double Queries | 
|---|
| 147 |  | 
|---|
| 148 | Dialog::DoubleQuery::DoubleQuery(string title, std::string _description) : | 
|---|
| 149 | Query(title, _description) | 
|---|
| 150 | {} | 
|---|
| 151 |  | 
|---|
| 152 | Dialog::DoubleQuery::~DoubleQuery() {}; | 
|---|
| 153 |  | 
|---|
| 154 | void Dialog::DoubleQuery::setResult() { | 
|---|
| 155 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| 156 | } | 
|---|
| 157 |  | 
|---|
| 158 |  | 
|---|
| 159 | // Atom Queries | 
|---|
| 160 |  | 
|---|
| 161 | Dialog::AtomQuery::AtomQuery(string title, std::string _description) : | 
|---|
| 162 | Query(title, _description), | 
|---|
| 163 | tmp(0) | 
|---|
| 164 | {} | 
|---|
| 165 |  | 
|---|
| 166 | Dialog::AtomQuery::~AtomQuery() {} | 
|---|
| 167 |  | 
|---|
| 168 | void Dialog::AtomQuery::setResult() { | 
|---|
| 169 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| 170 | } | 
|---|
| 171 |  | 
|---|
| 172 | // Molecule Queries | 
|---|
| 173 |  | 
|---|
| 174 | Dialog::MoleculeQuery::MoleculeQuery(string title, std::string _description) : | 
|---|
| 175 | Query(title, _description), | 
|---|
| 176 | tmp(0) | 
|---|
| 177 | {} | 
|---|
| 178 |  | 
|---|
| 179 | Dialog::MoleculeQuery::~MoleculeQuery() {} | 
|---|
| 180 |  | 
|---|
| 181 | void Dialog::MoleculeQuery::setResult() { | 
|---|
| 182 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| 183 | } | 
|---|
| 184 |  | 
|---|
| 185 | // Vector Queries | 
|---|
| 186 |  | 
|---|
| 187 | Dialog::VectorQuery::VectorQuery(std::string title,bool _check, std::string _description) : | 
|---|
| 188 | Query(title, _description), | 
|---|
| 189 | check(_check) | 
|---|
| 190 | { | 
|---|
| 191 | tmp = new Vector(); | 
|---|
| 192 | } | 
|---|
| 193 |  | 
|---|
| 194 | Dialog::VectorQuery::~VectorQuery() | 
|---|
| 195 | { | 
|---|
| 196 | delete tmp; | 
|---|
| 197 | } | 
|---|
| 198 |  | 
|---|
| 199 | void Dialog::VectorQuery::setResult() { | 
|---|
| 200 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| 201 | } | 
|---|
| 202 |  | 
|---|
| 203 | // Box Queries | 
|---|
| 204 |  | 
|---|
| 205 | Dialog::BoxQuery::BoxQuery(std::string title, std::string _description) : | 
|---|
| 206 | Query(title, _description) | 
|---|
| 207 | { | 
|---|
| 208 | tmp = new double[6]; | 
|---|
| 209 | } | 
|---|
| 210 |  | 
|---|
| 211 | Dialog::BoxQuery::~BoxQuery() | 
|---|
| 212 | { | 
|---|
| 213 | delete[] tmp; | 
|---|
| 214 | } | 
|---|
| 215 |  | 
|---|
| 216 | void Dialog::BoxQuery::setResult() { | 
|---|
| 217 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| 218 | } | 
|---|
| 219 |  | 
|---|
| 220 | // Element Queries | 
|---|
| 221 | Dialog::ElementQuery::ElementQuery(std::string title, std::string _description) : | 
|---|
| 222 | Query(title, _description) | 
|---|
| 223 | {} | 
|---|
| 224 |  | 
|---|
| 225 | Dialog::ElementQuery::~ElementQuery(){} | 
|---|
| 226 |  | 
|---|
| 227 | void Dialog::ElementQuery::setResult(){ | 
|---|
| 228 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| 229 | } | 
|---|