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
path: root/source
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2007-05-22 08:41:21 +0400
committerJoseph Eagar <joeedh@gmail.com>2007-05-22 08:41:21 +0400
commit9ac39d2e99f4417d7514b63a077df2e232879f00 (patch)
treea5abd9154146f13c19de32053381be087a1c32f3 /source
parent6b103057e8111fd9070f09e7751f7b9ad650eb27 (diff)
=ID Properties=
The code for preserving ID properties was apparently not working. Fixed that by adding a new function, IDP_ReplaceInGroup, that automatically handles overriding a property in a group while preserving the property order. Its odd though that the previous fix I had wasn't working :/
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_idprop.h5
-rw-r--r--source/blender/blenkernel/intern/idprop.c49
-rw-r--r--source/blender/python/api2_2x/IDProp.c19
3 files changed, 32 insertions, 41 deletions
diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h
index eed2d7d1ac5..92b624f80ab 100644
--- a/source/blender/blenkernel/BKE_idprop.h
+++ b/source/blender/blenkernel/BKE_idprop.h
@@ -78,6 +78,11 @@ void IDP_LinkID(struct IDProperty *prop, ID *id);
void IDP_UnlinkID(struct IDProperty *prop);
/*-------- Group Functions -------*/
+
+/*checks if a property with the same name as prop exists, and if so replaces it.
+ Use this to preserve order!*/
+void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop);
+
/*
This function has a sanity check to make sure ID properties with the same name don't
get added to the group.
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c
index d92f7ed0096..4ff4073fdbe 100644
--- a/source/blender/blenkernel/intern/idprop.c
+++ b/source/blender/blenkernel/intern/idprop.c
@@ -53,8 +53,8 @@ static char idp_size_table[] = {
1, /*strings*/
sizeof(int),
sizeof(float),
- sizeof(float)*3, /*Vector type*/
- sizeof(float)*16, /*Matrix type, we allocate max 4x4 even if in 3x3 mode*/
+ sizeof(float)*3, /*Vector type, deprecated*/
+ sizeof(float)*16, /*Matrix type, deprecated*/
0, /*arrays don't have a fixed size*/
sizeof(ListBase), /*Group type*/
sizeof(void*)
@@ -169,6 +169,27 @@ void IDP_UnlinkID(IDProperty *prop)
}
/*-------- Group Functions -------*/
+
+/*checks if a property with the same name as prop exists, and if so replaces it.*/
+void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop)
+{
+ IDProperty *loop;
+ for (loop=group->data.group.first; loop; loop=loop->next) {
+ if (BSTR_EQ(loop->name, prop->name)) {
+ if (loop->next) BLI_insertlinkbefore(&group->data.group, loop->next, prop);
+ else BLI_addtail(&group->data.group, prop);
+ BLI_remlink(&group->data.group, loop);
+ IDP_FreeProperty(loop);
+ MEM_freeN(loop);
+ group->len++;
+ return;
+ }
+ }
+
+ group->len++;
+ BLI_addtail(&group->data.group, prop);
+}
+
/*returns 0 if an id property with the same name exists and it failed,
or 1 if it succeeded in adding to the group.*/
int IDP_AddToGroup(IDProperty *group, IDProperty *prop)
@@ -323,26 +344,6 @@ IDProperty *IDP_New(int type, IDPropertyTemplate val, char *name)
/* heh I think all needed values are set properly by calloc anyway :) */
break;
}
- case IDP_MATRIX:
- prop = MEM_callocN(sizeof(IDProperty), "IDProperty array");
- if (val.matrix_or_vector.matvec_size == IDP_MATRIX4X4)
- prop->data.pointer = MEM_callocN(sizeof(float)*4*4, "matrix 4x4 idproperty");
- else
- prop->data.pointer = MEM_callocN(sizeof(float)*3*3, "matrix 3x3 idproperty");
- case IDP_VECTOR:
- prop = MEM_callocN(sizeof(IDProperty), "IDProperty array");
- switch (val.matrix_or_vector.matvec_size) {
- case IDP_VECTOR4D:
- prop->data.pointer = MEM_callocN(sizeof(float)*4, "vector 4d idproperty");
- break;
- case IDP_VECTOR3D:
- prop->data.pointer = MEM_callocN(sizeof(float)*3, "vector 3d idproperty");
- break;
- case IDP_VECTOR2D:
- prop->data.pointer = MEM_callocN(sizeof(float)*2, "vector 2d idproperty");
- break;
-
- }
default:
{
prop = MEM_callocN(sizeof(IDProperty), "IDProperty array");
@@ -370,10 +371,6 @@ void IDP_FreeProperty(IDProperty *prop)
case IDP_GROUP:
IDP_FreeGroup(prop);
break;
- case IDP_VECTOR:
- case IDP_MATRIX:
- MEM_freeN(prop->data.pointer);
- break;
}
}
diff --git a/source/blender/python/api2_2x/IDProp.c b/source/blender/python/api2_2x/IDProp.c
index 8b2dc4543f9..3097f51e839 100644
--- a/source/blender/python/api2_2x/IDProp.c
+++ b/source/blender/python/api2_2x/IDProp.c
@@ -86,9 +86,6 @@ PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop )
array->prop = prop;
return (PyObject*) array;
}
- case IDP_MATRIX:
- case IDP_VECTOR:
- break;
}
Py_RETURN_NONE;
}
@@ -141,12 +138,12 @@ int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject *value)
return 0;
}
-PyObject *BPy_IDGroup_GetName(BPy_IDProperty *self)
+PyObject *BPy_IDGroup_GetName(BPy_IDProperty *self, void *bleh)
{
return Py_BuildValue("s", self->prop->name);
}
-int BPy_IDGroup_SetName(BPy_IDProperty *self, PyObject *value)
+int BPy_IDGroup_SetName(BPy_IDProperty *self, PyObject *value, void *bleh)
{
char *st;
if (!PyString_Check(value))
@@ -206,7 +203,7 @@ PyObject *BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item)
/*returns NULL on success, error string on failure*/
char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObject *ob)
{
- IDProperty *prop = NULL, *prop2=NULL, *prev=NULL;
+ IDProperty *prop = NULL;
IDPropertyTemplate val = {0};
if (PyFloat_Check(ob)) {
@@ -285,15 +282,7 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje
Py_XDECREF(vals);
} else return "invalid property value";
- prop2 = IDP_GetPropertyFromGroup(group, prop->name);
- if (prop2) {
- prev=prop2->prev; /*we want to insert new property in same place as old*/
- IDP_RemFromGroup(group, prop2);
- IDP_FreeProperty(prop2);
- MEM_freeN(prop2);
- }
-
- IDP_InsertToGroup(group, prev, prop);
+ IDP_ReplaceInGroup(group, prop);
return NULL;
}