2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-11-29 13:36:08 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-11-29 13:36:08 +00:00
|
|
|
*
|
|
|
|
* Contributor(s): Campbell Barton
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
2011-02-27 20:10:08 +00:00
|
|
|
|
|
|
|
/** \file blender/python/intern/bpy_rna.h
|
|
|
|
* \ingroup pythonintern
|
|
|
|
*/
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#ifndef __BPY_RNA_H__
|
|
|
|
#define __BPY_RNA_H__
|
2008-11-29 13:36:08 +00:00
|
|
|
|
2011-03-02 04:51:43 +00:00
|
|
|
/* --- bpy build options --- */
|
2011-03-03 12:00:35 +00:00
|
|
|
#ifdef WITH_PYTHON_SAFETY
|
|
|
|
|
2011-02-23 13:43:45 +00:00
|
|
|
/* play it safe and keep optional for now, need to test further now this affects looping on 10000's of verts for eg. */
|
2011-03-03 12:00:35 +00:00
|
|
|
#define USE_WEAKREFS
|
2011-02-23 13:43:45 +00:00
|
|
|
|
2011-03-01 14:53:26 +00:00
|
|
|
/* method to invalidate removed py data, XXX, slow to remove objects, otherwise no overhead */
|
2011-03-03 12:00:35 +00:00
|
|
|
/* #define USE_PYRNA_INVALIDATE_GC */
|
2011-03-01 14:53:26 +00:00
|
|
|
|
|
|
|
/* different method */
|
2011-03-03 12:00:35 +00:00
|
|
|
#define USE_PYRNA_INVALIDATE_WEAKREF
|
2011-03-01 14:53:26 +00:00
|
|
|
|
2011-03-03 09:16:06 +00:00
|
|
|
/* support for inter references, currently only needed for corner case */
|
2011-03-03 12:00:35 +00:00
|
|
|
#define USE_PYRNA_STRUCT_REFERENCE
|
2011-03-03 09:16:06 +00:00
|
|
|
|
2011-03-03 12:00:35 +00:00
|
|
|
#else /* WITH_PYTHON_SAFETY */
|
|
|
|
|
|
|
|
/* default, no defines! */
|
|
|
|
|
|
|
|
#endif /* !WITH_PYTHON_SAFETY */
|
|
|
|
|
|
|
|
|
2011-03-01 14:53:26 +00:00
|
|
|
/* sanity checks on above defs */
|
|
|
|
#if defined(USE_PYRNA_INVALIDATE_WEAKREF) && !defined(USE_WEAKREFS)
|
|
|
|
#define USE_WEAKREFS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_PYRNA_INVALIDATE_GC) && defined(USE_PYRNA_INVALIDATE_WEAKREF)
|
|
|
|
#error "Only 1 reference check method at a time!"
|
|
|
|
#endif
|
2011-08-05 16:29:38 +00:00
|
|
|
|
|
|
|
/* only used by operator introspection get_rna(), this is only used for doc gen
|
|
|
|
* so prefer the leak to the memory bloat for now. */
|
|
|
|
// #define PYRNA_FREE_SUPPORT
|
|
|
|
|
2011-09-30 07:47:45 +00:00
|
|
|
/* use real collection iterators rather than faking with a list
|
|
|
|
* this is needed so enums can be iterated over without crashing,
|
|
|
|
* since finishing the iteration frees temp allocated enums */
|
|
|
|
#define USE_PYRNA_ITER
|
|
|
|
|
2011-03-02 04:51:43 +00:00
|
|
|
/* --- end bpy build options --- */
|
|
|
|
|
2011-04-03 10:04:16 +00:00
|
|
|
struct ID;
|
2011-03-02 04:51:43 +00:00
|
|
|
|
|
|
|
extern PyTypeObject pyrna_struct_meta_idprop_Type;
|
|
|
|
extern PyTypeObject pyrna_struct_Type;
|
|
|
|
extern PyTypeObject pyrna_prop_Type;
|
|
|
|
extern PyTypeObject pyrna_prop_array_Type;
|
|
|
|
extern PyTypeObject pyrna_prop_collection_Type;
|
2011-08-05 16:21:37 +00:00
|
|
|
extern PyTypeObject pyrna_func_Type;
|
2011-03-02 04:51:43 +00:00
|
|
|
|
|
|
|
#define BPy_StructRNA_Check(v) (PyObject_TypeCheck(v, &pyrna_struct_Type))
|
|
|
|
#define BPy_StructRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_struct_Type)
|
|
|
|
#define BPy_PropertyRNA_Check(v) (PyObject_TypeCheck(v, &pyrna_prop_Type))
|
|
|
|
#define BPy_PropertyRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_prop_Type)
|
|
|
|
|
2012-02-26 23:59:08 +00:00
|
|
|
#define PYRNA_STRUCT_CHECK_OBJ(obj) if (UNLIKELY(pyrna_struct_validity_check(obj) == -1)) { return NULL; } (void)0
|
|
|
|
#define PYRNA_STRUCT_CHECK_INT(obj) if (UNLIKELY(pyrna_struct_validity_check(obj) == -1)) { return -1; } (void)0
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2012-02-26 23:59:08 +00:00
|
|
|
#define PYRNA_PROP_CHECK_OBJ(obj) if (UNLIKELY(pyrna_prop_validity_check(obj) == -1)) { return NULL; } (void)0
|
|
|
|
#define PYRNA_PROP_CHECK_INT(obj) if (UNLIKELY(pyrna_prop_validity_check(obj) == -1)) { return -1; } (void)0
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2012-02-26 23:59:08 +00:00
|
|
|
#define PYRNA_STRUCT_IS_VALID(pysrna) (LIKELY(((BPy_StructRNA *)(pysrna))->ptr.type != NULL))
|
|
|
|
#define PYRNA_PROP_IS_VALID(pysrna) (LIKELY(((BPy_PropertyRNA *)(pysrna))->ptr.type != NULL))
|
2011-03-01 14:53:26 +00:00
|
|
|
|
2011-03-02 16:22:04 +00:00
|
|
|
/* 'in_weakreflist' MUST be aligned */
|
|
|
|
|
2009-03-11 17:28:37 +00:00
|
|
|
typedef struct {
|
2009-11-11 16:28:53 +00:00
|
|
|
PyObject_HEAD /* required python macro */
|
2011-03-02 16:22:04 +00:00
|
|
|
#ifdef USE_WEAKREFS
|
|
|
|
PyObject *in_weakreflist;
|
|
|
|
#endif
|
2011-02-23 13:43:45 +00:00
|
|
|
PointerRNA ptr;
|
2009-11-11 16:28:53 +00:00
|
|
|
} BPy_DummyPointerRNA;
|
2009-03-11 17:28:37 +00:00
|
|
|
|
2008-11-29 13:36:08 +00:00
|
|
|
typedef struct {
|
2009-01-29 09:38:52 +00:00
|
|
|
PyObject_HEAD /* required python macro */
|
2011-02-23 13:43:45 +00:00
|
|
|
#ifdef USE_WEAKREFS
|
|
|
|
PyObject *in_weakreflist;
|
|
|
|
#endif
|
2011-03-02 16:22:04 +00:00
|
|
|
PointerRNA ptr;
|
2011-03-03 09:16:06 +00:00
|
|
|
#ifdef USE_PYRNA_STRUCT_REFERENCE
|
|
|
|
/* generic PyObject we hold a reference to, example use:
|
|
|
|
* hold onto the collection iterator to prevent it from freeing allocated data we may use */
|
|
|
|
PyObject *reference;
|
|
|
|
#endif /* !USE_PYRNA_STRUCT_REFERENCE */
|
2011-08-05 16:29:38 +00:00
|
|
|
|
|
|
|
#ifdef PYRNA_FREE_SUPPORT
|
2013-01-07 05:26:12 +00:00
|
|
|
bool freeptr; /* needed in some cases if ptr.data is created on the fly, free when deallocing */
|
2011-08-05 16:29:38 +00:00
|
|
|
#endif /* PYRNA_FREE_SUPPORT */
|
2008-11-29 13:36:08 +00:00
|
|
|
} BPy_StructRNA;
|
|
|
|
|
2010-09-02 06:35:00 +00:00
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD /* required python macro */
|
2011-02-23 13:43:45 +00:00
|
|
|
#ifdef USE_WEAKREFS
|
|
|
|
PyObject *in_weakreflist;
|
|
|
|
#endif
|
2011-03-02 16:22:04 +00:00
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
2010-09-02 06:35:00 +00:00
|
|
|
} BPy_PropertyRNA;
|
|
|
|
|
2008-11-29 13:36:08 +00:00
|
|
|
typedef struct {
|
2009-01-29 09:38:52 +00:00
|
|
|
PyObject_HEAD /* required python macro */
|
2011-03-02 16:22:04 +00:00
|
|
|
#ifdef USE_WEAKREFS
|
|
|
|
PyObject *in_weakreflist;
|
|
|
|
#endif
|
2008-11-29 13:36:08 +00:00
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
2009-09-06 15:13:57 +00:00
|
|
|
|
|
|
|
/* Arystan: this is a hack to allow sub-item r/w access like: face.uv[n][m] */
|
|
|
|
int arraydim; /* array dimension, e.g: 0 for face.uv, 2 for face.uv[n][m], etc. */
|
|
|
|
int arrayoffset; /* array first item offset, e.g. if face.uv is [4][2], arrayoffset for face.uv[n] is 2n */
|
2010-09-02 06:35:00 +00:00
|
|
|
} BPy_PropertyArrayRNA;
|
2008-11-29 13:36:08 +00:00
|
|
|
|
2011-03-03 07:41:09 +00:00
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD /* required python macro */
|
|
|
|
#ifdef USE_WEAKREFS
|
|
|
|
PyObject *in_weakreflist;
|
|
|
|
#endif
|
|
|
|
|
2011-10-17 06:39:13 +00:00
|
|
|
/* collection iterator specific parts */
|
2011-03-03 07:41:09 +00:00
|
|
|
CollectionPropertyIterator iter;
|
|
|
|
} BPy_PropertyCollectionIterRNA;
|
|
|
|
|
2011-08-05 16:21:37 +00:00
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD /* required python macro */
|
|
|
|
#ifdef USE_WEAKREFS
|
|
|
|
PyObject *in_weakreflist;
|
|
|
|
#endif
|
|
|
|
PointerRNA ptr;
|
|
|
|
FunctionRNA *func;
|
|
|
|
} BPy_FunctionRNA;
|
|
|
|
|
2009-03-21 06:55:30 +00:00
|
|
|
/* cheap trick */
|
|
|
|
#define BPy_BaseTypeRNA BPy_PropertyRNA
|
|
|
|
|
2010-03-16 17:20:15 +00:00
|
|
|
StructRNA *srna_from_self(PyObject *self, const char *error_prefix);
|
2013-01-07 05:26:12 +00:00
|
|
|
StructRNA *pyrna_struct_as_srna(PyObject *self, const bool parent, const char *error_prefix);
|
2009-12-30 22:14:32 +00:00
|
|
|
|
2011-06-02 08:29:16 +00:00
|
|
|
void BPY_rna_init(void);
|
|
|
|
PyObject *BPY_rna_module(void);
|
|
|
|
void BPY_update_rna_module(void);
|
|
|
|
/*PyObject *BPY_rna_doc(void);*/
|
|
|
|
PyObject *BPY_rna_types(void);
|
2012-12-20 13:29:58 +00:00
|
|
|
void BPY_rna_register_cb(void);
|
2008-11-29 13:36:08 +00:00
|
|
|
|
2011-06-02 08:29:16 +00:00
|
|
|
PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr);
|
|
|
|
PyObject *pyrna_prop_CreatePyObject(PointerRNA *ptr, PropertyRNA *prop);
|
2008-11-29 13:36:08 +00:00
|
|
|
|
2012-09-15 01:52:28 +00:00
|
|
|
/* extern'd by other modules which don't deal closely with RNA */
|
|
|
|
PyObject *pyrna_id_CreatePyObject(struct ID *id);
|
2013-01-07 05:26:12 +00:00
|
|
|
bool pyrna_id_FromPyObject(PyObject *obj, struct ID **id);
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
bool pyrna_id_CheckPyObject(PyObject *obj);
|
2012-09-15 01:52:28 +00:00
|
|
|
|
2008-12-25 10:48:36 +00:00
|
|
|
/* operators also need this to set args */
|
2016-07-23 04:03:36 +10:00
|
|
|
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const bool all_args, const char *error_prefix);
|
2011-06-02 08:29:16 +00:00
|
|
|
PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
|
2009-04-07 00:49:39 +00:00
|
|
|
|
2016-01-06 19:34:42 +01:00
|
|
|
unsigned int *pyrna_set_to_enum_bitmap(
|
2017-10-18 15:07:26 +11:00
|
|
|
const struct EnumPropertyItem *items, PyObject *value,
|
2016-01-06 19:34:42 +01:00
|
|
|
int type_size, bool type_convert_sign,
|
|
|
|
int bitmap_size,
|
|
|
|
const char *error_prefix);
|
2017-10-18 15:07:26 +11:00
|
|
|
PyObject *pyrna_enum_bitfield_to_py(
|
|
|
|
const struct EnumPropertyItem *items, int value);
|
|
|
|
int pyrna_set_to_enum_bitfield(
|
|
|
|
const struct EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix);
|
2010-02-27 15:28:34 +00:00
|
|
|
|
2017-10-18 15:07:26 +11:00
|
|
|
int pyrna_enum_value_from_id(
|
|
|
|
const EnumPropertyItem *item, const char *identifier, int *value, const char *error_prefix);
|
2010-01-23 01:02:53 +00:00
|
|
|
|
2013-03-22 15:47:02 +00:00
|
|
|
int pyrna_deferred_register_class(struct StructRNA *srna, PyTypeObject *py_class);
|
define operator properties in the class, similar to django fields
# Before
[
bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= ""),
bpy.props.BoolProperty(attr="use_modifiers", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True),
bpy.props.BoolProperty(attr="use_normals", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True),
bpy.props.BoolProperty(attr="use_uvs", name="Export UVs", description="Exort the active UV layer", default= True),
bpy.props.BoolProperty(attr="use_colors", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
]
# After
path = StringProperty(attr="", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= "")
use_modifiers = BoolProperty(attr="", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True)
use_normals = BoolProperty(attr="", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True)
use_uvs = BoolProperty(attr="", name="Export UVs", description="Exort the active UV layer", default= True)
use_colors = BoolProperty(attr="", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
2009-10-31 16:40:14 +00:00
|
|
|
|
2009-08-14 12:29:55 +00:00
|
|
|
/* called before stopping python */
|
2009-08-15 09:53:38 +00:00
|
|
|
void pyrna_alloc_types(void);
|
2009-08-14 12:29:55 +00:00
|
|
|
void pyrna_free_types(void);
|
|
|
|
|
Implemented dynamic and multidimensional array support in RNA.
Example code: http://www.pasteall.org/7332/c.
New API functions: http://www.pasteall.org/7330/c.
Maximum number of dimensions is currently limited to 3, but can be increased arbitrarily if needed.
What this means for ID property access:
* MeshFace.verts - dynamic array, size 3 or 4 depending on MFace.v4
* MeshTextureFace.uv - dynamic, 2-dimensional array, size depends on MFace.v4
* Object.matrix - 2-dimensional array
What this means for functions:
* more intuitive API possibility, for example:
Mesh.add_vertices([(x, y, z), (x, y, z), ...])
Mesh.add_faces([(1, 2, 3), (4, 5, 6), ...])
Python part is not complete yet, e.g. it is possible to:
MeshFace.verts = (1, 2, 3) # even if Mesh.verts is (1, 2, 3, 4) and vice-versa
MeshTextureFace.uv = [(0.0, 0.0)] * 4 # only if a corresponding MFace is a quad
but the following won't work:
MeshTextureFace.uv[3] = (0.0, 0.0) # setting uv[3] modifies MTFace.uv[1][0] instead of MTFace.uv[3]
2009-08-25 17:06:36 +00:00
|
|
|
/* primitive type conversion */
|
2010-10-13 23:25:08 +00:00
|
|
|
int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, char *param_data, PyObject *py, const char *error_prefix);
|
2009-09-06 15:13:57 +00:00
|
|
|
int pyrna_py_to_array_index(PointerRNA *ptr, PropertyRNA *prop, int arraydim, int arrayoffset, int index, PyObject *py, const char *error_prefix);
|
2010-09-23 02:12:33 +00:00
|
|
|
PyObject *pyrna_array_index(PointerRNA *ptr, PropertyRNA *prop, int index);
|
2009-09-06 15:13:57 +00:00
|
|
|
|
|
|
|
PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop);
|
2010-09-02 06:35:00 +00:00
|
|
|
PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, int index);
|
2009-09-06 15:13:57 +00:00
|
|
|
PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop);
|
2009-12-08 09:40:30 +00:00
|
|
|
int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value);
|
Implemented dynamic and multidimensional array support in RNA.
Example code: http://www.pasteall.org/7332/c.
New API functions: http://www.pasteall.org/7330/c.
Maximum number of dimensions is currently limited to 3, but can be increased arbitrarily if needed.
What this means for ID property access:
* MeshFace.verts - dynamic array, size 3 or 4 depending on MFace.v4
* MeshTextureFace.uv - dynamic, 2-dimensional array, size depends on MFace.v4
* Object.matrix - 2-dimensional array
What this means for functions:
* more intuitive API possibility, for example:
Mesh.add_vertices([(x, y, z), (x, y, z), ...])
Mesh.add_faces([(1, 2, 3), (4, 5, 6), ...])
Python part is not complete yet, e.g. it is possible to:
MeshFace.verts = (1, 2, 3) # even if Mesh.verts is (1, 2, 3, 4) and vice-versa
MeshTextureFace.uv = [(0.0, 0.0)] * 4 # only if a corresponding MFace is a quad
but the following won't work:
MeshTextureFace.uv[3] = (0.0, 0.0) # setting uv[3] modifies MTFace.uv[1][0] instead of MTFace.uv[3]
2009-08-25 17:06:36 +00:00
|
|
|
|
2013-01-07 05:26:12 +00:00
|
|
|
bool pyrna_write_check(void);
|
|
|
|
void pyrna_write_set(bool val);
|
2011-02-01 00:32:50 +00:00
|
|
|
|
2012-10-26 10:33:57 +00:00
|
|
|
void pyrna_invalidate(BPy_DummyPointerRNA *self);
|
2011-03-02 04:51:43 +00:00
|
|
|
int pyrna_struct_validity_check(BPy_StructRNA *pysrna);
|
|
|
|
int pyrna_prop_validity_check(BPy_PropertyRNA *self);
|
|
|
|
|
2011-02-11 00:11:17 +00:00
|
|
|
/* bpy.utils.(un)register_class */
|
|
|
|
extern PyMethodDef meth_bpy_register_class;
|
|
|
|
extern PyMethodDef meth_bpy_unregister_class;
|
|
|
|
|
2018-03-01 01:26:02 +11:00
|
|
|
/* bpy.utils._bl_owner_(get/set) */
|
|
|
|
extern PyMethodDef meth_bpy_owner_id_set;
|
|
|
|
extern PyMethodDef meth_bpy_owner_id_get;
|
|
|
|
|
2008-11-29 13:36:08 +00:00
|
|
|
#endif
|