From 9a936639210b68873fa2573bdcb858d0087bf16e Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Thu, 9 Mar 2017 15:05:25 +0100 Subject: [PATCH] Spherical and Rectangular detector items now derived from common base DetectorItem. --- GUI/coregui/Models/DetectorItems.h | 7 ++- GUI/coregui/Models/ItemFactory.cpp | 3 +- .../Models/RectangularDetectorItem.cpp | 59 ++++++++----------- GUI/coregui/Models/RectangularDetectorItem.h | 12 ++-- GUI/coregui/Models/SphericalDetectorItem.cpp | 29 ++++----- GUI/coregui/Models/SphericalDetectorItem.h | 10 +--- GUI/coregui/Models/TransformFromDomain.cpp | 2 + GUI/coregui/Models/TransformToDomain.cpp | 2 + .../ImportDataWidgets/ImportDataAssistant.cpp | 2 + .../DetectorEditorWidget.cpp | 3 +- .../DetectorMaskDelegate.cpp | 2 + .../RectangularDetectorWidget.cpp | 1 + .../SphericalDetectorWidget.cpp | 1 + Tests/UnitTests/GUI/TestMapperCases.h | 2 + 14 files changed, 62 insertions(+), 73 deletions(-) diff --git a/GUI/coregui/Models/DetectorItems.h b/GUI/coregui/Models/DetectorItems.h index 979d23b1a0d..aae8e2c210e 100644 --- a/GUI/coregui/Models/DetectorItems.h +++ b/GUI/coregui/Models/DetectorItems.h @@ -17,10 +17,11 @@ #ifndef DETECTORITEMS_H #define DETECTORITEMS_H -#include "RectangularDetectorItem.h" -#include "SphericalDetectorItem.h" +#include "SessionItem.h" class MaskContainerItem; +class IDetector2D; +class IResolutionFunction2D; //! DetectorItem, holds masks and either rectangular or spherical detector as sub item class BA_CORE_API_ DetectorContainerItem : public SessionItem @@ -28,7 +29,7 @@ class BA_CORE_API_ DetectorContainerItem : public SessionItem public: static const QString P_DETECTOR; static const QString T_MASKS; - explicit DetectorContainerItem(); + DetectorContainerItem(); virtual ~DetectorContainerItem(){} MaskContainerItem *maskContainerItem() const; diff --git a/GUI/coregui/Models/ItemFactory.cpp b/GUI/coregui/Models/ItemFactory.cpp index c518adc850c..e01598ebf22 100644 --- a/GUI/coregui/Models/ItemFactory.cpp +++ b/GUI/coregui/Models/ItemFactory.cpp @@ -20,6 +20,8 @@ #include "BeamItem.h" #include "BeamWavelengthItem.h" #include "DetectorItems.h" +#include "SphericalDetectorItem.h" +#include "RectangularDetectorItem.h" #include "FTDecayFunctionItems.h" #include "FTDistributionItems.h" #include "FitParameterItems.h" @@ -76,7 +78,6 @@ ItemFactory::ItemMap_t initializeItemMap() { result[Constants::InterferenceFunction2DLatticeType] = &createInstance<InterferenceFunction2DLatticeItem>; result[Constants::InterferenceFunction1DLatticeType] = &createInstance<InterferenceFunction1DLatticeItem>; result[Constants::InstrumentType] = &createInstance<InstrumentItem>; - result[Constants::DetectorContainerType] = &createInstance<DetectorContainerItem>; result[Constants::BeamType] = &createInstance<BeamItem>; result[Constants::VectorType] = &createInstance<VectorItem>; result[Constants::PropertyType] = &createInstance<PropertyItem>; diff --git a/GUI/coregui/Models/RectangularDetectorItem.cpp b/GUI/coregui/Models/RectangularDetectorItem.cpp index bcecff006db..aa7f806791d 100644 --- a/GUI/coregui/Models/RectangularDetectorItem.cpp +++ b/GUI/coregui/Models/RectangularDetectorItem.cpp @@ -71,11 +71,10 @@ const QString RectangularDetectorItem::P_DBEAM_V0 = "v0 (dbeam)"; const QString RectangularDetectorItem::P_DISTANCE = "Distance"; RectangularDetectorItem::RectangularDetectorItem() - : SessionItem(Constants::RectangularDetectorType) - , m_is_constructed(false) + : DetectorItem(Constants::RectangularDetectorType), m_is_constructed(false) { // axes parameters - SessionItem *item = addGroupProperty(P_X_AXIS, Constants::BasicAxisType); + SessionItem* item = addGroupProperty(P_X_AXIS, Constants::BasicAxisType); item->getItem(BasicAxisItem::P_TITLE)->setVisible(false); item->getItem(BasicAxisItem::P_MIN)->setVisible(false); item->setItemValue(BasicAxisItem::P_MAX, default_detector_width); @@ -105,47 +104,42 @@ RectangularDetectorItem::RectangularDetectorItem() item->setItemValue(VectorItem::P_Y, -1.0); addProperty(P_U0, default_detector_width / 2.) - ->setToolTip(tooltip_u0).setLimits(RealLimits::limitless()); - addProperty(P_V0, 0.0) - ->setToolTip(tooltip_v0).setLimits(RealLimits::limitless()); + ->setToolTip(tooltip_u0) + .setLimits(RealLimits::limitless()); + addProperty(P_V0, 0.0)->setToolTip(tooltip_v0).setLimits(RealLimits::limitless()); addProperty(P_DBEAM_U0, default_detector_width / 2.) - ->setToolTip(tooltip_dbeam_u0).setLimits(RealLimits::limitless()); - addProperty(P_DBEAM_V0, 0.0) - ->setToolTip(tooltip_dbeam_v0).setLimits(RealLimits::limitless()); + ->setToolTip(tooltip_dbeam_u0) + .setLimits(RealLimits::limitless()); + addProperty(P_DBEAM_V0, 0.0)->setToolTip(tooltip_dbeam_v0).setLimits(RealLimits::limitless()); addProperty(P_DISTANCE, default_detector_distance) - ->setToolTip(QStringLiteral("Distance in [mm] from the sample origin to the detector plane")); + ->setToolTip( + QStringLiteral("Distance in [mm] from the sample origin to the detector plane")); update_properties_appearance(); - m_is_constructed=true; + m_is_constructed = true; - mapper()->setOnPropertyChange( - [this](const QString &name) { - if(name == P_ALIGNMENT && m_is_constructed) update_properties_appearance(); + mapper()->setOnPropertyChange([this](const QString& name) { + if (name == P_ALIGNMENT && m_is_constructed) + update_properties_appearance(); }); } std::unique_ptr<IDetector2D> RectangularDetectorItem::createDetector() const { // basic axes parameters - auto x_axis = dynamic_cast<BasicAxisItem *>( - getItem(RectangularDetectorItem::P_X_AXIS)); + auto x_axis = dynamic_cast<BasicAxisItem*>(getItem(RectangularDetectorItem::P_X_AXIS)); Q_ASSERT(x_axis); int n_x = x_axis->getItemValue(BasicAxisItem::P_NBINS).toInt(); double width = x_axis->getItemValue(BasicAxisItem::P_MAX).toDouble(); - auto y_axis = dynamic_cast<BasicAxisItem *>( - getItem(RectangularDetectorItem::P_Y_AXIS)); + auto y_axis = dynamic_cast<BasicAxisItem*>(getItem(RectangularDetectorItem::P_Y_AXIS)); Q_ASSERT(y_axis); int n_y = y_axis->getItemValue(BasicAxisItem::P_NBINS).toInt(); double height = y_axis->getItemValue(BasicAxisItem::P_MAX).toDouble(); -// std::unique_ptr<RectangularDetector> result(new RectangularDetector(100, 20.0, 100, 20.0)); -// result->setPerpendicularToSampleX(1000.0, 10.0, 0.0); - std::unique_ptr<RectangularDetector> result(new RectangularDetector(n_x, width, n_y, height)); - // distance and alighnment double u0 = getItemValue(P_U0).toDouble(); double v0 = getItemValue(P_V0).toDouble(); @@ -180,24 +174,23 @@ std::unique_ptr<IDetector2D> RectangularDetectorItem::createDetector() const std::unique_ptr<IResolutionFunction2D> RectangularDetectorItem::createResolutionFunction() { - auto resfuncItem = dynamic_cast<ResolutionFunctionItem *>( - getGroupItem(P_RESOLUTION_FUNCTION)); + auto resfuncItem = dynamic_cast<ResolutionFunctionItem*>(getGroupItem(P_RESOLUTION_FUNCTION)); Q_ASSERT(resfuncItem); std::unique_ptr<IResolutionFunction2D> result(resfuncItem->createResolutionFunction()); return result; } -void RectangularDetectorItem::setDetectorAlignment(const QString &alignment) +void RectangularDetectorItem::setDetectorAlignment(const QString& alignment) { ComboProperty combo_property = getItemValue(RectangularDetectorItem::P_ALIGNMENT).value<ComboProperty>(); - if(!combo_property.getValues().contains(alignment)) { - throw GUIHelpers::Error("RectangularDetectorItem::setDetectorAlignment -> Unexpected alignment"); + if (!combo_property.getValues().contains(alignment)) { + throw GUIHelpers::Error( + "RectangularDetectorItem::setDetectorAlignment -> Unexpected alignment"); } combo_property.setValue(alignment); setItemValue(RectangularDetectorItem::P_ALIGNMENT, combo_property.getVariant()); - } //! updates property tooltips and visibility flags, depending from type of alignment selected @@ -207,7 +200,7 @@ void RectangularDetectorItem::update_properties_appearance() ComboProperty alignment = getItemValue(P_ALIGNMENT).value<ComboProperty>(); QStringList prop_list; prop_list << P_NORMAL << P_DIRECTION << P_U0 << P_V0 << P_DBEAM_U0 << P_DBEAM_V0 << P_DISTANCE; - foreach(auto prop, prop_list) { + foreach (auto prop, prop_list) { getItem(prop)->setVisible(false); } @@ -248,18 +241,14 @@ void RectangularDetectorItem::update_properties_appearance() kvector_t RectangularDetectorItem::getNormalVector() const { - auto item = dynamic_cast<VectorItem *>( - getItem(RectangularDetectorItem::P_NORMAL)); + auto item = dynamic_cast<VectorItem*>(getItem(RectangularDetectorItem::P_NORMAL)); Q_ASSERT(item); return item->getVector(); } kvector_t RectangularDetectorItem::getDirectionVector() const { - auto item = dynamic_cast<VectorItem *>( - getItem(RectangularDetectorItem::P_DIRECTION)); + auto item = dynamic_cast<VectorItem*>(getItem(RectangularDetectorItem::P_DIRECTION)); Q_ASSERT(item); return item->getVector(); } - - diff --git a/GUI/coregui/Models/RectangularDetectorItem.h b/GUI/coregui/Models/RectangularDetectorItem.h index bc21b960b93..50b42618e8c 100644 --- a/GUI/coregui/Models/RectangularDetectorItem.h +++ b/GUI/coregui/Models/RectangularDetectorItem.h @@ -17,14 +17,10 @@ #ifndef RECTANGULARDETECTORITEM_H #define RECTANGULARDETECTORITEM_H -#include "SessionItem.h" +#include "DetectorItems.h" #include "Vectors3D.h" -class IDetector2D; -class IResolutionFunction2D; - - -class BA_CORE_API_ RectangularDetectorItem : public SessionItem +class BA_CORE_API_ RectangularDetectorItem : public DetectorItem { public: static const QString P_X_AXIS; @@ -39,12 +35,12 @@ public: static const QString P_DBEAM_V0; static const QString P_DISTANCE; - explicit RectangularDetectorItem(); + RectangularDetectorItem(); std::unique_ptr<IDetector2D> createDetector() const; std::unique_ptr<IResolutionFunction2D> createResolutionFunction(); - void setDetectorAlignment(const QString &alignment); + void setDetectorAlignment(const QString& alignment); private: void update_properties_appearance(); diff --git a/GUI/coregui/Models/SphericalDetectorItem.cpp b/GUI/coregui/Models/SphericalDetectorItem.cpp index 0c9a56c605c..bacd0a56cdf 100644 --- a/GUI/coregui/Models/SphericalDetectorItem.cpp +++ b/GUI/coregui/Models/SphericalDetectorItem.cpp @@ -24,10 +24,9 @@ const QString SphericalDetectorItem::P_PHI_AXIS = "Phi axis"; const QString SphericalDetectorItem::P_ALPHA_AXIS = "Alpha axis"; const QString SphericalDetectorItem::P_RESOLUTION_FUNCTION = "Type"; -SphericalDetectorItem::SphericalDetectorItem() - : SessionItem(Constants::SphericalDetectorType) +SphericalDetectorItem::SphericalDetectorItem() : DetectorItem(Constants::SphericalDetectorType) { - SessionItem *item = addGroupProperty(P_PHI_AXIS, Constants::BasicAxisType); + SessionItem* item = addGroupProperty(P_PHI_AXIS, Constants::BasicAxisType); item->getItem(BasicAxisItem::P_TITLE)->setVisible(false); item->setItemValue(BasicAxisItem::P_MIN, -1.0); item->setItemValue(BasicAxisItem::P_MAX, 1.0); @@ -45,23 +44,17 @@ std::unique_ptr<IDetector2D> SphericalDetectorItem::createDetector() const { std::unique_ptr<SphericalDetector> result(new SphericalDetector()); - auto x_axis = dynamic_cast<BasicAxisItem *>( - getItem(SphericalDetectorItem::P_PHI_AXIS)); + auto x_axis = dynamic_cast<BasicAxisItem*>(getItem(SphericalDetectorItem::P_PHI_AXIS)); Q_ASSERT(x_axis); int n_x = x_axis->getItemValue(BasicAxisItem::P_NBINS).toInt(); - double x_min - = Units::deg2rad(x_axis->getItemValue(BasicAxisItem::P_MIN).toDouble()); - double x_max - = Units::deg2rad(x_axis->getItemValue(BasicAxisItem::P_MAX).toDouble()); + double x_min = Units::deg2rad(x_axis->getItemValue(BasicAxisItem::P_MIN).toDouble()); + double x_max = Units::deg2rad(x_axis->getItemValue(BasicAxisItem::P_MAX).toDouble()); - auto y_axis = dynamic_cast<BasicAxisItem *>( - getItem(SphericalDetectorItem::P_ALPHA_AXIS)); + auto y_axis = dynamic_cast<BasicAxisItem*>(getItem(SphericalDetectorItem::P_ALPHA_AXIS)); Q_ASSERT(y_axis); int n_y = y_axis->getItemValue(BasicAxisItem::P_NBINS).toInt(); - double y_min - = Units::deg2rad(y_axis->getItemValue(BasicAxisItem::P_MIN).toDouble()); - double y_max - = Units::deg2rad(y_axis->getItemValue(BasicAxisItem::P_MAX).toDouble()); + double y_min = Units::deg2rad(y_axis->getItemValue(BasicAxisItem::P_MIN).toDouble()); + double y_max = Units::deg2rad(y_axis->getItemValue(BasicAxisItem::P_MAX).toDouble()); result->setDetectorParameters(n_x, x_min, x_max, n_y, y_min, y_max); @@ -71,11 +64,11 @@ std::unique_ptr<IDetector2D> SphericalDetectorItem::createDetector() const std::unique_ptr<IResolutionFunction2D> SphericalDetectorItem::createResolutionFunction() { // setting up resolution function - auto resfuncItem = dynamic_cast<ResolutionFunctionItem *>( - getGroupItem(P_RESOLUTION_FUNCTION)); + auto resfuncItem = dynamic_cast<ResolutionFunctionItem*>(getGroupItem(P_RESOLUTION_FUNCTION)); Q_ASSERT(resfuncItem); - std::unique_ptr<IResolutionFunction2D> result(resfuncItem->createResolutionFunction(Units::degree)); + std::unique_ptr<IResolutionFunction2D> result( + resfuncItem->createResolutionFunction(Units::degree)); return result; } diff --git a/GUI/coregui/Models/SphericalDetectorItem.h b/GUI/coregui/Models/SphericalDetectorItem.h index 6e0fc93150d..6d663e04de6 100644 --- a/GUI/coregui/Models/SphericalDetectorItem.h +++ b/GUI/coregui/Models/SphericalDetectorItem.h @@ -17,22 +17,18 @@ #ifndef SPHERICALDETECTORITEM_H #define SPHERICALDETECTORITEM_H -#include "SessionItem.h" +#include "DetectorItems.h" -class IDetector2D; -class IResolutionFunction2D; - -class SphericalDetectorItem : public SessionItem +class BA_CORE_API_ SphericalDetectorItem : public DetectorItem { public: static const QString P_PHI_AXIS; static const QString P_ALPHA_AXIS; static const QString P_RESOLUTION_FUNCTION; - explicit SphericalDetectorItem(); + SphericalDetectorItem(); std::unique_ptr<IDetector2D> createDetector() const; std::unique_ptr<IResolutionFunction2D> createResolutionFunction(); - }; #endif // SPHERICALDETECTORITEM_H diff --git a/GUI/coregui/Models/TransformFromDomain.cpp b/GUI/coregui/Models/TransformFromDomain.cpp index 3494db2fd3b..46ba217bffd 100644 --- a/GUI/coregui/Models/TransformFromDomain.cpp +++ b/GUI/coregui/Models/TransformFromDomain.cpp @@ -23,6 +23,8 @@ #include "ComboProperty.h" #include "ConvolutionDetectorResolution.h" #include "DetectorItems.h" +#include "SphericalDetectorItem.h" +#include "RectangularDetectorItem.h" #include "Distributions.h" #include "Ellipse.h" #include "FTDecayFunctionItems.h" diff --git a/GUI/coregui/Models/TransformToDomain.cpp b/GUI/coregui/Models/TransformToDomain.cpp index a28c27fa626..802dac82d51 100644 --- a/GUI/coregui/Models/TransformToDomain.cpp +++ b/GUI/coregui/Models/TransformToDomain.cpp @@ -21,6 +21,8 @@ #include "BornAgainNamespace.h" #include "ComboProperty.h" #include "DetectorItems.h" +#include "SphericalDetectorItem.h" +#include "RectangularDetectorItem.h" #include "Distributions.h" #include "FTDecayFunctionItems.h" #include "FTDistributionItems.h" diff --git a/GUI/coregui/Views/ImportDataWidgets/ImportDataAssistant.cpp b/GUI/coregui/Views/ImportDataWidgets/ImportDataAssistant.cpp index 3d084665a16..dd526f00741 100644 --- a/GUI/coregui/Views/ImportDataWidgets/ImportDataAssistant.cpp +++ b/GUI/coregui/Views/ImportDataWidgets/ImportDataAssistant.cpp @@ -25,6 +25,8 @@ #include "InstrumentItem.h" #include "AxesItems.h" #include "DetectorItems.h" +#include "SphericalDetectorItem.h" +#include "RectangularDetectorItem.h" #include "IDetector2D.h" #include <QFileDialog> #include <QFileInfo> diff --git a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp index 0028d90715b..98fce51731f 100644 --- a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp @@ -17,7 +17,8 @@ #include "DetectorEditorWidget.h" #include "ComponentBoxEditor.h" #include "DetectorItems.h" -#include "DetectorItems.h" +#include "SphericalDetectorItem.h" +#include "RectangularDetectorItem.h" #include "ExtendedDetectorDialog.h" #include "GUIHelpers.h" #include "GroupInfoBox.h" diff --git a/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp b/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp index fca368af830..8ba108975a5 100644 --- a/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp @@ -18,6 +18,8 @@ #include "AxesItems.h" #include "ComboProperty.h" #include "DetectorItems.h" +#include "SphericalDetectorItem.h" +#include "RectangularDetectorItem.h" #include "GUIHelpers.h" #include "InstrumentModel.h" #include "IntensityDataItem.h" diff --git a/GUI/coregui/Views/InstrumentWidgets/RectangularDetectorWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/RectangularDetectorWidget.cpp index 9a9e7915273..8043d5ea549 100644 --- a/GUI/coregui/Views/InstrumentWidgets/RectangularDetectorWidget.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/RectangularDetectorWidget.cpp @@ -19,6 +19,7 @@ #include "ComponentBoxEditor.h" #include "ComponentEditor.h" #include "DetectorItems.h" +#include "RectangularDetectorItem.h" #include "ExtendedDetectorDialog.h" #include "GroupInfoBox.h" #include "columnresizer.h" diff --git a/GUI/coregui/Views/InstrumentWidgets/SphericalDetectorWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/SphericalDetectorWidget.cpp index ae77f75c88f..ed95ee36604 100644 --- a/GUI/coregui/Views/InstrumentWidgets/SphericalDetectorWidget.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/SphericalDetectorWidget.cpp @@ -17,6 +17,7 @@ #include "SphericalDetectorWidget.h" #include "ComponentBoxEditor.h" #include "DetectorItems.h" +#include "SphericalDetectorItem.h" #include "ExtendedDetectorDialog.h" #include "GroupInfoBox.h" #include "columnresizer.h" diff --git a/Tests/UnitTests/GUI/TestMapperCases.h b/Tests/UnitTests/GUI/TestMapperCases.h index 1972912815a..8c3b4efaf7b 100644 --- a/Tests/UnitTests/GUI/TestMapperCases.h +++ b/Tests/UnitTests/GUI/TestMapperCases.h @@ -7,6 +7,8 @@ #include "InterferenceFunctionItems.h" #include "ParticleLayoutItem.h" #include "DetectorItems.h" +#include "SphericalDetectorItem.h" +#include "RectangularDetectorItem.h" #include "ComboProperty.h" #include "DocumentModel.h" #include "SimulationOptionsItem.h" -- GitLab