diff --git a/Base/Util/ConversionUtil.cpp b/Base/Util/ConversionUtil.cpp index 28437a029630d3aff9756fcf56a784cf62d96ca8..f7d67c63b2832de360f36933fdf1c35c63129133 100644 --- a/Base/Util/ConversionUtil.cpp +++ b/Base/Util/ConversionUtil.cpp @@ -17,13 +17,12 @@ #include <cmath> #include <numbers> -double Conversion::Refl::qz2alpha(double lambda, double qz) +/* rad */ double Conversion::Refl::qz2alpha(double lambda /* nm */, double qz /* 1/nm */) { return std::asin(qz * lambda / 4.0 / std::numbers::pi); } -double Conversion::Refl::qz2lambda(double alpha, double qz) +/* nm */ double Conversion::Refl::qz2lambda(double alpha /* rad */, double qz /* 1/nm */) { return 4.0 * std::numbers::pi * std::sin(alpha) / qz; } - diff --git a/Base/Util/ConversionUtil.h b/Base/Util/ConversionUtil.h index 67bb7747669deaeb2b1d395a86f4172b6037e66d..3e00da341de7c4ace4bdadd5ca7a3cbc4edf21a3 100644 --- a/Base/Util/ConversionUtil.h +++ b/Base/Util/ConversionUtil.h @@ -21,6 +21,6 @@ double qz2alpha(double lambda, double qz); double qz2lambda(double alpha, double qz); -} +} // namespace Conversion::Refl #endif // BORNAGAIN_BASE_UTIL_CONVERSIONUTIL_H diff --git a/GUI/Model/Axis/BasicAxisItem.h b/GUI/Model/Axis/BasicAxisItem.h index 6b715a04252dc4ff6188040b1465ff4c8ce7d89f..5e158e809ce57af13ed9e58bdb642bfc74322635 100644 --- a/GUI/Model/Axis/BasicAxisItem.h +++ b/GUI/Model/Axis/BasicAxisItem.h @@ -33,13 +33,13 @@ public: public: Scale makeScale(std::string name) const; - virtual int size() const { return m_nbins; } + int size() const { return m_nbins; } void resize(size_t value); - virtual double min() const { return m_min; } + double min() const { return m_min; } void setMin(double value); - virtual double max() const { return m_max; } + double max() const { return m_max; } void setMax(double value); bool isVisible() const { return m_visible; } diff --git a/GUI/Model/Axis/PointwiseAxisItem.cpp b/GUI/Model/Axis/PointwiseAxisItem.cpp index 56398fbc80a3c611ba367b8c8899726c0352bac7..12c8f1a47fae2bc3499d7ba76755c9eca579a62e 100644 --- a/GUI/Model/Axis/PointwiseAxisItem.cpp +++ b/GUI/Model/Axis/PointwiseAxisItem.cpp @@ -16,6 +16,7 @@ #include "Base/Axis/Frame.h" #include "Base/Axis/MakeScale.h" #include "Base/Axis/Scale.h" +#include "Base/Const/Units.h" #include "Device/Data/Datafield.h" #include "Device/IO/ReadWriteINT.h" #include "GUI/Support/XML/UtilXML.h" @@ -50,24 +51,6 @@ const Scale* PointwiseAxisItem::axis() const return m_axis.get(); } -int PointwiseAxisItem::size() const -{ - ASSERT(m_axis); - return m_axis->size(); -} - -double PointwiseAxisItem::min() const -{ - ASSERT(m_axis); - return m_axis->min(); -} - -double PointwiseAxisItem::max() const -{ - ASSERT(m_axis); - return m_axis->max(); -} - QString PointwiseAxisItem::nativeAxisUnits() const { return m_nativeAxisUnits; @@ -152,7 +135,13 @@ void PointwiseAxisItem::updateAxIndicators(const Frame& cs) if (!m_axis || nativeAxisUnits() == "bin") return; - setMin(cs.axis(0).min()); - setMax(cs.axis(0).max()); + double min = cs.axis(0).min(); + double max = cs.axis(0).max(); + if (cs.axis(0).unit() == "rad") { + min = Units::rad2deg(cs.axis(0).min()); + max = Units::rad2deg(cs.axis(0).max()); + } + setMin(min); + setMax(max); resize(static_cast<int>(m_axis->size())); } diff --git a/GUI/Model/Axis/PointwiseAxisItem.h b/GUI/Model/Axis/PointwiseAxisItem.h index f9e3c205c6f6337abc1faefcdf8567631d52ab46..852e09d0bca840ddbea14204d04d8a51227000bd 100644 --- a/GUI/Model/Axis/PointwiseAxisItem.h +++ b/GUI/Model/Axis/PointwiseAxisItem.h @@ -30,10 +30,6 @@ public: void setAxis(const Scale& axis); const Scale* axis() const; - int size() const override; - double min() const override; - double max() const override; - QString nativeAxisUnits() const; void updateAxIndicators(const Frame& cs); diff --git a/GUI/Model/Beam/GrazingScanItem.cpp b/GUI/Model/Beam/GrazingScanItem.cpp index 9535efed13361948bba2370e298830e355143d0a..e60c61a1af9d1c4c547dd9934cfc85b069983e8a 100644 --- a/GUI/Model/Beam/GrazingScanItem.cpp +++ b/GUI/Model/Beam/GrazingScanItem.cpp @@ -186,13 +186,18 @@ void GrazingScanItem::initUniformAxis(const Scale& axis) m_uniformAlphaAxis->resize(static_cast<int>(axis.size())); } -void GrazingScanItem::initListScan(const Scale& axis, const Frame& frame) +void GrazingScanItem::initListScan(const Scale& axis) { if (!m_pointwiseAlphaAxis) { m_pointwiseAlphaAxis = std::make_unique<PointwiseAxisItem>(); setAxisPresentationDefaults(m_pointwiseAlphaAxis.get()); } - m_pointwiseAlphaAxis->setAxis(axis); +} + +void GrazingScanItem::updateAxIndicators(const Frame& frame) +{ + if (!m_pointwiseAlphaAxis) + return; m_pointwiseAlphaAxis->updateAxIndicators(frame); } diff --git a/GUI/Model/Beam/GrazingScanItem.h b/GUI/Model/Beam/GrazingScanItem.h index 4095cb586f0a26c26582d3461530361cdc32f225..ff459bd5bfbebd08f1e7a17fed377dc8edba6d82 100644 --- a/GUI/Model/Beam/GrazingScanItem.h +++ b/GUI/Model/Beam/GrazingScanItem.h @@ -59,7 +59,8 @@ public: void selectListScan(); void initUniformAxis(const Scale& axis); - void initListScan(const Scale& axis, const Frame& frame); + void initListScan(const Scale& axis); + void updateAxIndicators(const Frame& frame); private: std::unique_ptr<BasicAxisItem> m_uniformAlphaAxis; diff --git a/GUI/Model/Beam/SourceItems.cpp b/GUI/Model/Beam/SourceItems.cpp index 0572ec16b11f6c69fe6781f9e55ea9948ab2e201..1d3d1cc41ccc88630f06446d93835b1f01fae8d4 100644 --- a/GUI/Model/Beam/SourceItems.cpp +++ b/GUI/Model/Beam/SourceItems.cpp @@ -16,6 +16,7 @@ #include "Base/Axis/Scale.h" #include "Base/Const/Units.h" #include "Base/Util/Assert.h" +#include "Base/Util/ConversionUtil.h" #include "Device/Beam/Beam.h" #include "Device/Beam/FootprintGauss.h" #include "Device/Beam/FootprintSquare.h" @@ -359,13 +360,13 @@ BasicAxisItem* ScanItem::inclinationAxisItem() const return grazingScanItem()->alphaAxisItem(); } -void ScanItem::updateToData(const Scale& axis, const Frame& frame) +void ScanItem::updateToData(const Scale& axis) { if (axis.unit() == "bin") { grazingScanItem()->initUniformAxis(axis); grazingScanItem()->selectUniformAxis(); } else { - grazingScanItem()->initListScan(axis, frame); + grazingScanItem()->initListScan(axis); grazingScanItem()->selectListScan(); } } diff --git a/GUI/Model/Beam/SourceItems.h b/GUI/Model/Beam/SourceItems.h index 862e914a70e9d08d3953e3a22c43e965735c7b56..bdc96167cac94dcecdefe9f319f654d0b9a64d4a 100644 --- a/GUI/Model/Beam/SourceItems.h +++ b/GUI/Model/Beam/SourceItems.h @@ -100,7 +100,7 @@ public: GrazingScanItem* grazingScanItem() const; BasicAxisItem* inclinationAxisItem() const; - void updateToData(const Scale& axis, const Frame& frame); + void updateToData(const Scale& axis); private: std::unique_ptr<GrazingScanItem> m_grazingScanItem; diff --git a/GUI/Model/Device/InstrumentItems.cpp b/GUI/Model/Device/InstrumentItems.cpp index 58479c0d47fa7b7f0a39066593b7de8922d85b49..7229b5d6b0181e47453a550fd96b6225165a3629 100644 --- a/GUI/Model/Device/InstrumentItems.cpp +++ b/GUI/Model/Device/InstrumentItems.cpp @@ -17,6 +17,7 @@ #include "Base/Axis/Scale.h" #include "Base/Const/Units.h" #include "Base/Util/Assert.h" +#include "Base/Util/ConversionUtil.h" #include "Device/Beam/Beam.h" #include "Device/Beam/IFootprint.h" #include "Device/Data/Datafield.h" @@ -372,7 +373,8 @@ void SpecularInstrumentItem::updateToRealData(const DatafileItem* item) throw std::runtime_error("Specular instrument type is incompatible with passed data shape"); const auto& dataAxis = item->nativeDatafield()->axis(0); - scanItem()->updateToData(dataAxis, makeFrame()); + scanItem()->updateToData(dataAxis); + scanItem()->grazingScanItem()->updateAxIndicators(makeFrame()); } bool SpecularInstrumentItem::alignedWith(const DatafileItem* item) const @@ -407,15 +409,30 @@ Frame SpecularInstrumentItem::makeFrame() const ASSERT(axis_item); if (auto* pointwise_axis = dynamic_cast<PointwiseAxisItem*>(axis_item)) { - if (!pointwise_axis->axis()) // workaround for loading project + const Scale* pAxis = pointwise_axis->axis(); + if (!pAxis) // workaround for loading project return Frame({}); - Scale* ax0 = pointwise_axis->axis()->clone(); + + if (pAxis->unit() == "1/nm") { + double lambda = scanItem()->wavelength(); + Scale ax = + pAxis->transformedScale(Coordinate("alpha_i", "rad").label(), [lambda](double x) { + return Conversion::Refl::qz2alpha(lambda, x); + }); + return Frame(std::move(ax.clone())); + + } else if (pAxis->unit() == "deg") { + Scale ax = pAxis->transformedScale(Coordinate(pAxis->coordName(), "rad").label(), + Units::deg2rad); + return Frame(std::move(ax.clone())); + } + + Scale* ax0 = pAxis->clone(); std::vector<const Scale*> f{ax0}; return Frame(f); } Scale axis = axis_item->makeScale("alpha_i (rad)"); - std::vector<const Scale*> f{axis.clone()}; return Frame(f); }