Skip to content
Snippets Groups Projects
Commit 14cb9fc2 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

GUI now uses width/center

parent 378a68e6
No related branches found
No related tags found
1 merge request!2189Detector2D now parameterized through width and center in phi,alpha (#854)
......@@ -20,8 +20,8 @@ namespace {
namespace Tag {
const QString Nbins("Nbins");
const QString Min("Min");
const QString Max("Max");
const QString Width("Width");
const QString Center("Center");
const QString ExpandGroupbox("ExpandGroupbox"); // obsolete since v22.0
} // namespace Tag
......@@ -29,21 +29,21 @@ const QString ExpandGroupbox("ExpandGroupbox"); // obsolete since v22.0
SpanProperty::SpanProperty() = default;
void SpanProperty::initMin(const QString& label, const QString& tooltip, double value,
void SpanProperty::initWidth(const QString& label, const QString& tooltip, double value,
const RealLimits& limits, uint decimals)
{
m_min.init(label, tooltip, value, decimals, limits, "min");
m_width.init(label, tooltip, value, decimals, limits, "width");
}
void SpanProperty::initMax(const QString& label, const QString& tooltip, double value,
void SpanProperty::initCenter(const QString& label, const QString& tooltip, double value,
const RealLimits& limits, uint decimals)
{
m_max.init(label, tooltip, value, decimals, limits, "max");
m_center.init(label, tooltip, value, decimals, limits, "center");
}
Scale SpanProperty::createAxis(const std::string& name) const
{
return EquiDivision(name, m_nbins, m_min, m_max);
return EquiDivision(name, m_nbins, m_center - m_width / 2, m_center + m_width / 2);
}
void SpanProperty::writeTo(QXmlStreamWriter* w) const
......@@ -55,14 +55,14 @@ void SpanProperty::writeTo(QXmlStreamWriter* w) const
XML::writeAttribute(w, XML::Attrib::value, m_nbins);
w->writeEndElement();
// min
w->writeStartElement(Tag::Min);
m_min.writeTo(w);
// width
w->writeStartElement(Tag::Width);
m_width.writeTo(w);
w->writeEndElement();
// max
w->writeStartElement(Tag::Max);
m_max.writeTo(w);
// center
w->writeStartElement(Tag::Center);
m_center.writeTo(w);
w->writeEndElement();
}
......@@ -79,14 +79,14 @@ void SpanProperty::readFrom(QXmlStreamReader* r)
XML::readAttribute(r, XML::Attrib::value, &m_nbins);
XML::gotoEndElementOfTag(r, tag);
// min
} else if (tag == Tag::Min) {
m_min.readFrom(r);
// width
} else if (tag == Tag::Width) {
m_width.readFrom(r);
XML::gotoEndElementOfTag(r, tag);
// max
} else if (tag == Tag::Max) {
m_max.readFrom(r);
// center
} else if (tag == Tag::Center) {
m_center.readFrom(r);
XML::gotoEndElementOfTag(r, tag);
} else
......
......@@ -36,17 +36,17 @@ class SpanProperty {
public:
explicit SpanProperty();
DoubleProperty& min() { return m_min; }
const DoubleProperty& min() const { return m_min; }
void setMin(double v) { m_min.setValue(v); }
DoubleProperty& width() { return m_width; }
const DoubleProperty& width() const { return m_width; }
void setWidth(double v) { m_width.setValue(v); }
DoubleProperty& max() { return m_max; }
const DoubleProperty& max() const { return m_max; }
void setMax(double v) { m_max.setValue(v); }
DoubleProperty& center() { return m_center; }
const DoubleProperty& center() const { return m_center; }
void setCenter(double v) { m_center.setValue(v); }
void initMin(const QString& label, const QString& tooltip, double value,
void initWidth(const QString& label, const QString& tooltip, double value,
const RealLimits& limits = RealLimits::nonnegative(), uint decimals = 3);
void initMax(const QString& label, const QString& tooltip, double value,
void initCenter(const QString& label, const QString& tooltip, double value,
const RealLimits& limits = RealLimits::nonnegative(), uint decimals = 3);
Scale createAxis(const std::string& name) const;
......@@ -59,8 +59,8 @@ public:
private:
uint m_nbins = 100;
DoubleProperty m_min;
DoubleProperty m_max;
DoubleProperty m_width;
DoubleProperty m_center;
};
#endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_SPANPROPERTY_H
......@@ -39,13 +39,13 @@ const QString ResolutionFunction("ResolutionFunction");
DetectorItem::DetectorItem()
{
m_phiAxis.initMin("Min (deg)", "Lower edge of first phi-bin", -2.0,
m_phiAxis.initWidth("Width (deg)", "Lower edge of first phi-bin", -2.0,
RealLimits::limited(-90, 90));
m_phiAxis.initMax("Max (deg)", "Upper edge of last phi-bin", 2.0, RealLimits::limited(-90, 90));
m_phiAxis.initCenter("Center (deg)", "Upper edge of last phi-bin", 2.0, RealLimits::limited(-90, 90));
m_alphaAxis.initMin("Min (deg)", "Lower edge of first alpha-bin", 0.0,
m_alphaAxis.initWidth("Width (deg)", "Lower edge of first alpha-bin", 0.0,
RealLimits::limited(-90, 90));
m_alphaAxis.initMax("Max (deg)", "Upper edge of last alpha-bin", 3.0,
m_alphaAxis.initCenter("Center (deg)", "Upper edge of last alpha-bin", 3.0,
RealLimits::limited(-90, 90));
m_resolutionFunction.init("Resolution function", "Detector resolution function",
......@@ -57,16 +57,12 @@ DetectorItem::~DetectorItem() = default;
std::unique_ptr<IDetector> DetectorItem::createDetector() const
{
const int n_x = m_phiAxis.nbins();
const double x_min = Units::deg2rad(m_phiAxis.min());
const double x_max = Units::deg2rad(m_phiAxis.max());
const double x_wid = x_max - x_min;
const double x_cen = (x_min + x_max) / 2;
const double x_wid= Units::deg2rad(m_phiAxis.width());
const double x_cen = Units::deg2rad(m_phiAxis.center());
const int n_y = m_alphaAxis.nbins();
const double y_min = Units::deg2rad(m_alphaAxis.min());
const double y_max = Units::deg2rad(m_alphaAxis.max());
const double y_wid = y_max - y_min;
const double y_cen = (y_min + y_max) / 2;
const double y_wid= Units::deg2rad(m_alphaAxis.width());
const double y_cen = Units::deg2rad(m_alphaAxis.center());
auto result = std::make_unique<Detector2D>(x_wid, y_wid, n_x, n_y, x_cen, y_cen);
......
......@@ -256,11 +256,11 @@ void updateDetector(GISASInstrumentItem* instrument_item, const IDetector& detec
auto* detector_item = instrument_item->detectorItem();
detector_item->phiAxis().setNbins(detector.axis(0).size());
detector_item->phiAxis().setMin(Units::rad2deg(detector.axis(0).min()));
detector_item->phiAxis().setMax(Units::rad2deg(detector.axis(0).max()));
detector_item->phiAxis().setWidth(Units::rad2deg(detector.axis(0).span()));
detector_item->phiAxis().setCenter(Units::rad2deg(detector.axis(0).center()));
detector_item->alphaAxis().setNbins(detector.axis(1).size());
detector_item->alphaAxis().setMin(Units::rad2deg(detector.axis(1).min()));
detector_item->alphaAxis().setMax(Units::rad2deg(detector.axis(1).max()));
detector_item->alphaAxis().setWidth(Units::rad2deg(detector.axis(1).span()));
detector_item->alphaAxis().setCenter(Units::rad2deg(detector.axis(1).center()));
setDetectorResolution(detector_item, detector);
setMaskStacks(detector_item, detector);
......
......@@ -385,12 +385,12 @@ void ParameterTreeBuilder::addDetector(ParameterLabelItem* parentLabel, Detector
};
auto* label = new ParameterLabelItem("Detector", parentLabel);
auto* phiLabel = new ParameterLabelItem("Phi axis", label);
addParameterItem(phiLabel, detector->phiAxis().min());
addParameterItem(phiLabel, detector->phiAxis().max());
auto* alphaLabel = new ParameterLabelItem("Alpha axis", label);
addParameterItem(alphaLabel, detector->alphaAxis().min());
addParameterItem(alphaLabel, detector->alphaAxis().max());
auto* phiLabel = new ParameterLabelItem("Phi span", label);
addParameterItem(phiLabel, detector->phiAxis().width());
addParameterItem(phiLabel, detector->phiAxis().center());
auto* alphaLabel = new ParameterLabelItem("Alpha span", label);
addParameterItem(alphaLabel, detector->alphaAxis().width());
addParameterItem(alphaLabel, detector->alphaAxis().center());
addResolutionFunction(label);
}
......
......@@ -38,27 +38,27 @@ SpanPropertyForm::SpanPropertyForm(QWidget* parent, const QString& groupTitle,
RealLimits::nonnegative(), nbinsTooltip);
layout->addRow("# bins:", m_nbinsSpinBox);
m_minSpinBox = GUI::Util::createDoubleSpinBoxRow(layout, spanProperty->min());
m_maxSpinBox = GUI::Util::createDoubleSpinBoxRow(layout, spanProperty->max());
m_widthSpinBox = GUI::Util::createDoubleSpinBoxRow(layout, spanProperty->width());
m_centerSpinBox = GUI::Util::createDoubleSpinBoxRow(layout, spanProperty->center());
connect(m_minSpinBox, &DoubleSpinBox::baseValueChanged, [this](double v) {
if (m_spanProperty->min() != v) {
m_spanProperty->setMin(v);
connect(m_widthSpinBox, &DoubleSpinBox::baseValueChanged, [this](double v) {
if (m_spanProperty->width() != v) {
m_spanProperty->setWidth(v);
emit dataChanged();
if (m_spanProperty->max() < v) {
m_spanProperty->setMax(v);
m_maxSpinBox->updateValue();
if (m_spanProperty->center() < v) {
m_spanProperty->setCenter(v);
m_centerSpinBox->updateValue();
}
}
});
connect(m_maxSpinBox, &DoubleSpinBox::baseValueChanged, [this](double v) {
if (m_spanProperty->max() != v) {
m_spanProperty->setMax(v);
connect(m_centerSpinBox, &DoubleSpinBox::baseValueChanged, [this](double v) {
if (m_spanProperty->center() != v) {
m_spanProperty->setCenter(v);
emit dataChanged();
if (m_spanProperty->min() > v) {
m_spanProperty->setMin(v);
m_minSpinBox->updateValue();
if (m_spanProperty->width() > v) {
m_spanProperty->setWidth(v);
m_widthSpinBox->updateValue();
}
}
});
......
......@@ -38,8 +38,8 @@ signals:
private:
QSpinBox* m_nbinsSpinBox;
SpanProperty* m_spanProperty;
DoubleSpinBox* m_minSpinBox;
DoubleSpinBox* m_maxSpinBox;
DoubleSpinBox* m_widthSpinBox;
DoubleSpinBox* m_centerSpinBox;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment