| 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 Box;
|
|---|
| 17 | class element;
|
|---|
| 18 | class molecule;
|
|---|
| 19 | class Vector;
|
|---|
| 20 |
|
|---|
| 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 | */
|
|---|
| 32 | class Dialog
|
|---|
| 33 | {
|
|---|
| 34 | public:
|
|---|
| 35 | Dialog();
|
|---|
| 36 | virtual ~Dialog();
|
|---|
| 37 |
|
|---|
| 38 | virtual void queryEmpty(const char *, std::string = "")=0;
|
|---|
| 39 | virtual void queryBoolean(const char *, std::string = "")=0;
|
|---|
| 40 | virtual void queryInt(const char *, std::string = "")=0;
|
|---|
| 41 | virtual void queryDouble(const char*, std::string = "")=0;
|
|---|
| 42 | virtual void queryString(const char*, std::string = "")=0;
|
|---|
| 43 | virtual void queryStrings(const char*, std::string = "")=0;
|
|---|
| 44 | virtual void queryAtom(const char*,std::string = "")=0;
|
|---|
| 45 | virtual void queryMolecule(const char*, std::string = "")=0;
|
|---|
| 46 | virtual void queryVector(const char*,bool, std::string = "")=0;
|
|---|
| 47 | virtual void queryBox(const char*, std::string = "")=0;
|
|---|
| 48 | virtual void queryElement(const char*, std::string = "")=0;
|
|---|
| 49 |
|
|---|
| 50 | virtual bool display();
|
|---|
| 51 |
|
|---|
| 52 | virtual bool checkAll();
|
|---|
| 53 | virtual void setAll();
|
|---|
| 54 |
|
|---|
| 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
|
|---|
| 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 {
|
|---|
| 68 | friend class Dialog;
|
|---|
| 69 | public:
|
|---|
| 70 | Query(std::string _title, std::string _description = "");
|
|---|
| 71 | virtual ~Query();
|
|---|
| 72 | virtual bool handle()=0;
|
|---|
| 73 | virtual void setResult()=0;
|
|---|
| 74 | protected:
|
|---|
| 75 | const std::string getTitle() const;
|
|---|
| 76 | const std::string getDescription() const;
|
|---|
| 77 | private:
|
|---|
| 78 | std::string title; //!< short title of the query
|
|---|
| 79 | std::string description; //!< longer description for tooltips or for help
|
|---|
| 80 | };
|
|---|
| 81 |
|
|---|
| 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();
|
|---|
| 89 | };
|
|---|
| 90 |
|
|---|
| 91 | //Specialized classes for certain types. GUI-Types are not specialized at this time
|
|---|
| 92 | class BooleanQuery : public Query {
|
|---|
| 93 | public:
|
|---|
| 94 | BooleanQuery(std::string title, std::string _description = "");
|
|---|
| 95 | virtual ~BooleanQuery();
|
|---|
| 96 | virtual bool handle()=0;
|
|---|
| 97 | virtual void setResult();
|
|---|
| 98 | protected:
|
|---|
| 99 | bool tmp;
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 | class IntQuery : public Query {
|
|---|
| 103 | public:
|
|---|
| 104 | IntQuery(std::string title, std::string _description = "");
|
|---|
| 105 | virtual ~IntQuery();
|
|---|
| 106 | virtual bool handle()=0;
|
|---|
| 107 | virtual void setResult();
|
|---|
| 108 | protected:
|
|---|
| 109 | int tmp;
|
|---|
| 110 | };
|
|---|
| 111 |
|
|---|
| 112 | class DoubleQuery : public Query {
|
|---|
| 113 | public:
|
|---|
| 114 | DoubleQuery(std::string title, std::string _description = "");
|
|---|
| 115 | virtual ~DoubleQuery();
|
|---|
| 116 | virtual bool handle()=0;
|
|---|
| 117 | virtual void setResult();
|
|---|
| 118 | protected:
|
|---|
| 119 | double tmp;
|
|---|
| 120 | };
|
|---|
| 121 |
|
|---|
| 122 | class StringQuery : public Query {
|
|---|
| 123 | public:
|
|---|
| 124 | StringQuery(std::string title, std::string _description = "");
|
|---|
| 125 | virtual ~StringQuery();
|
|---|
| 126 | virtual bool handle()=0;
|
|---|
| 127 | virtual void setResult();
|
|---|
| 128 | protected:
|
|---|
| 129 | std::string tmp;
|
|---|
| 130 | };
|
|---|
| 131 |
|
|---|
| 132 | class StringsQuery : public Query {
|
|---|
| 133 | public:
|
|---|
| 134 | StringsQuery(std::string title, std::string _description = "");
|
|---|
| 135 | virtual ~StringsQuery();
|
|---|
| 136 | virtual bool handle()=0;
|
|---|
| 137 | virtual void setResult();
|
|---|
| 138 | protected:
|
|---|
| 139 | std::string temp;
|
|---|
| 140 | std::vector<std::string> tmp;
|
|---|
| 141 | };
|
|---|
| 142 |
|
|---|
| 143 | class MoleculeQuery : public Query {
|
|---|
| 144 | public:
|
|---|
| 145 | MoleculeQuery(std::string title, std::string _description = "");
|
|---|
| 146 | virtual ~MoleculeQuery();
|
|---|
| 147 | virtual bool handle()=0;
|
|---|
| 148 | virtual void setResult();
|
|---|
| 149 | protected:
|
|---|
| 150 | molecule *tmp;
|
|---|
| 151 | };
|
|---|
| 152 |
|
|---|
| 153 | class AtomQuery : public Query {
|
|---|
| 154 | public:
|
|---|
| 155 | AtomQuery(std::string title, std::string _description = "");
|
|---|
| 156 | virtual ~AtomQuery();
|
|---|
| 157 | virtual bool handle()=0;
|
|---|
| 158 | virtual void setResult();
|
|---|
| 159 | protected:
|
|---|
| 160 | atom *tmp;
|
|---|
| 161 | };
|
|---|
| 162 |
|
|---|
| 163 | class VectorQuery : public Query {
|
|---|
| 164 | public:
|
|---|
| 165 | VectorQuery(std::string title,bool _check, std::string _description = "");
|
|---|
| 166 | virtual ~VectorQuery();
|
|---|
| 167 | virtual bool handle()=0;
|
|---|
| 168 | virtual void setResult();
|
|---|
| 169 | protected:
|
|---|
| 170 | Vector *tmp;
|
|---|
| 171 | bool check;
|
|---|
| 172 | };
|
|---|
| 173 |
|
|---|
| 174 | class BoxQuery : public Query {
|
|---|
| 175 | public:
|
|---|
| 176 | BoxQuery(std::string title, std::string _description = "");
|
|---|
| 177 | virtual ~BoxQuery();
|
|---|
| 178 | virtual bool handle()=0;
|
|---|
| 179 | virtual void setResult();
|
|---|
| 180 | protected:
|
|---|
| 181 | double* tmp;
|
|---|
| 182 | };
|
|---|
| 183 |
|
|---|
| 184 | class ElementQuery : public Query {
|
|---|
| 185 | public:
|
|---|
| 186 | ElementQuery(std::string title, std::string _description = "");
|
|---|
| 187 | virtual ~ElementQuery();
|
|---|
| 188 | virtual bool handle()=0;
|
|---|
| 189 | virtual void setResult();
|
|---|
| 190 | protected:
|
|---|
| 191 | std::vector<element *> tmp;
|
|---|
| 192 | };
|
|---|
| 193 |
|
|---|
| 194 | void registerQuery(Query* query);
|
|---|
| 195 |
|
|---|
| 196 | private:
|
|---|
| 197 | std::list<Query*> queries;
|
|---|
| 198 |
|
|---|
| 199 | };
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 | #endif /* DIALOG_HPP_ */
|
|---|