BornAgain  1.19.79
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/Model/Data/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 
16 #include "Device/Coord/ICoordSystem.h"
20 #include "GUI/Model/Job/JobItem.h"
21 #include "GUI/Util/CoordName.h"
22 
23 namespace {
24 
25 ICoordSystem* getConverter(Data1DViewItem* view_item)
26 {
27  auto* job_item = view_item->jobItem();
28  ASSERT(job_item->instrumentItem());
29 
30  return job_item->instrumentItem()->createCoordSystem();
31 }
32 
33 Coords selectedUnits(Data1DViewItem* view_item)
34 {
35  QString current_unit_name = view_item->axesUnits().getValue();
36  return GUI::Util::CoordName::coordFromName(current_unit_name);
37 }
38 
39 } // namespace
40 
41 
43 {
44  std::unique_ptr<ICoordSystem> converter{getConverter(view_item)};
45  if (!converter)
46  return;
47  auto current_units = selectedUnits(view_item);
48  view_item->setXaxisTitle(QString::fromStdString(converter->axisName(0, current_units)));
49  if (converter->rank() > 1)
50  view_item->setYaxisTitle(QString::fromStdString(converter->axisName(1, current_units)));
51 }
52 
53 std::unique_ptr<Datafield> GUI::Model::DataViewUtils::getTranslatedData(Data1DViewItem* view_item,
54  DataItem* data_item)
55 {
56  if (!data_item || !data_item->getDatafield())
57  return {};
58 
59  auto* converter = getConverter(view_item);
60  auto current_units = selectedUnits(view_item);
61 
62  auto result = std::make_unique<Datafield>(converter->convertedAxes(current_units));
63 
64  result->setVector(data_item->getDatafield()->flatVector());
65 
66  return result;
67 }
Defines namespace GUI::Util::CoordName.
Defines class Data1DViewItem.
Declares class DataItem.
Defines namespace GUI::Model::DataViewUtils.
Defines class InstrumentItem and all its children.
Defines class JobItem.
QString getValue() const
View model for 1D DataItem. Can represent several items at once. In current implementation the first ...
JobItem * jobItem()
Returns either parenting JobItem or job item set with DataItem1DView::setJobItem.
void setXaxisTitle(const QString &title)
void setYaxisTitle(const QString &title)
ComboProperty axesUnits() const
Abstract base class for IntensityDataItem and SpecularDataItem. Owns one simulated data set of type D...
Definition: DataItem.h:34
Datafield * getDatafield()
Definition: DataItem.h:41
std::unique_ptr< Datafield > getTranslatedData(Data1DViewItem *view_item, DataItem *data_item)
void updateAxesTitle(Data1DViewItem *view_item)
Coords coordFromName(const QString &name)
Returns domain axes units type from their GUI name.
Definition: CoordName.cpp:46