BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
GUI::Model::JobItemUtils Namespace Reference

Description

Contains convenience methods to trasfer data from domain simulation to IntensityDataItem. Used to modify Datafield's axes units as requested by IntensityDataItem.

Functions

ComboProperty availableUnits (const ICoordSystem &converter)
 
void createDefaultDetectorMap (DataItem *intensityItem, const Instrument2DItem *instrumentItem)
 
void setIntensityItemCoords (DataItem *intensityItem, const ICoordSystem &converter)
 
void setIntensityItemCoords (DataItem *intensityItem, const InstrumentItem *instrumentItem)
 Sets axes units suitable for given instrument. More...
 
void setResults (DataItem *intensityItem, const SimulationResult &result)
 Sets simulation results into the DataItem. More...
 
void updateDataAxes (DataItem *intensityItem, const InstrumentItem *instrumentItem)
 updates axes of Datafield in IntensityData item More...
 

Function Documentation

◆ availableUnits()

ComboProperty GUI::Model::JobItemUtils::availableUnits ( const ICoordSystem &  converter)

Definition at line 103 of file JobItemUtils.cpp.

104 {
105  ComboProperty result;
106  for (auto units : converter.availableUnits()) {
107  auto unit_name = GUI::Util::CoordName::nameFromCoord(units);
108  if (!unit_name.isEmpty())
109  result << unit_name;
110  }
111 
112  result.setValue(GUI::Util::CoordName::nameFromCoord(converter.defaultUnits()));
113  return result;
114 }
Custom property to define list of string values with multiple selections. Intended for QVariant.
Definition: ComboProperty.h:25
void setValue(const QString &name)
QString nameFromCoord(Coords units)
Returns axes units names from their domain counterpart.
Definition: CoordName.cpp:36

References GUI::Util::CoordName::nameFromCoord(), and ComboProperty::setValue().

Referenced by GUI::Model::JobFunctions::initDataView(), and setIntensityItemCoords().

Here is the call graph for this function:

◆ createDefaultDetectorMap()

void GUI::Model::JobItemUtils::createDefaultDetectorMap ( DataItem intensityItem,
const Instrument2DItem instrumentItem 
)

Definition at line 82 of file JobItemUtils.cpp.

84 {
85  auto* const converter = instrumentItem->createCoordSystem();
86  auto output_data = std::make_unique<Datafield>(converter->defaultAxes());
87  intensityItem->setDatafield(output_data.release());
88  setIntensityItemCoords(intensityItem, *converter);
89  updateAxesTitle(intensityItem, *converter, converter->defaultUnits());
90 }
virtual void setDatafield(Datafield *data)=0
The given pointer becomes owned by this class!!
Definition: DataItem.cpp:20
virtual ICoordSystem * createCoordSystem() const =0
void updateAxesTitle(Data1DViewItem *view_item)
void setIntensityItemCoords(DataItem *intensityItem, const InstrumentItem *instrumentItem)
Sets axes units suitable for given instrument.

References InstrumentItem::createCoordSystem(), DataItem::setDatafield(), setIntensityItemCoords(), and GUI::Model::DataViewUtils::updateAxesTitle().

Here is the call graph for this function:

◆ setIntensityItemCoords() [1/2]

void GUI::Model::JobItemUtils::setIntensityItemCoords ( DataItem intensityItem,
const ICoordSystem &  converter 
)

Definition at line 75 of file JobItemUtils.cpp.

77 {
78  ComboProperty combo = availableUnits(converter);
79  intensityItem->setAxesUnits(combo);
80 }
void setAxesUnits(const ComboProperty &units)
Definition: DataItem.cpp:96
ComboProperty availableUnits(const ICoordSystem &converter)

References availableUnits(), and DataItem::setAxesUnits().

Here is the call graph for this function:

◆ setIntensityItemCoords() [2/2]

void GUI::Model::JobItemUtils::setIntensityItemCoords ( DataItem intensityItem,
const InstrumentItem instrumentItem 
)

Sets axes units suitable for given instrument.

Definition at line 66 of file JobItemUtils.cpp.

68 {
69  auto* const converter = instrumentItem->createCoordSystem();
70  if (!converter)
71  return;
72  setIntensityItemCoords(intensityItem, *converter);
73 }

References InstrumentItem::createCoordSystem().

Referenced by createDefaultDetectorMap(), setResults(), and RealDataItem::updateToInstrument().

Here is the call graph for this function:

◆ setResults()

void GUI::Model::JobItemUtils::setResults ( DataItem intensityItem,
const SimulationResult &  result 
)

Sets simulation results into the DataItem.

Definition at line 92 of file JobItemUtils.cpp.

93 {
94  if (intensityItem->getDatafield() == nullptr) {
95  const auto& converter = result.converter();
96  GUI::Model::JobItemUtils::setIntensityItemCoords(intensityItem, converter);
97  updateAxesTitle(intensityItem, converter, converter.defaultUnits());
98  }
99  auto selected_units = GUI::Util::CoordName::coordFromName(intensityItem->selectedCoords());
100  intensityItem->setDatafield(result.datafield(selected_units));
101 }
Datafield * getDatafield()
Definition: DataItem.h:41
QString selectedCoords() const
Definition: DataItem.cpp:91
Coords coordFromName(const QString &name)
Returns domain axes units type from their GUI name.
Definition: CoordName.cpp:46

References GUI::Util::CoordName::coordFromName(), DataItem::getDatafield(), DataItem::selectedCoords(), DataItem::setDatafield(), setIntensityItemCoords(), and GUI::Model::DataViewUtils::updateAxesTitle().

Referenced by JobItem::setResults().

Here is the call graph for this function:

◆ updateDataAxes()

void GUI::Model::JobItemUtils::updateDataAxes ( DataItem intensityItem,
const InstrumentItem instrumentItem 
)

updates axes of Datafield in IntensityData item

Updates axes of Datafield in IntensityData item to correspond with ::P_AXES_UNITS selection. InstrumentItem is used to get domain's detector map for given units.

Definition at line 37 of file JobItemUtils.cpp.

39 {
40  ASSERT(intensityItem);
41 
42  if (!instrumentItem) {
43  // special case when reading old project files: project failed on load instrument
44  // but we want to try to recover the rest.
45  return;
46  }
47 
48  if (!intensityItem->getDatafield())
49  return;
50 
51  Coords requested_units = GUI::Util::CoordName::coordFromName(intensityItem->selectedCoords());
52 
53  auto* const converter = instrumentItem->createCoordSystem();
54 
55  auto newData = std::make_unique<Datafield>(converter->convertedAxes(requested_units));
56 
57  newData->setVector(intensityItem->getDatafield()->flatVector());
58 
59  intensityItem->setDatafield(newData.release());
60  intensityItem->setAxesRangeToData();
61  updateAxesTitle(intensityItem, *converter, requested_units);
62 }
virtual void setAxesRangeToData()=0

References GUI::Util::CoordName::coordFromName(), InstrumentItem::createCoordSystem(), DataItem::getDatafield(), DataItem::selectedCoords(), DataItem::setAxesRangeToData(), DataItem::setDatafield(), and GUI::Model::DataViewUtils::updateAxesTitle().

Referenced by IntensityDataItem::updateCoords(), and SpecularDataItem::updateCoords().

Here is the call graph for this function: