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