src/EditRecipeTab7.cpp

Thu, 14 Apr 2022 21:54:37 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 14 Apr 2022 21:54:37 +0200
changeset 133
08635b028dcf
parent 131
0115b97e8c39
child 134
5099df8ba6c6
permissions
-rw-r--r--

Load waters during recipe startup. Started calcWater() function. Load profile_setup record global. The print function uses the globals now too instead of loading from the database.

/**
 * EditRecipe.cpp is part of bmsapp.
 *
 * tab 6, water.
 *
 * bmsapp is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * bmsapp is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


void EditRecipe::refreshWaters()
{

    // calc_acid
    ui->mw_phEdit->setValue(recipe->mash_ph);
    // mash_name
    //ui->mw_acidpercEdit->setValue(recipe->

}


double EditRecipe::mix(double v1, double v2, double c1, double c2)
{
    if ((v1 + v2) > 0) {
	return ((v1 * c1) + (v2 * c2)) / (v1 + v2);
    }
    return 0;
}


void EditRecipe::calcWater()
{
    double liters = 0;
    double calcium = 0;
    double magnesium = 0;
    double sodium = 0;
    double total_alkalinity = 0;
    double bicarbonate = 0;
    double chloride = 0;
    double sulfate = 0;
    double ph = 0;

    qDebug() << "calcWater";

    /*
     * If there is a dilute water source, mix the waters.
     */
    if (recipe->w2_name != "") {
	liters = recipe->w1_amount + recipe->w2_amount;
	calcium = mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_calcium, recipe->w2_calcium);
	magnesium = mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_magnesium, recipe->w2_magnesium);
	sodium = mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_sodium, recipe->w2_sodium);
	chloride = mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_chloride, recipe->w2_chloride);
	sulfate = mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_sulfate, recipe->w2_sulfate);
	total_alkalinity = mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_total_alkalinity, recipe->w2_total_alkalinity);
	ph = -log10(((pow(10, -recipe->w1_ph) * recipe->w1_amount) + (pow(10, -recipe->w2_ph) * recipe->w2_amount)) / liters);
    } else {
	liters = recipe->w1_amount;
	calcium = recipe->w1_calcium;
	magnesium = recipe->w1_magnesium;
	sodium = recipe->w1_sodium;
	chloride = recipe->w1_chloride;
	sulfate = recipe->w1_sulfate;
	total_alkalinity = recipe->w1_total_alkalinity;
	ph = recipe->w1_ph;
    }

    recipe->wg_amount = liters;
    recipe->wg_calcium = round(calcium * 10.0) / 10.0;
    recipe->wg_magnesium = round(magnesium * 10.0) / 10.0;
    recipe->wg_sodium = round(sodium * 10.0) / 10.0;
    recipe->wg_chloride = round(chloride * 10.0) / 10.0;
    recipe->wg_sulfate = round(sulfate * 10.0) / 10.0;
    recipe->wg_total_alkalinity = round(total_alkalinity * 10.0) / 10.0;

    ui->wg_volEdit->setValue(liters);
    ui->wg_caEdit->setValue(calcium);
    ui->wg_mgEdit->setValue(magnesium);
    ui->wg_hco3Edit->setValue(total_alkalinity * 1.22);
    ui->wg_caco3Edit->setValue(total_alkalinity);
    ui->wg_naEdit->setValue(sodium);
    ui->wg_clEdit->setValue(chloride);
    ui->wg_so4Edit->setValue(sulfate);
    ui->wg_phEdit->setValue(ph);
    bicarbonate = total_alkalinity * 1.22;

    /* Save mixed water ions for later */
    double wg_calcium = calcium;
    double wg_sodium = sodium;
    double wg_total_alkalinity = total_alkalinity;
    double wg_chloride = chloride;
    double wg_sulfate = sulfate;
    double wg_bicarbonate = bicarbonate;

}


void EditRecipe::on_w2_vol_changed(double val)
{
}


void EditRecipe::on_cacl2_changed(double val)
{
    set_brewing_salt("CaCl2", val);
}


void EditRecipe::on_caso4_changed(double val)
{
    set_brewing_salt("CaSO4", val);
}


void EditRecipe::on_mgso4_changed(double val)
{
    set_brewing_salt("MgSO4", val);
}


void EditRecipe::on_nacl_changed(double val)
{
    set_brewing_salt("NaCl", val);
}


void EditRecipe::on_mgcl2_changed(double val)
{
    set_brewing_salt("MgCl2", val);
}


void EditRecipe::on_nahco3_changed(double val)
{
    set_brewing_salt("NaHCO3", val);
}


void EditRecipe::on_caco3_changed(double val)
{
    set_brewing_salt("CaCO3", val);
}


mercurial