Revision: 20480
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20480
Author:   blendix
Date:     2009-05-29 01:23:47 +0200 (Fri, 29 May 2009)

Log Message:
-----------
RNA:
* Automatically do us++ and us-- reference counting in ID pointer
  set functions.
* Added an enum property callback to dynamically vary the list of
  available items.
* Added some functions to do removes on pointers and collections
  runtime defined for RNA and using ID properties.

* Constraints now have owner/target space wrapped, and most
  pointers made editable. They can be ported to use python layouts.
* Also other pointers made editable that I think are see now with
  the automatic reference counting.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
    branches/blender2.5/blender/source/blender/makesrna/RNA_define.h
    branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_camera.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_constraint.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_controller.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_curve.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c
    
branches/blender2.5/blender/source/blender/makesrna/intern/rna_internal_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_lamp.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_material.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_mesh.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_modifier.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_nodetree.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_object.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_particle.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_scene.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_sensor.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_texture.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_userdef.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_world.c

Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_access.h    
2009-05-28 23:13:42 UTC (rev 20479)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_access.h    
2009-05-28 23:23:47 UTC (rev 20480)
@@ -430,7 +430,9 @@
 
 /* to create ID property groups */
 void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop);
+void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop);
 void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, 
PointerRNA *r_ptr);
+void RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int 
key);
 void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop);
 
 /* Path

Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_define.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_define.h    
2009-05-28 23:13:42 UTC (rev 20479)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_define.h    
2009-05-28 23:23:47 UTC (rev 20480)
@@ -141,7 +141,7 @@
 void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const 
char *set);
 void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char 
*set, const char *range);
 void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const 
char *set, const char *range);
-void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const 
char *set);
+void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const 
char *set, const char *item);
 void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const 
char *length, const char *set);
 void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const 
char *set);
 void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, 
const char *next, const char *end, const char *get, const char *length, const 
char *lookupint, const char *lookupstring);

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c       
2009-05-28 23:13:42 UTC (rev 20479)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c       
2009-05-28 23:23:47 UTC (rev 20480)
@@ -156,6 +156,17 @@
        return result;
 }
 
+static StructRNA *rna_find_struct(const char *identifier)
+{
+       StructDefRNA *ds;
+
+       for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
+               if(strcmp(ds->srna->identifier, identifier)==0)
+                       return ds->srna;
+
+       return NULL;
+}
+
 static const char *rna_find_type(const char *type)
 {
        StructDefRNA *ds;
@@ -250,8 +261,10 @@
        EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
        int a, mask= 0;
 
-       for(a=0; a<eprop->totitem; a++)
-               mask |= eprop->item[a].value;
+       if(eprop->item) {
+               for(a=0; a<eprop->totitem; a++)
+                       mask |= eprop->item[a].value;
+       }
        
        return mask;
 }
@@ -496,8 +509,19 @@
                                fprintf(f, "    %s(ptr, value);\n", manualfunc);
                        }
                        else {
+                               PointerPropertyRNA *pprop= 
(PointerPropertyRNA*)prop;
+                               StructRNA *type= 
rna_find_struct((char*)pprop->type);
+
                                rna_print_data_get(f, dp);
+
+                               if(type && (type->flag & STRUCT_ID) && 
strcmp(type->identifier, "Object")!=0) {
+                                       fprintf(f, "\n  if(data->%s)\n", 
dp->dnaname);
+                                       fprintf(f, "            
id_us_min((ID*)data->%s);\n", dp->dnaname);
+                                       fprintf(f, "    if(value.data)\n");
+                                       fprintf(f, "            
id_us_plus((ID*)value.data);\n\n");
+                               }
                                fprintf(f, "    data->%s= value.data;\n", 
dp->dnaname);
+
                        }
                        fprintf(f, "}\n\n");
                        break;
@@ -1454,6 +1478,7 @@
                                                DefRNA.error= 1;
                                        }
                                }
+                               else if(eprop->itemf);
                                else {
                                        fprintf(stderr, "rna_generate_structs: 
%s%s.%s, enum must have items defined.\n", srna->identifier, errnest, 
prop->identifier);
                                        DefRNA.error= 1;
@@ -1581,7 +1606,12 @@
                                                                                
                }
                        case PROP_ENUM: {
                                EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
-                               fprintf(f, "\t%s, %s, rna_%s%s_%s_items, %d, 
%d\n", rna_function_string(eprop->get), rna_function_string(eprop->set), 
srna->identifier, strnest, prop->identifier, eprop->totitem, 
eprop->defaultvalue);
+                               fprintf(f, "\t%s, %s, %s, ", 
rna_function_string(eprop->get), rna_function_string(eprop->set), 
rna_function_string(eprop->itemf));
+                               if(eprop->item)
+                                       fprintf(f, "rna_%s%s_%s_items, ", 
srna->identifier, strnest, prop->identifier);
+                               else
+                                       fprintf(f, "NULL, ");
+                               fprintf(f, "%d, %d\n", eprop->totitem, 
eprop->defaultvalue);
                                break;
                                                                                
        }
                        case PROP_POINTER: {
@@ -1798,8 +1828,11 @@
        fprintf(f, "#include <limits.h>\n");
        fprintf(f, "#include <string.h>\n\n");
 
+       fprintf(f, "#include \"DNA_ID.h\"\n");
+
        fprintf(f, "#include \"BLI_blenlib.h\"\n\n");
 
+       fprintf(f, "#include \"BKE_library.h\"\n");
        fprintf(f, "#include \"BKE_utildefines.h\"\n\n");
 
        fprintf(f, "#include \"RNA_define.h\"\n");

Modified: 
branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c     
2009-05-28 23:13:42 UTC (rev 20479)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c     
2009-05-28 23:23:47 UTC (rev 20480)
@@ -599,9 +599,17 @@
 void RNA_property_enum_items(PointerRNA *ptr, PropertyRNA *prop, const 
EnumPropertyItem **item, int *totitem)
 {
        EnumPropertyRNA *eprop= (EnumPropertyRNA*)rna_ensure_property(prop);
+       int tot;
 
-       *item= eprop->item;
-       *totitem= eprop->totitem;
+       if(eprop->itemf) {
+               *item= eprop->itemf(ptr);
+               for(tot=0; (*item)[tot].identifier; tot++);
+               *totitem= tot;
+       }
+       else {
+               *item= eprop->item;
+               *totitem= eprop->totitem;
+       }
 }
 
 int RNA_property_enum_value(PointerRNA *ptr, PropertyRNA *prop, const char 
*identifier, int *value)
@@ -1182,6 +1190,23 @@
                printf("RNA_property_pointer_add %s.%s: only supported for id 
properties.\n", ptr->type->identifier, prop->identifier);
 }
 
+void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop)
+{
+       IDProperty *idprop, *group;
+
+       if((idprop=rna_idproperty_check(&prop, ptr))) {
+               group= RNA_struct_idproperties(ptr, 0);
+               
+               if(group) {
+                       IDP_RemFromGroup(group, idprop);
+                       IDP_FreeProperty(idprop);
+                       MEM_freeN(idprop);
+               }
+       }
+       else
+               printf("RNA_property_pointer_remove %s.%s: only supported for 
id properties.\n", ptr->type->identifier, prop->identifier);
+}
+
 static void rna_property_collection_get_idp(CollectionPropertyIterator *iter)
 {
        CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)iter->prop;
@@ -1309,6 +1334,33 @@
        }
 }
 
+void RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int 
key)
+{
+       IDProperty *idprop;
+
+       if((idprop=rna_idproperty_check(&prop, ptr))) {
+               IDProperty tmp, *array;
+               int len;
+
+               len= idprop->len;
+               array= IDP_IDPArray(idprop);
+
+               if(key >= 0 && key < len) {
+                       if(key+1 < len) {
+                               /* move element to be removed to the back */
+                               memcpy(&tmp, &array[key], sizeof(IDProperty));
+                               memmove(array+key, array+key+1, 
sizeof(IDProperty)*(len-key+1));
+                               memcpy(&array[len-1], &tmp, sizeof(IDProperty));
+                       }
+
+                       IDP_ResizeIDPArray(idprop, len-1);
+               }
+       }
+       else if(prop->flag & PROP_IDPROPERTY);
+       else
+               printf("RNA_property_collection_remove %s.%s: only supported 
for id properties.\n", ptr->type->identifier, prop->identifier);
+}
+
 void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop)
 {
        IDProperty *idprop;

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c      
2009-05-28 23:13:42 UTC (rev 20479)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c      
2009-05-28 23:23:47 UTC (rev 20480)
@@ -189,7 +189,7 @@
        RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_FIXED_TEX);
        RNA_def_property_ui_text(prop, "Fixed Texture", "Keep texture origin in 
fixed position.");*/
 
-       prop= RNA_def_property(srna, "curve", PROP_POINTER, PROP_NONE);
+       prop= RNA_def_property(srna, "curve", PROP_POINTER, PROP_NEVER_NULL);
        RNA_def_property_ui_text(prop, "Curve", "Editable falloff curve.");
 
        /* texture */
@@ -198,7 +198,7 @@
        /* clone tool */
        prop= RNA_def_property(srna, "clone_image", PROP_POINTER, PROP_NONE);
        RNA_def_property_pointer_sdna(prop, NULL, "clone.image");
-       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Clone Image", "Image for clone tool.");
        
        prop= RNA_def_property(srna, "clone_opacity", PROP_FLOAT, PROP_NONE);

Modified: 
branches/blender2.5/blender/source/blender/makesrna/intern/rna_camera.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_camera.c     
2009-05-28 23:13:42 UTC (rev 20479)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_camera.c     
2009-05-28 23:23:47 UTC (rev 20480)
@@ -158,6 +158,7 @@
        prop= RNA_def_property(srna, "dof_object", PROP_POINTER, PROP_NONE);
        RNA_def_property_struct_type(prop, "Object");
        RNA_def_property_pointer_sdna(prop, NULL, "dof_ob");
+       RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "DOF Object", "Use this object to define 
the depth of field focal point.");
        RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
 }

Modified: 
branches/blender2.5/blender/source/blender/makesrna/intern/rna_constraint.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_constraint.c 
2009-05-28 23:13:42 UTC (rev 20479)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_constraint.c 
2009-05-28 23:23:47 UTC (rev 20480)
@@ -61,6 +61,7 @@
 #ifdef RNA_RUNTIME
 
 #include "BKE_action.h"
+#include "BKE_constraint.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 
@@ -116,19 +117,9 @@
 
 static char *rna_Constraint_path(PointerRNA *ptr)
 {
-       return BLI_sprintfN("constraints[%s]", 
((bConstraint*)ptr->data)->name); // XXX not unique
+       return BLI_sprintfN("constraints[%s]", ((bConstraint*)ptr->data)->name);
 }
 
-void rna_CopyLocationConstraint_target_set(PointerRNA *ptr, PointerRNA value)
-{

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to