src/EditProductTab9.cpp

Sun, 15 May 2022 23:10:15 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 15 May 2022 23:10:15 +0200
changeset 210
b45bd6da5220
parent 209
19c50b1f58d3
child 212
8b84dd3579ef
permissions
-rw-r--r--

Implemented brewday change cooling, aeration, whirlpool and fermenter volumes values. All editable values on the brewday tab are now functional.

/**
 * EditProduct.cpp is part of bmsapp.
 *
 * Tab 9, brewday.
 *
 * 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/>.
 */


/**
 * @brief Check the state by examining the date values.
 *        1. startdate and enddate invalid, planning/wait status.
 *           The enddate cannot be set.
 *        2. startdate valid and endate invalid, brewdate is planned.
 *           The fase will be brew. Enable setting of enddate.
 *        3. startdate valid, enddate and start and endtime can be set.
 *           The enddate cannot be before the startdate and not after 4
 *           days from the start.
 *        4. startdate and enddate and times are set and valid. Block
 *           the startdate setting. But only after setting a lot of
 *           brewdata move the fase to primary.
 *
 */
void EditProduct::updateBrewday()
{
    setStage();

    qDebug() << "updateBrewday" << product->brew_date_start.date() << product->brew_date_end.date();

    ui->brew_startDate->setDate(product->brew_date_start.date());
    ui->brew_startTime->setTime(product->brew_date_start.time());
    ui->brew_endDate->setDate(product->brew_date_end.date());
    ui->brew_endTime->setTime(product->brew_date_end.time());
}


void EditProduct::brew_date_clear()
{
    product->brew_date_start.setDate(QDate());
    ui->brew_startDate->setDate(QDate());
}


void EditProduct::brew_date_today()
{
    product->brew_date_start.setDate(QDate::currentDate());
    ui->brew_startDate->setDate(QDate::currentDate());
}


void EditProduct::brew_start_date_changed(QDate val)
{
    product->brew_date_start.setDate(ui->brew_startDate->nullDate());
    qDebug() << "brew_start_date_changed" << product->brew_date_start.date();
    updateBrewday();
    is_changed();
}


void EditProduct::brew_end_today()
{
}


void EditProduct::brew_end_date_changed(QDate val)
{
    qDebug() << "brew_end_date_changed" << val;
}


void EditProduct::brew_mashph_changed(double val)
{
    if (product->brew_mash_ph == 0) {
	product->brew_mash_ph = 4.8;
	const QSignalBlocker blocker1(ui->brew_mashphEdit);
	ui->brew_mashphEdit->setValue(4.8);
    } else {
    	product->brew_mash_ph = val;
    }
    is_changed();
}


void EditProduct::brew_mashsg_changed(double val)
{
    product->brew_mash_sg = val;
    double c = Utils::sg_to_plato(product->est_mash_sg);
    double m = Utils::sg_to_plato(val);

    if (c > 0.5)
	product->brew_mash_efficiency = 100 * m / c;
    else
	product->brew_mash_efficiency = 0;
    ui->brew_masheffShow->setValue(product->brew_mash_efficiency);
    is_changed();
}


void EditProduct::brew_spargeph_changed(double val)
{
    if (product->brew_sparge_ph == 0) {
        product->brew_sparge_ph = 4.8;
        const QSignalBlocker blocker1(ui->brew_spargephEdit);
        ui->brew_spargephEdit->setValue(4.8);
    } else {
    	product->brew_sparge_ph = val;
    }
    is_changed();
}


void EditProduct::brew_preboilph_changed(double val)
{
    if (product->brew_preboil_ph == 0) {
        product->brew_preboil_ph = 4.8;
        const QSignalBlocker blocker1(ui->brew_preboilphEdit);
        ui->brew_preboilphEdit->setValue(4.8);
    } else {
        product->brew_preboil_ph = val;
    }
    is_changed();
}


void EditProduct::calcEfficiencyBeforeBoil()
{
    double m = 0;
    double tot;
    double result = 0;

    if (product->fermentables.size() == 0)
	return;	// no fermentables loaded yet
    for (int i = 0; i < product->fermentables.size(); i++) {
   	if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_MASH) {
	    m += product->fermentables.at(i).f_amount * (product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100);
	}
    }
    tot = Utils::sg_to_plato(product->brew_preboil_sg) * (product->brew_preboil_volume / 1.04) * product->brew_preboil_sg * 10 / 1000;

    if (m > 0)
	result = round((tot / m * 100) * 10.0) / 10.0;

    if (result < 0)
	result = 0;
    ui->brew_preboileffShow->setValue(result);
}


