| 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 | virtual void queryEmpty(const char *, std::string = "")=0; | 
|---|
| 41 | virtual void queryBoolean(const char *, std::string = "")=0; | 
|---|
| 42 | virtual void queryInt(const char *, std::string = "")=0; | 
|---|
| 43 | virtual void queryInts(const char *, std::string = "")=0; | 
|---|
| 44 | virtual void queryDouble(const char*, std::string = "")=0; | 
|---|
| 45 | virtual void queryDoubles(const char*, std::string = "")=0; | 
|---|
| 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; | 
|---|
| 49 | virtual void queryAtoms(const char*,std::string = "")=0; | 
|---|
| 50 | virtual void queryMolecule(const char*, std::string = "")=0; | 
|---|
| 51 | virtual void queryMolecules(const char*, std::string = "")=0; | 
|---|
| 52 | virtual void queryVector(const char*,bool, std::string = "")=0; | 
|---|
| 53 | virtual void queryVectors(const char*,bool, std::string = "")=0; | 
|---|
| 54 | virtual void queryBox(const char*, std::string = "")=0; | 
|---|
| 55 | virtual void queryElement(const char*, std::string = "")=0; | 
|---|
| 56 | virtual void queryElements(const char*, std::string = "")=0; | 
|---|
| 57 |  | 
|---|
| 58 | virtual bool display(); | 
|---|
| 59 |  | 
|---|
| 60 | virtual bool checkAll(); | 
|---|
| 61 | virtual void setAll(); | 
|---|
| 62 |  | 
|---|
| 63 | virtual bool hasQueries(); | 
|---|
| 64 |  | 
|---|
| 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 | 
|---|
| 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 { | 
|---|
| 78 | friend class Dialog; | 
|---|
| 79 | public: | 
|---|
| 80 | Query(std::string _title, std::string _description = ""); | 
|---|
| 81 | virtual ~Query(); | 
|---|
| 82 | virtual bool handle()=0; | 
|---|
| 83 | virtual void setResult()=0; | 
|---|
| 84 | protected: | 
|---|
| 85 | const std::string getTitle() const; | 
|---|
| 86 | const std::string getDescription() const; | 
|---|
| 87 | private: | 
|---|
| 88 | std::string title;  //!< short title of the query | 
|---|
| 89 | std::string description; //!< longer description for tooltips or for help | 
|---|
| 90 | }; | 
|---|
| 91 |  | 
|---|
| 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(); | 
|---|
| 99 | }; | 
|---|
| 100 |  | 
|---|
| 101 | //Specialized classes for certain types. GUI-Types are not specialized at this time | 
|---|
| 102 | class BooleanQuery : public Query { | 
|---|
| 103 | public: | 
|---|
| 104 | BooleanQuery(std::string title, std::string _description = ""); | 
|---|
| 105 | virtual ~BooleanQuery(); | 
|---|
| 106 | virtual bool handle()=0; | 
|---|
| 107 | virtual void setResult(); | 
|---|
| 108 | protected: | 
|---|
| 109 | bool tmp; | 
|---|
| 110 | }; | 
|---|
| 111 |  | 
|---|
| 112 | class IntQuery : public Query { | 
|---|
| 113 | public: | 
|---|
| 114 | IntQuery(std::string title, std::string _description = ""); | 
|---|
| 115 | virtual ~IntQuery(); | 
|---|
| 116 | virtual bool handle()=0; | 
|---|
| 117 | virtual void setResult(); | 
|---|
| 118 | protected: | 
|---|
| 119 | int tmp; | 
|---|
| 120 | }; | 
|---|
| 121 |  | 
|---|
| 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 |  | 
|---|
| 133 | class DoubleQuery : public Query { | 
|---|
| 134 | public: | 
|---|
| 135 | DoubleQuery(std::string title, std::string _description = ""); | 
|---|
| 136 | virtual ~DoubleQuery(); | 
|---|
| 137 | virtual bool handle()=0; | 
|---|
| 138 | virtual void setResult(); | 
|---|
| 139 | protected: | 
|---|
| 140 | double tmp; | 
|---|
| 141 | }; | 
|---|
| 142 |  | 
|---|
| 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 |  | 
|---|
| 154 | class StringQuery : public Query { | 
|---|
| 155 | public: | 
|---|
| 156 | StringQuery(std::string title, std::string _description = ""); | 
|---|
| 157 | virtual ~StringQuery(); | 
|---|
| 158 | virtual bool handle()=0; | 
|---|
| 159 | virtual void setResult(); | 
|---|
| 160 | protected: | 
|---|
| 161 | std::string tmp; | 
|---|
| 162 | }; | 
|---|
| 163 |  | 
|---|
| 164 | class StringsQuery : public Query { | 
|---|
| 165 | public: | 
|---|
| 166 | StringsQuery(std::string title, std::string _description = ""); | 
|---|
| 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 |  | 
|---|
| 175 | class MoleculeQuery : public Query { | 
|---|
| 176 | public: | 
|---|
| 177 | MoleculeQuery(std::string title, std::string _description = ""); | 
|---|
| 178 | virtual ~MoleculeQuery(); | 
|---|
| 179 | virtual bool handle()=0; | 
|---|
| 180 | virtual void setResult(); | 
|---|
| 181 | protected: | 
|---|
| 182 | molecule *tmp; | 
|---|
| 183 | }; | 
|---|
| 184 |  | 
|---|
| 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 |  | 
|---|
| 196 | class AtomQuery : public Query { | 
|---|
| 197 | public: | 
|---|
| 198 | AtomQuery(std::string title, std::string _description = ""); | 
|---|
| 199 | virtual ~AtomQuery(); | 
|---|
| 200 | virtual bool handle()=0; | 
|---|
| 201 | virtual void setResult(); | 
|---|
| 202 | protected: | 
|---|
| 203 | atom *tmp; | 
|---|
| 204 | }; | 
|---|
| 205 |  | 
|---|
| 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 |  | 
|---|
| 217 | class VectorQuery : public Query { | 
|---|
| 218 | public: | 
|---|
| 219 | VectorQuery(std::string title,bool _check, std::string _description = ""); | 
|---|
| 220 | virtual ~VectorQuery(); | 
|---|
| 221 | virtual bool handle()=0; | 
|---|
| 222 | virtual void setResult(); | 
|---|
| 223 | protected: | 
|---|
| 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; | 
|---|
| 237 | bool check; | 
|---|
| 238 | }; | 
|---|
| 239 |  | 
|---|
| 240 | class BoxQuery : public Query { | 
|---|
| 241 | public: | 
|---|
| 242 | BoxQuery(std::string title, std::string _description = ""); | 
|---|
| 243 | virtual ~BoxQuery(); | 
|---|
| 244 | virtual bool handle()=0; | 
|---|
| 245 | virtual void setResult(); | 
|---|
| 246 | protected: | 
|---|
| 247 | Box tmp; | 
|---|
| 248 | }; | 
|---|
| 249 |  | 
|---|
| 250 | class ElementQuery : public Query { | 
|---|
| 251 | public: | 
|---|
| 252 | ElementQuery(std::string title, std::string _description = ""); | 
|---|
| 253 | virtual ~ElementQuery(); | 
|---|
| 254 | virtual bool handle()=0; | 
|---|
| 255 | virtual void setResult(); | 
|---|
| 256 | protected: | 
|---|
| 257 | const 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 | const element *temp; | 
|---|
| 268 | std::vector<const element *> tmp; | 
|---|
| 269 | }; | 
|---|
| 270 |  | 
|---|
| 271 | void registerQuery(Query* query); | 
|---|
| 272 |  | 
|---|
| 273 | private: | 
|---|
| 274 | std::list<Query*> queries; | 
|---|
| 275 |  | 
|---|
| 276 | }; | 
|---|
| 277 |  | 
|---|
| 278 |  | 
|---|
| 279 | #endif /* DIALOG_HPP_ */ | 
|---|