Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenFlipper-Free
OpenFlipper
Commits
b86bdb3c
Commit
b86bdb3c
authored
Feb 28, 2019
by
Jan Möbius
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added python conversion for DataType type
parent
cec408c3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
1 deletion
+87
-1
PythonInterpreter/PythonTypeConversions.hh
PythonInterpreter/PythonTypeConversions.hh
+87
-1
No files found.
PythonInterpreter/PythonTypeConversions.hh
View file @
b86bdb3c
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment