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