[f5a86a] | 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>
|
---|
[104524] | 13 | #include<vector>
|
---|
[f5a86a] | 14 |
|
---|
[8bc733] | 15 | #include "Box.hpp"
|
---|
[57f243] | 16 | #include "LinearAlgebra/Vector.hpp"
|
---|
[7cd6e7] | 17 |
|
---|
[97ebf8] | 18 | class atom;
|
---|
[84c494] | 19 | class Box;
|
---|
[97ebf8] | 20 | class element;
|
---|
[7aa000] | 21 | class molecule;
|
---|
[45f5d6] | 22 |
|
---|
[de8e45] | 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 | */
|
---|
[f5a86a] | 34 | class Dialog
|
---|
| 35 | {
|
---|
| 36 | public:
|
---|
| 37 | Dialog();
|
---|
| 38 | virtual ~Dialog();
|
---|
| 39 |
|
---|
[9ee38b] | 40 | template <class T> void query(const char *, std::string = "");
|
---|
| 41 |
|
---|
[86466e] | 42 | virtual void queryEmpty(const char *, std::string = "")=0;
|
---|
[75dc28] | 43 | virtual void queryBoolean(const char *, std::string = "")=0;
|
---|
| 44 | virtual void queryInt(const char *, std::string = "")=0;
|
---|
[7cd6e7] | 45 | virtual void queryInts(const char *, std::string = "")=0;
|
---|
[75dc28] | 46 | virtual void queryDouble(const char*, std::string = "")=0;
|
---|
[7cd6e7] | 47 | virtual void queryDoubles(const char*, std::string = "")=0;
|
---|
[75dc28] | 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;
|
---|
[7cd6e7] | 51 | virtual void queryAtoms(const char*,std::string = "")=0;
|
---|
[75dc28] | 52 | virtual void queryMolecule(const char*, std::string = "")=0;
|
---|
[7cd6e7] | 53 | virtual void queryMolecules(const char*, std::string = "")=0;
|
---|
[75dc28] | 54 | virtual void queryVector(const char*,bool, std::string = "")=0;
|
---|
[7cd6e7] | 55 | virtual void queryVectors(const char*,bool, std::string = "")=0;
|
---|
[75dc28] | 56 | virtual void queryBox(const char*, std::string = "")=0;
|
---|
| 57 | virtual void queryElement(const char*, std::string = "")=0;
|
---|
[7cd6e7] | 58 | virtual void queryElements(const char*, std::string = "")=0;
|
---|
[f5a86a] | 59 |
|
---|
[45f5d6] | 60 | virtual bool display();
|
---|
[f5a86a] | 61 |
|
---|
[d3a5ea] | 62 | virtual bool checkAll();
|
---|
| 63 | virtual void setAll();
|
---|
| 64 |
|
---|
[c508ef5] | 65 | virtual bool hasQueries();
|
---|
| 66 |
|
---|
[f5a86a] | 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
|
---|
[45f5d6] | 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 {
|
---|
[94d131] | 80 | friend class Dialog;
|
---|
[45f5d6] | 81 | public:
|
---|
[a2ab15] | 82 | Query(std::string _title, std::string _description = "");
|
---|
[5a7243] | 83 | virtual ~Query();
|
---|
[45f5d6] | 84 | virtual bool handle()=0;
|
---|
| 85 | virtual void setResult()=0;
|
---|
| 86 | protected:
|
---|
| 87 | const std::string getTitle() const;
|
---|
[a2ab15] | 88 | const std::string getDescription() const;
|
---|
[45f5d6] | 89 | private:
|
---|
[a2ab15] | 90 | std::string title; //!< short title of the query
|
---|
| 91 | std::string description; //!< longer description for tooltips or for help
|
---|
[f5a86a] | 92 | };
|
---|
| 93 |
|
---|
[86466e] | 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();
|
---|
[f5a86a] | 101 | };
|
---|
| 102 |
|
---|
[45f5d6] | 103 | //Specialized classes for certain types. GUI-Types are not specialized at this time
|
---|
[97ebf8] | 104 | class BooleanQuery : public Query {
|
---|
| 105 | public:
|
---|
[75dc28] | 106 | BooleanQuery(std::string title, std::string _description = "");
|
---|
[97ebf8] | 107 | virtual ~BooleanQuery();
|
---|
| 108 | virtual bool handle()=0;
|
---|
| 109 | virtual void setResult();
|
---|
| 110 | protected:
|
---|
| 111 | bool tmp;
|
---|
| 112 | };
|
---|
| 113 |
|
---|
[45f5d6] | 114 | class IntQuery : public Query {
|
---|
| 115 | public:
|
---|
[75dc28] | 116 | IntQuery(std::string title, std::string _description = "");
|
---|
[5a7243] | 117 | virtual ~IntQuery();
|
---|
[45f5d6] | 118 | virtual bool handle()=0;
|
---|
| 119 | virtual void setResult();
|
---|
| 120 | protected:
|
---|
| 121 | int tmp;
|
---|
| 122 | };
|
---|
| 123 |
|
---|
[7cd6e7] | 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 |
|
---|
[2ededc2] | 135 | class DoubleQuery : public Query {
|
---|
| 136 | public:
|
---|
[75dc28] | 137 | DoubleQuery(std::string title, std::string _description = "");
|
---|
[5a7243] | 138 | virtual ~DoubleQuery();
|
---|
[2ededc2] | 139 | virtual bool handle()=0;
|
---|
| 140 | virtual void setResult();
|
---|
| 141 | protected:
|
---|
| 142 | double tmp;
|
---|
| 143 | };
|
---|
| 144 |
|
---|
[7cd6e7] | 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 |
|
---|
[45f5d6] | 156 | class StringQuery : public Query {
|
---|
| 157 | public:
|
---|
[75dc28] | 158 | StringQuery(std::string title, std::string _description = "");
|
---|
[5a7243] | 159 | virtual ~StringQuery();
|
---|
[45f5d6] | 160 | virtual bool handle()=0;
|
---|
| 161 | virtual void setResult();
|
---|
| 162 | protected:
|
---|
| 163 | std::string tmp;
|
---|
| 164 | };
|
---|
| 165 |
|
---|
[cd8e55] | 166 | class StringsQuery : public Query {
|
---|
| 167 | public:
|
---|
[75dc28] | 168 | StringsQuery(std::string title, std::string _description = "");
|
---|
[cd8e55] | 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 |
|
---|
[7aa000] | 177 | class MoleculeQuery : public Query {
|
---|
| 178 | public:
|
---|
[75dc28] | 179 | MoleculeQuery(std::string title, std::string _description = "");
|
---|
[5a7243] | 180 | virtual ~MoleculeQuery();
|
---|
[7aa000] | 181 | virtual bool handle()=0;
|
---|
| 182 | virtual void setResult();
|
---|
| 183 | protected:
|
---|
| 184 | molecule *tmp;
|
---|
| 185 | };
|
---|
| 186 |
|
---|
[7cd6e7] | 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 |
|
---|
[97ebf8] | 198 | class AtomQuery : public Query {
|
---|
| 199 | public:
|
---|
[75dc28] | 200 | AtomQuery(std::string title, std::string _description = "");
|
---|
[97ebf8] | 201 | virtual ~AtomQuery();
|
---|
| 202 | virtual bool handle()=0;
|
---|
| 203 | virtual void setResult();
|
---|
| 204 | protected:
|
---|
| 205 | atom *tmp;
|
---|
| 206 | };
|
---|
| 207 |
|
---|
[7cd6e7] | 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 |
|
---|
[2ededc2] | 219 | class VectorQuery : public Query {
|
---|
| 220 | public:
|
---|
[75dc28] | 221 | VectorQuery(std::string title,bool _check, std::string _description = "");
|
---|
[5a7243] | 222 | virtual ~VectorQuery();
|
---|
[2ededc2] | 223 | virtual bool handle()=0;
|
---|
| 224 | virtual void setResult();
|
---|
| 225 | protected:
|
---|
[7cd6e7] | 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;
|
---|
[2ededc2] | 239 | bool check;
|
---|
| 240 | };
|
---|
| 241 |
|
---|
[97ebf8] | 242 | class BoxQuery : public Query {
|
---|
| 243 | public:
|
---|
[75dc28] | 244 | BoxQuery(std::string title, std::string _description = "");
|
---|
[97ebf8] | 245 | virtual ~BoxQuery();
|
---|
| 246 | virtual bool handle()=0;
|
---|
| 247 | virtual void setResult();
|
---|
| 248 | protected:
|
---|
[8bc733] | 249 | Box tmp;
|
---|
[97ebf8] | 250 | };
|
---|
| 251 |
|
---|
[5a7243] | 252 | class ElementQuery : public Query {
|
---|
| 253 | public:
|
---|
[75dc28] | 254 | ElementQuery(std::string title, std::string _description = "");
|
---|
[5a7243] | 255 | virtual ~ElementQuery();
|
---|
| 256 | virtual bool handle()=0;
|
---|
| 257 | virtual void setResult();
|
---|
| 258 | protected:
|
---|
[e5c0a1] | 259 | const element * tmp;
|
---|
[7cd6e7] | 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:
|
---|
[e5c0a1] | 269 | const element *temp;
|
---|
| 270 | std::vector<const element *> tmp;
|
---|
[5a7243] | 271 | };
|
---|
| 272 |
|
---|
[45f5d6] | 273 | void registerQuery(Query* query);
|
---|
| 274 |
|
---|
| 275 | private:
|
---|
| 276 | std::list<Query*> queries;
|
---|
[f5a86a] | 277 |
|
---|
| 278 | };
|
---|
| 279 |
|
---|
[a2ab15] | 280 |
|
---|
[f5a86a] | 281 | #endif /* DIALOG_HPP_ */
|
---|