[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 | *
|
---|
[db7cb0] | 28 | * The Dialog is meant for asking the user for information needed to perform
|
---|
| 29 | * actions he desires, such as asking for a position in space or a length.
|
---|
[de8e45] | 30 | *
|
---|
[db7cb0] | 31 | * For this purpose there is the base class Query and numerous specializations
|
---|
| 32 | * for each of the types to be asked. There are primitives integer, doubles and
|
---|
| 33 | * string, but also advanced types such as element, molecule or Vector. There
|
---|
| 34 | * is also an empty query for displaying text.
|
---|
[de8e45] | 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 |
|
---|
[db7cb0] | 81 | /** Base class for all queries.
|
---|
| 82 | *
|
---|
| 83 | *
|
---|
| 84 | * <h1>How to add another query?</h1>
|
---|
| 85 | *
|
---|
| 86 | * Let's say we want to query for a type called \a Value.
|
---|
| 87 | *
|
---|
| 88 | * Then, we do the following:
|
---|
| 89 | * -# Add a class ValueQuery inside class Dialog, the class contains
|
---|
| 90 | * -# constructor/destructor (latter virtual! because of derived class)
|
---|
| 91 | * -# virtual bool handle() and virtual void setResult()
|
---|
| 92 | * -# a protected member tmp of type Value (NOTE: herein the result is stored)
|
---|
| 93 | * -# if temporaries for conversion are needed put them in here
|
---|
| 94 | * -# add a function queryValue
|
---|
| 95 | * -# now, for each of the GUIs we basically have to repeat the above, i.e.
|
---|
| 96 | * add the class and the function that implement the virtual ones above.
|
---|
[4cf323d] | 97 | * -# QT: an extra class called ValueQtQueryPipe that actually handles
|
---|
[db7cb0] | 98 | * showing dialogs to obtain the value and placing it into the \a tmp
|
---|
| 99 | * variable (via a given pointer to it as reference). handle() will
|
---|
[4cf323d] | 100 | * simply return true. This is needed because of a restriction of Qt4:
|
---|
[db7cb0] | 101 | * its meta-object-compiler does not like nested classes.
|
---|
| 102 | * -# CommandLine: nothing special, handle() imports value from \a
|
---|
| 103 | * CommandLineParser and sets the tmp variable.
|
---|
| 104 | * -# Text: nothing special, handle() queries the user and sets the tmp
|
---|
| 105 | * variable
|
---|
| 106 | */
|
---|
[45f5d6] | 107 | class Query {
|
---|
[94d131] | 108 | friend class Dialog;
|
---|
[45f5d6] | 109 | public:
|
---|
[a2ab15] | 110 | Query(std::string _title, std::string _description = "");
|
---|
[5a7243] | 111 | virtual ~Query();
|
---|
[45f5d6] | 112 | virtual bool handle()=0;
|
---|
| 113 | virtual void setResult()=0;
|
---|
| 114 | protected:
|
---|
| 115 | const std::string getTitle() const;
|
---|
[a2ab15] | 116 | const std::string getDescription() const;
|
---|
[45f5d6] | 117 | private:
|
---|
[a2ab15] | 118 | std::string title; //!< short title of the query
|
---|
| 119 | std::string description; //!< longer description for tooltips or for help
|
---|
[f5a86a] | 120 | };
|
---|
| 121 |
|
---|
[86466e] | 122 | // Empty Query is just meant for showing text, such as version, help, initial message or alike
|
---|
| 123 | class EmptyQuery : public Query {
|
---|
| 124 | public:
|
---|
| 125 | EmptyQuery(std::string title, std::string _description = "");
|
---|
| 126 | virtual ~EmptyQuery();
|
---|
| 127 | virtual bool handle()=0;
|
---|
| 128 | virtual void setResult();
|
---|
[f5a86a] | 129 | };
|
---|
| 130 |
|
---|
[45f5d6] | 131 | //Specialized classes for certain types. GUI-Types are not specialized at this time
|
---|
[97ebf8] | 132 | class BooleanQuery : public Query {
|
---|
| 133 | public:
|
---|
[75dc28] | 134 | BooleanQuery(std::string title, std::string _description = "");
|
---|
[97ebf8] | 135 | virtual ~BooleanQuery();
|
---|
| 136 | virtual bool handle()=0;
|
---|
| 137 | virtual void setResult();
|
---|
| 138 | protected:
|
---|
| 139 | bool tmp;
|
---|
| 140 | };
|
---|
| 141 |
|
---|
[45f5d6] | 142 | class IntQuery : public Query {
|
---|
| 143 | public:
|
---|
[75dc28] | 144 | IntQuery(std::string title, std::string _description = "");
|
---|
[5a7243] | 145 | virtual ~IntQuery();
|
---|
[45f5d6] | 146 | virtual bool handle()=0;
|
---|
| 147 | virtual void setResult();
|
---|
| 148 | protected:
|
---|
| 149 | int tmp;
|
---|
| 150 | };
|
---|
| 151 |
|
---|
[7cd6e7] | 152 | class IntsQuery : public Query {
|
---|
| 153 | public:
|
---|
| 154 | IntsQuery(std::string title, std::string _description = "");
|
---|
| 155 | virtual ~IntsQuery();
|
---|
| 156 | virtual bool handle()=0;
|
---|
| 157 | virtual void setResult();
|
---|
| 158 | protected:
|
---|
| 159 | int temp;
|
---|
| 160 | std::vector<int> tmp;
|
---|
| 161 | };
|
---|
| 162 |
|
---|
[2ededc2] | 163 | class DoubleQuery : public Query {
|
---|
| 164 | public:
|
---|
[75dc28] | 165 | DoubleQuery(std::string title, std::string _description = "");
|
---|
[5a7243] | 166 | virtual ~DoubleQuery();
|
---|
[2ededc2] | 167 | virtual bool handle()=0;
|
---|
| 168 | virtual void setResult();
|
---|
| 169 | protected:
|
---|
| 170 | double tmp;
|
---|
| 171 | };
|
---|
| 172 |
|
---|
[7cd6e7] | 173 | class DoublesQuery : public Query {
|
---|
| 174 | public:
|
---|
| 175 | DoublesQuery(std::string title, std::string _description = "");
|
---|
| 176 | virtual ~DoublesQuery();
|
---|
| 177 | virtual bool handle()=0;
|
---|
| 178 | virtual void setResult();
|
---|
| 179 | protected:
|
---|
| 180 | double temp;
|
---|
| 181 | std::vector<double> tmp;
|
---|
| 182 | };
|
---|
| 183 |
|
---|
[45f5d6] | 184 | class StringQuery : public Query {
|
---|
| 185 | public:
|
---|
[75dc28] | 186 | StringQuery(std::string title, std::string _description = "");
|
---|
[5a7243] | 187 | virtual ~StringQuery();
|
---|
[45f5d6] | 188 | virtual bool handle()=0;
|
---|
| 189 | virtual void setResult();
|
---|
| 190 | protected:
|
---|
| 191 | std::string tmp;
|
---|
| 192 | };
|
---|
| 193 |
|
---|
[cd8e55] | 194 | class StringsQuery : public Query {
|
---|
| 195 | public:
|
---|
[75dc28] | 196 | StringsQuery(std::string title, std::string _description = "");
|
---|
[cd8e55] | 197 | virtual ~StringsQuery();
|
---|
| 198 | virtual bool handle()=0;
|
---|
| 199 | virtual void setResult();
|
---|
| 200 | protected:
|
---|
| 201 | std::string temp;
|
---|
| 202 | std::vector<std::string> tmp;
|
---|
| 203 | };
|
---|
| 204 |
|
---|
[7aa000] | 205 | class MoleculeQuery : public Query {
|
---|
| 206 | public:
|
---|
[75dc28] | 207 | MoleculeQuery(std::string title, std::string _description = "");
|
---|
[5a7243] | 208 | virtual ~MoleculeQuery();
|
---|
[7aa000] | 209 | virtual bool handle()=0;
|
---|
| 210 | virtual void setResult();
|
---|
| 211 | protected:
|
---|
| 212 | molecule *tmp;
|
---|
| 213 | };
|
---|
| 214 |
|
---|
[7cd6e7] | 215 | class MoleculesQuery : public Query {
|
---|
| 216 | public:
|
---|
| 217 | MoleculesQuery(std::string title, std::string _description = "");
|
---|
| 218 | virtual ~MoleculesQuery();
|
---|
| 219 | virtual bool handle()=0;
|
---|
| 220 | virtual void setResult();
|
---|
| 221 | protected:
|
---|
| 222 | molecule * temp;
|
---|
| 223 | std::vector<molecule *> tmp;
|
---|
| 224 | };
|
---|
| 225 |
|
---|
[97ebf8] | 226 | class AtomQuery : public Query {
|
---|
| 227 | public:
|
---|
[75dc28] | 228 | AtomQuery(std::string title, std::string _description = "");
|
---|
[97ebf8] | 229 | virtual ~AtomQuery();
|
---|
| 230 | virtual bool handle()=0;
|
---|
| 231 | virtual void setResult();
|
---|
| 232 | protected:
|
---|
| 233 | atom *tmp;
|
---|
| 234 | };
|
---|
| 235 |
|
---|
[7cd6e7] | 236 | class AtomsQuery : public Query {
|
---|
| 237 | public:
|
---|
| 238 | AtomsQuery(std::string title, std::string _description = "");
|
---|
| 239 | virtual ~AtomsQuery();
|
---|
| 240 | virtual bool handle()=0;
|
---|
| 241 | virtual void setResult();
|
---|
| 242 | protected:
|
---|
| 243 | atom *temp;
|
---|
| 244 | std::vector<atom *> tmp;
|
---|
| 245 | };
|
---|
| 246 |
|
---|
[2ededc2] | 247 | class VectorQuery : public Query {
|
---|
| 248 | public:
|
---|
[75dc28] | 249 | VectorQuery(std::string title,bool _check, std::string _description = "");
|
---|
[5a7243] | 250 | virtual ~VectorQuery();
|
---|
[2ededc2] | 251 | virtual bool handle()=0;
|
---|
| 252 | virtual void setResult();
|
---|
| 253 | protected:
|
---|
[7cd6e7] | 254 | Vector tmp;
|
---|
| 255 | bool check;
|
---|
| 256 | };
|
---|
| 257 |
|
---|
| 258 | class VectorsQuery : public Query {
|
---|
| 259 | public:
|
---|
| 260 | VectorsQuery(std::string title,bool _check, std::string _description = "");
|
---|
| 261 | virtual ~VectorsQuery();
|
---|
| 262 | virtual bool handle()=0;
|
---|
| 263 | virtual void setResult();
|
---|
| 264 | protected:
|
---|
| 265 | Vector temp;
|
---|
| 266 | std::vector<Vector> tmp;
|
---|
[2ededc2] | 267 | bool check;
|
---|
| 268 | };
|
---|
| 269 |
|
---|
[97ebf8] | 270 | class BoxQuery : public Query {
|
---|
| 271 | public:
|
---|
[75dc28] | 272 | BoxQuery(std::string title, std::string _description = "");
|
---|
[97ebf8] | 273 | virtual ~BoxQuery();
|
---|
| 274 | virtual bool handle()=0;
|
---|
| 275 | virtual void setResult();
|
---|
| 276 | protected:
|
---|
[8bc733] | 277 | Box tmp;
|
---|
[97ebf8] | 278 | };
|
---|
| 279 |
|
---|
[5a7243] | 280 | class ElementQuery : public Query {
|
---|
| 281 | public:
|
---|
[75dc28] | 282 | ElementQuery(std::string title, std::string _description = "");
|
---|
[5a7243] | 283 | virtual ~ElementQuery();
|
---|
| 284 | virtual bool handle()=0;
|
---|
| 285 | virtual void setResult();
|
---|
| 286 | protected:
|
---|
[e5c0a1] | 287 | const element * tmp;
|
---|
[7cd6e7] | 288 | };
|
---|
| 289 |
|
---|
| 290 | class ElementsQuery : public Query {
|
---|
| 291 | public:
|
---|
| 292 | ElementsQuery(std::string title, std::string _description = "");
|
---|
| 293 | virtual ~ElementsQuery();
|
---|
| 294 | virtual bool handle()=0;
|
---|
| 295 | virtual void setResult();
|
---|
| 296 | protected:
|
---|
[e5c0a1] | 297 | const element *temp;
|
---|
| 298 | std::vector<const element *> tmp;
|
---|
[5a7243] | 299 | };
|
---|
| 300 |
|
---|
[6f5dfe] | 301 | class FileQuery : public Query {
|
---|
| 302 | public:
|
---|
| 303 | FileQuery(std::string title, std::string _description = "");
|
---|
| 304 | virtual ~FileQuery();
|
---|
| 305 | virtual bool handle()=0;
|
---|
| 306 | virtual void setResult();
|
---|
| 307 | protected:
|
---|
| 308 | boost::filesystem::path tmp;
|
---|
| 309 | };
|
---|
| 310 |
|
---|
[45f5d6] | 311 | void registerQuery(Query* query);
|
---|
| 312 |
|
---|
| 313 | private:
|
---|
| 314 | std::list<Query*> queries;
|
---|
[f5a86a] | 315 |
|
---|
| 316 | };
|
---|
| 317 |
|
---|
[a2ab15] | 318 |
|
---|
[f5a86a] | 319 | #endif /* DIALOG_HPP_ */
|
---|