| 1 | /*************************************************************************** |
| 2 | recipe.h |
| 3 | ------------------- |
| 4 | Recipe (document) class |
| 5 | ------------------- |
| 6 | Copyright 2001-2008, David Johnson |
| 7 | All rights reserved. |
| 8 | |
| 9 | Redistribution and use in source and binary forms, with or without |
| 10 | modification, are permitted provided that the following conditions |
| 11 | are met: |
| 12 | |
| 13 | 1. Redistributions of source code must retain the above copyright |
| 14 | notice, this list of conditions and the following disclaimer. |
| 15 | |
| 16 | 2. Redistributions in binary form must reproduce the above copyright |
| 17 | notice, this list of conditions and the following disclaimer in the |
| 18 | documentation and/or other materials provided with the distribution. |
| 19 | |
| 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | ***************************************************************************/ |
| 32 | |
| 33 | #ifndef RECIPE_H |
| 34 | #define RECIPE_H |
| 35 | |
| 36 | #include <QObject> |
| 37 | #include <QString> |
| 38 | |
| 39 | #include "quantity.h" |
| 40 | #include "grain.h" |
| 41 | #include "hop.h" |
| 42 | #include "misc.h" |
| 43 | #include "style.h" |
| 44 | |
| 45 | class TextPrinter; |
| 46 | |
| 47 | class Recipe : public QObject { |
| 48 | Q_OBJECT |
| 49 | public: |
| 50 | // TODO: make sure am comparing lowercase |
| 51 | // recipe strings |
| 52 | static const QByteArray EXTRACT_STRING; |
| 53 | static const QByteArray PARTIAL_STRING; |
| 54 | static const QByteArray ALLGRAIN_STRING; |
| 55 | |
| 56 | // default constructor |
| 57 | Recipe(QObject *parent=0); |
| 58 | Recipe(const Recipe &recipe); |
| 59 | Recipe operator=(const Recipe &recipe); |
| 60 | virtual ~Recipe(); |
| 61 | |
| 62 | // start a new recipe |
| 63 | void newRecipe(); |
| 64 | // load a recipe |
| 65 | bool loadRecipe(const QString &filename); |
| 66 | // save the current recipe |
| 67 | bool saveRecipe(const QString &filename); |
| 68 | // preview the recipe |
| 69 | void previewRecipe(TextPrinter *textprinter); |
| 70 | // print the recipe |
| 71 | void printRecipe(TextPrinter *textprinter); |
| 72 | // is the file in native format? |
| 73 | bool nativeFormat(const QString &filename); |
| 74 | // is the file in BeerXml format? |
| 75 | bool beerXmlFormat(const QString &filename); |
| 76 | |
| 77 | // import a recipe from another BeerXML format |
| 78 | bool importBeerXml(const QString &filename); |
| 79 | // export the recipe as html |
| 80 | bool exportHtml(const QString &filename); |
| 81 | // export the recipe to BeerXML format |
| 82 | bool exportBeerXML(const QString &filename); |
| 83 | // export the recipe as pdf |
| 84 | bool exportPdf(TextPrinter *textprinter, const QString &filename); |
| 85 | // export the recipe as html |
| 86 | bool exportText(const QString &filename); |
| 87 | |
| 88 | // get and set |
| 89 | const QString& title() const; |
| 90 | void setTitle(const QString &t); |
| 91 | const QString& brewer() const; |
| 92 | void setBrewer(const QString &b); |
| 93 | const Volume &size() const; |
| 94 | void setSize(const Volume &s); |
| 95 | const Style &style() const; |
| 96 | void setStyle(const Style &s); |
| 97 | void setStyle(const QString &s); |
| 98 | const QString& recipeNotes() const; |
| 99 | void setRecipeNotes(const QString &n); |
| 100 | const QString& batchNotes() const; |
| 101 | void setBatchNotes(const QString &n); |
| 102 | |
| 103 | // add an ingredient to the recipe |
| 104 | void addGrain(const Grain &g); |
| 105 | void addHop(const Hop &h); |
| 106 | void addMisc(const Misc &m); |
| 107 | |
| 108 | // return pointer to ingredient lists |
| 109 | GrainList *grains(); |
| 110 | HopList *hops(); |
| 111 | MiscList *miscs(); |
| 112 | |
| 113 | // return original gravity |
| 114 | double OG(); |
| 115 | // return bitterness |
| 116 | int IBU(); |
| 117 | // return color |
| 118 | int SRM(); |
| 119 | // return estimated final gravity |
| 120 | double FGEstimate(); |
| 121 | // return method of recipe |
| 122 | QString method(); |
| 123 | |
| 124 | // return alcohol %v |
| 125 | double ABV(); |
| 126 | static double ABV(double og, double fg); |
| 127 | // return alcohol %w |
| 128 | double ABW(); |
| 129 | static double ABW(double og, double fg); |
| 130 | // convert Specific Gravity to Plato |
| 131 | static double SgToP(double sg); |
| 132 | // convert grain extract to yield |
| 133 | static double extractToYield(double extract); |
| 134 | static double yieldToExtract(double yield); |
| 135 | |
| 136 | // is the recipe modified? |
| 137 | bool modified() const; |
| 138 | |
| 139 | public slots: |
| 140 | // recalculate the recipe values |
| 141 | void recalc(); |
| 142 | // set recipe as modified |
| 143 | void setModified(bool m); |
| 144 | |
| 145 | signals: |
| 146 | // send that the recipe has been loaded or created |
| 147 | void recipeChanged(); |
| 148 | // send that the recipe has been modified |
| 149 | void recipeModified(); |
| 150 | |
| 151 | private: |
| 152 | // calculations |
| 153 | double calcOG(); |
| 154 | int calcSRM(); |
| 155 | int calcIBU(); |
| 156 | int calcRagerIBU(); |
| 157 | int calcTinsethIBU(); |
| 158 | |
| 159 | const QString recipeHTML(); |
| 160 | const QString recipeText(); |
| 161 | |
| 162 | private: |
| 163 | bool modified_; |
| 164 | |
| 165 | QString title_; |
| 166 | QString brewer_; |
| 167 | |
| 168 | Volume size_; |
| 169 | Style style_; |
| 170 | |
| 171 | GrainList grains_; |
| 172 | HopList hops_; |
| 173 | MiscList miscs_; |
| 174 | |
| 175 | QString recipenotes_; |
| 176 | QString batchnotes_; |
| 177 | |
| 178 | double og_; |
| 179 | int ibu_; |
| 180 | int srm_; |
| 181 | }; |
| 182 | |
| 183 | // Inlined Methods ////////////////////////////////////////////////////////// |
| 184 | |
| 185 | inline const QString &Recipe::title() const |
| 186 | { return title_; } |
| 187 | |
| 188 | inline void Recipe::setTitle(const QString &t) |
| 189 | { title_ = t; setModified(true); } |
| 190 | |
| 191 | inline const QString &Recipe::brewer() const |
| 192 | { return brewer_; } |
| 193 | |
| 194 | inline void Recipe::setBrewer(const QString &b) |
| 195 | { brewer_ = b; setModified(true); } |
| 196 | |
| 197 | inline const Volume &Recipe::size() const |
| 198 | { return size_; } |
| 199 | |
| 200 | inline void Recipe::setSize(const Volume &s) |
| 201 | { size_ = s; recalc(); setModified(true); } |
| 202 | |
| 203 | inline const Style &Recipe::style() const |
| 204 | { return style_; } |
| 205 | |
| 206 | inline void Recipe::setStyle(const Style &s) |
| 207 | { style_ = s; setModified(true); } |
| 208 | |
| 209 | inline const QString& Recipe::recipeNotes() const |
| 210 | { return recipenotes_; } |
| 211 | |
| 212 | inline void Recipe::setRecipeNotes(const QString &n) |
| 213 | { recipenotes_ = n; setModified(true); } |
| 214 | |
| 215 | inline const QString& Recipe::batchNotes() const |
| 216 | { return batchnotes_; } |
| 217 | |
| 218 | inline void Recipe::setBatchNotes(const QString &n) |
| 219 | { batchnotes_ = n; setModified(true); } |
| 220 | |
| 221 | inline GrainList *Recipe::grains() { return &grains_; } |
| 222 | |
| 223 | inline HopList *Recipe::hops() { return &hops_; } |
| 224 | |
| 225 | inline MiscList *Recipe::miscs() { return &miscs_; } |
| 226 | |
| 227 | inline double Recipe::OG() { return og_; } |
| 228 | |
| 229 | inline int Recipe::IBU() { return ibu_; } |
| 230 | |
| 231 | inline int Recipe::SRM() { return srm_; } |
| 232 | |
| 233 | #endif // RECIPE_H |