=ID Properties=

This commit adds supports for per-ID properties to blender.
See http://mediawiki.blender.org/index.php/BlenderDev/ID_Property
for more information on how it all works.

ID properties are accesable by python; but note that 
bindings have only been added to Object and Material thus
far.  However adding more bindings is easy and I plan
on adding several more hopefully within an hour of this inital 
commit.

A generic UI panel is also planned, that will go wherever its
needed; for example in the material buttons, editing buttons, etc.
I'll likely submit the initial code for that as a patch, though,
so matt and ton and others can go over it and make sure it's
all good. :)

VERY important, if you intend to use ID properties please
go to http://mediawiki.blender.org/index.php/BlenderDev/PropertyStandards
and start writing the appropriate standards for it.
This commit is contained in:
2006-11-17 04:46:48 +00:00
parent 24f4440d05
commit 8768707610
11 changed files with 1794 additions and 9 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,26 @@
#include <Python.h>
struct ID;
struct IDProperty;
struct BPy_IDGroup_Iter;
typedef struct BPy_IDProperty {
PyObject_VAR_HEAD
struct ID *id;
struct IDProperty *prop;
PyObject *data_wrap;
} BPy_IDProperty;
typedef struct BPy_IDArray {
PyObject_VAR_HEAD
struct ID *id;
struct IDProperty *prop;
} BPy_IDArray;
typedef struct BPy_IDGroup_Iter {
PyObject_VAR_HEAD
BPy_IDProperty *group;
struct IDProperty *cur;
} BPy_IDGroup_Iter;
PyObject *BPy_Wrap_IDProperty(struct ID *id, struct IDProperty *prop);

View File

@@ -41,6 +41,7 @@
#include "BKE_library.h"
#include "BKE_material.h"
#include "BKE_texture.h"
#include "BKE_idprop.h"
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BSE_editipo.h"
@@ -52,6 +53,7 @@
#include "Ipo.h"
#include "Group.h"
#include "gen_utils.h"
#include "IDProp.h"
/*****************************************************************************/
/* Python BPy_Material defaults: */
@@ -602,6 +604,7 @@ static PyObject *Material_clearScriptLinks(BPy_Material *self, PyObject *args);
static PyObject *Material_insertIpoKey( BPy_Material * self, PyObject * args );
static PyObject *Material_copy( BPy_Material * self );
static PyObject *Material_getProperties( BPy_Material * self );
/*****************************************************************************/
@@ -609,6 +612,8 @@ static PyObject *Material_copy( BPy_Material * self );
/*****************************************************************************/
static PyMethodDef BPy_Material_methods[] = {
/* name, method, flags, doc */
{"getProperties", ( PyCFunction) Material_getProperties, METH_NOARGS,
"() Return Material's ID Properties"},
{"getName", ( PyCFunction ) Material_getName, METH_NOARGS,
"() - Return Material's name"},
{"getIpo", ( PyCFunction ) Material_getIpo, METH_NOARGS,
@@ -1080,6 +1085,8 @@ static PyGetSetDef BPy_Material_getseters[] = {
(getter)Material_getUsers, (setter)NULL,
"Number of material users",
NULL},
{"properties", (getter) Material_getProperties, (setter)NULL,
"Get material's ID properties"},
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};
@@ -1280,6 +1287,12 @@ Material *GetMaterialByName( char *name )
/* Python BPy_Material methods: */
/*****************************************************************************/
static PyObject *Material_getProperties( BPy_Material * self )
{
/*sanity check, we set parent property type to Group here*/
return BPy_Wrap_IDProperty((ID*)self->material, IDP_GetProperties((ID*)self->material, 1));
}
static PyObject *Material_getIpo( BPy_Material * self )
{
Ipo *ipo = self->material->ipo;

View File

@@ -66,6 +66,7 @@ struct rctf;
#include "BKE_scene.h"
#include "BKE_nla.h"
#include "BKE_material.h"
#include "BKE_idprop.h"
#include "BSE_editipo.h"
#include "BSE_edit.h"
@@ -114,6 +115,7 @@ struct rctf;
#include "gen_utils.h"
#include "EXPP_interface.h"
#include "BIF_editkey.h"
#include "IDProp.h"
/* Defines for insertIpoKey */
@@ -326,6 +328,7 @@ struct PyMethodDef M_Object_methods[] = {
static int setupSB(Object* ob); /*Make sure Softbody Pointer is initialized */
static int setupPI(Object* ob);
static PyObject *Object_GetProperties(BPy_Object * self);
static PyObject *Object_buildParts( BPy_Object * self );
static PyObject *Object_clearIpo( BPy_Object * self );
static PyObject *Object_clrParent( BPy_Object * self, PyObject * args );
@@ -750,6 +753,8 @@ works only if self and the object specified are of the same type."},
"() - Insert a Shape Key in the current object"},
{"__copy__", ( PyCFunction ) Object_copy, METH_NOARGS,
"() - Return a copy of this object."},
{"getProperties", ( PyCFunction ) Object_GetProperties, METH_NOARGS,
"() return a reference to the ID properties associated with this object."},
{NULL, NULL, 0, NULL}
};
@@ -982,6 +987,12 @@ static PyObject *M_Object_Duplicate( PyObject * self_unused,
/* Python BPy_Object methods: */
/*****************************************************************************/
static PyObject *Object_GetProperties(BPy_Object * self)
{
return BPy_Wrap_IDProperty((ID*)self->object, IDP_GetProperties((ID*)self->object, 1));
}
static PyObject *Object_buildParts( BPy_Object * self )
{
build_particle_system( self->object );
@@ -4983,7 +4994,8 @@ static PyGetSetDef BPy_Object_getseters[] = {
(getter)Object_getType, (setter)NULL,
"String describing Object type",
NULL},
{"properties", (getter)Object_GetProperties, (setter)NULL,
"Get the ID properties associated with this object"},
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};

View File

@@ -0,0 +1,65 @@
class IDProperty:
"""
The IDProperty wrapper type
===========================
@ivar name: the name of the property
@ivar type: the property type (is read-only)
@ivar data: the property's data.
"""
class IDGroup:
"""
The IDGroup wrapper type
========================
This type supports both iteration and the []
operator to get child ID properties.
You can also add new properties using the [] operator.
For example:
group['a float!'] = 0.0
group['an int!'] = 0
group['a string!'] = "hi!"
group['an array!'] = [0, 0, 1.0, 0] #note that any floats in the list
#makes the whole list a float array.
group['a subgroup!] = {"float": 0.0, "an int": 1.0, "an array": [1, 2], \
"another subgroup": {"a": 0.0, "str": "bleh"}}
you also do del group['item']
"""
def newProperty(type, name, array_type="Float", val=""):
"""
This function creates a new child ID property in the group.
@type type: an int or a string
@param type: The ID property type. Can be:
"String" or Blender.IDPropTypes['String']
"Int" or Blender.IDPropTypes['Int']
"Float" or Blender.IDPropTypes['Float']
"Array" or Blender.IDPropTypes['Array']
"Group" or Blender.IDPropTypes['Group']
"""
def deleteProperty(prop):
"""
deletes a property, takes either a name or a reference
as an argument.
"""
class IDArray:
"""
The IDArray wrapper type
========================
@ivar type: returns the type of the array, can be either IDP_Int or IDP_Float
"""
def __getitem__(self):
pass
def __setitem__(self):
pass
def __len__(self):
pass