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