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