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 | class atom;
|
---|
16 | class Box;
|
---|
17 | class element;
|
---|
18 | class molecule;
|
---|
19 | class Vector;
|
---|
20 |
|
---|
21 |
|
---|
22 | /** Dialog is one of the two main classes of the UIFactory base class.
|
---|
23 | *
|
---|
24 | * The Dialog is meant for asking the user for information needed to perform actions he
|
---|
25 | * desires, such as asking for a position in space or a length.
|
---|
26 | *
|
---|
27 | * For this purpose there is the base class Query and numerous specializations for each
|
---|
28 | * of the types to be asked. There are primitives integer, doubles and string, but also
|
---|
29 | * advanced types such as element, molecule or Vector. There is also an empty query for
|
---|
30 | * displaying text.
|
---|
31 | */
|
---|
32 | class Dialog
|
---|
33 | {
|
---|
34 | public:
|
---|
35 | Dialog();
|
---|
36 | virtual ~Dialog();
|
---|
37 |
|
---|
38 | virtual void queryEmpty(const char *, std::string = "")=0;
|
---|
39 | virtual void queryBoolean(const char *, bool *, std::string = "")=0;
|
---|
40 | virtual void queryInt(const char *, int *, std::string = "")=0;
|
---|
41 | virtual void queryDouble(const char*,double *, std::string = "")=0;
|
---|
42 | virtual void queryString(const char*, std::string *, std::string = "")=0;
|
---|
43 | virtual void queryAtom(const char*,atom**,std::string = "")=0;
|
---|
44 | virtual void queryMolecule(const char*,molecule**, std::string = "")=0;
|
---|
45 | virtual void queryVector(const char*,Vector *,bool, std::string = "")=0;
|
---|
46 | virtual void queryBox(const char*,Box*, std::string = "")=0;
|
---|
47 | virtual void queryElement(const char*, std::vector<element *> *, std::string = "")=0;
|
---|
48 |
|
---|
49 | virtual bool display();
|
---|
50 |
|
---|
51 | virtual bool checkAll();
|
---|
52 | virtual void setAll();
|
---|
53 |
|
---|
54 | protected:
|
---|
55 | // methodology for handling queries
|
---|
56 | // all queries are stored and then performed at appropriate times
|
---|
57 |
|
---|
58 | //these queries can be handled by this dialog
|
---|
59 |
|
---|
60 | //TODO: Find a way to reduce complexity...
|
---|
61 | //needs O(N*M) query classes, where N is the number of query types and M is the number of GUIs
|
---|
62 | //usual approach for reducing inheritance complexity (strategy pattern) does not work,
|
---|
63 | //due to lack of common code for query types as well as GUI-Types (all subtypes differ a lot)
|
---|
64 |
|
---|
65 | //base class for all queries
|
---|
66 | class Query {
|
---|
67 | friend class Dialog;
|
---|
68 | public:
|
---|
69 | Query(std::string _title, std::string _description = "");
|
---|
70 | virtual ~Query();
|
---|
71 | virtual bool handle()=0;
|
---|
72 | virtual void setResult()=0;
|
---|
73 | protected:
|
---|
74 | const std::string getTitle() const;
|
---|
75 | const std::string getDescription() const;
|
---|
76 | private:
|
---|
77 | std::string title; //!< short title of the query
|
---|
78 | std::string description; //!< longer description for tooltips or for help
|
---|
79 | };
|
---|
80 |
|
---|
81 | // Empty Query is just meant for showing text, such as version, help, initial message or alike
|
---|
82 | class EmptyQuery : public Query {
|
---|
83 | public:
|
---|
84 | EmptyQuery(std::string title, std::string _description = "");
|
---|
85 | virtual ~EmptyQuery();
|
---|
86 | virtual bool handle()=0;
|
---|
87 | virtual void setResult();
|
---|
88 | };
|
---|
89 |
|
---|
90 | //Specialized classes for certain types. GUI-Types are not specialized at this time
|
---|
91 | class BooleanQuery : public Query {
|
---|
92 | public:
|
---|
93 | BooleanQuery(std::string title,bool *_target, std::string _description = "");
|
---|
94 | virtual ~BooleanQuery();
|
---|
95 | virtual bool handle()=0;
|
---|
96 | virtual void setResult();
|
---|
97 | protected:
|
---|
98 | bool tmp;
|
---|
99 | private:
|
---|
100 | bool *target;
|
---|
101 | };
|
---|
102 |
|
---|
103 | class IntQuery : public Query {
|
---|
104 | public:
|
---|
105 | IntQuery(std::string title,int *_target, std::string _description = "");
|
---|
106 | virtual ~IntQuery();
|
---|
107 | virtual bool handle()=0;
|
---|
108 | virtual void setResult();
|
---|
109 | protected:
|
---|
110 | int tmp;
|
---|
111 | private:
|
---|
112 | int *target;
|
---|
113 | };
|
---|
114 |
|
---|
115 | class DoubleQuery : public Query {
|
---|
116 | public:
|
---|
117 | DoubleQuery(std::string title,double *_target, std::string _description = "");
|
---|
118 | virtual ~DoubleQuery();
|
---|
119 | virtual bool handle()=0;
|
---|
120 | virtual void setResult();
|
---|
121 | protected:
|
---|
122 | double tmp;
|
---|
123 | private:
|
---|
124 | double *target;
|
---|
125 | };
|
---|
126 |
|
---|
127 | class StringQuery : public Query {
|
---|
128 | public:
|
---|
129 | StringQuery(std::string title,std::string *_target, std::string _description = "");
|
---|
130 | virtual ~StringQuery();
|
---|
131 | virtual bool handle()=0;
|
---|
132 | virtual void setResult();
|
---|
133 | protected:
|
---|
134 | std::string tmp;
|
---|
135 | private:
|
---|
136 | std::string *target;
|
---|
137 | };
|
---|
138 |
|
---|
139 | class MoleculeQuery : public Query {
|
---|
140 | public:
|
---|
141 | MoleculeQuery(std::string title, molecule **_target, std::string _description = "");
|
---|
142 | virtual ~MoleculeQuery();
|
---|
143 | virtual bool handle()=0;
|
---|
144 | virtual void setResult();
|
---|
145 | protected:
|
---|
146 | molecule *tmp;
|
---|
147 | private:
|
---|
148 | molecule **target;
|
---|
149 | };
|
---|
150 |
|
---|
151 | class AtomQuery : public Query {
|
---|
152 | public:
|
---|
153 | AtomQuery(std::string title, atom **_target, std::string _description = "");
|
---|
154 | virtual ~AtomQuery();
|
---|
155 | virtual bool handle()=0;
|
---|
156 | virtual void setResult();
|
---|
157 | protected:
|
---|
158 | atom *tmp;
|
---|
159 | private:
|
---|
160 | atom **target;
|
---|
161 | };
|
---|
162 |
|
---|
163 | class VectorQuery : public Query {
|
---|
164 | public:
|
---|
165 | VectorQuery(std::string title,Vector *_target,bool _check, std::string _description = "");
|
---|
166 | virtual ~VectorQuery();
|
---|
167 | virtual bool handle()=0;
|
---|
168 | virtual void setResult();
|
---|
169 | protected:
|
---|
170 | Vector *tmp;
|
---|
171 | bool check;
|
---|
172 | private:
|
---|
173 | Vector *target;
|
---|
174 | };
|
---|
175 |
|
---|
176 | class BoxQuery : public Query {
|
---|
177 | public:
|
---|
178 | BoxQuery(std::string title,Box *_cellSize, std::string _description = "");
|
---|
179 | virtual ~BoxQuery();
|
---|
180 | virtual bool handle()=0;
|
---|
181 | virtual void setResult();
|
---|
182 | protected:
|
---|
183 | double* tmp;
|
---|
184 | private:
|
---|
185 | Box* target;
|
---|
186 | };
|
---|
187 |
|
---|
188 | class ElementQuery : public Query {
|
---|
189 | public:
|
---|
190 | ElementQuery(std::string title, std::vector<element *> *_target, std::string _description = "");
|
---|
191 | virtual ~ElementQuery();
|
---|
192 | virtual bool handle()=0;
|
---|
193 | virtual void setResult();
|
---|
194 | protected:
|
---|
195 | std::vector<element *> elements;
|
---|
196 | private:
|
---|
197 | std::vector<element *> * const target;
|
---|
198 | };
|
---|
199 |
|
---|
200 | void registerQuery(Query* query);
|
---|
201 |
|
---|
202 | private:
|
---|
203 | std::list<Query*> queries;
|
---|
204 |
|
---|
205 | };
|
---|
206 |
|
---|
207 |
|
---|
208 | #endif /* DIALOG_HPP_ */
|
---|