| 1 | /*
|
|---|
| 2 | * Dialog.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Jan 5, 2010
|
|---|
| 5 | * Author: crueger
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include "Helpers/MemDebug.hpp"
|
|---|
| 9 |
|
|---|
| 10 | #include <cassert>
|
|---|
| 11 |
|
|---|
| 12 | #include "Dialog.hpp"
|
|---|
| 13 |
|
|---|
| 14 | #include "atom.hpp"
|
|---|
| 15 | #include "element.hpp"
|
|---|
| 16 | #include "molecule.hpp"
|
|---|
| 17 | #include "vector.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 | 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
|
|---|
| 43 | if(!retval) {
|
|---|
| 44 | DoeLog(1) && (eLog() << Verbose(1) << "The following query failed: " << (**iter).getTitle() << "." << endl);
|
|---|
| 45 | break;
|
|---|
| 46 | }
|
|---|
| 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;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | /****************** Query types Infrastructure **************************/
|
|---|
| 58 |
|
|---|
| 59 | // Base class
|
|---|
| 60 | Dialog::Query::Query(string _title, string _description) :
|
|---|
| 61 | title(_title),
|
|---|
| 62 | description(_description)
|
|---|
| 63 | {}
|
|---|
| 64 |
|
|---|
| 65 | Dialog::Query::~Query() {}
|
|---|
| 66 |
|
|---|
| 67 | const std::string Dialog::Query::getTitle() const{
|
|---|
| 68 | return title;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | const std::string Dialog::Query::getDescription() const{
|
|---|
| 72 | return description;
|
|---|
| 73 | }
|
|---|
| 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 |
|
|---|
| 85 | // Int Queries
|
|---|
| 86 |
|
|---|
| 87 | Dialog::IntQuery::IntQuery(string title,int *_target, std::string description) :
|
|---|
| 88 | Query(title, description), target(_target)
|
|---|
| 89 | {}
|
|---|
| 90 |
|
|---|
| 91 | Dialog::IntQuery::~IntQuery() {}
|
|---|
| 92 |
|
|---|
| 93 | void Dialog::IntQuery::setResult() {
|
|---|
| 94 | *target = tmp;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 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 |
|
|---|
| 109 | // String Queries
|
|---|
| 110 |
|
|---|
| 111 | Dialog::StringQuery::StringQuery(string title,string *_target, std::string _description) :
|
|---|
| 112 | Query(title, _description), target(_target)
|
|---|
| 113 | {}
|
|---|
| 114 |
|
|---|
| 115 | Dialog::StringQuery::~StringQuery() {};
|
|---|
| 116 |
|
|---|
| 117 | void Dialog::StringQuery::setResult() {
|
|---|
| 118 | *target = tmp;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | // Double Queries
|
|---|
| 122 |
|
|---|
| 123 | Dialog::DoubleQuery::DoubleQuery(string title,double *_target, std::string _description) :
|
|---|
| 124 | Query(title, _description), target(_target)
|
|---|
| 125 | {}
|
|---|
| 126 |
|
|---|
| 127 | Dialog::DoubleQuery::~DoubleQuery() {};
|
|---|
| 128 |
|
|---|
| 129 | void Dialog::DoubleQuery::setResult() {
|
|---|
| 130 | *target = tmp;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 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 |
|
|---|
| 149 | // Molecule Queries
|
|---|
| 150 |
|
|---|
| 151 | Dialog::MoleculeQuery::MoleculeQuery(string title, molecule **_target, std::string _description) :
|
|---|
| 152 | Query(title, _description),
|
|---|
| 153 | tmp(0),
|
|---|
| 154 | target(_target)
|
|---|
| 155 |
|
|---|
| 156 | {}
|
|---|
| 157 |
|
|---|
| 158 | Dialog::MoleculeQuery::~MoleculeQuery() {}
|
|---|
| 159 |
|
|---|
| 160 | void Dialog::MoleculeQuery::setResult() {
|
|---|
| 161 | *target = tmp;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | // Vector Queries
|
|---|
| 165 |
|
|---|
| 166 | Dialog::VectorQuery::VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check, std::string _description) :
|
|---|
| 167 | Query(title, _description),
|
|---|
| 168 | cellSize(_cellSize),
|
|---|
| 169 | check(_check),
|
|---|
| 170 | target(_target)
|
|---|
| 171 | {
|
|---|
| 172 | tmp = new Vector();
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | Dialog::VectorQuery::~VectorQuery()
|
|---|
| 176 | {
|
|---|
| 177 | delete tmp;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | void Dialog::VectorQuery::setResult() {
|
|---|
| 181 | *target = *tmp;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 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() {
|
|---|
| 199 | for (int i=0;i<6;i++) {
|
|---|
| 200 | (*target)[i] = tmp[i];
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | // Element Queries
|
|---|
| 205 | Dialog::ElementQuery::ElementQuery(std::string title, std::vector<element *> *_target, std::string _description) :
|
|---|
| 206 | Query(title, _description),
|
|---|
| 207 | target(_target)
|
|---|
| 208 | {}
|
|---|
| 209 |
|
|---|
| 210 | Dialog::ElementQuery::~ElementQuery(){}
|
|---|
| 211 |
|
|---|
| 212 | void Dialog::ElementQuery::setResult(){
|
|---|
| 213 | *target=elements;
|
|---|
| 214 | }
|
|---|