Revision: 18195
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18195
Author:   blendix
Date:     2008-12-31 14:16:37 +0100 (Wed, 31 Dec 2008)

Log Message:
-----------
RNA
* Store RNA collections different in ID properties, using a generic
  ID property array, using the patch provided by Joe.
* Fix bug accessing registered operator properties in the wm from the
  outliner.
* In the outliner, only use the RNA icon for RNA data, and use dot
  again for unknown icon.
* Also, show pointer properties data in the second column, and auto
  expand two levels when opening them.
* Added small RNA_struct_defined_properties function to get only the
  defined properties without builtin and undefined id properties
  (for py operators).

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_idprop.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/idprop.c
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
    branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c
    branches/blender2.5/blender/source/blender/editors/space_outliner/outliner.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_ID.h
    branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_wm.c
    branches/blender2.5/blender/source/blender/windowmanager/intern/wm.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_idprop.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_idprop.h  
2008-12-31 10:44:00 UTC (rev 18194)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_idprop.h  
2008-12-31 13:16:37 UTC (rev 18195)
@@ -49,7 +49,22 @@
        } matrix_or_vector;
 } IDPropertyTemplate;
 
-/* ----------- Array Type ----------- */
+/* ----------- Property Array Type ---------- */
+
+/*note: as a start to move away from the stupid IDP_New function, this type
+  has it's own allocation function.*/
+IDProperty *IDP_NewIDPArray(const char *name);
+IDProperty *IDP_CopyIDPArray(IDProperty *array);
+
+void IDP_FreeIDPArray(IDProperty *prop);
+
+/* shallow copies item */
+void IDP_SetIndexArray(struct IDProperty *prop, int index, struct IDProperty 
*item);
+struct IDProperty *IDP_GetIndexArray(struct IDProperty *prop, int index);
+struct IDProperty *IDP_AppendArray(struct IDProperty *prop, struct IDProperty 
*item);
+void IDP_ResizeIDPArray(struct IDProperty *prop, int len);
+
+/* ----------- Numeric Array Type ----------- */
 /*this function works for strings too!*/
 void IDP_ResizeArray(struct IDProperty *prop, int newlen);
 void IDP_FreeArray(struct IDProperty *prop);
@@ -152,7 +167,7 @@
 IDP_AddToGroup or MEM_freeN the property, doing anything else might result in
 a memory leak.
 */
-struct IDProperty *IDP_New(int type, IDPropertyTemplate val, char *name);
+struct IDProperty *IDP_New(int type, IDPropertyTemplate val, const char *name);
 \
 /*NOTE: this will free all child properties of list arrays and groups!
   Also, note that this does NOT unlink anything!  Plus it doesn't free
@@ -162,10 +177,11 @@
 /*Unlinks any struct IDProperty<->ID linkage that might be going on.*/
 void IDP_UnlinkProperty(struct IDProperty *prop);
 
-#define IDP_Int(prop) (prop->data.val)
-#define IDP_Float(prop) (*(float*)&prop->data.val)
-#define IDP_String(prop) ((char*)prop->data.pointer)
-#define IDP_Array(prop) (prop->data.pointer)
-#define IDP_Double(prop) (*(double*)&prop->data.val)
+#define IDP_Int(prop) ((prop)->data.val)
+#define IDP_Float(prop) (*(float*)&(prop)->data.val)
+#define IDP_String(prop) ((char*)(prop)->data.pointer)
+#define IDP_Array(prop) ((prop)->data.pointer)
+#define IDP_IDPArray(prop) ((IDProperty*)(prop)->data.pointer)
+#define IDP_Double(prop) (*(double*)&(prop)->data.val)
 
 #endif /* _BKE_IDPROP_H */

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/idprop.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/idprop.c       
2008-12-31 10:44:00 UTC (rev 18194)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/idprop.c       
2008-12-31 13:16:37 UTC (rev 18195)
@@ -58,9 +58,126 @@
        sizeof(double)
 };
 
+/* ------------Property Array Type ----------- */
+#define GETPROP(prop, i) (((IDProperty*)(prop)->data.pointer)+(i))
 
-/* ----------- Array Type ----------- */
+/* --------- property array type -------------*/
 
+/*note: as a start to move away from the stupid IDP_New function, this type
+  has it's own allocation function.*/
+IDProperty *IDP_NewIDPArray(const char *name)
+{
+       IDProperty *prop = MEM_callocN(sizeof(IDProperty), "IDProperty prop 
array");
+       prop->type = IDP_IDPARRAY;
+       prop->len = 0;
+       BLI_strncpy(prop->name, name, MAX_IDPROP_NAME);
+       
+       return prop;
+}
+
+IDProperty *IDP_CopyIDPArray(IDProperty *array)
+{
+       IDProperty *narray = MEM_dupallocN(array), *tmp;
+       int i;
+       
+       narray->data.pointer = MEM_dupallocN(array->data.pointer);
+       for (i=0; i<narray->len; i++) {
+               /*ok, the copy functions always allocate a new structure,
+                 which doesn't work here.  instead, simply copy the
+                 contents of the new structure into the array cell,
+                 then free it.  this makes for more maintainable
+                 code than simply reimplementing the copy functions
+                 in this loop.*/
+               tmp = IDP_CopyProperty(GETPROP(narray, i));
+               memcpy(GETPROP(narray, i), tmp, sizeof(IDProperty));
+               MEM_freeN(tmp);
+       }
+       
+       return narray;
+}
+
+void IDP_FreeIDPArray(IDProperty *prop)
+{
+       int i;
+       
+       for (i=0; i<prop->len; i++)
+               IDP_FreeProperty(GETPROP(prop, i));
+
+       if(prop->data.pointer)
+               MEM_freeN(prop->data.pointer);
+}
+
+/*shallow copies item*/
+void IDP_SetIndexArray(IDProperty *prop, int index, IDProperty *item)
+{
+       IDProperty *old = GETPROP(prop, index);
+       if (index >= prop->len || index < 0) return;
+       if (item != old) IDP_FreeProperty(old);
+       
+       memcpy(GETPROP(prop, index), item, sizeof(IDProperty));
+}
+
+IDProperty *IDP_GetIndexArray(IDProperty *prop, int index)
+{
+       return GETPROP(prop, index);
+}
+
+IDProperty *IDP_AppendArray(IDProperty *prop, IDProperty *item)
+{
+       IDP_ResizeIDPArray(prop, prop->len+1);
+       IDP_SetIndexArray(prop, prop->len-1, item);
+       return item;
+}
+
+void IDP_ResizeIDPArray(IDProperty *prop, int newlen)
+{
+       void *newarr;
+       int newsize=newlen;
+
+       /*first check if the array buffer size has room*/
+       /*if newlen is 200 chars less then totallen, reallocate anyway*/
+       if (newlen <= prop->totallen && prop->totallen - newlen < 200) {
+               int i;
+
+               for(i=newlen; i<prop->len; i++)
+                       IDP_FreeProperty(GETPROP(prop, i));
+
+               prop->len = newlen;
+               return;
+       }
+
+       /* - Note: This code comes from python, here's the corrusponding 
comment. - */
+       /* This over-allocates proportional to the list size, making room
+        * for additional growth.  The over-allocation is mild, but is
+        * enough to give linear-time amortized behavior over a long
+        * sequence of appends() in the presence of a poorly-performing
+        * system realloc().
+        * The growth pattern is:  0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
+        */
+       newsize = (newsize >> 3) + (newsize < 9 ? 3 : 6) + newsize;
+
+       newarr = MEM_callocN(sizeof(IDProperty)*newsize, "idproperty array 
resized");
+       if (newlen >= prop->len) {
+               /* newlen is bigger*/
+               memcpy(newarr, prop->data.pointer, 
prop->len*sizeof(IDProperty));
+       }
+       else {
+               int i;
+               /* newlen is smaller*/
+               for (i=newlen; i<prop->len; i++) {
+                       IDP_FreeProperty(GETPROP(prop, i));
+               }
+               memcpy(newarr, prop->data.pointer, 
newlen*prop->len*sizeof(IDProperty));
+       }
+
+       if(prop->data.pointer)
+               MEM_freeN(prop->data.pointer);
+       prop->data.pointer = newarr;
+       prop->len = newlen;
+       prop->totallen = newsize;
+}
+
+/* ----------- Numerical Array Type ----------- */
 static void idp_resize_group_array(IDProperty *prop, int newlen, void *newarr)
 {
        if(prop->subtype != IDP_GROUP)
@@ -144,7 +261,7 @@
  {
        IDProperty *newp = MEM_callocN(sizeof(IDProperty), "IDProperty array 
dup");
 
-       strncpy(newp->name, prop->name, MAX_IDPROP_NAME);
+       BLI_strncpy(newp->name, prop->name, MAX_IDPROP_NAME);
        newp->type = prop->type;
        newp->flag = prop->flag;
        newp->data.val = prop->data.val;
@@ -234,7 +351,8 @@
 
 void IDP_FreeString(IDProperty *prop)
 {
-       MEM_freeN(prop->data.pointer);
+       if(prop->data.pointer)
+               MEM_freeN(prop->data.pointer);
 }
 
 
@@ -388,6 +506,7 @@
                case IDP_GROUP: return IDP_CopyGroup(prop);
                case IDP_STRING: return IDP_CopyString(prop);
                case IDP_ARRAY: return IDP_CopyArray(prop);
+               case IDP_IDPARRAY: return IDP_CopyIDPArray(prop);
                default: return idp_generic_copy(prop);
        }
 }
@@ -408,7 +527,7 @@
        }
 }
 
-IDProperty *IDP_New(int type, IDPropertyTemplate val, char *name)
+IDProperty *IDP_New(int type, IDPropertyTemplate val, const char *name)
 {
        IDProperty *prop=NULL;
 
@@ -431,8 +550,8 @@
                        if (val.array.type == IDP_FLOAT || val.array.type == 
IDP_INT || val.array.type == IDP_DOUBLE || val.array.type == IDP_GROUP) {
                                prop = MEM_callocN(sizeof(IDProperty), 
"IDProperty array");
                                prop->subtype = val.array.type;
-                               prop->data.pointer = 
MEM_callocN(idp_size_table[val.array.type]*val.array.len, "id property array");
-                               idp_resize_group_array(prop, val.array.len, 
prop->data.pointer);
+                               if (val.array.len)
+                                       prop->data.pointer = 
MEM_callocN(idp_size_table[val.array.type]*val.array.len, "id property array");
                                prop->len = prop->totallen = val.array.len;
                                break;
                        } else {
@@ -471,7 +590,7 @@
        }
 
        prop->type = type;
-       strncpy(prop->name, name, MAX_IDPROP_NAME);
+       BLI_strncpy(prop->name, name, MAX_IDPROP_NAME);
        
        /*security null byte*/
        prop->name[MAX_IDPROP_NAME-1] = 0;
@@ -494,6 +613,9 @@
                case IDP_GROUP:
                        IDP_FreeGroup(prop);
                        break;
+               case IDP_IDPARRAY:
+                       IDP_FreeIDPArray(prop);
+                       break;
        }
 }
 

