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