~scottydelicious666/brewtarget/brewtarget

« back to all changes in this revision

Viewing changes to src/recipe.h

  • Committer: Philip Greggory Lee
  • Date: 2009-08-23 16:53:43 UTC
  • Revision ID: git-v1:f8d1a25135bd92f06c46c562293800e4faa42c61
Made a src/ and ui/ directory and moved everything.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * recipe.h is part of Brewtarget, and is Copyright Philip G. Lee
 
3
 * (rocketman768@gmail.com), 2009.
 
4
 *
 
5
 * Brewtarget is free software: you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation, either version 3 of the License, or
 
8
 * (at your option) any later version.
 
9
 
 
10
 * Brewtarget is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
#ifndef _RECIPE_H
 
19
#define _RECIPE_H
 
20
 
 
21
class Recipe;
 
22
class RecipeException;
 
23
 
 
24
#include <QColor>
 
25
#include <QVariant>
 
26
#include <QDomNode>
 
27
#include "BeerXMLElement.h"
 
28
#include <string>
 
29
#include <exception>
 
30
#include "xmlnode.h"
 
31
#include "style.h"
 
32
#include "misc.h"
 
33
#include "mash.h"
 
34
#include "hop.h"
 
35
#include "fermentable.h"
 
36
#include "equipment.h"
 
37
#include "yeast.h"
 
38
#include "water.h"
 
39
#include "observable.h"
 
40
#include "instruction.h"
 
41
 
 
42
class Recipe : public Observable, public MultipleObserver, public BeerXMLElement
 
