16 #include "Base/Py/PyFmt.h"
17 #include "Device/Data/Datafield.h"
25 #include <QFileDialog>
26 #include <QTextStream>
28 #include <boost/polymorphic_cast.hpp>
30 using boost::polymorphic_downcast;
34 const int bin_centers_colwidth = 12;
35 const int bin_values_colwidth = 20;
37 QString to_scientific_str(
double value)
39 auto str = Py::Fmt::printScientificDouble(value);
40 return QString(
"%1").arg(QString::fromStdString(str), -bin_values_colwidth);
43 QString to_double_str(
double value)
45 auto str = Py::Fmt::printDouble(value);
46 return QString(
"%1").arg(QString::fromStdString(str), -bin_centers_colwidth);
51 return polymorphic_downcast<VerticalLineItem*>(item1)->posX()
52 < polymorphic_downcast<VerticalLineItem*>(item2)->posX();
57 return polymorphic_downcast<HorizontalLineItem*>(item1)->posY()
58 < polymorphic_downcast<HorizontalLineItem*>(item2)->posY();
70 ASSERT(intensityItem);
73 QString fileName = QFileDialog::getSaveFileName(
74 parent,
"Save projections data", defaultName,
"",
nullptr,
76 : QFileDialog::DontUseNativeDialog);
78 if (fileName.isEmpty())
82 if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
83 throw Error(
"TestGUI::Project::Utils::createTestFile() -> Error. "
88 QTextStream out(&file);
90 out <<
"# Projections along x-axis (horizontal projections) \n";
94 out <<
"# Projections along y-axis (vertical projections) \n";
107 QTextStream out(&result);
111 if (projData.projections.isEmpty())
116 auto bin_centers = projData.bin_centers;
118 for (
int i_point = 0; i_point < bin_centers.size(); ++i_point) {
119 out << to_double_str(bin_centers[i_point]) <<
" ";
120 for (
auto& data : projData.projections)
121 out << to_scientific_str(data.bin_values[i_point]);
137 std::unique_ptr<Datafield> field;
141 data.
axis_value = polymorphic_downcast<HorizontalLineItem*>(item)->posY();
144 data.
axis_value = polymorphic_downcast<VerticalLineItem*>(item)->posX();
148 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
149 auto values = field->flatVector();
150 auto centers = field->axis(0).binCenters();
151 data.
bin_values = QVector<double>(values.begin(), values.end());
153 result.
bin_centers = QVector<double>(centers.begin(), centers.end());
155 data.
bin_values = QVector<double>::fromStdVector(hist->binValues());
157 result.
bin_centers = QVector<double>::fromStdVector(hist->binCenters());
171 std::sort(result.begin(), result.end(),
187 result.append(QString(
"%1").arg(xcol, -bin_centers_colwidth));
190 result.append(QString(
"%1%2").arg(ycol).arg(data.axis_value,
191 -(bin_values_colwidth - ycol.size()),
'f', 4));
ApplicationSettings * appSettings
global pointer to the instance
Defines class ApplicationSettings.
Defines class IntensityDataItem.
Defines MaskItems classes.
Defines class ProjectDocument.
Defines items related to projections over color map.
Defines class SaveProjectionsAssistant.
SessionData * gSessionData
global pointer to the single instance
Defines struct SessionData.
bool useNativeFileDialog() const
Datafield * getDatafield()
static constexpr auto M_TYPE
ProjectionContainerItem * projectionContainerItem()
SaveProjectionsAssistant()
QString projectionFileHeader(ProjectionsData &projectionsData)
Returns projections header. For projections along x it will be "# x y=6.0194 y=33....
std::unique_ptr< Datafield > m_field
ProjectionsData projectionsData(const QString &projectionsType, IntensityDataItem *intensityItem)
Returns projections data for all projections of given type (horizontal, vertical).
QString projectionsToString(const QString &projectionsType, IntensityDataItem *intensityItem)
Generates multi-line string with projections data of given type (horizontal, vertical).
~SaveProjectionsAssistant()
QVector< SessionItem * > projectionItems(const QString &projectionsType, IntensityDataItem *intensityItem)
Returns vector of ProjectionItems sorted according to axis value.
void saveProjections(QWidget *parent, IntensityDataItem *intensityItem)
Calls file open dialog and writes projection data as ASCII.
Base class for a GUI data item.
QVector< SessionItem * > childrenOfType(const QString &model_type) const
Returns a vector of all children of the given type.
static constexpr auto M_TYPE
QVector< double > bin_values
double axis_value
value on axis where projection has been made
QVector< Projection > projections
QVector< double > bin_centers
std::optional< ProjectDocument * > projectDocument