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,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2008-12-01 16:59:18 +00:00
|
|
|
extern PyTypeObject pyrna_struct_Type;
|
|
|
|
extern PyTypeObject pyrna_prop_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 {
|
|
|
|
void * _a;
|
|
|
|
void * _b;
|
|
|
|
PyTypeObject *py_type;
|
|
|
|
} BPy_StructFakeType;
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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 */
|
2008-11-29 13:36:08 +00:00
|
|
|
} BPy_PropertyRNA;
|
|
|
|
|
2009-03-21 06:55:30 +00:00
|
|
|
/* cheap trick */
|
|
|
|
#define BPy_BaseTypeRNA BPy_PropertyRNA
|
|
|
|
|
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 );
|
2009-06-18 19:51:22 +00:00
|
|
|
PyObject *BPY_rna_props( 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-23 13:48:15 +00:00
|
|
|
int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value, const char *error_prefix);
|
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
|
|
|
|
2009-03-16 15:54:43 +00:00
|
|
|
/* functions for setting up new props - experemental */
|
|
|
|
PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw);
|
2.5: RNA, defining enums, pointers and collections properties is now
possible from python, but it's still work in progress.
Pointers and collections are restricted to types derived from
IDPropertyGroup (same as for operators), because RNA knows how to
allocate/deallocate those.
Collections have .add() and .remove(number) functions that can be
used. The remove function should be fixed to take an other argument
than a number.
With the IDPropertyGroup restriction, pointers are more like nested
structs. They don't have add(), remove() yet, not sure where to put
them. Currently the pointer / nested struct is automatically allocated
in the get() function, this needs to be fixed, rule is that RNA get()
will not change any data for thread safety.
Also, it is only possible to add properties to structs after they have
been registered, which needs to be improved as well.
Example code:
http://www.pasteall.org/7201/python
2009-08-18 01:29:25 +00:00
|
|
|
PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw);
|
|
|
|
PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw);
|
2009-06-18 19:51:22 +00:00
|
|
|
PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw);
|
2.5: RNA, defining enums, pointers and collections properties is now
possible from python, but it's still work in progress.
Pointers and collections are restricted to types derived from
IDPropertyGroup (same as for operators), because RNA knows how to
allocate/deallocate those.
Collections have .add() and .remove(number) functions that can be
used. The remove function should be fixed to take an other argument
than a number.
With the IDPropertyGroup restriction, pointers are more like nested
structs. They don't have add(), remove() yet, not sure where to put
them. Currently the pointer / nested struct is automatically allocated
in the get() function, this needs to be fixed, rule is that RNA get()
will not change any data for thread safety.
Also, it is only possible to add properties to structs after they have
been registered, which needs to be improved as well.
Example code:
http://www.pasteall.org/7201/python
2009-08-18 01:29:25 +00:00
|
|
|
PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw);
|
|
|
|
PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw);
|
|
|
|
PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw);
|
2009-03-16 15:54:43 +00:00
|
|
|
|
2009-04-19 13:37:59 +00:00
|
|
|
/* function for registering types */
|
|
|
|
PyObject *pyrna_basetype_register(PyObject *self, PyObject *args);
|
|
|
|
PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *args);
|
2009-03-16 15:54:43 +00:00
|
|
|
|
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
|
|
|
int pyrna_deferred_register_props(struct StructRNA *srna, PyObject *class_dict);
|
|
|
|
|
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 */
|
2009-09-06 15:13:57 +00:00
|
|
|
int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, char *param_data, PyObject *py, const char *error_prefix);
|
|
|
|
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);
|
|
|
|
PyObject *pyrna_py_from_array_index(BPy_PropertyRNA *self, int index);
|
|
|
|
PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop);
|
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
|