Modified: 
branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c     
2008-12-31 10:44:00 UTC (rev 18194)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c     
2008-12-31 13:16:37 UTC (rev 18195)
@@ -1346,6 +1346,24 @@
 void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData *fd);
 void IDP_LibLinkProperty(IDProperty *prop, int switch_endian, FileData *fd);
 
+static void IDP_DirectLinkIDPArray(IDProperty *prop, int switch_endian, 
FileData *fd)
+{
+       IDProperty **array;
+       int i;
+
+       /*since we didn't save the extra buffer, set totallen to len.*/
+       prop->totallen = prop->len;
+       prop->data.pointer = newdataadr(fd, prop->data.pointer);
+
+       if (switch_endian) {
+               test_pointer_array(fd, prop->data.pointer);
+               array= (IDProperty**) prop->data.pointer;
+
+               for(i=0; i<prop->len; i++)
+                       IDP_DirectLinkProperty(array[i], switch_endian, fd);
+       }
+}
+
 static void IDP_DirectLinkArray(IDProperty *prop, int switch_endian, FileData 
*fd)
 {
        IDProperty **array;
@@ -1407,6 +1425,9 @@
                case IDP_ARRAY:
                        IDP_DirectLinkArray(prop, switch_endian, fd);
                        break;
+               case IDP_IDPARRAY:
+                       IDP_DirectLinkIDPArray(prop, switch_endian, fd);
+                       break;
                case IDP_DOUBLE:
                        /*erg, stupid doubles.  since I'm storing them
                         in the same field as int val; val2 in the

Modified: 
branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c    
2008-12-31 10:44:00 UTC (rev 18194)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c    
2008-12-31 13:16:37 UTC (rev 18195)
@@ -391,7 +391,7 @@
        if (prop->data.pointer) {
                writedata(wd, DATA, MEM_allocN_len(prop->data.pointer), 
prop->data.pointer);
 
-               if(prop->type == IDP_GROUP) {
+               if(prop->subtype == IDP_GROUP) {

@@ 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