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