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