Skip to content
Snippets Groups Projects
Commit feb37a8d authored by Matthias Puchner's avatar Matthias Puchner
Browse files

free RotationItems from SessionItem

parent e9a97421
No related branches found
No related tags found
1 merge request!570remove SessionModel/Item from SampleModel and all related items
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Sample/RotationItemCatalog.cpp
//! @brief Implements class RotationItemCatalog
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/Model/Sample/RotationItemCatalog.h"
#include "GUI/Model/Sample/RotationItems.h"
RotationItem* RotationItemCatalog::create(Type type)
{
switch (type) {
case Type::None:
return nullptr;
case Type::X:
return new XRotationItem();
case Type::Y:
return new YRotationItem();
case Type::Z:
return new ZRotationItem();
case Type::Euler:
return new EulerRotationItem();
}
ASSERT(false);
}
QVector<RotationItemCatalog::Type> RotationItemCatalog::types()
{
return {Type::None, Type::X, Type::Y, Type::Z, Type::Euler};
}
RotationItemCatalog::UiInfo RotationItemCatalog::uiInfo(Type type)
{
auto createUiInfo = [](const QString& menuEntry, const QString& description) {
UiInfo info;
info.menuEntry = menuEntry;
info.description = description;
return info;
};
switch (type) {
case Type::None:
return createUiInfo("None", "");
case Type::X:
return createUiInfo("X axis Rotation", "Particle rotation around x-axis");
case Type::Y:
return createUiInfo("Y axis Rotation", "Particle rotation around y-axis");
case Type::Z:
return createUiInfo("Z axis Rotation", "Particle rotation around z-axis");
case Type::Euler:
return createUiInfo("Euler Rotation",
"Sequence of three rotations following Euler angles; notation z-x'-z'");
}
ASSERT(false);
}
RotationItemCatalog::Type RotationItemCatalog::type(RotationItem* item)
{
if (!item)
return Type::None;
if (dynamic_cast<XRotationItem*>(item))
return Type::X;
if (dynamic_cast<YRotationItem*>(item))
return Type::Y;
if (dynamic_cast<ZRotationItem*>(item))
return Type::Z;
if (dynamic_cast<EulerRotationItem*>(item))
return Type::Euler;
ASSERT(false);
}
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Sample/RotationItemCatalog.h
//! @brief Defines class RotationItemCatalog
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#ifndef BORNAGAIN_GUI_MODEL_SAMPLE_ROTATIONITEMCATALOG_H
#define BORNAGAIN_GUI_MODEL_SAMPLE_ROTATIONITEMCATALOG_H
#include <QString>
class RotationItem;
class RotationItemCatalog {
public:
using CatalogedType = RotationItem;
// Do not change the numbering! It is serialized!
enum class Type : uint8_t {
None = 0,
X = 1,
Y = 2,
Z = 3,
Euler = 4,
};
struct UiInfo {
QString menuEntry;
QString description;
QString iconPath;
};
//! Creates the item of the given type.
//!
//! If type is "None", a nullptr is returned.
static RotationItem* create(Type type);
//! Available types of interference items.
//!
//! Contains also type "None".
//! This list is sorted as expected in the UI (e.g. in combo box)
static QVector<Type> types();
//! UiInfo on the given type.
static UiInfo uiInfo(Type t);
//! Returns the enum type of the given item.
static Type type(RotationItem* item);
};
#endif // BORNAGAIN_GUI_MODEL_SAMPLE_ROTATIONITEMCATALOG_H
......@@ -2,27 +2,26 @@
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Trafo/RotationItems.cpp
//! @file GUI/Model/Sample/RotationItems.cpp
//! @brief Implements class RotationItems
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/Model/Trafo/RotationItems.h"
#include "GUI/Model/Sample/RotationItems.h"
#include "Base/Const/Units.h"
#include "Base/Vector/RotMatrix.h"
#include "GUI/Model/Types/DoubleDescriptor.h"
#include "Sample/Scattering/Rotations.h"
using namespace Units;
// ----------------------------------------------------------------------------
RotationItem::RotationItem(const QString& name) : SessionItem(name) {}
RotationItem::RotationItem() {}
RotMatrix RotationItem::rotation() const
{
......@@ -32,10 +31,9 @@ RotMatrix RotationItem::rotation() const
// ----------------------------------------------------------------------------
XRotationItem::XRotationItem() : RotationItem(M_TYPE)
XRotationItem::XRotationItem()
{
setToolTip("Particle rotation around x-axis");
addProperty(P_ANGLE, 0.0)->setToolTip("Rotation angle around x-axis in degrees");
m_angle.init("Angle", "Rotation angle around x-axis", 0.0, Unit::degree, "angle");
}
unique_ptr<IRotation> XRotationItem::createRotation() const
......@@ -45,17 +43,14 @@ unique_ptr<IRotation> XRotationItem::createRotation() const
DoubleDescriptor XRotationItem::angle() const
{
DoubleDescriptor d(getItem(P_ANGLE), Unit::degree);
d.tooltip = "Rotation angle around x-axis"; // tooltip w/o unit
return d;
return m_angle;
}
// ----------------------------------------------------------------------------
YRotationItem::YRotationItem() : RotationItem(M_TYPE)
YRotationItem::YRotationItem()
{
setToolTip("Particle rotation around y-axis");
addProperty(P_ANGLE, 0.0)->setToolTip("Rotation angle around y-axis in degrees");
m_angle.init("Angle", "Rotation angle around y-axis", 0.0, Unit::degree, "angle");
}
unique_ptr<IRotation> YRotationItem::createRotation() const
......@@ -65,17 +60,14 @@ unique_ptr<IRotation> YRotationItem::createRotation() const
DoubleDescriptor YRotationItem::angle() const
{
DoubleDescriptor d(getItem(P_ANGLE), Unit::degree);
d.tooltip = "Rotation angle around y-axis"; // tooltip w/o unit
return d;
return m_angle;
}
// ----------------------------------------------------------------------------
ZRotationItem::ZRotationItem() : RotationItem(M_TYPE)
ZRotationItem::ZRotationItem()
{
setToolTip("Particle rotation around z-axis");
addProperty(P_ANGLE, 0.0)->setToolTip("Rotation angle around z-axis in degrees");
m_angle.init("Angle", "Rotation angle around z-axis", 0.0, Unit::degree, "angle");
}
unique_ptr<IRotation> ZRotationItem::createRotation() const
......@@ -85,20 +77,16 @@ unique_ptr<IRotation> ZRotationItem::createRotation() const
DoubleDescriptor ZRotationItem::angle() const
{
DoubleDescriptor d(getItem(P_ANGLE), Unit::degree);
d.tooltip = "Rotation angle around z-axis"; // tooltip w/o unit
return d;
return m_angle;
}
// ----------------------------------------------------------------------------
EulerRotationItem::EulerRotationItem() : RotationItem(M_TYPE)
EulerRotationItem::EulerRotationItem()
{
setToolTip("Sequence of three rotations following Euler angles \n"
"notation z-x'-z'");
addProperty(P_ALPHA, 0.0)->setToolTip("First Euler angle in z-x'-z' sequence in degrees");
addProperty(P_BETA, 0.0)->setToolTip("Second Euler angle in z-x'-z' sequence in degrees");
addProperty(P_GAMMA, 0.0)->setToolTip("Third Euler angle in z-x'-z' sequence in degrees");
m_alpha.init("Alpha", "First Euler angle in z-x'-z' sequence", 0.0, Unit::degree, "alpha");
m_beta.init("Beta", "Second Euler angle in z-x'-z' sequence", 0.0, Unit::degree, "beta");
m_gamma.init("Gamma", "Third Euler angle in z-x'-z' sequence", 0.0, Unit::degree, "gamma");
}
unique_ptr<IRotation> EulerRotationItem::createRotation() const
......@@ -108,21 +96,15 @@ unique_ptr<IRotation> EulerRotationItem::createRotation() const
DoubleDescriptor EulerRotationItem::alpha() const
{
DoubleDescriptor d(getItem(P_ALPHA), Unit::degree);
d.tooltip = "First Euler angle in z-x'-z' sequence"; // tooltip w/o unit
return d;
return m_alpha;
}
DoubleDescriptor EulerRotationItem::beta() const
{
DoubleDescriptor d(getItem(P_BETA), Unit::degree);
d.tooltip = "Second Euler angle in z-x'-z' sequence"; // tooltip w/o unit
return d;
return m_beta;
}
DoubleDescriptor EulerRotationItem::gamma() const
{
DoubleDescriptor d(getItem(P_GAMMA), Unit::degree);
d.tooltip = "Third Euler angle in z-x'-z' sequence"; // tooltip w/o unit
return d;
return m_gamma;
}
......@@ -2,86 +2,78 @@
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Trafo/RotationItems.h
//! @file GUI/Model/Sample/RotationItems.h
//! @brief Defines class RotationItems
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#ifndef BORNAGAIN_GUI_MODEL_TRAFO_ROTATIONITEMS_H
#define BORNAGAIN_GUI_MODEL_TRAFO_ROTATIONITEMS_H
#ifndef BORNAGAIN_GUI_MODEL_SAMPLE_ROTATIONITEMS_H
#define BORNAGAIN_GUI_MODEL_SAMPLE_ROTATIONITEMS_H
#include "GUI/Model/Session/SessionItem.h"
#include "GUI/Model/Types/DoubleProperty.h"
class IRotation;
class RotMatrix;
class DoubleDescriptor;
using std::unique_ptr;
class BA_CORE_API_ RotationItem : public SessionItem {
class RotationItem {
public:
virtual ~RotationItem() = default;
RotMatrix rotation() const;
protected:
explicit RotationItem(const QString& name);
RotationItem();
virtual unique_ptr<IRotation> createRotation() const = 0;
};
class XRotationItem : public RotationItem {
private:
static constexpr auto P_ANGLE{"Angle"};
public:
static constexpr auto M_TYPE{"XRotation"};
XRotationItem();
DoubleDescriptor angle() const;
protected:
unique_ptr<IRotation> createRotation() const override;
};
class YRotationItem : public RotationItem {
private:
static constexpr auto P_ANGLE{"Angle"};
DoubleProperty m_angle;
};
class YRotationItem : public RotationItem {
public:
static constexpr auto M_TYPE{"YRotation"};
YRotationItem();
DoubleDescriptor angle() const;
protected:
unique_ptr<IRotation> createRotation() const override;
};
class ZRotationItem : public RotationItem {
private:
static constexpr auto P_ANGLE{"Angle"};
DoubleProperty m_angle;
};
class ZRotationItem : public RotationItem {
public:
static constexpr auto M_TYPE{"ZRotation"};
ZRotationItem();
DoubleDescriptor angle() const;
protected:
unique_ptr<IRotation> createRotation() const override;
};
class EulerRotationItem : public RotationItem {
private:
static constexpr auto P_ALPHA{"Alpha"};
static constexpr auto P_BETA{"Beta"};
static constexpr auto P_GAMMA{"Gamma"};
DoubleProperty m_angle;
};
class EulerRotationItem : public RotationItem {
public:
static constexpr auto M_TYPE{"EulerRotation"};
EulerRotationItem();
DoubleDescriptor alpha() const;
......@@ -90,6 +82,11 @@ public:
protected:
unique_ptr<IRotation> createRotation() const override;
private:
DoubleProperty m_alpha;
DoubleProperty m_beta;
DoubleProperty m_gamma;
};
#endif // BORNAGAIN_GUI_MODEL_TRAFO_ROTATIONITEMS_H
#endif // BORNAGAIN_GUI_MODEL_SAMPLE_ROTATIONITEMS_H
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