[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;
|
---|
[cd8e55] | 43 | virtual void queryStrings(const char*, std::vector<std::string> *, std::string = "")=0;
|
---|
[97ebf8] | 44 | virtual void queryAtom(const char*,atom**,std::string = "")=0;
|
---|
| 45 | virtual void queryMolecule(const char*,molecule**, std::string = "")=0;
|
---|
[84c494] | 46 | virtual void queryVector(const char*,Vector *,bool, std::string = "")=0;
|
---|
| 47 | virtual void queryBox(const char*,Box*, std::string = "")=0;
|
---|
[104524] | 48 | virtual void queryElement(const char*, std::vector<element *> *, std::string = "")=0;
|
---|
[f5a86a] | 49 |
|
---|
[45f5d6] | 50 | virtual bool display();
|
---|
[f5a86a] | 51 |
|
---|
[d3a5ea] | 52 | virtual bool checkAll();
|
---|
| 53 | virtual void setAll();
|
---|
| 54 |
|
---|
[f5a86a] | 55 | protected:
|
---|
| 56 | // methodology for handling queries
|
---|
| 57 | // all queries are stored and then performed at appropriate times
|
---|
| 58 |
|
---|
| 59 | //these queries can be handled by this dialog
|
---|
[45f5d6] | 60 |
|
---|
| 61 | //TODO: Find a way to reduce complexity...
|
---|
| 62 | //needs O(N*M) query classes, where N is the number of query types and M is the number of GUIs
|
---|
| 63 | //usual approach for reducing inheritance complexity (strategy pattern) does not work,
|
---|
| 64 | //due to lack of common code for query types as well as GUI-Types (all subtypes differ a lot)
|
---|
| 65 |
|
---|
| 66 | //base class for all queries
|
---|
| 67 | class Query {
|
---|
[94d131] | 68 | friend class Dialog;
|
---|
[45f5d6] | 69 | public:
|
---|
[a2ab15] | 70 | Query(std::string _title, std::string _description = "");
|
---|
[5a7243] | 71 | virtual ~Query();
|
---|
[45f5d6] | 72 | virtual bool handle()=0;
|
---|
| 73 | virtual void setResult()=0;
|
---|
| 74 | protected:
|
---|
| 75 | const std::string getTitle() const;
|
---|
[a2ab15] | 76 | const std::string getDescription() const;
|
---|
[45f5d6] | 77 | private:
|
---|
[a2ab15] | 78 | std::string title; //!< short title of the query
|
---|
| 79 | std::string description; //!< longer description for tooltips or for help
|
---|
[f5a86a] | 80 | };
|
---|
| 81 |
|
---|
[86466e] | 82 | // Empty Query is just meant for showing text, such as version, help, initial message or alike
|
---|
| 83 | class EmptyQuery : public Query {
|
---|
| 84 | public:
|
---|
| 85 | EmptyQuery(std::string title, std::string _description = "");
|
---|
| 86 | virtual ~EmptyQuery();
|
---|
| 87 | virtual bool handle()=0;
|
---|
| 88 | virtual void setResult();
|
---|
[f5a86a] | 89 | };
|
---|
| 90 |
|
---|
[45f5d6] | 91 | //Specialized classes for certain types. GUI-Types are not specialized at this time
|
---|
[97ebf8] | 92 | class BooleanQuery : public Query {
|
---|
| 93 | public:
|
---|
| 94 | BooleanQuery(std::string title,bool *_target, std::string _description = "");
|
---|
| 95 | virtual ~BooleanQuery();
|
---|
| 96 | virtual bool handle()=0;
|
---|
| 97 | virtual void setResult();
|
---|
| 98 | protected:
|
---|
| 99 | bool tmp;
|
---|
| 100 | private:
|
---|
| 101 | bool *target;
|
---|
| 102 | };
|
---|
| 103 |
|
---|
[45f5d6] | 104 | class IntQuery : public Query {
|
---|
| 105 | public:
|
---|
[a2ab15] | 106 | IntQuery(std::string title,int *_target, std::string _description = "");
|
---|
[5a7243] | 107 | virtual ~IntQuery();
|
---|
[45f5d6] | 108 | virtual bool handle()=0;
|
---|
| 109 | virtual void setResult();
|
---|
| 110 | protected:
|
---|
| 111 | int tmp;
|
---|
| 112 | private:
|
---|
| 113 | int *target;
|
---|
| 114 | };
|
---|
| 115 |
|
---|
[2ededc2] | 116 | class DoubleQuery : public Query {
|
---|
| 117 | public:
|
---|
[a2ab15] | 118 | DoubleQuery(std::string title,double *_target, std::string _description = "");
|
---|
[5a7243] | 119 | virtual ~DoubleQuery();
|
---|
[2ededc2] | 120 | virtual bool handle()=0;
|
---|
| 121 | virtual void setResult();
|
---|
| 122 | protected:
|
---|
| 123 | double tmp;
|
---|
| 124 | private:
|
---|
| 125 | double *target;
|
---|
| 126 | };
|
---|
| 127 |
|
---|
[45f5d6] | 128 | class StringQuery : public Query {
|
---|
| 129 | public:
|
---|
[a2ab15] | 130 | StringQuery(std::string title,std::string *_target, std::string _description = "");
|
---|
[5a7243] | 131 | virtual ~StringQuery();
|
---|
[45f5d6] | 132 | virtual bool handle()=0;
|
---|
| 133 | virtual void setResult();
|
---|
| 134 | protected:
|
---|
| 135 | std::string tmp;
|
---|
| 136 | private:
|
---|
| 137 | std::string *target;
|
---|
| 138 | };
|
---|
| 139 |
|
---|
[cd8e55] | 140 | class StringsQuery : public Query {
|
---|
| 141 | public:
|
---|
| 142 | StringsQuery(std::string title,std::vector<std::string> *_target, std::string _description = "");
|
---|
| 143 | virtual ~StringsQuery();
|
---|
| 144 | virtual bool handle()=0;
|
---|
| 145 | virtual void setResult();
|
---|
| 146 | protected:
|
---|
| 147 | std::string temp;
|
---|
| 148 | std::vector<std::string> tmp;
|
---|
| 149 | private:
|
---|
| 150 | std::vector<std::string> *target;
|
---|
| 151 | };
|
---|
| 152 |
|
---|
[7aa000] | 153 | class MoleculeQuery : public Query {
|
---|
| 154 | public:
|
---|
[97ebf8] | 155 | MoleculeQuery(std::string title, molecule **_target, std::string _description = "");
|
---|
[5a7243] | 156 | virtual ~MoleculeQuery();
|
---|
[7aa000] | 157 | virtual bool handle()=0;
|
---|
| 158 | virtual void setResult();
|
---|
| 159 | protected:
|
---|
| 160 | molecule *tmp;
|
---|
| 161 | private:
|
---|
| 162 | molecule **target;
|
---|
| 163 | };
|
---|
| 164 |
|
---|
[97ebf8] | 165 | class AtomQuery : public Query {
|
---|
| 166 | public:
|
---|
| 167 | AtomQuery(std::string title, atom **_target, std::string _description = "");
|
---|
| 168 | virtual ~AtomQuery();
|
---|
| 169 | virtual bool handle()=0;
|
---|
| 170 | virtual void setResult();
|
---|
| 171 | protected:
|
---|
| 172 | atom *tmp;
|
---|
| 173 | private:
|
---|
| 174 | atom **target;
|
---|
| 175 | };
|
---|
| 176 |
|
---|
[2ededc2] | 177 | class VectorQuery : public Query {
|
---|
| 178 | public:
|
---|
[84c494] | 179 | VectorQuery(std::string title,Vector *_target,bool _check, std::string _description = "");
|
---|
[5a7243] | 180 | virtual ~VectorQuery();
|
---|
[2ededc2] | 181 | virtual bool handle()=0;
|
---|
| 182 | virtual void setResult();
|
---|
| 183 | protected:
|
---|
| 184 | Vector *tmp;
|
---|
| 185 | bool check;
|
---|
| 186 | private:
|
---|
| 187 | Vector *target;
|
---|
| 188 | };
|
---|
| 189 |
|
---|
[97ebf8] | 190 | class BoxQuery : public Query {
|
---|
| 191 | public:
|
---|
[84c494] | 192 | BoxQuery(std::string title,Box *_cellSize, std::string _description = "");
|
---|
[97ebf8] | 193 | virtual ~BoxQuery();
|
---|
| 194 | virtual bool handle()=0;
|
---|
| 195 | virtual void setResult();
|
---|
| 196 | protected:
|
---|
[84c494] | 197 | double* tmp;
|
---|
[97ebf8] | 198 | private:
|
---|
[84c494] | 199 | Box* target;
|
---|
[97ebf8] | 200 | };
|
---|
| 201 |
|
---|
[5a7243] | 202 | class ElementQuery : public Query {
|
---|
| 203 | public:
|
---|
[104524] | 204 | ElementQuery(std::string title, std::vector<element *> *_target, std::string _description = "");
|
---|
[5a7243] | 205 | virtual ~ElementQuery();
|
---|
| 206 | virtual bool handle()=0;
|
---|
| 207 | virtual void setResult();
|
---|
| 208 | protected:
|
---|
[104524] | 209 | std::vector<element *> elements;
|
---|
[5a7243] | 210 | private:
|
---|
[104524] | 211 | std::vector<element *> * const target;
|
---|
[5a7243] | 212 | };
|
---|
| 213 |
|
---|
[45f5d6] | 214 | void registerQuery(Query* query);
|
---|
| 215 |
|
---|
| 216 | private:
|
---|
| 217 | std::list<Query*> queries;
|
---|
[f5a86a] | 218 |
|
---|
| 219 | };
|
---|
| 220 |
|
---|
[a2ab15] | 221 |
|
---|
[f5a86a] | 222 | #endif /* DIALOG_HPP_ */
|
---|