src/EditRecipeTab7.cpp

changeset 361
ec8de79f6ff6
parent 359
dfbb012c631c
child 365
4bc746c65650
equal deleted inserted replaced
360:b70cfa20ac46 361:ec8de79f6ff6
66 } else { 66 } else {
67 /* 67 /*
68 * If the acid_to_ph_5.7 is unknown from the maltster, guess the required acid. 68 * If the acid_to_ph_5.7 is unknown from the maltster, guess the required acid.
69 */ 69 */
70 switch (F.graintype) { 70 switch (F.graintype) {
71 case 0: // Base, Special, Kilned 71 case FERMENTABLE_GRAINTYPE_BASE:
72 case 3: 72 case FERMENTABLE_GRAINTYPE_KILNED:
73 case 5: C1 = 0.014 * F.color - 34.192; 73 case FERMENTABLE_GRAINTYPE_SPECIAL: C1 = 0.014 * F.color - 34.192;
74 break; 74 break;
75 case 2: C1 = -0.0597 * F.color - 32.457; // Crystal 75 case FERMENTABLE_GRAINTYPE_CRYSTAL: C1 = -0.0597 * F.color - 32.457;
76 break; 76 break;
77 case 1: C1 = 0.0107 * F.color - 54.768; // Roast 77 case FERMENTABLE_GRAINTYPE_ROAST: C1 = 0.0107 * F.color - 54.768;
78 break; 78 break;
79 case 4: C1 = -149; // Sour malt 79 case FERMENTABLE_GRAINTYPE_SOUR_MALT: C1 = -149;
80 break; 80 break;
81 } 81 }
82 } 82 }
83 return C1; 83 return C1;
84 } 84 }
85 85
103 * proton deficit for the grist 103 * proton deficit for the grist
104 */ 104 */
105 if (recipe->fermentables.size()) { 105 if (recipe->fermentables.size()) {
106 for (i = 0; i < recipe->fermentables.size(); i++) { 106 for (i = 0; i < recipe->fermentables.size(); i++) {
107 F = recipe->fermentables.at(i); 107 F = recipe->fermentables.at(i);
108 if (F.added == 0 && F.graintype != 6) { // Added == Mash && graintype != No Malt 108 if (F.added == FERMENTABLE_ADDED_MASH && F.graintype != FERMENTABLE_GRAINTYPE_NO_MALT) {
109 x = AcidRequired(pHZ, F) * F.amount; 109 x = AcidRequired(pHZ, F) * F.amount;
110 Result += x; 110 Result += x;
111 } 111 }
112 } 112 }
113 } else { 113 } else {
136 pd = ProtonDeficit(pH); 136 pd = ProtonDeficit(pH);
137 } 137 }
138 pH = round(pH * 1000000) / 1000000.0; 138 pH = round(pH * 1000000) / 1000000.0;
139 qDebug() << " MashpH() n:" << n << "pH:" << pH; 139 qDebug() << " MashpH() n:" << n << "pH:" << pH;
140 return pH; 140 return pH;
141 }
142
143
144 void EditRecipe::setButtons(bool locked)
145 {
146 if (locked) {
147 /*
148 * If recipe is locked, disable the buttons and that's it.
149 */
150 ui->w1_spButton->setDisabled(true);
151 ui->w2_spButton->setDisabled(true);
152 ui->wg_spButton->setDisabled(true);
153 return;
154 }
155 ui->w1_spButton->setDisabled(false);
156
157 const QSignalBlocker blocker1(ui->w1_spButton);
158 const QSignalBlocker blocker2(ui->w2_spButton);
159 const QSignalBlocker blocker3(ui->wg_spButton);
160
161 if (recipe->w2_name != "") {
162 ui->w2_spButton->setDisabled(false);
163 if (recipe->w2_amount > 0.1 && recipe->w2_ph > 5) {
164 /*
165 * Water 2 is valid and used for mash, mixed is available.
166 */
167 ui->wg_spButton->setDisabled(false);
168 } else {
169 /*
170 * No mixed water for mash. We can still sparge with source 2.
171 */
172 ui->wg_spButton->setDisabled(true);
173 if (recipe->sparge_source == 2) {
174 /*
175 * If mixed was selected, switch to source 2.
176 */
177 recipe->sparge_source = 1;
178 ui->w2_spButton->setChecked(true);
179 }
180 }
181 } else {
182 ui->w2_spButton->setDisabled(true);
183 ui->wg_spButton->setDisabled(true);
184 recipe->sparge_source = 0; // Fallback to source 1
185 ui->w1_spButton->setChecked(true);
186 }
141 } 187 }
142 188
143 189
144 void EditRecipe::calcWater() 190 void EditRecipe::calcWater()
145 { 191 {
426 double TargetpH = recipe->sparge_ph; 472 double TargetpH = recipe->sparge_ph;
427 double Source_pH = recipe->w1_ph; 473 double Source_pH = recipe->w1_ph;
428 double Source_alkalinity = recipe->w1_total_alkalinity; 474 double Source_alkalinity = recipe->w1_total_alkalinity;
429 475
430 qDebug() << "calcSparge()"; 476 qDebug() << "calcSparge()";
431 477 setButtons(recipe->locked);
432 const QSignalBlocker blocker2(ui->w1_spButton); 478
433 const QSignalBlocker blocker3(ui->w2_spButton); 479 if (recipe->sparge_source == 1 && recipe->w2_ph > 0.0) {
434 const QSignalBlocker blocker4(ui->wg_spButton); 480 Source_pH = recipe->w2_ph;
435 481 Source_alkalinity = recipe->w2_total_alkalinity;
436 // Select watersource or fallback to the first source. 482 ui->sp_caEdit->setValue(recipe->w2_calcium);
437 if (recipe->sparge_source == 1) { // Source 2 483 ui->sp_mgEdit->setValue(recipe->w2_magnesium);
438 if (recipe->w2_ph > 0.0 && recipe->w2_amount > 0) { 484 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w2_total_alkalinity, recipe->w2_ph));
439 Source_pH = recipe->w2_ph; 485 ui->sp_caco3Edit->setValue(recipe->w2_total_alkalinity);
440 Source_alkalinity = recipe->w2_total_alkalinity; 486 ui->sp_naEdit->setValue(recipe->w2_sodium);
441 ui->sp_caEdit->setValue(recipe->w2_calcium); 487 ui->sp_clEdit->setValue(recipe->w2_chloride);
442 ui->sp_mgEdit->setValue(recipe->w2_magnesium); 488 ui->sp_so4Edit->setValue(recipe->w2_sulfate);
443 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w2_total_alkalinity, recipe->w2_ph)); 489 ui->sp_phShow->setValue(recipe->w2_ph);
444 ui->sp_caco3Edit->setValue(recipe->w2_total_alkalinity); 490 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w2_calcium, recipe->w2_magnesium));
445 ui->sp_naEdit->setValue(recipe->w2_sodium); 491 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w2_total_alkalinity, recipe->w2_calcium, recipe->w2_magnesium));
446 ui->sp_clEdit->setValue(recipe->w2_chloride); 492 } else if (recipe->sparge_source == 2 && recipe->w2_ph > 0.0) {
447 ui->sp_so4Edit->setValue(recipe->w2_sulfate); 493 Source_pH = recipe->wg_ph;
448 ui->sp_phShow->setValue(recipe->w2_ph); 494 Source_alkalinity = recipe->wg_total_alkalinity;
449 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w2_calcium, recipe->w2_magnesium)); 495 ui->sp_caEdit->setValue(recipe->wg_calcium);
450 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w2_total_alkalinity, recipe->w2_calcium, recipe->w2_magnesium)); 496 ui->sp_mgEdit->setValue(recipe->wg_magnesium);
451 ui->w2_spButton->setChecked(true); 497 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->wg_total_alkalinity, recipe->wg_ph));
452 } else { 498 ui->sp_caco3Edit->setValue(recipe->wg_total_alkalinity);
453 recipe->sparge_source = 0; // Fallback to source 1 499 ui->sp_naEdit->setValue(recipe->wg_sodium);
454 ui->w1_spButton->setChecked(true); 500 ui->sp_clEdit->setValue(recipe->wg_chloride);
455 } 501 ui->sp_so4Edit->setValue(recipe->wg_sulfate);
456 } else if (recipe->sparge_source == 2) { // Mixed 502 ui->sp_phShow->setValue(recipe->wg_ph);
457 if (recipe->w2_ph > 0.0 && recipe->w2_amount > 0) { 503 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->wg_calcium, recipe->wg_magnesium));
458 Source_pH = recipe->wg_ph; 504 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->wg_total_alkalinity, recipe->wg_calcium, recipe->wg_magnesium));
459 Source_alkalinity = recipe->wg_total_alkalinity; 505 } else {
460 ui->sp_caEdit->setValue(recipe->wg_calcium); 506 ui->sp_caEdit->setValue(recipe->w1_calcium);
461 ui->sp_mgEdit->setValue(recipe->wg_magnesium); 507 ui->sp_mgEdit->setValue(recipe->w1_magnesium);
462 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->wg_total_alkalinity, recipe->wg_ph)); 508 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w1_total_alkalinity, recipe->w1_ph));
463 ui->sp_caco3Edit->setValue(recipe->wg_total_alkalinity); 509 ui->sp_caco3Edit->setValue(recipe->w1_total_alkalinity);
464 ui->sp_naEdit->setValue(recipe->wg_sodium); 510 ui->sp_naEdit->setValue(recipe->w1_sodium);
465 ui->sp_clEdit->setValue(recipe->wg_chloride); 511 ui->sp_clEdit->setValue(recipe->w1_chloride);
466 ui->sp_so4Edit->setValue(recipe->wg_sulfate); 512 ui->sp_so4Edit->setValue(recipe->w1_sulfate);
467 ui->sp_phShow->setValue(recipe->wg_ph); 513 ui->sp_phShow->setValue(recipe->w1_ph);
468 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->wg_calcium, recipe->wg_magnesium)); 514 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w1_calcium, recipe->w1_magnesium));
469 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->wg_total_alkalinity, recipe->wg_calcium, recipe->wg_magnesium)); 515 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w1_total_alkalinity, recipe->w1_calcium, recipe->w1_magnesium));
470 ui->wg_spButton->setChecked(true);
471 } else {
472 recipe->sparge_source = 0; // Fallback to source 1
473 ui->w1_spButton->setChecked(true);
474 }
475 }
476 if (recipe->sparge_source == 0) {
477 ui->sp_caEdit->setValue(recipe->w1_calcium);
478 ui->sp_mgEdit->setValue(recipe->w1_magnesium);
479 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w1_total_alkalinity, recipe->w1_ph));
480 ui->sp_caco3Edit->setValue(recipe->w1_total_alkalinity);
481 ui->sp_naEdit->setValue(recipe->w1_sodium);
482 ui->sp_clEdit->setValue(recipe->w1_chloride);
483 ui->sp_so4Edit->setValue(recipe->w1_sulfate);
484 ui->sp_phShow->setValue(recipe->w1_ph);
485 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w1_calcium, recipe->w1_magnesium));
486 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w1_total_alkalinity, recipe->w1_calcium, recipe->w1_magnesium));
487 ui->w1_spButton->setChecked(true);
488 } 516 }
489 // The spargewater is set. 517 // The spargewater is set.
490 518
491 int AT = recipe->sparge_acid_type; 519 int AT = recipe->sparge_acid_type;
492 if (AT < 0 || AT >= my_acids.size()) { 520 if (AT < 0 || AT >= my_acids.size()) {

mercurial