* Added more error prints for wrong definitions, for cases that
  would laters cause problems compiling or crash at runtime, and
  also made messages more clear.
* Added some skeleton code for main/ID/mesh/vertex types for testing.
* Added support for automatic arrays as collections using SDNA.

* Changed how pointers to data work. Now they are always wrapped
  in a PointerRNA struct, which contains the data pointer and type,
  and also the data pointer and type of the ID datablock that this
  belongs to, since for example a vertex on it's own may not have
  enough information for some operations, it also needs the mesh.

* Added some code for defining dependencies with RNA, and looking up
  data with paths like: scenes[0].objects["Cube"].data.verts[7].co.
  Note sure either will end up being used, this is experimental.

http://wiki.blender.org/index.php/BlenderDev/Blender2.5/RNA
This commit is contained in:
2008-11-07 02:58:25 +00:00
parent 21a0e55c50
commit 7e8ba5c84d
14 changed files with 1428 additions and 401 deletions

View File

@@ -27,49 +27,90 @@
struct bContext;
struct BlenderRNA;
struct PropertyRNA;
struct StructRNA;
struct PropertyRNA;
struct PointerRNA;
struct CollectionPropertyIterator;
struct Main;
/* Property */
/* Pointer
*
* Currently only an RNA pointer to Main can be obtained, this
* should be extended to allow making other pointers as well. */
void RNA_property_notify(struct PropertyRNA *prop, struct bContext *C, void *data);
int RNA_property_readonly(struct PropertyRNA *prop, struct bContext *C, void *data);
void RNA_pointer_main_get(struct Main *main, struct PointerRNA *r_ptr);
int RNA_property_boolean_get(struct PropertyRNA *prop, void *data);
void RNA_property_boolean_set(struct PropertyRNA *prop, void *data, int value);
int RNA_property_boolean_get_array(struct PropertyRNA *prop, void *data, int index);
void RNA_property_boolean_set_array(struct PropertyRNA *prop, void *data, int index, int value);
/* Property
*
* Access to struct properties. All this works with RNA pointers rather than
* direct pointers to the data. */
int RNA_property_int_get(struct PropertyRNA *prop, void *data);
void RNA_property_int_set(struct PropertyRNA *prop, void *data, int value);
int RNA_property_int_get_array(struct PropertyRNA *prop, void *data, int index);
void RNA_property_int_set_array(struct PropertyRNA *prop, void *data, int index, int value);
int RNA_property_editable(struct PropertyRNA *prop, struct PointerRNA *ptr);
int RNA_property_evaluated(struct PropertyRNA *prop, struct PointerRNA *ptr);
float RNA_property_float_get(struct PropertyRNA *prop, void *data);
void RNA_property_float_set(struct PropertyRNA *prop, void *data, float value);
float RNA_property_float_get_array(struct PropertyRNA *prop, void *data, int index);
void RNA_property_float_set_array(struct PropertyRNA *prop, void *data, int index, float value);
void RNA_property_notify(struct PropertyRNA *prop, struct bContext *C, struct PointerRNA *ptr);
void RNA_property_string_get(struct PropertyRNA *prop, void *data, char *value);
int RNA_property_string_length(struct PropertyRNA *prop, void *data);
void RNA_property_string_set(struct PropertyRNA *prop, void *data, const char *value);
int RNA_property_boolean_get(struct PropertyRNA *prop, struct PointerRNA *ptr);
void RNA_property_boolean_set(struct PropertyRNA *prop, struct PointerRNA *ptr, int value);
int RNA_property_boolean_get_array(struct PropertyRNA *prop, struct PointerRNA *ptr, int index);
void RNA_property_boolean_set_array(struct PropertyRNA *prop, struct PointerRNA *ptr, int index, int value);
int RNA_property_enum_get(struct PropertyRNA *prop, void *data);
void RNA_property_enum_set(struct PropertyRNA *prop, void *data, int value);
int RNA_property_int_get(struct PropertyRNA *prop, struct PointerRNA *ptr);
void RNA_property_int_set(struct PropertyRNA *prop, struct PointerRNA *ptr, int value);
int RNA_property_int_get_array(struct PropertyRNA *prop, struct PointerRNA *ptr, int index);
void RNA_property_int_set_array(struct PropertyRNA *prop, struct PointerRNA *ptr, int index, int value);
void *RNA_property_pointer_get(struct PropertyRNA *prop, void *data);
void RNA_property_pointer_set(struct PropertyRNA *prop, void *data, void *value);
struct StructRNA *RNA_property_pointer_type(struct PropertyRNA *prop, void *data);
float RNA_property_float_get(struct PropertyRNA *prop, struct PointerRNA *ptr);
void RNA_property_float_set(struct PropertyRNA *prop, struct PointerRNA *ptr, float value);
float RNA_property_float_get_array(struct PropertyRNA *prop, struct PointerRNA *ptr, int index);
void RNA_property_float_set_array(struct PropertyRNA *prop, struct PointerRNA *ptr, int index, float value);
void RNA_property_collection_begin(struct PropertyRNA *prop, struct CollectionPropertyIterator *iter, void *data);
void RNA_property_string_get(struct PropertyRNA *prop, struct PointerRNA *ptr, char *value);
int RNA_property_string_length(struct PropertyRNA *prop, struct PointerRNA *ptr);
void RNA_property_string_set(struct PropertyRNA *prop, struct PointerRNA *ptr, const char *value);
int RNA_property_enum_get(struct PropertyRNA *prop, struct PointerRNA *ptr);
void RNA_property_enum_set(struct PropertyRNA *prop, struct PointerRNA *ptr, int value);
void RNA_property_pointer_get(struct PropertyRNA *prop, struct PointerRNA *ptr, struct PointerRNA *r_ptr);
void RNA_property_pointer_set(struct PropertyRNA *prop, struct PointerRNA *ptr, struct PointerRNA *ptr_value);
struct StructRNA *RNA_property_pointer_type(struct PropertyRNA *prop, struct PointerRNA *ptr);
void RNA_property_collection_begin(struct PropertyRNA *prop, struct CollectionPropertyIterator *iter, struct PointerRNA *ptr);
void RNA_property_collection_next(struct PropertyRNA *prop, struct CollectionPropertyIterator *iter);
void RNA_property_collection_end(struct PropertyRNA *prop, struct CollectionPropertyIterator *iter);
void *RNA_property_collection_get(struct PropertyRNA *prop, struct CollectionPropertyIterator *iter);
void RNA_property_collection_get(struct PropertyRNA *prop, struct CollectionPropertyIterator *iter, struct PointerRNA *r_ptr);
struct StructRNA *RNA_property_collection_type(struct PropertyRNA *prop, struct CollectionPropertyIterator *iter);
int RNA_property_collection_length(struct PropertyRNA *prop, void *data);
void *RNA_property_collection_lookup_int(struct PropertyRNA *prop, void *data, int key, struct StructRNA **type);
void *RNA_property_collection_lookup_string(struct PropertyRNA *prop, void *data, const char *key, struct StructRNA **type);
int RNA_property_collection_length(struct PropertyRNA *prop, struct PointerRNA *ptr);
int RNA_property_collection_lookup_int(struct PropertyRNA *prop, struct PointerRNA *ptr, int key, struct PointerRNA *r_ptr);
int RNA_property_collection_lookup_string(struct PropertyRNA *prop, struct PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr);
/* Path
*
* Experimental method to refer to structs and properties with a string,
* using a syntax like: scenes[0].objects["Cube"].data.verts[7].co
*
* This provides a way to refer to RNA data while being detached from any
* particular pointers, which is useful in a number of applications, like
* UI code or Actions, though efficiency is a concern. */
char *RNA_path_append(const char *path, struct PropertyRNA *prop, int intkey, const char *strkey);
char *RNA_path_back(const char *path);
int RNA_path_resolve(struct PointerRNA *ptr, const char *path,
struct PointerRNA *r_ptr, struct PropertyRNA **r_prop);
/* Dependency
*
* Experimental code that will generate callbacks for each dependency
* between ID types. This may end up being useful for UI
* and evaluation code that needs to know such dependencies for correct
* redraws and re-evaluations. */
typedef void (*PropDependencyCallback)(void *udata, struct PointerRNA *from, struct PointerRNA *to);
void RNA_test_dependencies_cb(void *udata, struct PointerRNA *from, struct PointerRNA *to);
void RNA_generate_dependencies(struct PointerRNA *mainptr, void *udata, PropDependencyCallback cb);
#endif /* RNA_ACCESS */

View File

