| [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 | 
 | 
|---|
| [cd8e55] | 130 | // Strings Queries
 | 
|---|
 | 131 | 
 | 
|---|
 | 132 | Dialog::StringsQuery::StringsQuery(string title,vector<string> *_target, std::string _description) :
 | 
|---|
 | 133 |     Query(title, _description), target(_target)
 | 
|---|
 | 134 | {}
 | 
|---|
 | 135 | 
 | 
|---|
 | 136 | Dialog::StringsQuery::~StringsQuery() {};
 | 
|---|
 | 137 | 
 | 
|---|
 | 138 | void Dialog::StringsQuery::setResult() {
 | 
|---|
 | 139 |   *target = tmp;
 | 
|---|
 | 140 | }
 | 
|---|
 | 141 | 
 | 
|---|
| [2ededc2] | 142 | // Double Queries
 | 
|---|
 | 143 | 
 | 
|---|
| [a2ab15] | 144 | Dialog::DoubleQuery::DoubleQuery(string title,double *_target, std::string _description) :
 | 
|---|
 | 145 |     Query(title, _description), target(_target)
 | 
|---|
| [2ededc2] | 146 | {}
 | 
|---|
 | 147 | 
 | 
|---|
 | 148 | Dialog::DoubleQuery::~DoubleQuery() {};
 | 
|---|
 | 149 | 
 | 
|---|
 | 150 | void Dialog::DoubleQuery::setResult() {
 | 
|---|
 | 151 |   *target = tmp;
 | 
|---|
 | 152 | }
 | 
|---|
 | 153 | 
 | 
|---|
 | 154 | 
 | 
|---|
| [97ebf8] | 155 | // Atom Queries
 | 
|---|
 | 156 | 
 | 
|---|
 | 157 | Dialog::AtomQuery::AtomQuery(string title, atom **_target, std::string _description) :
 | 
|---|
 | 158 |     Query(title, _description),
 | 
|---|
 | 159 |     tmp(0),
 | 
|---|
 | 160 |     target(_target)
 | 
|---|
 | 161 | 
 | 
|---|
 | 162 | {}
 | 
|---|
 | 163 | 
 | 
|---|
 | 164 | Dialog::AtomQuery::~AtomQuery() {}
 | 
|---|
 | 165 | 
 | 
|---|
 | 166 | void Dialog::AtomQuery::setResult() {
 | 
|---|
 | 167 |   *target = tmp;
 | 
|---|
 | 168 | }
 | 
|---|
 | 169 | 
 | 
|---|
| [7aa000] | 170 | // Molecule Queries
 | 
|---|
 | 171 | 
 | 
|---|
| [97ebf8] | 172 | Dialog::MoleculeQuery::MoleculeQuery(string title, molecule **_target, std::string _description) :
 | 
|---|
| [a2ab15] | 173 |     Query(title, _description),
 | 
|---|
| [24a5e0] | 174 |     tmp(0),
 | 
|---|
 | 175 |     target(_target)
 | 
|---|
 | 176 | 
 | 
|---|
| [7aa000] | 177 | {}
 | 
|---|
 | 178 | 
 | 
|---|
 | 179 | Dialog::MoleculeQuery::~MoleculeQuery() {}
 | 
|---|
 | 180 | 
 | 
|---|
 | 181 | void Dialog::MoleculeQuery::setResult() {
 | 
|---|
 | 182 |   *target = tmp;
 | 
|---|
 | 183 | }
 | 
|---|
| [2ededc2] | 184 | 
 | 
|---|
 | 185 | // Vector Queries
 | 
|---|
 | 186 | 
 | 
|---|
| [a2ab15] | 187 | Dialog::VectorQuery::VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check, std::string _description) :
 | 
|---|
 | 188 |   Query(title, _description),
 | 
|---|
| [24a5e0] | 189 |   cellSize(_cellSize),
 | 
|---|
 | 190 |   check(_check),
 | 
|---|
 | 191 |   target(_target)
 | 
|---|
| [2ededc2] | 192 | {
 | 
|---|
| [26f75a] | 193 |   tmp = new Vector();
 | 
|---|
| [2ededc2] | 194 | }
 | 
|---|
 | 195 | 
 | 
|---|
 | 196 | Dialog::VectorQuery::~VectorQuery()
 | 
|---|
 | 197 | {
 | 
|---|
 | 198 |   delete tmp;
 | 
|---|
 | 199 | }
 | 
|---|
 | 200 | 
 | 
|---|
 | 201 | void Dialog::VectorQuery::setResult() {
 | 
|---|
 | 202 |   *target = *tmp;
 | 
|---|
 | 203 | }
 | 
|---|
| [5a7243] | 204 | 
 | 
|---|
| [97ebf8] | 205 | // Box Queries
 | 
|---|
 | 206 | 
 | 
|---|
 | 207 | Dialog::BoxQuery::BoxQuery(std::string title, double ** const _cellSize, std::string _description) :
 | 
|---|
 | 208 |   Query(title, _description),
 | 
|---|
 | 209 |   target(_cellSize)
 | 
|---|
 | 210 | {
 | 
|---|
 | 211 |     tmp = new double[6];
 | 
|---|
 | 212 | }
 | 
|---|
 | 213 | 
 | 
|---|
 | 214 | Dialog::BoxQuery::~BoxQuery()
 | 
|---|
 | 215 | {
 | 
|---|
 | 216 |   delete[] tmp;
 | 
|---|
 | 217 | }
 | 
|---|
 | 218 | 
 | 
|---|
 | 219 | void Dialog::BoxQuery::setResult() {
 | 
|---|
| [26f75a] | 220 |   for (int i=0;i<6;i++) {
 | 
|---|
 | 221 |     (*target)[i] = tmp[i];
 | 
|---|
 | 222 |   }
 | 
|---|
| [97ebf8] | 223 | }
 | 
|---|
 | 224 | 
 | 
|---|
| [5a7243] | 225 | // Element Queries
 | 
|---|
| [104524] | 226 | Dialog::ElementQuery::ElementQuery(std::string title, std::vector<element *> *_target, std::string _description) :
 | 
|---|
| [a2ab15] | 227 |   Query(title, _description),
 | 
|---|
| [5605032] | 228 |   target(_target)
 | 
|---|
| [5a7243] | 229 |   {}
 | 
|---|
 | 230 | 
 | 
|---|
 | 231 | Dialog::ElementQuery::~ElementQuery(){}
 | 
|---|
 | 232 | 
 | 
|---|
 | 233 | void Dialog::ElementQuery::setResult(){
 | 
|---|
| [104524] | 234 |   *target=elements;
 | 
|---|
| [5a7243] | 235 | }
 | 
|---|