diff --git a/Device/IO/IOFactory.cpp b/Device/IO/IOFactory.cpp index 1a30d293940453cd690723d6d2255f1270b6de36..3b5782c80866c53801129c5a382e38c4ae2a0b2e 100644 --- a/Device/IO/IOFactory.cpp +++ b/Device/IO/IOFactory.cpp @@ -108,7 +108,7 @@ void stream2file(const std::string& file_name, std::stringstream& s) fout.close(); } -bool fileTypeMatchesFiletype2D(const std::string& fileName, IO::Filetype2D selector) +bool fileTypeMatchesFiletype(const std::string& fileName, IO::Filetype selector) { switch (selector) { case IO::bornagain: @@ -117,7 +117,7 @@ bool fileTypeMatchesFiletype2D(const std::string& fileName, IO::Filetype2D selec return DataUtil::Format::isNicosFile(fileName); case IO::tiff: return DataUtil::Format::isTiffFile(fileName); - case IO::auto2D: + default: return false; } @@ -127,11 +127,11 @@ bool fileTypeMatchesFiletype2D(const std::string& fileName, IO::Filetype2D selec } // namespace -Datafield* IO::readData2D(const std::string& file_name, Filetype2D selector) +Datafield* IO::readData2D(const std::string& file_name, Filetype selector) { - const auto readAs = [=](Filetype2D testForSelector) { + const auto readAs = [=](Filetype testForSelector) { return (selector == testForSelector) - || (selector == auto2D && ::fileTypeMatchesFiletype2D(file_name, testForSelector)); + || (selector == nil && ::fileTypeMatchesFiletype(file_name, testForSelector)); }; auto s = ::file2stream(file_name); @@ -154,7 +154,7 @@ Datafield* IO::readData2D(const std::string& file_name, Filetype2D selector) return Util::RW::readNumpyTxt(s); } -Datafield* IO::readData1D(const std::string& file_name, Filetype1D /*selector*/) +Datafield* IO::readData1D(const std::string& file_name, Filetype /*selector*/) { auto s = ::file2stream(file_name); return Util::RW::readReflectometryTable(s); diff --git a/Device/IO/IOFactory.h b/Device/IO/IOFactory.h index 5b9733497d18f4b96730b76c80fc22b21af09bfa..35c5951c9d7786ff858b98d944137d4fdf291464 100644 --- a/Device/IO/IOFactory.h +++ b/Device/IO/IOFactory.h @@ -21,22 +21,21 @@ class Datafield; namespace IO { -enum Filetype2D { auto2D, bornagain, tiff, nicos }; -enum Filetype1D { auto1D, mft }; +enum Filetype { nil, bornagain, tiff, nicos, mft }; //! Reads 1D data file and returns newly created Datafield object. -//! If selector is 'auto1D', then the file extension will determine the loader to be used. +//! If selector is 'nil', then the file extension will determine the loader to be used. //! For any other selector, the file extension is ignored. //! If file name ends with "*.gz" or "*.bz2" the file will be unzipped on the fly. //! May throw, but will never return nullptr. -Datafield* readData1D(const std::string& file_name, Filetype1D selector = auto1D); +Datafield* readData1D(const std::string& file_name, Filetype selector = nil); //! Reads 2D data file and returns newly created Datafield object. -//! If selector is 'auto2D', then the file extension will determine the loader to be used. +//! If selector is 'nil', then the file extension will determine the loader to be used. //! For any other selector, the file extension is ignored. //! If file name ends with "*.gz" or "*.bz2" the file will be unzipped on the fly. //! May throw, but will never return nullptr. -Datafield* readData2D(const std::string& file_name, Filetype2D selector = auto2D); +Datafield* readData2D(const std::string& file_name, Filetype selector = nil); //! Writes Datafield to file. //! If selector is 'auto2D', then the file extension will determine the loader to be used. diff --git a/GUI/View/Import/ImportDataUtil.cpp b/GUI/View/Import/ImportDataUtil.cpp index 3ff6ba9b703fa391d1e52796e37db124d7400edd..ae50eda6d4eb2c0b6e868221000fb49430d6d29d 100644 --- a/GUI/View/Import/ImportDataUtil.cpp +++ b/GUI/View/Import/ImportDataUtil.cpp @@ -32,8 +32,7 @@ const QString filter_string_ascii = "Intensity File (*.int *.int.gz *.txt *.csv //! Allocates Datafield, and returns owning pointer. //! Currently used for all 2D, and some 1D data files. -std::unique_ptr<Datafield> ImportKnownData(const QString& fileName, - IO::Filetype2D loader = IO::auto2D) +std::unique_ptr<Datafield> ImportKnownData(const QString& fileName, IO::Filetype loader = IO::nil) { // Try to use the canonical tools for importing data std::unique_ptr<Datafield> result; @@ -52,7 +51,7 @@ std::unique_ptr<Datafield> ImportKnownData(const QString& fileName, std::unique_ptr<Datafield> GUI::View::ImportDataUtil::Import2dData(const QString& fileName, - IO::Filetype2D loader) + IO::Filetype loader) { return ImportKnownData(fileName, loader); } diff --git a/GUI/View/Import/ImportDataUtil.h b/GUI/View/Import/ImportDataUtil.h index 38ca1a1f60f6ca13509e393977dce0a2df95fece..6adbd28e4549a5fda5a07cfcf3c0667c6b1946b8 100644 --- a/GUI/View/Import/ImportDataUtil.h +++ b/GUI/View/Import/ImportDataUtil.h @@ -29,7 +29,7 @@ class AbstractDataLoader; namespace GUI::View::ImportDataUtil { //! Imports 2D data, stores them as Datafield, and returns owning pointer. -std::unique_ptr<Datafield> Import2dData(const QString& fileName, IO::Filetype2D loader); +std::unique_ptr<Datafield> Import2dData(const QString& fileName, IO::Filetype loader); //! Imports 1D data into the given item. diff --git a/GUI/View/Import/RealDataSelectorWidget.cpp b/GUI/View/Import/RealDataSelectorWidget.cpp index f6ea07d54eb55a2992cb808fb2cafa0fe92d602f..d697f08c31fa4c379dfa4b3759f6c446ec7ceb0c 100644 --- a/GUI/View/Import/RealDataSelectorWidget.cpp +++ b/GUI/View/Import/RealDataSelectorWidget.cpp @@ -282,10 +282,10 @@ void RealDataSelectorWidget::importData1D() void RealDataSelectorWidget::importData2D() { - QMap<QString, IO::Filetype2D> loaderOfFilter; + QMap<QString, IO::Filetype> loaderOfFilter; QString filters; - const auto addFilter = [&](IO::Filetype2D loaderSelector, const QString& filter) { + const auto addFilter = [&](IO::Filetype loaderSelector, const QString& filter) { if (!filters.isEmpty()) filters += ";;"; filters += filter; @@ -294,8 +294,8 @@ void RealDataSelectorWidget::importData2D() addFilter(IO::tiff, "TIFF (*.tif *.tiff *.tif.gz)"); addFilter(IO::nicos, "Nicos/SANSDRaw (*.001)"); addFilter(IO::bornagain, "BornAgain (*.int.gz)"); - addFilter(IO::auto2D, "CSV (*.txt *.csv *.dat)"); - addFilter(IO::auto2D, "All (*.*)"); + addFilter(IO::nil, "CSV (*.txt *.csv *.dat)"); + addFilter(IO::nil, "All (*.*)"); QString selectedFilter = ProjectManager::instance()->recentlyUsedImportFilter2D(); @@ -310,7 +310,7 @@ void RealDataSelectorWidget::importData2D() ProjectManager::instance()->setImportDirFromFilePath(fileNames[0]); ProjectManager::instance()->setRecentlyUsedImportFilter2D(selectedFilter); - const auto selectedLoader = loaderOfFilter.value(selectedFilter, IO::auto2D); + const auto selectedLoader = loaderOfFilter.value(selectedFilter, IO::nil); for (const auto& fileName : fileNames) { std::unique_ptr<Datafield> data = diff --git a/Tests/Unit/Device/ReadSANSDRawTest.cpp b/Tests/Unit/Device/ReadSANSDRawTest.cpp index 5fa6b9ee33ce3c59665e272a3a7d3760a0b9a1df..1aa637034d7a7a2f20784d123d7293ba39fdae0f 100644 --- a/Tests/Unit/Device/ReadSANSDRawTest.cpp +++ b/Tests/Unit/Device/ReadSANSDRawTest.cpp @@ -6,7 +6,7 @@ TEST(ReadSANSDRawTest, Read) { const auto fname = BATesting::ExampleDataDir() + "/SANSDRaw.001"; - Datafield* data = IO::readData2D(fname, IO::auto2D); + Datafield* data = IO::readData2D(fname); EXPECT_NE(data, nullptr); if (!data) return; diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py index ea8489498f81cadc3569815f12cafbba2a3a04db..f67daa4a817234cc4f5b352c8aa2f55ff412df0b 100644 --- a/auto/Wrap/libBornAgainDevice.py +++ b/auto/Wrap/libBornAgainDevice.py @@ -2989,7 +2989,7 @@ class SphericalDetector(IDetector): # Register SphericalDetector in _libBornAgainDevice: _libBornAgainDevice.SphericalDetector_swigregister(SphericalDetector) -auto2D = _libBornAgainDevice.auto2D +nil = _libBornAgainDevice.nil bornagain = _libBornAgainDevice.bornagain @@ -2997,17 +2997,15 @@ tiff = _libBornAgainDevice.tiff nicos = _libBornAgainDevice.nicos -auto1D = _libBornAgainDevice.auto1D - mft = _libBornAgainDevice.mft def readData1D(*args): - r"""readData1D(std::string const & file_name, IO::Filetype1D selector=auto1D) -> Datafield""" + r"""readData1D(std::string const & file_name, IO::Filetype selector=nil) -> Datafield""" return _libBornAgainDevice.readData1D(*args) def readData2D(*args): - r"""readData2D(std::string const & file_name, IO::Filetype2D selector=auto2D) -> Datafield""" + r"""readData2D(std::string const & file_name, IO::Filetype selector=nil) -> Datafield""" return _libBornAgainDevice.readData2D(*args) def writeDatafield(data, file_name): diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp index 19d8f8fd4ae9de51b8241212df5d2fd9bf19a126..f501458ed4b58b26cca6b888ff02184de07d22bb 100644 --- a/auto/Wrap/libBornAgainDevice_wrap.cpp +++ b/auto/Wrap/libBornAgainDevice_wrap.cpp @@ -36185,7 +36185,7 @@ SWIGINTERN PyObject *SphericalDetector_swiginit(PyObject *SWIGUNUSEDPARM(self), SWIGINTERN PyObject *_wrap_readData1D__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; std::string *arg1 = 0 ; - IO::Filetype1D arg2 ; + IO::Filetype arg2 ; int res1 = SWIG_OLDOBJ ; int val2 ; int ecode2 = 0 ; @@ -36205,9 +36205,9 @@ SWIGINTERN PyObject *_wrap_readData1D__SWIG_0(PyObject *self, Py_ssize_t nobjs, } ecode2 = SWIG_AsVal_int(swig_obj[1], &val2); if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "readData1D" "', argument " "2"" of type '" "IO::Filetype1D""'"); + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "readData1D" "', argument " "2"" of type '" "IO::Filetype""'"); } - arg2 = static_cast< IO::Filetype1D >(val2); + arg2 = static_cast< IO::Filetype >(val2); result = (Datafield *)IO::readData1D((std::string const &)*arg1,arg2); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Datafield, 0 | 0 ); if (SWIG_IsNewObj(res1)) delete arg1; @@ -36280,7 +36280,7 @@ SWIGINTERN PyObject *_wrap_readData1D(PyObject *self, PyObject *args) { fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'readData1D'.\n" " Possible C/C++ prototypes are:\n" - " IO::readData1D(std::string const &,IO::Filetype1D)\n" + " IO::readData1D(std::string const &,IO::Filetype)\n" " IO::readData1D(std::string const &)\n"); return 0; } @@ -36289,7 +36289,7 @@ fail: SWIGINTERN PyObject *_wrap_readData2D__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; std::string *arg1 = 0 ; - IO::Filetype2D arg2 ; + IO::Filetype arg2 ; int res1 = SWIG_OLDOBJ ; int val2 ; int ecode2 = 0 ; @@ -36309,9 +36309,9 @@ SWIGINTERN PyObject *_wrap_readData2D__SWIG_0(PyObject *self, Py_ssize_t nobjs, } ecode2 = SWIG_AsVal_int(swig_obj[1], &val2); if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "readData2D" "', argument " "2"" of type '" "IO::Filetype2D""'"); + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "readData2D" "', argument " "2"" of type '" "IO::Filetype""'"); } - arg2 = static_cast< IO::Filetype2D >(val2); + arg2 = static_cast< IO::Filetype >(val2); result = (Datafield *)IO::readData2D((std::string const &)*arg1,arg2); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Datafield, 0 | 0 ); if (SWIG_IsNewObj(res1)) delete arg1; @@ -36384,7 +36384,7 @@ SWIGINTERN PyObject *_wrap_readData2D(PyObject *self, PyObject *args) { fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'readData2D'.\n" " Possible C/C++ prototypes are:\n" - " IO::readData2D(std::string const &,IO::Filetype2D)\n" + " IO::readData2D(std::string const &,IO::Filetype)\n" " IO::readData2D(std::string const &)\n"); return 0; } @@ -38262,8 +38262,8 @@ static PyMethodDef SwigMethods[] = { { "SphericalDetector_indexOfSpecular", _wrap_SphericalDetector_indexOfSpecular, METH_VARARGS, "SphericalDetector_indexOfSpecular(SphericalDetector self, Beam beam) -> size_t"}, { "SphericalDetector_swigregister", SphericalDetector_swigregister, METH_O, NULL}, { "SphericalDetector_swiginit", SphericalDetector_swiginit, METH_VARARGS, NULL}, - { "readData1D", _wrap_readData1D, METH_VARARGS, "readData1D(std::string const & file_name, IO::Filetype1D selector=auto1D) -> Datafield"}, - { "readData2D", _wrap_readData2D, METH_VARARGS, "readData2D(std::string const & file_name, IO::Filetype2D selector=auto2D) -> Datafield"}, + { "readData1D", _wrap_readData1D, METH_VARARGS, "readData1D(std::string const & file_name, IO::Filetype selector=nil) -> Datafield"}, + { "readData2D", _wrap_readData2D, METH_VARARGS, "readData2D(std::string const & file_name, IO::Filetype selector=nil) -> Datafield"}, { "writeDatafield", _wrap_writeDatafield, METH_VARARGS, "writeDatafield(Datafield data, std::string const & file_name)"}, { "filesAgree", _wrap_filesAgree, METH_VARARGS, "filesAgree(std::string const & datFileName, std::string const & refFileName, double tol) -> bool"}, { "new_SimulationResult", _wrap_new_SimulationResult, METH_VARARGS, "\n" @@ -39261,11 +39261,10 @@ SWIG_init(void) { SWIG_Python_SetConstant(d, "RectangularDetector_PERPENDICULAR_TO_SAMPLE",SWIG_From_int(static_cast< int >(RectangularDetector::PERPENDICULAR_TO_SAMPLE))); SWIG_Python_SetConstant(d, "RectangularDetector_PERPENDICULAR_TO_DIRECT_BEAM",SWIG_From_int(static_cast< int >(RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM))); SWIG_Python_SetConstant(d, "RectangularDetector_PERPENDICULAR_TO_REFLECTED_BEAM",SWIG_From_int(static_cast< int >(RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM))); - SWIG_Python_SetConstant(d, "auto2D",SWIG_From_int(static_cast< int >(IO::auto2D))); + SWIG_Python_SetConstant(d, "nil",SWIG_From_int(static_cast< int >(IO::nil))); SWIG_Python_SetConstant(d, "bornagain",SWIG_From_int(static_cast< int >(IO::bornagain))); SWIG_Python_SetConstant(d, "tiff",SWIG_From_int(static_cast< int >(IO::tiff))); SWIG_Python_SetConstant(d, "nicos",SWIG_From_int(static_cast< int >(IO::nicos))); - SWIG_Python_SetConstant(d, "auto1D",SWIG_From_int(static_cast< int >(IO::auto1D))); SWIG_Python_SetConstant(d, "mft",SWIG_From_int(static_cast< int >(IO::mft))); #if PY_VERSION_HEX >= 0x03000000 return m;