| [f5a86a] | 1 | /* | 
|---|
|  | 2 | * Dialog.cpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Jan 5, 2010 | 
|---|
|  | 5 | *      Author: crueger | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
| [112b09] | 8 | #include "Helpers/MemDebug.hpp" | 
|---|
|  | 9 |  | 
|---|
| [5079a0] | 10 | #include "Dialog.hpp" | 
|---|
| [75dc28] | 11 | #include "ValueStorage.hpp" | 
|---|
| [f5a86a] | 12 |  | 
|---|
| [36166d] | 13 | #include "verbose.hpp" | 
|---|
| [97ebf8] | 14 | #include "atom.hpp" | 
|---|
|  | 15 | #include "element.hpp" | 
|---|
|  | 16 | #include "molecule.hpp" | 
|---|
| [2ededc2] | 17 | #include "vector.hpp" | 
|---|
| [84c494] | 18 | #include "Matrix.hpp" | 
|---|
|  | 19 | #include "Box.hpp" | 
|---|
| [2ededc2] | 20 |  | 
|---|
| [f5a86a] | 21 | using namespace std; | 
|---|
|  | 22 |  | 
|---|
|  | 23 | Dialog::Dialog() | 
|---|
|  | 24 | { | 
|---|
|  | 25 | } | 
|---|
|  | 26 |  | 
|---|
|  | 27 | Dialog::~Dialog() | 
|---|
|  | 28 | { | 
|---|
| [45f5d6] | 29 | list<Query*>::iterator iter; | 
|---|
|  | 30 | for(iter=queries.begin();iter!=queries.end();iter++){ | 
|---|
|  | 31 | delete (*iter); | 
|---|
|  | 32 | } | 
|---|
| [f5a86a] | 33 | } | 
|---|
|  | 34 |  | 
|---|
| [45f5d6] | 35 | void Dialog::registerQuery(Query *query){ | 
|---|
|  | 36 | queries.push_back(query); | 
|---|
|  | 37 | } | 
|---|
| [f5a86a] | 38 |  | 
|---|
| [45f5d6] | 39 | bool Dialog::display(){ | 
|---|
| [d3a5ea] | 40 | if(checkAll()){ | 
|---|
|  | 41 | setAll(); | 
|---|
|  | 42 | return true; | 
|---|
|  | 43 | } | 
|---|
|  | 44 | else{ | 
|---|
|  | 45 | return false; | 
|---|
|  | 46 | } | 
|---|
|  | 47 | } | 
|---|
|  | 48 |  | 
|---|
|  | 49 | bool Dialog::checkAll(){ | 
|---|
| [45f5d6] | 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 | 
|---|
| [94d131] | 55 | if(!retval) { | 
|---|
|  | 56 | DoeLog(1) && (eLog() << Verbose(1) << "The following query failed: " << (**iter).getTitle() << "." << endl); | 
|---|
| [45f5d6] | 57 | break; | 
|---|
| [94d131] | 58 | } | 
|---|
| [45f5d6] | 59 | } | 
|---|
|  | 60 | return retval; | 
|---|
| [f5a86a] | 61 | } | 
|---|
|  | 62 |  | 
|---|
| [d3a5ea] | 63 | void Dialog::setAll(){ | 
|---|
|  | 64 | list<Query*>::iterator iter; | 
|---|
|  | 65 | for(iter=queries.begin(); iter!=queries.end(); iter++) { | 
|---|
|  | 66 | (*iter)->setResult(); | 
|---|
|  | 67 | } | 
|---|
|  | 68 | } | 
|---|
|  | 69 |  | 
|---|
| [7aa000] | 70 | /****************** Query types Infrastructure **************************/ | 
|---|
|  | 71 |  | 
|---|
|  | 72 | // Base class | 
|---|
| [a2ab15] | 73 | Dialog::Query::Query(string _title, string _description) : | 
|---|
|  | 74 | title(_title), | 
|---|
|  | 75 | description(_description) | 
|---|
| [45f5d6] | 76 | {} | 
|---|
| [f5a86a] | 77 |  | 
|---|
| [45f5d6] | 78 | Dialog::Query::~Query() {} | 
|---|
|  | 79 |  | 
|---|
|  | 80 | const std::string Dialog::Query::getTitle() const{ | 
|---|
|  | 81 | return title; | 
|---|
| [f5a86a] | 82 | } | 
|---|
|  | 83 |  | 
|---|
| [a2ab15] | 84 | const std::string Dialog::Query::getDescription() const{ | 
|---|
|  | 85 | return description; | 
|---|
|  | 86 | } | 
|---|
| [86466e] | 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 |  | 
|---|
| [7aa000] | 98 | // Int Queries | 
|---|
|  | 99 |  | 
|---|
| [75dc28] | 100 | Dialog::IntQuery::IntQuery(string title, std::string description) : | 
|---|
|  | 101 | Query(title, description) | 
|---|
| [45f5d6] | 102 | {} | 
|---|
|  | 103 |  | 
|---|
|  | 104 | Dialog::IntQuery::~IntQuery() {} | 
|---|
|  | 105 |  | 
|---|
|  | 106 | void Dialog::IntQuery::setResult() { | 
|---|
| [75dc28] | 107 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| [f5a86a] | 108 | } | 
|---|
| [45f5d6] | 109 |  | 
|---|
| [97ebf8] | 110 | // Int Queries | 
|---|
|  | 111 |  | 
|---|
| [75dc28] | 112 | Dialog::BooleanQuery::BooleanQuery(string title,std::string description) : | 
|---|
|  | 113 | Query(title, description) | 
|---|
| [97ebf8] | 114 | {} | 
|---|
|  | 115 |  | 
|---|
|  | 116 | Dialog::BooleanQuery::~BooleanQuery() {} | 
|---|
|  | 117 |  | 
|---|
|  | 118 | void Dialog::BooleanQuery::setResult() { | 
|---|
| [75dc28] | 119 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| [97ebf8] | 120 | } | 
|---|
|  | 121 |  | 
|---|
| [7aa000] | 122 | // String Queries | 
|---|
|  | 123 |  | 
|---|
| [75dc28] | 124 | Dialog::StringQuery::StringQuery(string title,std::string _description) : | 
|---|
|  | 125 | Query(title, _description) | 
|---|
| [45f5d6] | 126 | {} | 
|---|
|  | 127 |  | 
|---|
|  | 128 | Dialog::StringQuery::~StringQuery() {}; | 
|---|
|  | 129 |  | 
|---|
|  | 130 | void Dialog::StringQuery::setResult() { | 
|---|
| [75dc28] | 131 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| [45f5d6] | 132 | } | 
|---|
|  | 133 |  | 
|---|
| [cd8e55] | 134 | // Strings Queries | 
|---|
|  | 135 |  | 
|---|
| [75dc28] | 136 | Dialog::StringsQuery::StringsQuery(string title,std::string _description) : | 
|---|
|  | 137 | Query(title, _description) | 
|---|
| [cd8e55] | 138 | {} | 
|---|
|  | 139 |  | 
|---|
|  | 140 | Dialog::StringsQuery::~StringsQuery() {}; | 
|---|
|  | 141 |  | 
|---|
|  | 142 | void Dialog::StringsQuery::setResult() { | 
|---|
| [75dc28] | 143 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| [cd8e55] | 144 | } | 
|---|
|  | 145 |  | 
|---|
| [2ededc2] | 146 | // Double Queries | 
|---|
|  | 147 |  | 
|---|
| [75dc28] | 148 | Dialog::DoubleQuery::DoubleQuery(string title, std::string _description) : | 
|---|
|  | 149 | Query(title, _description) | 
|---|
| [2ededc2] | 150 | {} | 
|---|
|  | 151 |  | 
|---|
|  | 152 | Dialog::DoubleQuery::~DoubleQuery() {}; | 
|---|
|  | 153 |  | 
|---|
|  | 154 | void Dialog::DoubleQuery::setResult() { | 
|---|
| [75dc28] | 155 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| [2ededc2] | 156 | } | 
|---|
|  | 157 |  | 
|---|
|  | 158 |  | 
|---|
| [97ebf8] | 159 | // Atom Queries | 
|---|
|  | 160 |  | 
|---|
| [75dc28] | 161 | Dialog::AtomQuery::AtomQuery(string title, std::string _description) : | 
|---|
| [97ebf8] | 162 | Query(title, _description), | 
|---|
| [75dc28] | 163 | tmp(0) | 
|---|
| [97ebf8] | 164 | {} | 
|---|
|  | 165 |  | 
|---|
|  | 166 | Dialog::AtomQuery::~AtomQuery() {} | 
|---|
|  | 167 |  | 
|---|
|  | 168 | void Dialog::AtomQuery::setResult() { | 
|---|
| [75dc28] | 169 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| [97ebf8] | 170 | } | 
|---|
|  | 171 |  | 
|---|
| [7aa000] | 172 | // Molecule Queries | 
|---|
|  | 173 |  | 
|---|
| [75dc28] | 174 | Dialog::MoleculeQuery::MoleculeQuery(string title, std::string _description) : | 
|---|
| [a2ab15] | 175 | Query(title, _description), | 
|---|
| [75dc28] | 176 | tmp(0) | 
|---|
| [7aa000] | 177 | {} | 
|---|
|  | 178 |  | 
|---|
|  | 179 | Dialog::MoleculeQuery::~MoleculeQuery() {} | 
|---|
|  | 180 |  | 
|---|
|  | 181 | void Dialog::MoleculeQuery::setResult() { | 
|---|
| [75dc28] | 182 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| [7aa000] | 183 | } | 
|---|
| [2ededc2] | 184 |  | 
|---|
|  | 185 | // Vector Queries | 
|---|
|  | 186 |  | 
|---|
| [75dc28] | 187 | Dialog::VectorQuery::VectorQuery(std::string title,bool _check, std::string _description) : | 
|---|
| [a2ab15] | 188 | Query(title, _description), | 
|---|
| [75dc28] | 189 | check(_check) | 
|---|
| [2ededc2] | 190 | { | 
|---|
| [26f75a] | 191 | tmp = new Vector(); | 
|---|
| [2ededc2] | 192 | } | 
|---|
|  | 193 |  | 
|---|
|  | 194 | Dialog::VectorQuery::~VectorQuery() | 
|---|
|  | 195 | { | 
|---|
|  | 196 | delete tmp; | 
|---|
|  | 197 | } | 
|---|
|  | 198 |  | 
|---|
|  | 199 | void Dialog::VectorQuery::setResult() { | 
|---|
| [75dc28] | 200 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| [2ededc2] | 201 | } | 
|---|
| [5a7243] | 202 |  | 
|---|
| [97ebf8] | 203 | // Box Queries | 
|---|
|  | 204 |  | 
|---|
| [75dc28] | 205 | Dialog::BoxQuery::BoxQuery(std::string title, std::string _description) : | 
|---|
|  | 206 | Query(title, _description) | 
|---|
| [97ebf8] | 207 | { | 
|---|
|  | 208 | tmp = new double[6]; | 
|---|
|  | 209 | } | 
|---|
|  | 210 |  | 
|---|
|  | 211 | Dialog::BoxQuery::~BoxQuery() | 
|---|
|  | 212 | { | 
|---|
|  | 213 | delete[] tmp; | 
|---|
|  | 214 | } | 
|---|
|  | 215 |  | 
|---|
|  | 216 | void Dialog::BoxQuery::setResult() { | 
|---|
| [75dc28] | 217 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| [97ebf8] | 218 | } | 
|---|
|  | 219 |  | 
|---|
| [5a7243] | 220 | // Element Queries | 
|---|
| [75dc28] | 221 | Dialog::ElementQuery::ElementQuery(std::string title, std::string _description) : | 
|---|
|  | 222 | Query(title, _description) | 
|---|
| [5a7243] | 223 | {} | 
|---|
|  | 224 |  | 
|---|
|  | 225 | Dialog::ElementQuery::~ElementQuery(){} | 
|---|
|  | 226 |  | 
|---|
|  | 227 | void Dialog::ElementQuery::setResult(){ | 
|---|
| [75dc28] | 228 | ValueStorage::getInstance().setCurrentValue(title, tmp); | 
|---|
| [5a7243] | 229 | } | 
|---|