@@ -48,12 +48,13 @@ void RNA_free(struct BlenderRNA *brna);
/* Struct */
struct StructRNA *RNA_def_struct(struct BlenderRNA *brna, const char *cname, const char *name);
void RNA_def_struct_sdna(struct StructRNA *rna, const char *structname);
void RNA_def_struct_name_property(struct StructRNA *rna, struct PropertyRNA *prop);
void RNA_def_struct_sdna(struct StructRNA *srna, const char *structname);
void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *prop);
void RNA_def_struct_flag(struct StructRNA *srna, int flag);
/* Property */
struct PropertyRNA *RNA_def_property(struct StructRNA *strct, const char *cname, int type, int subtype);
struct PropertyRNA *RNA_def_property(struct StructRNA *srna, const char *cname, int type, int subtype);
void RNA_def_property_boolean_sdna(struct PropertyRNA *prop, const char *structname, const char *propname, int bit);
void RNA_def_property_int_sdna(struct PropertyRNA *prop, const char *structname, const char *propname);
@@ -61,10 +62,10 @@ void RNA_def_property_float_sdna(struct PropertyRNA *prop, const char *structnam
void RNA_def_property_string_sdna(struct PropertyRNA *prop, const char *structname, const char *propname);
void RNA_def_property_enum_sdna(struct PropertyRNA *prop, const char *structname, const char *propname);
void RNA_def_property_pointer_sdna(struct PropertyRNA *prop, const char *structname, const char *propname);
void RNA_def_property_collection_sdna(struct PropertyRNA *prop, const char *structname, const char *propname);
void RNA_def_property_collection_sdna(struct PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname);
void RNA_def_property_flag(struct PropertyRNA *prop, int flag);
void RNA_def_property_array(struct PropertyRNA *prop, int arraylength);
void RNA_def_property_access(struct PropertyRNA *prop, int editable, int evaluatable);
void RNA_def_property_range(struct PropertyRNA *prop, double min, double max);
void RNA_def_property_enum_items(struct PropertyRNA *prop, const struct PropertyEnumItem *item);
@@ -83,14 +84,14 @@ void RNA_def_property_string_default(struct PropertyRNA *prop, const char *value
void RNA_def_property_ui_text(struct PropertyRNA *prop, const char *name, const char *description);
void RNA_def_property_ui_range(struct PropertyRNA *prop, double min, double max, double step, double precision);
void RNA_def_property_funcs(struct PropertyRNA *prop, char *notify, char *readonly);
void RNA_def_property_boolean_funcs(struct PropertyRNA *prop, char *get, char *set);
void RNA_def_property_int_funcs(struct PropertyRNA *prop, char *get, char *set);
void RNA_def_property_float_funcs(struct PropertyRNA *prop, char *get, char *set);
void RNA_def_property_enum_funcs(struct PropertyRNA *prop, char *get, char *set);
void RNA_def_property_string_funcs(struct PropertyRNA *prop, char *get, char *length, char *set);
void RNA_def_property_pointer_funcs(struct PropertyRNA *prop, char *get, char *type, char *set);
void RNA_def_property_collection_funcs(struct PropertyRNA *prop, char *begin, char *next, char *end, char *get, char *type, char *length, char *lookupint, char *lookupstring);
void RNA_def_property_funcs(struct PropertyRNA *prop, const char *notify, const char *readonly);
void RNA_def_property_boolean_funcs(struct PropertyRNA *prop, const char *get, const char *set);
void RNA_def_property_int_funcs(struct PropertyRNA *prop, const char *get, const char *set);
void RNA_def_property_float_funcs(struct PropertyRNA *prop, const char *get, const char *set);
void RNA_def_property_enum_funcs(struct PropertyRNA *prop, const char *get, const char *set);
void RNA_def_property_string_funcs(struct PropertyRNA *prop, const char *get, const char *length, const char *set);
void RNA_def_property_pointer_funcs(struct PropertyRNA *prop, const char *get, const char *type, const char *set);
void RNA_def_property_collection_funcs(struct PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *type, const char *length, const char *lookupint, const char *lookupstring);
#endif /* RNA_DEFINE_H */

View File

@@ -30,38 +30,60 @@
struct BlenderRNA;
struct StructRNA;
struct PropertyRNA;
struct PointerRNA;
struct CollectionPropertyIterator;
struct bContext;
typedef void (*PropNotifyFunc)(struct bContext *C, void *data);
typedef int (*PropBooleanGetFunc)(void *data);
typedef void (*PropBooleanSetFunc)(void *data, int value);
typedef int (*PropBooleanArrayGetFunc)(void *data, int index);
typedef void (*PropBooleanArraySetFunc)(void *data, int index, int value);
typedef int (*PropIntGetFunc)(void *data);
typedef void (*PropIntSetFunc)(void *data, int value);
typedef int (*PropIntArrayGetFunc)(void *data, int index);
typedef void (*PropIntArraySetFunc)(void *data, int index, int value);
typedef float (*PropFloatGetFunc)(void *data);
typedef void (*PropFloatSetFunc)(void *data, float value);
typedef float (*PropFloatArrayGetFunc)(void *data, int index);
typedef void (*PropFloatArraySetFunc)(void *data, int index, float value);
typedef void (*PropStringGetFunc)(void *data, char *value);
typedef int (*PropStringLengthFunc)(void *data);
typedef void (*PropStringSetFunc)(void *data, const char *value);
typedef int (*PropEnumGetFunc)(void *data);
typedef void (*PropEnumSetFunc)(void *data, int value);
typedef void* (*PropPointerGetFunc)(void *data);
typedef void (*PropPointerSetFunc)(void *data, void *value);
typedef struct StructRNA* (*PropPointerTypeFunc)(void *data);
typedef void (*PropCollectionBeginFunc)(struct CollectionPropertyIterator *iter, void *data);
/* Function Callbacks */
typedef void (*PropNotifyFunc)(struct bContext *C, struct PointerRNA *ptr);
typedef int (*PropBooleanGetFunc)(struct PointerRNA *ptr);
typedef void (*PropBooleanSetFunc)(struct PointerRNA *ptr, int value);
typedef int (*PropBooleanArrayGetFunc)(struct PointerRNA *ptr, int index);
typedef void (*PropBooleanArraySetFunc)(struct PointerRNA *ptr, int index, int value);
typedef int (*PropIntGetFunc)(struct PointerRNA *ptr);
typedef void (*PropIntSetFunc)(struct PointerRNA *ptr, int value);
typedef int (*PropIntArrayGetFunc)(struct PointerRNA *ptr, int index);
typedef void (*PropIntArraySetFunc)(struct PointerRNA *ptr, int index, int value);
typedef float (*PropFloatGetFunc)(struct PointerRNA *ptr);
typedef void (*PropFloatSetFunc)(struct PointerRNA *ptr, float value);
typedef float (*PropFloatArrayGetFunc)(struct PointerRNA *ptr, int index);
typedef void (*PropFloatArraySetFunc)(struct PointerRNA *ptr, int index, float value);
typedef void (*PropStringGetFunc)(struct PointerRNA *ptr, char *value);
typedef int (*PropStringLengthFunc)(struct PointerRNA *ptr);
typedef void (*PropStringSetFunc)(struct PointerRNA *ptr, const char *value);
typedef int (*PropEnumGetFunc)(struct PointerRNA *ptr);
typedef void (*PropEnumSetFunc)(struct PointerRNA *ptr, int value);
typedef void* (*PropPointerGetFunc)(struct PointerRNA *ptr);
typedef void (*PropPointerSetFunc)(struct PointerRNA *ptr, void *value);
typedef struct StructRNA* (*PropPointerTypeFunc)(struct PointerRNA *ptr);
typedef void (*PropCollectionBeginFunc)(struct CollectionPropertyIterator *iter, struct PointerRNA *ptr);
typedef void (*PropCollectionNextFunc)(struct CollectionPropertyIterator *iter);
typedef void (*PropCollectionEndFunc)(struct CollectionPropertyIterator *iter);
typedef void* (*PropCollectionGetFunc)(struct CollectionPropertyIterator *iter);
typedef struct StructRNA* (*PropCollectionTypeFunc)(struct CollectionPropertyIterator *iter);
typedef int (*PropCollectionLengthFunc)(void *data);
typedef void* (*PropCollectionLookupIntFunc)(void *data, int key, struct StructRNA **type);
typedef void* (*PropCollectionLookupStringFunc)(void *data, const char *key, struct StructRNA **type);
typedef int (*PropCollectionLengthFunc)(struct PointerRNA *ptr);
typedef void* (*PropCollectionLookupIntFunc)(struct PointerRNA *ptr, int key, struct StructRNA **type);
typedef void* (*PropCollectionLookupStringFunc)(struct PointerRNA *ptr, const char *key, struct StructRNA **type);
/* Pointer
*
* RNA pointers are not a single C pointer but include the type,
* and a pointer to the ID struct that owns the struct, since
* in some cases this information is needed to correctly get/set
* the properties and validate them. */
typedef struct PointerRNA {
struct {
struct StructRNA *type;
void *data;
} id;
struct StructRNA *type;
void *data;
} PointerRNA;
/* Property */
typedef enum PropertyType {
PROP_BOOLEAN = 0,
@@ -84,11 +106,36 @@ typedef enum PropertySubType {
} PropertySubType;
typedef enum PropertyFlag {
/* editable means the property is editable in the user
* interface, evaluated means that the property is set
* as part of an evaluation. these can change at runtime
* the property flag contains the default. editable is
* enabled by default except for collections. */
PROP_EDITABLE = 1,
PROP_EVALUATEABLE = 2
PROP_EVALUATED = 2,
/* driveable means the property can be driven by some
* other input, be it animation curves, expressions, ..
* in other words making the property evaluated. this is
* enable by default except for pointers and collections. */
PROP_DRIVEABLE = 4,
/* for pointers and collections, means that the struct
* depends on the data pointed to for evaluation, such
* that a change in the data pointed to will affect the
* evaluated result of this struct. */
PROP_EVALUATE_DEPENDENCY = 8,
PROP_INVERSE_EVALUATE_DEPENDENCY = 16,
/* for pointers and collections, means that the struct
* requires the data pointed to for rendering in the,
* be it the render engine or viewport */
PROP_RENDER_DEPENDENCY = 32,
PROP_INVERSE_RENDER_DEPENDENCY = 64,
} PropertyFlag;
typedef struct CollectionPropertyIterator {
PointerRNA pointer;
void *internal;
int valid;
} CollectionPropertyIterator;
@@ -123,7 +170,8 @@ typedef struct PropertyRNA {
PropNotifyFunc notify;
} PropertyRNA;
/* information specific to the property type */
/* Property Types */
typedef struct BooleanPropertyRNA {
PropertyRNA property;
@@ -220,6 +268,13 @@ typedef struct CollectionPropertyRNA {
struct StructRNA *structtype;
} CollectionPropertyRNA;
/* Struct */
typedef enum StructFlag {
/* indicates that this struct is an ID struct */
STRUCT_ID = 1
} StructFlag;
typedef struct StructRNA {
struct StructRNA *next, *prev;
@@ -238,8 +293,11 @@ typedef struct StructRNA {
ListBase properties;
} StructRNA;
/* Blender RNA
*
* Root RNA data structure that lists all struct types. */
typedef struct BlenderRNA {
/* structs */
ListBase structs;
} BlenderRNA;

View File

@@ -12,12 +12,15 @@ source_files = env.Glob('*.c')
# making rna_access.c part of both makesrna and blender seems to
# give conflict, how to solve?
source_files.remove('rna_access.c')
source_files.remove('rna_dependency.c')
makesrna_tool = env.Copy()
rna = env.Copy()
makesrna_tool.Append(CCFLAGS = '-DBASE_HEADER="\\"source/blender/makesrna/\\"" ')
makesrna_tool.Append (CPPPATH = ['#/intern/guardedalloc',
'../../blenlib',
'../../blenkernel',
'../../makesdna',
'../../makesrna'])
@@ -44,6 +47,6 @@ if env['OURPLATFORM'] != 'linuxcross':
rna.Command ('rna.c', '', root_build_dir+os.sep+"makesrna $TARGET")
else:
rna.Command ('rna.c', '', root_build_dir+os.sep+"makesrna.exe $TARGET")
obj = ['intern/rna.c', 'intern/rna_access.c']
obj = ['intern/rna.c', 'intern/rna_access.c', 'intern/rna_dependency.c']
Return ('obj')

View File

@@ -44,11 +44,6 @@
#endif
#endif
/* TODO
* - better crash checks for autogenerated functions
* - missing warnings for makesdna/rna scons compile?
*/
/* Preprocessing */
static void rna_print_c_string(FILE *f, const char *str)
@@ -101,52 +96,55 @@ static const char *rna_type_type(PropertyRNA *prop)
}
}
static char *rna_def_property_get_func(FILE *f, PropertyRNA *prop, PropertyDefRNA *dp)
static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp)
{
char *func;
if(!dp->dnastructname || !dp->dnaname) {
fprintf(stderr, "rna_def_property_get_func: %s has no valid dna info.\n", prop->cname);
fprintf(stderr, "rna_def_property_get_func: %s.%s has no valid dna info.\n", srna->cname, prop->cname);
DefRNA.error= 1;
return NULL;
}
if(prop->type == PROP_STRING && ((StringPropertyRNA*)prop)->maxlength == 0) {
fprintf(stderr, "rna_def_property_get_func: string %s has max length 0.\n", prop->cname);
fprintf(stderr, "rna_def_property_get_func: string %s.%s has max length 0.\n", srna->cname, prop->cname);
DefRNA.error= 1;
return NULL;
}
func= rna_alloc_function_name(dp->strct->cname, prop->cname, "get");
func= rna_alloc_function_name(srna->cname, prop->cname, "get");
switch(prop->type) {
case PROP_STRING: {
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
fprintf(f, "static void %s(void *data, char *value)\n", func);
fprintf(f, "static void %s(PointerRNA *ptr, char *value)\n", func);
fprintf(f, "{\n");
fprintf(f, " BLI_strncpy(value, ((%s*)data)->%s, %d);\n", dp->dnastructname, dp->dnaname, sprop->maxlength);
fprintf(f, " %s *data= (%s*)ptr->data;\n", dp->dnastructname, dp->dnastructname);
fprintf(f, " BLI_strncpy(value, data->%s, %d);\n", dp->dnaname, sprop->maxlength);
fprintf(f, "}\n\n");
break;
}
default:
if(prop->arraylength) {
fprintf(f, "static %s %s(void *data, int index)\n", rna_type_type(prop), func);
fprintf(f, "static %s %s(PointerRNA *ptr, int index)\n", rna_type_type(prop), func);
fprintf(f, "{\n");
fprintf(f, " %s *data= (%s*)ptr->data;\n", dp->dnastructname, dp->dnastructname);
if(prop->type == PROP_BOOLEAN && dp->booleanbit && dp->dnaarraylength==1)
fprintf(f, " return ((((%s*)data)->%s & (%d<<index)) != 0);\n", dp->dnastructname, dp->dnaname, dp->booleanbit);
fprintf(f, " return ((data->%s & (%d<<index)) != 0);\n", dp->dnaname, dp->booleanbit);
else if(prop->type == PROP_BOOLEAN && dp->booleanbit)
fprintf(f, " return ((((%s*)data)->%s[index] & %d) != 0);\n", dp->dnastructname, dp->dnaname, dp->booleanbit);
fprintf(f, " return ((data->%s[index] & %d) != 0);\n", dp->dnaname, dp->booleanbit);
else
fprintf(f, " return (%s)(((%s*)data)->%s[index]);\n", rna_type_type(prop), dp->dnastructname, dp->dnaname);
fprintf(f, " return (%s)(data->%s[index]);\n", rna_type_type(prop), dp->dnaname);
fprintf(f, "}\n\n");
}
else {
fprintf(f, "static %s %s(void *data)\n", rna_type_type(prop), func);
fprintf(f, "static %s %s(PointerRNA *ptr)\n", rna_type_type(prop), func);
fprintf(f, "{\n");
fprintf(f, " %s *data= (%s*)ptr->data;\n", dp->dnastructname, dp->dnastructname);
if(prop->type == PROP_BOOLEAN && dp->booleanbit)
fprintf(f, " return (((((%s*)data)->%s) & %d) != 0);\n", dp->dnastructname, dp->dnaname, dp->booleanbit);
fprintf(f, " return (((data->%s) & %d) != 0);\n", dp->dnaname, dp->booleanbit);
else
fprintf(f, " return (%s)(((%s*)data)->%s);\n", rna_type_type(prop), dp->dnastructname, dp->dnaname);
fprintf(f, " return (%s)(data->%s);\n", rna_type_type(prop), dp->dnaname);
fprintf(f, "}\n\n");
}
break;
@@ -187,55 +185,58 @@ static void rna_clamp_value(FILE *f, PropertyRNA *prop)
}
}
static char *rna_def_property_set_func(FILE *f, PropertyRNA *prop, PropertyDefRNA *dp)
static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp)
{
char *func;
if(!dp->dnastructname || !dp->dnaname) {
fprintf(stderr, "rna_def_property_set_func: %s has no valid dna info.\n", prop->cname);
fprintf(stderr, "rna_def_property_set_func: %s.%s has no valid dna info.\n", srna->cname, prop->cname);
DefRNA.error= 1;
return NULL;
}
func= rna_alloc_function_name(dp->strct->cname, prop->cname, "set");
func= rna_alloc_function_name(srna->cname, prop->cname, "set");
switch(prop->type) {
case PROP_STRING: {
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
fprintf(f, "static void %s(void *data, const char *value)\n", func);
fprintf(f, "static void %s(PointerRNA *ptr, const char *value)\n", func);
fprintf(f, "{\n");
fprintf(f, " BLI_strncpy(((%s*)data)->%s, value, %d);\n", dp->dnastructname, dp->dnaname, sprop->maxlength);
fprintf(f, " %s *data= (%s*)ptr->data;\n", dp->dnastructname, dp->dnastructname);
fprintf(f, " BLI_strncpy(data->%s, value, %d);\n", dp->dnaname, sprop->maxlength);
fprintf(f, "}\n\n");
break;
}
default:
if(prop->arraylength) {
fprintf(f, "static void %s(void *data, int index, %s value)\n", func, rna_type_type(prop));
fprintf(f, "static void %s(PointerRNA *ptr, int index, %s value)\n", func, rna_type_type(prop));
fprintf(f, "{\n");
fprintf(f, " %s *data= (%s*)ptr->data;\n", dp->dnastructname, dp->dnastructname);
if(prop->type == PROP_BOOLEAN && dp->booleanbit && dp->dnaarraylength==1) {
fprintf(f, " if(value) ((%s*)data)->%s |= (%d<<index);\n", dp->dnastructname, dp->dnaname, dp->booleanbit);
fprintf(f, " else ((%s*)data)->%s &= ~(%d<<index);\n", dp->dnastructname, dp->dnaname, dp->booleanbit);
fprintf(f, " if(value) data->%s |= (%d<<index);\n", dp->dnaname, dp->booleanbit);
fprintf(f, " else data->%s &= ~(%d<<index);\n", dp->dnaname, dp->booleanbit);
}
else if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
fprintf(f, " if(value) ((%s*)data)->%s[index] |= %d;\n", dp->dnastructname, dp->dnaname, dp->booleanbit);
fprintf(f, " else ((%s*)data)->%s[index] &= ~%d;\n", dp->dnastructname, dp->dnaname, dp->booleanbit);
fprintf(f, " if(value) data->%s[index] |= %d;\n", dp->dnaname, dp->booleanbit);
fprintf(f, " else data->%s[index] &= ~%d;\n", dp->dnaname, dp->booleanbit);
}
else {
rna_clamp_value(f, prop);
fprintf(f, " ((%s*)data)->%s[index]= value;\n", dp->dnastructname, dp->dnaname);
fprintf(f, " data->%s[index]= value;\n", dp->dnaname);
}
fprintf(f, "}\n\n");
}
else {
fprintf(f, "static void %s(void *data, %s value)\n", func, rna_type_type(prop));
fprintf(f, "static void %s(PointerRNA *ptr, %s value)\n", func, rna_type_type(prop));
fprintf(f, "{\n");
fprintf(f, " %s *data= (%s*)ptr->data;\n", dp->dnastructname, dp->dnastructname);
if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
fprintf(f, " if(value) ((%s*)data)->%s |= %d;\n", dp->dnastructname, dp->dnaname, dp->booleanbit);
fprintf(f, " else ((%s*)data)->%s &= ~%d;\n", dp->dnastructname, dp->dnaname, dp->booleanbit);
fprintf(f, " if(value) data->%s |= %d;\n", dp->dnaname, dp->booleanbit);
fprintf(f, " else data->%s &= ~%d;\n", dp->dnaname, dp->booleanbit);
}
else {
rna_clamp_value(f, prop);
fprintf(f, " ((%s*)data)->%s= value;\n", dp->dnastructname, dp->dnaname);
fprintf(f, " data->%s= value;\n", dp->dnaname);
}
fprintf(f, "}\n\n");
}
@@ -245,42 +246,70 @@ static char *rna_def_property_set_func(FILE *f, PropertyRNA *prop, PropertyDefRN
return func;
}
static char *rna_def_property_length_func(FILE *f, PropertyRNA *prop, PropertyDefRNA *dp)
static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp)
{
char *func;
char *func= NULL;
if(!dp->dnastructname || !dp->dnaname) {
fprintf(stderr, "rna_def_property_length_func: %s has no valid dna info.\n", prop->cname);
DefRNA.error= 1;
return NULL;
if(prop->type == PROP_STRING) {
if(!dp->dnastructname || !dp->dnaname) {
fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->cname, prop->cname);
DefRNA.error= 1;
return NULL;
}
func= rna_alloc_function_name(srna->cname, prop->cname, "length");
fprintf(f, "static int %s(PointerRNA *ptr)\n", func);
fprintf(f, "{\n");
fprintf(f, " %s *data= (%s*)ptr->data;\n", dp->dnastructname, dp->dnastructname);
fprintf(f, " return strlen(data->%s);\n", dp->dnaname);
fprintf(f, "}\n\n");
}
else if(prop->type == PROP_COLLECTION) {
if(prop->type == PROP_COLLECTION && !dp->dnalengthname) {
fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->cname, prop->cname);
DefRNA.error= 1;
return NULL;
}
func= rna_alloc_function_name(dp->strct->cname, prop->cname, "length");
func= rna_alloc_function_name(srna->cname, prop->cname, "length");
fprintf(f, "static int %s(void *data)\n", func);
fprintf(f, "{\n");
fprintf(f, " return strlen(((%s*)data)->%s);\n", dp->dnastructname, dp->dnaname);
fprintf(f, "}\n\n");
fprintf(f, "static int %s(PointerRNA *ptr)\n", func);
fprintf(f, "{\n");
fprintf(f, " %s *data= (%s*)ptr->data;\n", dp->dnastructname, dp->dnastructname);
fprintf(f, " return data->%s;\n", dp->dnalengthname);
fprintf(f, "}\n\n");
}
return func;
}
static char *rna_def_property_begin_func(FILE *f, PropertyRNA *prop, PropertyDefRNA *dp)
static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp)
{
char *func;
if(!dp->dnastructname || !dp->dnaname) {
fprintf(stderr, "rna_def_property_begin_func: %s has no valid dna info.\n", prop->cname);
fprintf(stderr, "rna_def_property_begin_func: %s.%s has no valid dna info.\n", srna->cname, prop->cname);
DefRNA.error= 1;
return NULL;
}
func= rna_alloc_function_name(dp->strct->cname, prop->cname, "begin");
func= rna_alloc_function_name(srna->cname, prop->cname, "begin");
fprintf(f, "static void %s(CollectionPropertyIterator *iter, void *data)\n", func);
fprintf(f, "{\n");
fprintf(f, " rna_iterator_listbase_begin(iter, &((%s*)data)->%s);\n", dp->dnastructname, dp->dnaname);
fprintf(f, "}\n\n");
if(dp->dnalengthname) {
fprintf(f, "static void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
fprintf(f, "{\n");
fprintf(f, " %s *data= (%s*)ptr->data;\n", dp->dnastructname, dp->dnastructname);
fprintf(f, " rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), data->%s);\n", dp->dnaname, dp->dnaname, dp->dnalengthname);
fprintf(f, "}\n\n");
}
else {
fprintf(f, "static void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
fprintf(f, "{\n");
fprintf(f, " %s *data= (%s*)ptr->data;\n", dp->dnastructname, dp->dnastructname);
fprintf(f, " rna_iterator_listbase_begin(iter, &data->%s);\n", dp->dnaname);
fprintf(f, "}\n\n");
}
return func;
}
@@ -288,7 +317,9 @@ static char *rna_def_property_begin_func(FILE *f, PropertyRNA *prop, PropertyDef
static void rna_def_property_funcs(FILE *f, PropertyDefRNA *dp)
{
PropertyRNA *prop;
StructRNA *srna;
srna= dp->srna;
prop= dp->prop;
switch(prop->type) {
@@ -296,12 +327,12 @@ static void rna_def_property_funcs(FILE *f, PropertyDefRNA *dp)
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
if(!prop->arraylength) {
if(!bprop->get) bprop->get= (void*)rna_def_property_get_func(f, prop, dp);
if(!bprop->set) bprop->set= (void*)rna_def_property_set_func(f, prop, dp);
if(!bprop->get) bprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp);
if(!bprop->set) bprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp);
}
else {
if(!bprop->getarray) bprop->getarray= (void*)rna_def_property_get_func(f, prop, dp);
if(!bprop->setarray) bprop->setarray= (void*)rna_def_property_set_func(f, prop, dp);
if(!bprop->getarray) bprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp);
if(!bprop->setarray) bprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp);
}
break;
}
@@ -309,12 +340,12 @@ static void rna_def_property_funcs(FILE *f, PropertyDefRNA *dp)
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
if(!prop->arraylength) {
if(!iprop->get) iprop->get= (void*)rna_def_property_get_func(f, prop, dp);
if(!iprop->set) iprop->set= (void*)rna_def_property_set_func(f, prop, dp);
if(!iprop->get) iprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp);
if(!iprop->set) iprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp);
}
else {
if(!iprop->getarray) iprop->getarray= (void*)rna_def_property_get_func(f, prop, dp);
if(!iprop->setarray) iprop->setarray= (void*)rna_def_property_set_func(f, prop, dp);
if(!iprop->getarray) iprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp);
if(!iprop->setarray) iprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp);
}
break;
}
@@ -322,43 +353,71 @@ static void rna_def_property_funcs(FILE *f, PropertyDefRNA *dp)
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
if(!prop->arraylength) {
if(!fprop->get) fprop->get= (void*)rna_def_property_get_func(f, prop, dp);
if(!fprop->set) fprop->set= (void*)rna_def_property_set_func(f, prop, dp);
if(!fprop->get) fprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp);
if(!fprop->set) fprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp);
}
else {
if(!fprop->getarray) fprop->getarray= (void*)rna_def_property_get_func(f, prop, dp);
if(!fprop->setarray) fprop->setarray= (void*)rna_def_property_set_func(f, prop, dp);
if(!fprop->getarray) fprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp);
if(!fprop->setarray) fprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp);
}
break;
}
case PROP_ENUM: {
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
if(!eprop->get) eprop->get= (void*)rna_def_property_get_func(f, prop, dp);
if(!eprop->set) eprop->set= (void*)rna_def_property_set_func(f, prop, dp);
if(!eprop->get) eprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp);
if(!eprop->set) eprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp);
break;
}
case PROP_STRING: {
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
if(!sprop->get) sprop->get= (void*)rna_def_property_get_func(f, prop, dp);
if(!sprop->length) sprop->length= (void*)rna_def_property_length_func(f, prop, dp);
if(!sprop->set) sprop->set= (void*)rna_def_property_set_func(f, prop, dp);
if(!sprop->get) sprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp);
if(!sprop->length) sprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp);
if(!sprop->set) sprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp);
break;
}
case PROP_POINTER: {
PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
if(!pprop->get) pprop->get= (void*)rna_def_property_get_func(f, prop, dp);
if(!pprop->set) pprop->set= (void*)rna_def_property_set_func(f, prop, dp);
if(!pprop->get) pprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp);
if(!pprop->set) pprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp);
if(!pprop->structtype && !pprop->type) {
fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have either type function or fixed type.\n", srna->cname, prop->cname);
DefRNA.error= 1;
}
break;
}
case PROP_COLLECTION: {
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
if(dp->dnatype && strcmp(dp->dnatype, "ListBase")==0)
if(dp->dnatype && strcmp(dp->dnatype, "ListBase")==0) {
if(!cprop->begin)
cprop->begin= (void*)rna_def_property_begin_func(f, prop, dp);
cprop->begin= (void*)rna_def_property_begin_func(f, srna, prop, dp);
}
else if(dp->dnalengthname) {
if(!cprop->begin)
cprop->begin= (void*)rna_def_property_begin_func(f, srna, prop, dp);
if(!cprop->length)
cprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp);
}
if(!cprop->begin) {
fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a begin function.\n", srna->cname, prop->cname);
DefRNA.error= 1;
}
if(!cprop->next) {
fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a next function.\n", srna->cname, prop->cname);
DefRNA.error= 1;
}
if(!cprop->get) {
fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a get function.\n", srna->cname, prop->cname);
DefRNA.error= 1;
}
if(!cprop->structtype && !cprop->type) {
fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have either type function or fixed type.\n", srna->cname, prop->cname);
DefRNA.error= 1;
}
break;
}
}
@@ -370,7 +429,7 @@ static const char *rna_find_type(const char *type)
for(ds=DefRNA.structs.first; ds; ds=ds->next)
if(ds->dnaname && strcmp(ds->dnaname, type)==0)
return ds->strct->cname;
return ds->srna->cname;
return NULL;
}
@@ -455,46 +514,46 @@ static const char *rna_property_subtypename(PropertyType type)
static void rna_generate_prototypes(BlenderRNA *brna, FILE *f)
{
StructRNA *strct;
StructRNA *srna;
for(strct=brna->structs.first; strct; strct=strct->next)
fprintf(f, "StructRNA RNA_%s;\n", strct->cname);
for(srna=brna->structs.first; srna; srna=srna->next)
fprintf(f, "StructRNA RNA_%s;\n", srna->cname);
fprintf(f, "\n");
fprintf(f, "BlenderRNA BLENDER_RNA = {");
strct= brna->structs.first;
if(strct) fprintf(f, "{&RNA_%s, ", strct->cname);
srna= brna->structs.first;
if(srna) fprintf(f, "{&RNA_%s, ", srna->cname);
else fprintf(f, "{NULL, ");
strct= brna->structs.last;
if(strct) fprintf(f, "&RNA_%s}", strct->cname);
srna= brna->structs.last;
if(srna) fprintf(f, "&RNA_%s}", srna->cname);
else fprintf(f, "NULL}");
fprintf(f, "};\n\n");
}
static void rna_generate_struct(BlenderRNA *brna, StructRNA *strct, FILE *f)
static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
{
PropertyRNA *prop;
fprintf(f, "/* %s */\n", strct->name);
fprintf(f, "/* %s */\n", srna->name);
if(strct->properties.first)
if(srna->properties.first)
fprintf(f, "\n");
for(prop=strct->properties.first; prop; prop=prop->next)
fprintf(f, "static %s rna_%s_%s;\n", rna_property_structname(prop->type), strct->cname, prop->cname);
for(prop=srna->properties.first; prop; prop=prop->next)
fprintf(f, "static %s rna_%s_%s;\n", rna_property_structname(prop->type), srna->cname, prop->cname);
fprintf(f, "\n");
for(prop=strct->properties.first; prop; prop=prop->next) {
for(prop=srna->properties.first; prop; prop=prop->next) {
switch(prop->type) {
case PROP_ENUM: {
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
int i;
if(eprop->item) {
fprintf(f, "static PropertyEnumItem rna_%s_%s_items[%d] = {", strct->cname, prop->cname, eprop->totitem);
fprintf(f, "static PropertyEnumItem rna_%s_%s_items[%d] = {", srna->cname, prop->cname, eprop->totitem);
for(i=0; i<eprop->totitem; i++) {
fprintf(f, "{%d, ", eprop->item[i].value);
@@ -513,7 +572,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *strct, FILE *f)
unsigned int i;
if(bprop->defaultarray) {
fprintf(f, "static int rna_%s_%s_default[%d] = {", strct->cname, prop->cname, prop->arraylength);
fprintf(f, "static int rna_%s_%s_default[%d] = {", srna->cname, prop->cname, prop->arraylength);
for(i=0; i<prop->arraylength; i++) {
fprintf(f, "%d", bprop->defaultarray[i]);
@@ -530,7 +589,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *strct, FILE *f)
unsigned int i;
if(iprop->defaultarray) {
fprintf(f, "static int rna_%s_%s_default[%d] = {", strct->cname, prop->cname, prop->arraylength);
fprintf(f, "static int rna_%s_%s_default[%d] = {", srna->cname, prop->cname, prop->arraylength);
for(i=0; i<prop->arraylength; i++) {
fprintf(f, "%d", iprop->defaultarray[i]);
@@ -547,7 +606,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *strct, FILE *f)
unsigned int i;
if(fprop->defaultarray) {
fprintf(f, "static float rna_%s_%s_default[%d] = {", strct->cname, prop->cname, prop->arraylength);
fprintf(f, "static float rna_%s_%s_default[%d] = {", srna->cname, prop->cname, prop->arraylength);
for(i=0; i<prop->arraylength; i++) {
rna_float_print(f, fprop->defaultarray[i]);
@@ -563,11 +622,11 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *strct, FILE *f)
break;
}
fprintf(f, "static %s rna_%s_%s = {\n", rna_property_structname(prop->type), strct->cname, prop->cname);
fprintf(f, "static %s rna_%s_%s = {\n", rna_property_structname(prop->type), srna->cname, prop->cname);
if(prop->next) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", strct->cname, prop->next->cname);
if(prop->next) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->cname, prop->next->cname);
else fprintf(f, "\t{NULL, ");
if(prop->prev) fprintf(f, "(PropertyRNA*)&rna_%s_%s,\n", strct->cname, prop->prev->cname);
if(prop->prev) fprintf(f, "(PropertyRNA*)&rna_%s_%s,\n", srna->cname, prop->prev->cname);
else fprintf(f, "NULL,\n");
fprintf(f, "\t"); rna_print_c_string(f, prop->cname);
fprintf(f, ", %d, ", prop->flag);
@@ -580,14 +639,14 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *strct, FILE *f)
case PROP_BOOLEAN: {
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
fprintf(f, "\t%s, %s, %s, %s, %d, ", rna_function_string(bprop->get), rna_function_string(bprop->set), rna_function_string(bprop->getarray), rna_function_string(bprop->setarray), bprop->defaultvalue);
if(bprop->defaultarray) fprintf(f, "rna_%s_%s_default\n", strct->name, prop->cname);
if(bprop->defaultarray) fprintf(f, "rna_%s_%s_default\n", srna->name, prop->cname);
else fprintf(f, "NULL\n");
break;
}
case PROP_INT: {
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
fprintf(f, "\t%s, %s, %s, %s, %d, %d, %d, %d, %d,\n\t%d, \n", rna_function_string(iprop->get), rna_function_string(iprop->set), rna_function_string(iprop->getarray), rna_function_string(iprop->setarray), iprop->softmin, iprop->softmax, iprop->hardmin, iprop->hardmax, iprop->step, iprop->defaultvalue);
if(iprop->defaultarray) fprintf(f, "rna_%s_%s_default\n", strct->name, prop->cname);
if(iprop->defaultarray) fprintf(f, "rna_%s_%s_default\n", srna->name, prop->cname);
else fprintf(f, "NULL\n");
break;
}
@@ -601,7 +660,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *strct, FILE *f)
rna_float_print(f, fprop->step); fprintf(f, ", ");
rna_float_print(f, fprop->precision); fprintf(f, ", ");
rna_float_print(f, fprop->defaultvalue); fprintf(f, ", ");
if(fprop->defaultarray) fprintf(f, "rna_%s_%s_default\n", strct->name, prop->cname);
if(fprop->defaultarray) fprintf(f, "rna_%s_%s_default\n", srna->name, prop->cname);
else fprintf(f, "NULL\n");
break;
}
@@ -613,7 +672,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *strct, FILE *f)
}
case PROP_ENUM: {
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
fprintf(f, "\t%s, %s, rna_%s_%s_items, %d, %d\n", rna_function_string(eprop->get), rna_function_string(eprop->set), strct->cname, prop->cname, eprop->totitem, eprop->defaultvalue);
fprintf(f, "\t%s, %s, rna_%s_%s_items, %d, %d\n", rna_function_string(eprop->get), rna_function_string(eprop->set), srna->cname, prop->cname, eprop->totitem, eprop->defaultvalue);
break;
}
case PROP_POINTER: {
@@ -635,29 +694,29 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *strct, FILE *f)
fprintf(f, "};\n\n");
}
fprintf(f, "StructRNA RNA_%s = {\n", strct->cname);
fprintf(f, "StructRNA RNA_%s = {\n", srna->cname);
if(strct->next) fprintf(f, "\t&RNA_%s, ", strct->next->cname);
if(srna->next) fprintf(f, "\t&RNA_%s, ", srna->next->cname);
else fprintf(f, "\tNULL, ");
if(strct->prev) fprintf(f, "&RNA_%s,\n", strct->prev->cname);
if(srna->prev) fprintf(f, "&RNA_%s,\n", srna->prev->cname);
else fprintf(f, "NULL,\n");
fprintf(f, "\t");
rna_print_c_string(f, strct->cname);
fprintf(f, ", %d, ", strct->flag);
rna_print_c_string(f, strct->name);
rna_print_c_string(f, srna->cname);
fprintf(f, ", %d, ", srna->flag);
rna_print_c_string(f, srna->name);
fprintf(f, ",\n");
prop= strct->nameproperty;
if(prop) fprintf(f, "\t(PropertyRNA*)&rna_%s_%s,\n", strct->cname, prop->cname);
prop= srna->nameproperty;
if(prop) fprintf(f, "\t(PropertyRNA*)&rna_%s_%s,\n", srna->cname, prop->cname);
else fprintf(f, "\tNULL,\n");
prop= strct->properties.first;
if(prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", strct->cname, prop->cname);
prop= srna->properties.first;
if(prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->cname, prop->cname);
else fprintf(f, "\t{NULL, ");
prop= strct->properties.last;
if(prop) fprintf(f, "(PropertyRNA*)&rna_%s_%s}\n", strct->cname, prop->cname);
prop= srna->properties.last;
if(prop) fprintf(f, "(PropertyRNA*)&rna_%s_%s}\n", srna->cname, prop->cname);
else fprintf(f, "NULL}\n");
fprintf(f, "};\n");
@@ -671,6 +730,9 @@ typedef struct RNAProcessItem {
} RNAProcessItem;
RNAProcessItem PROCESS_ITEMS[]= {
{"rna_ID.c", NULL},
{"rna_main.c", RNA_def_main},
{"rna_mesh.c", RNA_def_mesh},
{"rna_object.c", RNA_def_object},
{"rna_scene.c", RNA_def_scene},
{NULL, NULL}};
@@ -678,7 +740,7 @@ RNAProcessItem PROCESS_ITEMS[]= {
static int rna_preprocess(char *basedirectory, FILE *f)
{
BlenderRNA *brna;
StructRNA *strct;
StructRNA *srna;
int i, status;
fprintf(f, "\n/* Automatically generated struct definitions for the Data API.\n"
@@ -699,19 +761,20 @@ static int rna_preprocess(char *basedirectory, FILE *f)
fprintf(f, "#include \"RNA_types.h\"\n\n");
fprintf(f, "#include \"rna_internal.h\"\n\n");
for(i=0; PROCESS_ITEMS[i].define; i++)
for(i=0; PROCESS_ITEMS[i].filename; i++)
fprintf(f, "#include \"%s\"\n", PROCESS_ITEMS[i].filename);
fprintf(f, "\n");
for(i=0; PROCESS_ITEMS[i].define; i++)
PROCESS_ITEMS[i].define(brna);
for(i=0; PROCESS_ITEMS[i].filename; i++)
if(PROCESS_ITEMS[i].define)
PROCESS_ITEMS[i].define(brna);
rna_auto_types();
rna_generate_prototypes(brna, f);
rna_auto_functions(f);
for(strct=brna->structs.first; strct; strct=strct->next)
rna_generate_struct(brna, strct, f);
for(srna=brna->structs.first; srna; srna=srna->next)
rna_generate_struct(brna, srna, f);
status= DefRNA.error;

View File

@@ -0,0 +1,69 @@
/**
* $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): Blender Foundation (2008).
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <stdlib.h>
#include "RNA_define.h"
#include "RNA_types.h"
#include "DNA_ID.h"
#ifdef RNA_RUNTIME
/* name functions that ignore the first two ID characters */
static void rna_ID_name_get(PointerRNA *ptr, char *value)
{
ID *id= (ID*)ptr->data;
BLI_strncpy(value, id->name+2, sizeof(id->name)-2);
}
static int rna_ID_name_length(PointerRNA *ptr)
{
ID *id= (ID*)ptr->data;
return strlen(id->name+2);
}
static void rna_ID_name_set(PointerRNA *ptr, const char *value)
{
ID *id= (ID*)ptr->data;
BLI_strncpy(id->name+2, value, sizeof(id->name)-2);
}
#else
void RNA_def_ID(StructRNA *srna)
{
PropertyRNA *prop;
RNA_def_struct_flag(srna, STRUCT_ID);
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, "ID", "name");
RNA_def_property_ui_text(prop, "Name", "Object ID name.");
RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set");
RNA_def_struct_name_property(srna, prop);
}
#endif

View File

@@ -30,182 +30,217 @@
#include "RNA_access.h"
#include "RNA_types.h"
/* Accessors */
#include "rna_internal.h"
void RNA_property_notify(PropertyRNA *prop, struct bContext *C, void *data)
#include "BLI_blenlib.h"
#include "BLI_dynstr.h"
/* Pointer */
void RNA_pointer_main_get(struct Main *main, struct PointerRNA *r_ptr)
{
if(prop->notify)
prop->notify(C, data);
r_ptr->data= main;
r_ptr->type= &RNA_Main;
r_ptr->id.data= NULL;
r_ptr->id.type= NULL;
}
int RNA_property_editable(PropertyRNA *prop, struct bContext *C, void *data)
static void rna_pointer_inherit_id(PointerRNA *parent, PointerRNA *ptr)
{
if(ptr->type && ptr->type->flag & STRUCT_ID) {
ptr->id.data= ptr->data;
ptr->id.type= ptr->type;
}
else {
ptr->id.data= parent->id.data;
ptr->id.type= parent->id.type;
}
}
/* Property */
int RNA_property_editable(PropertyRNA *prop, PointerRNA *ptr)
{
return (prop->flag & PROP_EDITABLE);
}
int RNA_property_evaluatable(PropertyRNA *prop, struct bContext *C, void *data)
int RNA_property_evaluated(PropertyRNA *prop, PointerRNA *ptr)
{
return (prop->flag & PROP_EVALUATEABLE);
return (prop->flag & PROP_EVALUATED);
}
int RNA_property_boolean_get(PropertyRNA *prop, void *data)
void RNA_property_notify(PropertyRNA *prop, struct bContext *C, PointerRNA *ptr)
{
if(prop->notify)
prop->notify(C, ptr);
}
int RNA_property_boolean_get(PropertyRNA *prop, PointerRNA *ptr)
{
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
return bprop->get(data);
return bprop->get(ptr);
}
void RNA_property_boolean_set(PropertyRNA *prop, void *data, int value)
void RNA_property_boolean_set(PropertyRNA *prop, PointerRNA *ptr, int value)
{
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
bprop->set(data, value);
bprop->set(ptr, value);
}
int RNA_property_boolean_get_array(PropertyRNA *prop, void *data, int index)
int RNA_property_boolean_get_array(PropertyRNA *prop, PointerRNA *ptr, int index)
{
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
return bprop->getarray(data, index);
return bprop->getarray(ptr, index);
}
void RNA_property_boolean_set_array(PropertyRNA *prop, void *data, int index, int value)
void RNA_property_boolean_set_array(PropertyRNA *prop, PointerRNA *ptr, int index, int value)
{
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
bprop->setarray(data, index, value);
bprop->setarray(ptr, index, value);
}
int RNA_property_int_get(PropertyRNA *prop, void *data)
int RNA_property_int_get(PropertyRNA *prop, PointerRNA *ptr)
{
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
return iprop->get(data);
return iprop->get(ptr);
}
void RNA_property_int_set(PropertyRNA *prop, void *data, int value)
void RNA_property_int_set(PropertyRNA *prop, PointerRNA *ptr, int value)
{
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
iprop->set(data, value);
iprop->set(ptr, value);
}
int RNA_property_int_get_array(PropertyRNA *prop, void *data, int index)
int RNA_property_int_get_array(PropertyRNA *prop, PointerRNA *ptr, int index)
{
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
return iprop->getarray(data, index);
return iprop->getarray(ptr, index);
}
void RNA_property_int_set_array(PropertyRNA *prop, void *data, int index, int value)
void RNA_property_int_set_array(PropertyRNA *prop, PointerRNA *ptr, int index, int value)
{
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
iprop->setarray(data, index, value);
iprop->setarray(ptr, index, value);
}
float RNA_property_float_get(PropertyRNA *prop, void *data)
float RNA_property_float_get(PropertyRNA *prop, PointerRNA *ptr)
{
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
return fprop->get(data);
return fprop->get(ptr);
}
void RNA_property_float_set(PropertyRNA *prop, void *data, float value)
void RNA_property_float_set(PropertyRNA *prop, PointerRNA *ptr, float value)
{
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
fprop->set(data, value);
fprop->set(ptr, value);
}
float RNA_property_float_get_array(PropertyRNA *prop, void *data, int index)
float RNA_property_float_get_array(PropertyRNA *prop, PointerRNA *ptr, int index)
{
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
return fprop->getarray(data, index);
return fprop->getarray(ptr, index);
}
void RNA_property_float_set_array(PropertyRNA *prop, void *data, int index, float value)
void RNA_property_float_set_array(PropertyRNA *prop, PointerRNA *ptr, int index, float value)
{
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
fprop->setarray(data, index, value);
fprop->setarray(ptr, index, value);
}
void RNA_property_string_get(PropertyRNA *prop, void *data, char *value)
void RNA_property_string_get(PropertyRNA *prop, PointerRNA *ptr, char *value)
{
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
sprop->get(data, value);
sprop->get(ptr, value);
}
int RNA_property_string_length(PropertyRNA *prop, void *data)
int RNA_property_string_length(PropertyRNA *prop, PointerRNA *ptr)
{
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
return sprop->length(data);
return sprop->length(ptr);
}
void RNA_property_string_set(PropertyRNA *prop, void *data, const char *value)
void RNA_property_string_set(PropertyRNA *prop, PointerRNA *ptr, const char *value)
{
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
sprop->set(data, value);
sprop->set(ptr, value);
}
int RNA_property_enum_get(PropertyRNA *prop, void *data)
int RNA_property_enum_get(PropertyRNA *prop, PointerRNA *ptr)
{
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
return eprop->get(data);
return eprop->get(ptr);
}
void RNA_property_enum_set(PropertyRNA *prop, void *data, int value)
void RNA_property_enum_set(PropertyRNA *prop, PointerRNA *ptr, int value)
{
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
eprop->set(data, value);
eprop->set(ptr, value);
}
void *RNA_property_pointer_get(PropertyRNA *prop, void *data)
void RNA_property_pointer_get(PropertyRNA *prop, PointerRNA *ptr, PointerRNA *r_ptr)
{
PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
return pprop->get(data);
r_ptr->data= pprop->get(ptr);
if(r_ptr->data) {
r_ptr->type= RNA_property_pointer_type(prop, ptr);
rna_pointer_inherit_id(ptr, r_ptr);
}
else
memset(r_ptr, 0, sizeof(*r_ptr));
}
void RNA_property_pointer_set(PropertyRNA *prop, void *data, void *value)
void RNA_property_pointer_set(PropertyRNA *prop, PointerRNA *ptr, PointerRNA *ptr_value)
{
PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
pprop->set(data, value);
pprop->set(ptr, ptr_value->data);
}
StructRNA *RNA_property_pointer_type(PropertyRNA *prop, void *data)
StructRNA *RNA_property_pointer_type(PropertyRNA *prop, PointerRNA *ptr)
{
PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
if(pprop->type)
return pprop->type(data);
return pprop->type(ptr);
return pprop->structtype;
}
void RNA_property_collection_begin(PropertyRNA *prop, struct CollectionPropertyIterator *iter, void *data)
void RNA_property_collection_begin(PropertyRNA *prop, CollectionPropertyIterator *iter, PointerRNA *ptr)
{
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
cprop->begin(iter, data);
iter->pointer= *ptr;
cprop->begin(iter, ptr);
}
void RNA_property_collection_next(PropertyRNA *prop, struct CollectionPropertyIterator *iter)
void RNA_property_collection_next(PropertyRNA *prop, CollectionPropertyIterator *iter)
{
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
cprop->next(iter);
}
void RNA_property_collection_end(PropertyRNA *prop, struct CollectionPropertyIterator *iter)
void RNA_property_collection_end(PropertyRNA *prop, CollectionPropertyIterator *iter)
{
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
@@ -213,14 +248,21 @@ void RNA_property_collection_end(PropertyRNA *prop, struct CollectionPropertyIte
cprop->end(iter);
}
void *RNA_property_collection_get(PropertyRNA *prop, struct CollectionPropertyIterator *iter)
void RNA_property_collection_get(PropertyRNA *prop, CollectionPropertyIterator *iter, PointerRNA *r_ptr)
{
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
return cprop->get(iter);
r_ptr->data= cprop->get(iter);
if(r_ptr->data) {
r_ptr->type= RNA_property_collection_type(prop, iter);
rna_pointer_inherit_id(&iter->pointer, r_ptr);
}
else
memset(r_ptr, 0, sizeof(*r_ptr));
}
StructRNA *RNA_property_collection_type(PropertyRNA *prop, struct CollectionPropertyIterator *iter)
StructRNA *RNA_property_collection_type(PropertyRNA *prop, CollectionPropertyIterator *iter)
{
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
@@ -230,18 +272,18 @@ StructRNA *RNA_property_collection_type(PropertyRNA *prop, struct CollectionProp
return cprop->structtype;
}
int RNA_property_collection_length(PropertyRNA *prop, void *data)
int RNA_property_collection_length(PropertyRNA *prop, PointerRNA *ptr)
{
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
if(cprop->length) {
return cprop->length(data);
return cprop->length(ptr);
}
else {
CollectionPropertyIterator iter;
int length= 0;
for(cprop->begin(&iter, data); iter.valid; cprop->next(&iter))
for(cprop->begin(&iter, ptr); iter.valid; cprop->next(&iter))
length++;
if(cprop->end)
@@ -251,105 +293,114 @@ int RNA_property_collection_length(PropertyRNA *prop, void *data)
}
}
void *RNA_property_collection_lookup_int(PropertyRNA *prop, void *data, int key, StructRNA **type)
int RNA_property_collection_lookup_int(PropertyRNA *prop, PointerRNA *ptr, int key, PointerRNA *r_ptr)
{
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
void *value;
if(cprop->lookupint) {
value= cprop->lookupint(data, key, type);
/* we have a callback defined, use it */
r_ptr->data= cprop->lookupint(ptr, key, &r_ptr->type);
if(value && type && !*type)
*type= cprop->structtype;
if(r_ptr->data) {
if(!r_ptr->type)
r_ptr->type= cprop->structtype;
rna_pointer_inherit_id(ptr, r_ptr);
return value;
}
else {
CollectionPropertyIterator iter;
int i= 0;
void *value;
for(cprop->begin(&iter, data); iter.valid; cprop->next(&iter), i++)
if(i == key)
break;
if(iter.valid) {
value= cprop->get(&iter);
if(type) *type= RNA_property_collection_type(prop, &iter);
return 1;
}
else {
value= NULL;
if(type) *type= NULL;
memset(r_ptr, 0, sizeof(*r_ptr));
return 0;
}
}
else {
/* no callback defined, just iterate and find the nth item */
CollectionPropertyIterator iter;
int i;
if(cprop->end)
cprop->end(&iter);
RNA_property_collection_begin(prop, &iter, ptr);
for(i=0; iter.valid; RNA_property_collection_next(prop, &iter), i++) {
if(i == key) {
RNA_property_collection_get(prop, &iter, r_ptr);
break;
}
}
RNA_property_collection_end(prop, &iter);
return value;
if(!iter.valid)
memset(r_ptr, 0, sizeof(*r_ptr));
return iter.valid;
}
}
void *RNA_property_collection_lookup_string(PropertyRNA *prop, void *data, const char *key, StructRNA **type)
int RNA_property_collection_lookup_string(PropertyRNA *prop, PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
{
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
void *value;
if(cprop->lookupstring) {
value= cprop->lookupstring(data, key, type);
/* we have a callback defined, use it */
r_ptr->data= cprop->lookupstring(ptr, key, &r_ptr->type);
if(value && type && !*type)
*type= cprop->structtype;
if(r_ptr->data) {
if(!r_ptr->type)
r_ptr->type= cprop->structtype;
rna_pointer_inherit_id(ptr, r_ptr);
return value;
return 1;
}
else {
memset(r_ptr, 0, sizeof(*r_ptr));
return 0;
}
}
else {
/* no callback defined, compare with name properties if they exist */
CollectionPropertyIterator iter;
StructRNA *itertype= NULL;
StringPropertyRNA *sprop;
void *value= NULL;
PropertyRNA *prop;
PointerRNA iterptr;
char name[256], *nameptr;
int length, alloc, found= 0;
for(cprop->begin(&iter, data); iter.valid && !found; cprop->next(&iter)) {
itertype= RNA_property_collection_type(prop, &iter);
RNA_property_collection_begin(prop, &iter, ptr);
for(; iter.valid; RNA_property_collection_next(prop, &iter)) {
RNA_property_collection_get(prop, &iter, &iterptr);
if(itertype->nameproperty) {
value= cprop->get(&iter);
if(iterptr.data && iterptr.type->nameproperty) {
prop= iterptr.type->nameproperty;
if(value) {
sprop= (StringPropertyRNA*)itertype->nameproperty;
length= sprop->length(value);
length= RNA_property_string_length(prop, &iterptr);
if(sizeof(name)-1 < length) {
nameptr= name;
alloc= 0;
}
else {
nameptr= MEM_mallocN(sizeof(char)*length+1, "RNA_lookup_string");
alloc= 1;
}
sprop->get(value, nameptr);
if(strcmp(nameptr, key) == 0)
found= 1;
if(alloc)
MEM_freeN(nameptr);
if(sizeof(name)-1 < length) {
nameptr= name;
alloc= 0;
}
else {
nameptr= MEM_mallocN(sizeof(char)*length+1, "RNA_lookup_string");
alloc= 1;
}
RNA_property_string_get(prop, &iterptr, nameptr);
if(strcmp(nameptr, key) == 0) {
*r_ptr= iterptr;
found= 1;
}
if(alloc)
MEM_freeN(nameptr);
if(found)
break;
}
}
RNA_property_collection_end(prop, &iter);
if(found && type)
*type= itertype;
if(!iter.valid)
memset(r_ptr, 0, sizeof(*r_ptr));
if(cprop->end)
cprop->end(&iter);
return value;
return iter.valid;
}
return NULL;
}
/* Standard iterator functions */
@@ -371,12 +422,6 @@ void *rna_iterator_listbase_get(CollectionPropertyIterator *iter)
return iter->internal;
}
typedef struct ArrayIterator {
char *ptr;
char *endptr;
int itemsize;
} ArrayIterator;
void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length)
{
ArrayIterator *internal;
@@ -384,6 +429,7 @@ void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int i
internal= MEM_callocN(sizeof(ArrayIterator), "ArrayIterator");
internal->ptr= ptr;
internal->endptr= ((char*)ptr)+length*itemsize;
internal->itemsize= itemsize;
iter->internal= internal;
iter->valid= (internal->ptr != internal->endptr);
@@ -409,3 +455,238 @@ void rna_iterator_array_end(CollectionPropertyIterator *iter)
MEM_freeN(iter->internal);
}
/* RNA Path - Experiment */
static char *rna_path_token(const char **path, char *fixedbuf, int fixedlen, int bracket)
{
const char *p;
char *buf;
int i, j, len, escape;
len= 0;
if(bracket) {
/* get data between [], check escaping ] with \] */
if(**path == '[') (*path)++;
else return NULL;
p= *path;
escape= 0;
while(*p && (*p != ']' || escape)) {
escape= (*p == '\\');
len++;
p++;
}
if(*p != ']') return NULL;
}
else {
/* get data until . or [ */
p= *path;
while(*p && *p != '.' && *p != '[') {
len++;
p++;
}
}
/* empty, return */
if(len == 0)
return NULL;
/* try to use fixed buffer if possible */
if(len+1 < fixedlen)
buf= fixedbuf;
else
buf= MEM_callocN(sizeof(char)*(len+1), "rna_path_token");
/* copy string, taking into account escaped ] */
for(p=*path, i=0, j=0; i<len; i++, p++) {
if(*p == '\\' && *(p+1) == ']');
else buf[j++]= *p;
}
buf[j]= 0;
/* set path to start of next token */
if(*p == ']') p++;
if(*p == '.') p++;
*path= p;
return buf;
}
int RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
{
PropertyRNA *prop;
PointerRNA curptr, nextptr;
char fixedbuf[256], *token;
int len, intkey;
prop= NULL;
curptr= *ptr;
while(*path) {
/* look up property name in current struct */
token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 0);
if(!token)
return 0;
for(prop=curptr.type->properties.first; prop; prop=prop->next)
if(strcmp(token, prop->cname) == 0)
break;
if(token != fixedbuf)
MEM_freeN(token);
if(!prop)
return 0;
/* now look up the value of this property if it is a pointer or
* collection, otherwise return the property rna so that the
* caller can read the value of the property itself */
if(prop->type == PROP_POINTER) {
RNA_property_pointer_get(prop, &curptr, &nextptr);
if(nextptr.data)
curptr= nextptr;
else
return 0;
}
else if(prop->type == PROP_COLLECTION && *path) {
/* resolve the lookup with [] brackets */
token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
if(!token)
return 0;
len= strlen(token);
/* check for "" to see if it is a string */
if(len >= 2 && *token == '"' && token[len-2] == '"') {
/* strip away "" */
token[len-2]= 0;
RNA_property_collection_lookup_string(prop, &curptr, token+1, &nextptr);
}
else {
/* otherwise do int lookup */
intkey= atoi(token);
RNA_property_collection_lookup_int(prop, &curptr, intkey, &nextptr);
}
if(token != fixedbuf)
MEM_freeN(token);
if(nextptr.data)
curptr= nextptr;
else
return 0;
}
}
*r_ptr= curptr;
*r_prop= prop;
return 1;
}
char *RNA_path_append(const char *path, PropertyRNA *prop, int intkey, const char *strkey)
{
DynStr *dynstr;
const char *s;
char appendstr[128], *result;
dynstr= BLI_dynstr_new();
/* add .cname */
if(path) {
BLI_dynstr_append(dynstr, (char*)path);
if(*path)
BLI_dynstr_append(dynstr, ".");
}
BLI_dynstr_append(dynstr, (char*)prop->cname);
if(prop->type == PROP_COLLECTION) {
/* add ["strkey"] or [intkey] */
BLI_dynstr_append(dynstr, "[");
if(strkey) {
BLI_dynstr_append(dynstr, "\"");
for(s=strkey; *s; s++) {
if(*s == '[') {
appendstr[0]= '\\';
appendstr[1]= *s;
appendstr[2]= 0;
}
else {
appendstr[0]= *s;
appendstr[1]= 0;
}
BLI_dynstr_append(dynstr, appendstr);
}
BLI_dynstr_append(dynstr, "\"");
}
else {
sprintf(appendstr, "%d", intkey);
BLI_dynstr_append(dynstr, appendstr);
}
BLI_dynstr_append(dynstr, "]");
}
result= BLI_dynstr_get_cstring(dynstr);
BLI_dynstr_free(dynstr);
return result;
}
char *RNA_path_back(const char *path)
{
char fixedbuf[256];
const char *previous, *current;
char *result, *token;
int i;
if(!path)
return NULL;
previous= NULL;
current= path;
/* parse token by token until the end, then we back up to the previous
* position and strip of the next token to get the path one step back */
while(*current) {
token= rna_path_token(&current, fixedbuf, sizeof(fixedbuf), 0);
if(!token)
return NULL;
if(token != fixedbuf)
MEM_freeN(token);
/* in case of collection we also need to strip off [] */
token= rna_path_token(&current, fixedbuf, sizeof(fixedbuf), 1);
if(token && token != fixedbuf)
MEM_freeN(token);
if(!*current)
break;
previous= current;
}
if(!previous)
return NULL;
/* copy and strip off last token */
i= previous - path;
result= BLI_strdup(path);
if(i > 0 && result[i-1] == '.') i--;
result[i]= 0;
return result;
}

View File

@@ -157,15 +157,15 @@ BlenderRNA *RNA_create()
void RNA_define_free(BlenderRNA *brna)
{
StructDefRNA *strct;
StructDefRNA *srna;
AllocDefRNA *alloc;
for(alloc=DefRNA.allocs.first; alloc; alloc=alloc->next)
MEM_freeN(alloc->mem);
rna_freelistN(&DefRNA.allocs);
for(strct=DefRNA.structs.first; strct; strct=strct->next)
rna_freelistN(&strct->properties);
for(srna=DefRNA.structs.first; srna; srna=srna->next)
rna_freelistN(&srna->properties);
rna_freelistN(&DefRNA.structs);
@@ -179,12 +179,12 @@ void RNA_define_free(BlenderRNA *brna)
void RNA_free(BlenderRNA *brna)
{
StructRNA *strct;
StructRNA *srna;
RNA_define_free(brna);
for(strct=brna->structs.first; strct; strct=strct->next)
rna_freelistN(&strct->properties);
for(srna=brna->structs.first; srna; srna=srna->next)
rna_freelistN(&srna->properties);
rna_freelistN(&brna->structs);
@@ -195,23 +195,23 @@ void RNA_free(BlenderRNA *brna)
StructRNA *RNA_def_struct(BlenderRNA *brna, const char *cname, const char *name)
{
StructRNA *strct;
StructRNA *srna;
StructDefRNA *ds;
ds= MEM_callocN(sizeof(StructDefRNA), "StructDefRNA");
rna_addtail(&DefRNA.structs, ds);
strct= MEM_callocN(sizeof(StructRNA), "StructRNA");
strct->cname= cname;
strct->name= name;
srna= MEM_callocN(sizeof(StructRNA), "StructRNA");
srna->cname= cname;
srna->name= name;
ds->strct= strct;
ds->srna= srna;
rna_addtail(&brna->structs, strct);
rna_addtail(&brna->structs, srna);
RNA_def_struct_sdna(strct, strct->cname);
RNA_def_struct_sdna(srna, srna->cname);
return strct;
return srna;
}
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
@@ -232,16 +232,21 @@ void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *prop)
{
if(prop->type != PROP_STRING) {
fprintf(stderr, "RNA_def_struct_name_property: must be a string property.\n");
fprintf(stderr, "RNA_def_struct_name_property: %s.%s, must be a string property.\n", srna->cname, prop->cname);
DefRNA.error= 1;
}
else
srna->nameproperty= prop;
}
void RNA_def_struct_flag(StructRNA *srna, int flag)
{
srna->flag= flag;
}
/* Property Definition */
PropertyRNA *RNA_def_property(StructRNA *strct, const char *cname, int type, int subtype)
PropertyRNA *RNA_def_property(StructRNA *srna, const char *cname, int type, int subtype)
{
StructDefRNA *ds;
PropertyDefRNA *dp;
@@ -298,12 +303,12 @@ PropertyRNA *RNA_def_property(StructRNA *strct, const char *cname, int type, int
prop= MEM_callocN(sizeof(CollectionPropertyRNA), "CollectionPropertyRNA");
break;
default:
fprintf(stderr, "RNA_def_property: invalid property type.\n");
fprintf(stderr, "RNA_def_property: %s.%s, invalid property type.\n", ds->srna->cname, cname);
DefRNA.error= 1;
return NULL;
}
dp->strct= strct;
dp->srna= srna;
dp->prop= prop;
prop->cname= cname;
@@ -311,65 +316,78 @@ PropertyRNA *RNA_def_property(StructRNA *strct, const char *cname, int type, int
prop->subtype= subtype;
prop->name= cname;
prop->description= "";
prop->flag= PROP_EDITABLE|PROP_EVALUATEABLE;
if(type == PROP_COLLECTION)
prop->flag= 0;
else if(type == PROP_POINTER)
prop->flag= PROP_EDITABLE;
else
prop->flag= PROP_EDITABLE|PROP_DRIVEABLE;
switch(type) {
case PROP_BOOLEAN:
DefRNA.silent= 1;
RNA_def_property_boolean_sdna(prop, strct->cname, cname, 0);
RNA_def_property_boolean_sdna(prop, srna->cname, cname, 0);
DefRNA.silent= 0;
break;
case PROP_INT: {
DefRNA.silent= 1;
RNA_def_property_int_sdna(prop, strct->cname, cname);
RNA_def_property_int_sdna(prop, srna->cname, cname);
DefRNA.silent= 0;
break;
}
case PROP_FLOAT: {
DefRNA.silent= 1;
RNA_def_property_float_sdna(prop, strct->cname, cname);
RNA_def_property_float_sdna(prop, srna->cname, cname);
DefRNA.silent= 0;
break;
}
case PROP_STRING: {
DefRNA.silent= 1;
RNA_def_property_string_sdna(prop, strct->cname, cname);
RNA_def_property_string_sdna(prop, srna->cname, cname);
DefRNA.silent= 0;
break;
}
case PROP_ENUM:
DefRNA.silent= 1;
RNA_def_property_enum_sdna(prop, strct->cname, cname);
RNA_def_property_enum_sdna(prop, srna->cname, cname);
DefRNA.silent= 0;
break;
case PROP_POINTER:
DefRNA.silent= 1;
RNA_def_property_pointer_sdna(prop, strct->cname, cname);
RNA_def_property_pointer_sdna(prop, srna->cname, cname);
DefRNA.silent= 0;
break;
case PROP_COLLECTION:
DefRNA.silent= 1;
RNA_def_property_collection_sdna(prop, strct->cname, cname);
RNA_def_property_collection_sdna(prop, srna->cname, cname, NULL);
DefRNA.silent= 0;
break;
}
rna_addtail(&strct->properties, prop);
rna_addtail(&srna->properties, prop);
return prop;
}
void RNA_def_property_access(PropertyRNA *prop, int editable, int evaluatable)
void RNA_def_property_flag(PropertyRNA *prop, int flag)
{
if(editable) prop->flag |= PROP_EDITABLE;
else prop->flag &= ~PROP_EDITABLE;
StructDefRNA *ds= DefRNA.structs.last;
if(evaluatable) prop->flag |= PROP_EVALUATEABLE;
else prop->flag &= ~PROP_EVALUATEABLE;
prop->flag= flag;
if(prop->type != PROP_POINTER && prop->type != PROP_COLLECTION) {
if(flag & (PROP_EVALUATE_DEPENDENCY|PROP_INVERSE_EVALUATE_DEPENDENCY|PROP_RENDER_DEPENDENCY|PROP_INVERSE_RENDER_DEPENDENCY)) {
fprintf(stderr, "RNA_def_property_flag: %s.%s, only pointer and collection types can create dependencies.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
}
}
}
void RNA_def_property_array(PropertyRNA *prop, int arraylength)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_BOOLEAN:
case PROP_INT:
@@ -377,7 +395,7 @@ void RNA_def_property_array(PropertyRNA *prop, int arraylength)
prop->arraylength= arraylength;
break;
default:
fprintf(stderr, "RNA_def_property_array: only boolean/int/float can be array.\n");
fprintf(stderr, "RNA_def_property_array: %s.%s, only boolean/int/float can be array.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -391,6 +409,8 @@ void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *d
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, double precision)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_INT: {
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
@@ -408,7 +428,7 @@ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double
break;
}
default:
fprintf(stderr, "RNA_def_property_ui_range: invalid type for ui range.\n");
fprintf(stderr, "RNA_def_property_ui_range: %s.%s, invalid type for ui range.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -416,6 +436,8 @@ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_INT: {
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
@@ -434,7 +456,7 @@ void RNA_def_property_range(PropertyRNA *prop, double min, double max)
break;
}
default:
fprintf(stderr, "RNA_def_property_range: invalid type for range.\n");
fprintf(stderr, "RNA_def_property_range: %s.%s, invalid type for range.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -442,6 +464,8 @@ void RNA_def_property_range(PropertyRNA *prop, double min, double max)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_POINTER: {
PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
@@ -454,7 +478,7 @@ void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
break;
}
default:
fprintf(stderr, "RNA_def_property_struct_type: invalid type for struct type.\n");
fprintf(stderr, "RNA_def_property_struct_type: %s.%s, invalid type for struct type.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -462,6 +486,7 @@ void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_property_enum_items(PropertyRNA *prop, const PropertyEnumItem *item)
{
StructDefRNA *ds= DefRNA.structs.last;
int i;
switch(prop->type) {
@@ -475,7 +500,7 @@ void RNA_def_property_enum_items(PropertyRNA *prop, const PropertyEnumItem *item
break;
}
default:
fprintf(stderr, "RNA_def_property_struct_type: invalid type for struct type.\n");
fprintf(stderr, "RNA_def_property_struct_type: %s.%s, invalid type for struct type.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -483,6 +508,8 @@ void RNA_def_property_enum_items(PropertyRNA *prop, const PropertyEnumItem *item
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_STRING: {
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
@@ -490,7 +517,7 @@ void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
break;
}
default:
fprintf(stderr, "RNA_def_property_string_maxlength: type is not string.\n");
fprintf(stderr, "RNA_def_property_string_maxlength: %s.%s, type is not string.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -498,6 +525,8 @@ void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
void RNA_def_property_boolean_default(PropertyRNA *prop, int value)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_BOOLEAN: {
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
@@ -505,7 +534,7 @@ void RNA_def_property_boolean_default(PropertyRNA *prop, int value)
break;
}
default:
fprintf(stderr, "RNA_def_property_boolean_default: type is not boolean.\n");
fprintf(stderr, "RNA_def_property_boolean_default: %s.%s, type is not boolean.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -513,6 +542,8 @@ void RNA_def_property_boolean_default(PropertyRNA *prop, int value)
void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_BOOLEAN: {
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
@@ -520,7 +551,7 @@ void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array)
break;
}
default:
fprintf(stderr, "RNA_def_property_boolean_default: type is not boolean.\n");
fprintf(stderr, "RNA_def_property_boolean_default: %s.%s, type is not boolean.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -528,6 +559,8 @@ void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array)
void RNA_def_property_int_default(PropertyRNA *prop, int value)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_INT: {
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
@@ -535,7 +568,7 @@ void RNA_def_property_int_default(PropertyRNA *prop, int value)
break;
}
default:
fprintf(stderr, "RNA_def_property_int_default: type is not int.\n");
fprintf(stderr, "RNA_def_property_int_default: %s.%s, type is not int.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -543,6 +576,8 @@ void RNA_def_property_int_default(PropertyRNA *prop, int value)
void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_INT: {
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
@@ -550,7 +585,7 @@ void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array)
break;
}
default:
fprintf(stderr, "RNA_def_property_int_default: type is not int.\n");
fprintf(stderr, "RNA_def_property_int_default: %s.%s, type is not int.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -558,6 +593,8 @@ void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array)
void RNA_def_property_float_default(PropertyRNA *prop, float value)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_FLOAT: {
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
@@ -565,7 +602,7 @@ void RNA_def_property_float_default(PropertyRNA *prop, float value)
break;
}
default:
fprintf(stderr, "RNA_def_property_float_default: type is not float.\n");
fprintf(stderr, "RNA_def_property_float_default: %s.%s, type is not float.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -573,6 +610,8 @@ void RNA_def_property_float_default(PropertyRNA *prop, float value)
void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_FLOAT: {
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
@@ -580,7 +619,7 @@ void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
break;
}
default:
fprintf(stderr, "RNA_def_property_float_default: type is not float.\n");
fprintf(stderr, "RNA_def_property_float_default: %s.%s, type is not float.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -588,6 +627,8 @@ void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_STRING: {
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
@@ -595,7 +636,7 @@ void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
break;
}
default:
fprintf(stderr, "RNA_def_property_string_default: type is not string.\n");
fprintf(stderr, "RNA_def_property_string_default: %s.%s, type is not string.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -603,6 +644,8 @@ void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
void RNA_def_property_enum_default(PropertyRNA *prop, int value)
{
StructDefRNA *ds= DefRNA.structs.last;
switch(prop->type) {
case PROP_ENUM: {
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
@@ -610,7 +653,7 @@ void RNA_def_property_enum_default(PropertyRNA *prop, int value)
break;
}
default:
fprintf(stderr, "RNA_def_property_enum_default: type is not enum.\n");
fprintf(stderr, "RNA_def_property_enum_default: %s.%s, type is not enum.\n", ds->srna->cname, prop->cname);
DefRNA.error= 1;
break;
}
@@ -734,7 +777,7 @@ void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, co
}
}
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
{
PropertyDefRNA *dp;
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
@@ -754,16 +797,39 @@ void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname,
cprop->get= (PropCollectionGetFunc)"rna_iterator_listbase_get";
}
}
if(dp && lengthpropname) {
DNAStructMember smember;
StructDefRNA *ds= DefRNA.structs.last;
if(!structname)
structname= ds->dnaname;
if(!rna_find_sdna_member(DefRNA.sdna, structname, lengthpropname, &smember)) {
if(!DefRNA.silent) {
fprintf(stderr, "RNA_def_property_collection_sdna: %s.%s not found.\n", structname, lengthpropname);
DefRNA.error= 1;
}
}
else {
dp->dnalengthstructname= structname;
dp->dnalengthname= lengthpropname;
cprop->next= (PropCollectionNextFunc)"rna_iterator_array_next";
cprop->get= (PropCollectionGetFunc)"rna_iterator_array_get";
cprop->end= (PropCollectionEndFunc)"rna_iterator_array_end";
}
}
}
/* Functions */
void RNA_def_property_notify_func(PropertyRNA *prop, char *notify)
void RNA_def_property_notify_func(PropertyRNA *prop, const char *notify)
{
if(notify) prop->notify= (PropNotifyFunc)notify;
}
void RNA_def_property_boolean_funcs(PropertyRNA *prop, char *get, char *set)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
{
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
@@ -777,7 +843,7 @@ void RNA_def_property_boolean_funcs(PropertyRNA *prop, char *get, char *set)
}
}
void RNA_def_property_int_funcs(PropertyRNA *prop, char *get, char *set)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set)
{
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
@@ -791,7 +857,7 @@ void RNA_def_property_int_funcs(PropertyRNA *prop, char *get, char *set)
}
}
void RNA_def_property_float_funcs(PropertyRNA *prop, char *get, char *set)
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set)
{
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
@@ -805,7 +871,7 @@ void RNA_def_property_float_funcs(PropertyRNA *prop, char *get, char *set)
}
}
void RNA_def_property_enum_funcs(PropertyRNA *prop, char *get, char *set)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set)
{
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
@@ -813,7 +879,7 @@ void RNA_def_property_enum_funcs(PropertyRNA *prop, char *get, char *set)
if(set) eprop->set= (PropEnumSetFunc)set;
}
void RNA_def_property_string_funcs(PropertyRNA *prop, char *get, char *length, char *set)
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
{
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
@@ -822,7 +888,7 @@ void RNA_def_property_string_funcs(PropertyRNA *prop, char *get, char *length, c
if(set) sprop->set= (PropStringSetFunc)set;
}
void RNA_def_property_pointer_funcs(PropertyRNA *prop, char *get, char *type, char *set)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *type, const char *set)
{
PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
@@ -831,7 +897,7 @@ void RNA_def_property_pointer_funcs(PropertyRNA *prop, char *get, char *type, ch
if(set) pprop->set= (PropPointerSetFunc)set;
}
void RNA_def_property_collection_funcs(PropertyRNA *prop, char *begin, char *next, char *end, char *get, char *type, char *length, char *lookupint, char *lookupstring)
void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *type, const char *length, const char *lookupint, const char *lookupstring)
{
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;

View File

@@ -0,0 +1,91 @@
#include <stdio.h>
#include <stdlib.h>
#include "DNA_scene_types.h"
#include "RNA_access.h"
#include "RNA_types.h"
#include "BKE_main.h"
typedef struct RNAGenDeps {
void *udata;
PropDependencyCallback cb;
} RNAGenDeps;
static void rna_generate_deps(RNAGenDeps *gen, PointerRNA *ptr, PointerRNA *idptr)
{
PropertyRNA *prop;
PointerRNA pptr;
CollectionPropertyIterator iter;
/* traverse recursively into ID struct properties, other
* pointers we potentially add as dependencies */
for(prop=ptr->type->properties.first; prop; prop=prop->next) {
if(prop->type == PROP_POINTER) {
RNA_property_pointer_get(prop, ptr, &pptr);
if(pptr.data && pptr.type) {
if(idptr && (pptr.type->flag & STRUCT_ID)) {
if(prop->flag & PROP_EVALUATE_DEPENDENCY)
gen->cb(gen->udata, ptr, &pptr);
else if(prop->flag & PROP_INVERSE_EVALUATE_DEPENDENCY)
gen->cb(gen->udata, ptr, &pptr);
}
else
rna_generate_deps(gen, &pptr, (idptr)? idptr: &pptr);
}
}
else if(prop->type == PROP_COLLECTION) {
RNA_property_collection_begin(prop, &iter, ptr);
while(iter.valid) {
RNA_property_collection_get(prop, &iter, &pptr);
if(pptr.data && pptr.type) {
if(idptr && (pptr.type->flag & STRUCT_ID)) {
if(prop->flag & PROP_EVALUATE_DEPENDENCY)
gen->cb(gen->udata, ptr, &pptr);
else if(prop->flag & PROP_INVERSE_EVALUATE_DEPENDENCY)
gen->cb(gen->udata, ptr, &pptr);
}
else
rna_generate_deps(gen, &pptr, (idptr)? idptr: &pptr);
}
RNA_property_collection_next(prop, &iter);
}
RNA_property_collection_end(prop, &iter);
}
}
}
void RNA_generate_dependencies(PointerRNA *ptr, void *udata, PropDependencyCallback cb)
{
RNAGenDeps gen;
gen.udata= udata;
gen.cb= cb;
rna_generate_deps(&gen, ptr, NULL);
}
void RNA_test_dependencies_cb(void *udata, PointerRNA *from, PointerRNA *to)
{
PropertyRNA *prop;
char name[256], nameto[256];
prop= from->type? from->type->nameproperty: NULL;
if(prop) RNA_property_string_get(prop, from, name);
else strcpy(name, "unknown");
prop= from->type? from->type->nameproperty: NULL;
if(prop) RNA_property_string_get(prop, to, nameto);
else strcpy(nameto, "unknown");
printf("%s (%s) -> %s (%s)\n", name, from->type->cname, nameto, to->type->cname);
}

View File

@@ -35,11 +35,13 @@ struct ListBase;
typedef struct PropertyDefRNA {
struct PropertyDefRNA *next, *prev;
struct StructRNA *strct;
struct StructRNA *srna;
struct PropertyRNA *prop;
const char *dnastructname;
const char *dnaname;
const char *dnalengthstructname;
const char *dnalengthname;
const char *dnatype;
int dnaarraylength;
@@ -49,7 +51,7 @@ typedef struct PropertyDefRNA {
typedef struct StructDefRNA {
struct StructDefRNA *next, *prev;
struct StructRNA *strct;
struct StructRNA *srna;
const char *dnaname;
ListBase properties;
@@ -71,6 +73,15 @@ extern BlenderDefRNA DefRNA;
/* Define functions for all types */
extern StructRNA RNA_Main;
extern StructRNA RNA_Mesh;
extern StructRNA RNA_Object;
extern StructRNA RNA_Scene;
void RNA_def_ID(struct StructRNA *srna);
void RNA_def_main(struct BlenderRNA *brna);
void RNA_def_mesh(struct BlenderRNA *brna);
void RNA_def_object(struct BlenderRNA *brna);
void RNA_def_scene(struct BlenderRNA *brna);
@@ -80,6 +91,12 @@ void rna_iterator_listbase_begin(struct CollectionPropertyIterator *iter, struct
void rna_iterator_listbase_next(struct CollectionPropertyIterator *iter);
void *rna_iterator_listbase_get(struct CollectionPropertyIterator *iter);
typedef struct ArrayIterator {
char *ptr;
char *endptr;
int itemsize;
} ArrayIterator;
void rna_iterator_array_begin(struct CollectionPropertyIterator *iter, void *ptr, int itemsize, int length);
void rna_iterator_array_next(struct CollectionPropertyIterator *iter);
void *rna_iterator_array_get(struct CollectionPropertyIterator *iter);

View File

@@ -0,0 +1,252 @@
/**
* $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): Blender Foundation (2008).
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <stdlib.h>
#include <string.h>
#include "RNA_define.h"
#include "RNA_types.h"
#ifdef RNA_RUNTIME
#include "BKE_main.h"
/* all the list begin functions are added manually here, Main is not in SDNA */
static void rna_Main_scene_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->scene);
}
static void rna_Main_object_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->object);
}
#if 0
static void rna_Main_library_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->library);
}
#endif
static void rna_Main_mesh_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->mesh);
}
#if 0
static void rna_Main_curve_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->curve);
}
static void rna_Main_mball_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->mball);
}
static void rna_Main_mat_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->mat);
}
static void rna_Main_tex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->tex);
}
static void rna_Main_image_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->image);
}
static void rna_Main_latt_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->latt);
}
static void rna_Main_lamp_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->lamp);
}
static void rna_Main_camera_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->camera);
}
static void rna_Main_ipo_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->ipo);
}
static void rna_Main_key_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->key);
}
static void rna_Main_world_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->world);
}
static void rna_Main_screen_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->screen);
}
static void rna_Main_script_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->script);
}
static void rna_Main_vfont_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->vfont);
}
static void rna_Main_text_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->text);
}
static void rna_Main_sound_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->sound);
}
static void rna_Main_group_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->group);
}
static void rna_Main_armature_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->armature);
}
static void rna_Main_action_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->action);
}
static void rna_Main_nodetree_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->nodetree);
}
static void rna_Main_brush_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->brush);
}
static void rna_Main_particle_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->particle);
}
static void rna_Main_wm_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->wm);
}
#endif
#else
void RNA_def_main(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
const char *lists[][4]= {
{"scenes", "Scene", "rna_Main_scene_begin"},
{"objects", "Object", "rna_Main_object_begin"},
{"meshes", "Mesh", "rna_Main_mesh_begin"},
{NULL, NULL, NULL},
{"libraries", "Library", "rna_Main_library_begin"},
{"curves", "Curve", "rna_Main_curve_begin"},
{"metaballs", "MBall", "rna_Main_mball_begin"},
{"materials", "Material", "rna_Main_mat_begin"},
{"textures", "Texture", "rna_Main_tex_begin"},
{"images", "Image", "rna_Main_image_begin"},
{"lattices", "Lattice", "rna_Main_latt_begin"},
{"lamps", "Lamp", "rna_Main_lamp_begin"},
{"cameras", "Camera", "rna_Main_camera_begin"},
{"ipos", "Ipo", "rna_Main_ipo_begin"},
{"keys", "Key", "rna_Main_key_begin"},
{"worlds", "World", "rna_Main_world_begin"},
{"screens", "Screen", "rna_Main_screen_begin"},
{"scripts", "Script", "rna_Main_script_begin"},
{"vfonts", "VFont", "rna_Main_vfont_begin"},
{"texts", "Text", "rna_Main_text_begin"},
{"sounds", "Sound", "rna_Main_sound_begin"},
{"groups", "Group", "rna_Main_group_begin"},
{"armatures", "Armature", "rna_Main_armature_begin"},
{"actions", "Action", "rna_Main_action_begin"},
{"nodegroups", "NodeGroup", "rna_Main_nodetree_begin"},
{"brushes", "Brush", "rna_Main_brush_begin"},
{"particles", "Particle", "rna_Main_particle_begin"},
{"windowmanagers", "wmWindowManager", "rna_Main_wm_begin"},
{NULL, NULL, NULL}};
int i;
srna= RNA_def_struct(brna, "Main", "Main");
for(i=0; lists[i][0]; i++)
{
prop= RNA_def_property(srna, lists[i][0], PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, lists[i][1]);
RNA_def_property_collection_funcs(prop, lists[i][2], "rna_iterator_listbase_next", 0, "rna_iterator_listbase_get", 0, 0, 0, 0);
}
}
#endif

