BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
DataViewUtils.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/DataViewUtils.cpp
6 //! @brief Implements functions in namespace DataViewUtils
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
23 
24 namespace {
25 std::unique_ptr<IUnitConverter> getConverter(Data1DViewItem* view_item)
26 {
27  auto job_item = view_item->jobItem();
28  ASSERT(job_item->instrumentItem());
29 
30  return DomainObjectBuilder::createUnitConverter(job_item->instrumentItem());
31 }
32 
33 Axes::Units selectedUnits(Data1DViewItem* view_item)
34 {
35  auto current_unit_name =
36  view_item->getItemValue(Data1DViewItem::P_AXES_UNITS).value<ComboProperty>().getValue();
37  return JobItemUtils::axesUnitsFromName(current_unit_name);
38 }
39 } // namespace
40 
42 {
43  auto converter = getConverter(view_item);
44  if (!converter)
45  return;
46  auto current_units = selectedUnits(view_item);
47  view_item->setXaxisTitle(QString::fromStdString(converter->axisName(0, current_units)));
48  if (converter->dimension() > 1)
49  view_item->setYaxisTitle(QString::fromStdString(converter->axisName(1, current_units)));
50 }
51 
52 std::unique_ptr<OutputData<double>> DataViewUtils::getTranslatedData(Data1DViewItem* view_item,
53  DataItem* data_item)
54 {
55  std::unique_ptr<OutputData<double>> result;
56  if (!data_item || !data_item->getOutputData())
57  return result;
58 
59  auto converter = getConverter(view_item);
60  auto current_units = selectedUnits(view_item);
61 
62  result = UnitConverterUtils::createOutputData(*converter, current_units);
63  result->setRawDataVector(data_item->getOutputData()->getRawDataVector());
64 
65  return result;
66 }
#define ASSERT(condition)
Definition: Assert.h:31
Defines class Data1DViewItem.
Declares class DataItem.
Defines class DataPropertyContainer.
Defines namespace DataViewUtils.
Defines DomainObjectBuilder namespace.
Defines class JobItemUtils.
Defines class JobItem.
Declares utilities for unit converters.
Custom property to define list of string values with multiple selections.
Definition: ComboProperty.h:25
View model for 1D DataItem.
JobItem * jobItem()
Returns either parenting JobItem or job item set with DataItem1DView::setJobItem.
static const QString P_AXES_UNITS
void setXaxisTitle(const QString &title)
void setYaxisTitle(const QString &title)
Provides common functionality for IntensityDataItem and SpecularDataItem.
Definition: DataItem.h:29
OutputData< double > * getOutputData()
Definition: DataItem.h:36
std::vector< T > getRawDataVector() const
Returns copy of raw data vector.
Definition: OutputData.h:334
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
std::unique_ptr< OutputData< double > > getTranslatedData(Data1DViewItem *view_item, DataItem *data_item)
void updateAxesTitle(Data1DViewItem *view_item)
std::unique_ptr< IUnitConverter > createUnitConverter(const InstrumentItem *instrumentItem)
Creates a unit converter corresponding to the given instrument item.
Axes::Units axesUnitsFromName(const QString &name)
returns domain axes units type from their GUI name
std::unique_ptr< OutputData< double > > createOutputData(const IUnitConverter &converter, Axes::Units units)
Returns zero-valued output data array in specified units.