From 72aba834db8ca3d3234eb1151d2a3f64d75bda46 Mon Sep 17 00:00:00 2001 From: Walter Van Herck <w.van.herck@fz-juelich.de> Date: Mon, 19 Oct 2015 11:20:08 +0200 Subject: [PATCH] Fix bug: creation of axes in GUI produces wrong axis names --- Core/Algorithms/src/GISASSimulation.cpp | 14 ++----- GUI/coregui/Models/DetectorItems.cpp | 4 -- GUI/coregui/Models/DetectorItems.h | 1 - GUI/coregui/Models/TransformFromDomain.cpp | 25 ------------- GUI/coregui/Models/TransformFromDomain.h | 2 - GUI/coregui/Models/TransformToDomain.cpp | 37 +++++++------------ GUI/coregui/Models/item_constants.h | 3 -- .../DetectorEditorWidget.cpp | 12 +++--- .../InstrumentWidgets/DetectorEditorWidget.h | 2 +- 9 files changed, 22 insertions(+), 78 deletions(-) diff --git a/Core/Algorithms/src/GISASSimulation.cpp b/Core/Algorithms/src/GISASSimulation.cpp index 82873b1d626..4fb337a796b 100644 --- a/Core/Algorithms/src/GISASSimulation.cpp +++ b/Core/Algorithms/src/GISASSimulation.cpp @@ -104,17 +104,9 @@ int GISASSimulation::getNumberOfSimulationElements() const throw RuntimeErrorException("GISASSimulation::getNumberOfSimulationElements: " "detector is not two-dimensional"); } - const IAxis &phi_axis = m_instrument.getDetectorAxis(BornAgain::PHI_AXIS_INDEX); - if (phi_axis.getName()!=BornAgain::PHI_AXIS_NAME) { - throw RuntimeErrorException("GISASSimulation::getNumberOfSimulationElements: " - "phi-axis is not correct"); - } - const IAxis &alpha_axis = m_instrument.getDetectorAxis(BornAgain::ALPHA_AXIS_INDEX); - if (alpha_axis.getName()!=BornAgain::ALPHA_AXIS_NAME) { - throw RuntimeErrorException("GISASSimulation::getNumberOfSimulationElements: " - "alpha-axis is not correct"); - } - return phi_axis.getSize()*alpha_axis.getSize(); + const IAxis &x_axis = m_instrument.getDetectorAxis(BornAgain::X_AXIS_INDEX); + const IAxis &y_axis = m_instrument.getDetectorAxis(BornAgain::X_AXIS_INDEX); + return x_axis.getSize()*y_axis.getSize(); } OutputData<double> *GISASSimulation::getDetectorIntensity() const diff --git a/GUI/coregui/Models/DetectorItems.cpp b/GUI/coregui/Models/DetectorItems.cpp index 0bfb6acbbbd..bf3236a81be 100644 --- a/GUI/coregui/Models/DetectorItems.cpp +++ b/GUI/coregui/Models/DetectorItems.cpp @@ -30,7 +30,6 @@ DetectorItem::DetectorItem(ParameterizedItem *parent) // -------------------------------------------------------------------------- // -const QString PhiAlphaDetectorItem::P_BINNING = "Binning"; const QString PhiAlphaDetectorItem::P_PHI_AXIS = "Phi axis"; const QString PhiAlphaDetectorItem::P_ALPHA_AXIS = "Alpha axis"; const QString PhiAlphaDetectorItem::P_RESOLUTION_FUNCTION = "Type"; @@ -39,9 +38,6 @@ PhiAlphaDetectorItem::PhiAlphaDetectorItem(ParameterizedItem *parent) : ParameterizedItem(Constants::PhiAlphaDetectorType, parent) { setItemName(Constants::PhiAlphaDetectorType); - ComboProperty binning; - binning << Constants::AXIS_CONSTK_BINNING << Constants::AXIS_FIXED_BINNING; - registerProperty(P_BINNING, binning.getVariant()); registerGroupProperty(P_PHI_AXIS, Constants::BasicAxisType); getSubItems()[P_PHI_AXIS]->setPropertyAppearance(BasicAxisItem::P_TITLE, PropertyAttribute::HIDDEN); diff --git a/GUI/coregui/Models/DetectorItems.h b/GUI/coregui/Models/DetectorItems.h index 03cafb70872..a8342a3f28a 100644 --- a/GUI/coregui/Models/DetectorItems.h +++ b/GUI/coregui/Models/DetectorItems.h @@ -31,7 +31,6 @@ public: class PhiAlphaDetectorItem : public ParameterizedItem { public: - static const QString P_BINNING; static const QString P_PHI_AXIS; static const QString P_ALPHA_AXIS; static const QString P_RESOLUTION_FUNCTION; diff --git a/GUI/coregui/Models/TransformFromDomain.cpp b/GUI/coregui/Models/TransformFromDomain.cpp index a3747389aab..0a157ba5b06 100644 --- a/GUI/coregui/Models/TransformFromDomain.cpp +++ b/GUI/coregui/Models/TransformFromDomain.cpp @@ -409,24 +409,6 @@ bool TransformFromDomain::isHexagonalLattice(double length1, double length2, dou return false; } -//! FIXME Remove hardcoded strings -QString TransformFromDomain::getDetectorBinning(const IDetector2D *detector) -{ - boost::scoped_ptr<IAxis> P_phi_axis(detector->getAxis(0).clone()); - boost::scoped_ptr<IAxis> P_alpha_axis(detector->getAxis(1).clone()); - - if (dynamic_cast<ConstKBinAxis *>(P_phi_axis.get()) - && dynamic_cast<ConstKBinAxis *>(P_alpha_axis.get())) { - return Constants::AXIS_CONSTK_BINNING; - } else if (dynamic_cast<FixedBinAxis *>(P_phi_axis.get()) - && dynamic_cast<FixedBinAxis *>(P_alpha_axis.get())) { - return Constants::AXIS_FIXED_BINNING; - } else { - throw GUIHelpers::Error("TransformFromDomain::getDetectorBinning()" - " -> Error. Can't determine detector binning"); - } -} - void TransformFromDomain::setItemFromSample(BeamItem *beamItem, const GISASSimulation &simulation) { Q_ASSERT(beamItem); @@ -468,13 +450,6 @@ void TransformFromDomain::setItemFromSample(PhiAlphaDetectorItem *detectorItem, const IAxis &phi_axis = detector->getAxis(0); const IAxis &alpha_axis = detector->getAxis(1); - ComboProperty binning_property - = detectorItem->getRegisteredProperty(PhiAlphaDetectorItem::P_BINNING) - .value<ComboProperty>(); - binning_property.setValue(TransformFromDomain::getDetectorBinning(detector)); - detectorItem->setRegisteredProperty(PhiAlphaDetectorItem::P_BINNING, - binning_property.getVariant()); - BasicAxisItem *phiAxisItem = dynamic_cast<BasicAxisItem *>( detectorItem->getSubItems()[PhiAlphaDetectorItem::P_PHI_AXIS]); Q_ASSERT(phiAxisItem); diff --git a/GUI/coregui/Models/TransformFromDomain.h b/GUI/coregui/Models/TransformFromDomain.h index 9ad32ef0d0e..934e4d07260 100644 --- a/GUI/coregui/Models/TransformFromDomain.h +++ b/GUI/coregui/Models/TransformFromDomain.h @@ -66,8 +66,6 @@ BA_CORE_API_ bool isValidRoughness(const LayerRoughness *roughness); BA_CORE_API_ bool isSquareLattice(double length1, double length2, double angle); BA_CORE_API_ bool isHexagonalLattice(double length1, double length2, double angle); -BA_CORE_API_ QString getDetectorBinning(const IDetector2D *detector); - BA_CORE_API_ void setItemFromSample(BeamItem *beamItem, const GISASSimulation &simulation); BA_CORE_API_ void setItemFromSample(PhiAlphaDetectorItem *detectorItem, const GISASSimulation &simulation); diff --git a/GUI/coregui/Models/TransformToDomain.cpp b/GUI/coregui/Models/TransformToDomain.cpp index 9fe907be2ce..09cd79c5b95 100644 --- a/GUI/coregui/Models/TransformToDomain.cpp +++ b/GUI/coregui/Models/TransformToDomain.cpp @@ -309,9 +309,6 @@ Beam *TransformToDomain::createBeam(const ParameterizedItem &item) double azimuthal_angle = Units::deg2rad(beamItem->getAzimuthalAngle()); result->setCentralK( lambda, inclination_angle, azimuthal_angle); -// AngleProperty inclination_angle = item.getRegisteredProperty(BeamItem::P_INCLINATION_ANGLE).value<AngleProperty>(); -// AngleProperty azimuthal_angle = item.getRegisteredProperty(BeamItem::P_AZIMUTHAL_ANGLE).value<AngleProperty>(); -// result->setCentralK( lambda, inclination_angle.getValueInRadians(), azimuthal_angle.getValueInRadians()); return result; } @@ -322,27 +319,19 @@ void TransformToDomain::initInstrumentFromDetectorItem(const ParameterizedItem & if (subDetector->modelType() == Constants::PhiAlphaDetectorType) { - BasicAxisItem *phiAxis = dynamic_cast<BasicAxisItem *>(subDetector->getSubItems()[PhiAlphaDetectorItem::P_PHI_AXIS]); - Q_ASSERT(phiAxis); - int nphi = phiAxis->getRegisteredProperty(BasicAxisItem::P_NBINS).toInt(); - double phi_min = Units::deg2rad(phiAxis->getRegisteredProperty(BasicAxisItem::P_MIN).toDouble()); - double phi_max = Units::deg2rad(phiAxis->getRegisteredProperty(BasicAxisItem::P_MAX).toDouble()); - - BasicAxisItem *alphaAxis = dynamic_cast<BasicAxisItem *>(subDetector->getSubItems()[PhiAlphaDetectorItem::P_ALPHA_AXIS]); - Q_ASSERT(alphaAxis); - int nalpha = alphaAxis->getRegisteredProperty(BasicAxisItem::P_NBINS).toInt(); - double alpha_min = Units::deg2rad(alphaAxis->getRegisteredProperty(BasicAxisItem::P_MIN).toDouble()); - double alpha_max = Units::deg2rad(alphaAxis->getRegisteredProperty(BasicAxisItem::P_MAX).toDouble()); - - ComboProperty binning = subDetector->getRegisteredProperty(PhiAlphaDetectorItem::P_BINNING).value<ComboProperty>(); - - if(binning.getValue() == Constants::AXIS_CONSTK_BINNING) { - instrument->setDetectorAxes(ConstKBinAxis("phi_x",nphi, phi_min, phi_max), ConstKBinAxis("alpha_x", nalpha, alpha_min, alpha_max)); - }else if(binning.getValue() == Constants::AXIS_FIXED_BINNING) { - instrument->setDetectorAxes(FixedBinAxis("phi_x",nphi, phi_min, phi_max), FixedBinAxis("alpha_x", nalpha, alpha_min, alpha_max)); - } else { - throw GUIHelpers::Error("TransformToDomain::initInstrumentFromDetectorItem() -> Unknown axes"); - } + BasicAxisItem *x_axis = dynamic_cast<BasicAxisItem *>(subDetector->getSubItems()[PhiAlphaDetectorItem::P_PHI_AXIS]); + Q_ASSERT(x_axis); + int n_x = x_axis->getRegisteredProperty(BasicAxisItem::P_NBINS).toInt(); + double x_min = Units::deg2rad(x_axis->getRegisteredProperty(BasicAxisItem::P_MIN).toDouble()); + double x_max = Units::deg2rad(x_axis->getRegisteredProperty(BasicAxisItem::P_MAX).toDouble()); + + BasicAxisItem *y_axis = dynamic_cast<BasicAxisItem *>(subDetector->getSubItems()[PhiAlphaDetectorItem::P_ALPHA_AXIS]); + Q_ASSERT(y_axis); + int n_y = y_axis->getRegisteredProperty(BasicAxisItem::P_NBINS).toInt(); + double y_min = Units::deg2rad(y_axis->getRegisteredProperty(BasicAxisItem::P_MIN).toDouble()); + double y_max = Units::deg2rad(y_axis->getRegisteredProperty(BasicAxisItem::P_MAX).toDouble()); + + instrument->setDetectorParameters(n_x, x_min, x_max, n_y, y_min, y_max); // setting up resolution function ResolutionFunctionItem *resfuncItem = dynamic_cast<ResolutionFunctionItem *> diff --git a/GUI/coregui/Models/item_constants.h b/GUI/coregui/Models/item_constants.h index 03320f99eeb..a784f3c884f 100644 --- a/GUI/coregui/Models/item_constants.h +++ b/GUI/coregui/Models/item_constants.h @@ -162,9 +162,6 @@ const ModelType GRADIENT_SPECTRUM = "Spectrum"; const ModelType GRADIENT_JET = "Jet"; const ModelType GRADIENT_HUES = "Hues"; -const ModelType AXIS_FIXED_BINNING = "Fixed"; -const ModelType AXIS_CONSTK_BINNING = "Const KBin"; - const ModelType JOB_RUN_IMMEDIATELY = "Immediately"; const ModelType JOB_RUN_IN_BACKGROUND = "In background"; const ModelType JOB_RUN_SUBMIT_ONLY = "Submit only"; diff --git a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp index 3b663d92450..641d67df54e 100644 --- a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp @@ -20,7 +20,7 @@ #include <QVBoxLayout> DetectorEditorWidget::DetectorEditorWidget(QWidget *parent) - : QWidget(parent), m_binningEditor(0), m_phiAxisEditor(0), m_alphaAxisEditor(0), + : QWidget(parent), m_detectorTypeEditor(0), m_phiAxisEditor(0), m_alphaAxisEditor(0), m_resolutionFunctionEditor(0), m_gridLayout(0), m_detectorItem(0) { QGroupBox *groupBox = new QGroupBox("Detector Parameters"); @@ -30,8 +30,8 @@ DetectorEditorWidget::DetectorEditorWidget(QWidget *parent) // whole content is represented as grid layout m_gridLayout = new QGridLayout; - m_binningEditor = new AwesomePropertyEditor(this, AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE); - m_gridLayout->addWidget(m_binningEditor, 0, 0); + m_detectorTypeEditor = new AwesomePropertyEditor(this, AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE); + m_gridLayout->addWidget(m_detectorTypeEditor, 0, 0); m_phiAxisEditor = new AwesomePropertyEditor(this, AwesomePropertyEditor::BROWSER_GROUPBOX_TYPE); m_gridLayout->addWidget(m_phiAxisEditor, 1, 0); m_alphaAxisEditor @@ -54,7 +54,7 @@ DetectorEditorWidget::DetectorEditorWidget(QWidget *parent) void DetectorEditorWidget::setDetectorItem(DetectorItem *detectorItem) { m_detectorItem = detectorItem; - m_binningEditor->clearEditor(); + m_detectorTypeEditor->clearEditor(); m_phiAxisEditor->clearEditor(); m_alphaAxisEditor->clearEditor(); m_resolutionFunctionEditor->clearEditor(); @@ -65,11 +65,9 @@ void DetectorEditorWidget::setDetectorItem(DetectorItem *detectorItem) PhiAlphaDetectorItem *subDetector = dynamic_cast<PhiAlphaDetectorItem *>( detectorItem->getSubItems()[DetectorItem::P_DETECTOR]); - m_binningEditor->addItemProperty(detectorItem, DetectorItem::P_DETECTOR, QString(), + m_detectorTypeEditor->addItemProperty(detectorItem, DetectorItem::P_DETECTOR, QString(), AwesomePropertyEditor::SKIP); - m_binningEditor->addItemProperty(subDetector, PhiAlphaDetectorItem::P_BINNING); - ParameterizedItem *phiAxisItem = subDetector->getSubItems()[PhiAlphaDetectorItem::P_PHI_AXIS]; m_phiAxisEditor->addItemProperties(phiAxisItem, QString("Phi axis"), AwesomePropertyEditor::INSERT_AFTER); diff --git a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.h b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.h index c30834b94a6..3f75c5b43cc 100644 --- a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.h +++ b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.h @@ -34,7 +34,7 @@ public: QGridLayout *getGridLayout() { return m_gridLayout;} private: - AwesomePropertyEditor *m_binningEditor; + AwesomePropertyEditor *m_detectorTypeEditor; AwesomePropertyEditor *m_phiAxisEditor; AwesomePropertyEditor *m_alphaAxisEditor; AwesomePropertyEditor *m_resolutionFunctionEditor; -- GitLab