| 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 | target(_target),
|
|---|
| 118 | molecules(_molecules),
|
|---|
| 119 | tmp(0)
|
|---|
| 120 | {}
|
|---|
| 121 |
|
|---|
| 122 | Dialog::MoleculeQuery::~MoleculeQuery() {}
|
|---|
| 123 |
|
|---|
| 124 | void Dialog::MoleculeQuery::setResult() {
|
|---|
| 125 | *target = tmp;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | // Vector Queries
|
|---|
| 129 |
|
|---|
| 130 | Dialog::VectorQuery::VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check) :
|
|---|
| 131 | Query(title), target(_target), cellSize(_cellSize), check(_check)
|
|---|
| 132 | {
|
|---|
| 133 | tmp = new Vector();
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | Dialog::VectorQuery::~VectorQuery()
|
|---|
| 137 | {
|
|---|
| 138 | delete tmp;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | void Dialog::VectorQuery::setResult() {
|
|---|
| 142 | *target = *tmp;
|
|---|
| 143 | }
|
|---|