| 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 |  | 
|---|
| 12 | #include "verbose.hpp" | 
|---|
| 13 | #include "atom.hpp" | 
|---|
| 14 | #include "element.hpp" | 
|---|
| 15 | #include "molecule.hpp" | 
|---|
| 16 | #include "vector.hpp" | 
|---|
| 17 | #include "Matrix.hpp" | 
|---|
| 18 | #include "Box.hpp" | 
|---|
| 19 |  | 
|---|
| 20 | using namespace std; | 
|---|
| 21 |  | 
|---|
| 22 | Dialog::Dialog() | 
|---|
| 23 | { | 
|---|
| 24 | } | 
|---|
| 25 |  | 
|---|
| 26 | Dialog::~Dialog() | 
|---|
| 27 | { | 
|---|
| 28 | list<Query*>::iterator iter; | 
|---|
| 29 | for(iter=queries.begin();iter!=queries.end();iter++){ | 
|---|
| 30 | delete (*iter); | 
|---|
| 31 | } | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | void Dialog::registerQuery(Query *query){ | 
|---|
| 35 | queries.push_back(query); | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 38 | bool Dialog::display(){ | 
|---|
| 39 | if(checkAll()){ | 
|---|
| 40 | setAll(); | 
|---|
| 41 | return true; | 
|---|
| 42 | } | 
|---|
| 43 | else{ | 
|---|
| 44 | return false; | 
|---|
| 45 | } | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | bool Dialog::checkAll(){ | 
|---|
| 49 | list<Query*>::iterator iter; | 
|---|
| 50 | bool retval = true; | 
|---|
| 51 | for(iter=queries.begin(); iter!=queries.end(); iter++){ | 
|---|
| 52 | retval &= (*iter)->handle(); | 
|---|
| 53 | // if any query fails (is canceled), we can end the handling process | 
|---|
| 54 | if(!retval) { | 
|---|
| 55 | DoeLog(1) && (eLog() << Verbose(1) << "The following query failed: " << (**iter).getTitle() << "." << endl); | 
|---|
| 56 | break; | 
|---|
| 57 | } | 
|---|
| 58 | } | 
|---|
| 59 | return retval; | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | void Dialog::setAll(){ | 
|---|
| 63 | list<Query*>::iterator iter; | 
|---|
| 64 | for(iter=queries.begin(); iter!=queries.end(); iter++) { | 
|---|
| 65 | (*iter)->setResult(); | 
|---|
| 66 | } | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | /****************** Query types Infrastructure **************************/ | 
|---|
| 70 |  | 
|---|
| 71 | // Base class | 
|---|
| 72 | Dialog::Query::Query(string _title, string _description) : | 
|---|
| 73 | title(_title), | 
|---|
| 74 | description(_description) | 
|---|
| 75 | {} | 
|---|
| 76 |  | 
|---|
| 77 | Dialog::Query::~Query() {} | 
|---|
| 78 |  | 
|---|
| 79 | const std::string Dialog::Query::getTitle() const{ | 
|---|
| 80 | return title; | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | const std::string Dialog::Query::getDescription() const{ | 
|---|
| 84 | return description; | 
|---|
| 85 | } | 
|---|
| 86 | // empty Queries | 
|---|
| 87 |  | 
|---|
| 88 | Dialog::EmptyQuery::EmptyQuery(string title, std::string description) : | 
|---|
| 89 | Query(title, description) | 
|---|
| 90 | {} | 
|---|
| 91 |  | 
|---|
| 92 | Dialog::EmptyQuery::~EmptyQuery() {} | 
|---|
| 93 |  | 
|---|
| 94 | void Dialog::EmptyQuery::setResult() { | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | // Int Queries | 
|---|
| 98 |  | 
|---|
| 99 | Dialog::IntQuery::IntQuery(string title,int *_target, std::string description) : | 
|---|
| 100 | Query(title, description), target(_target) | 
|---|
| 101 | {} | 
|---|
| 102 |  | 
|---|
| 103 | Dialog::IntQuery::~IntQuery() {} | 
|---|
| 104 |  | 
|---|
| 105 | void Dialog::IntQuery::setResult() { | 
|---|
| 106 | *target = tmp; | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | // Int Queries | 
|---|
| 110 |  | 
|---|
| 111 | Dialog::BooleanQuery::BooleanQuery(string title,bool *_target, std::string description) : | 
|---|
| 112 | Query(title, description), target(_target) | 
|---|
| 113 | {} | 
|---|
| 114 |  | 
|---|
| 115 | Dialog::BooleanQuery::~BooleanQuery() {} | 
|---|
| 116 |  | 
|---|
| 117 | void Dialog::BooleanQuery::setResult() { | 
|---|
| 118 | *target = tmp; | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | // String Queries | 
|---|
| 122 |  | 
|---|
| 123 | Dialog::StringQuery::StringQuery(string title,string *_target, std::string _description) : | 
|---|
| 124 | Query(title, _description), target(_target) | 
|---|
| 125 | {} | 
|---|
| 126 |  | 
|---|
| 127 | Dialog::StringQuery::~StringQuery() {}; | 
|---|
| 128 |  | 
|---|
| 129 | void Dialog::StringQuery::setResult() { | 
|---|
| 130 | *target = tmp; | 
|---|
| 131 | } | 
|---|
| 132 |  | 
|---|
| 133 | // Double Queries | 
|---|
| 134 |  | 
|---|
| 135 | Dialog::DoubleQuery::DoubleQuery(string title,double *_target, std::string _description) : | 
|---|
| 136 | Query(title, _description), target(_target) | 
|---|
| 137 | {} | 
|---|
| 138 |  | 
|---|
| 139 | Dialog::DoubleQuery::~DoubleQuery() {}; | 
|---|
| 140 |  | 
|---|
| 141 | void Dialog::DoubleQuery::setResult() { | 
|---|
| 142 | *target = tmp; | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 |  | 
|---|
| 146 | // Atom Queries | 
|---|
| 147 |  | 
|---|
| 148 | Dialog::AtomQuery::AtomQuery(string title, atom **_target, std::string _description) : | 
|---|
| 149 | Query(title, _description), | 
|---|
| 150 | tmp(0), | 
|---|
| 151 | target(_target) | 
|---|
| 152 |  | 
|---|
| 153 | {} | 
|---|
| 154 |  | 
|---|
| 155 | Dialog::AtomQuery::~AtomQuery() {} | 
|---|
| 156 |  | 
|---|
| 157 | void Dialog::AtomQuery::setResult() { | 
|---|
| 158 | *target = tmp; | 
|---|
| 159 | } | 
|---|
| 160 |  | 
|---|
| 161 | // Molecule Queries | 
|---|
| 162 |  | 
|---|
| 163 | Dialog::MoleculeQuery::MoleculeQuery(string title, molecule **_target, std::string _description) : | 
|---|
| 164 | Query(title, _description), | 
|---|
| 165 | tmp(0), | 
|---|
| 166 | target(_target) | 
|---|
| 167 |  | 
|---|
| 168 | {} | 
|---|
| 169 |  | 
|---|
| 170 | Dialog::MoleculeQuery::~MoleculeQuery() {} | 
|---|
| 171 |  | 
|---|
| 172 | void Dialog::MoleculeQuery::setResult() { | 
|---|
| 173 | *target = tmp; | 
|---|
| 174 | } | 
|---|
| 175 |  | 
|---|
| 176 | // Vector Queries | 
|---|
| 177 |  | 
|---|
| 178 | Dialog::VectorQuery::VectorQuery(std::string title,Vector *_target,bool _check, std::string _description) : | 
|---|
| 179 | Query(title, _description), | 
|---|
| 180 | check(_check), | 
|---|
| 181 | target(_target) | 
|---|
| 182 | { | 
|---|
| 183 | tmp = new Vector(); | 
|---|
| 184 | } | 
|---|
| 185 |  | 
|---|
| 186 | Dialog::VectorQuery::~VectorQuery() | 
|---|
| 187 | { | 
|---|
| 188 | delete tmp; | 
|---|
| 189 | } | 
|---|
| 190 |  | 
|---|
| 191 | void Dialog::VectorQuery::setResult() { | 
|---|
| 192 | *target = *tmp; | 
|---|
| 193 | } | 
|---|
| 194 |  | 
|---|
| 195 | // Box Queries | 
|---|
| 196 |  | 
|---|
| 197 | Dialog::BoxQuery::BoxQuery(std::string title, Box* _cellSize, std::string _description) : | 
|---|
| 198 | Query(title, _description), | 
|---|
| 199 | target(_cellSize) | 
|---|
| 200 | { | 
|---|
| 201 | tmp = new double[6]; | 
|---|
| 202 | } | 
|---|
| 203 |  | 
|---|
| 204 | Dialog::BoxQuery::~BoxQuery() | 
|---|
| 205 | { | 
|---|
| 206 | delete[] tmp; | 
|---|
| 207 | } | 
|---|
| 208 |  | 
|---|
| 209 | void Dialog::BoxQuery::setResult() { | 
|---|
| 210 | (*target)= ReturnFullMatrixforSymmetric(tmp); | 
|---|
| 211 | } | 
|---|
| 212 |  | 
|---|
| 213 | // Element Queries | 
|---|
| 214 | Dialog::ElementQuery::ElementQuery(std::string title, std::vector<element *> *_target, std::string _description) : | 
|---|
| 215 | Query(title, _description), | 
|---|
| 216 | target(_target) | 
|---|
| 217 | {} | 
|---|
| 218 |  | 
|---|
| 219 | Dialog::ElementQuery::~ElementQuery(){} | 
|---|
| 220 |  | 
|---|
| 221 | void Dialog::ElementQuery::setResult(){ | 
|---|
| 222 | *target=elements; | 
|---|
| 223 | } | 
|---|