| 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 | 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; | 
|---|
| 48 | } | 
|---|
| 49 |  | 
|---|
| 50 | /****************** Query types Infrastructure **************************/ | 
|---|
| 51 |  | 
|---|
| 52 | // Base class | 
|---|
| 53 | Dialog::Query::Query(string _title) : | 
|---|
| 54 | title(_title) | 
|---|
| 55 | {} | 
|---|
| 56 |  | 
|---|
| 57 | Dialog::Query::~Query() {} | 
|---|
| 58 |  | 
|---|
| 59 | const std::string Dialog::Query::getTitle() const{ | 
|---|
| 60 | return title; | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 | // Int Queries | 
|---|
| 64 |  | 
|---|
| 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; | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | // String Queries | 
|---|
| 76 |  | 
|---|
| 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 |  | 
|---|
| 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 |  | 
|---|
| 100 | // Molecule Queries | 
|---|
| 101 |  | 
|---|
| 102 | Dialog::MoleculeQuery::MoleculeQuery(string title, molecule **_target, MoleculeListClass *_molecules) : | 
|---|
| 103 | Query(title), | 
|---|
| 104 | tmp(0), | 
|---|
| 105 | molecules(_molecules), | 
|---|
| 106 | target(_target) | 
|---|
| 107 |  | 
|---|
| 108 | {} | 
|---|
| 109 |  | 
|---|
| 110 | Dialog::MoleculeQuery::~MoleculeQuery() {} | 
|---|
| 111 |  | 
|---|
| 112 | void Dialog::MoleculeQuery::setResult() { | 
|---|
| 113 | *target = tmp; | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 | // Vector Queries | 
|---|
| 117 |  | 
|---|
| 118 | Dialog::VectorQuery::VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check) : | 
|---|
| 119 | Query(title), | 
|---|
| 120 | cellSize(_cellSize), | 
|---|
| 121 | check(_check), | 
|---|
| 122 | target(_target) | 
|---|
| 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 | } | 
|---|