28#include "RNA_prototypes.hh"
68 if (!PyUnicode_Check(o)) {
69 PyErr_Format(PyExc_TypeError,
"expected a string (got %.200s)", Py_TYPE(o)->tp_name);
72 const char *gz_prop_id = PyUnicode_AsUTF8(o);
74 if (gz_prop ==
nullptr) {
75 PyErr_Format(PyExc_ValueError,
76 "Gizmo target property '%s.%s' not found!",
81 gizmo_with_target->
gz_prop = gz_prop;
94 const char *gz_prop_id = PyUnicode_AsUTF8(o);
95 PyErr_Format(PyExc_ValueError,
96 "Gizmo target property '%s.%s' has not been initialized, "
97 "Call \"target_set_prop\" first!",
112 if (!PyUnicode_Check(o)) {
113 PyErr_Format(PyExc_TypeError,
"expected a string (got %.200s)", Py_TYPE(o)->tp_name);
116 const char *gz_prop_id = PyUnicode_AsUTF8(o);
119 if (gz_prop_type ==
nullptr) {
120 PyErr_Format(PyExc_ValueError,
121 "Gizmo target property '%s.%s' not found!",
141#define BPY_GIZMO_FN_SLOT_LEN (BPY_GIZMO_FN_SLOT_RANGE_GET + 1)
152 const PyGILState_STATE gilstate = PyGILState_Ensure();
157 if (
ret ==
nullptr) {
162 float *value =
static_cast<float *
>(value_p);
164 if ((*value = PyFloat_AsDouble(
ret)) == -1.0f && PyErr_Occurred()) {
174 "Gizmo get callback: ") == -1)
181 PyErr_SetString(PyExc_AttributeError,
"internal error, unsupported type");
187 PyGILState_Release(gilstate);
195 PyGILState_Release(gilstate);
202 const PyGILState_STATE gilstate = PyGILState_Ensure();
207 PyObject *args = PyTuple_New(1);
211 const float *value =
static_cast<const float *
>(value_p);
214 py_value = PyFloat_FromDouble(*value);
219 if (py_value ==
nullptr) {
222 PyTuple_SET_ITEM(args, 0, py_value);
225 PyErr_SetString(PyExc_AttributeError,
"internal error, unsupported type");
230 if (
ret ==
nullptr) {
236 PyGILState_Release(gilstate);
244 PyGILState_Release(gilstate);
251 const PyGILState_STATE gilstate = PyGILState_Ensure();
257 if (
ret ==
nullptr) {
261 if (!PyTuple_Check(
ret)) {
262 PyErr_Format(PyExc_TypeError,
"Expected a tuple, not %.200s", Py_TYPE(
ret)->tp_name);
266 if (PyTuple_GET_SIZE(
ret) != 2) {
267 PyErr_Format(PyExc_TypeError,
"Expected a tuple of size 2, not %d", PyTuple_GET_SIZE(
ret));
273 for (
int i = 0; i < 2; i++) {
274 if (((range[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(
ret, i))) == -1.0f && PyErr_Occurred()) ==
283 memcpy(value_p, range,
sizeof(range));
286 PyErr_SetString(PyExc_AttributeError,
"internal error, unsupported type");
291 PyGILState_Release(gilstate);
299 PyGILState_Release(gilstate);
304 const PyGILState_STATE gilstate = PyGILState_Ensure();
310 Py_XDECREF(
data->fn_slots[i]);
312 PyGILState_Release(gilstate);
319 bpy_gizmo_target_set_handler_doc,
320 ".. method:: target_set_handler(target, get, set, range=None)\n"
322 " Assigns callbacks to a gizmos property.\n"
324 " :param target: Target property name.\n"
325 " :type target: str\n"
326 " :param get: Function that returns the value for this property "
327 "(single value or sequence).\n"
328 " :type get: Callable[[], float | Sequence[float]]\n"
329 " :param set: Function that takes a single value argument and applies it.\n"
330 " :type set: Callable[[tuple[float, ...]], Any]\n"
331 " :param range: Function that returns a (min, max) tuple for gizmos that use a range. "
332 "The returned value is not used.\n"
333 " :type range: Callable[[], tuple[float, float]] | None\n");
347 static const char *
const _keywords[] = {
"self",
"target",
"get",
"set",
"range",
nullptr};
348 static _PyArg_Parser _parser = {
355 ":target_set_handler",
364 if (!_PyArg_ParseTupleAndKeywordsFast(args,
369 ¶ms.gz_with_target_type.gz,
372 ¶ms.gz_with_target_type,
381 gz = params.gz_with_target_type.gz;
382 gz_prop_type = params.gz_with_target_type.gz_prop_type;
389 const int slots_required = 2;
390 const int slots_start = 2;
392 if (params.py_fn_slots[i] ==
nullptr) {
393 if (i < slots_required) {
394 PyErr_Format(PyExc_ValueError,
"Argument '%s' not given", _keywords[slots_start + i]);
398 else if (!PyCallable_Check(params.py_fn_slots[i])) {
399 PyErr_Format(PyExc_ValueError,
"Argument '%s' not callable", _keywords[slots_start + i]);
408 data->fn_slots[i] = params.py_fn_slots[i];
409 Py_XINCREF(params.py_fn_slots[i]);
436 bpy_gizmo_target_get_value_doc,
437 ".. method:: target_get_value(target)\n"
439 " Get the value of this target property.\n"
441 " :param target: Target property name.\n"
442 " :type target: str\n"
443 " :return: The value of the target property as a value or array based on the target type.\n"
444 " :rtype: float | tuple[float, ...]\n");
453 static const char *
const _keywords[] = {
"self",
"target",
nullptr};
454 static _PyArg_Parser _parser = {
466 if (!_PyArg_ParseTupleAndKeywordsFast(args,
471 ¶ms.gz_with_target.gz,
474 ¶ms.gz_with_target))
479 gz = params.gz_with_target.gz;
480 gz_prop = params.gz_with_target.gz_prop;
485 if (array_len != 0) {
492 return PyFloat_FromDouble(value);
495 PyErr_SetString(PyExc_RuntimeError,
"Not yet supported type");
506 bpy_gizmo_target_set_value_doc,
507 ".. method:: target_set_value(target)\n"
509 " Set the value of this target property.\n"
511 " :param target: Target property name.\n"
512 " :type target: str\n");
523 static const char *
const _keywords[] = {
"self",
"target",
"value",
nullptr};
524 static _PyArg_Parser _parser = {
537 if (!_PyArg_ParseTupleAndKeywordsFast(args,
542 ¶ms.gz_with_target.gz,
545 ¶ms.gz_with_target,
552 gz = params.gz_with_target.gz;
553 gz_prop = params.gz_with_target.gz_prop;
558 if (array_len != 0) {
565 "Gizmo target property array: ") == -1)
573 if ((value = PyFloat_AsDouble(params.value)) == -1.0f && PyErr_Occurred()) {
581 PyErr_SetString(PyExc_RuntimeError,
"Not yet supported type");
592 bpy_gizmo_target_get_range_doc,
593 ".. method:: target_get_range(target)\n"
595 " Get the range for this target property.\n"
597 " :param target: Target property name.\n"
598 " :type target: str\n"
599 " :return: The range of this property (min, max).\n"
600 " :rtype: tuple[float, float]\n");
609 static const char *
const _keywords[] = {
"self",
"target",
nullptr};
610 static _PyArg_Parser _parser = {
621 if (!_PyArg_ParseTupleAndKeywordsFast(args,
626 ¶ms.gz_with_target.gz,
629 ¶ms.gz_with_target))
634 gz = params.gz_with_target.gz;
635 gz_prop = params.gz_with_target.gz_prop;
644 PyErr_SetString(PyExc_RuntimeError,
"Not yet supported type");
664# pragma clang diagnostic push
665# pragma clang diagnostic ignored "-Wcast-function-type"
667# pragma GCC diagnostic push
668# pragma GCC diagnostic ignored "-Wcast-function-type"
672 static PyMethodDef method_def_array[] = {
674 {
"target_set_handler",
676 METH_VARARGS | METH_KEYWORDS,
677 bpy_gizmo_target_set_handler_doc},
681 METH_VARARGS | METH_KEYWORDS,
682 bpy_gizmo_target_get_value_doc},
685 METH_VARARGS | METH_KEYWORDS,
686 bpy_gizmo_target_set_value_doc},
689 METH_VARARGS | METH_KEYWORDS,
690 bpy_gizmo_target_get_range_doc},
696# pragma clang diagnostic pop
698# pragma GCC diagnostic pop
702 for (
int i = 0; i <
ARRAY_SIZE(method_def_array); i++) {
703 PyMethodDef *m = &method_def_array[i];
704 PyObject *func = PyCFunction_New(m,
nullptr);
705 PyObject *func_inst = PyInstanceMethod_New(func);
707 char name_prefix[128];
708 PyOS_snprintf(name_prefix,
sizeof(name_prefix),
"_rna_gizmo_%s", m->ml_name);
710 PyModule_AddObject(mod_par, name_prefix, func_inst);
#define BLI_array_alloca(arr, realsize)
Read Blender memory allocation and freeing.
#define BPy_StructRNA_Check(v)
#define BPY_GIZMO_FN_SLOT_LEN
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ BPY_GIZMO_FN_SLOT_RANGE_GET
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
bool BPY_rna_gizmo_module(PyObject *mod_par)
void WM_gizmo_target_property_float_get_array(const wmGizmo *gz, wmGizmoProperty *gz_prop, float *value)
const wmGizmoPropertyType * WM_gizmotype_target_property_find(const wmGizmoType *gzt, const char *idname)
void WM_gizmo_target_property_def_func_ptr(wmGizmo *gz, const wmGizmoPropertyType *gz_prop_type, const wmGizmoPropertyFnParams *params)
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static int py_rna_gizmo_target_id_parse_and_ensure_is_valid(PyObject *o, void *p)
int PyC_AsArray(void *array, const size_t array_item_size, PyObject *value, const Py_ssize_t length, const PyTypeObject *type, const char *error_prefix)
static void py_rna_gizmo_handler_set_cb(const wmGizmo *, wmGizmoProperty *gz_prop, const void *value_p)
static int py_rna_gizmo_parse(PyObject *o, void *p)
static void py_rna_gizmo_handler_range_get_cb(const wmGizmo *, wmGizmoProperty *gz_prop, void *value_p)
void WM_gizmo_target_property_float_set(bContext *C, const wmGizmo *gz, wmGizmoProperty *gz_prop, const float value)
static void py_rna_gizmo_handler_get_cb(const wmGizmo *, wmGizmoProperty *gz_prop, void *value_p)
void WM_gizmo_target_property_float_set_array(bContext *C, const wmGizmo *gz, wmGizmoProperty *gz_prop, const float *value)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
struct bContext * BPY_context_get()
BMesh const char void * data
static void py_rna_gizmo_handler_free_cb(const wmGizmo *, wmGizmoProperty *gz_prop)
wmGizmoProperty * WM_gizmo_target_property_find(wmGizmo *gz, const char *idname)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
bool WM_gizmo_target_property_is_valid(const wmGizmoProperty *gz_prop)
static PyObject * bpy_gizmo_target_set_handler(PyObject *, PyObject *args, PyObject *kw)
static PyObject * bpy_gizmo_target_get_value(PyObject *, PyObject *args, PyObject *kw)
static int py_rna_gizmo_target_id_parse(PyObject *o, void *p)
PyObject * PyC_Tuple_PackArray_F32(const float *array, uint len)
static PyObject * bpy_gizmo_target_get_range(PyObject *, PyObject *args, PyObject *kw)
static int py_rna_gizmo_target_type_id_parse(PyObject *o, void *p)
static PyObject * bpy_gizmo_target_set_value(PyObject *, PyObject *args, PyObject *kw)
int WM_gizmo_target_property_array_length(const wmGizmo *, wmGizmoProperty *gz_prop)
float WM_gizmo_target_property_float_get(const wmGizmo *gz, wmGizmoProperty *gz_prop)
bool WM_gizmo_target_property_float_range_get(const wmGizmo *gz, wmGizmoProperty *gz_prop, float range[2])
header-only compatibility defines.
PyObject * fn_slots[BPY_GIZMO_FN_SLOT_LEN]
const wmGizmoPropertyType * gz_prop_type
wmGizmoProperty * gz_prop
wmGizmoPropertyFnSet value_set_fn
wmGizmoPropertyFnRangeGet range_get_fn
wmGizmoPropertyFnGet value_get_fn
wmGizmoPropertyFnFree free_fn
const wmGizmoPropertyType * type
struct blender::wmGizmoProperty::@216011055122204070127377170176223170047224321165 custom_func