Skip to content
Snippets Groups Projects
Commit 5083b9a8 authored by Matthias Puchner's avatar Matthias Puchner
Browse files

split computation method setting in two methods; use string constants

parent 85adde49
No related branches found
No related tags found
1 merge request!217Refactor SimulationOptionsItem for strong typed methods
Pipeline #41779 passed
......@@ -36,6 +36,14 @@ const QString tooltip_ambientmaterial =
const QString tooltip_specularpeak =
"Defines if the specular peak should be included in the simulation result";
const QString Immediately = "Immediately";
const QString InBackground = "In background";
const QString Analytical = "Analytical";
const QString MonteCarlo = "Monte-Carlo Integration";
const QString AmbientLayerMaterial = "Ambient Layer Material";
const QString AverageLayerMaterial = "Average Layer Material";
const QString Yes = "Yes";
const QString No = "No";
} // namespace
const QString SimulationOptionsItem::P_RUN_POLICY = "Run Policy";
......@@ -61,21 +69,18 @@ SimulationOptionsItem::SimulationOptionsItem() : SessionItem(M_TYPE)
addProperty(P_NTHREADS, nthreads.variant())->setToolTip(tooltip_nthreads);
ComboProperty computationMethod;
computationMethod << "Analytical"
<< "Monte-Carlo Integration";
computationMethod << Analytical << MonteCarlo;
addProperty(P_COMPUTATION_METHOD, computationMethod.variant())->setToolTip(tooltip_computation);
addProperty(P_MC_POINTS, 100)->setEnabled(false);
ComboProperty averageLayerMaterials;
averageLayerMaterials << "Ambient Layer Material"
<< "Average Layer Material";
averageLayerMaterials << AmbientLayerMaterial << AverageLayerMaterial;
addProperty(P_FRESNEL_MATERIAL_METHOD, averageLayerMaterials.variant())
->setToolTip(tooltip_ambientmaterial);
ComboProperty includeSpecularPeak;
includeSpecularPeak << "No"
<< "Yes";
includeSpecularPeak << No << Yes;
addProperty(P_INCLUDE_SPECULAR_PEAK, includeSpecularPeak.variant())
->setToolTip(tooltip_specularpeak);
......@@ -83,17 +88,14 @@ SimulationOptionsItem::SimulationOptionsItem() : SessionItem(M_TYPE)
if (name == P_COMPUTATION_METHOD && isTag(P_MC_POINTS)) {
ComboProperty combo = getItemValue(P_COMPUTATION_METHOD).value<ComboProperty>();
if (combo.getValue() == "Analytical") {
if (combo.getValue() == Analytical)
getItem(P_MC_POINTS)->setEnabled(false);
} else {
else
getItem(P_MC_POINTS)->setEnabled(true);
}
} else if (name == P_NTHREADS) {
} else if (name == P_NTHREADS)
updateComboItem(P_NTHREADS, getCPUUsageOptions());
} else if (name == P_RUN_POLICY) {
else if (name == P_RUN_POLICY)
updateComboItem(P_RUN_POLICY, getRunPolicyNames());
}
});
}
......@@ -117,17 +119,17 @@ void SimulationOptionsItem::setNumberOfThreads(int number)
bool SimulationOptionsItem::runImmediately() const
{
return runPolicy() == "Immediately";
return runPolicy() == Immediately;
}
bool SimulationOptionsItem::runInBackground() const
{
return runPolicy() == "In background";
return !runImmediately();
}
void SimulationOptionsItem::setRunImmediately(bool runImmediately)
{
setRunPolicy(runImmediately ? "Immediately" : "In background");
setRunPolicy(runImmediately ? Immediately : InBackground);
}
void SimulationOptionsItem::setRunPolicy(const QString& policy)
......@@ -137,19 +139,20 @@ void SimulationOptionsItem::setRunPolicy(const QString& policy)
setItemValue(P_RUN_POLICY, combo.variant());
}
void SimulationOptionsItem::setMonteCarloIntegration(bool useMonteCarlo, int numberOfPoints)
void SimulationOptionsItem::setUseMonteCarloIntegration(int numberOfPoints)
{
if (useMonteCarlo) {
setComputationMethod("Monte-Carlo Integration");
setNumberOfMonteCarloPoints(numberOfPoints);
} else {
setComputationMethod("Analytical");
}
setComputationMethod(MonteCarlo);
setNumberOfMonteCarloPoints(numberOfPoints);
}
void SimulationOptionsItem::setUseAnalytical()
{
setComputationMethod(Analytical);
}
bool SimulationOptionsItem::useMonteCarloIntegration() const
{
return getComputationMethod().startsWith("Mon");
return getComputationMethod() == MonteCarlo;
}
void SimulationOptionsItem::setComputationMethod(const QString& name)
......@@ -177,13 +180,12 @@ void SimulationOptionsItem::setNumberOfMonteCarloPoints(int npoints)
void SimulationOptionsItem::setUseAverageMaterials(bool useAverageMaterials)
{
setFresnelMaterialMethod(useAverageMaterials ? "Average Layer Material"
: "Ambient Layer Material");
setFresnelMaterialMethod(useAverageMaterials ? AverageLayerMaterial : AmbientLayerMaterial);
}
bool SimulationOptionsItem::useAverageMaterials() const
{
return getFresnelMaterialMethod().startsWith("Aver");
return getFresnelMaterialMethod() == AverageLayerMaterial;
}
void SimulationOptionsItem::setFresnelMaterialMethod(const QString& name)
......@@ -202,14 +204,14 @@ QString SimulationOptionsItem::getFresnelMaterialMethod() const
void SimulationOptionsItem::setIncludeSpecularPeak(bool includeSpecularPeak)
{
ComboProperty combo = getItemValue(P_INCLUDE_SPECULAR_PEAK).value<ComboProperty>();
combo.setValue(includeSpecularPeak ? "Yes" : "No");
combo.setValue(includeSpecularPeak ? Yes : No);
setItemValue(P_INCLUDE_SPECULAR_PEAK, combo.variant());
}
bool SimulationOptionsItem::includeSpecularPeak() const
{
ComboProperty combo = getItemValue(P_INCLUDE_SPECULAR_PEAK).value<ComboProperty>();
return combo.getValue() == "Yes";
return combo.getValue() == Yes;
}
SessionItem* SimulationOptionsItem::monteCarloPointsItem() const
......@@ -247,8 +249,7 @@ QStringList SimulationOptionsItem::getCPUUsageOptions()
QStringList SimulationOptionsItem::getRunPolicyNames()
{
QStringList result;
result << "Immediately"
<< "In background";
result << Immediately << InBackground;
return result;
}
......
......@@ -43,7 +43,8 @@ public:
bool runImmediately() const;
bool runInBackground() const;
void setMonteCarloIntegration(bool useMonteCarlo, int numberOfPoints = 50);
void setUseMonteCarloIntegration(int numberOfPoints);
void setUseAnalytical();
bool useMonteCarloIntegration() const;
void setNumberOfMonteCarloPoints(int npoints);
......
......@@ -38,6 +38,6 @@ TEST_F(TestMapperCases, test_SimulationOptionsComputationToggle)
EXPECT_EQ(item->useMonteCarloIntegration(), false);
EXPECT_FALSE(item->monteCarloPointsItem()->isEnabled());
item->setMonteCarloIntegration(true);
item->setUseMonteCarloIntegration(100);
EXPECT_TRUE(item->monteCarloPointsItem()->isEnabled());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment