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