diff --git a/Device/Beam/Beam.h b/Device/Beam/Beam.h index c18442f7f9a92e8c44a1d018ce5aaaa0f00cc5c4..f20fb8a8c8a4e9541b2fd9631c4842799d8d19ff 100644 --- a/Device/Beam/Beam.h +++ b/Device/Beam/Beam.h @@ -15,7 +15,7 @@ #ifndef BORNAGAIN_DEVICE_BEAM_BEAM_H #define BORNAGAIN_DEVICE_BEAM_BEAM_H -// #include "Base/Types/ICloneable.h" +#include "Base/Types/ICloneable.h" #include "Param/Node/INode.h" #include <heinz/Vectors3D.h> @@ -24,20 +24,20 @@ class SpinMatrix; //! An incident neutron or x-ray beam. -class Beam : /*public ICloneable,*/ public INode { +class Beam : public ICloneable, public INode { public: Beam(double intensity, double wavelength, double alpha, double phi = 0); ~Beam() override; std::string className() const final { return "Beam"; } + Beam* clone() const override; + //... Setters: void setFootprint(const IFootprint* shape_factor); void setPolarization(R3 polarization); #ifndef SWIG - Beam* clone() const /*override*/; - //... Setters: void setIntensity(double intensity); void setWavelength(double wavelength); diff --git a/GUI/Model/Beam/SourceItems.cpp b/GUI/Model/Beam/SourceItems.cpp index 927f8c4119ffadb64c4d63cc5ee3018c7389959a..b764ccbd39adbc3c1a2553cd882e2af83f4049c8 100644 --- a/GUI/Model/Beam/SourceItems.cpp +++ b/GUI/Model/Beam/SourceItems.cpp @@ -269,8 +269,7 @@ std::unique_ptr<Beam> BeamItem::createBeam() const double inclination_angle = Units::deg2rad(getInclinationAngle()); double azimuthal_angle = Units::deg2rad(azimuthalAngle()); - auto result = - std::make_unique<Beam>(Beam(intensity(), lambda, inclination_angle, azimuthal_angle)); + auto result = std::make_unique<Beam>(intensity(), lambda, inclination_angle, azimuthal_angle); result->setFootprint(m_footprint.currentItem()->createFootprint().get()); return result; } diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py index 3703418cccb74f77111307d55cc521729ecdeaae..51e4eb92c53430c5ebebba3987c29375af208333 100644 --- a/auto/Wrap/libBornAgainDevice.py +++ b/auto/Wrap/libBornAgainDevice.py @@ -2181,7 +2181,7 @@ class Datafield(object): # Register Datafield in _libBornAgainDevice: _libBornAgainDevice.Datafield_swigregister(Datafield) -class Beam(libBornAgainParam.INode): +class Beam(libBornAgainBase.ICloneable, libBornAgainParam.INode): r"""Proxy of C++ Beam class.""" thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") @@ -2196,6 +2196,10 @@ class Beam(libBornAgainParam.INode): r"""className(Beam self) -> std::string""" return _libBornAgainDevice.Beam_className(self) + def clone(self): + r"""clone(Beam self) -> Beam""" + return _libBornAgainDevice.Beam_clone(self) + def setFootprint(self, shape_factor): r"""setFootprint(Beam self, IFootprint shape_factor)""" return _libBornAgainDevice.Beam_setFootprint(self, shape_factor) diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp index 9f3c7e9a8d28e1b343c2d65a0c96c8cf0a5c7314..1b1c75808efb17fac61c1bc7117ee7a828301581 100644 --- a/auto/Wrap/libBornAgainDevice_wrap.cpp +++ b/auto/Wrap/libBornAgainDevice_wrap.cpp @@ -31102,6 +31102,39 @@ fail: } +SWIGINTERN PyObject *_wrap_Beam_clone(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + Beam *arg1 = (Beam *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + Beam *result = 0 ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_Beam, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Beam_clone" "', argument " "1"" of type '" "Beam const *""'"); + } + arg1 = reinterpret_cast< Beam * >(argp1); + { + try { + result = (Beam *)((Beam const *)arg1)->clone(); + } catch (const std::exception& ex) { + // message shown in the Python interpreter + const std::string msg { + "BornAgain C++ Exception: " + std::string(ex.what()) + }; + SWIG_exception(SWIG_RuntimeError, msg.c_str()); + } + } + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Beam, 0 | 0 ); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_Beam_setFootprint(PyObject *self, PyObject *args) { PyObject *resultobj = 0; Beam *arg1 = (Beam *) 0 ; @@ -40971,6 +41004,7 @@ static PyMethodDef SwigMethods[] = { { "new_Beam", _wrap_new_Beam, METH_VARARGS, "Beam(double intensity, double wavelength, double alpha, double phi=0)"}, { "delete_Beam", _wrap_delete_Beam, METH_O, "delete_Beam(Beam self)"}, { "Beam_className", _wrap_Beam_className, METH_O, "Beam_className(Beam self) -> std::string"}, + { "Beam_clone", _wrap_Beam_clone, METH_O, "Beam_clone(Beam self) -> Beam"}, { "Beam_setFootprint", _wrap_Beam_setFootprint, METH_VARARGS, "Beam_setFootprint(Beam self, IFootprint shape_factor)"}, { "Beam_setPolarization", _wrap_Beam_setPolarization, METH_VARARGS, "Beam_setPolarization(Beam self, R3 polarization)"}, { "Beam_swigregister", Beam_swigregister, METH_O, NULL}, @@ -41223,6 +41257,9 @@ static PyMethodDef SwigMethods[] = { /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ +static void *_p_BeamTo_p_ICloneable(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((ICloneable *) ((Beam *) x)); +} static void *_p_EllipseTo_p_ICloneable(void *x, int *SWIGUNUSEDPARM(newmemory)) { return (void *)((ICloneable *) (IShape2D *) ((Ellipse *) x)); } @@ -41528,7 +41565,7 @@ static swig_cast_info _swigc__p_FootprintGauss[] = { {&_swigt__p_FootprintGauss static swig_cast_info _swigc__p_FootprintSquare[] = { {&_swigt__p_FootprintSquare, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_Frame[] = { {&_swigt__p_Frame, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_HorizontalLine[] = { {&_swigt__p_HorizontalLine, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_ICloneable[] = { {&_swigt__p_ICloneable, 0, 0, 0}, {&_swigt__p_Ellipse, _p_EllipseTo_p_ICloneable, 0, 0}, {&_swigt__p_FlatDetector, _p_FlatDetectorTo_p_ICloneable, 0, 0}, {&_swigt__p_FootprintGauss, _p_FootprintGaussTo_p_ICloneable, 0, 0}, {&_swigt__p_FootprintSquare, _p_FootprintSquareTo_p_ICloneable, 0, 0}, {&_swigt__p_HorizontalLine, _p_HorizontalLineTo_p_ICloneable, 0, 0}, {&_swigt__p_IDetector, _p_IDetectorTo_p_ICloneable, 0, 0}, {&_swigt__p_IDetectorResolution, _p_IDetectorResolutionTo_p_ICloneable, 0, 0}, {&_swigt__p_IFootprint, _p_IFootprintTo_p_ICloneable, 0, 0}, {&_swigt__p_IResolutionFunction2D, _p_IResolutionFunction2DTo_p_ICloneable, 0, 0}, {&_swigt__p_IShape2D, _p_IShape2DTo_p_ICloneable, 0, 0}, {&_swigt__p_Line, _p_LineTo_p_ICloneable, 0, 0}, {&_swigt__p_Polygon, _p_PolygonTo_p_ICloneable, 0, 0}, {&_swigt__p_Rectangle, _p_RectangleTo_p_ICloneable, 0, 0}, {&_swigt__p_ResolutionFunction2DGaussian, _p_ResolutionFunction2DGaussianTo_p_ICloneable, 0, 0}, {&_swigt__p_SphericalDetector, _p_SphericalDetectorTo_p_ICloneable, 0, 0}, {&_swigt__p_VerticalLine, _p_VerticalLineTo_p_ICloneable, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_ICloneable[] = { {&_swigt__p_ICloneable, 0, 0, 0}, {&_swigt__p_Beam, _p_BeamTo_p_ICloneable, 0, 0}, {&_swigt__p_Ellipse, _p_EllipseTo_p_ICloneable, 0, 0}, {&_swigt__p_FlatDetector, _p_FlatDetectorTo_p_ICloneable, 0, 0}, {&_swigt__p_FootprintGauss, _p_FootprintGaussTo_p_ICloneable, 0, 0}, {&_swigt__p_FootprintSquare, _p_FootprintSquareTo_p_ICloneable, 0, 0}, {&_swigt__p_HorizontalLine, _p_HorizontalLineTo_p_ICloneable, 0, 0}, {&_swigt__p_IDetector, _p_IDetectorTo_p_ICloneable, 0, 0}, {&_swigt__p_IDetectorResolution, _p_IDetectorResolutionTo_p_ICloneable, 0, 0}, {&_swigt__p_IFootprint, _p_IFootprintTo_p_ICloneable, 0, 0}, {&_swigt__p_IResolutionFunction2D, _p_IResolutionFunction2DTo_p_ICloneable, 0, 0}, {&_swigt__p_IShape2D, _p_IShape2DTo_p_ICloneable, 0, 0}, {&_swigt__p_Line, _p_LineTo_p_ICloneable, 0, 0}, {&_swigt__p_Polygon, _p_PolygonTo_p_ICloneable, 0, 0}, {&_swigt__p_Rectangle, _p_RectangleTo_p_ICloneable, 0, 0}, {&_swigt__p_ResolutionFunction2DGaussian, _p_ResolutionFunction2DGaussianTo_p_ICloneable, 0, 0}, {&_swigt__p_SphericalDetector, _p_SphericalDetectorTo_p_ICloneable, 0, 0}, {&_swigt__p_VerticalLine, _p_VerticalLineTo_p_ICloneable, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_IDetector[] = { {&_swigt__p_IDetector, 0, 0, 0}, {&_swigt__p_FlatDetector, _p_FlatDetectorTo_p_IDetector, 0, 0}, {&_swigt__p_SphericalDetector, _p_SphericalDetectorTo_p_IDetector, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_IDetectorResolution[] = { {&_swigt__p_IDetectorResolution, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_IFootprint[] = { {&_swigt__p_IFootprint, 0, 0, 0}, {&_swigt__p_FootprintGauss, _p_FootprintGaussTo_p_IFootprint, 0, 0}, {&_swigt__p_FootprintSquare, _p_FootprintSquareTo_p_IFootprint, 0, 0},{0, 0, 0, 0}};