File indexing completed on 2024-04-21 03:41:38
0001 /* 0002 SPDX-FileCopyrightText: 2009 Kashyap R Puranik <kashthealien@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef GASCALCULATOR_H 0008 #define GASCALCULATOR_H 0009 0010 #include "kalzium_debug.h" 0011 0012 #include <KUnitConversion/Converter> 0013 #include <KUnitConversion/UnitCategory> 0014 0015 #include <kalziumdataobject.h> 0016 0017 #include "ui_gasCalculator.h" 0018 0019 // The universal Gas constant is defined here. 0020 const double R = 0.08206; 0021 0022 using namespace KUnitConversion; 0023 0024 /// This is the enumeration for the error type required in the error(int mode) function 0025 enum ERROR_TYPE_GAS { RESET_GAS_MESSAGE = 0, VOL_ZERO, GAS_MOLAR_MASS_ZERO }; 0026 0027 /// This is the enumeration for the mode of calculation for the gas calculator 0028 enum MODE_CALCULATION_GAS { MOLES = 0, PRESSURE, TEMPERATURE, VOLUME }; 0029 0030 /** 0031 * This class implements the gas calculator. It performs basic calculations like 0032 * calculation of volume given pressure, temperature, amount etc. and so on. 0033 * 0034 * Van der Val's gas equation 0035 * ( P + n^2 a / V^2) ( V - nb ) = nRT 0036 * 0037 * where P - pressure 0038 * V - Volume 0039 * n - number of moles 0040 * R - Universal gas constant 0041 * T - temperature 0042 * 0043 * a,b - Van der Val's constants 0044 * 0045 * @author Kashyap R Puranik 0046 **/ 0047 class gasCalculator : public QWidget 0048 { 0049 Q_OBJECT 0050 0051 public: 0052 explicit gasCalculator(QWidget *parent = nullptr); 0053 ~gasCalculator() override; 0054 0055 public Q_SLOTS: 0056 /// Calculates the Pressure and updates the UI 0057 void calculatePressure(); 0058 0059 /// Calculates the Volume and updates the UI 0060 void calculateVol(); 0061 0062 /// Calculates the Temperature and updates the UI 0063 void calculateTemp(); 0064 0065 /// Calculates the number of moles and updates the UI 0066 void calculateMoles(); 0067 0068 /// Calculates the mass of substance and updates the UI 0069 void calculateMass(); 0070 0071 /// Calculates the molar mass of the substance and updates the UI 0072 void calculateMolarMass(); 0073 0074 /// Functions (slots) that occur on changing a value 0075 /// This function is called when the volume is changed 0076 void volChanged(); 0077 0078 /// This function is called when the temperature is changed 0079 void tempChanged(); 0080 0081 /// This function is called when the pressure is changed 0082 void pressureChanged(); 0083 0084 /// This function is called when the mass is changed 0085 void massChanged(); 0086 0087 /** 0088 * This function is called when the number of moles is changed 0089 * @param value is the number of moles 0090 **/ 0091 void molesChanged(double value); 0092 0093 /** 0094 * This function is called when the molar mass is changed 0095 * @param value is the molar mass 0096 **/ 0097 void molarMassChanged(double value); 0098 0099 /// This function is called when Vander Val's constant a is changed 0100 void Vand_aChanged(); 0101 0102 /// This function is called when Vander Val's constant b is changed 0103 void Vand_bChanged(); 0104 0105 /// This function is called when any quantity is changed 0106 void calculate(); 0107 0108 /** 0109 * This function is called when an error occurs 0110 * @param mode indicates the mode of error 0111 * Refer ERROR_MODE_GAS for various modes 0112 **/ 0113 void error(int); 0114 0115 /** 0116 * This function is called when the mode is changed 0117 * @param indicates the mode of calculation. 0118 * Refer MODE_CALCULATION_GAS for various modes 0119 **/ 0120 void setMode(int); 0121 0122 void init(); 0123 0124 private: 0125 void setupUnitComboboxes(); 0126 void populateUnitCombobox(QComboBox *comboBox, const QList<int> &unitList); 0127 0128 int getCurrentUnitId(QComboBox *comboBox); 0129 0130 Ui::gasCalculator ui; 0131 0132 double m_moles; 0133 double m_molarMass; 0134 Value m_mass; 0135 Value m_temp; 0136 Value m_pressure; 0137 Value m_vol; 0138 Value m_Vand_b; 0139 double m_Vand_a; 0140 0141 int m_mode; 0142 }; 0143 0144 #endif // GASCALCULATOR_H