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