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