1 | /*
|
---|
2 | * Dialog.cpp
|
---|
3 | *
|
---|
4 | * Created on: Jan 5, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Dialog.hpp"
|
---|
11 |
|
---|
12 | #include "atom.hpp"
|
---|
13 | #include "element.hpp"
|
---|
14 | #include "molecule.hpp"
|
---|
15 | #include "vector.hpp"
|
---|
16 |
|
---|
17 | using namespace std;
|
---|
18 |
|
---|
19 | Dialog::Dialog()
|
---|
20 | {
|
---|
21 | }
|
---|
22 |
|
---|
23 | Dialog::~Dialog()
|
---|
24 | {
|
---|
25 | list<Query*>::iterator iter;
|
---|
26 | for(iter=queries.begin();iter!=queries.end();iter++){
|
---|
27 | delete (*iter);
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | void Dialog::registerQuery(Query *query){
|
---|
32 | queries.push_back(query);
|
---|
33 | }
|
---|
34 |
|
---|
35 | bool Dialog::display(){
|
---|
36 | if(checkAll()){
|
---|
37 | setAll();
|
---|
38 | return true;
|
---|
39 | }
|
---|
40 | else{
|
---|
41 | return false;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | bool Dialog::checkAll(){
|
---|
46 | list<Query*>::iterator iter;
|
---|
47 | bool retval = true;
|
---|
48 | for(iter=queries.begin(); iter!=queries.end(); iter++){
|
---|
49 | retval &= (*iter)->handle();
|
---|
50 | // if any query fails (is canceled), we can end the handling process
|
---|
51 | if(!retval) {
|
---|
52 | DoeLog(1) && (eLog() << Verbose(1) << "The following query failed: " << (**iter).getTitle() << "." << endl);
|
---|
53 | break;
|
---|
54 | }
|
---|
55 | }
|
---|
56 | return retval;
|
---|
57 | }
|
---|
58 |
|
---|
59 | void Dialog::setAll(){
|
---|
60 | list<Query*>::iterator iter;
|
---|
61 | for(iter=queries.begin(); iter!=queries.end(); iter++) {
|
---|
62 | (*iter)->setResult();
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | /****************** Query types Infrastructure **************************/
|
---|
67 |
|
---|
68 | // Base class
|
---|
69 | Dialog::Query::Query(string _title, string _description) :
|
---|
70 | title(_title),
|
---|
71 | description(_description)
|
---|
72 | {}
|
---|
73 |
|
---|
74 | Dialog::Query::~Query() {}
|
---|
75 |
|
---|
76 | const std::string Dialog::Query::getTitle() const{
|
---|
77 | return title;
|
---|
78 | }
|
---|
79 |
|
---|
80 | const std::string Dialog::Query::getDescription() const{
|
---|
81 | return description;
|
---|
82 | }
|
---|
83 | // empty Queries
|
---|
84 |
|
---|
85 | Dialog::EmptyQuery::EmptyQuery(string title, std::string description) :
|
---|
86 | Query(title, description)
|
---|
87 | {}
|
---|
88 |
|
---|
89 | Dialog::EmptyQuery::~EmptyQuery() {}
|
---|
90 |
|
---|
91 | void Dialog::EmptyQuery::setResult() {
|
---|
92 | }
|
---|
93 |
|
---|
94 | // Int Queries
|
---|
95 |
|
---|
96 | Dialog::IntQuery::IntQuery(string title,int *_target, std::string description) :
|
---|
97 | Query(title, description), target(_target)
|
---|
98 | {}
|
---|
99 |
|
---|
100 | Dialog::IntQuery::~IntQuery() {}
|
---|
101 |
|
---|
102 | void Dialog::IntQuery::setResult() {
|
---|
103 | *target = tmp;
|
---|
104 | }
|
---|
105 |
|
---|
106 | // Int Queries
|
---|
107 |
|
---|
108 | Dialog::BooleanQuery::BooleanQuery(string title,bool *_target, std::string description) :
|
---|
109 | Query(title, description), target(_target)
|
---|
110 | {}
|
---|
111 |
|
---|
112 | Dialog::BooleanQuery::~BooleanQuery() {}
|
---|
113 |
|
---|
114 | void Dialog::BooleanQuery::setResult() {
|
---|
115 | *target = tmp;
|
---|
116 | }
|
---|
117 |
|
---|
118 | // String Queries
|
---|
119 |
|
---|
120 | Dialog::StringQuery::StringQuery(string title,string *_target, std::string _description) :
|
---|
121 | Query(title, _description), target(_target)
|
---|
122 | {}
|
---|
123 |
|
---|
124 | Dialog::StringQuery::~StringQuery() {};
|
---|
125 |
|
---|
126 | void Dialog::StringQuery::setResult() {
|
---|
127 | *target = tmp;
|
---|
128 | }
|
---|
129 |
|
---|
130 | // Double Queries
|
---|
131 |
|
---|
132 | Dialog::DoubleQuery::DoubleQuery(string title,double *_target, std::string _description) :
|
---|
133 | Query(title, _description), target(_target)
|
---|
134 | {}
|
---|
135 |
|
---|
136 | Dialog::DoubleQuery::~DoubleQuery() {};
|
---|
137 |
|
---|
138 | void Dialog::DoubleQuery::setResult() {
|
---|
139 | *target = tmp;
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | // Atom Queries
|
---|
144 |
|
---|
145 | Dialog::AtomQuery::AtomQuery(string title, atom **_target, std::string _description) :
|
---|
146 | Query(title, _description),
|
---|
147 | tmp(0),
|
---|
148 | target(_target)
|
---|
149 |
|
---|
150 | {}
|
---|
151 |
|
---|
152 | Dialog::AtomQuery::~AtomQuery() {}
|
---|
153 |
|
---|
154 | void Dialog::AtomQuery::setResult() {
|
---|
155 | *target = tmp;
|
---|
156 | }
|
---|
157 |
|
---|
158 | // Molecule Queries
|
---|
159 |
|
---|
160 | Dialog::MoleculeQuery::MoleculeQuery(string title, molecule **_target, std::string _description) :
|
---|
161 | Query(title, _description),
|
---|
162 | tmp(0),
|
---|
163 | target(_target)
|
---|
164 |
|
---|
165 | {}
|
---|
166 |
|
---|
167 | Dialog::MoleculeQuery::~MoleculeQuery() {}
|
---|
168 |
|
---|
169 | void Dialog::MoleculeQuery::setResult() {
|
---|
170 | *target = tmp;
|
---|
171 | }
|
---|
172 |
|
---|
173 | // Vector Queries
|
---|
174 |
|
---|
175 | Dialog::VectorQuery::VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check, std::string _description) :
|
---|
176 | Query(title, _description),
|
---|
177 | cellSize(_cellSize),
|
---|
178 | check(_check),
|
---|
179 | target(_target)
|
---|
180 | {
|
---|
181 | tmp = new Vector();
|
---|
182 | }
|
---|
183 |
|
---|
184 | Dialog::VectorQuery::~VectorQuery()
|
---|
185 | {
|
---|
186 | delete tmp;
|
---|
187 | }
|
---|
188 |
|
---|
189 | void Dialog::VectorQuery::setResult() {
|
---|
190 | *target = *tmp;
|
---|
191 | }
|
---|
192 |
|
---|
193 | // Box Queries
|
---|
194 |
|
---|
195 | Dialog::BoxQuery::BoxQuery(std::string title, double ** const _cellSize, std::string _description) :
|
---|
196 | Query(title, _description),
|
---|
197 | target(_cellSize)
|
---|
198 | {
|
---|
199 | tmp = new double[6];
|
---|
200 | }
|
---|
201 |
|
---|
202 | Dialog::BoxQuery::~BoxQuery()
|
---|
203 | {
|
---|
204 | delete[] tmp;
|
---|
205 | }
|
---|
206 |
|
---|
207 | void Dialog::BoxQuery::setResult() {
|
---|
208 | for (int i=0;i<6;i++) {
|
---|
209 | (*target)[i] = tmp[i];
|
---|
210 | }
|
---|
211 | }
|
---|
212 |
|
---|
213 | // Element Queries
|
---|
214 | Dialog::ElementQuery::ElementQuery(std::string title, std::vector<element *> *_target, std::string _description) :
|
---|
215 | Query(title, _description),
|
---|
216 | target(_target)
|
---|
217 | {}
|
---|
218 |
|
---|
219 | Dialog::ElementQuery::~ElementQuery(){}
|
---|
220 |
|
---|
221 | void Dialog::ElementQuery::setResult(){
|
---|
222 | *target=elements;
|
---|
223 | }
|
---|