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

free Lattice2DItems from SessionItem

parent f2be35a1
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/Lattice2DItemCatalog.cpp
//! @brief Implements class Lattice2DItemCatalog
//!
//! @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/Lattice2DItemCatalog.h"
#include "Base/Util/Assert.h"
#include "GUI/Model/Sample/Lattice2DItems.h"
Lattice2DItemCatalog::CatalogedType* Lattice2DItemCatalog::create(Type type)
{
switch (type) {
case Type::Basic:
return new BasicLattice2DItem();
case Type::Square:
return new SquareLattice2DItem();
case Type::Hexagonal:
return new HexagonalLattice2DItem();
default:
ASSERT(false);
}
}
QVector<Lattice2DItemCatalog::Type> Lattice2DItemCatalog::types()
{
return {Type::Basic, Type::Square, Type::Hexagonal};
}
Lattice2DItemCatalog::UiInfo Lattice2DItemCatalog::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::Basic:
return createUiInfo("Basic", "Two dimensional lattice");
case Type::Square:
return createUiInfo("Square", "");
case Type::Hexagonal:
return createUiInfo("Hexagonal", "");
default:
ASSERT(false);
}
}
Lattice2DItemCatalog::Type Lattice2DItemCatalog::type(CatalogedType* item)
{
ASSERT(item);
#define CHECK(type) \
if (dynamic_cast<type##Lattice2DItem*>(item)) \
return Type::type
CHECK(Basic);
CHECK(Square);
CHECK(Hexagonal);
#undef CHECK
ASSERT(false);
}
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Sample/Lattice2DItemCatalog.h
//! @brief Defines class Lattice2DItemCatalog
//!
//! @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_LATTICE2DITEMCATALOG_H
#define BORNAGAIN_GUI_MODEL_SAMPLE_LATTICE2DITEMCATALOG_H
#include <QVector>
class Lattice2DItem;
class Lattice2DItemCatalog {
public:
using CatalogedType = Lattice2DItem;
// Do not change the numbering! It is serialized!
enum class Type : uint8_t { Basic = 1, Square = 2, Hexagonal };
struct UiInfo {
QString menuEntry;
QString description;
QString iconPath;
};
//! Creates the item of the given type.
static CatalogedType* create(Type type);
//! List of available types, sorted as expected in the UI.
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(CatalogedType* item);
};
#endif // BORNAGAIN_GUI_MODEL_SAMPLE_LATTICE2DITEMCATALOG_H
...@@ -14,19 +14,14 @@ ...@@ -14,19 +14,14 @@
#include "GUI/Model/Sample/Lattice2DItems.h" #include "GUI/Model/Sample/Lattice2DItems.h"
#include "Base/Const/Units.h" #include "Base/Const/Units.h"
#include "GUI/Model/Types/DoubleDescriptor.h" #include "Base/Util/Assert.h"
#include "Sample/Lattice/Lattice2D.h" #include "Sample/Lattice/Lattice2D.h"
namespace { Lattice2DItem::Lattice2DItem()
const QString axis_rotation_tooltip =
"Rotation of lattice with respect to x-axis of reference frame \n"
"(beam direction) in degrees";
}
Lattice2DItem::Lattice2DItem(const QString& modelType) : SessionItem(modelType)
{ {
addProperty(P_LATTICE_ROTATION_ANGLE, 0.0)->setToolTip(axis_rotation_tooltip); m_latticeRotationAngle.init(
"Xi", "Rotation of lattice with respect to x-axis of reference frame (beam direction)", 0.0,
Unit::degree, "xi");
} }
double Lattice2DItem::unitCellArea() const double Lattice2DItem::unitCellArea() const
...@@ -34,132 +29,105 @@ double Lattice2DItem::unitCellArea() const ...@@ -34,132 +29,105 @@ double Lattice2DItem::unitCellArea() const
return createLattice()->unitCellArea(); return createLattice()->unitCellArea();
} }
SessionItem* Lattice2DItem::latticeRotationAngleItem() const
{
return getItem(P_LATTICE_ROTATION_ANGLE);
}
DoubleDescriptor Lattice2DItem::latticeRotationAngle() const DoubleDescriptor Lattice2DItem::latticeRotationAngle() const
{ {
DoubleDescriptor d(getItem(P_LATTICE_ROTATION_ANGLE), Unit::degree); return m_latticeRotationAngle;
d.tooltip = "Rotation of lattice with respect to x-axis of reference frame (beam direction)";
return d;
} }
void Lattice2DItem::setLatticeRotationAngle(const double angle) void Lattice2DItem::setLatticeRotationAngle(const double angle)
{ {
setItemValue(P_LATTICE_ROTATION_ANGLE, angle); m_latticeRotationAngle.set(angle);
}
void Lattice2DItem::enableRotationAngle(bool b)
{
latticeRotationAngleItem()->setEnabled(b);
} }
// --------------------------------------------------------------------------------------------- // // --------------------------------------------------------------------------------------------- //
BasicLattice2DItem::BasicLattice2DItem() : Lattice2DItem(M_TYPE) BasicLattice2DItem::BasicLattice2DItem()
{ {
setToolTip("Two dimensional lattice"); m_length1.init("LatticeLength1", "Length of first lattice vector", 20.0, Unit::nanometer,
addProperty(P_LATTICE_LENGTH1, 20.0) "len1");
->setToolTip("Length of first lattice vector in nanometers"); m_length2.init("LatticeLength2", "Length of second lattice vector", 20.0, Unit::nanometer,
addProperty(P_LATTICE_LENGTH2, 20.0) "len2");
->setToolTip("Length of second lattice vector in nanometers"); m_angle.init("Angle", "Angle between lattice vectors", 90.0, Unit::degree, "angle");
addProperty(P_LATTICE_ANGLE, 90.0)->setToolTip("Angle between lattice vectors in degrees");
} }
std::unique_ptr<Lattice2D> BasicLattice2DItem::createLattice() const std::unique_ptr<Lattice2D> BasicLattice2DItem::createLattice() const
{ {
return std::make_unique<BasicLattice2D>( return std::make_unique<BasicLattice2D>(m_length1, m_length2, Units::deg2rad(m_angle),
getItemValue(P_LATTICE_LENGTH1).toDouble(), getItemValue(P_LATTICE_LENGTH2).toDouble(), Units::deg2rad(latticeRotationAngle()));
Units::deg2rad(getItemValue(P_LATTICE_ANGLE).toDouble()),
Units::deg2rad(latticeRotationAngle()));
} }
DoubleDescriptor BasicLattice2DItem::latticeLength1() const DoubleDescriptor BasicLattice2DItem::latticeLength1() const
{ {
DoubleDescriptor d(getItem(P_LATTICE_LENGTH1), Unit::nanometer); return m_length1;
d.tooltip = "Length of first lattice vector";
return d;
} }
void BasicLattice2DItem::setLatticeLength1(const double length1) void BasicLattice2DItem::setLatticeLength1(const double length1)
{ {
setItemValue(P_LATTICE_LENGTH1, length1); m_length1.set(length1);
} }
DoubleDescriptor BasicLattice2DItem::latticeLength2() const DoubleDescriptor BasicLattice2DItem::latticeLength2() const
{ {
DoubleDescriptor d(getItem(P_LATTICE_LENGTH2), Unit::nanometer); return m_length2;
d.tooltip = "Length of second lattice vector";
return d;
} }
void BasicLattice2DItem::setLatticeLength2(const double length2) void BasicLattice2DItem::setLatticeLength2(const double length2)
{ {
setItemValue(P_LATTICE_LENGTH2, length2); m_length2.set(length2);
} }
DoubleDescriptor BasicLattice2DItem::latticeAngle() const DoubleDescriptor BasicLattice2DItem::latticeAngle() const
{ {
DoubleDescriptor d(getItem(P_LATTICE_ANGLE), Unit::degree); return m_angle;
d.tooltip = "Angle between lattice vectors";
return d;
} }
void BasicLattice2DItem::setLatticeAngle(const double angle) void BasicLattice2DItem::setLatticeAngle(const double angle)
{ {
setItemValue(P_LATTICE_ANGLE, angle); m_angle.set(angle);
} }
// --------------------------------------------------------------------------------------------- // // --------------------------------------------------------------------------------------------- //
SquareLattice2DItem::SquareLattice2DItem() : Lattice2DItem(M_TYPE) SquareLattice2DItem::SquareLattice2DItem()
{ {
addProperty(P_LATTICE_LENGTH, 20.0) m_length.init("LatticeLength", "Length of first and second lattice vectors", 20.0,
->setToolTip("Length of first and second lattice vectors in nanometers"); Unit::nanometer, "len");
} }
std::unique_ptr<Lattice2D> SquareLattice2DItem::createLattice() const std::unique_ptr<Lattice2D> SquareLattice2DItem::createLattice() const
{ {
return std::make_unique<SquareLattice2D>(getItemValue(P_LATTICE_LENGTH).toDouble(), return std::make_unique<SquareLattice2D>(m_length, Units::deg2rad(latticeRotationAngle()));
Units::deg2rad(latticeRotationAngle()));
} }
DoubleDescriptor SquareLattice2DItem::latticeLength() const DoubleDescriptor SquareLattice2DItem::latticeLength() const
{ {
DoubleDescriptor d(getItem(P_LATTICE_LENGTH), Unit::nanometer); return m_length;
d.tooltip = "Length of first and second lattice vectors";
return d;
} }
void SquareLattice2DItem::setLatticeLength(const double length) void SquareLattice2DItem::setLatticeLength(const double length)
{ {
setItemValue(P_LATTICE_LENGTH, length); m_length.set(length);
} }
// --------------------------------------------------------------------------------------------- // // --------------------------------------------------------------------------------------------- //
HexagonalLattice2DItem::HexagonalLattice2DItem() : Lattice2DItem(M_TYPE) HexagonalLattice2DItem::HexagonalLattice2DItem()
{ {
addProperty(P_LATTICE_LENGTH, 20.0) m_length.init("LatticeLength", "Length of first and second lattice vectors", 20.0,
->setToolTip("Length of first and second lattice vectors in nanometers"); Unit::nanometer, "len");
} }
std::unique_ptr<Lattice2D> HexagonalLattice2DItem::createLattice() const std::unique_ptr<Lattice2D> HexagonalLattice2DItem::createLattice() const
{ {
return std::make_unique<HexagonalLattice2D>(getItemValue(P_LATTICE_LENGTH).toDouble(), return std::make_unique<HexagonalLattice2D>(m_length, Units::deg2rad(latticeRotationAngle()));
Units::deg2rad(latticeRotationAngle()));
} }
DoubleDescriptor HexagonalLattice2DItem::latticeLength() const DoubleDescriptor HexagonalLattice2DItem::latticeLength() const
{ {
DoubleDescriptor d(getItem(P_LATTICE_LENGTH), Unit::nanometer); return m_length;
d.tooltip = "Length of first and second lattice vectors";
return d;
} }
void HexagonalLattice2DItem::setLatticeLength(const double length) void HexagonalLattice2DItem::setLatticeLength(const double length)
{ {
setItemValue(P_LATTICE_LENGTH, length); m_length.set(length);
} }
...@@ -15,42 +15,29 @@ ...@@ -15,42 +15,29 @@
#ifndef BORNAGAIN_GUI_MODEL_SAMPLE_LATTICE2DITEMS_H #ifndef BORNAGAIN_GUI_MODEL_SAMPLE_LATTICE2DITEMS_H
#define BORNAGAIN_GUI_MODEL_SAMPLE_LATTICE2DITEMS_H #define BORNAGAIN_GUI_MODEL_SAMPLE_LATTICE2DITEMS_H
#include "GUI/Model/Session/SessionItem.h" #include "GUI/Model/Types/DoubleProperty.h"
#include <QVector>
class Lattice2D; class Lattice2D;
class DoubleDescriptor; class DoubleDescriptor;
class Lattice2DItem : public SessionItem { class Lattice2DItem {
private:
static constexpr auto P_LATTICE_ROTATION_ANGLE{"Xi"};
protected: protected:
explicit Lattice2DItem(const QString& modelType); Lattice2DItem();
public: public:
virtual std::unique_ptr<Lattice2D> createLattice() const = 0; virtual std::unique_ptr<Lattice2D> createLattice() const = 0;
double unitCellArea() const; double unitCellArea() const;
SessionItem* latticeRotationAngleItem() const;
DoubleDescriptor latticeRotationAngle() const; DoubleDescriptor latticeRotationAngle() const;
void setLatticeRotationAngle(double angle); void setLatticeRotationAngle(double angle);
//! enable or disable rotation angle in ParameterTuningTree. private:
//! DoubleProperty m_latticeRotationAngle;
//! #bamigration This is for migration only; after SessionModel migration, this has to be done
//! in the creation of the tuning tree
void enableRotationAngle(bool b);
}; };
class BasicLattice2DItem : public Lattice2DItem { class BasicLattice2DItem : public Lattice2DItem {
private:
static constexpr auto P_LATTICE_LENGTH1{"LatticeLength1"};
static constexpr auto P_LATTICE_LENGTH2{"LatticeLength2"};
static constexpr auto P_LATTICE_ANGLE{"Alpha"};
public: public:
static constexpr auto M_TYPE{"BasicLattice2D"};
BasicLattice2DItem(); BasicLattice2DItem();
std::unique_ptr<Lattice2D> createLattice() const override; std::unique_ptr<Lattice2D> createLattice() const override;
...@@ -62,34 +49,35 @@ public: ...@@ -62,34 +49,35 @@ public:
DoubleDescriptor latticeAngle() const; DoubleDescriptor latticeAngle() const;
void setLatticeAngle(double angle); void setLatticeAngle(double angle);
};
class SquareLattice2DItem : public Lattice2DItem {
private: private:
static constexpr auto P_LATTICE_LENGTH{"LatticeLength"}; DoubleProperty m_length1;
DoubleProperty m_length2;
DoubleProperty m_angle;
};
class SquareLattice2DItem : public Lattice2DItem {
public: public:
static constexpr auto M_TYPE{"SquareLattice2D"};
SquareLattice2DItem(); SquareLattice2DItem();
std::unique_ptr<Lattice2D> createLattice() const override; std::unique_ptr<Lattice2D> createLattice() const override;
DoubleDescriptor latticeLength() const; DoubleDescriptor latticeLength() const;
void setLatticeLength(double length); void setLatticeLength(double length);
};
class HexagonalLattice2DItem : public Lattice2DItem {
private: private:
static constexpr auto P_LATTICE_LENGTH{"LatticeLength"}; DoubleProperty m_length;
};
class HexagonalLattice2DItem : public Lattice2DItem {
public: public:
static constexpr auto M_TYPE{"HexagonalLattice2D"};
HexagonalLattice2DItem(); HexagonalLattice2DItem();
std::unique_ptr<Lattice2D> createLattice() const override; std::unique_ptr<Lattice2D> createLattice() const override;
DoubleDescriptor latticeLength() const; DoubleDescriptor latticeLength() const;
void setLatticeLength(double length); void setLatticeLength(double length);
private:
DoubleProperty m_length;
}; };
#endif // BORNAGAIN_GUI_MODEL_SAMPLE_LATTICE2DITEMS_H #endif // BORNAGAIN_GUI_MODEL_SAMPLE_LATTICE2DITEMS_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment