OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
PyLine.cpp
Go to the documentation of this file.
1#include <Python.h>
2
3#include "Lines/Line.h"
7
8//using namespace boost::python;
9namespace PyOpal {
10namespace PyLineNS {
11
12template <>
13std::vector<PyOpalObjectNS::AttributeDef> PyOpalObjectNS::PyOpalObject<TBeamline<Element> >::attributes = {
14 {"L", "length", "", PyOpalObjectNS::DOUBLE},
15 {"ORIGIN", "origin", "", PyOpalObjectNS::STRING},
16 {"ORIENTATION", "orientation", "", PyOpalObjectNS::STRING},
17 {"X", "x", "", PyOpalObjectNS::DOUBLE},
18 {"Y", "y", "", PyOpalObjectNS::DOUBLE},
19 {"Z", "z", "", PyOpalObjectNS::DOUBLE},
20 {"THETA", "theta", "", PyOpalObjectNS::DOUBLE},
21 {"PHI", "phi", "", PyOpalObjectNS::DOUBLE},
22 {"PSI", "psi", "", PyOpalObjectNS::DOUBLE}
23};
24
25
29 PyLine aLine;
30 auto lineClass = aLine.make_class("Line");
31 // https://docs.python.org/3/library/collections.abc.html
32 lineClass
33 .def("__len__", &PyLine::getLength)
34 .def("__getitem__", &PyLine::getElement)
35 .def("__setitem__", &PyLine::setElement)
36 //.def("__delitem__", &PyLine::removeElement)
37 .def("append", &PyLine::append);
38 lineClass.def("register", &PyLine::registerObject);
39 aLine.addGetOpalElement(lineClass);
40
41 // line is dependent on opal_element; all line elements are stored as
42 // abstract opal_elements and we need boost to know how to do the
43 // translation
44 PyObject* mod = PyImport_ImportModule("pyopal.elements.opal_element");
45 if (mod == nullptr) {
46 PyErr_Print();
47 }
48}
49
50}
51}
PyLine_< TBeamline< FlaggedElmPtr > > PyLine
Definition: PyLine.h:16
void Initialise()
Definition: Globals.cpp:78
BOOST_PYTHON_MODULE(line)
Definition: PyLine.cpp:29
void registerObject()
int getLength() const
Definition: PyLine.h:64
void append(boost::python::object element)
void setElement(int i, boost::python::object element)
boost::python::object getElement(int i)