diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_idprop.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 11 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/idprop.c | 60 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 3 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_ID.h | 15 |
5 files changed, 74 insertions, 16 deletions
diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h index 92b624f80ab..961cca511de 100644 --- a/source/blender/blenkernel/BKE_idprop.h +++ b/source/blender/blenkernel/BKE_idprop.h @@ -137,6 +137,7 @@ void IDP_FreeIterBeforeEnd(void *vself); to create the Group property and attach it to id if it doesn't exist; otherwise the function will return NULL if there's no Group property attached to the ID.*/ struct IDProperty *IDP_GetProperties(struct ID *id, int create_if_needed); +struct IDProperty *IDP_CopyProperty(struct IDProperty *prop); /* Allocate a new ID. diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index d5368242baf..25b8c9ac171 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -162,14 +162,21 @@ void clone_constraint_channels (ListBase *dst, ListBase *src) void copy_constraints (ListBase *dst, ListBase *src) { - bConstraint *con; + bConstraint *con, *srccon; dst->first= dst->last= NULL; duplicatelist (dst, src); - for (con = dst->first; con; con=con->next) { + for (con = dst->first, srccon=src->first; con; srccon=srccon->next, con=con->next) { con->data = MEM_dupallocN (con->data); + if (con->type == CONSTRAINT_TYPE_PYTHON) { + bPythonConstraint *pycon = (bPythonConstraint*) con->data; + bPythonConstraint *opycon = (bPythonConstraint*) srccon->data; + + pycon->prop = IDP_CopyProperty(opycon->prop); + } + /* removed a whole lot of useless code here (ton) */ } } diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index bb4c66da0b1..bf2a3aae11a 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -104,6 +104,31 @@ void IDP_ResizeArray(IDProperty *prop, int newlen) MEM_freeN(prop->data.pointer); } + + static IDProperty *idp_generic_copy(IDProperty *prop) + { + IDProperty *newp = MEM_callocN(sizeof(IDProperty), "IDProperty array dup"); + + strncpy(newp->name, prop->name, MAX_IDPROP_NAME); + newp->type = prop->type; + newp->flag = prop->flag; + newp->data.val = prop->data.val; + + return newp; + } + +IDProperty *IDP_CopyArray(IDProperty *prop) +{ + IDProperty *newp = idp_generic_copy(prop); + + if (prop->data.pointer) newp->data.pointer = MEM_dupallocN(prop->data.pointer); + newp->len = prop->len; + newp->subtype = prop->subtype; + newp->totallen = prop->totallen; + + return newp; +} + /*taken from readfile.c*/ #define SWITCH_LONGINT(a) { \ char s_i, *p_i; \ @@ -116,6 +141,19 @@ void IDP_ResizeArray(IDProperty *prop, int newlen) /* ---------- String Type ------------ */ +IDProperty *IDP_CopyString(IDProperty *prop) +{ + IDProperty *newp = idp_generic_copy(prop); + + if (prop->data.pointer) newp->data.pointer = MEM_dupallocN(prop->data.pointer); + newp->len = prop->len; + newp->subtype = prop->subtype; + newp->totallen = prop->totallen; + + return newp; +} + + void IDP_AssignString(IDProperty *prop, char *st) { int stlen; @@ -154,7 +192,7 @@ void IDP_FreeString(IDProperty *prop) } -/*-------- ID Type -------*/ +/*-------- ID Type, not in use yet -------*/ void IDP_LinkID(IDProperty *prop, ID *id) { @@ -171,6 +209,17 @@ void IDP_UnlinkID(IDProperty *prop) /*-------- Group Functions -------*/ /*checks if a property with the same name as prop exists, and if so replaces it.*/ +IDProperty *IDP_CopyGroup(IDProperty *prop) +{ + IDProperty *newp = idp_generic_copy(prop), *link; + + for (link=prop->data.group.first; link; link=link->next) { + BLI_addtail(&newp->data.group, IDP_CopyProperty(link)); + } + + return newp; +} + void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) { IDProperty *loop; @@ -282,6 +331,15 @@ void IDP_FreeGroup(IDProperty *prop) /*-------- Main Functions --------*/ +IDProperty *IDP_CopyProperty(IDProperty *prop) +{ + switch (prop->type) { + case IDP_GROUP: return IDP_CopyGroup(prop); + case IDP_STRING: return IDP_CopyString(prop); + case IDP_ARRAY: return IDP_CopyArray(prop); + default: return idp_generic_copy(prop); + } +} IDProperty *IDP_GetProperties(ID *id, int create_if_needed) { diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 0163cced795..28a6aad7b4d 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -409,7 +409,8 @@ void *copy_libblock(void *rt) id->newid= idn; idn->flag |= LIB_NEW; - + if (id->properties) idn->properties = IDP_CopyProperty(id->properties); + return idn; } diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h index 14e39faf2c6..f8ad5399af3 100644 --- a/source/blender/makesdna/DNA_ID.h +++ b/source/blender/makesdna/DNA_ID.h @@ -65,7 +65,7 @@ typedef struct IDProperty { /*totallen is total length of allocated array/string, including a buffer. Note that the buffering is mild; the code comes from python's list implementation.*/ int totallen; /*strings and arrays are both buffered, though the buffer isn't - saved. at least it won't be when I write that code. :)*/ + saved.*/ } IDProperty; #define MAX_IDPROP_NAME 32 @@ -75,21 +75,12 @@ typedef struct IDProperty { #define IDP_STRING 0 #define IDP_INT 1 #define IDP_FLOAT 2 -#define IDP_VECTOR 3 -#define IDP_MATRIX 4 #define IDP_ARRAY 5 #define IDP_GROUP 6 +/*the ID link property type hasn't been implemented yet, this will require + some cleanup of blenkernel, most likely.*/ #define IDP_ID 7 -/*special types for vector, matrices and arrays - these arn't quite completely implemented, and - may be removed.*/ -#define IDP_MATRIX4X4 9 -#define IDP_MATRIX3X3 10 -#define IDP_VECTOR2D 11 -#define IDP_VECTOR3D 12 -#define IDP_VECTOR4D 13 -#define IDP_FILE 14 /*add any future new id property types here.*/ /* watch it: Sequence has identical beginning. */ |