Skip to content
Snippets Groups Projects
Commit d1632bea authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

[from_SelectionDescriptor_3.1] GUI: rm SelectionDescriptor for detector alignment ()

Merging branch 'from_SelectionDescriptor_3.1'  into 'main'.

See merge request !1172
parents 3d81c6e1 1841d973
No related branches found
No related tags found
1 merge request!1172GUI: rm SelectionDescriptor for detector alignment
Pipeline #82457 passed
......@@ -17,8 +17,6 @@
#include "GUI/Util/ComboProperty.h"
class MinimizerItem;
//! The MinimizerItemCatalog class is a static class to provide MinimizerItem
//! with the list of available minimizers/algorithms.
......
......@@ -45,32 +45,14 @@ const double default_detector_width = 20.0;
const double default_detector_height = 20.0;
const double default_detector_distance = 1000.0;
QString alignmentTitle(RectangularDetector::EDetectorArrangement a)
{
switch (a) {
case RectangularDetector::GENERIC:
return "Generic";
case RectangularDetector::PERPENDICULAR_TO_SAMPLE:
return "Perpendicular to sample x-axis";
case RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM:
return "Perpendicular to direct beam";
case RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM:
return "Perpendicular to reflected beam";
case RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS:
return "Perpendicular to reflected beam (intersection unknown)";
default:
ASSERT(false);
}
}
//! Returns the alignments as expected on the UI
QList<RectangularDetector::EDetectorArrangement> alignments()
{
return {RectangularDetector::GENERIC, RectangularDetector::PERPENDICULAR_TO_SAMPLE,
RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM,
RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM,
RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS};
}
//! Holds the alignments as expected on the UI (map is sorted by keys)
const QMap<RectangularDetector::EDetectorArrangement, QString> alignment_names_map = {
{RectangularDetector::GENERIC, "Generic"},
{RectangularDetector::PERPENDICULAR_TO_SAMPLE, "Perpendicular to sample x-axis"},
{RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM, "Perpendicular to direct beam"},
{RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM, "Perpendicular to reflected beam"},
{RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS,
"Perpendicular to reflected beam (intersection unknown)"}};
void initResolutionFunction(ResolutionFunctionItem* newFunc, const ResolutionFunctionItem*)
{
......@@ -107,15 +89,15 @@ RectangularDetectorItem::RectangularDetectorItem()
m_distance.init("Distance", "Distance from the sample origin to the detector plane",
default_detector_distance, "mm", "distance");
m_detectorAlignment = RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM;
m_detectorAlignment = ComboProperty::fromList(
alignment_names_map.values(),
alignment_names_map.value(RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM));
updateTooltips();
}
void RectangularDetectorItem::serialize(Streamer& s)
{
int alignment = m_detectorAlignment;
s.assertVersion(0);
// base class members
Serialize::rwClass(s, Tag::Masks, m_maskItems);
......@@ -126,7 +108,20 @@ void RectangularDetectorItem::serialize(Streamer& s)
Serialize::rwValue(s, Tag::YSize, m_ySize);
Serialize::rwProperty(s, Tag::Width, m_width);
Serialize::rwProperty(s, Tag::Height, m_height);
Serialize::rwValue(s, Tag::Alignment, alignment);
if (auto* w = s.xmlWriter()) {
w->writeStartElement(Tag::Alignment);
m_detectorAlignment.writeTo(w);
w->writeEndElement();
} else {
auto* r = s.xmlReader();
r->readNextStartElement();
if (r->name() == Tag::Alignment) {
m_detectorAlignment.readFrom(r);
GUI::Session::XML::gotoEndElementOfTag(r, Tag::Alignment);
}
}
m_normalVector.rwProperty(s, Tag::NormalVector);
m_directionVector.rwProperty(s, Tag::DirectionVector);
Serialize::rwProperty(s, Tag::u0, m_u0);
......@@ -134,58 +129,27 @@ void RectangularDetectorItem::serialize(Streamer& s)
Serialize::rwProperty(s, Tag::Distance, m_distance);
if (s.xmlReader()) {
setDetectorAlignment(static_cast<RectangularDetector::EDetectorArrangement>(alignment));
m_resolutionFunction->setUnit("mm");
}
}
void RectangularDetectorItem::setDetectorAlignment(const QString& alignment)
{
ASSERT(alignment_names_map.values().contains(alignment));
setDetectorAlignment(alignment_names_map.key(alignment));
}
void RectangularDetectorItem::setDetectorAlignment(
RectangularDetector::EDetectorArrangement alignment)
{
m_detectorAlignment = alignment;
m_detectorAlignment.setCurrentValue(alignment_names_map.value(alignment));
updateTooltips();
}
RectangularDetector::EDetectorArrangement RectangularDetectorItem::detectorAlignment() const
{
return m_detectorAlignment;
}
int RectangularDetectorItem::xSize() const
{
return m_xSize;
}
int RectangularDetectorItem::ySize() const
{
return m_ySize;
}
void RectangularDetectorItem::setXSize(size_t nx)
{
m_xSize = static_cast<int>(nx);
}
void RectangularDetectorItem::setYSize(size_t ny)
{
m_ySize = static_cast<int>(ny);
}
SelectionDescriptor<RectangularDetector::EDetectorArrangement>
RectangularDetectorItem::detectorAlignmentSelection() const
{
SelectionDescriptor<RectangularDetector::EDetectorArrangement> d;
d.label = "Alignment";
for (auto a : alignments())
d.options << alignmentTitle(a);
d.currentIndexSetter = [&](int newIndex) {
const_cast<RectangularDetectorItem*>(this)->setDetectorAlignment(alignments()[newIndex]);
};
d.currentIndexGetter = [&]() { return alignments().indexOf(m_detectorAlignment); };
return d;
ASSERT(alignment_names_map.values().contains(m_detectorAlignment.currentValue()));
return alignment_names_map.key(m_detectorAlignment.currentValue());
}
std::unique_ptr<IDetector> RectangularDetectorItem::createDomainDetector() const
......@@ -193,7 +157,7 @@ std::unique_ptr<IDetector> RectangularDetectorItem::createDomainDetector() const
auto result = std::make_unique<RectangularDetector>(xSize(), width(), ySize(), height());
// distance and alignment
switch (m_detectorAlignment) {
switch (detectorAlignment()) {
case RectangularDetector::GENERIC:
result->setDetectorPosition(m_normalVector, m_u0, m_v0, m_directionVector);
break;
......@@ -219,7 +183,7 @@ std::unique_ptr<IDetector> RectangularDetectorItem::createDomainDetector() const
void RectangularDetectorItem::updateTooltips()
{
switch (m_detectorAlignment) {
switch (detectorAlignment()) {
case RectangularDetector::GENERIC:
m_u0.setTooltip(
"u-coordinate of point of intersection of normal vector and detector plane");
......
......@@ -20,27 +20,16 @@
#include "GUI/Model/Device/DetectorItems.h"
class RectangularDetectorItem : public DetectorItem {
private:
static constexpr auto P_X_AXIS{"X axis"};
static constexpr auto P_Y_AXIS{"Y axis"};
static constexpr auto P_NORMAL{"Normal vector"};
static constexpr auto P_DIRECTION{"Direction vector"};
static constexpr auto P_U0{"u0"};
static constexpr auto P_V0{"v0"};
static constexpr auto P_DBEAM_U0{"u0 (dbeam)"};
static constexpr auto P_DBEAM_V0{"v0 (dbeam)"};
static constexpr auto P_DISTANCE{"Distance"};
public:
RectangularDetectorItem();
void serialize(Streamer& s) override;
int xSize() const override;
void setXSize(size_t nx) override;
int xSize() const override { return m_xSize; }
void setXSize(size_t nx) override { m_xSize = static_cast<int>(nx); }
int ySize() const override;
void setYSize(size_t ny) override;
int ySize() const override { return m_ySize; }
void setYSize(size_t ny) override { m_ySize = static_cast<int>(ny); }
DoubleProperty& width() { return m_width; }
const DoubleProperty& width() const { return m_width; }
......@@ -50,10 +39,10 @@ public:
const DoubleProperty& height() const { return m_height; }
void setHeight(double v) { m_height.setValue(v); }
void setDetectorAlignment(RectangularDetector::EDetectorArrangement alignment);
const ComboProperty& detectorAlignmentCombo() const { return m_detectorAlignment; }
RectangularDetector::EDetectorArrangement detectorAlignment() const;
SelectionDescriptor<RectangularDetector::EDetectorArrangement>
detectorAlignmentSelection() const;
void setDetectorAlignment(const QString& alignment);
void setDetectorAlignment(RectangularDetector::EDetectorArrangement alignment);
VectorProperty& normalVector() { return m_normalVector; }
const VectorProperty& normalVector() const { return m_normalVector; }
......@@ -80,11 +69,10 @@ private:
void updateTooltips();
private:
RectangularDetector::EDetectorArrangement m_detectorAlignment;
ComboProperty m_detectorAlignment;
int m_xSize;
int m_ySize;
protected:
VectorProperty m_normalVector;
VectorProperty m_directionVector;
......
......@@ -50,13 +50,13 @@ DetectorAlignmentEditor::DetectorAlignmentEditor(QWidget* parent, RectangularDet
m_formLayout->setContentsMargins(0, 15, 0, 0);
m_formLayout->setSpacing(8);
auto* m_combo =
GUI::Util::createComboBoxFromDescriptor(item->detectorAlignmentSelection(), [=](int) {
createAligmentWidgets();
emit dataChanged();
});
m_formLayout->addRow("Alignment:", m_combo);
m_formLayout->addRow(
"Alignment:", GUI::Util::createSafeComboBox([=] { return item->detectorAlignmentCombo(); },
[=](const QString& t) {
item->setDetectorAlignment(t);
createAligmentWidgets();
emit dataChanged();
}));
createAligmentWidgets();
}
......
......@@ -54,6 +54,14 @@ QComboBox* GUI::Util::createComboBox(function<ComboProperty()> comboFunction,
return combo;
}
QComboBox* GUI::Util::createSafeComboBox(function<ComboProperty()> comboFunction,
function<void(const QString&)> slot,
QList<function<void()>>* updaters, QString tooltip)
{
return createComboBox(comboFunction, slot, updaters, tooltip, false);
}
DoubleSpinBox* GUI::Util::createDoubleSpinBoxRow(QFormLayout* parentLayout, DoubleProperty& d,
function<void(double)> slot)
{
......
......@@ -46,6 +46,10 @@ QComboBox* createComboBox(std::function<ComboProperty()> comboFunction,
std::function<void(const QString&)> slot,
QList<std::function<void()>>* updaters = nullptr, QString tooltip = "",
bool isScrollable = true);
QComboBox* createSafeComboBox(std::function<ComboProperty()> comboFunction,
std::function<void(const QString&)> slot,
QList<std::function<void()>>* updaters = nullptr,
QString tooltip = "");
//! Create a combo box with the information found in a selection descriptor.
//!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment