30 #include <QApplication>
31 #include <QFileDialog>
33 #include <QMessageBox>
36 const QString filter_string_ba =
"Intensity File (*.int *.gz *.tif *.tiff *.txt *.csv);;"
38 const QString filter_string_ascii =
"Intensity File (*.int *.int.gz *.txt *.csv *.dat *.ascii);;"
39 "Ascii column-wise data (*.*)";
43 return static_cast<int>(item.
shape().size());
48 return static_cast<int>(item.
shape().size());
56 std::unique_ptr<OutputData<double>> result;
58 std::unique_ptr<OutputData<double>> data(
61 }
catch (std::exception& ex) {
62 QString message = QString(
"Error while trying to read file\n\n'%1'\n\n%2")
64 .arg(QString::fromStdString(std::string(ex.what())));
70 std::unique_ptr<OutputData<double>>
73 std::unique_ptr<OutputData<double>> result;
75 std::unique_ptr<OutputData<double>> data(
78 }
catch (std::exception& ex) {
79 QString message = QString(
"Error while trying to read file\n\n'%1'\n\n%2")
81 .arg(QString::fromStdString(std::string(ex.what())));
96 const std::string fileNameStdString = fileName.toStdString();
98 if (selectedLoader ==
nullptr) {
108 }
catch (std::exception& ex) {
110 const bool tryWithLoaders =
117 return QString::fromLatin1(ex.what());
124 QFile file(fileName);
125 const bool fileCouldBeOpened = file.open(QFile::ReadOnly | QIODevice::Text);
127 if (!fileCouldBeOpened)
128 return "File could not be opened.";
130 QByteArray fileContent = file.readAll();
133 if (fileContent.isEmpty())
134 return "The imported file is empty.";
141 if (selectedLoader ==
nullptr)
144 loader = selectedLoader->
clone();
148 QApplication::setOverrideCursor(Qt::WaitCursor);
152 QApplication::restoreOverrideCursor();
160 return rank(instrumentItem) == rank(realDataItem);
163 std::unique_ptr<OutputData<double>>
166 const size_t data_rank = data.
rank();
167 if (data_rank > 2 || data_rank < 1)
168 throw std::runtime_error(
"Error in ImportDataUtils::CreateSimplifiedOutputData: passed "
169 "array is neither 1D nor 2D");
172 for (
size_t i = 0; i < data_rank; ++i) {
174 const size_t axis_size = axis.
size();
175 const double min = 0.0;
176 const double max = axis_size;
185 const std::vector<int>& data_shape)
187 auto to_str = [](
const std::vector<int>& shape) {
189 for (
size_t i = 0, size = shape.size(); i < size; ++i) {
190 result += std::to_string(shape[i]);
197 std::string message_string =
"instrument [";
198 message_string += to_str(instrument_shape);
199 message_string +=
"], data [";
200 message_string += to_str(data_shape);
201 message_string +=
"]";
202 return QString::fromStdString(std::move(message_string));
Defines class AbstractDataLoader1D.
Defines various axis items.
Defines class DataLoaders1D.
Defines class GUIHelpers functions.
Defines class ProjectManager.
Defines ImportDataUtils namespace.
Defines InstrumentItems classes.
Defines class IntensityDataIOFactory.
Defines class IntensityDataItem.
Defines class PointwiseAxis.
Defines class QREDataLoader.
Defines class RealDataItem.
Base class for all data loaders (classes which can import real data)
virtual void guessSettings()
Guess appropriate settings (for example the separator in a CSV file).
virtual void setFileContents(const QByteArray &fileContent)=0
Sets the file contents to be imported.
virtual void processContents()=0
Process the file contents.
virtual void initWithDefaultImportSettings()
Set import settings to defaults.
virtual AbstractDataLoader * clone() const =0
Create a complete clone, including all internal states.
void setRealDataItem(RealDataItem *item)
Define the real data item on which the import shall work.
Axis with fixed bin size.
Interface for one-dimensional axes.
virtual size_t size() const =0
retrieve the number of bins
std::string getName() const
retrieve the label of the axis
Carries information about loaded data.
virtual std::vector< int > shape() const =0
static OutputData< double > * readOutputData(const std::string &file_name)
Reads file and returns newly created OutputData object.
static OutputData< double > * readReflectometryData(const std::string &file_name)
size_t rank() const
Returns number of dimensions.
std::vector< T > getRawDataVector() const
Returns copy of raw data vector.
const IAxis & axis(size_t serial_number) const
returns axis with given serial number
Real data loader for Q/R/E reflectometry CSV files.
The RealDataItem class represents intensity data imported from file and intended for fitting.
void setImportData(ImportDataInfo data)
Sets imported data to underlying item.
std::vector< int > shape() const
Returns the shape of underlying data item.
QString nativeFileName() const
void setDataLoader(AbstractDataLoader *loader)
Takes ownership of loader.
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
std::unique_ptr< OutputData< double > > CreateSimplifiedOutputData(const OutputData< double > &data)
Creates OutputData with bin-valued axes.
std::unique_ptr< OutputData< double > > ImportReflectometryData(const QString &baseNameOfLoadedFile)
QString Import1dData(RealDataItem *realDataItem, const AbstractDataLoader *selectedLoader)
Import 1D data into the given item.
QString printShapeMessage(const std::vector< int > &instrument_shape, const std::vector< int > &data_shape)
Composes a message with the shapes of InstrumentItem and RealDataItem.
std::unique_ptr< OutputData< double > > ImportKnownData(const QString &baseNameOfLoadedFile)
bool Compatible(const InstrumentItem &instrumentItem, const RealDataItem &realDataItem)
Check whether data item is compatible with instrument (same rank)
std::unique_ptr< OutputData< double > > Import2dData(const QString &baseNameOfLoadedFile)