View File

@@ -0,0 +1,60 @@
/**
* $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): Blender Foundation (2008).
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <stdlib.h>
#include "RNA_define.h"
#include "RNA_types.h"
#include "rna_internal.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#ifdef RNA_RUNTIME
#else
void RNA_def_mesh(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
/* mesh */
srna= RNA_def_struct(brna, "Mesh", "Mesh");
RNA_def_ID(srna);
prop= RNA_def_property(srna, "verts", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "mvert", "totvert");
RNA_def_property_struct_type(prop, "MVert");
/* vertex */
srna= RNA_def_struct(brna, "MVert", "Mesh Vertex");
prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_NONE);
}
#endif

View File

@@ -24,28 +24,70 @@
#include <stdlib.h>
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_types.h"
#include "rna_internal.h"
#include "DNA_object_types.h"
#ifdef RNA_RUNTIME
static StructRNA *rna_Object_data_type(PointerRNA *ptr)
{
Object *ob= (Object*)ptr->data;
switch(ob->type) {
case OB_EMPTY:
return NULL;
case OB_MESH:
return &RNA_Mesh;
#if 0
case OB_CURVE:
return &RNA_Curve;
case OB_SURF:
return &RNA_Surface;
case OB_FONT:
return &RNA_Font;
case OB_MBALL:
return &RNA_MBall;
case OB_LAMP:
return &RNA_Lamp;
case OB_CAMERA:
return &RNA_Camera;
case OB_WAVE:
return &RNA_Wave;
case OB_LATTICE:
return &RNA_Lattice;
#endif
default:
return NULL;
}
}
#else
void RNA_def_object(BlenderRNA *brna)
{
StructRNA *strct;
StructRNA *srna;
PropertyRNA *prop;
strct= RNA_def_struct(brna, "Object", "Object");
srna= RNA_def_struct(brna, "Object", "Object");
prop= RNA_def_property(strct, "name", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, "ID", "name");
RNA_def_property_ui_text(prop, "Name", "Object ID name.");
RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set");
RNA_def_ID(srna);
RNA_def_struct_name_property(strct, prop);
prop= RNA_def_property(srna, "data", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_EDITABLE|PROP_RENDER_DEPENDENCY);
RNA_def_property_pointer_funcs(prop, NULL, "rna_Object_data_type", NULL);
prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Object");
RNA_def_property_flag(prop, PROP_EVALUATE_DEPENDENCY);
prop= RNA_def_property(srna, "track", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Object");
RNA_def_property_flag(prop, PROP_EVALUATE_DEPENDENCY);
}
#endif

View File

@@ -27,6 +27,8 @@
#include "RNA_define.h"
#include "RNA_types.h"
#include "rna_internal.h"
#include "DNA_scene_types.h"
#ifdef RNA_RUNTIME
@@ -39,22 +41,6 @@ void *rna_Scene_objects_get(CollectionPropertyIterator *iter)
return ((Base*)iter->internal)->object;
}
/* name functions that ignore the first two ID characters */
static void rna_ID_name_get(void *data, char *value)
{
BLI_strncpy(value, ((ID*)data)->name+2, sizeof(((ID*)data)->name)-2);
}
static int rna_ID_name_length(void *data)
{
return strlen(((ID*)data)->name+2);
}
static void rna_ID_name_set(void *data, const char *value)
{
BLI_strncpy(((ID*)data)->name+2, value, sizeof(((ID*)data)->name)-2);
}
#else
void RNA_def_scene(BlenderRNA *brna)
@@ -66,25 +52,22 @@ void RNA_def_scene(BlenderRNA *brna)
srna= RNA_def_struct(brna, "Scene", "Scene");
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, "ID", "name");
RNA_def_property_ui_text(prop, "Name", "Object ID name.");
RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set");
RNA_def_struct_name_property(srna, prop);
RNA_def_ID(srna);
prop= RNA_def_property(srna, "camera", PROP_POINTER, PROP_NONE);
RNA_def_property_ui_text(prop, "Active Camera", "Active camera used for rendering the scene.");
RNA_def_property_flag(prop, PROP_EDITABLE|PROP_DRIVEABLE|PROP_RENDER_DEPENDENCY);
prop= RNA_def_property(srna, "cursor", PROP_FLOAT, PROP_VECTOR);
RNA_def_property_ui_text(prop, "Cursor Location", "3D cursor location.");
RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 4);
prop= RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "base");
RNA_def_property_collection_sdna(prop, NULL, "base", NULL);
RNA_def_property_struct_type(prop, "Object");
RNA_def_property_ui_text(prop, "Objects", "Objects in the scene.");
RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Scene_objects_get", 0, 0, 0, 0);
RNA_def_property_flag(prop, PROP_RENDER_DEPENDENCY);
prop= RNA_def_property(srna, "layer", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "lay", 1);
@@ -96,10 +79,10 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Proportional Mode", "Proportional edit mode.");
prop= RNA_def_property(srna, "current_frame", PROP_INT, PROP_NONE);
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_int_sdna(prop, NULL, "r.cfra");
RNA_def_property_range(prop, MINFRAME, MAXFRAME);
RNA_def_property_ui_text(prop, "Current Frame", "Current frame.");
RNA_def_property_access(prop, PROP_EDITABLE, 0);
prop= RNA_def_property(srna, "stamp_note", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "r.stamp_udata");