From 99369efbb1356e1329cf301d64f1fb36289c893d Mon Sep 17 00:00:00 2001 From: Tobias Knopff <t.knopff@fz-juelich.de> Date: Wed, 18 Aug 2021 11:03:49 +0200 Subject: [PATCH] Rename functions to be consistent with other names and add new functions needed by upcoming changes. --- GUI/Models/InstrumentItems.cpp | 26 ++++++++++++------- GUI/Models/InstrumentItems.h | 8 +++--- GUI/Models/TransformFromDomain.cpp | 6 ++--- .../InstrumentWidgets/GISASDetectorEditor.cpp | 2 +- .../PolarizationAnalysisEditor.cpp | 4 +-- Tests/Performance/GUI/GUIPerformanceTest.cpp | 4 +-- Tests/Unit/GUI/TestDetectorItems.cpp | 2 +- Tests/Unit/GUI/TestLinkInstrument.cpp | 4 +-- 8 files changed, 32 insertions(+), 24 deletions(-) diff --git a/GUI/Models/InstrumentItems.cpp b/GUI/Models/InstrumentItems.cpp index 98942d1c7a2..6cf6d24130e 100644 --- a/GUI/Models/InstrumentItems.cpp +++ b/GUI/Models/InstrumentItems.cpp @@ -342,7 +342,7 @@ Instrument2DItem::Instrument2DItem(const QString& modelType) : InstrumentItem(mo Instrument2DItem::~Instrument2DItem() = default; -DetectorItem* Instrument2DItem::detectorItem() const +DetectorItem* Instrument2DItem::detector() const { return &groupItem<DetectorItem>(P_DETECTOR); } @@ -352,21 +352,29 @@ GroupItem* Instrument2DItem::detectorGroup() return item<GroupItem>(P_DETECTOR); } +DetectorItem* Instrument2DItem::setDetectorType(const QString& model_type) +{ + ASSERT(model_type == RectangularDetectorItem::M_TYPE + || model_type == SphericalDetectorItem::M_TYPE); + + return static_cast<DetectorItem*>(setGroupProperty(P_DETECTOR, model_type)); +} + void Instrument2DItem::clearMasks() { - detectorItem()->clearMasks(); + detector()->clearMasks(); } void Instrument2DItem::importMasks(const MaskContainerItem* maskContainer) { - detectorItem()->importMasks(maskContainer); + detector()->importMasks(maskContainer); } std::unique_ptr<Instrument> Instrument2DItem::createInstrument() const { std::unique_ptr<Instrument> instrument(new Instrument); instrument->setBeam(*beamItem()->createBeam()); - instrument->setDetector(*detectorItem()->createDetector()); + instrument->setDetector(*detector()->createDetector()); return instrument; } @@ -386,7 +394,7 @@ GISASInstrumentItem::GISASInstrumentItem() : Instrument2DItem(M_TYPE) {} std::vector<int> GISASInstrumentItem::shape() const { - auto detector_item = detectorItem(); + auto detector_item = detector(); return {detector_item->xSize(), detector_item->ySize()}; } @@ -399,8 +407,8 @@ void GISASInstrumentItem::updateToRealData(const RealDataItem* 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]); + detector()->setXSize(data_shape[0]); + detector()->setYSize(data_shape[1]); } QString GISASInstrumentItem::defaultName() const @@ -438,7 +446,7 @@ OffSpecularInstrumentItem::OffSpecularInstrumentItem() : Instrument2DItem(M_TYPE std::vector<int> OffSpecularInstrumentItem::shape() const { const int x_size = item<BasicAxisItem>(P_ALPHA_AXIS)->binCount(); - auto detector_item = detectorItem(); + auto detector_item = detector(); return {x_size, detector_item->ySize()}; } @@ -453,7 +461,7 @@ void OffSpecularInstrumentItem::updateToRealData(const RealDataItem* dataItem) "instrument is incompatible with passed data shape."); item<BasicAxisItem>(P_ALPHA_AXIS)->setBinCount(data_shape[0]); - detectorItem()->setYSize(data_shape[1]); + detector()->setYSize(data_shape[1]); } QString OffSpecularInstrumentItem::defaultName() const diff --git a/GUI/Models/InstrumentItems.h b/GUI/Models/InstrumentItems.h index c97ef93ee60..65cc0caacae 100644 --- a/GUI/Models/InstrumentItems.h +++ b/GUI/Models/InstrumentItems.h @@ -119,10 +119,10 @@ private: public: ~Instrument2DItem() override; - DetectorItem* detectorItem() const; + DetectorItem* detector() const; GroupItem* detectorGroup(); - - template <typename T> T* setDetectorGroup(); + template <typename T> T* setDetectorType(); + DetectorItem* setDetectorType(const QString& model_type); void clearMasks() override; void importMasks(const MaskContainerItem* maskContainer) override; @@ -178,7 +178,7 @@ template <typename T> T* InstrumentItem::setBackgroundType() return setGroupPropertyType<T>(P_BACKGROUND); } -template <typename T> T* Instrument2DItem::setDetectorGroup() +template <typename T> T* Instrument2DItem::setDetectorType() { static_assert(std::is_base_of<DetectorItem, T>::value, "Class must be derived from DetectorItem"); diff --git a/GUI/Models/TransformFromDomain.cpp b/GUI/Models/TransformFromDomain.cpp index c77c8371bc1..9d0b042d806 100644 --- a/GUI/Models/TransformFromDomain.cpp +++ b/GUI/Models/TransformFromDomain.cpp @@ -508,7 +508,7 @@ void GUI::Transform::FromDomain::setDetector(Instrument2DItem* instrument_item, const IDetector& detector = simulation.detector(); setDetectorGeometry(instrument_item, detector); - auto detector_item = instrument_item->detectorItem(); + auto detector_item = instrument_item->detector(); setDetectorResolution(detector_item, detector); setDetectorProperties(detector_item, detector); @@ -519,10 +519,10 @@ void GUI::Transform::FromDomain::setDetectorGeometry(Instrument2DItem* instrumen const IDetector& detector) { if (auto det = dynamic_cast<const SphericalDetector*>(&detector)) { - auto item = instrument_item->setDetectorGroup<SphericalDetectorItem>(); + auto item = instrument_item->setDetectorType<SphericalDetectorItem>(); setSphericalDetector(item, *det); } else if (auto det = dynamic_cast<const RectangularDetector*>(&detector)) { - auto item = instrument_item->setDetectorGroup<RectangularDetectorItem>(); + auto item = instrument_item->setDetectorType<RectangularDetectorItem>(); setRectangularDetector(item, *det); } else { throw Error("GUI::Transform::FromDomain::setDetectorGeometry() -> Unknown detector type."); diff --git a/GUI/Views/InstrumentWidgets/GISASDetectorEditor.cpp b/GUI/Views/InstrumentWidgets/GISASDetectorEditor.cpp index 03a2a1bffed..839066c9f3a 100644 --- a/GUI/Views/InstrumentWidgets/GISASDetectorEditor.cpp +++ b/GUI/Views/InstrumentWidgets/GISASDetectorEditor.cpp @@ -62,5 +62,5 @@ Instrument2DItem* GISASDetectorEditor::instrumentItem() void GISASDetectorEditor::updateDetectorPresenter() { - m_detectorPresenter->setItem(instrumentItem()->detectorItem()); + m_detectorPresenter->setItem(instrumentItem()->detector()); } diff --git a/GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.cpp b/GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.cpp index 9e21747ccd2..4cb163caebd 100644 --- a/GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.cpp +++ b/GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.cpp @@ -155,8 +155,8 @@ void PolarizationAnalysisEditor::setItem(Instrument2DItem* item) if (m_item) { m_polarizer_editor->setItem(m_item->beamItem()->polarizationItem()); - m_analyzer_editor->setItem(m_item->detectorItem()->analyzerDirectionItem()); - m_properties_editor->setItem(m_item->detectorItem()); + m_analyzer_editor->setItem(m_item->detector()->analyzerDirectionItem()); + m_properties_editor->setItem(m_item->detector()); } else { m_polarizer_editor->clearItem(); m_analyzer_editor->clearItem(); diff --git a/Tests/Performance/GUI/GUIPerformanceTest.cpp b/Tests/Performance/GUI/GUIPerformanceTest.cpp index bb82a321895..f198bdd9559 100644 --- a/Tests/Performance/GUI/GUIPerformanceTest.cpp +++ b/Tests/Performance/GUI/GUIPerformanceTest.cpp @@ -130,8 +130,8 @@ void GUIPerformanceTest::test_real_time() auto instrument2DItem = dynamic_cast<Instrument2DItem*>(m_models->instrumentModel()->instrumentItems().front()); ASSERT(instrument2DItem); - instrument2DItem->detectorItem()->setXSize(50); - instrument2DItem->detectorItem()->setYSize(50); + instrument2DItem->detector()->setXSize(50); + instrument2DItem->detector()->setYSize(50); jobItem = m_models->jobModel()->addJob( m_models->sampleModel()->multiLayerItem(), diff --git a/Tests/Unit/GUI/TestDetectorItems.cpp b/Tests/Unit/GUI/TestDetectorItems.cpp index d0a125f9501..876e84eb4a4 100644 --- a/Tests/Unit/GUI/TestDetectorItems.cpp +++ b/Tests/Unit/GUI/TestDetectorItems.cpp @@ -35,7 +35,7 @@ TEST_F(TestDetectorItems, test_resolutionFunction) InstrumentModel model; auto instrument = model.insertItem<GISASInstrumentItem>(); - DetectorItem* detectorItem = instrument->detectorItem(); + DetectorItem* detectorItem = instrument->detector(); detectorItem->setResolutionFunctionType<ResolutionFunction2DGaussianItem>(); diff --git a/Tests/Unit/GUI/TestLinkInstrument.cpp b/Tests/Unit/GUI/TestLinkInstrument.cpp index 0ff6bfa2e24..5e2d0f06ac5 100644 --- a/Tests/Unit/GUI/TestLinkInstrument.cpp +++ b/Tests/Unit/GUI/TestLinkInstrument.cpp @@ -37,12 +37,12 @@ TEST_F(TestLinkInstrument, test_canLinkToInstrument) EXPECT_EQ(manager.linkedRealDataItems(instrument), QList<RealDataItem*>() << realData); // changing detector type and checking that link remain - instrument->setDetectorGroup<RectangularDetectorItem>(); + instrument->setDetectorType<RectangularDetectorItem>(); EXPECT_EQ(manager.linkedRealDataItems(instrument), QList<RealDataItem*>() << realData); // changing detector binning and checking that link is destroyed RectangularDetectorItem* detectorItem = - dynamic_cast<RectangularDetectorItem*>(instrument->detectorItem()); + dynamic_cast<RectangularDetectorItem*>(instrument->detector()); auto x_axis = detectorItem->xAxisItem(); x_axis->setBinCount(10); -- GitLab