From ee7cab36f4629f72720ebd8cbc452f7b6fe83781 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Fri, 23 Apr 2021 15:13:03 +0200
Subject: [PATCH] megre 2 source pairs to treat DepthProbe on par with other
 simulations

---
 .../Models/DepthProbeInstrumentItem.cpp       | 99 -------------------
 GUI/coregui/Models/DepthProbeInstrumentItem.h | 43 --------
 GUI/coregui/Models/DomainObjectBuilder.cpp    |  2 +-
 .../Models/DomainSimulationBuilder.cpp        |  7 +-
 GUI/coregui/Models/InstrumentItems.cpp        | 89 ++++++++++++++++-
 GUI/coregui/Models/InstrumentItems.h          | 23 ++++-
 GUI/coregui/Models/ItemCatalog.cpp            |  2 +-
 GUI/coregui/Models/JobModelFunctions.cpp      |  1 -
 GUI/coregui/Models/SessionDecorationModel.cpp |  1 -
 .../DepthProbeInstrumentEditor.cpp            |  2 +-
 .../InstrumentWidgets/InstrumentPresenter.cpp |  1 -
 .../InstrumentViewActions.cpp                 |  1 -
 12 files changed, 117 insertions(+), 154 deletions(-)
 delete mode 100644 GUI/coregui/Models/DepthProbeInstrumentItem.cpp
 delete mode 100644 GUI/coregui/Models/DepthProbeInstrumentItem.h

