Commit b86bdb3c authored by Jan Möbius's avatar Jan Möbius

Added python conversion for DataType type

parent cec408c3
......@@ -461,7 +461,7 @@ namespace pybind11 { namespace detail {
*/
static handle cast(IdList src, return_value_policy /* policy */, handle parent ) {
// Create numpy array
py::array a(1, src.data());
py::array a(src.size(), src.data());
return a.release();
}
};
......@@ -570,3 +570,89 @@ namespace pybind11 { namespace detail {
};
}} // namespace pybind11::detail
/** \page python_scripting_DaraType_type DataType data type used for python scripting
*
* The DataType type describing objects in OpenFlipper is mapped to python.
*
* The integrated conversion can map the C++ DataType type to and from a String. *
* \code
* core.objectUpdated(5,"Selection;Geometry")
* \endcode
*
* Some examples for possible data types are:
* - All
* - Group
* - BSplineCurve
* - BSplineSurface
* - Coordsys
* - Light
* - TriangleMesh
* - PolyMesh
* - HexahedralMesh
* - PolyhedralMesh
* - TetrahedralMesh
* - Plane
* - PolyLine
* - PolyLineCollection
* - QtWidget
* - Skeleton
* - Sphere
* - SplatCloud
*
* Other plugins might have implemented additional data types, which will be automatically mapped.
*/
namespace pybind11 { namespace detail {
template <> struct type_caster<DataType> {
public:
/**
* This macro establishes the name 'DataType' in
* function signatures and declares a local variable
* 'value' of type DataType
*/
PYBIND11_TYPE_CASTER(DataType, _("DataType"));
/**
* Conversion part 1 (Python->C++): convert a PyObject into a DataType
* instance or return false upon failure. The second argument
* indicates whether implicit conversions should be applied.
*/
bool load(handle src, bool ) {
/* Extract PyObject from handle */
PyObject *source = src.ptr();
if (!PyUnicode_Check(source))
return false;
Py_ssize_t size;
const char *ptr = PyUnicode_AsUTF8AndSize(source, &size);
if (!ptr) {
return NULL;
}
QString typeString = QString::fromUtf8(ptr, size);
value = typeId(typeString);
/* Ensure return code was OK (to avoid out-of-range errors etc) */
return ( !PyErr_Occurred() );
}
/**
* Conversion part 2 (C++ -> Python): convert an DataType instance into
* a Python object. The second and third arguments are used to
* indicate the return value policy and parent object (for
* ``return_value_policy::reference_internal``) and are generally
* ignored by implicit casters.
*/
static handle cast(DataType src, return_value_policy /* policy */, handle /* parent */) {
return (PyUnicode_FromString( typeName(src).toUtf8().data()) );
}
};
}} // namespace pybind11::detail
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment