Skip to content

Commit 14013a8

Browse files
committed
Seperated sanity checks and eroor mesaages
1 parent a4af45f commit 14013a8

2 files changed

Lines changed: 149 additions & 104 deletions

File tree

src/app/parameters.cpp

Lines changed: 140 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//**********************************************************************
55

66
#include "parameters.h"
7-
#include "qcombobox.h"
8-
#include "qradiobutton.h"
7+
#include <QComboBox>
8+
#include <QRadioButton>
99
#include <QMessageBox>
1010

1111
parameters::parameters(void)
@@ -20,199 +20,235 @@ parameters::~parameters(void)
2020
bool parameters::CheckCommonParameters(QRadioButton *radioButton_MonoDisperse,
2121
QRadioButton *radioButton_NumDen,
2222
QRadioButton *radioButton_VolFrac)
23+
{
24+
bool monoDisperseSelection = false;
25+
bool numDenSelection = false;
26+
bool volFracSelection = false;
27+
28+
if (radioButton_MonoDisperse->isChecked())
29+
monoDisperseSelection = true;
30+
if (radioButton_NumDen->isChecked())
31+
numDenSelection = true;
32+
if (radioButton_VolFrac->isChecked())
33+
volFracSelection = true;
34+
35+
ParameterValidationResult check = CheckValidityCommonParameters(monoDisperseSelection,
36+
numDenSelection,volFracSelection);
37+
if (!check.isValid)
38+
{
39+
QMessageBox msgBoxError;
40+
msgBoxError.setWindowTitle("Error");
41+
msgBoxError.setIcon(QMessageBox::Critical);
42+
msgBoxError.setText(check.errorMessage);
43+
msgBoxError.exec();
44+
return false;
45+
}
46+
else
47+
return true;
48+
}
49+
50+
ParameterValidationResult parameters::CheckValidityCommonParameters(
51+
bool monoDisperseSelection,
52+
bool numDenSelection,
53+
bool volFracSelection)
2354
{
24-
QMessageBox msgBox, msgBoxWarn;
25-
msgBox.setWindowTitle("Error");
26-
msgBox.setIcon(QMessageBox::Critical);
27-
msgBoxWarn.setWindowTitle("Warning");
28-
msgBoxWarn.setIcon(QMessageBox::Warning);
55+
ParameterValidationResult result;
56+
result.isValid = true;
2957

3058
if ((scatRefReal <= 0.0) || (medRef <= 0.0))
3159
{
32-
msgBox.setText("Refractive index cannot be zero");
33-
msgBox.exec();
34-
return 1;
60+
result.isValid = false;
61+
result.errorMessage = "Refractive index cannot be zero.";
62+
return result;
63+
3564
}
3665
if ((scatRefReal/medRef == 1.0))
3766
{
38-
msgBox.setText("Relative refractive index cannot be 1.0");
39-
msgBox.exec();
40-
return 1;
67+
result.isValid = false;
68+
result.errorMessage = "Relative refractive index cannot be 1.0.";
69+
return result;
4170
}
4271
double m = scatRefReal / medRef;
4372
if ((m < 0.05) || (m > 5.0))
4473
{
45-
msgBoxWarn.setText("Unrealistic relative refractive index.");
46-
msgBoxWarn.setInformativeText("Check sphere and medium refractive index values");
47-
msgBoxWarn.exec();
48-
return 1;
74+
result.isValid = false;
75+
result.errorMessage = "Unrealistic relative refractive index! Check sphere and medium refractive index values.";
76+
return result;
4977
}
5078
if (scatRefImag >= 5.0)
5179
{
52-
msgBox.setText("Imaginary refractive index must be negative or less than 5.0.");
53-
msgBox.exec();
54-
return 1;
80+
result.isValid = false;
81+
result.errorMessage = "Imaginary refractive index must be negative or less than 5.0.";
82+
return result;
5583
}
5684
//Avoid zeros
5785
if ((startWavel <= 0.0) || (endWavel <= 0.0))
5886
{
59-
msgBox.setText("The starting or ending wavelength cannot be zero");
60-
msgBox.exec();
61-
return 1;
87+
result.isValid = false;
88+
result.errorMessage = "The starting or ending wavelength cannot be zero.";
89+
return result;
6290
}
6391
//Avoid zeros
6492
if (stepWavel <= 0.0)
6593
{
66-
msgBox.setText("Wavelength step cannot be zero");
67-
msgBox.exec();
68-
return 1;
94+
result.isValid = false;
95+
result.errorMessage = "Wavelength step cannot be zero.";
96+
return result;
6997
}
7098
if (startWavel < 50.0)
7199
{
72-
msgBox.setText("Minimum wavlength is 50nm");
73-
msgBox.exec();
74-
return 1;
100+
result.isValid = false;
101+
result.errorMessage = "Current minimum wavlength is 50nm.";
102+
return result;
75103
}
76104
if (endWavel > 3000.0)
77105
{
78-
msgBox.setText("Maximum wavlength is 3000nm");
79-
msgBox.exec();
80-
return 1;
106+
result.isValid = false;
107+
result.errorMessage = "Current maximum wavlength is 3000nm.";
108+
return result;
81109
}
82110
if (endWavel - startWavel < 0.0)
83111
{
84-
msgBox.setText("The starting wavelength is greater than the ending wavelength");
85-
msgBox.exec();
86-
return 1;
112+
result.isValid = false;
113+
result.errorMessage = "The starting wavelength is greater than the ending wavelength.";
114+
return result;
87115
}
88-
if (radioButton_NumDen->isChecked())
116+
if (numDenSelection)
89117
{
90118
if (sphNumDensity <= 0.0)
91119
{
92-
msgBox.setText("Sphere concentration cannot be zero");
93-
msgBox.exec();
94-
return 1;
120+
result.isValid = false;
121+
result.errorMessage = "Sphere concentration cannot be zero.";
122+
return result;
95123
}
96124
}
97-
if (radioButton_VolFrac->isChecked())
125+
if (volFracSelection)
98126
{
99127
if (volFraction <= 0.0)
100128
{
101-
msgBox.setText("Volume Fraction cannot be zero");
102-
msgBox.exec();
103-
return 1;
129+
result.isValid = false;
130+
result.errorMessage = "Volume Fraction cannot be zero.";
131+
return result;
104132
}
105133

106134
if (volFraction >= 1.0)
107135
{
108-
msgBox.setText("Volume Fraction cannot exceed 1.0");
109-
msgBox.exec();
110-
return 1;
136+
result.isValid = false;
137+
result.errorMessage = "Volume Fraction cannot exceed 1.0.";
138+
return result;
111139
}
112140
}
113141
if ((meanRadius < 0.00005) ||(meanRadius >150))
114142
{
115-
msgBox.setText("Diameter is out of range!");
116-
msgBox.setInformativeText("Enter a value between 0.0001μm and 300μm");
117-
msgBox.exec();
118-
return 1;
143+
result.isValid = false;
144+
result.errorMessage = "Diameter is out of range! Enter a value between 0.0001μm and 300μm.";
145+
return result;
119146
}
120-
if (radioButton_MonoDisperse->isChecked())
147+
if (monoDisperseSelection)
121148
{
122-
if (radioButton_NumDen->isChecked())
149+
if (numDenSelection)
123150
{
124151
double volume = 4.0 * M_PI *meanRadius * meanRadius * meanRadius / 3.0;
125152
if (sphNumDensity*volume >= 1e9)
126153
{
127-
msgBoxWarn.setText("Concentration x Sphere Volume exceeds 1mm³.");
128-
msgBoxWarn.setInformativeText("Reduce Concentration.");
129-
msgBoxWarn.exec();
130-
return 1;
154+
result.isValid = false;
155+
result.errorMessage = "Concentration x Sphere Volume exceeds 1mm³! Reduce Concentration (Conc).";
156+
return result;
131157
}
132158
}
133159
}
134-
return 0;
160+
return result;
135161
}
136162