diff --git a/GUI/coregui/Models/DepthProbeInstrumentItem.cpp b/GUI/coregui/Models/DepthProbeInstrumentItem.cpp
deleted file mode 100644
index afea9a15517..00000000000
--- a/GUI/coregui/Models/DepthProbeInstrumentItem.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-//  ************************************************************************************************
-//
-//  BornAgain: simulate and fit reflection and scattering
-//
-//! @file      GUI/coregui/Models/DepthProbeInstrumentItem.cpp
-//! @brief     Implements DepthProbeInstrumentItem class
-//!
-//! @homepage  http://www.bornagainproject.org
-//! @license   GNU General Public License v3 or higher (see COPYING)
-//! @copyright Forschungszentrum Jülich GmbH 2018
-//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
-//
-//  ************************************************************************************************
-
-#include "GUI/coregui/Models/DepthProbeInstrumentItem.h"
-#include "Base/Const/Units.h"
-#include "Core/Simulation/DepthProbeSimulation.h"
-#include "GUI/coregui/Models/AxesItems.h"
-#include "GUI/coregui/Models/BeamItems.h"
-#include "GUI/coregui/Models/BeamWavelengthItem.h"
-#include "GUI/coregui/Models/SpecularBeamInclinationItem.h"
-#include "GUI/coregui/Models/TransformToDomain.h"
-
-const QString DepthProbeInstrumentItem::P_BEAM = "Beam";
-const QString DepthProbeInstrumentItem::P_Z_AXIS = "Z axis";
-
-DepthProbeInstrumentItem::DepthProbeInstrumentItem() : InstrumentItem("DepthProbeInstrument")
-{
-    setItemName("DepthProbeInstrument");
-
-    addProperty<SpecularBeamItem>(P_BEAM);
-
-    auto axisItem = beamItem()->currentInclinationAxisItem();
-    axisItem->setLowerBound(0.0);
-    axisItem->setUpperBound(1.0);
-    axisItem->setBinCount(500);
-
-    auto axis = addProperty<BasicAxisItem>(P_Z_AXIS);
-    axis->setLowerBound(-100.0);
-    axis->setUpperBound(100.0);
-    axis->getItem(BasicAxisItem::P_TITLE)->setVisible(false);
-    axis->getItem(BasicAxisItem::P_NBINS)
-        ->setToolTip("Number of points in scan across sample bulk");
-    axis->getItem(BasicAxisItem::P_MIN_DEG)
-        ->setToolTip("Starting value below sample horizont in nm");
-    axis->getItem(BasicAxisItem::P_MAX_DEG)->setToolTip("Ending value above sample horizont in nm");
-}
-
-SpecularBeamItem* DepthProbeInstrumentItem::beamItem() const
-{
-    return item<SpecularBeamItem>(P_BEAM);
-}
-
-std::unique_ptr<Instrument> DepthProbeInstrumentItem::createInstrument() const
-{
-    throw std::runtime_error("DepthProbeInstrumentItem::createInstrument()");
-}
-
-std::vector<int> DepthProbeInstrumentItem::shape() const
-{
-    return std::vector<int>(); // no certain shape to avoid linking to real data
-}
-
-void DepthProbeInstrumentItem::updateToRealData(const RealDataItem*)
-{
-    throw std::runtime_error("DepthProbeInstrumentItem::updateToRealData()");
-}
-
-QString DepthProbeInstrumentItem::defaultName() const
-{
-    return "DepthProbe";
-}
-
-std::unique_ptr<DepthProbeSimulation> DepthProbeInstrumentItem::createSimulation() const
-{
-    std::unique_ptr<DepthProbeSimulation> simulation = std::make_unique<DepthProbeSimulation>();
-
-    const auto axis_item = beamItem()->currentInclinationAxisItem();
-
-    auto axis = axis_item->createAxis(Units::deg);
-
-    simulation->setBeamParameters(beamItem()->wavelength(), static_cast<int>(axis->size()),
-                                  axis->lowerBound(), axis->upperBound());
-
-    auto depthAxisItem = dynamic_cast<BasicAxisItem*>(getItem(P_Z_AXIS));
-    auto depthAxis = depthAxisItem->createAxis(1.0);
-    simulation->setZSpan(depthAxis->size(), depthAxis->lowerBound(), depthAxis->upperBound());
-
-    TransformToDomain::setBeamDistribution(
-        "Wavelength", *beamItem()->item<BeamWavelengthItem>(SpecularBeamItem::P_WAVELENGTH),
-        *simulation.get());
-
-    TransformToDomain::setBeamDistribution(
-        "InclinationAngle",
-        *beamItem()->item<SpecularBeamInclinationItem>(SpecularBeamItem::P_INCLINATION_ANGLE),
-        *simulation.get());
-
-    return simulation;
-}
diff --git a/GUI/coregui/Models/DepthProbeInstrumentItem.h b/GUI/coregui/Models/DepthProbeInstrumentItem.h
deleted file mode 100644
index ba1f29d09a0..00000000000
--- a/GUI/coregui/Models/DepthProbeInstrumentItem.h
+++ /dev/null
@@ -1,43 +0,0 @@
-//  ************************************************************************************************
-//
-//  BornAgain: simulate and fit reflection and scattering
-//
-//! @file      GUI/coregui/Models/DepthProbeInstrumentItem.h
-//! @brief     Defines DepthProbeInstrumentItem class
-//!
-//! @homepage  http://www.bornagainproject.org
-//! @license   GNU General Public License v3 or higher (see COPYING)
-//! @copyright Forschungszentrum Jülich GmbH 2018
-//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
-//
-//  ************************************************************************************************
-
-#ifndef BORNAGAIN_GUI_COREGUI_MODELS_DEPTHPROBEINSTRUMENTITEM_H
-#define BORNAGAIN_GUI_COREGUI_MODELS_DEPTHPROBEINSTRUMENTITEM_H
-
-#include "GUI/coregui/Models/InstrumentItems.h"
-
-class DepthProbeSimulation;
-
-//! Depth probe instrument.
-
-class BA_CORE_API_ DepthProbeInstrumentItem : public InstrumentItem {
-public:
-    static const QString P_BEAM;
-    static const QString P_Z_AXIS;
-
-    DepthProbeInstrumentItem();
-
-    SpecularBeamItem* beamItem() const override;
-
-    std::unique_ptr<Instrument> createInstrument() const override;
-    std::vector<int> shape() const override;
-    void updateToRealData(const RealDataItem* item) override;
-    virtual QString defaultName() const override;
-
-    // FIXME switch to base ISimulation class after InstrumentItem refactoring and
-    // after ISimulation gets createUnitConverter method
-    std::unique_ptr<DepthProbeSimulation> createSimulation() const;
-};
-
-#endif // BORNAGAIN_GUI_COREGUI_MODELS_DEPTHPROBEINSTRUMENTITEM_H
diff --git a/GUI/coregui/Models/DomainObjectBuilder.cpp b/GUI/coregui/Models/DomainObjectBuilder.cpp
index a2a359ef452..d7489d73fd7 100644
--- a/GUI/coregui/Models/DomainObjectBuilder.cpp
+++ b/GUI/coregui/Models/DomainObjectBuilder.cpp
@@ -20,8 +20,8 @@
 #include "Device/Detector/UnitConverter2D.h"
 #include "GUI/coregui/Models/AxesItems.h"
 #include "GUI/coregui/Models/ComboProperty.h"
-#include "GUI/coregui/Models/DepthProbeInstrumentItem.h"
 #include "GUI/coregui/Models/InterferenceFunctionItems.h"
+#include "GUI/coregui/Models/InstrumentItems.h"
 #include "GUI/coregui/Models/LayerItem.h"
 #include "GUI/coregui/Models/ParticleDistributionItem.h"
 #include "GUI/coregui/Models/ParticleLayoutItem.h"
diff --git a/GUI/coregui/Models/DomainSimulationBuilder.cpp b/GUI/coregui/Models/DomainSimulationBuilder.cpp
index 6d63782be56..907bd0f2812 100644
--- a/GUI/coregui/Models/DomainSimulationBuilder.cpp
+++ b/GUI/coregui/Models/DomainSimulationBuilder.cpp
@@ -20,10 +20,10 @@
 #include "Device/Beam/IFootprintFactor.h"
 #include "GUI/coregui/Models/AxesItems.h"
 #include "GUI/coregui/Models/BackgroundItems.h"
-#include "GUI/coregui/Models/DepthProbeInstrumentItem.h"
 #include "GUI/coregui/Models/DetectorItems.h"
 #include "GUI/coregui/Models/DomainObjectBuilder.h"
 #include "GUI/coregui/Models/FootprintItems.h"
+#include "GUI/coregui/Models/InstrumentItems.h"
 #include "GUI/coregui/Models/MultiLayerItem.h"
 #include "GUI/coregui/Models/SimulationOptionsItem.h"
 #include "GUI/coregui/Models/SpecularBeamInclinationItem.h"
@@ -115,12 +115,12 @@ createSpecularSimulation(std::unique_ptr<MultiLayer> P_multilayer,
 }
 
 std::unique_ptr<DepthProbeSimulation>
