From 2ac754dee16c06f781cc49d136fad19f47d39c57 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Wed, 7 Oct 2020 17:21:12 +0200 Subject: [PATCH] dissolve Core/PyIO --- {Core/PyIO => Base/Utils}/PyEmbeddedUtils.cpp | 5 +- {Core/PyIO => Base/Utils}/PyEmbeddedUtils.h | 2 +- Core/Export/SampleToPython.cpp | 2 +- Core/Export/SimulationToPython.cpp | 2 +- Core/Instrument/AngularSpecScan.cpp | 2 +- .../PyFmt2.cpp} | 4 +- .../PyFmt2.h} | 2 +- Core/Instrument/QSpecScan.cpp | 2 +- Core/{PyIO => Multilayer}/PyImport.cpp | 6 +- Core/{PyIO => Multilayer}/PyImport.h | 2 +- GUI/coregui/mainwindow/PyImportAssistant.cpp | 2 +- Tests/Functional/Python/PyEmbedded/Tests.cpp | 4 +- .../ExportToPython/PythonFormattingTest.cpp | 2 +- auto/Wrap/doxygenBase.i | 77 +++++++ auto/Wrap/doxygenCore.i | 193 +++++------------- 15 files changed, 141 insertions(+), 166 deletions(-) rename {Core/PyIO => Base/Utils}/PyEmbeddedUtils.cpp (97%) rename {Core/PyIO => Base/Utils}/PyEmbeddedUtils.h (97%) rename Core/{PyIO/PythonFormatting.cpp => Instrument/PyFmt2.cpp} (98%) rename Core/{PyIO/PythonFormatting.h => Instrument/PyFmt2.h} (97%) rename Core/{PyIO => Multilayer}/PyImport.cpp (96%) rename Core/{PyIO => Multilayer}/PyImport.h (97%) diff --git a/Core/PyIO/PyEmbeddedUtils.cpp b/Base/Utils/PyEmbeddedUtils.cpp similarity index 97% rename from Core/PyIO/PyEmbeddedUtils.cpp rename to Base/Utils/PyEmbeddedUtils.cpp index 2331dd58d84..1c7088d3f90 100644 --- a/Core/PyIO/PyEmbeddedUtils.cpp +++ b/Base/Utils/PyEmbeddedUtils.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file Core/PyIO/PyEmbeddedUtils.cpp +//! @file Base/Utils/PyEmbeddedUtils.cpp //! @brief IOmplements various functions from PyEmbeddedUtils namespace //! //! @homepage http://www.bornagainproject.org @@ -14,10 +14,9 @@ #ifdef BORNAGAIN_PYTHON -#include "Core/PyIO/PyEmbeddedUtils.h" +#include "Base/Utils/PyEmbeddedUtils.h" #include "Base/Utils/PythonCore.h" #include "Base/Utils/SysUtils.h" -#include "Core/PyIO/PythonFormatting.h" #include <iostream> #include <sstream> #include <stdexcept> diff --git a/Core/PyIO/PyEmbeddedUtils.h b/Base/Utils/PyEmbeddedUtils.h similarity index 97% rename from Core/PyIO/PyEmbeddedUtils.h rename to Base/Utils/PyEmbeddedUtils.h index c29778da825..b612a0f2706 100644 --- a/Core/PyIO/PyEmbeddedUtils.h +++ b/Base/Utils/PyEmbeddedUtils.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file Core/PyIO/PyEmbeddedUtils.h +//! @file Base/Utils/PyEmbeddedUtils.h //! @brief Defines PyEmbeddedUtils namespace //! //! @homepage http://www.bornagainproject.org diff --git a/Core/Export/SampleToPython.cpp b/Core/Export/SampleToPython.cpp index 25753cd63e0..1953fe6423e 100644 --- a/Core/Export/SampleToPython.cpp +++ b/Core/Export/SampleToPython.cpp @@ -32,7 +32,7 @@ #include "Core/Particle/ParticleComposition.h" #include "Core/Particle/ParticleCoreShell.h" #include "Core/Particle/ParticleDistribution.h" -#include "Core/PyIO/PythonFormatting.h" +#include "Core/Instrument/PyFmt2.h" #include "Core/Scattering/IFormFactor.h" #include <iomanip> #include <map> diff --git a/Core/Export/SimulationToPython.cpp b/Core/Export/SimulationToPython.cpp index 10b84940893..588a1357bc1 100644 --- a/Core/Export/SimulationToPython.cpp +++ b/Core/Export/SimulationToPython.cpp @@ -29,7 +29,7 @@ #include "Core/Parametrization/ParameterUtils.h" #include "Base/Utils/PyFmt.h" #include "Core/Parametrization/PyFmtLimits.h" -#include "Core/PyIO/PythonFormatting.h" +#include "Core/Instrument/PyFmt2.h" #include "Core/Simulation/GISASSimulation.h" #include "Core/Simulation/OffSpecSimulation.h" #include "Core/Simulation/SpecularSimulation.h" diff --git a/Core/Instrument/AngularSpecScan.cpp b/Core/Instrument/AngularSpecScan.cpp index 52056f39fb7..5992cd3c801 100644 --- a/Core/Instrument/AngularSpecScan.cpp +++ b/Core/Instrument/AngularSpecScan.cpp @@ -21,7 +21,7 @@ #include "Core/Parametrization/ParameterSample.h" #include "Base/Utils/PyFmt.h" #include "Core/Parametrization/RangedDistributions.h" -#include "Core/PyIO/PythonFormatting.h" +#include "Core/Instrument/PyFmt2.h" #include "Fit/Tools/RealLimits.h" namespace diff --git a/Core/PyIO/PythonFormatting.cpp b/Core/Instrument/PyFmt2.cpp similarity index 98% rename from Core/PyIO/PythonFormatting.cpp rename to Core/Instrument/PyFmt2.cpp index 978616d8e41..cc631765fc8 100644 --- a/Core/PyIO/PythonFormatting.cpp +++ b/Core/Instrument/PyFmt2.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file Core/PyIO/PythonFormatting.cpp +//! @file Core/Instrument/PyFmt2.cpp //! @brief Implements functions from namespace pyfmt2. //! //! @homepage http://www.bornagainproject.org @@ -12,7 +12,7 @@ // // ************************************************************************** // -#include "Core/PyIO/PythonFormatting.h" +#include "Core/Instrument/PyFmt2.h" #include "Base/Const/MathConstants.h" #include "Base/Const/Units.h" #include "Base/Utils/Algorithms.h" diff --git a/Core/PyIO/PythonFormatting.h b/Core/Instrument/PyFmt2.h similarity index 97% rename from Core/PyIO/PythonFormatting.h rename to Core/Instrument/PyFmt2.h index c0897c498f8..857b125e7ff 100644 --- a/Core/PyIO/PythonFormatting.h +++ b/Core/Instrument/PyFmt2.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file Core/PyIO/PythonFormatting.h +//! @file Core/Instrument/PyFmt2.h //! @brief Defines namespace pyfmt2. //! //! @homepage http://www.bornagainproject.org diff --git a/Core/Instrument/QSpecScan.cpp b/Core/Instrument/QSpecScan.cpp index ef011cacfaf..916f2219fd5 100644 --- a/Core/Instrument/QSpecScan.cpp +++ b/Core/Instrument/QSpecScan.cpp @@ -20,7 +20,7 @@ #include "Core/Parametrization/ParameterSample.h" #include "Base/Utils/PyFmt.h" #include "Core/Parametrization/RangedDistributions.h" -#include "Core/PyIO/PythonFormatting.h" +#include "Core/Instrument/PyFmt2.h" #include "Fit/Tools/RealLimits.h" namespace diff --git a/Core/PyIO/PyImport.cpp b/Core/Multilayer/PyImport.cpp similarity index 96% rename from Core/PyIO/PyImport.cpp rename to Core/Multilayer/PyImport.cpp index 32e7d9a941a..2732487f770 100644 --- a/Core/PyIO/PyImport.cpp +++ b/Core/Multilayer/PyImport.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file Core/PyIO/PyImport.cpp +//! @file Core/Multilayer/PyImport.cpp //! @brief Implements PyImport namespace //! //! @homepage http://www.bornagainproject.org @@ -14,10 +14,10 @@ #ifdef BORNAGAIN_PYTHON -#include "Core/PyIO/PyImport.h" +#include "Core/Multilayer/PyImport.h" #include "Base/Utils/PythonCore.h" #include "Core/Multilayer/MultiLayer.h" -#include "Core/PyIO/PyEmbeddedUtils.h" +#include "Base/Utils/PyEmbeddedUtils.h" namespace { diff --git a/Core/PyIO/PyImport.h b/Core/Multilayer/PyImport.h similarity index 97% rename from Core/PyIO/PyImport.h rename to Core/Multilayer/PyImport.h index a2222bddf9a..cb67d597ffc 100644 --- a/Core/PyIO/PyImport.h +++ b/Core/Multilayer/PyImport.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file Core/PyIO/PyImport.h +//! @file Core/Multilayer/PyImport.h //! @brief Defines PyImport namespace //! //! @homepage http://www.bornagainproject.org diff --git a/GUI/coregui/mainwindow/PyImportAssistant.cpp b/GUI/coregui/mainwindow/PyImportAssistant.cpp index eb17fd5c863..11202ece0f8 100644 --- a/GUI/coregui/mainwindow/PyImportAssistant.cpp +++ b/GUI/coregui/mainwindow/PyImportAssistant.cpp @@ -18,7 +18,7 @@ #include "BABuild.h" #include "Base/Utils/SysUtils.h" #include "Core/Multilayer/MultiLayer.h" -#include "Core/PyIO/PyImport.h" +#include "Core/Multilayer/PyImport.h" #include "GUI/coregui/Models/GUIObjectBuilder.h" #include "GUI/coregui/Views/InfoWidgets/ComboSelectorDialog.h" #include "GUI/coregui/Views/InfoWidgets/DetailedMessageBox.h" diff --git a/Tests/Functional/Python/PyEmbedded/Tests.cpp b/Tests/Functional/Python/PyEmbedded/Tests.cpp index 9e1af07a32f..5bab1394b37 100644 --- a/Tests/Functional/Python/PyEmbedded/Tests.cpp +++ b/Tests/Functional/Python/PyEmbedded/Tests.cpp @@ -18,8 +18,8 @@ #include "Core/Export/ExportToPython.h" #include "Core/Multilayer/MultiLayer.h" #include "Base/Utils/PyFmt.h" -#include "Core/PyIO/PyEmbeddedUtils.h" -#include "Core/PyIO/PyImport.h" +#include "Base/Utils/PyEmbeddedUtils.h" +#include "Core/Multilayer/PyImport.h" #include "Core/StandardSamples/SampleBuilderFactory.h" #include "Tests/GTestWrapper/google_test.h" #include <iostream> diff --git a/Tests/UnitTests/Core/ExportToPython/PythonFormattingTest.cpp b/Tests/UnitTests/Core/ExportToPython/PythonFormattingTest.cpp index 432e402007a..86974d80671 100644 --- a/Tests/UnitTests/Core/ExportToPython/PythonFormattingTest.cpp +++ b/Tests/UnitTests/Core/ExportToPython/PythonFormattingTest.cpp @@ -1,4 +1,4 @@ -#include "Core/PyIO/PythonFormatting.h" +#include "Core/Instrument/PyFmt2.h" #include "Base/Const/Units.h" #include "Core/Axis/FixedBinAxis.h" #include "Core/Axis/PointwiseAxis.h" diff --git a/auto/Wrap/doxygenBase.i b/auto/Wrap/doxygenBase.i index 08dab96b028..a2d83ce0c03 100644 --- a/auto/Wrap/doxygenBase.i +++ b/auto/Wrap/doxygenBase.i @@ -834,6 +834,41 @@ convolution of two real vectors of equal size "; +// File: namespacePyEmbeddedUtils.xml +%feature("docstring") PyEmbeddedUtils::toString "std::string PyEmbeddedUtils::toString(PyObject *obj) + +Converts PyObject into string, if possible, or throws exception. +"; + +%feature("docstring") PyEmbeddedUtils::toVectorString "std::vector< std::string > PyEmbeddedUtils::toVectorString(PyObject *obj) + +Converts PyObject into vector of strings, if possible, or throws exception. +"; + +%feature("docstring") PyEmbeddedUtils::toString "std::string PyEmbeddedUtils::toString(char *c) + +Converts char to string. In the case of nullptr will return an empty string. +"; + +%feature("docstring") PyEmbeddedUtils::toString "std::string PyEmbeddedUtils::toString(wchar_t *c) +"; + +%feature("docstring") PyEmbeddedUtils::import_bornagain "void PyEmbeddedUtils::import_bornagain(const std::string &path=\"\") + +Imports BornAgain from given location. If path is empty, tries to rely on PYTHONPATH. +"; + +%feature("docstring") PyEmbeddedUtils::pythonRuntimeInfo "std::string PyEmbeddedUtils::pythonRuntimeInfo() + +Returns multi-line string representing PATH, PYTHONPATH, sys.path and other info. +"; + +%feature("docstring") PyEmbeddedUtils::pythonStackTrace "std::string PyEmbeddedUtils::pythonStackTrace() + +Returns string representing python stack trace. +"; + + // File: namespacepyfmt.xml %feature("docstring") pyfmt::scriptPreamble "std::string pyfmt::scriptPreamble() "; @@ -883,6 +918,36 @@ Returns a string of blanks with given width. By default the width equals standar "; +// File: namespacepyfmt2.xml +%feature("docstring") pyfmt2::representShape2D "std::string pyfmt2::representShape2D(const std::string &indent, const IShape2D *ishape, bool mask_value, std::function< std::string(double)> printValueFunc) + +Returns fixed Python code snippet that defines the function \"runSimulation\". +"; + +%feature("docstring") pyfmt2::valueTimesUnit "std::string pyfmt2::valueTimesUnit(const RealParameter *par) + +Returns parameter value, followed by its unit multiplicator (like \"* nm\"). +"; + +%feature("docstring") pyfmt2::argumentList "std::string pyfmt2::argumentList(const IParameterized *ip) + +Returns comma-separated list of parameter values, including unit multiplicator (like \"* nm\"). +"; + +%feature("docstring") pyfmt2::printDistribution "std::string pyfmt2::printDistribution(const IDistribution1D &par_distr, const std::string &units) + +Prints distribution with constructor parameters in given units. ba.DistributionGaussian(2.0*deg, 0.02*deg) +"; + +%feature("docstring") pyfmt2::printParameterDistribution "std::string pyfmt2::printParameterDistribution(const ParameterDistribution &par_distr, const std::string &distVarName, const std::string &units) +"; + +%feature("docstring") pyfmt2::printAxis "std::string pyfmt2::printAxis(const IAxis &axis, const std::string &units, size_t offset) + +Prints python-script definition for given axis. offset is used for alignment and indentation in multiple-line definitions +"; + + // File: namespaceSysUtils.xml %feature("docstring") SysUtils::getCurrentDateAndTime "std::string SysUtils::getCurrentDateAndTime() "; @@ -983,12 +1048,24 @@ Template function to create an integrator object // File: Precomputed_8h.xml +// File: PyEmbeddedUtils_8cpp.xml + + +// File: PyEmbeddedUtils_8h.xml + + // File: PyFmt_8cpp.xml // File: PyFmt_8h.xml +// File: PyFmt2_8cpp.xml + + +// File: PyFmt2_8h.xml + + // File: PyObject_8h.xml diff --git a/auto/Wrap/doxygenCore.i b/auto/Wrap/doxygenCore.i index 59d2b287fef..d83811fc3c1 100644 --- a/auto/Wrap/doxygenCore.i +++ b/auto/Wrap/doxygenCore.i @@ -16021,10 +16021,7 @@ C++ includes: ZLimits.h // File: namespace_0d270.xml -// File: namespace_0d284.xml - - -// File: namespace_0d315.xml +// File: namespace_0d286.xml // File: namespace_0d317.xml @@ -16033,34 +16030,34 @@ C++ includes: ZLimits.h // File: namespace_0d319.xml -// File: namespace_0d341.xml +// File: namespace_0d321.xml -// File: namespace_0d345.xml +// File: namespace_0d343.xml -// File: namespace_0d349.xml +// File: namespace_0d347.xml -// File: namespace_0d365.xml +// File: namespace_0d351.xml -// File: namespace_0d374.xml +// File: namespace_0d367.xml -// File: namespace_0d378.xml +// File: namespace_0d376.xml -// File: namespace_0d388.xml +// File: namespace_0d380.xml // File: namespace_0d390.xml -// File: namespace_0d396.xml +// File: namespace_0d392.xml -// File: namespace_0d398.xml +// File: namespace_0d394.xml // File: namespace_0d4.xml @@ -16078,70 +16075,73 @@ C++ includes: ZLimits.h // File: namespace_0d406.xml +// File: namespace_0d408.xml + + // File: namespace_0d410.xml -// File: namespace_0d412.xml +// File: namespace_0d414.xml -// File: namespace_0d422.xml +// File: namespace_0d416.xml -// File: namespace_0d435.xml +// File: namespace_0d426.xml -// File: namespace_0d444.xml +// File: namespace_0d439.xml -// File: namespace_0d450.xml +// File: namespace_0d448.xml -// File: namespace_0d466.xml +// File: namespace_0d452.xml -// File: namespace_0d492.xml +// File: namespace_0d468.xml -// File: namespace_0d499.xml +// File: namespace_0d495.xml -// File: namespace_0d501.xml +// File: namespace_0d497.xml -// File: namespace_0d509.xml +// File: namespace_0d505.xml -// File: namespace_0d521.xml +// File: namespace_0d517.xml -// File: namespace_0d544.xml +// File: namespace_0d540.xml -// File: namespace_0d552.xml +// File: namespace_0d548.xml -// File: namespace_0d558.xml +// File: namespace_0d554.xml -// File: namespace_0d560.xml +// File: namespace_0d556.xml -// File: namespace_0d571.xml +// File: namespace_0d567.xml -// File: namespace_0d583.xml +// File: namespace_0d579.xml -// File: namespace_0d589.xml +// File: namespace_0d585.xml -// File: namespace_0d593.xml +// File: namespace_0d589.xml -// File: namespace_0d611.xml +// File: namespace_0d607.xml -// File: namespace_0d630.xml +// File: namespace_0d626.xml // File: namespace_0d78.xml @@ -16560,72 +16560,7 @@ for importing 2D array of doubles from python into OutputData "; -// File: namespacePyEmbeddedUtils.xml -%feature("docstring") PyEmbeddedUtils::toString "std::string PyEmbeddedUtils::toString(PyObject *obj) - -Converts PyObject into string, if possible, or throws exception. -"; - -%feature("docstring") PyEmbeddedUtils::toVectorString "std::vector< std::string > PyEmbeddedUtils::toVectorString(PyObject *obj) - -Converts PyObject into vector of strings, if possible, or throws exception. -"; - -%feature("docstring") PyEmbeddedUtils::toString "std::string PyEmbeddedUtils::toString(char *c) - -Converts char to string. In the case of nullptr will return an empty string. -"; - -%feature("docstring") PyEmbeddedUtils::toString "std::string PyEmbeddedUtils::toString(wchar_t *c) -"; - -%feature("docstring") PyEmbeddedUtils::import_bornagain "void PyEmbeddedUtils::import_bornagain(const std::string &path=\"\") - -Imports BornAgain from given location. If path is empty, tries to rely on PYTHONPATH. -"; - -%feature("docstring") PyEmbeddedUtils::pythonRuntimeInfo "std::string PyEmbeddedUtils::pythonRuntimeInfo() - -Returns multi-line string representing PATH, PYTHONPATH, sys.path and other info. -"; - -%feature("docstring") PyEmbeddedUtils::pythonStackTrace "std::string PyEmbeddedUtils::pythonStackTrace() - -Returns string representing python stack trace. -"; - - // File: namespacepyfmt.xml -%feature("docstring") pyfmt::scriptPreamble "std::string pyfmt::scriptPreamble() -"; - -%feature("docstring") pyfmt::getSampleFunctionName "std::string pyfmt::getSampleFunctionName() -"; - -%feature("docstring") pyfmt::printBool "std::string pyfmt::printBool(double value) -"; - -%feature("docstring") pyfmt::printDouble "std::string pyfmt::printDouble(double input) -"; - -%feature("docstring") pyfmt::printNm "std::string pyfmt::printNm(double input) -"; - -%feature("docstring") pyfmt::printNm2 "std::string pyfmt::printNm2(double input) -"; - -%feature("docstring") pyfmt::printScientificDouble "std::string pyfmt::printScientificDouble(double input) -"; - -%feature("docstring") pyfmt::printDegrees "std::string pyfmt::printDegrees(double input) -"; - -%feature("docstring") pyfmt::printValue "std::string pyfmt::printValue(double value, const std::string &units) -"; - -%feature("docstring") pyfmt::printString "std::string pyfmt::printString(const std::string &value) -"; - %feature("docstring") pyfmt::printRealLimits "std::string pyfmt::printRealLimits(const RealLimits &limits, const std::string &units) "; @@ -16634,27 +16569,6 @@ Returns string representing python stack trace. Prints RealLimits in the form of argument (in the context of ParameterDistribution and similar). Default RealLimits will not be printed, any other will be printed as \", ba.RealLimits.limited(1*deg, 2*deg)\" "; -%feature("docstring") pyfmt::isSquare "bool pyfmt::isSquare(double length1, double length2, double angle) - -Prints ParameterDistribution. distVarName is a string representing IDistribution1D variable, e.g. \"distr_1\" - -ba.ParameterDistribution(\"/Particle/Height\", distr_1, 10, 0.0, ba.RealLimits.limited(1*nm,2*nm)) -"; - -%feature("docstring") pyfmt::isHexagonal "bool pyfmt::isHexagonal(double length1, double length2, double angle) -"; - -%feature("docstring") pyfmt::printKvector "std::string pyfmt::printKvector(const kvector_t value) -"; - -%feature("docstring") pyfmt::indent "std::string pyfmt::indent(size_t width) - -Returns a string of blanks with given width. By default the width equals standard offset in python files. -"; - -%feature("docstring") pyfmt::printInt "std::string pyfmt::printInt(int value) -"; - // File: namespacepyfmt2.xml %feature("docstring") pyfmt2::representShape2D "std::string pyfmt2::representShape2D(const std::string &indent, const IShape2D *ishape, bool mask_value, std::function< std::string(double)> printValueFunc) @@ -17852,6 +17766,12 @@ Generate z values (equidistant) for use in MaterialProfile. // File: PyArrayImportUtils_8h.xml +// File: PyFmt2_8cpp.xml + + +// File: PyFmt2_8h.xml + + // File: QSpecScan_8cpp.xml @@ -18244,6 +18164,12 @@ magnetization (in A/m) // File: MultiLayerUtils_8h.xml +// File: PyImport_8cpp.xml + + +// File: PyImport_8h.xml + + // File: RoughnessModels_8cpp.xml @@ -18426,12 +18352,6 @@ magnetization (in A/m) // File: ParameterUtils_8h.xml -// File: PyFmt_8cpp.xml - - -// File: PyFmt_8h.xml - - // File: PyFmtLimits_8cpp.xml @@ -18566,24 +18486,6 @@ Creates averaged material. Square refractive index of returned material is arith // File: SimulationElement_8h.xml -// File: PyEmbeddedUtils_8cpp.xml - - -// File: PyEmbeddedUtils_8h.xml - - -// File: PyImport_8cpp.xml - - -// File: PyImport_8h.xml - - -// File: PythonFormatting_8cpp.xml - - -// File: PythonFormatting_8h.xml - - // File: ILayerRTCoefficients_8h.xml @@ -19134,9 +19036,6 @@ Generate vertices of centered ellipse with given semi-axes at height z. // File: dir_359af669373d7705e93988ea0fa15f60.xml -// File: dir_437a42df1810106c8392af0ca05a14b2.xml - - // File: dir_8e60847f0ac26e3d8a13e8a06357123f.xml -- GitLab