4#include <structmember.h>
9#include <boost/python.hpp>
10#include <boost/noncopyable.hpp>
11#include <boost/mpl/front.hpp>
47namespace PyElementNS {
50template <
class C>
class PyElement;
51template <
class C>
struct PyElementGetProperty;
52template <
class C>
struct PyElementSetProperty;
134 boost::python::class_<PyC>
make_class(
const char* className);
144 template <
class ValueType>
150 template <
class ValueType>
181 boost::python::object
getFieldValue(
double x,
double y,
double z,
double t)
const;
221 template <
class ArgumentPackage>
222 PyObject*
postcall(ArgumentPackage
const&, PyObject* result);
252 template <
class ArgumentPackage>
253 PyObject*
postcall(ArgumentPackage
const& args, PyObject* result);
283 ElementBase* element = element_m->getElement()->removeWrappers();
285 if (component == NULL) {
287 "Failed to deduce Component from ElementBase.");
289 bool outOfBounds = component->
apply(
R, P, t, E, B);
290 return boost::python::make_tuple(outOfBounds,
299 "Element was not initialised");
301 Attribute* attribute = element_m->findAttribute(opalName);
302 if (attribute == NULL) {
304 "Failed to parse attribute "+opalName);
314 pyvalue = PyFloat_FromDouble(value);
317 pyvalue = PyLong_FromDouble(value);
328 "Element was not initialised");
330 Attribute* attribute = element_m->findAttribute(opalName);
331 if (attribute == NULL) {
333 "Failed to parse attribute "+opalName);
336 double value = PyFloat_AsDouble(pyvalue);
339 double value = PyLong_AsDouble(pyvalue);
352 if (attribute == NULL) {
365 boost::python::docstring_options docop(
true,
true,
false);
366 auto pyclass = boost::python::class_<PyC>(className);
367 addAttributes(pyclass);
376 std::string docString = getDocString(*iter);
377 std::string pyname = iter->pyName_m.c_str();
378 if (iter->type_m ==
DOUBLE) {
379 pyclass.add_property(pyname.c_str(),
380 boost::python::make_function(&PyC::dummyGet<double>, getProp),
381 boost::python::make_function(&PyC::dummySet<double>, setProp),
384 }
else if (iter->type_m ==
INT) {
385 pyclass.add_property(pyname.c_str(),
386 boost::python::make_function(&PyC::dummyGet<int>, getProp),
387 boost::python::make_function(&PyC::dummySet<int>, setProp),
392 pyclass.def(
"get_opal_element", &PyC::getPyOpalElement);
393 if (hasGetFieldValue) {
402 if (element == NULL) {
404 "Failed to cast to OpalElement");
411 std::shared_ptr<OpalElement> elementPtr = std::dynamic_pointer_cast<OpalElement, C>(element_m);
412 if (elementPtr.get() == NULL) {
413 throw OpalException(
"PyElement<C>::getPyOpalElement",
"Wrapped object was not an OpalElement");
416 boost::python::object pyelement(element);
423template <
class ArgumentPackage>
426 result = element_m->getAttribute(
DOUBLE, opalName_m);
436template <
class ArgumentPackage>
440 if (!PyArg_ParseTuple(args,
"OO", &pyElement, &value)) {
444 element_m->setAttribute(
DOUBLE, opalName_m, value);
std::map< AttributeType, std::string > attributeName
boost::python::object getFieldValue(PyOpalObjectNS::PyOpalObject< C > &pyobject, double x, double y, double z, double t)
double getReal(const Attribute &attr)
Return real value.
void setReal(Attribute &attr, double val)
Set real value.
std::string::iterator iterator
boost::function< boost::tuple< double, bool >(arguments_t)> type
PyElement(std::shared_ptr< C > element)
static std::string classDocstring
void dummySet(ValueType test)
PyObject * getAttribute(AttributeType type, std::string opalName) const
static std::vector< AttributeDef > attributes
static bool hasGetFieldValue
std::shared_ptr< C > element_m
ValueType dummyGet() const
std::string getDocString(AttributeDef &def)
void setAttribute(AttributeType type, std::string opalName, PyObject *value)
OpalElement * getOpalElement()
static bool converterRegistered
boost::python::object getFieldValue(double x, double y, double z, double t) const
boost::python::class_< PyC > make_class(const char *className)
void addAttributes(boost::python::class_< PyC > &pyclass)
boost::python::object getPyOpalElement()
PyObject * postcall(ArgumentPackage const &, PyObject *result)
static const PyElement< C > * element_m
static void setElement(const PyElement< C > *element)
PyElementGetProperty(AttributeType type, std::string opalName)
PyElementSetProperty(AttributeType type, std::string opalName)
PyObject * postcall(ArgumentPackage const &args, PyObject *result)
static void setElement(PyElement< C > *element)
static PyElement< C > * element_m
A representation of an Object attribute.
const std::string & getHelp() const
Return the help string.
Interface for a single beam element.
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B)
The base class for all OPAL exceptions.