-createDepthProbeSimulation(std::unique_ptr<MultiLayer> P_multilayer,
+createDepthProbeSimulation(std::unique_ptr<MultiLayer> multilayer,
                            const DepthProbeInstrumentItem* instrument,
                            const SimulationOptionsItem* options_item)
 {
     std::unique_ptr<DepthProbeSimulation> ret = instrument->createSimulation();
-    ret->setSample(*P_multilayer);
+    ret->setSample(*multilayer);
 
     if (options_item)
         TransformToDomain::setSimulationOptions(ret.get(), *options_item);
@@ -130,6 +130,7 @@ createDepthProbeSimulation(std::unique_ptr<MultiLayer> P_multilayer,
 
 } // namespace
 
+
 std::unique_ptr<ISimulation>
 DomainSimulationBuilder::createSimulation(const MultiLayerItem* sampleItem,
                                           const InstrumentItem* instrumentItem,
diff --git a/GUI/coregui/Models/InstrumentItems.cpp b/GUI/coregui/Models/InstrumentItems.cpp
index f41ca929572..98ee33e9313 100644
--- a/GUI/coregui/Models/InstrumentItems.cpp
+++ b/GUI/coregui/Models/InstrumentItems.cpp
@@ -13,11 +13,13 @@
 //  ************************************************************************************************
 
 #include "GUI/coregui/Models/InstrumentItems.h"
+#include "Base/Const/Units.h"
 #include "Core/Scan/UnitConverter1D.h"
+#include "Core/Simulation/DepthProbeSimulation.h"
 #include "Device/Detector/IDetector2D.h"
 #include "Device/Instrument/Instrument.h"
 #include "GUI/coregui/Models/BackgroundItems.h"
-#include "GUI/coregui/Models/BeamItems.h"
+#include "GUI/coregui/Models/BeamWavelengthItem.h"
 #include "GUI/coregui/Models/DataItem.h"
 #include "GUI/coregui/Models/DetectorItems.h"
 #include "GUI/coregui/Models/GroupItem.h"
@@ -27,6 +29,8 @@
 #include "GUI/coregui/Models/PointwiseAxisItem.h"
 #include "GUI/coregui/Models/RealDataItem.h"
 #include "GUI/coregui/Models/SessionModel.h"
+#include "GUI/coregui/Models/SpecularBeamInclinationItem.h"
+#include "GUI/coregui/Models/TransformToDomain.h"
 #include "GUI/coregui/utils/GUIHelpers.h"
 
 namespace {
@@ -345,3 +349,86 @@ QString OffSpecularInstrumentItem::defaultName() const
 {
     return "OffSpecular";
 }
+
+
+//  ************************************************************************************************
+//  class DepthProbeInstrumentItem
+//  ************************************************************************************************
+
+
+const QString DepthProbeInstrumentItem::P_BEAM = "Beam";
+const QString DepthProbeInstrumentItem::P_Z_AXIS = "Z axis";
+
+DepthProbeInstrumentItem::DepthProbeInstrumentItem() : InstrumentItem("DepthProbeInstrument")
+{
+    setItemName("DepthProbeInstrument");
+
+    addProperty<SpecularBeamItem>(P_BEAM);
+
+    auto axisItem = beamItem()->currentInclinationAxisItem();
+    axisItem->setLowerBound(0.0);
+    axisItem->setUpperBound(1.0);
+    axisItem->setBinCount(500);
+
+    auto axis = addProperty<BasicAxisItem>(P_Z_AXIS);
+    axis->setLowerBound(-100.0);
+    axis->setUpperBound(100.0);
+    axis->getItem(BasicAxisItem::P_TITLE)->setVisible(false);
+    axis->getItem(BasicAxisItem::P_NBINS)
+        ->setToolTip("Number of points in scan across sample bulk");
+    axis->getItem(BasicAxisItem::P_MIN_DEG)
+        ->setToolTip("Starting value below sample horizont in nm");
+    axis->getItem(BasicAxisItem::P_MAX_DEG)->setToolTip("Ending value above sample horizont in nm");
+}
+
+SpecularBeamItem* DepthProbeInstrumentItem::beamItem() const
+{
+    return item<SpecularBeamItem>(P_BEAM);
+}
+
+std::unique_ptr<Instrument> DepthProbeInstrumentItem::createInstrument() const
+{
+    throw std::runtime_error("DepthProbeInstrumentItem::createInstrument()");
+}
+
+std::vector<int> DepthProbeInstrumentItem::shape() const
+{
+    return std::vector<int>(); // no certain shape to avoid linking to real data
+}
+
+void DepthProbeInstrumentItem::updateToRealData(const RealDataItem*)
+{
+    throw std::runtime_error("DepthProbeInstrumentItem::updateToRealData()");
+}
+
+QString DepthProbeInstrumentItem::defaultName() const
+{
+    return "DepthProbe";
+}
+
+std::unique_ptr<DepthProbeSimulation> DepthProbeInstrumentItem::createSimulation() const
+{
+    std::unique_ptr<DepthProbeSimulation> simulation = std::make_unique<DepthProbeSimulation>();
+
+    const auto axis_item = beamItem()->currentInclinationAxisItem();
+
+    auto axis = axis_item->createAxis(Units::deg);
+
+    simulation->setBeamParameters(beamItem()->wavelength(), static_cast<int>(axis->size()),
+                                  axis->lowerBound(), axis->upperBound());
+
+    auto depthAxisItem = dynamic_cast<BasicAxisItem*>(getItem(P_Z_AXIS));
+    auto depthAxis = depthAxisItem->createAxis(1.0);
+    simulation->setZSpan(depthAxis->size(), depthAxis->lowerBound(), depthAxis->upperBound());
+
+    TransformToDomain::setBeamDistribution(
+        "Wavelength", *beamItem()->item<BeamWavelengthItem>(SpecularBeamItem::P_WAVELENGTH),
+        *simulation.get());
+
+    TransformToDomain::setBeamDistribution(
+        "InclinationAngle",
+        *beamItem()->item<SpecularBeamInclinationItem>(SpecularBeamItem::P_INCLINATION_ANGLE),
+        *simulation.get());
+
+    return simulation;
+}
diff --git a/GUI/coregui/Models/InstrumentItems.h b/GUI/coregui/Models/InstrumentItems.h
index d79f2051fff..aa3e0eb0f20 100644
--- a/GUI/coregui/Models/InstrumentItems.h
+++ b/GUI/coregui/Models/InstrumentItems.h
@@ -15,10 +15,11 @@
 #ifndef BORNAGAIN_GUI_COREGUI_MODELS_INSTRUMENTITEMS_H
 #define BORNAGAIN_GUI_COREGUI_MODELS_INSTRUMENTITEMS_H
 
-#include "GUI/coregui/Models/BeamItems.h"
+#include "GUI/coregui/Models/BeamItems.h" // inheritance prevents forward declaration
 
 class BackgroundItem;
 class DataItem;
+class DepthProbeSimulation;
 class DetectorItem;
 class GroupItem;
 class Instrument;
@@ -123,4 +124,24 @@ public:
     virtual QString defaultName() const override;
 };
 
+
+class BA_CORE_API_ DepthProbeInstrumentItem : public InstrumentItem {
+public:
+    static const QString P_BEAM;
+    static const QString P_Z_AXIS;
+
+    DepthProbeInstrumentItem();
+
+    SpecularBeamItem* beamItem() const override;
+
+    std::unique_ptr<Instrument> createInstrument() const override;
+    std::vector<int> shape() const override;
+    void updateToRealData(const RealDataItem* item) override;
+    virtual QString defaultName() const override;
+
+    // FIXME switch to base ISimulation class after InstrumentItem refactoring and
+    // after ISimulation gets createUnitConverter method
+    std::unique_ptr<DepthProbeSimulation> createSimulation() const;
+};
+
 #endif // BORNAGAIN_GUI_COREGUI_MODELS_INSTRUMENTITEMS_H
diff --git a/GUI/coregui/Models/ItemCatalog.cpp b/GUI/coregui/Models/ItemCatalog.cpp
index 4c095c430c0..a88ffd651e0 100644
--- a/GUI/coregui/Models/ItemCatalog.cpp
+++ b/GUI/coregui/Models/ItemCatalog.cpp
@@ -19,7 +19,6 @@
 #include "GUI/coregui/Models/Data1DViewItem.h"
 #include "GUI/coregui/Models/DataProperties.h"
 #include "GUI/coregui/Models/DataPropertyContainer.h"
-#include "GUI/coregui/Models/DepthProbeInstrumentItem.h"
 #include "GUI/coregui/Models/FTDecayFunctionItems.h"
 #include "GUI/coregui/Models/FTDistributionItems.h"
 #include "GUI/coregui/Models/FitParameterItems.h"
@@ -27,6 +26,7 @@
 #include "GUI/coregui/Models/FootprintItems.h"
 #include "GUI/coregui/Models/FormFactorItems.h"
 #include "GUI/coregui/Models/GroupItem.h"
+#include "GUI/coregui/Models/InstrumentItems.h"
 #include "GUI/coregui/Models/IntensityDataItem.h"
 #include "GUI/coregui/Models/InterferenceFunctionItems.h"
 #include "GUI/coregui/Models/JobItem.h"
diff --git a/GUI/coregui/Models/JobModelFunctions.cpp b/GUI/coregui/Models/JobModelFunctions.cpp
index 794d0cd693c..e0e1544ef63 100644
--- a/GUI/coregui/Models/JobModelFunctions.cpp
+++ b/GUI/coregui/Models/JobModelFunctions.cpp
@@ -18,7 +18,6 @@
 #include "Device/Unit/IUnitConverter.h"
 #include "GUI/coregui/Models/Data1DViewItem.h"
 #include "GUI/coregui/Models/DataPropertyContainer.h"
-#include "GUI/coregui/Models/DepthProbeInstrumentItem.h"
 #include "GUI/coregui/Models/DetectorItems.h"
 #include "GUI/coregui/Models/DomainObjectBuilder.h"
 #include "GUI/coregui/Models/FitParameterItems.h"
diff --git a/GUI/coregui/Models/SessionDecorationModel.cpp b/GUI/coregui/Models/SessionDecorationModel.cpp
index 08e166e8468..938b0a01477 100644
--- a/GUI/coregui/Models/SessionDecorationModel.cpp
+++ b/GUI/coregui/Models/SessionDecorationModel.cpp
@@ -13,7 +13,6 @@
 //  ************************************************************************************************
 
 #include "GUI/coregui/Models/SessionDecorationModel.h"
-#include "GUI/coregui/Models/DepthProbeInstrumentItem.h"
 #include "GUI/coregui/Models/InstrumentItems.h"
 #include "GUI/coregui/Models/MaterialItem.h"
 #include "GUI/coregui/Models/SessionModel.h"
diff --git a/GUI/coregui/Views/InstrumentWidgets/DepthProbeInstrumentEditor.cpp b/GUI/coregui/Views/InstrumentWidgets/DepthProbeInstrumentEditor.cpp
index 36b6ef34bb0..acde70ca746 100644
--- a/GUI/coregui/Views/InstrumentWidgets/DepthProbeInstrumentEditor.cpp
+++ b/GUI/coregui/Views/InstrumentWidgets/DepthProbeInstrumentEditor.cpp
@@ -13,7 +13,7 @@
 //  ************************************************************************************************
 
 #include "GUI/coregui/Views/InstrumentWidgets/DepthProbeInstrumentEditor.h"
-#include "GUI/coregui/Models/DepthProbeInstrumentItem.h"
+#include "GUI/coregui/Models/InstrumentItems.h"
 #include "GUI/coregui/Models/SpecularBeamInclinationItem.h"
 #include "GUI/coregui/Views/InfoWidgets/DistributionDialog.h"
 #include "GUI/coregui/Views/PropertyEditor/ComponentEditor.h"
diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentPresenter.cpp b/GUI/coregui/Views/InstrumentWidgets/InstrumentPresenter.cpp
index 9f12cfd69ef..03e2c5cf2e5 100644
--- a/GUI/coregui/Views/InstrumentWidgets/InstrumentPresenter.cpp
+++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentPresenter.cpp
@@ -13,7 +13,6 @@
 //  ************************************************************************************************
 
 #include "GUI/coregui/Views/InstrumentWidgets/InstrumentPresenter.h"
-#include "GUI/coregui/Models/DepthProbeInstrumentItem.h"
 #include "GUI/coregui/Models/InstrumentItems.h"
 #include "GUI/coregui/Models/SessionItem.h"
 #include "GUI/coregui/Views/InstrumentWidgets/DepthProbeInstrumentEditor.h"
diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentViewActions.cpp b/GUI/coregui/Views/InstrumentWidgets/InstrumentViewActions.cpp
index 8f2c92f192d..cdacc5b732f 100644
--- a/GUI/coregui/Views/InstrumentWidgets/InstrumentViewActions.cpp
+++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentViewActions.cpp
@@ -13,7 +13,6 @@
 //  ************************************************************************************************
 
 #include "GUI/coregui/Views/InstrumentWidgets/InstrumentViewActions.h"
-#include "GUI/coregui/Models/DepthProbeInstrumentItem.h"
 #include "GUI/coregui/Models/GroupItem.h"
 #include "GUI/coregui/Models/InstrumentItems.h"
 #include "GUI/coregui/Models/ModelUtils.h"
-- 
GitLab