--- a/src/EditRecipeTab2.cpp Wed Apr 20 14:30:06 2022 +0200 +++ b/src/EditRecipeTab2.cpp Wed Apr 20 22:48:20 2022 +0200 @@ -270,15 +270,15 @@ /* * Color of the wort */ - if (ui->color_methodEdit->currentIndex() == 4) { // Naudts + if (recipe->color_method == 4) { // Naudts color = round(((Utils::sg_to_plato(og) / 8.6) * colorn) + (ui->boil_timeEdit->value() / 60)); - } else if (ui->color_methodEdit->currentIndex() == 3) { // Hans Halberstadt + } else if (recipe->color_method == 3) { // Hans Halberstadt double bv = 0.925; // Beer loss efficiency double sr = 0.95; // Mash and sparge efficiency color = round((4.46 * bv * sr) / ui->batch_sizeEdit->value() * colorh); } else { double cw = colort / ui->batch_sizeEdit->value() * 8.34436; - color = Utils::kw_to_ebc(ui->color_methodEdit->currentIndex(), cw); + color = Utils::kw_to_ebc(recipe->color_method, cw); } qDebug() << " color" << ui->est_colorEdit->value() << color << recipe->est_color; recipe->est_color = color; @@ -349,6 +349,39 @@ } +void EditRecipe::calcFermentablesFromOG(double og) +{ + qDebug() << "calcFermentablesFromOG" << og; + + int i; + double totmass = 0; + double tot = 0; + double d, amount; + double efficiency = recipe->efficiency; + double sug = Utils::sg_to_plato(og) * recipe->batch_size * og / 100.0; // total amount of sugars in kg. + + for (i = 0; i < recipe->fermentables.size(); i++) { + if (recipe->fermentables.at(i).f_added < 4) { + d = recipe->fermentables.at(i).f_percentage / 100.0 * + (recipe->fermentables.at(i).f_yield / 100.0) * + (1 - recipe->fermentables.at(i).f_moisture / 100.0); + if (recipe->fermentables.at(i).f_added == 0) // Mash + d = efficiency / 100.0 * d; + tot += d; + } + } + if (tot) + totmass = round((sug / tot) * 1000.0) / 1000.0; + + if (totmass) { + for (i = 0; i < recipe->fermentables.size(); i++) { + amount = round(recipe->fermentables.at(i).f_percentage * 10.0 * totmass) / 1000.0; + recipe->fermentables[i].f_amount = amount; + } + } +} + + void EditRecipe::ferment_perc_mash_valueChanged(int value) { if (value < 90)