~scottydelicious666/brewtarget/brewtarget

« back to all changes in this revision

Viewing changes to src/ScaleRecipeTool.cpp

  • 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
* ScaleRecipeTool.cpp 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
 
 
19
#include "ScaleRecipeTool.h"
 
20
#include "brewtarget.h"
 
21
#include <QMessageBox>
 
22
 
 
23
ScaleRecipeTool::ScaleRecipeTool(QWidget* parent) : QDialog(parent)
 
24
{
 
25
   setupUi(this);
 
26
   recObs = 0;
 
27
   
 
28
   connect(buttonBox, SIGNAL(accepted()), this, SLOT(scale()) );
 
29
   connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()) );
 
30
}
 
31
 
 
32
void ScaleRecipeTool::setRecipe(Recipe* rec)
 
33
{
 
34
   recObs = rec;
 
35
}
 
36
 
 
37
void ScaleRecipeTool::show()
 
38
{
 
39
   // Set the batch size display to the current batch size.
 
40
   if( recObs != 0 )
 
41
   {
 
42
      double batchSize = recObs->getBatchSize_l();
 
43
      lineEdit_newBatchSize->setText(Brewtarget::displayAmount(batchSize, Units::liters));
 
44
   }
 
45
   
 
46
   setVisible(true);
 
47
}
 
48
 
 
49
void ScaleRecipeTool::scale()
 
50
{
 
51
   if( recObs == 0 )
 
52
      return;
 
53
   
 
54
   unsigned int i, size;
 
55
   
 
56
   double currentBatchSize_l = recObs->getBatchSize_l();
 
57
   double newBatchSize_l = Unit::qstringToSI(lineEdit_newBatchSize->text());
 
58
   
 
59
   double ratio = newBatchSize_l / currentBatchSize_l;
 
60
   
 
61
   // I think you want the equipment to be clean.
 
62
   recObs->setEquipment(new Equipment());
 
63
   recObs->setBatchSize_l(newBatchSize_l);
 
64
   recObs->setBoilSize_l(newBatchSize_l);
 
65
   
 
66
   size = recObs->getNumFermentables();
 
67
   for( i = 0; i < size; ++i )
 
68
   {
 
69
      Fermentable* ferm = recObs->getFermentable(i);
 
70
      if( ferm == 0 )
 
71
         continue;
 
72
      
 
73
      ferm->setAmount_kg(ferm->getAmount_kg() * ratio);
 
74
   }
 
75
   
 
76
   size = recObs->getNumHops();
 
77
   for( i = 0; i < size; ++i )
 
78
   {
 
79
      Hop* hop = recObs->getHop(i);
 
80
      if( hop == 0 )
 
81
         continue;
 
82
      
 
83
      hop->setAmount_kg(hop->getAmount_kg() * ratio);
 
84
   }
 
85
   
 
86
   size = recObs->getNumMiscs();
 
87
   for( i = 0; i < size; ++i )
 
88
   {
 
89
      Misc* misc = recObs->getMisc(i);
 
90
      if( misc == 0 )
 
91
         continue;
 
92
      
 
93
      misc->setAmount( misc->getAmount() * ratio );
 
94
   }
 
95
   
 
96
   size = recObs->getNumWaters();
 
97
   for( i = 0; i < size; ++i )
 
98
   {
 
99
      Water* water = recObs->getWater(i);
 
100
      if( water == 0 )
 
101
         continue;
 
102
      
 
103
      water->setAmount_l(water->getAmount_l() * ratio);
 
104
   }
 
105
   
 
106
   Mash *mash = recObs->getMash();
 
107
   if( mash == 0 )
 
108
      return;
 
109
   
 
110
   size = mash->getNumMashSteps();
 
111
   for( i = 0; i < size; ++i )
 
112
   {
 
113
      MashStep* step = mash->getMashStep(i);
 
114
      if( step == 0 )
 
115
         continue;
 
116
      
 
117
      // Reset all these to zero so that the user
 
118
      // will know to re-run the mash wizard.
 
119
      step->setDecoctionAmount_l(0);
 
120
      step->setInfuseAmount_l(0);
 
121
   }
 
122
   
 
123
   // I don't think I should scale the yeasts.
 
124
   
 
125
   // Let the user know what happened.
 
126
   QMessageBox::information(this, tr("Recipe Scaled"),
 
127
                            tr("The equipment and mash have been reset due to the fact that mash temperatures do not scale easily. Please re-run the mash wizard.") );
 
128
}
 
 
b'\\ No newline at end of file'