void EditProduct::brew_preboilsg_changed(double val)
{
    if (product->brew_preboil_sg == 0) {
	product->brew_preboil_sg = product->preboil_sg;
	const QSignalBlocker blocker1(ui->brew_preboilsgEdit);
        ui->brew_preboilsgEdit->setValue(product->preboil_sg);
    } else {
    	product->brew_preboil_sg = val;
    }
    is_changed();
    calcEfficiencyBeforeBoil();
}


void EditProduct::brew_preboilvol_changed(double val)
{
    if (product->brew_preboil_volume == 0) {
	product->brew_preboil_volume = product->boil_size * 1.04;
	const QSignalBlocker blocker1(ui->brew_preboilvolEdit);
        ui->brew_preboilvolEdit->setValue(product->boil_size * 1.04);
    } else {
    	product->brew_preboil_volume = val;
    }
    is_changed();
    calcEfficiencyBeforeBoil();
}


void EditProduct::brew_aboilph_changed(double val)
{
    if (product->brew_aboil_ph == 0) {
        product->brew_aboil_ph = 4.8;
        const QSignalBlocker blocker1(ui->brew_aboilphEdit);
        ui->brew_aboilphEdit->setValue(4.8);
    } else {
        product->brew_aboil_ph = val;
    }
    is_changed();
}


void EditProduct::calcEfficiencyAfterBoil()
{
    double m = 0;	// Sugars added at mash
    double b = 0;	// Sugars added at boil
    double result = 0;

    if (product->fermentables.size() == 0)
        return; // no fermentables loaded yet
    for (int i = 0; i < product->fermentables.size(); i++) {
	if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_MASH) {
	    m += product->fermentables.at(i).f_amount * (product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100);
	} else if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_BOIL) {
	    b += product->fermentables.at(i).f_amount * (product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100);
	}
    }
    double tot = Utils::sg_to_plato(product->brew_aboil_sg) * (product->brew_aboil_volume / 1.04) * product->brew_aboil_sg * 10 / 1000;
    tot -= b;	// total sugars in wort  minus added sugars.

    if (m > 0)
	result = round((tot / m * 100) * 10.0) / 10.0;
    product->brew_aboil_efficiency = result;
    ui->brew_aboileffShow->setValue(result);
    calcFermentables();	// This will also recalculate all volumes.
}


void EditProduct::brew_aboilsg_changed(double val)
{
    if (product->brew_aboil_sg == 0) {
        product->brew_aboil_sg = product->est_og3;
        const QSignalBlocker blocker1(ui->brew_aboilsgEdit);
        ui->brew_aboilsgEdit->setValue(product->est_og3);
    } else {
        product->brew_aboil_sg = val;
    }
    is_changed();
    calcEfficiencyAfterBoil();
}


void EditProduct::brew_aboilvol_changed(double val)
{
    if (product->brew_aboil_volume == 0) {
        product->brew_aboil_volume = product->batch_size * 1.04;
        const QSignalBlocker blocker1(ui->brew_aboilvolEdit);
        ui->brew_aboilvolEdit->setValue(product->batch_size * 1.04);
    } else {
        product->brew_aboil_volume = val;
    }
    is_changed();
    calcEfficiencyAfterBoil();
}


void EditProduct::brew_cooling_method_changed(int val)
{
    product->brew_cooling_method = val;
    is_changed();
}


void EditProduct::brew_cooling_to_changed(double val)
{
    product->brew_cooling_to = val;
    is_changed();
}


void EditProduct::brew_cooling_time_changed(double val)
{
    product->brew_cooling_time = val;
    is_changed();
}


void EditProduct::brew_whirlpool9_changed(double val)
{
    product->brew_whirlpool9 = val;
    is_changed();
}


void EditProduct::brew_whirlpool7_changed(double val)
{
    product->brew_whirlpool7 = val;
    is_changed();
}


void EditProduct::brew_whirlpool6_changed(double val)
{
    product->brew_whirlpool6 = val;
    is_changed();
}


void EditProduct::brew_whirlpool2_changed(double val)
{
    product->brew_whirlpool2 = val;
    is_changed();
}


void EditProduct::brew_aerwith_changed(int val)
{
    product->brew_aeration_type = val;
    is_changed();
}


void EditProduct::brew_aerspeed_changed(double val)
{
    product->brew_aeration_speed = val;
    is_changed();
}


void EditProduct::brew_aertime_changed(double val)
{
    product->brew_aeration_time = val;
    is_changed();
}


void EditProduct::brew_trubloss_changed(double val)
{
    product->brew_fermenter_tcloss = val;
    is_changed();
    calcFermentables(); // This will also recalculate all volumes.
    calcIBUs();
}


void EditProduct::brew_topupwater_changed(double val)
{
    product->brew_fermenter_extrawater = val;
    is_changed();
    calcFermentables(); // This will also recalculate all volumes.
    calcIBUs();
}

mercurial