Skip to content
Snippets Groups Projects
Commit e7f58553 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

mv ownership out of create... fcts

parent 159f3691
No related branches found
No related tags found
1 merge request!918rename and simplify in GUI/Core conversion
......@@ -13,9 +13,9 @@
// ************************************************************************************************
#include "GUI/Model/Device/InstrumentCollection.h"
#include "GUI/Model/Device/InstrumentItems.h"
#include "GUI/Model/CatDevice/InstrumentItemCatalog.h"
#include "GUI/Model/Data/RealDataItem.h"
#include "GUI/Model/Device/InstrumentItems.h"
#include "GUI/Support/XML/Serialize.h"
#include "GUI/Util/String.h"
......
......@@ -15,10 +15,10 @@
#ifndef BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTCOLLECTION_H
#define BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTCOLLECTION_H
#include <functional>
#include <memory>
#include <QStringList>
#include <QVector>
#include <functional>
#include <memory>
class InstrumentItem;
class Instrument2DItem;
......
......@@ -299,10 +299,9 @@ QString DepthProbeInstrumentItem::instrumentType() const
return "Depth probe";
}
std::unique_ptr<DepthProbeSimulation>
DepthProbeInstrumentItem::createSimulation(const MultiLayer& sample) const
DepthProbeSimulation* DepthProbeInstrumentItem::createSimulation(const MultiLayer& sample) const
{
auto simulation = std::make_unique<DepthProbeSimulation>(sample);
auto* simulation = new DepthProbeSimulation(sample);
auto* const axis_item = beamItem()->inclinationAxis();
auto axis = axis_item->createAxis(Units::deg);
......@@ -368,27 +367,25 @@ std::unique_ptr<Instrument> Instrument2DItem::createInstrument() const
return std::make_unique<Instrument>(*beam, *detector);
}
std::unique_ptr<ScatteringSimulation>
Instrument2DItem::createScatteringSimulation(const MultiLayer& sample) const
ScatteringSimulation* Instrument2DItem::createScatteringSimulation(const MultiLayer& sample) const
{
auto beam = beamItem()->createBeam();
auto detector = detectorItem()->createDetector();
detector->setDetectorNormal(beam->direction().zReflected());
auto result = std::make_unique<ScatteringSimulation>(*beam, sample, *detector);
auto* result = new ScatteringSimulation(*beam, sample, *detector);
result->setPolarization(m_polarization);
result->setAnalyzer(m_analyzerDirection, m_analyzerEfficiency, m_analyzerTotalTransmission);
return result;
}
std::unique_ptr<OffspecSimulation>
Instrument2DItem::createOffspecSimulation(const MultiLayer& sample) const
OffspecSimulation* Instrument2DItem::createOffspecSimulation(const MultiLayer& sample) const
{
auto beam = beamItem()->createBeam();
auto detector = detectorItem()->createDetector();
detector->setDetectorNormal(beam->direction().zReflected());
auto result = std::make_unique<OffspecSimulation>(*beam, sample, *detector);
auto* result = new OffspecSimulation(*beam, sample, *detector);
result->setPolarization(m_polarization);
result->setAnalyzer(m_analyzerDirection, m_analyzerEfficiency, m_analyzerTotalTransmission);
return result;
......
......@@ -138,7 +138,7 @@ public:
// FIXME switch to base ISimulation class after InstrumentItem refactoring and
// after ISimulation gets createCoordSystem method
std::unique_ptr<DepthProbeSimulation> createSimulation(const MultiLayer& sample) const;
DepthProbeSimulation* createSimulation(const MultiLayer& sample) const;
ICoordSystem* createCoordSystem() const override;
......@@ -159,9 +159,8 @@ public:
void importMasks(const MaskContainerItem* maskContainer) override;
std::unique_ptr<Instrument> createInstrument() const;
std::unique_ptr<ScatteringSimulation>
createScatteringSimulation(const MultiLayer& sample) const;
std::unique_ptr<OffspecSimulation> createOffspecSimulation(const MultiLayer& sample) const;
ScatteringSimulation* createScatteringSimulation(const MultiLayer& sample) const;
OffspecSimulation* createOffspecSimulation(const MultiLayer& sample) const;
static bool isDetectorPropertyName(const QString& name);
......
......@@ -68,8 +68,7 @@ SpecularInstrumentItem* createSpecularInstrumentItem(InstrumentCollection* model
// class implementation
// ************************************************************************************************
InstrumentCollection*
GUI::Transform::FromDomain::itemizeInstruments(const ISimulation& simulation)
InstrumentCollection* GUI::Transform::FromDomain::itemizeInstruments(const ISimulation& simulation)
{
auto* result = new InstrumentCollection;
......
......@@ -114,30 +114,22 @@ void setSimulationOptions(ISimulation* simulation, const SimulationOptionsItem&
simulation->options().setIncludeSpecular(optionItem.includeSpecularPeak());
}
std::unique_ptr<ScatteringSimulation>
createScatteringSimulation(std::unique_ptr<MultiLayer> sample,
const GISASInstrumentItem* instrumentItem,
const SimulationOptionsItem& optionsItem)
ScatteringSimulation* createScatteringSimulation(std::unique_ptr<MultiLayer> sample,
const GISASInstrumentItem* instrumentItem)
{
std::unique_ptr<ScatteringSimulation> result(
instrumentItem->createScatteringSimulation(*sample));
ScatteringSimulation* result = instrumentItem->createScatteringSimulation(*sample);
addDistributionParametersToSimulation(*instrumentItem->beamItem(), *result);
// ISimulation options
setSimulationOptions(result.get(), optionsItem);
addBackgroundToSimulation(*instrumentItem, *result);
return result;
}
std::unique_ptr<OffspecSimulation>
createOffspecSimulation(std::unique_ptr<MultiLayer> sample,
const OffspecInstrumentItem* instrumentItem,
const SimulationOptionsItem& optionsItem)
OffspecSimulation* createOffspecSimulation(std::unique_ptr<MultiLayer> sample,
const OffspecInstrumentItem* instrumentItem)
{
std::unique_ptr<OffspecSimulation> result(instrumentItem->createOffspecSimulation(*sample));
OffspecSimulation* result = instrumentItem->createOffspecSimulation(*sample);
auto* beamItem = instrumentItem->beamItem();
const auto axis = instrumentItem->alphaAxis().createAxis(Units::deg);
......@@ -147,18 +139,13 @@ createOffspecSimulation(std::unique_ptr<MultiLayer> sample,
// addDistributionParametersToSimulation(*gisasInstrument->beamItem(),
// gisas.get());
// ISimulation options
setSimulationOptions(result.get(), optionsItem);
addBackgroundToSimulation(*instrumentItem, *result);
return result;
}
std::unique_ptr<SpecularSimulation>
createSpecularSimulation(std::unique_ptr<MultiLayer> P_sample,
const SpecularInstrumentItem* instrument,
const SimulationOptionsItem& optionsItem)
SpecularSimulation* createSpecularSimulation(std::unique_ptr<MultiLayer> sample,
const SpecularInstrumentItem* instrument)
{
auto* beam_item = instrument->beamItem();
auto* const axis_item = beam_item->inclinationAxis();
......@@ -169,27 +156,18 @@ createSpecularSimulation(std::unique_ptr<MultiLayer> P_sample,
addBeamDivergencesToScan(*beam_item, scan);
auto result = std::make_unique<SpecularSimulation>(scan, *P_sample);
auto* result = new SpecularSimulation(scan, *sample);
result->beam().setIntensity(beam_item->intensity());
// ISimulation options
setSimulationOptions(result.get(), optionsItem);
addBackgroundToSimulation(*instrument, *result);
return result;
}
std::unique_ptr<DepthProbeSimulation>
createDepthProbeSimulation(std::unique_ptr<MultiLayer> sample,
const DepthProbeInstrumentItem* instrument,
const SimulationOptionsItem& optionsItem)
DepthProbeSimulation* createDepthProbeSimulation(std::unique_ptr<MultiLayer> sample,
const DepthProbeInstrumentItem* instrument)
{
std::unique_ptr<DepthProbeSimulation> result = instrument->createSimulation(*sample);
setSimulationOptions(result.get(), optionsItem);
return result;
return instrument->createSimulation(*sample);
}
} // namespace
......@@ -203,17 +181,23 @@ GUI::Transform::ToDomain::itemsToSimulation(const MultiLayerItem* sampleItem,
ASSERT(sampleItem);
ASSERT(instrumentItem);
auto P_sample = GUI::Transform::ToDomain::itemToSample(*sampleItem);
std::unique_ptr<MultiLayer> sample = GUI::Transform::ToDomain::itemToSample(*sampleItem);
std::unique_ptr<ISimulation> result;
if (const auto* gisasInstrument = dynamic_cast<const GISASInstrumentItem*>(instrumentItem))
return createScatteringSimulation(std::move(P_sample), gisasInstrument, optionsItem);
if (const auto* offspecInstrument = dynamic_cast<const OffspecInstrumentItem*>(instrumentItem))
return createOffspecSimulation(std::move(P_sample), offspecInstrument, optionsItem);
if (const auto* specular_instrument =
dynamic_cast<const SpecularInstrumentItem*>(instrumentItem))
return createSpecularSimulation(std::move(P_sample), specular_instrument, optionsItem);
if (const auto* penetrator = dynamic_cast<const DepthProbeInstrumentItem*>(instrumentItem))
return createDepthProbeSimulation(std::move(P_sample), penetrator, optionsItem);
ASSERT(0);
result.reset(createScatteringSimulation(std::move(sample), gisasInstrument));
else if (const auto* offspecInstrument =
dynamic_cast<const OffspecInstrumentItem*>(instrumentItem))
result.reset(createOffspecSimulation(std::move(sample), offspecInstrument));
else if (const auto* specular_instrument =
dynamic_cast<const SpecularInstrumentItem*>(instrumentItem))
result.reset(createSpecularSimulation(std::move(sample), specular_instrument));
else if (const auto* penetrator = dynamic_cast<const DepthProbeInstrumentItem*>(instrumentItem))
result.reset(createDepthProbeSimulation(std::move(sample), penetrator));
else
ASSERT(0);
setSimulationOptions(result.get(), optionsItem);
return result;
}
......@@ -130,8 +130,7 @@ GUI::Transform::ToDomain::itemToLayerRoughness(LayerBasicRoughnessItem* roughnes
roughness->lateralCorrelationLength());
}
std::unique_ptr<MultiLayer>
GUI::Transform::ToDomain::itemToSample(const MultiLayerItem& sampleItem)
std::unique_ptr<MultiLayer> GUI::Transform::ToDomain::itemToSample(const MultiLayerItem& sampleItem)
{
auto P_sample = createMultiLayer(sampleItem);
for (auto* layerItem : sampleItem.layers()) {
......
......@@ -30,7 +30,6 @@ std::unique_ptr<LayerRoughness> itemToLayerRoughness(LayerBasicRoughnessItem* ro
std::unique_ptr<MultiLayer> itemToSample(const MultiLayerItem& item);
} // namespace GUI::Transform::ToDomain
#endif // BORNAGAIN_GUI_MODEL_TODOMAIN_TODOMAIN_H
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