| 1 | /*
 | 
|---|
| 2 |  * Dialog.cpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: Jan 5, 2010
 | 
|---|
| 5 |  *      Author: crueger
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include <cassert>
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include "UIElements/Dialog.hpp"
 | 
|---|
| 11 | 
 | 
|---|
| 12 | #include "vector.hpp"
 | 
|---|
| 13 | 
 | 
|---|
| 14 | using namespace std;
 | 
|---|
| 15 | 
 | 
|---|
| 16 | Dialog::Dialog()
 | 
|---|
| 17 | {
 | 
|---|
| 18 | }
 | 
|---|
| 19 | 
 | 
|---|
| 20 | Dialog::~Dialog()
 | 
|---|
| 21 | {
 | 
|---|
| 22 |   list<Query*>::iterator iter;
 | 
|---|
| 23 |   for(iter=queries.begin();iter!=queries.end();iter++){
 | 
|---|
| 24 |     delete (*iter);
 | 
|---|
| 25 |   }
 | 
|---|
| 26 | }
 | 
|---|
| 27 | 
 | 
|---|
| 28 | void Dialog::registerQuery(Query *query){
 | 
|---|
| 29 |   queries.push_back(query);
 | 
|---|
| 30 | }
 | 
|---|
| 31 | 
 | 
|---|
| 32 | bool Dialog::display(){
 | 
|---|
| 33 |   if(checkAll()){
 | 
|---|
| 34 |     setAll();
 | 
|---|
| 35 |     return true;
 | 
|---|
| 36 |   }
 | 
|---|
| 37 |   else{
 | 
|---|
| 38 |     return false;
 | 
|---|
| 39 |   }
 | 
|---|
| 40 | }
 | 
|---|
| 41 | 
 | 
|---|
| 42 | bool Dialog::checkAll(){
 | 
|---|
| 43 |   list<Query*>::iterator iter;
 | 
|---|
| 44 |   bool retval = true;
 | 
|---|
| 45 |   for(iter=queries.begin(); iter!=queries.end(); iter++){
 | 
|---|
| 46 |     retval &= (*iter)->handle();
 | 
|---|
| 47 |     // if any query fails (is canceled), we can end the handling process
 | 
|---|
| 48 |     if(!retval)
 | 
|---|
| 49 |       break;
 | 
|---|
| 50 |   }
 | 
|---|
| 51 |   return retval;
 | 
|---|
| 52 | }
 | 
|---|
| 53 | 
 | 
|---|
| 54 | void Dialog::setAll(){
 | 
|---|
| 55 |   list<Query*>::iterator iter;
 | 
|---|
| 56 |   for(iter=queries.begin(); iter!=queries.end(); iter++) {
 | 
|---|
| 57 |     (*iter)->setResult();
 | 
|---|
| 58 |   }
 | 
|---|
| 59 | }
 | 
|---|
| 60 | 
 | 
|---|
| 61 | /****************** Query types Infrastructure **************************/
 | 
|---|
| 62 | 
 | 
|---|
| 63 | // Base class
 | 
|---|
| 64 | Dialog::Query::Query(string _title) :
 | 
|---|
| 65 |     title(_title)
 | 
|---|
| 66 | {}
 | 
|---|
| 67 | 
 | 
|---|
| 68 | Dialog::Query::~Query() {}
 | 
|---|
| 69 | 
 | 
|---|
| 70 | const std::string Dialog::Query::getTitle() const{
 | 
|---|
| 71 |   return title;
 | 
|---|
| 72 | }
 | 
|---|
| 73 | 
 | 
|---|
| 74 | // Int Queries
 | 
|---|
| 75 | 
 | 
|---|
| 76 | Dialog::IntQuery::IntQuery(string title,int *_target) :
 | 
|---|
| 77 |     Query(title), target(_target)
 | 
|---|
| 78 | {}
 | 
|---|
| 79 | 
 | 
|---|
| 80 | Dialog::IntQuery::~IntQuery() {}
 | 
|---|
| 81 | 
 | 
|---|
| 82 | void Dialog::IntQuery::setResult() {
 | 
|---|
| 83 |   *target = tmp;
 | 
|---|
| 84 | }
 | 