43
{
 
44
public:
 
45
 
 
46
   Recipe();
 
47
   //Recipe(const XmlNode *node);
 
48
   Recipe(const QDomNode& recipeNode);
 
49
 
 
50
   enum{INSTRUCTION};
 
51
 
 
52
   friend bool operator<(Recipe &r1, Recipe &r2 );
 
53
   friend bool operator==(Recipe &r1, Recipe &r2 );
 
54
 
 
55
   virtual void toXml(QDomDocument& doc, QDomNode& parent); // From BeerXMLElement
 
56
   //std::string toXml();
 
57
   void clear(); // Retains only the name, but sets everything else to defaults.
 
58
   virtual void notify(Observable *notifier, QVariant info = QVariant()); // Inherited from MultipleObserver.
 
59
   
 
60
   void setName( const std::string &var );
 
61
   void setType( const std::string &var );
 
62
   void setBrewer( const std::string &var );
 
63
   void setStyle( Style *var );
 
64
   void setBatchSize_l( double var );
 
65
   void setBoilSize_l( double var );
 
66
   void setBoilTime_min( double var );
 
67
   void setEfficiency_pct( double var );
 
68
   
 
69
   void addHop( Hop *var );
 
70
   bool removeHop( Hop *var );
 
71
   void addFermentable( Fermentable* var );
 
72
   bool removeFermentable( Fermentable* var );
 
73
   void addMisc( Misc* var );
 
74
   bool removeMisc( Misc* var );
 
75
   void addYeast( Yeast* var );
 
76
   bool removeYeast( Yeast* var );
 
77
   void addWater( Water* var );
 
78
   bool removeWater( Water* var );
 
79
 
 
80
   void addInstruction( Instruction* ins );
 
81
   void removeInstruction( Instruction* ins );
 
82
   void swapInstructions( unsigned int j, unsigned int k );
 
83
   void clearInstructions();
 
84
   void insertInstruction( Instruction* ins, int pos );
 
85
   int getNumInstructions();
 
86
   Instruction* getInstruction(int i);
 
87
   void generateInstructions();
 
88
   QString nextAddToBoil(double& time);
 
89
 
 
90
   void setMash( Mash *var );
 
91
   void setAsstBrewer( const std::string &var );
 
92
   void setEquipment( Equipment *var );
 
93
   void setNotes( const std::string &var );
 
94
   void setTasteNotes( const std::string &var );
 
95
   void setTasteRating( double var );
 
96
   void setOg( double var );
 
97
   void setFg( double var );
 
98
   void setFermentationStages( int var );
 
99
   void setPrimaryAge_days( double var );
 
100
   void setPrimaryTemp_c( double var );
 
101
   void setSecondaryAge_days( double var );
 
102
   void setSecondaryTemp_c( double var );
 
103
   void setTertiaryAge_days( double var );
 
104
   void setTertiaryTemp_c( double var );
 
105
   void setAge_days( double var );
 
106
   void setAgeTemp_c( double var );
 
107
   void setDate( const std::string &var );
 
108
   void setCarbonation_vols( double var );
 
109
   void setForcedCarbonation( bool var );
 
110
   void setPrimingSugarName( const std::string &var );
 
111
   void setCarbonationTemp_c( double var );
 
112
   void setPrimingSugarEquiv( double var );
 
113
   void setKegPrimingFactor( double var );
 
114
 
 
115
   std::string getName() const;
 
116
   std::string getType() const;
 
117
   std::string getBrewer() const;
 
118
   Style *getStyle() const;
 
119
   double getBatchSize_l() const;
 
120
   double getBoilSize_l() const;
 
121
   double getBoilTime_min() const;
 
122
   double getEfficiency_pct() const;
 
123
   
 
124
   unsigned int getNumHops() const;
 
125
   Hop* getHop(unsigned int i);
 
126
   unsigned int getNumFermentables() const;
 
127
   Fermentable* getFermentable(unsigned int i);
 
128
   unsigned int getNumMiscs() const;
 
129
   Misc* getMisc(unsigned int i);
 
130
   unsigned int getNumYeasts() const;
 
131
   Yeast* getYeast(unsigned int i);
 
132
   unsigned int getNumWaters() const;
 
133
   Water* getWater(unsigned int i);
 
134
   
 
135
   Mash* getMash() const;
 
136
 
 
137
   std::string getAsstBrewer() const;
 
138
   Equipment* getEquipment() const;
 
139
   std::string getNotes() const;
 
140
   std::string getTasteNotes() const;
 
141
   double getTasteRating() const;
 
142
   double getOg() const;
 
143
   double getFg() const;
 
144
   int getFermentationStages() const;
 
145
   double getPrimaryAge_days() const;
 
146
   double getPrimaryTemp_c() const;
 
147
   double getSecondaryAge_days() const;
 
148
   double getSecondaryTemp_c() const;
 
149
   double getTertiaryAge_days() const;
 
150
   double getTertiaryTemp_c() const;
 
151
   double getAge_days() const;
 
152
   double getAgeTemp_c() const;
 
153
   std::string getDate() const;
 
154
   double getCarbonation_vols() const;
 
155
   bool getForcedCarbonation() const;
 
156
   std::string getPrimingSugarName() const;
 
157
   double getCarbonationTemp_c() const;
 
158
   double getPrimingSugarEquiv() const;
 
159
   double getKegPrimingFactor() const;
 
160
 
 
161
   void recalculate(); // Calculates some parameters.
 
162
   double getABV_pct();
 
163
   double getColor_srm();
 
164
   double getWortGrav();
 
165
   double getIBU();
 
166
   double getIBUFromHop( unsigned int i );
 
167
   QColor getSRMColor();
 
168
   double estimateWortFromMash_l() const; // Estimate amount of wort collected immediately after the mash.
 
169
   double estimateBoilVolume_l() const; // Estimate boil volume based on user inputs.
 
170
   double estimateFinalVolume_l() const; // Estimate final volume based on user inputs.
 
171
   double getGrainsInMash_kg() const;
 
172
 
 
173
private:
 
174
 
 
175
   std::string name;
 
176
   static const int version = 1;
 
177
   std::string type;
 
178
   std::string brewer;
 
179
   Style* style;
 
180
   double batchSize_l;
 
181
   double boilSize_l;
 
182
   double boilTime_min;
 
183
   double efficiency_pct;
 
184
   std::vector<Hop*> hops;
 
185
   std::vector<Fermentable*> fermentables;
 
186
   std::vector<Misc*> miscs;
 
187
   std::vector<Yeast*> yeasts;
 
188
   std::vector<Water*> waters;
 
189
   Mash *mash;
 
190
   std::vector<Instruction*> instructions;
 
191
   
 
192
   std::string asstBrewer;
 
193
   Equipment* equipment;
 
194
   std::string notes;
 
195
   std::string tasteNotes;
 
196
   double tasteRating;
 
197
   double og;
 
198
   double fg;
 
199
   int fermentationStages;
 
200
   double primaryAge_days;
 
201
   double primaryTemp_c;
 
202
   double secondaryAge_days;
 
203
   double secondaryTemp_c;
 
204
   double tertiaryAge_days;
 
205
   double tertiaryTemp_c;
 
206
   double age_days;
 
207
   double ageTemp_c;
 
208
   std::string date;
 
209
   double carbonation_vols;
 
210
   bool forcedCarbonation;
 
211
   std::string primingSugarName;
 
212
   double carbonationTemp_c;
 
213
   double primingSugarEquiv;
 
214
   double kegPrimingFactor;
 
215
   
 
216
   void setDefaults();
 
217
   bool isValidType( const std::string &str );
 
218
};
 
219
 
 
220
class RecipeException : public std::exception
 
221
{
 
222
public:
 
223
 
 
224
   virtual const char* what() const throw()
 
225
   {
 
226
      return std::string("BeerXML RECIPE error: " + _err + "\n").c_str();
 
227
   }
 
228
 
 
229
   RecipeException( std::string message )
 
230
   {
 
231
      _err = message;
 
232
   }
 
233
 
 
234
   ~RecipeException() throw() {}
 
235
 
 
236
private:
 
237
 
 
238
   std::string _err;
 
239
};
 
240
 
 
241
struct Recipe_ptr_cmp
 
242
{
 
243
   bool operator()( Recipe* lhs, Recipe* rhs)
 
244
   {
 
245
      return *lhs < *rhs;
 
246
   }
 
247
};
 
248
 
 
249
struct Recipe_ptr_equals
 
250
{
 
251
   bool operator()( Recipe* lhs, Recipe* rhs )
 
252
   {
 
253
      return *lhs == *rhs;
 
254
   }
 
255
};
 
256
 
 
257
#endif /* _RECIPE_H */