| 1 | /*************************************************************************** |
| 2 | hydrometertool.h |
| 3 | ------------------- |
| 4 | A hydrometer correction utility for QBrew |
| 5 | ------------------- |
| 6 | Copyright 2004-2008, David Johnson <[email protected]> |
| 7 | Based on code Copyright 2001, Abe Kabakoff <[email protected]> |
| 8 | Please see the header file for copyright and license information |
| 9 | ***************************************************************************/ |
| 10 | |
| 11 | #include <QLabel> |
| 12 | |
| 13 | #include "resource.h"cxx . . $ `<file>/src/resource.h`/ |
| 14 | #include "data.h"cxx . . $ `<file>/src/data.h`/ |
| 15 | #include "hydrometertool.h"cxx . . $ `<file>/src/hydrometertool.h`/ |
| 16 | |
| 17 | using Resourcecxx . . $ Resource/::TITLEcxx . . $ TITLE.; |
| 18 | |
| 19 | ////////////////////////////////////////////////////////////////////////////// |
| 20 | // HydrometerTool() |
| 21 | // ---------------- |
| 22 | // Constructor |
| 23 | |
| 24 | HydrometerToolcxx . . $ HydrometerTool#:: HydrometerToolcxx . . $ HydrometerTool#HydrometerTool(108f35f7aa7f3cf9).(QWidgetcxx . . $ QWidget#* parent) |
| 25 | : QDialogcxx . . $ QDialog#QDialog(872e7b0c281abd8d).(parent) |
| 26 | { |
| 27 | uicxx . . $ HydrometerTool#ui..setupUicxx . . $ Ui_HydrometerTool#setupUi(d194de0c0f68c28b).(this); |
| 28 | |
| 29 | QStringcxx . . $ QString# SUFFIX = QStringcxx . . $ QString#QString(85c52e162fed56f9).(" %1%2") |
| 30 | .argcxx . . $ QString#arg(21127e6081d7bbe9).(Resourcecxx . . $ Resource/::DEGREEcxx . . $ Resource/DEGREE.) |
| 31 | .argcxx . . $ QString#arg(bc823072288cbbb5).(Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->defaultTempUnitcxx . . $ Data#defaultTempUnit(1a4d46a500733df5).().symbolcxx . . $ Unit#symbol(6ef7b6c27b00b43d).()); |
| 32 | |
| 33 | setWindowTitlecxx . . $ QWidget#setWindowTitle(3520e46b33348bf6).(TITLEcxx . . $ TITLE. +cxx . . $ operator+(57364c1b23444736). trcxx . . $ HydrometerTool#tr(75d9f1c324b4579d).(" - Hydrometer Tool")); |
| 34 | |
| 35 | // additional setup |
| 36 | QFontcxx . . $ QFont# fntcxx . . $ QFont#QFont(d0a4bd0c8524b912).(fontcxx . . $ QWidget#font(c5040538afc47120).()); |
| 37 | fnt.setBoldcxx . . $ QFont#setBold(b45ddcbc8423892c).(true); |
| 38 | uicxx . . $ HydrometerTool#ui..correctedcxx . . $ Ui_HydrometerTool#corrected.->setFontcxx . . $ QWidget#setFont(d0a4bd0c8524b912).(fnt); |
| 39 | |
| 40 | uicxx . . $ HydrometerTool#ui..calibratedcxx . . $ Ui_HydrometerTool#calibrated.->setSuffixcxx . . $ QDoubleSpinBox#setSuffix(3520e46b33348bf6).(SUFFIX); |
| 41 | uicxx . . $ HydrometerTool#ui..samplecxx . . $ Ui_HydrometerTool#sample.->setSuffixcxx . . $ QDoubleSpinBox#setSuffix(3520e46b33348bf6).(SUFFIX); |
| 42 | |
| 43 | // convert UI properties of celsius |
| 44 | if (Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->defaultTempUnitcxx . . $ Data#defaultTempUnit(1a4d46a500733df5).() ==cxx . . $ Unit#`operator==`(98df4da96071e2dd). Temperaturecxx . . $ Temperature#::celsiuscxx . . $ Temperature#celsius.) { |
| 45 | uicxx . . $ HydrometerTool#ui..calibratedcxx . . $ Ui_HydrometerTool#calibrated.->setMinimumcxx . . $ QDoubleSpinBox#setMinimum(ba8836b59fb42830).(0.0); |
| 46 | uicxx . . $ HydrometerTool#ui..calibratedcxx . . $ Ui_HydrometerTool#calibrated.->setMaximumcxx . . $ QDoubleSpinBox#setMaximum(ba8836b59fb42830).(100.0); |
| 47 | uicxx . . $ HydrometerTool#ui..calibratedcxx . . $ Ui_HydrometerTool#calibrated.->setValuecxx . . $ QDoubleSpinBox#setValue(ba8836b59fb42830).(15.0); |
| 48 | uicxx . . $ HydrometerTool#ui..samplecxx . . $ Ui_HydrometerTool#sample.->setMinimumcxx . . $ QDoubleSpinBox#setMinimum(ba8836b59fb42830).(0.0); |
| 49 | uicxx . . $ HydrometerTool#ui..samplecxx . . $ Ui_HydrometerTool#sample.->setMaximumcxx . . $ QDoubleSpinBox#setMaximum(ba8836b59fb42830).(100.0); |
| 50 | uicxx . . $ HydrometerTool#ui..samplecxx . . $ Ui_HydrometerTool#sample.->setValuecxx . . $ QDoubleSpinBox#setValue(ba8836b59fb42830).(15.0); |
| 51 | } |
| 52 | |
| 53 | // connections |
| 54 | connectcxx . . $ QObject#connect(158df1d9a01a3410).(uicxx . . $ HydrometerTool#ui..samplecxx . . $ Ui_HydrometerTool#sample., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(valueChanged(double)), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(recalc())); |
| 55 | connectcxx . . $ QObject#connect(158df1d9a01a3410).(uicxx . . $ HydrometerTool#ui..calibratedcxx . . $ Ui_HydrometerTool#calibrated., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(valueChanged(double)), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(recalc())); |
| 56 | connectcxx . . $ QObject#connect(158df1d9a01a3410).(uicxx . . $ HydrometerTool#ui..readingcxx . . $ Ui_HydrometerTool#reading., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(valueChanged(double)), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(recalc())); |
| 57 | |
| 58 | recalccxx . . $ HydrometerTool#recalc(49f6e7a06ebc5aa8).(); |
| 59 | } |
| 60 | |
| 61 | ////////////////////////////////////////////////////////////////////////////// |
| 62 | // recalc() |
| 63 | // -------- |
| 64 | // the signal to calculate the actual SG |
| 65 | |
| 66 | void HydrometerToolcxx . . $ HydrometerTool#::recalccxx . . $ HydrometerTool#recalc(49f6e7a06ebc5aa8).() |
| 67 | { |
| 68 | // see http://www.hbd.org/brewery/library/HydromCorr0992.html |
| 69 | |
| 70 | const double COEFF1 = 1.313454; |
| 71 | const double COEFF2 = 0.132674; |
| 72 | const double COEFF3 = 2.057793E-3; |
| 73 | const double COEFF4 = 2.627634E-6; |
| 74 | |
| 75 | double calterm; // E is the correction factor for the calibration temp |
| 76 | double corr; // the corrected reading |
| 77 | |
| 78 | double samp = uicxx . . $ HydrometerTool#ui..samplecxx . . $ Ui_HydrometerTool#sample.->valuecxx . . $ QDoubleSpinBox#value(21b6c25e127938e2).(); |
| 79 | double cal = uicxx . . $ HydrometerTool#ui..calibratedcxx . . $ Ui_HydrometerTool#calibrated.->valuecxx . . $ QDoubleSpinBox#value(21b6c25e127938e2).(); |
| 80 | double read = uicxx . . $ HydrometerTool#ui..readingcxx . . $ Ui_HydrometerTool#reading.->valuecxx . . $ QDoubleSpinBox#value(21b6c25e127938e2).(); |
| 81 | |
| 82 | // calc needs to be in fahrenheit |
| 83 | if (Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->defaultTempUnitcxx . . $ Data#defaultTempUnit(1a4d46a500733df5).() ==cxx . . $ Unit#`operator==`(98df4da96071e2dd). Temperaturecxx . . $ Temperature#::celsiuscxx . . $ Temperature#celsius.) { |
| 84 | samp = celsius2fahrenheitcxx . . $ celsius2fahrenheit(447c67c6676f75c3).(samp); |
| 85 | cal = celsius2fahrenheitcxx . . $ celsius2fahrenheit(447c67c6676f75c3).(cal); |
| 86 | } |
| 87 | |
| 88 | // Correction(@59F) = 1.313454 - 0.132674*T + 2.057793e-3*T**2 - 2.627634e-6*T**3 |
| 89 | // the equation is set up for 59F (15C) |
| 90 | calterm = (COEFF1 |
| 91 | - (COEFF2 * cal) |
| 92 | + (COEFF3 * (cal*cal)) |
| 93 | - (COEFF4 * (cal*cal*cal))); |
| 94 | corr = (COEFF1 |
| 95 | - (COEFF2 * samp) |
| 96 | + (COEFF3 * (samp*samp)) |
| 97 | - (COEFF4 * (samp*samp*samp))) - calterm; |
| 98 | |
| 99 | corr /= 1000.0; |
| 100 | corr = 1.0 - corr; |
| 101 | corr = read / corr; |
| 102 | |
| 103 | // now that we have the value change the reading |
| 104 | uicxx . . $ HydrometerTool#ui..correctedcxx . . $ Ui_HydrometerTool#corrected.->setTextcxx . . $ QLabel#setText(3520e46b33348bf6).(QStringcxx . . $ QString#::numbercxx . . $ QString#number(ac5d358e2e30f7ea).(corr, 'f', 3)); |
| 105 | } |