From 4f01085709908e5626c735b01d6c2202236f41e6 Mon Sep 17 00:00:00 2001 From: Joseph Eagar Date: Mon, 9 Jul 2007 20:42:14 +0000 Subject: =ID Property update= ID Properties weren't being duplicated (by shift-D or any of the other duplication functions). So now ID properties are duplicated in the main copy_libblock function, which (as far as I can check) covers all ID-contained ID properties. I also updated the constraint system to copy pyconstraint ID properties on shift-D. This would probably be a good thing to add to the stable branch, btw. --- source/blender/blenkernel/BKE_idprop.h | 1 + source/blender/blenkernel/intern/constraint.c | 11 ++++- source/blender/blenkernel/intern/idprop.c | 60 ++++++++++++++++++++++++++- source/blender/blenkernel/intern/library.c | 3 +- 4 files changed, 71 insertions(+), 4 deletions(-) (limited to 'source/blender/blenkernel') 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; } -- cgit v1.2.3