Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2008-11-29 22:08:46 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2008-11-29 22:08:46 +0300
commit2b7e3909670bd06f967884a908b9f805ec10dc3f (patch)
treec11930bb998dd1a30297a45a1673ff6cd6aa3358 /source/blender/makesrna
parent2ff4ac139ba430e606accf44874a3fce10e9c635 (diff)
RNA
* Fix sensor data pointer code, also made sensor type non editable, would need to do more work than just setting the type. * Fix a fairly obscure bug related to inheritance and sorting. * Complete DNA_ID.h wrapping, just a few extra properties and the Library struct, most of this is internal.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/intern/makesrna.c7
-rw-r--r--source/blender/makesrna/intern/rna_ID.c48
-rw-r--r--source/blender/makesrna/intern/rna_access.c2
-rw-r--r--source/blender/makesrna/intern/rna_color.c1
-rw-r--r--source/blender/makesrna/intern/rna_define.c78
-rw-r--r--source/blender/makesrna/intern/rna_main.c4
-rw-r--r--source/blender/makesrna/intern/rna_sensor.c14
7 files changed, 114 insertions, 40 deletions
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 510281d0619..fd2a3c4124a 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -490,7 +490,7 @@ static void rna_def_property_funcs(FILE *f, PropertyDefRNA *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->identifier, prop->identifier);
+ fprintf(stderr, "rna_def_property_funcs: %s.%s, pointer must have either type function or fixed type.\n", srna->identifier, prop->identifier);
DefRNA.error= 1;
}
break;
@@ -777,7 +777,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
}
case PROP_INT: {
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
- fprintf(f, "\t%s, %s, %s, %s, %s,\n\t", rna_function_string(iprop->get), rna_function_string(iprop->set), rna_function_string(iprop->getarray), rna_function_string(iprop->setarray), rna_function_string(iprop->range), iprop->softmin, iprop->softmax, iprop->hardmin, iprop->hardmax, iprop->step, iprop->defaultvalue);
+ fprintf(f, "\t%s, %s, %s, %s, %s,\n\t", rna_function_string(iprop->get), rna_function_string(iprop->set), rna_function_string(iprop->getarray), rna_function_string(iprop->setarray), rna_function_string(iprop->range));
rna_int_print(f, iprop->softmin); fprintf(f, ", ");
rna_int_print(f, iprop->softmax); fprintf(f, ", ");
rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
@@ -921,6 +921,8 @@ static int rna_preprocess(char *basedirectory, FILE *f)
for(i=0; PROCESS_ITEMS[i].filename; i++)
if(PROCESS_ITEMS[i].define)
PROCESS_ITEMS[i].define(brna);
+
+ rna_sort(brna);
rna_auto_types();
rna_generate_prototypes(brna, f);
@@ -930,7 +932,6 @@ static int rna_preprocess(char *basedirectory, FILE *f)
fprintf(f, "\n");
rna_auto_functions(f);
- rna_sort(brna);
for(srna=brna->structs.first; srna; srna=srna->next)
rna_generate_struct(brna, srna, f);
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index b5a5a41069f..4974d21e755 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -59,6 +59,7 @@ static StructRNA *rna_ID_refine(PointerRNA *ptr)
switch(GS(id->name)) {
case ID_LA: return &RNA_Lamp;
+ case ID_LI: return &RNA_Library;
case ID_MA: return &RNA_Material;
case ID_NT: return &RNA_NodeTree;
case ID_ME: return &RNA_Mesh;
@@ -70,6 +71,20 @@ static StructRNA *rna_ID_refine(PointerRNA *ptr)
}
}
+static void rna_ID_fake_user_set(PointerRNA *ptr, int value)
+{
+ ID *id= (ID*)ptr->data;
+
+ if(value && !(id->flag & LIB_FAKEUSER)) {
+ id->flag |= LIB_FAKEUSER;
+ id->us++;
+ }
+ else if(!value && (id->flag & LIB_FAKEUSER)) {
+ id->flag &= ~LIB_FAKEUSER;
+ id->us--;
+ }
+}
+
#else
static void rna_def_ID_properties(BlenderRNA *brna)
@@ -122,7 +137,7 @@ static void rna_def_ID_properties(BlenderRNA *brna)
srna= RNA_def_struct(brna, "IDPropertyGroup", NULL, "ID Property Group");
}
-void rna_def_ID(BlenderRNA *brna)
+static void rna_def_ID(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
@@ -137,15 +152,40 @@ void rna_def_ID(BlenderRNA *brna)
RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set");
RNA_def_property_string_maxlength(prop, 22);
RNA_def_struct_name_property(srna, prop);
+
+ prop= RNA_def_property(srna, "users", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_int_sdna(prop, NULL, "us");
+ RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
+ RNA_def_property_ui_text(prop, "Users", "Number of times this datablock is referenced.");
+
+ prop= RNA_def_property(srna, "fake_user", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", LIB_FAKEUSER);
+ RNA_def_property_ui_text(prop, "Fake User", "Saves this datablock even if it has no users");
+ RNA_def_property_boolean_funcs(prop, NULL, "rna_ID_fake_user_set");
+
+ prop= RNA_def_property(srna, "library", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "lib");
+ RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
+ RNA_def_property_ui_text(prop, "Library", "Library file the datablock is linked from.");
}
+static void rna_def_library(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna= RNA_def_struct(brna, "Library", "ID", "Library");
+
+ prop= RNA_def_property(srna, "filename", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "name");
+ RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
+ RNA_def_property_ui_text(prop, "Filename", "Path to the library .blend file.");
+}
void RNA_def_ID(BlenderRNA *brna)
{
- /* ID */
rna_def_ID(brna);
-
- /* ID Properties */
rna_def_ID_properties(brna);
+ rna_def_library(brna);
}
#endif
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 3fbc2090cd4..5c1236e5fab 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -796,7 +796,7 @@ static StructRNA *rna_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop,
else
type= pprop->structtype;
- if(type->refine)
+ if(type && type->refine)
type= type->refine(r_ptr);
r_ptr->type= type;
diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c
index ff20a83e51e..d5c1b79d466 100644
--- a/source/blender/makesrna/intern/rna_color.c
+++ b/source/blender/makesrna/intern/rna_color.c
@@ -37,7 +37,6 @@
void RNA_def_color(BlenderRNA *brna)
{
StructRNA *srna;
- PropertyRNA *prop;
srna= RNA_def_struct(brna, "CurveMapPoint", NULL, "CurveMapPoint");
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index 8a254d47527..203051c09d3 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -249,12 +249,26 @@ static size_t rna_property_type_sizeof(PropertyType type)
}
}
+static PropertyDefRNA *rna_find_def_property(StructRNA *srna, PropertyRNA *prop)
+{
+ StructDefRNA *ds;
+ PropertyDefRNA *dp;
+
+ for(ds=DefRNA.structs.first; ds; ds=ds->next)
+ if(ds->srna == srna)
+ for(dp=ds->properties.first; dp; dp=dp->next)
+ if(dp->prop == prop)
+ return dp;
+
+ return NULL;
+}
+
/* Struct Definition */
StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from, const char *name)
{
StructRNA *srna, *srnafrom= NULL;
- StructDefRNA *ds;
+ StructDefRNA *ds= NULL;
PropertyRNA *prop, *propfrom;
if(from) {
@@ -272,9 +286,9 @@ StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *
srna= MEM_callocN(sizeof(StructRNA), "StructRNA");
DefRNA.laststruct= srna;
- /* copy from struct to derive stuff, a bit clumsy since we can't
- * use MEM_dupallocN, data structs may not be alloced but builtin */
if(srnafrom) {
+ /* copy from struct to derive stuff, a bit clumsy since we can't
+ * use MEM_dupallocN, data structs may not be alloced but builtin */
memcpy(srna, srnafrom, sizeof(StructRNA));
srna->properties.first= srna->properties.last= NULL;
@@ -282,6 +296,28 @@ StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *
srna->from= (StructRNA*)from;
else
srna->from= srnafrom;
+ }
+
+ srna->identifier= identifier;
+ srna->name= name;
+
+ rna_addtail(&brna->structs, srna);
+
+ if(DefRNA.preprocess) {
+ ds= MEM_callocN(sizeof(StructDefRNA), "StructDefRNA");
+ ds->srna= srna;
+ rna_addtail(&DefRNA.structs, ds);
+ }
+
+ /* in preprocess, try to find sdna */
+ if(DefRNA.preprocess)
+ RNA_def_struct_sdna(srna, srna->identifier);
+ else
+ srna->flag |= STRUCT_RUNTIME;
+
+ if(srnafrom) {
+ /* copy from struct to derive stuff, a bit clumsy since we can't
+ * use MEM_dupallocN, data structs may not be alloced but builtin */
for(propfrom= srnafrom->properties.first; propfrom; propfrom=propfrom->next) {
prop= RNA_def_property(srna, propfrom->identifier, propfrom->type, propfrom->subtype);
@@ -299,28 +335,24 @@ StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *
srna->nameproperty= prop;
if(propfrom == srnafrom->iteratorproperty)
srna->iteratorproperty= prop;
- }
- }
-
- srna->identifier= identifier;
- srna->name= name;
- if(DefRNA.preprocess) {
- ds= MEM_callocN(sizeof(StructDefRNA), "StructDefRNA");
- ds->srna= srna;
- rna_addtail(&DefRNA.structs, ds);
+ if(DefRNA.preprocess) {
+ PropertyDefRNA *dp, *dpfrom;
+
+ dp= ds->properties.last;
+ dpfrom= rna_find_def_property(srnafrom, propfrom);
+
+ rna_remlink(&ds->properties, dp);
+ memcpy(dp, dpfrom, sizeof(*dp));
+ dp->srna= srna;
+ dp->prop= prop;
+ dp->next= dp->prev= NULL;
+ rna_addtail(&ds->properties, dp);
+ }
+ }
}
-
- rna_addtail(&brna->structs, srna);
-
- /* in preprocess, try to find sdna */
- if(DefRNA.preprocess)
- RNA_def_struct_sdna(srna, srna->identifier);
- else
- srna->flag |= STRUCT_RUNTIME;
-
- /* define some builtin properties */
- if(!srnafrom) {
+ else {
+ /* define some builtin properties */
prop= RNA_def_property(srna, "rna_properties", PROP_COLLECTION, PROP_NONE);
RNA_def_property_flag(prop, PROP_BUILTIN);
RNA_def_property_ui_text(prop, "Properties", "RNA property collection.");
diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c
index fde151ce9ee..28b361a2d44 100644
--- a/source/blender/makesrna/intern/rna_main.c
+++ b/source/blender/makesrna/intern/rna_main.c
@@ -52,13 +52,11 @@ static void rna_Main_lamp_begin(CollectionPropertyIterator *iter, PointerRNA *pt
rna_iterator_listbase_begin(iter, &bmain->lamp, NULL);
}
-#if 0
static void rna_Main_library_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Main *bmain= (Main*)ptr->data;
rna_iterator_listbase_begin(iter, &bmain->library, NULL);
}
-#endif
static void rna_Main_mesh_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
@@ -227,10 +225,10 @@ void RNA_def_main(BlenderRNA *brna)
{"nodetrees", "NodeTree", "rna_Main_nodetree_begin", "Node Trees", "Nodetree datablocks."},
{"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh datablocks."},
{"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks."},
+ {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks."},
{"screens", "Screen", "rna_Main_screen_begin", "Screens", "Screen datablocks."},
{"windowmanagers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager datablocks."},
{NULL, NULL, NULL, NULL, NULL},
- {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks."},
{"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks."},
{"metaballs", "MBall", "rna_Main_mball_begin", "Metaballs", "Metaball datablocks."},
{"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture datablocks."},
diff --git a/source/blender/makesrna/intern/rna_sensor.c b/source/blender/makesrna/intern/rna_sensor.c
index 69ed9bbd667..35064a9c200 100644
--- a/source/blender/makesrna/intern/rna_sensor.c
+++ b/source/blender/makesrna/intern/rna_sensor.c
@@ -33,19 +33,22 @@
#include "DNA_sensor_types.h"
#ifdef RNA_RUNTIME
-/*
+
static struct StructRNA* rna_Sensor_data_type(struct PointerRNA *ptr)
{
+ bSensor *sensor= (bSensor*)ptr->data;
+
// This function should reture the type of
// void* data;
// in bSensor structure
- switch( ((bSensor*)ptr)->type ){
+ switch(sensor->type) {
case SENS_MOUSE:
return &RNA_MouseSensor;
}
+
return NULL;
}
-*/
+
#else
void RNA_def_sensor(BlenderRNA *brna)
{
@@ -93,7 +96,9 @@ void RNA_def_sensor(BlenderRNA *brna)
RNA_def_property_string_sdna(prop, NULL, "name");
RNA_def_property_ui_text(prop, "Name", "Sensor name.");
+ /* type is not editable, would need to do proper data free/alloc */
prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_enum_items(prop, sensor_types_items);
RNA_def_property_ui_text(prop, "Sensor types", "Sensor Types.");
@@ -111,7 +116,7 @@ void RNA_def_sensor(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Frequency", "Delay between repeated pulses(in logic tics, 0=no delay).");
RNA_def_property_range(prop, 0, 10000);
- /*
+
//This add data property to Sensor, and because data can be bMouseSensor, bNearSensor, bAlwaysSensor ...
//rna_Sensor_data_type defines above in runtime section to get its type and proper structure for data
prop= RNA_def_property(srna, "data", PROP_POINTER, PROP_NONE);
@@ -124,7 +129,6 @@ void RNA_def_sensor(BlenderRNA *brna)
prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, mouse_event_items);
RNA_def_property_ui_text(prop, "MouseEvent", "Specify the type of event this mouse sensor should trigger on.");
- */
}
#endif