From 3b01893cebbddfeabeefde007b65a430f6267d70 Mon Sep 17 00:00:00 2001
From: Dmitry Yurov <d.yurov@fz-juelich.de>
Date: Fri, 8 Mar 2019 16:00:00 +0100
Subject: [PATCH] Add SpecularSimulation::setScan method

---
 Core/Simulation/SpecularSimulation.cpp | 19 +++++++++++++++++++
 Core/Simulation/SpecularSimulation.h   |  3 +++
 2 files changed, 22 insertions(+)

diff --git a/Core/Simulation/SpecularSimulation.cpp b/Core/Simulation/SpecularSimulation.cpp
index e1550c91a4f..c6a22c8339e 100644
--- a/Core/Simulation/SpecularSimulation.cpp
+++ b/Core/Simulation/SpecularSimulation.cpp
@@ -89,6 +89,25 @@ SimulationResult SpecularSimulation::result() const
     return SimulationResult(*data, *converter);
 }
 
+void SpecularSimulation::setScan(const ISpecularScan& scan)
+{
+    // TODO: move inside AngularSpecScan when pointwise resolution is implemented
+    if (scan.coordinateAxis()->getMin() < 0.0)
+        throw std::runtime_error(
+            "Error in SpecularSimulation::setScan: minimum value on coordinate axis is negative.");
+
+    m_data_handler.reset(scan.clone());
+
+    SpecularDetector1D detector(*scan.coordinateAxis());
+    m_instrument.setDetector(detector);
+
+    // TODO: remove when pointwise resolution is implemented
+    if (scan.dataType() == ISpecularScan::angle) {
+        const auto& angular_scan = static_cast<const AngularSpecScan&>(scan);
+        m_instrument.setBeamParameters(angular_scan.wavelength(), zero_alpha_i, zero_phi_i);
+    }
+}
+
 void SpecularSimulation::setBeamParameters(double lambda, const IAxis& alpha_axis,
                                            const IFootprintFactor* beam_shape)
 {
diff --git a/Core/Simulation/SpecularSimulation.h b/Core/Simulation/SpecularSimulation.h
index 70c789478d2..601e2c2ecdd 100644
--- a/Core/Simulation/SpecularSimulation.h
+++ b/Core/Simulation/SpecularSimulation.h
@@ -53,6 +53,9 @@ public:
     //! zeros.
     SimulationResult result() const override;
 
+    //! Sets chosen specular scan to the simulation.
+    void setScan(const ISpecularScan& scan);
+
     void setBeamParameters(double lambda, int nbins, double alpha_i_min, double alpha_i_max,
                            const IFootprintFactor* beam_shape = nullptr);
     void setBeamParameters(double lambda, std::vector<double> incident_angle_values,
-- 
GitLab