2008-11-29 13:36:08 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* ***** 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 *****
|
|
|
|
*/
|
|
|
|
#ifndef BPY_RNA_H
|
|
|
|
#define BPY_RNA_H
|
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_types.h"
|
2008-12-29 03:24:13 +00:00
|
|
|
#include "BKE_idprop.h"
|
2008-11-29 13:36:08 +00:00
|
|
|
|
2010-09-10 14:54:50 +00:00
|
|
|
extern PyTypeObject pyrna_struct_meta_idprop_Type;
|
2008-12-01 16:59:18 +00:00
|
|
|
extern PyTypeObject pyrna_struct_Type;
|
|
|
|
extern PyTypeObject pyrna_prop_Type;
|
2010-02-15 23:43:51 +00:00
|
|
|
extern PyTypeObject pyrna_prop_array_Type;
|
|
|
|
extern PyTypeObject pyrna_prop_collection_Type;
|
2009-04-09 13:20:48 +00:00
|
|
|
|
2009-03-16 15:54: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)
|
2009-03-11 17:28:37 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2009-11-11 16:28:53 +00:00
|
|
|
PyObject_HEAD /* required python macro */
|
|
|
|
PointerRNA ptr;
|
|
|
|
} 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 */
|
2008-11-29 13:36:08 +00:00
|
|
|
PointerRNA ptr;
|
2009-01-08 15:29:09 +00:00
|
|
|
int freeptr; /* needed in some cases if ptr.data is created on the fly, free when deallocing */
|
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 */
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
} 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 */
|
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
|
|
|
|
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);
|
|
|
|
StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_prefix);
|
2009-12-30 22:14:32 +00:00
|
|
|
|
2009-11-08 01:13:19 +00:00
|
|
|
void BPY_rna_init( void );
|
2008-11-29 13:36:08 +00:00
|
|
|
PyObject *BPY_rna_module( void );
|
2009-08-15 09:53:38 +00:00
|
|
|
void BPY_update_rna_module( void );
|
2009-03-13 07:50:07 +00:00
|
|
|
/*PyObject *BPY_rna_doc( void );*/
|
|
|
|
PyObject *BPY_rna_types( void );
|
2008-11-29 13:36:08 +00:00
|
|
|
|
|
|
|
PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr );
|
|
|
|
PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop );
|
|
|
|
|
2008-12-25 10:48:36 +00:00
|
|
|
/* operators also need this to set args */
|
2009-07-30 01:52:00 +00:00
|
|
|
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix);
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
|
2009-04-07 00:49:39 +00:00
|
|
|
|
2010-01-23 01:02:53 +00:00
|
|
|
PyObject *pyrna_enum_bitfield_to_py(struct EnumPropertyItem *items, int value);
|
2010-02-01 22:04:33 +00:00
|
|
|
int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix);
|
2010-02-27 15:28:34 +00:00
|
|
|
|
|
|
|
int pyrna_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int *value, const char *error_prefix);
|
2010-01-23 01:02:53 +00:00
|
|
|
|
2010-08-19 10:16:30 +00:00
|
|
|
int pyrna_deferred_register_class(struct StructRNA *srna, PyObject *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-01-24 10:51:59 +00:00
|
|
|
int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, 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);
|
|
|
|
|
|
|
|
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
|
|
|
|
2008-11-29 13:36:08 +00:00
|
|
|
#endif
|