[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(){
|
---|
[d3a5ea] | 33 | if(checkAll()){
|
---|
| 34 | setAll();
|
---|
| 35 | return true;
|
---|
| 36 | }
|
---|
| 37 | else{
|
---|
| 38 | return false;
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | bool Dialog::checkAll(){
|
---|
[45f5d6] | 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;
|
---|
[f5a86a] | 52 | }
|
---|
| 53 |
|
---|
[d3a5ea] | 54 | void Dialog::setAll(){
|
---|
| 55 | list<Query*>::iterator iter;
|
---|
| 56 | for(iter=queries.begin(); iter!=queries.end(); iter++) {
|
---|
| 57 | (*iter)->setResult();
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[7aa000] | 61 | /****************** Query types Infrastructure **************************/
|
---|
| 62 |
|
---|
| 63 | // Base class
|
---|
[45f5d6] | 64 | Dialog::Query::Query(string _title) :
|
---|
| 65 | title(_title)
|
---|
| 66 | {}
|
---|
[f5a86a] | 67 |
|
---|
[45f5d6] | 68 | Dialog::Query::~Query() {}
|
---|
| 69 |
|
---|
| 70 | const std::string Dialog::Query::getTitle() const{
|
---|
| 71 | return title;
|
---|
[f5a86a] | 72 | }
|
---|
| 73 |
|
---|
[7aa000] | 74 | // Int Queries
|
---|
| 75 |
|
---|
[45f5d6] | 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;
|
---|
[f5a86a] | 84 | }
|
---|
[45f5d6] | 85 |
|
---|
[7aa000] | 86 | // String Queries
|
---|
| 87 |
|
---|
[45f5d6] | 88 | Dialog::StringQuery::StringQuery(string title,string *_target) :
|
---|
[d3a5ea] | 89 | Query(title),
|
---|
| 90 | target(_target),
|
---|
| 91 | tmp("")
|
---|
[45f5d6] | 92 | {}
|
---|
| 93 |
|
---|
| 94 | Dialog::StringQuery::~StringQuery() {};
|
---|
| 95 |
|
---|
| 96 | void Dialog::StringQuery::setResult() {
|
---|
| 97 | *target = tmp;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[2ededc2] | 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 |
|
---|
[7aa000] | 113 | // Molecule Queries
|
---|
| 114 |
|
---|
| 115 | Dialog::MoleculeQuery::MoleculeQuery(string title, molecule **_target, MoleculeListClass *_molecules) :
|
---|
| 116 | Query(title),
|
---|
[24a5e0] | 117 | tmp(0),
|
---|
[7aa000] | 118 | molecules(_molecules),
|
---|
[24a5e0] | 119 | target(_target)
|
---|
| 120 |
|
---|
[7aa000] | 121 | {}
|
---|
| 122 |
|
---|
| 123 | Dialog::MoleculeQuery::~MoleculeQuery() {}
|
---|
| 124 |
|
---|
| 125 | void Dialog::MoleculeQuery::setResult() {
|
---|
| 126 | *target = tmp;
|
---|
| 127 | }
|
---|
[2ededc2] | 128 |
|
---|
| 129 | // Vector Queries
|
---|
| 130 |
|
---|
| 131 | Dialog::VectorQuery::VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check) :
|
---|
[24a5e0] | 132 | Query(title),
|
---|
| 133 | cellSize(_cellSize),
|
---|
| 134 | check(_check),
|
---|
| 135 | target(_target)
|
---|
[2ededc2] | 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 | }
|
---|
[5a7243] | 148 |
|
---|
| 149 | // Element Queries
|
---|
[5605032] | 150 | Dialog::ElementQuery::ElementQuery(std::string title, const element **_target) :
|
---|
[5a7243] | 151 | Query(title),
|
---|
[5605032] | 152 | tmp(0),
|
---|
| 153 | target(_target)
|
---|
[5a7243] | 154 | {}
|
---|
| 155 |
|
---|
| 156 | Dialog::ElementQuery::~ElementQuery(){}
|
---|
| 157 |
|
---|
| 158 | void Dialog::ElementQuery::setResult(){
|
---|
| 159 | *target=tmp;
|
---|
| 160 | }
|
---|