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