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