| [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 |  | 
|---|
| [97ebf8] | 15 | class atom; | 
|---|
| [84c494] | 16 | class Box; | 
|---|
| [97ebf8] | 17 | class element; | 
|---|
| [7aa000] | 18 | class molecule; | 
|---|
| [2ededc2] | 19 | class Vector; | 
|---|
| [45f5d6] | 20 |  | 
|---|
| [de8e45] | 21 |  | 
|---|
|  | 22 | /** Dialog is one of the two main classes of the UIFactory base class. | 
|---|
|  | 23 | * | 
|---|
|  | 24 | * The Dialog is meant for asking the user for information needed to perform actions he | 
|---|
|  | 25 | * desires, such as asking for a position in space or a length. | 
|---|
|  | 26 | * | 
|---|
|  | 27 | * For this purpose there is the base class Query and numerous specializations for each | 
|---|
|  | 28 | * of the types to be asked. There are primitives integer, doubles and string, but also | 
|---|
|  | 29 | * advanced types such as element, molecule or Vector. There is also an empty query for | 
|---|
|  | 30 | * displaying text. | 
|---|
|  | 31 | */ | 
|---|
| [f5a86a] | 32 | class Dialog | 
|---|
|  | 33 | { | 
|---|
|  | 34 | public: | 
|---|
|  | 35 | Dialog(); | 
|---|
|  | 36 | virtual ~Dialog(); | 
|---|
|  | 37 |  | 
|---|
| [86466e] | 38 | virtual void queryEmpty(const char *, std::string = "")=0; | 
|---|
| [97ebf8] | 39 | virtual void queryBoolean(const char *, bool *, std::string = "")=0; | 
|---|
| [a2ab15] | 40 | virtual void queryInt(const char *, int *, std::string = "")=0; | 
|---|
|  | 41 | virtual void queryDouble(const char*,double *, std::string = "")=0; | 
|---|
|  | 42 | virtual void queryString(const char*, std::string *, std::string = "")=0; | 
|---|
| [97ebf8] | 43 | virtual void queryAtom(const char*,atom**,std::string = "")=0; | 
|---|
|  | 44 | virtual void queryMolecule(const char*,molecule**, std::string = "")=0; | 
|---|
| [84c494] | 45 | virtual void queryVector(const char*,Vector *,bool, std::string = "")=0; | 
|---|
|  | 46 | virtual void queryBox(const char*,Box*, std::string = "")=0; | 
|---|
| [104524] | 47 | virtual void queryElement(const char*, std::vector<element *> *, std::string = "")=0; | 
|---|
| [f5a86a] | 48 |  | 
|---|
| [45f5d6] | 49 | virtual bool display(); | 
|---|
| [f5a86a] | 50 |  | 
|---|
| [d3a5ea] | 51 | virtual bool checkAll(); | 
|---|
|  | 52 | virtual void setAll(); | 
|---|
|  | 53 |  | 
|---|
| [f5a86a] | 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 | 
|---|
| [45f5d6] | 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 { | 
|---|
| [94d131] | 67 | friend class Dialog; | 
|---|
| [45f5d6] | 68 | public: | 
|---|
| [a2ab15] | 69 | Query(std::string _title, std::string _description = ""); | 
|---|
| [5a7243] | 70 | virtual ~Query(); | 
|---|
| [45f5d6] | 71 | virtual bool handle()=0; | 
|---|
|  | 72 | virtual void setResult()=0; | 
|---|
|  | 73 | protected: | 
|---|
|  | 74 | const std::string getTitle() const; | 
|---|
| [a2ab15] | 75 | const std::string getDescription() const; | 
|---|
| [45f5d6] | 76 | private: | 
|---|
| [a2ab15] | 77 | std::string title;  //!< short title of the query | 
|---|
|  | 78 | std::string description; //!< longer description for tooltips or for help | 
|---|
| [f5a86a] | 79 | }; | 
|---|
|  | 80 |  | 
|---|
| [86466e] | 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(); | 
|---|
| [f5a86a] | 88 | }; | 
|---|
|  | 89 |  | 
|---|
| [45f5d6] | 90 | //Specialized classes for certain types. GUI-Types are not specialized at this time | 
|---|
| [97ebf8] | 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 |  | 
|---|
| [45f5d6] | 103 | class IntQuery : public Query { | 
|---|
|  | 104 | public: | 
|---|
| [a2ab15] | 105 | IntQuery(std::string title,int *_target, std::string _description = ""); | 
|---|
| [5a7243] | 106 | virtual ~IntQuery(); | 
|---|
| [45f5d6] | 107 | virtual bool handle()=0; | 
|---|
|  | 108 | virtual void setResult(); | 
|---|
|  | 109 | protected: | 
|---|
|  | 110 | int tmp; | 
|---|
|  | 111 | private: | 
|---|
|  | 112 | int *target; | 
|---|
|  | 113 | }; | 
|---|
|  | 114 |  | 
|---|
| [2ededc2] | 115 | class DoubleQuery : public Query { | 
|---|
|  | 116 | public: | 
|---|
| [a2ab15] | 117 | DoubleQuery(std::string title,double *_target, std::string _description = ""); | 
|---|
| [5a7243] | 118 | virtual ~DoubleQuery(); | 
|---|
| [2ededc2] | 119 | virtual bool handle()=0; | 
|---|
|  | 120 | virtual void setResult(); | 
|---|
|  | 121 | protected: | 
|---|
|  | 122 | double tmp; | 
|---|
|  | 123 | private: | 
|---|
|  | 124 | double *target; | 
|---|
|  | 125 | }; | 
|---|
|  | 126 |  | 
|---|
| [45f5d6] | 127 | class StringQuery : public Query { | 
|---|
|  | 128 | public: | 
|---|
| [a2ab15] | 129 | StringQuery(std::string title,std::string *_target, std::string _description = ""); | 
|---|
| [5a7243] | 130 | virtual ~StringQuery(); | 
|---|
| [45f5d6] | 131 | virtual bool handle()=0; | 
|---|
|  | 132 | virtual void setResult(); | 
|---|
|  | 133 | protected: | 
|---|
|  | 134 | std::string tmp; | 
|---|
|  | 135 | private: | 
|---|
|  | 136 | std::string *target; | 
|---|
|  | 137 | }; | 
|---|
|  | 138 |  | 
|---|
| [7aa000] | 139 | class MoleculeQuery : public Query { | 
|---|
|  | 140 | public: | 
|---|
| [97ebf8] | 141 | MoleculeQuery(std::string title, molecule **_target, std::string _description = ""); | 
|---|
| [5a7243] | 142 | virtual ~MoleculeQuery(); | 
|---|
| [7aa000] | 143 | virtual bool handle()=0; | 
|---|
|  | 144 | virtual void setResult(); | 
|---|
|  | 145 | protected: | 
|---|
|  | 146 | molecule *tmp; | 
|---|
|  | 147 | private: | 
|---|
|  | 148 | molecule **target; | 
|---|
|  | 149 | }; | 
|---|
|  | 150 |  | 
|---|
| [97ebf8] | 151 | class AtomQuery : public Query { | 
|---|
|  | 152 | public: | 
|---|
|  | 153 | AtomQuery(std::string title, atom **_target, std::string _description = ""); | 
|---|
|  | 154 | virtual ~AtomQuery(); | 
|---|
|  | 155 | virtual bool handle()=0; | 
|---|
|  | 156 | virtual void setResult(); | 
|---|
|  | 157 | protected: | 
|---|
|  | 158 | atom *tmp; | 
|---|
|  | 159 | private: | 
|---|
|  | 160 | atom **target; | 
|---|
|  | 161 | }; | 
|---|
|  | 162 |  | 
|---|
| [2ededc2] | 163 | class VectorQuery : public Query { | 
|---|
|  | 164 | public: | 
|---|
| [84c494] | 165 | VectorQuery(std::string title,Vector *_target,bool _check, std::string _description = ""); | 
|---|
| [5a7243] | 166 | virtual ~VectorQuery(); | 
|---|
| [2ededc2] | 167 | virtual bool handle()=0; | 
|---|
|  | 168 | virtual void setResult(); | 
|---|
|  | 169 | protected: | 
|---|
|  | 170 | Vector *tmp; | 
|---|
|  | 171 | bool check; | 
|---|
|  | 172 | private: | 
|---|
|  | 173 | Vector *target; | 
|---|
|  | 174 | }; | 
|---|
|  | 175 |  | 
|---|
| [97ebf8] | 176 | class BoxQuery : public Query { | 
|---|
|  | 177 | public: | 
|---|
| [84c494] | 178 | BoxQuery(std::string title,Box *_cellSize, std::string _description = ""); | 
|---|
| [97ebf8] | 179 | virtual ~BoxQuery(); | 
|---|
|  | 180 | virtual bool handle()=0; | 
|---|
|  | 181 | virtual void setResult(); | 
|---|
|  | 182 | protected: | 
|---|
| [84c494] | 183 | double* tmp; | 
|---|
| [97ebf8] | 184 | private: | 
|---|
| [84c494] | 185 | Box* target; | 
|---|
| [97ebf8] | 186 | }; | 
|---|
|  | 187 |  | 
|---|
| [5a7243] | 188 | class ElementQuery : public Query { | 
|---|
|  | 189 | public: | 
|---|
| [104524] | 190 | ElementQuery(std::string title, std::vector<element *> *_target, std::string _description = ""); | 
|---|
| [5a7243] | 191 | virtual ~ElementQuery(); | 
|---|
|  | 192 | virtual bool handle()=0; | 
|---|
|  | 193 | virtual void setResult(); | 
|---|
|  | 194 | protected: | 
|---|
| [104524] | 195 | std::vector<element *> elements; | 
|---|
| [5a7243] | 196 | private: | 
|---|
| [104524] | 197 | std::vector<element *> * const target; | 
|---|
| [5a7243] | 198 | }; | 
|---|
|  | 199 |  | 
|---|
| [45f5d6] | 200 | void registerQuery(Query* query); | 
|---|
|  | 201 |  | 
|---|
|  | 202 | private: | 
|---|
|  | 203 | std::list<Query*> queries; | 
|---|
| [f5a86a] | 204 |  | 
|---|
|  | 205 | }; | 
|---|
|  | 206 |  | 
|---|
| [a2ab15] | 207 |  | 
|---|
| [f5a86a] | 208 | #endif /* DIALOG_HPP_ */ | 
|---|