163+
//Check the validity of Distribution parameters
137164
bool parameters::CheckDistributionParameters(QComboBox *comboBox_Distribution)
138165
{
139-
QMessageBox msgBox;
140-
msgBox.setWindowTitle("Error");
166+
int comboBoxIndex =0;
167+
168+
if (comboBox_Distribution->currentIndex() == 0)
169+
comboBoxIndex = 0;
170+
if (comboBox_Distribution->currentIndex() == 1)
171+
comboBoxIndex = 1;
172+
173+
ParameterValidationResult check = CheckValidityDistributionParameters(comboBoxIndex);
174+
175+
if (!check.isValid)
176+
{
177+
QMessageBox msgBoxError;
178+
msgBoxError.setWindowTitle("Error");
179+
msgBoxError.setIcon(QMessageBox::Critical);
180+
msgBoxError.setText(check.errorMessage);
181+
msgBoxError.exec();
182+
return false;
183+
}
184+
else
185+
return true;
186+
}
187+
188+
ParameterValidationResult parameters::CheckValidityDistributionParameters(int comboBoxIndex)
189+
{
190+
ParameterValidationResult result;
191+
result.isValid = true;
141192

142193
if (stdDev == 0.0)
143194
{
144-
msgBox.setText("Standard Deviation is zero.");
145-
msgBox.setInformativeText("Use 'Mono Disperse'.");
146-
msgBox.exec();
147-
return 1;
195+
result.isValid = false;
196+
result.errorMessage = "Standard Deviation is zero! Use 'Mono Disperse'.";
197+
return result;
148198
}
149-
if(comboBox_Distribution->currentIndex() == 0)
199+
if(comboBoxIndex == 0)
150200
{
151201
if (stdDev > 3.0)
152202
{
153-
msgBox.setIcon(QMessageBox::Critical);
154-
msgBox.setText("Large standard deviation provides an abnormal Log Normal distribution.");
155-
msgBox.setInformativeText("The limit was set to 3.0μm.");
156-
msgBox.exec();
157-
return 1;
203+
result.isValid = false;
204+
result.errorMessage = "Large standard deviation provides an abnormal Log Normal distribution! Current limit for Log Normal is 3.0μm.";
205+
return result;
158206
}
159207
if (stdDev < 1e-5)
160208
{
161-
msgBox.setIcon(QMessageBox::Critical);
162-
msgBox.setText("The standard deviation is too small.");
163-
msgBox.setInformativeText("Use 'Mono Disperse'.");
164-
msgBox.exec();
165-
return 1;
209+
result.isValid = false;
210+
result.errorMessage = "The standard deviation is too small! Use 'Mono Disperse'.";
211+
return result;
166212
}
167213
}
168-
169-
if(comboBox_Distribution->currentIndex() == 1)
214+
if(comboBoxIndex == 1)
170215
{
171216
if (stdDev > 50.0)
172217
{
173-
msgBox.setIcon(QMessageBox::Critical);
174-
msgBox.setText("The standard deviation is too large.");
175-
msgBox.setInformativeText("The limit was set to 50.0μm.");
176-
msgBox.exec();
177-
return 1;
218+
result.isValid = false;
219+
result.errorMessage = "The standard deviation is too large! Current limit for Gaussian is 50.0μm.";
220+
return result;
178221
}
179222
if (stdDev < 1e-8)
180223
{
181-
msgBox.setIcon(QMessageBox::Critical);
182-
msgBox.setText("The standard deviation is too small.");
183-
msgBox.setInformativeText("Use 'Mono Disperse'.");
184-
msgBox.exec();
185-
return 1;
224+
result.isValid = false;
225+
result.errorMessage = "The standard deviation is too small! Use 'Mono Disperse'.";
226+
return result;
186227
}
187228
}
188229
if (nRadius == 1)
189230
{
190-
msgBox.setText("Discrete sphere size is 1. ");
191-
msgBox.setInformativeText("Use 'Mono Disperse'.");
192-
msgBox.exec();
193-
return 1;
231+
result.isValid = false;
232+
result.errorMessage = "Discrete sphere size is 1! Use 'Mono Disperse'.";
233+
return result;
194234
}
195235
if ((nRadius < 2.0) ||(nRadius >101.0))
196236
{
197-
msgBox.setText("Number of sphere sizes is out of range.");
198-
msgBox.setInformativeText("Enter a value between 2 and 101.");
199-
msgBox.exec();
200-
return 1;
237+
result.isValid = false;
238+
result.errorMessage = "Number of sphere sizes is out of range! Enter a value between 2 and 101.";
239+
return result;
201240
}
202241
if ((meanRadius < 0.0005) ||(meanRadius >25))
203242
{
204-
msgBox.setText("Diameter is out of range.");
205-
msgBox.setInformativeText("Enter a value between 0.001μm and 50μm.");
206-
msgBox.exec();
207-
return 1;
243+
result.isValid = false;
244+
result.errorMessage = "Diameter is out of range! Enter a value between 0.001μm and 50μm.";
245+
return result;
208246
}
209247
if (stdDev/meanRadius < 1.999e-5)
210248
{
211-
msgBox.setIcon(QMessageBox::Critical);
212-
msgBox.setText("Standard deviation to mean diameter ratio is smaller than 1e-5.");
213-
msgBox.setInformativeText("Use 'Mono Disperse'");
214-
msgBox.exec();
215-
return 1;
249+
result.isValid = false;
250+
result.errorMessage = "Standard deviation to mean diameter ratio is smaller than 1e-5! Use 'Mono Disperse'.";
251+
return result;
216252
}
217-
return 0;
253+
return result;
218254
}

src/app/parameters.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
#include <QRadioButton>
88
#include <QComboBox>
99

10+
struct ParameterValidationResult {
11+
bool isValid;
12+
QString errorMessage;
13+
};
14+
1015
class parameters
1116
{
1217
public:
@@ -17,6 +22,10 @@ class parameters
1722
QRadioButton *radioButton_NumDen,
1823
QRadioButton *radioButton_VolFrac);
1924
bool CheckDistributionParameters(QComboBox *comboBox_Distribution);
25+
ParameterValidationResult CheckValidityCommonParameters(bool monoDisperseSelection,
26+
bool numDenSelection,
27+
bool volFracSelection);
28+
ParameterValidationResult CheckValidityDistributionParameters(int comboBoxIndex);
2029

2130

2231
double *radArray = nullptr; // radArray: radius Array

0 commit comments

Comments
 (0)