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