diff --git a/GUI/Model/Device/InstrumentItems.cpp b/GUI/Model/Device/InstrumentItems.cpp index 33b20264b1a9dbd6fc121063fa2eb98ffd921f8d..1576dbfcbeeb5905e90b7677016376c15f794e67 100644 --- a/GUI/Model/Device/InstrumentItems.cpp +++ b/GUI/Model/Device/InstrumentItems.cpp @@ -312,35 +312,25 @@ const ICoordSystem* DepthProbeInstrumentItem::createCoordSystem() const Instrument2DItem::Instrument2DItem() { m_beamItem.reset(new GISASBeamItem()); - m_detectorItem.init("Detector", ""); + m_detectorSelection.init("Detector", ""); } void Instrument2DItem::serialize(Streamer& s) { s.assertVersion(0); Serialize::rwBaseClass<InstrumentItem>(s, "InstrumentItem", this); - m_detectorItem.rwSelected(s, Tag::Detector); -} - -DetectorItem* Instrument2DItem::detectorItem() const -{ - return m_detectorItem.currentItem(); -} - -SelectionDescriptor<DetectorItem*> Instrument2DItem::detectorSelection() const -{ - return m_detectorItem; + m_detectorSelection.rwSelected(s, Tag::Detector); } void Instrument2DItem::importMasks(const MaskContainerItem* maskContainer) { - detectorItem()->importMasks(maskContainer); + currentDetectorItem()->importMasks(maskContainer); } std::shared_ptr<Instrument> Instrument2DItem::createInstrument() const { auto beam = beamItem()->createBeam(); - auto detector = detectorItem()->createDetector(); + auto detector = currentDetectorItem()->createDetector(); detector->setDetectorNormal(beam->direction().zReflected()); return std::make_shared<Instrument>(beam, *detector); @@ -350,7 +340,7 @@ ScatteringSimulation* Instrument2DItem::createScatteringSimulation(const MultiLa { auto beam = beamItem()->createBeam(); beam->setPolarization(m_polarization); - auto detector = detectorItem()->createDetector(); + auto detector = currentDetectorItem()->createDetector(); detector->setAnalyzer(m_analyzerDirection, m_analyzerEfficiency, m_analyzerTotalTransmission); detector->setDetectorNormal(beam->direction().zReflected()); @@ -362,7 +352,7 @@ OffspecSimulation* Instrument2DItem::createOffspecSimulation(const MultiLayer& s { auto beam = beamItem()->createBeam(); beam->setPolarization(m_polarization); - auto detector = detectorItem()->createDetector(); + auto detector = currentDetectorItem()->createDetector(); detector->setAnalyzer(m_analyzerDirection, m_analyzerEfficiency, m_analyzerTotalTransmission); detector->setDetectorNormal(beam->direction().zReflected()); @@ -376,7 +366,7 @@ OffspecSimulation* Instrument2DItem::createOffspecSimulation(const MultiLayer& s std::vector<int> GISASInstrumentItem::shape() const { - auto* detector_item = detectorItem(); + auto* detector_item = currentDetectorItem(); return {detector_item->xSize(), detector_item->ySize()}; } @@ -389,8 +379,8 @@ void GISASInstrumentItem::updateToRealData(const RealItem* item) if (shape().size() != data_shape.size()) throw Error("Error in GISASInstrumentItem::updateToRealData: The type of " "instrument is incompatible with passed data shape."); - detectorItem()->setXSize(data_shape[0]); - detectorItem()->setYSize(data_shape[1]); + currentDetectorItem()->setXSize(data_shape[0]); + currentDetectorItem()->setYSize(data_shape[1]); } QString GISASInstrumentItem::defaultName() const @@ -431,7 +421,7 @@ void OffspecInstrumentItem::serialize(Streamer& s) std::vector<int> OffspecInstrumentItem::shape() const { - return {(int)m_alphaAxis.nbins(), detectorItem()->ySize()}; + return {(int)m_alphaAxis.nbins(), currentDetectorItem()->ySize()}; } void OffspecInstrumentItem::updateToRealData(const RealItem* dataItem) @@ -445,7 +435,7 @@ void OffspecInstrumentItem::updateToRealData(const RealItem* dataItem) "instrument is incompatible with passed data shape."); m_alphaAxis.setNbins(data_shape[0]); - detectorItem()->setYSize(data_shape[1]); + currentDetectorItem()->setYSize(data_shape[1]); } QString OffspecInstrumentItem::defaultName() const diff --git a/GUI/Model/Device/InstrumentItems.h b/GUI/Model/Device/InstrumentItems.h index 56ea7697ea5e84f45b06e759fe00e3827acfb37d..817716107cb2082f51fc274875ce548d92677c19 100644 --- a/GUI/Model/Device/InstrumentItems.h +++ b/GUI/Model/Device/InstrumentItems.h @@ -174,10 +174,10 @@ class Instrument2DItem : public InstrumentItem { public: void serialize(Streamer& s) override; - DetectorItem* detectorItem() const; template <typename T> T* setDetectorType(); - SelectionDescriptor<DetectorItem*> detectorSelection() const; + DetectorItem* currentDetectorItem() const { return m_detectorSelection.currentItem(); } + const SelectionProperty<DetectorItemCatalog>& detectorSelection() const { return m_detectorSelection; } void importMasks(const MaskContainerItem* maskContainer) override; @@ -190,7 +190,7 @@ public: protected: Instrument2DItem(); - SelectionProperty<DetectorItemCatalog> m_detectorItem; + SelectionProperty<DetectorItemCatalog> m_detectorSelection; }; @@ -239,8 +239,8 @@ T* InstrumentItem::setBackgroundType() template <typename T> T* Instrument2DItem::setDetectorType() { - m_detectorItem.setCurrentItem<T>(); - return dynamic_cast<T*>(m_detectorItem.currentItem()); + m_detectorSelection.setCurrentItem<T>(); + return dynamic_cast<T*>(m_detectorSelection.currentItem()); } #endif // BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTITEMS_H diff --git a/GUI/Model/FromCore/ItemizeSimulation.cpp b/GUI/Model/FromCore/ItemizeSimulation.cpp index 8d77ba169b182f171508ede143243e40a8957d68..550e5aafc6dd718e5b98c4540f6f9832359c51a8 100644 --- a/GUI/Model/FromCore/ItemizeSimulation.cpp +++ b/GUI/Model/FromCore/ItemizeSimulation.cpp @@ -414,7 +414,7 @@ void updateDetector(Instrument2DItem* instrument_item, const ISimulation2D& simu const IDetector& detector = simulation.detector(); setDetectorGeometry(instrument_item, detector); - auto* detector_item = instrument_item->detectorItem(); + auto* detector_item = instrument_item->currentDetectorItem(); setDetectorResolution(detector_item, detector); setDetectorMasks(detector_item, simulation); diff --git a/GUI/Model/Model/ParameterTreeUtils.cpp b/GUI/Model/Model/ParameterTreeUtils.cpp index fbfdfd136b0b632e0cbcfb7c679bfe45c4401376..6832e5ae5442e43102353f78b94f0a5c37e8842f 100644 --- a/GUI/Model/Model/ParameterTreeUtils.cpp +++ b/GUI/Model/Model/ParameterTreeUtils.cpp @@ -316,7 +316,7 @@ void ParameterTreeBuilder::addInstrument() addBeamDistribution(beamLabel, beamItem->wavelengthItem(), "Wavelength"); addBeamDistribution(beamLabel, beamItem->inclinationAngleItem(), "Inclination angle"); addBeamDistribution(beamLabel, beamItem->azimuthalAngleItem(), "Azimuthal angle"); - addDetector(label, gisas->detectorItem()); + addDetector(label, gisas->currentDetectorItem()); addPolarization(label, instrument); addBackground(label, instrument->currentBackgroundItem()); } else if (instrument->is<SpecularInstrumentItem>()) { @@ -333,7 +333,7 @@ void ParameterTreeBuilder::addInstrument() addParameterItem(beamLabel, beamItem->intensity()); addBeamDistribution(beamLabel, beamItem->wavelengthItem(), "Wavelength"); addBeamDistribution(beamLabel, beamItem->azimuthalAngleItem(), "Azimuthal angle"); - addDetector(label, os->detectorItem()); + addDetector(label, os->currentDetectorItem()); addPolarization(label, instrument); } else if (instrument->is<DepthProbeInstrumentItem>()) { auto* beamLabel = new ParameterLabelItem("Parameters", label); diff --git a/GUI/View/Instrument/DetectorEditor.cpp b/GUI/View/Instrument/DetectorEditor.cpp index 7ecdb9455ddd2f23307a331cf6a837b3701962fa..7e59ff590a53ddd40823373b47992823f2b1a21d 100644 --- a/GUI/View/Instrument/DetectorEditor.cpp +++ b/GUI/View/Instrument/DetectorEditor.cpp @@ -31,7 +31,7 @@ DetectorEditor::DetectorEditor(QWidget* parent, Instrument2DItem* instrument) m_formLayout = new QFormLayout(this); auto* detectorTypeCombo = - GUI::Util::createComboBoxFromDescriptor(instrument->detectorSelection(), [=](int) { + GUI::Util::createComboBoxFromDescriptor(instrument->detectorSelection().m_descriptor, [=](int) { createDetectorWidgets(); emit dataChanged(); }); diff --git a/Tests/Unit/GUI/TestDetectorItems.cpp b/Tests/Unit/GUI/TestDetectorItems.cpp index 2f22a28f1f1ccd850dbf391ddba68bcc37f988ca..9867adc9aeb69b38390499b09e7ab57ec4004ec3 100644 --- a/Tests/Unit/GUI/TestDetectorItems.cpp +++ b/Tests/Unit/GUI/TestDetectorItems.cpp @@ -17,7 +17,7 @@ TEST_F(TestDetectorItems, resolutionFunction) InstrumentCollection model; auto* instrument = model.addInstrument<GISASInstrumentItem>(); - DetectorItem* detectorItem = instrument->detectorItem(); + DetectorItem* detectorItem = instrument->currentDetectorItem(); detectorItem->setResolutionFunctionType<ResolutionFunction2DGaussianItem>(); diff --git a/Tests/Unit/GUI/TestLinkInstrument.cpp b/Tests/Unit/GUI/TestLinkInstrument.cpp index afdb4a1de4523930c6a30f8aacbb3e7ea0e6599e..904cb5003320ffd3b4b8640c867a28aa567ee688 100644 --- a/Tests/Unit/GUI/TestLinkInstrument.cpp +++ b/Tests/Unit/GUI/TestLinkInstrument.cpp @@ -55,7 +55,7 @@ TEST_F(TestLinkInstrument, canLinkToInstrument) << realData); // changing detector binning and checking that link is destroyed - auto* detectorItem = dynamic_cast<RectangularDetectorItem*>(instrument->detectorItem()); + auto* detectorItem = dynamic_cast<RectangularDetectorItem*>(instrument->currentDetectorItem()); detectorItem->setXSize(10); document.instrumentsEditController()->notifyInstrumentChanged(instrument);