|---|
| 85 | 
 | 
|---|
| 86 | // String Queries
 | 
|---|
| 87 | 
 | 
|---|
| 88 | Dialog::StringQuery::StringQuery(string title,string *_target) :
 | 
|---|
| 89 |     Query(title),
 | 
|---|
| 90 |     target(_target),
 | 
|---|
| 91 |     tmp("")
 | 
|---|
| 92 | {}
 | 
|---|
| 93 | 
 | 
|---|
| 94 | Dialog::StringQuery::~StringQuery() {};
 | 
|---|
| 95 | 
 | 
|---|
| 96 | void Dialog::StringQuery::setResult() {
 | 
|---|
| 97 |   *target = tmp;
 | 
|---|
| 98 | }
 | 
|---|
| 99 | 
 | 
|---|
| 100 | // Double Queries
 | 
|---|
| 101 | 
 | 
|---|
| 102 | Dialog::DoubleQuery::DoubleQuery(string title,double *_target) :
 | 
|---|
| 103 |     Query(title), target(_target)
 | 
|---|
| 104 | {}
 | 
|---|
| 105 | 
 | 
|---|
| 106 | Dialog::DoubleQuery::~DoubleQuery() {};
 | 
|---|
| 107 | 
 | 
|---|
| 108 | void Dialog::DoubleQuery::setResult() {
 | 
|---|
| 109 |   *target = tmp;
 | 
|---|
| 110 | }
 | 
|---|
| 111 | 
 | 
|---|
| 112 | 
 | 
|---|
| 113 | // Molecule Queries
 | 
|---|
| 114 | 
 | 
|---|
| 115 | Dialog::MoleculeQuery::MoleculeQuery(string title, molecule **_target, MoleculeListClass *_molecules) :
 | 
|---|
| 116 |     Query(title),
 | 
|---|
| 117 |     tmp(0),
 | 
|---|
| 118 |     molecules(_molecules),
 | 
|---|
| 119 |     target(_target)
 | 
|---|
| 120 | 
 | 
|---|
| 121 | {}
 | 
|---|
| 122 | 
 | 
|---|
| 123 | Dialog::MoleculeQuery::~MoleculeQuery() {}
 | 
|---|
| 124 | 
 | 
|---|
| 125 | void Dialog::MoleculeQuery::setResult() {
 | 
|---|
| 126 |   *target = tmp;
 | 
|---|
| 127 | }
 | 
|---|
| 128 | 
 | 
|---|
| 129 | // Vector Queries
 | 
|---|
| 130 | 
 | 
|---|
| 131 | Dialog::VectorQuery::VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check) :
 | 
|---|
| 132 |   Query(title),
 | 
|---|
| 133 |   cellSize(_cellSize),
 | 
|---|
| 134 |   check(_check),
 | 
|---|
| 135 |   target(_target)
 | 
|---|
| 136 | {
 | 
|---|
| 137 | tmp = new Vector();
 | 
|---|
| 138 | }
 | 
|---|
| 139 | 
 | 
|---|
| 140 | Dialog::VectorQuery::~VectorQuery()
 | 
|---|
| 141 | {
 | 
|---|
| 142 |   delete tmp;
 | 
|---|
| 143 | }
 | 
|---|
| 144 | 
 | 
|---|
| 145 | void Dialog::VectorQuery::setResult() {
 | 
|---|
| 146 |   *target = *tmp;
 | 
|---|
| 147 | }
 | 
|---|
| 148 | 
 | 
|---|
| 149 | // Element Queries
 | 
|---|
| 150 | Dialog::ElementQuery::ElementQuery(std::string title, const element **_target) :
 | 
|---|
| 151 |   Query(title),
 | 
|---|
| 152 |   tmp(0),
 | 
|---|
| 153 |   target(_target)
 | 
|---|
| 154 |   {}
 | 
|---|
| 155 | 
 | 
|---|
| 156 | Dialog::ElementQuery::~ElementQuery(){}
 | 
|---|
| 157 | 
 | 
|---|
| 158 | void Dialog::ElementQuery::setResult(){
 | 
|---|
| 159 |   *target=tmp;
 | 
|---|
| 160 | }
 | 
|---|