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