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