| 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 element; | 
|---|
| 17 | class molecule; | 
|---|
| 18 | class Vector; | 
|---|
| 19 |  | 
|---|
| 20 |  | 
|---|
| 21 | /** Dialog is one of the two main classes of the UIFactory base class. | 
|---|
| 22 | * | 
|---|
| 23 | * The Dialog is meant for asking the user for information needed to perform actions he | 
|---|
| 24 | * desires, such as asking for a position in space or a length. | 
|---|
| 25 | * | 
|---|
| 26 | * For this purpose there is the base class Query and numerous specializations for each | 
|---|
| 27 | * of the types to be asked. There are primitives integer, doubles and string, but also | 
|---|
| 28 | * advanced types such as element, molecule or Vector. There is also an empty query for | 
|---|
| 29 | * displaying text. | 
|---|
| 30 | */ | 
|---|
| 31 | class Dialog | 
|---|
| 32 | { | 
|---|
| 33 | public: | 
|---|
| 34 | Dialog(); | 
|---|
| 35 | virtual ~Dialog(); | 
|---|
| 36 |  | 
|---|
| 37 | virtual void queryEmpty(const char *, std::string = "")=0; | 
|---|
| 38 | virtual void queryBoolean(const char *, bool *, std::string = "")=0; | 
|---|
| 39 | virtual void queryInt(const char *, int *, std::string = "")=0; | 
|---|
| 40 | virtual void queryDouble(const char*,double *, std::string = "")=0; | 
|---|
| 41 | virtual void queryString(const char*, std::string *, std::string = "")=0; | 
|---|
| 42 | virtual void queryStrings(const char*, std::vector<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 *,const double *const,bool, std::string = "")=0; | 
|---|
| 46 | virtual void queryBox(const char*,double ** const, 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 StringsQuery : public Query { | 
|---|
| 140 | public: | 
|---|
| 141 | StringsQuery(std::string title,std::vector<std::string> *_target, std::string _description = ""); | 
|---|
| 142 | virtual ~StringsQuery(); | 
|---|
| 143 | virtual bool handle()=0; | 
|---|
| 144 | virtual void setResult(); | 
|---|
| 145 | protected: | 
|---|
| 146 | std::string temp; | 
|---|
| 147 | std::vector<std::string> tmp; | 
|---|
| 148 | private: | 
|---|
| 149 | std::vector<std::string> *target; | 
|---|
| 150 | }; | 
|---|
| 151 |  | 
|---|
| 152 | class MoleculeQuery : public Query { | 
|---|
| 153 | public: | 
|---|
| 154 | MoleculeQuery(std::string title, molecule **_target, std::string _description = ""); | 
|---|
| 155 | virtual ~MoleculeQuery(); | 
|---|
| 156 | virtual bool handle()=0; | 
|---|
| 157 | virtual void setResult(); | 
|---|
| 158 | protected: | 
|---|
| 159 | molecule *tmp; | 
|---|
| 160 | private: | 
|---|
| 161 | molecule **target; | 
|---|
| 162 | }; | 
|---|
| 163 |  | 
|---|
| 164 | class AtomQuery : public Query { | 
|---|
| 165 | public: | 
|---|
| 166 | AtomQuery(std::string title, atom **_target, std::string _description = ""); | 
|---|
| 167 | virtual ~AtomQuery(); | 
|---|
| 168 | virtual bool handle()=0; | 
|---|
| 169 | virtual void setResult(); | 
|---|
| 170 | protected: | 
|---|
| 171 | atom *tmp; | 
|---|
| 172 | private: | 
|---|
| 173 | atom **target; | 
|---|
| 174 | }; | 
|---|
| 175 |  | 
|---|
| 176 | class VectorQuery : public Query { | 
|---|
| 177 | public: | 
|---|
| 178 | VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check, std::string _description = ""); | 
|---|
| 179 | virtual ~VectorQuery(); | 
|---|
| 180 | virtual bool handle()=0; | 
|---|
| 181 | virtual void setResult(); | 
|---|
| 182 | protected: | 
|---|
| 183 | Vector *tmp; | 
|---|
| 184 | const double *const cellSize; | 
|---|
| 185 | bool check; | 
|---|
| 186 | private: | 
|---|
| 187 | Vector *target; | 
|---|
| 188 | }; | 
|---|
| 189 |  | 
|---|
| 190 | class BoxQuery : public Query { | 
|---|
| 191 | public: | 
|---|
| 192 | BoxQuery(std::string title,double ** const _cellSize, std::string _description = ""); | 
|---|
| 193 | virtual ~BoxQuery(); | 
|---|
| 194 | virtual bool handle()=0; | 
|---|
| 195 | virtual void setResult(); | 
|---|
| 196 | protected: | 
|---|
| 197 | double *tmp; | 
|---|
| 198 | private: | 
|---|
| 199 | double **target; | 
|---|
| 200 | }; | 
|---|
| 201 |  | 
|---|
| 202 | class ElementQuery : public Query { | 
|---|
| 203 | public: | 
|---|
| 204 | ElementQuery(std::string title, std::vector<element *> *_target, std::string _description = ""); | 
|---|
| 205 | virtual ~ElementQuery(); | 
|---|
| 206 | virtual bool handle()=0; | 
|---|
| 207 | virtual void setResult(); | 
|---|
| 208 | protected: | 
|---|
| 209 | std::vector<element *> elements; | 
|---|
| 210 | private: | 
|---|
| 211 | std::vector<element *> * const target; | 
|---|
| 212 | }; | 
|---|
| 213 |  | 
|---|
| 214 | void registerQuery(Query* query); | 
|---|
| 215 |  | 
|---|
| 216 | private: | 
|---|
| 217 | std::list<Query*> queries; | 
|---|
| 218 |  | 
|---|
| 219 | }; | 
|---|
| 220 |  | 
|---|
| 221 |  | 
|---|
| 222 | #endif /* DIALOG_HPP_ */ | 
|---|