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