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

free InterferenceItems from SessionItem

parent 53bea065
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/InterferenceItemCatalog.cpp
//! @brief Implements class InterferenceItemCatalog
//!
//! @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/InterferenceItemCatalog.h"
#include "GUI/Model/Sample/InterferenceItems.h"
InterferenceItem* InterferenceItemCatalog::create(Type type)
{
switch (type) {
case Type::None:
return nullptr;
case Type::RadialParaCrystalRadial:
return new InterferenceRadialParaCrystalItem();
case Type::ParaCrystal2D:
return new Interference2DParaCrystalItem();
case Type::Lattice1D:
return new Interference1DLatticeItem();
case Type::Lattice2D:
return new Interference2DLatticeItem();
case Type::FiniteLattice2D:
return new InterferenceFinite2DLatticeItem();
case Type::HardDisk:
return new InterferenceHardDiskItem();
default:
ASSERT(false);
}
}
QVector<InterferenceItemCatalog::Type> InterferenceItemCatalog::types()
{
return {Type::None, Type::RadialParaCrystalRadial, Type::Lattice1D,
Type::Lattice2D, Type::FiniteLattice2D, Type::ParaCrystal2D,
Type::HardDisk};
}
InterferenceItemCatalog::UiInfo InterferenceItemCatalog::uiInfo(Type type)
{
auto createUiInfo = [](const QString& menuEntry, const QString& iconPath,
const QString& description) {
UiInfo info;
info.menuEntry = menuEntry;
info.iconPath = iconPath;
info.description = description;
return info;
};
switch (type) {
case Type::None:
return createUiInfo("None", "", "");
case Type::RadialParaCrystalRadial:
return createUiInfo("Radial paracrystal",
":/SampleDesignerToolbox/images/ParaCrystal1D.png",
"Interference function of radial paracrystal");
case Type::ParaCrystal2D:
return createUiInfo("2D paracrystal", ":/SampleDesignerToolbox/images/ParaCrystal2D.png",
"Interference function of two-dimensional paracrystal");
case Type::Lattice1D:
return createUiInfo("1D lattice", ":/SampleDesignerToolbox/images/Lattice1D.png",
"Interference function of 1D lattice");
case Type::Lattice2D:
return createUiInfo("2D lattice", ":/SampleDesignerToolbox/images/Lattice2D.png",
"Interference function of 2D lattice");
case Type::FiniteLattice2D:
return createUiInfo("Finite 2D lattice",
":/SampleDesignerToolbox/images/Lattice2DFinite.png",
"Interference function of finite 2D lattice");
case Type::HardDisk:
return createUiInfo("Hard disk Percus-Yevick",
":/SampleDesignerToolbox/images/Lattice2D.png",
"Interference function for hard disk Percus-Yevick");
default:
ASSERT(false);
}
}
InterferenceItemCatalog::Type InterferenceItemCatalog::type(InterferenceItem* item)
{
if (!item)
return Type::None;
#define CHECK(itfClass, type) \
if (dynamic_cast<itfClass*>(item)) \
return Type::type
CHECK(InterferenceRadialParaCrystalItem, RadialParaCrystalRadial);
CHECK(Interference2DParaCrystalItem, ParaCrystal2D);
CHECK(Interference1DLatticeItem, Lattice1D);
CHECK(Interference2DLatticeItem, Lattice2D);
CHECK(InterferenceFinite2DLatticeItem, FiniteLattice2D);
CHECK(InterferenceHardDiskItem, HardDisk);
#undef CHECK
ASSERT(false);
}
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Sample/InterferenceItemCatalog.h
//! @brief Defines class InterferenceItemCatalog
//!
//! @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_INTERFERENCEITEMCATALOG_H
#define BORNAGAIN_GUI_MODEL_SAMPLE_INTERFERENCEITEMCATALOG_H
#include <QString>
class InterferenceItem;
class InterferenceItemCatalog {
public:
using CatalogedType = InterferenceItem;
// Do not change the numbering! It is serialized!
enum class Type : uint8_t {
None = 0,
RadialParaCrystalRadial = 1,
ParaCrystal2D = 2,
Lattice1D = 3,
Lattice2D = 4,
FiniteLattice2D = 5,
HardDisk = 6
};
struct UiInfo {
QString menuEntry;
QString description;
QString iconPath;
};
//! Creates the item of the given type.
//!
//! If type is "None", a nullptr is returned.
static InterferenceItem* 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(InterferenceItem* item);
};
#endif // BORNAGAIN_GUI_MODEL_SAMPLE_INTERFERENCEITEMCATALOG_H
This diff is collapsed.
......@@ -7,7 +7,7 @@
//!
//! @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)
//
// ************************************************************************************************
......@@ -15,8 +15,9 @@
#ifndef BORNAGAIN_GUI_MODEL_SAMPLE_INTERFERENCEITEMS_H
#define BORNAGAIN_GUI_MODEL_SAMPLE_INTERFERENCEITEMS_H
#include "GUI/Model/Group/SelectionDescriptor.h"
#include "GUI/Model/Session/SessionItem.h"
#include "GUI/Model/Types/DoubleProperty.h"
#include "GUI/Model/Types/SelectionProperty.h"
#include "GUI/Model/Types/UIntProperty.h"
class FTDecayFunction1DItem;
class FTDecayFunction2DItem;
......@@ -24,109 +25,95 @@ class FTDistribution1DItem;
class FTDistribution2DItem;
class IInterference;
class Lattice2DItem;
class DoubleDescriptor;
class UIntDescriptor;
class InterferenceItem : public SessionItem {
private:
static constexpr auto P_POSITION_VARIANCE{"PositionVariance"};
class InterferenceItem {
public:
~InterferenceItem() override;
virtual ~InterferenceItem() = default;
virtual std::unique_ptr<IInterference> createInterference() const = 0;
DoubleDescriptor positionVariance() const;
protected:
explicit InterferenceItem(const QString& modelType);
};
InterferenceItem();
class Interference1DLatticeItem : public InterferenceItem {
private:
static constexpr auto P_LENGTH{"Length"};
static constexpr auto P_ROTATION_ANGLE{"Xi"};
static constexpr auto P_DECAY_FUNCTION{"Decay Function"};
DoubleProperty m_positionVariance;
};
class Interference1DLatticeItem : public InterferenceItem {
public:
static constexpr auto M_TYPE{"Interference1DLattice"};
Interference1DLatticeItem();
std::unique_ptr<IInterference> createInterference() const override;
DoubleDescriptor length() const;
DoubleDescriptor rotationAngle() const;
template <typename T> T* setDecayFunctionType();
void setDecayFunction(FTDecayFunction1DItem* p);
SelectionDescriptor<FTDecayFunction1DItem*> decayFunction() const;
};
class Interference2DAbstractLatticeItem : public InterferenceItem {
private:
static constexpr auto P_LATTICE_TYPE{"LatticeType"};
static constexpr auto P_XI_INTEGRATION{"Integration_over_xi"};
DoubleProperty m_length;
DoubleProperty m_rotationAngle;
SelectionProperty<FTDecayFunction1DItem*> m_decayFunction;
};
class Interference2DAbstractLatticeItem : public InterferenceItem {
public:
SelectionDescriptor<Lattice2DItem*> latticeType() const;
template <typename T> T* setLatticeType();
void setLatticeType(Lattice2DItem* p);
bool xiIntegration() const;
void setXiIntegration(bool xi_integration);
void setXiIntegration(bool xiIntegration);
protected:
explicit Interference2DAbstractLatticeItem(const QString& modelType, bool xi_integration);
explicit Interference2DAbstractLatticeItem(bool xiIntegration);
bool m_xiIntegration; // #baMigration serialize
SelectionProperty<Lattice2DItem*> m_latticeType;
};
class Interference2DLatticeItem : public Interference2DAbstractLatticeItem {
private:
static constexpr auto P_DECAY_FUNCTION{"Decay Function"};
public:
static constexpr auto M_TYPE{"Interference2DLattice"};
Interference2DLatticeItem();
std::unique_ptr<IInterference> createInterference() const override;
template <typename T> T* setDecayFunctionType();
SelectionDescriptor<FTDecayFunction2DItem*> decayFunction() const;
protected:
SelectionProperty<FTDecayFunction2DItem*> m_decayFunction;
};
class Interference2DParaCrystalItem : public Interference2DAbstractLatticeItem {
private:
static constexpr auto P_DAMPING_LENGTH{"DampingLength"};
static constexpr auto P_DOMAIN_SIZE1{"DomainSize1"};
static constexpr auto P_DOMAIN_SIZE2{"DomainSize2"};
static constexpr auto P_PDF1{"PDF #1"};
static constexpr auto P_PDF2{"PDF #2"};
public:
static constexpr auto M_TYPE{"Interference2DParaCrystal"};
Interference2DParaCrystalItem();
std::unique_ptr<IInterference> createInterference() const override;
DoubleDescriptor dampingLength() const;
void setDampingLength(double damping_length);
void setDampingLength(double dampingLength);
DoubleDescriptor domainSize1() const;
void setDomainSize1(double domain_size1);
void setDomainSize1(double size);
DoubleDescriptor domainSize2() const;
void setDomainSize2(double domain_size2);
void setDomainSize2(double size);
SelectionDescriptor<FTDistribution2DItem*> probabilityDistribution1() const;
template <typename T> T* setPDF1Type();
void setPDF1Type(FTDistribution2DItem* p);
SelectionDescriptor<FTDistribution2DItem*> probabilityDistribution2() const;
template <typename T> T* setPDF2Type();
};
void setPDF2Type(FTDistribution2DItem* p);
class InterferenceFinite2DLatticeItem : public Interference2DAbstractLatticeItem {
private:
static constexpr auto P_DOMAIN_SIZE_1{"Domain_size_1"};
static constexpr auto P_DOMAIN_SIZE_2{"Domain_size_2"};
DoubleProperty m_dampingLength;
DoubleProperty m_domainSize1;
DoubleProperty m_domainSize2;
SelectionProperty<FTDistribution2DItem*> m_pdf1;
SelectionProperty<FTDistribution2DItem*> m_pdf2;
};
class InterferenceFinite2DLatticeItem : public Interference2DAbstractLatticeItem {
public:
static constexpr auto M_TYPE{"InterferenceFinite2DLattice"};
InterferenceFinite2DLatticeItem();
std::unique_ptr<IInterference> createInterference() const override;
......@@ -134,34 +121,27 @@ public:
void setDomainSize1(unsigned int domain_size1);
UIntDescriptor domainSize2();
void setDomainSize2(unsigned int domain_size2);
};
class InterferenceHardDiskItem : public InterferenceItem {
private:
static constexpr auto P_RADIUS{"Radius"};
static constexpr auto P_DENSITY{"TotalParticleDensity"};
UIntProperty m_domainSize1;
UIntProperty m_domainSize2;
};
class InterferenceHardDiskItem : public InterferenceItem {
public:
static constexpr auto M_TYPE{"InterferenceHardDisk"};
InterferenceHardDiskItem();
std::unique_ptr<IInterference> createInterference() const override;
DoubleDescriptor radius() const;
DoubleDescriptor density() const;
};
class InterferenceRadialParaCrystalItem : public InterferenceItem {
private:
static constexpr auto P_PEAK_DISTANCE{"PeakDistance"};
static constexpr auto P_DAMPING_LENGTH{"DampingLength"};
static constexpr auto P_DOMAIN_SIZE{"DomainSize"};
static constexpr auto P_KAPPA{"SizeSpaceCoupling"};
static constexpr auto P_PDF{"PDF"};
DoubleProperty m_radius;
DoubleProperty m_density;
};
class InterferenceRadialParaCrystalItem : public InterferenceItem {
public:
static constexpr auto M_TYPE{"InterferenceRadialParaCrystal"};
InterferenceRadialParaCrystalItem();
std::unique_ptr<IInterference> createInterference() const override;
......@@ -170,55 +150,14 @@ public:
DoubleDescriptor domainSize() const;
DoubleDescriptor kappa() const;
SelectionDescriptor<FTDistribution1DItem*> probabilityDistribution() const;
template <typename T> T* setPDFType();
};
template <typename T> T* Interference1DLatticeItem::setDecayFunctionType()
{
static_assert(std::is_base_of<FTDecayFunction1DItem, T>::value,
"Class must be derived from FTDecayFunction1DItem");
void setPDFType(FTDistribution1DItem* p);
return setGroupPropertyType<T>(P_DECAY_FUNCTION);
}
template <typename T> T* Interference2DAbstractLatticeItem::setLatticeType()
{
static_assert(std::is_base_of<Lattice2DItem, T>::value,
"Class must be derived from Lattice2DItem");
return setGroupPropertyType<T>(P_LATTICE_TYPE);
}
template <typename T> T* Interference2DLatticeItem::setDecayFunctionType()
{
static_assert(std::is_base_of<FTDecayFunction2DItem, T>::value,
"Class must be derived from FTDecayFunction2DItem");
return setGroupPropertyType<T>(P_DECAY_FUNCTION);
}
template <typename T> T* Interference2DParaCrystalItem::setPDF1Type()
{
static_assert(std::is_base_of<FTDistribution2DItem, T>::value,
"Class must be derived from FTDistribution2DItem");
return setGroupPropertyType<T>(P_PDF1);
}
template <typename T> T* Interference2DParaCrystalItem::setPDF2Type()
{
static_assert(std::is_base_of<FTDistribution2DItem, T>::value,
"Class must be derived from FTDistribution2DItem");
return setGroupPropertyType<T>(P_PDF2);
}
template <typename T> T* InterferenceRadialParaCrystalItem::setPDFType()
{
static_assert(std::is_base_of<FTDistribution1DItem, T>::value,
"Class must be derived from FTDistribution1DItem");
return setGroupPropertyType<T>(P_PDF);
}
private:
DoubleProperty m_peakDistance;
DoubleProperty m_dampingLength;
DoubleProperty m_domainSize;
DoubleProperty m_kappa;
SelectionProperty<FTDistribution1DItem*> m_pdf;
};
#endif // BORNAGAIN_GUI_MODEL_SAMPLE_INTERFERENCEITEMS_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