RNA
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 29 Nov 2008 19:08:46 +0000 (19:08 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 29 Nov 2008 19:08:46 +0000 (19:08 +0000)
* 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.

source/blender/editors/interface/interface.c
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_ID.c
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_color.c
source/blender/makesrna/intern/rna_define.c
source/blender/makesrna/intern/rna_main.c
source/blender/makesrna/intern/rna_sensor.c

index 9ffd252c231258f0c318d1dd866eb7395f725bee..be36b2a39b6a79edeb53353ae4d5ef3181dbe178 100644 (file)
@@ -1240,8 +1240,10 @@ void ui_get_but_string(uiBut *but, char *str, int maxlen)
 
 void ui_set_but_string(uiBut *but, const char *str)
 {
-       if(but->rnaprop)
-               RNA_property_string_set(&but->rnapoin, but->rnaprop, str);
+       if(but->rnaprop) {
+               if(RNA_property_editable(&but->rnapoin, but->rnaprop))
+                       RNA_property_string_set(&but->rnapoin, but->rnaprop, str);
+       }
        else
                BLI_strncpy(but->poin, str, but->max);
 }
index 510281d0619dd6dd57ec60eec7f924d54e7d1bbe..fd2a3c4124a86649b8538ed78babaccee548884c 100644 (file)
@@ -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);
index b5a5a41069fa069a2b9634f4d09fd4e82d3d520c..4974d21e7557e01baa580121eb33e896516e5d56 100644 (file)
@@ -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
index 3fbc2090cd448af4d5c22e65d2aba644957bf03f..5c1236e5fab6b5603158fc837cd87ab43baccd49 100644 (file)
@@ -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;
index ff20a83e51e8484323ea992f39849920499203fc..d5c1b79d46681cc71d54903b3bc0cfa1402c5991 100644 (file)
@@ -37,7 +37,6 @@
 void RNA_def_color(BlenderRNA *brna)
 {
        StructRNA *srna;
-       PropertyRNA *prop;
 
        srna= RNA_def_struct(brna, "CurveMapPoint", NULL, "CurveMapPoint");
 
index 8a254d47527f5990d3fa81b44ab6bc68ea8ca4bd..203051c09d31798d977ae29c39e2bcb9dbafa76f 100644 (file)
@@ -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.");
index fde151ce9ee26457a266dce364239c10262c8c67..28b361a2d44b2b94f7e6c7a50bfebd3c39e75f10 100644 (file)
@@ -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."},
index 69ed9bbd6676dc482b15538a418fe114967b49b9..35064a9c20096d463d2e200f040586fdca5c26f0 100644 (file)
 #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