1 | /*
|
---|
2 | * Dialog.hpp
|
---|
3 | *
|
---|
4 | * Created on: Jan 5, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef DIALOG_HPP_
|
---|
9 | #define DIALOG_HPP_
|
---|
10 |
|
---|
11 | #include<string>
|
---|
12 | #include<list>
|
---|
13 | #include<vector>
|
---|
14 |
|
---|
15 | #include <boost/filesystem.hpp>
|
---|
16 |
|
---|
17 | #include "Box.hpp"
|
---|
18 | #include "LinearAlgebra/Vector.hpp"
|
---|
19 |
|
---|
20 | class atom;
|
---|
21 | class Box;
|
---|
22 | class element;
|
---|
23 | class molecule;
|
---|
24 |
|
---|
25 |
|
---|
26 | /** Dialog is one of the two main classes of the UIFactory base class.
|
---|
27 | *
|
---|
28 | * The Dialog is meant for asking the user for information needed to perform actions he
|
---|
29 | * desires, such as asking for a position in space or a length.
|
---|
30 | *
|
---|
31 | * For this purpose there is the base class Query and numerous specializations for each
|
---|
32 | * of the types to be asked. There are primitives integer, doubles and string, but also
|
---|
33 | * advanced types such as element, molecule or Vector. There is also an empty query for
|
---|
34 | * displaying text.
|
---|
35 | */
|
---|
36 | class Dialog
|
---|
37 | {
|
---|
38 | public:
|
---|
39 | Dialog();
|
---|
40 | virtual ~Dialog();
|
---|
41 |
|
---|
42 | template <class T> void query(const char *, std::string = "");
|
---|
43 |
|
---|
44 | virtual void queryEmpty(const char *, std::string = "")=0;
|
---|
45 | virtual void queryBoolean(const char *, std::string = "")=0;
|
---|
46 | virtual void queryInt(const char *, std::string = "")=0;
|
---|
47 | virtual void queryInts(const char *, std::string = "")=0;
|
---|
48 | virtual void queryDouble(const char*, std::string = "")=0;
|
---|
49 | virtual void queryDoubles(const char*, std::string = "")=0;
|
---|
50 | virtual void queryString(const char*, std::string = "")=0;
|
---|
51 | virtual void queryStrings(const char*, std::string = "")=0;
|
---|
52 | virtual void queryAtom(const char*,std::string = "")=0;
|
---|
53 | virtual void queryAtoms(const char*,std::string = "")=0;
|
---|
54 | virtual void queryMolecule(const char*, std::string = "")=0;
|
---|
55 | virtual void queryMolecules(const char*, std::string = "")=0;
|
---|
56 | virtual void queryVector(const char*,bool, std::string = "")=0;
|
---|
57 | virtual void queryVectors(const char*,bool, std::string = "")=0;
|
---|
58 | virtual void queryBox(const char*, std::string = "")=0;
|
---|
59 | virtual void queryElement(const char*, std::string = "")=0;
|
---|
60 | virtual void queryElements(const char*, std::string = "")=0;
|
---|
61 | virtual void queryFile(const char*, std::string = "")=0;
|
---|
62 |
|
---|
63 | virtual bool display();
|
---|
64 |
|
---|
65 | virtual bool checkAll();
|
---|
66 | virtual void setAll();
|
---|
67 |
|
---|
68 | virtual bool hasQueries();
|
---|
69 |
|
---|
70 | protected:
|
---|
71 | // methodology for handling queries
|
---|
72 | // all queries are stored and then performed at appropriate times
|
---|
73 |
|
---|
74 | //these queries can be handled by this dialog
|
---|
75 |
|
---|
76 | //TODO: Find a way to reduce complexity...
|
---|
77 | //needs O(N*M) query classes, where N is the number of query types and M is the number of GUIs
|
---|
78 | //usual approach for reducing inheritance complexity (strategy pattern) does not work,
|
---|
79 | //due to lack of common code for query types as well as GUI-Types (all subtypes differ a lot)
|
---|
80 |
|
---|
81 | //base class for all queries
|
---|
82 | class Query {
|
---|
83 | friend class Dialog;
|
---|
84 | public:
|
---|
85 | Query(std::string _title, std::string _description = "");
|
---|
86 | virtual ~Query();
|
---|
87 | virtual bool handle()=0;
|
---|
88 | virtual void setResult()=0;
|
---|
89 | protected:
|
---|
90 | const std::string getTitle() const;
|
---|
91 | const std::string getDescription() const;
|
---|
92 | private:
|
---|
93 | std::string title; //!< short title of the query
|
---|
94 | std::string description; //!< longer description for tooltips or for help
|
---|
95 | };
|
---|
96 |
|
---|
97 | // Empty Query is just meant for showing text, such as version, help, initial message or alike
|
---|
98 | class EmptyQuery : public Query {
|
---|
99 | public:
|
---|
100 | EmptyQuery(std::string title, std::string _description = "");
|
---|
101 | virtual ~EmptyQuery();
|
---|
102 | virtual bool handle()=0;
|
---|
103 | virtual void setResult();
|
---|
104 | };
|
---|
105 |
|
---|
106 | //Specialized classes for certain types. GUI-Types are not specialized at this time
|
---|
107 | class BooleanQuery : public Query {
|
---|
108 | public:
|
---|
109 | BooleanQuery(std::string title, std::string _description = "");
|
---|
110 | virtual ~BooleanQuery();
|
---|
111 | virtual bool handle()=0;
|
---|
112 | virtual void setResult();
|
---|
113 | protected:
|
---|
114 | bool tmp;
|
---|
115 | };
|
---|
116 |
|
---|
117 | class IntQuery : public Query {
|
---|
118 | public:
|
---|
119 | IntQuery(std::string title, std::string _description = "");
|
---|
120 | virtual ~IntQuery();
|
---|
121 | virtual bool handle()=0;
|
---|
122 | virtual void setResult();
|
---|
123 | protected:
|
---|
124 | int tmp;
|
---|
125 | };
|
---|
126 |
|
---|
127 | class IntsQuery : public Query {
|
---|
128 | public:
|
---|
129 | IntsQuery(std::string title, std::string _description = "");
|
---|
130 | virtual ~IntsQuery();
|
---|
131 | virtual bool handle()=0;
|
---|
132 | virtual void setResult();
|
---|
133 | protected:
|
---|
134 | int temp;
|
---|
135 | std::vector<int> tmp;
|
---|
136 | };
|
---|
137 |
|
---|
138 | class DoubleQuery : public Query {
|
---|
139 | public:
|
---|
140 | DoubleQuery(std::string title, std::string _description = "");
|
---|
141 | virtual ~DoubleQuery();
|
---|
142 | virtual bool handle()=0;
|
---|
143 | virtual void setResult();
|
---|
144 | protected:
|
---|
145 | double tmp;
|
---|
146 | };
|
---|
147 |
|
---|
148 | class DoublesQuery : public Query {
|
---|
149 | public:
|
---|
150 | DoublesQuery(std::string title, std::string _description = "");
|
---|
151 | virtual ~DoublesQuery();
|
---|
152 | virtual bool handle()=0;
|
---|
153 | virtual void setResult();
|
---|
154 | protected:
|
---|
155 | double temp;
|
---|
156 | std::vector<double> tmp;
|
---|
157 | };
|
---|
158 |
|
---|
159 | class StringQuery : public Query {
|
---|
160 | public:
|
---|
161 | StringQuery(std::string title, std::string _description = "");
|
---|
162 | virtual ~StringQuery();
|
---|
163 | virtual bool handle()=0;
|
---|
164 | virtual void setResult();
|
---|
165 | protected:
|
---|
166 | std::string tmp;
|
---|
167 | };
|
---|
168 |
|
---|
169 | class StringsQuery : public Query {
|
---|
170 | public:
|
---|
171 | StringsQuery(std::string title, std::string _description = "");
|
---|
172 | virtual ~StringsQuery();
|
---|
173 | virtual bool handle()=0;
|
---|
174 | virtual void setResult();
|
---|
175 | protected:
|
---|
176 | std::string temp;
|
---|
177 | std::vector<std::string> tmp;
|
---|
178 | };
|
---|
179 |
|
---|
180 | class MoleculeQuery : public Query {
|
---|
181 | public:
|
---|
182 | MoleculeQuery(std::string title, std::string _description = "");
|
---|
183 | virtual ~MoleculeQuery();
|
---|
184 | virtual bool handle()=0;
|
---|
185 | virtual void setResult();
|
---|
186 | protected:
|
---|
187 | molecule *tmp;
|
---|
188 | };
|
---|
189 |
|
---|
190 | class MoleculesQuery : public Query {
|
---|
191 | public:
|
---|
192 | MoleculesQuery(std::string title, std::string _description = "");
|
---|
193 | virtual ~MoleculesQuery();
|
---|
194 | virtual bool handle()=0;
|
---|
195 | virtual void setResult();
|
---|
196 | protected:
|
---|
197 | molecule * temp;
|
---|
198 | std::vector<molecule *> tmp;
|
---|
199 | };
|
---|
200 |
|
---|
201 | class AtomQuery : public Query {
|
---|
202 | public:
|
---|
203 | AtomQuery(std::string title, std::string _description = "");
|
---|
204 | virtual ~AtomQuery();
|
---|
205 | virtual bool handle()=0;
|
---|
206 | virtual void setResult();
|
---|
207 | protected:
|
---|
208 | atom *tmp;
|
---|
209 | };
|
---|
210 |
|
---|
211 | class AtomsQuery : public Query {
|
---|
212 | public:
|
---|
213 | AtomsQuery(std::string title, std::string _description = "");
|
---|
214 | virtual ~AtomsQuery();
|
---|
215 | virtual bool handle()=0;
|
---|
216 | virtual void setResult();
|
---|
217 | protected:
|
---|
218 | atom *temp;
|
---|
219 | std::vector<atom *> tmp;
|
---|
220 | };
|
---|
221 |
|
---|
222 | class VectorQuery : public Query {
|
---|
223 | public:
|
---|
224 | VectorQuery(std::string title,bool _check, std::string _description = "");
|
---|
225 | virtual ~VectorQuery();
|
---|
226 | virtual bool handle()=0;
|
---|
227 | virtual void setResult();
|
---|
228 | protected:
|
---|
229 | Vector tmp;
|
---|
230 | bool check;
|
---|
231 | };
|
---|
232 |
|
---|
233 | class VectorsQuery : public Query {
|
---|
234 | public:
|
---|
235 | VectorsQuery(std::string title,bool _check, std::string _description = "");
|
---|
236 | virtual ~VectorsQuery();
|
---|
237 | virtual bool handle()=0;
|
---|
238 | virtual void setResult();
|
---|
239 | protected:
|
---|
240 | Vector temp;
|
---|
241 | std::vector<Vector> tmp;
|
---|
242 | bool check;
|
---|
243 | };
|
---|
244 |
|
---|
245 | class BoxQuery : public Query {
|
---|
246 | public:
|
---|
247 | BoxQuery(std::string title, std::string _description = "");
|
---|
248 | virtual ~BoxQuery();
|
---|
249 | virtual bool handle()=0;
|
---|
250 | virtual void setResult();
|
---|
251 | protected:
|
---|
252 | Box tmp;
|
---|
253 | };
|
---|
254 |
|
---|
255 | class ElementQuery : public Query {
|
---|
256 | public:
|
---|
257 | ElementQuery(std::string title, std::string _description = "");
|
---|
258 | virtual ~ElementQuery();
|
---|
259 | virtual bool handle()=0;
|
---|
260 | virtual void setResult();
|
---|
261 | protected:
|
---|
262 | const element * tmp;
|
---|
263 | };
|
---|
264 |
|
---|
265 | class ElementsQuery : public Query {
|
---|
266 | public:
|
---|
267 | ElementsQuery(std::string title, std::string _description = "");
|
---|
268 | virtual ~ElementsQuery();
|
---|
269 | virtual bool handle()=0;
|
---|
270 | virtual void setResult();
|
---|
271 | protected:
|
---|
272 | const element *temp;
|
---|
273 | std::vector<const element *> tmp;
|
---|
274 | };
|
---|
275 |
|
---|
276 | class FileQuery : public Query {
|
---|
277 | public:
|
---|
278 | FileQuery(std::string title, std::string _description = "");
|
---|
279 | virtual ~FileQuery();
|
---|
280 | virtual bool handle()=0;
|
---|
281 | virtual void setResult();
|
---|
282 | protected:
|
---|
283 | boost::filesystem::path tmp;
|
---|
284 | };
|
---|
285 |
|
---|
286 | void registerQuery(Query* query);
|
---|
287 |
|
---|
288 | private:
|
---|
289 | std::list<Query*> queries;
|
---|
290 |
|
---|
291 | };
|
---|
292 |
|
---|
293 |
|
---|
294 | #endif /* DIALOG_HPP_ */
|
---|