BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
CsvImportAssistant.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvImportAssistant.h
6 //! @brief Defines class CsvImportAssistant
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 
15 #ifndef BORNAGAIN_GUI_COREGUI_VIEWS_IMPORTDATAWIDGETS_CSVIMPORTASSISTANT_CSVIMPORTASSISTANT_H
16 #define BORNAGAIN_GUI_COREGUI_VIEWS_IMPORTDATAWIDGETS_CSVIMPORTASSISTANT_CSVIMPORTASSISTANT_H
17 
22 #include <QStringList>
23 #include <QWidget>
24 #include <memory>
25 #include <set>
26 
28 public:
30  : m_intensityColNum(-1)
32  , m_coordinateColNum(-1)
34  , m_firstRow(-1)
35  , m_lastRow(-1)
36  , m_units(Axes::Units::NBINS)
37  {
38  }
39 
45  int m_lastRow;
47 
48  bool availableData() { return m_intensityColNum > -1; }
49 };
50 
51 //! Logic for importing intensity data from csv files
52 class CsvImportAssistant : public QObject {
53  Q_OBJECT
54 public:
55  CsvImportAssistant(const QString& file, const bool useGUI = false, QWidget* parent = nullptr);
57  static void showErrorMessage(std::string message);
58  void setIntensityColumn(int iCol, double multiplier = 1.0);
59  void setCoordinateColumn(int iCol, Axes::Units units, double multiplier = 1.0);
60  void setFirstRow(int iRow);
61  void setLastRow(int iRow);
62  size_t columnCount() { return m_csvArray[0].size(); }
63  char separator() { return m_separator; }
64 
65 private:
66  bool loadCsvFile();
68  bool hasEqualLengthLines(csv::DataArray& dataArray);
69  char guessSeparator() const;
70  void removeBlankColumns();
72  void runDataSelector(QWidget* parent);
73  void getValuesFromColumns(std::vector<double>& intensityVals, std::vector<double>& coordVals);
74  void resetSelection();
75  void resetAssistant();
76 
77  QString m_fileName;
78  std::unique_ptr<CSVFile> m_csvFile;
86  int m_lastRow;
87  std::set<int> m_rowsToDiscard;
90 };
91 #endif // BORNAGAIN_GUI_COREGUI_VIEWS_IMPORTDATAWIDGETS_CSVIMPORTASSISTANT_CSVIMPORTASSISTANT_H
Defines classes CsvIntensityColumn and CsvCoordinateColumn.
Defines class CsvReader.
Defines class OutputDataIOFactory.
Defines ImportDataInfo helper struct.
Wrapper for detector axes units, required for a better representation of detector axes units in pytho...
Logic for importing intensity data from csv files.
void setIntensityColumn(int iCol, double multiplier=1.0)
csv::DataArray m_csvArray
std::set< int > m_rowsToDiscard
bool hasEqualLengthLines(csv::DataArray &dataArray)
void setFirstRow(int iRow)
static void showErrorMessage(std::string message)
ImportDataInfo getData()
ImportDataInfo fillData()
std::unique_ptr< CSVFile > m_csvFile
CsvImportAssistant(const QString &file, const bool useGUI=false, QWidget *parent=nullptr)
void setCoordinateColumn(int iCol, Axes::Units units, double multiplier=1.0)
void runDataSelector(QWidget *parent)
void getValuesFromColumns(std::vector< double > &intensityVals, std::vector< double > &coordVals)
Carries information about loaded data.
Constants and functions for physical unit conversions.
Definition: Units.h:30
std::vector< std::vector< std::string > > DataArray
Definition: CsvNamespace.h:26