BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
instrumentitems.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/model/instrumentitems.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
17 #include "gui2/model/modelutils.h"
22 #include <QColor>
23 
24 using namespace ModelView;
25 
26 namespace gui2 {
27 
28 BasicSpecularScanItem::BasicSpecularScanItem(const std::string& model_type)
30 {
31 }
32 
33 // ----------------------------------------------------------------------------
34 
36 {
37  addProperty(P_NBINS, 500)->setDisplayName("Nbins");
38  addProperty(P_QMIN, 0.0)->setDisplayName("Qmin");
39  addProperty(P_QMAX, 1.0)->setDisplayName("Qmax");
40 }
41 
42 std::vector<double> QSpecScanItem::qScanValues() const
43 {
44  int nbins = property<int>(P_NBINS);
45  double qmin = property<double>(P_QMIN);
46  double qmax = property<double>(P_QMAX);
47  return FixedBinAxisItem::create(nbins, qmin, qmax)->binCenters();
48 }
49 
50 // ----------------------------------------------------------------------------
51 
54 {
55  addProperty(P_IMPORTED_DATA, ExternalProperty::undefined())->setDisplayName("Graph");
56 }
57 
59 {
61 }
62 
64 {
65  if (model()) {
66  auto graph_id = property<ExternalProperty>(P_IMPORTED_DATA).identifier();
67  return dynamic_cast<GraphItem*>(model()->findItem(graph_id));
68  }
69  return nullptr;
70 }
71 
72 std::vector<double> ExperimentalScanItem::qScanValues() const
73 {
74  return graphItem() ? graphItem()->binCenters() : std::vector<double>();
75 }
76 
77 // ----------------------------------------------------------------------------
78 
80 {
81  registerItem<QSpecScanItem>("Q-scan", /*make_selected*/ true);
82  registerItem<ExperimentalScanItem>("Based on data");
83  init_group();
84 }
85 
86 // ----------------------------------------------------------------------------
87 
89 {
90  addProperty(P_INTENSITY, 1.0)->setDisplayName("Intensity");
91  addProperty<SpecularScanGroupItem>(P_SCAN_GROUP)->setDisplayName("Specular scan type");
92 }
93 
94 std::vector<double> SpecularBeamItem::qScanValues() const
95 {
96  auto scan_group = item<SpecularScanGroupItem>(P_SCAN_GROUP);
97  if (auto scanItem = dynamic_cast<const BasicSpecularScanItem*>(scan_group->currentItem());
98  scanItem)
99  return scanItem->qScanValues();
100  return {};
101 }
102 
104 {
105  return property<double>(P_INTENSITY);
106 }
107 
108 //! Returns corresponding experimental graph. If current setup is based on simple q-scan, will
109 //! return nullptr.
110 
112 {
113  auto scan_group = item<SpecularScanGroupItem>(P_SCAN_GROUP);
114  if (auto scanItem = dynamic_cast<const ExperimentalScanItem*>(scan_group->currentItem());
115  scanItem)
116  return scanItem->graphItem();
117  return nullptr;
118 }
119 
120 // ----------------------------------------------------------------------------
121 
124 {
125  addProperty<SpecularBeamItem>(P_BEAM);
126 }
127 
129 {
130  return item<SpecularBeamItem>(P_BEAM);
131 }
132 
133 } // namespace gui2
Defines class CLASS?
Complex item holding mixed SessionItem types (single properties and other CompountItems).
Definition: compounditem.h:28
T * addProperty(const std::string &name)
Adds property item of given type.
Definition: compounditem.h:43
static ExternalProperty undefined()
static std::unique_ptr< FixedBinAxisItem > create(int nbins, double xmin, double xmax)
Definition: axisitems.cpp:81
One-dimensional graph representation of Data1DItem.
Definition: graphitem.h:29
std::vector< double > binCenters() const
Definition: graphitem.cpp:59
Group item holds collection of predefined items.
Definition: groupitem.h:26
void init_group()
Inits group item by creating all registered items and constructing combo property for switching betwe...
Definition: groupitem.cpp:84
std::string identifier() const
Returns unique identifier.
Definition: sessionitem.cpp:87
SessionModel * model() const
Returns the model to which given item belongs to.
void setProperty(const std::string &tag, const T &value)
Sets value to property item.
Definition: sessionitem.h:190
SessionItem * findItem(const identifier_type &id)
Returns SessionItem for given identifier.
Represents base type for beam scan parameters.
Represents scan according to imported experimental data.
ModelView::GraphItem * graphItem() const
void setGraphItem(ModelView::GraphItem *graph)
static const std::string P_IMPORTED_DATA
std::vector< double > qScanValues() const override
static const std::string P_NBINS
static const std::string P_QMIN
std::vector< double > qScanValues() const override
static const std::string P_QMAX
Represents specular beam, contains settings of scan parameters.
std::vector< double > qScanValues() const
static const std::string P_INTENSITY
static const std::string P_SCAN_GROUP
ModelView::GraphItem * experimentalGraphItem() const
Returns corresponding experimental graph.
SpecularBeamItem * beamItem() const
static const std::string P_BEAM
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
std::string model_type
Definition: types.h:23
const std::string SpecularScanGroupItemType
const std::string SpecularBeamItemType
const std::string ExperimentalScanItemType
const std::string SpecularInstrumentItemType
const std::string QSpecScanItemType
DAREFLCORE_EXPORT ModelView::ExternalProperty CreateProperty(const ModelView::GraphItem *graph)
Returns property representing given graph.
Definition: modelutils.cpp:39
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20
Defines class CLASS?