[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11200] trunk/blender/source/blender: = ID Property update=
Joseph Eagar
joeedh at gmail.com
Mon Jul 9 22:42:14 CEST 2007
Revision: 11200
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11200
Author: joeedh
Date: 2007-07-09 22:42:14 +0200 (Mon, 09 Jul 2007)
Log Message:
-----------
=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.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/BKE_idprop.h
trunk/blender/source/blender/blenkernel/intern/constraint.c
trunk/blender/source/blender/blenkernel/intern/idprop.c
trunk/blender/source/blender/blenkernel/intern/library.c
trunk/blender/source/blender/makesdna/DNA_ID.h
Modified: trunk/blender/source/blender/blenkernel/BKE_idprop.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_idprop.h 2007-07-09 17:33:38 UTC (rev 11199)
+++ trunk/blender/source/blender/blenkernel/BKE_idprop.h 2007-07-09 20:42:14 UTC (rev 11200)
@@ -137,6 +137,7 @@
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.
Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c 2007-07-09 17:33:38 UTC (rev 11199)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c 2007-07-09 20:42:14 UTC (rev 11200)
@@ -162,14 +162,21 @@
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) */
}
}
Modified: trunk/blender/source/blender/blenkernel/intern/idprop.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/idprop.c 2007-07-09 17:33:38 UTC (rev 11199)
+++ trunk/blender/source/blender/blenkernel/intern/idprop.c 2007-07-09 20:42:14 UTC (rev 11200)
@@ -104,6 +104,31 @@
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 @@
/* ---------- 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 @@
}
-/*-------- ID Type -------*/
+/*-------- ID Type, not in use yet -------*/
void IDP_LinkID(IDProperty *prop, ID *id)
{
@@ -171,6 +209,17 @@
/*-------- 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 @@
/*-------- 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)
{
Modified: trunk/blender/source/blender/blenkernel/intern/library.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/library.c 2007-07-09 17:33:38 UTC (rev 11199)
+++ trunk/blender/source/blender/blenkernel/intern/library.c 2007-07-09 20:42:14 UTC (rev 11200)
@@ -409,7 +409,8 @@
id->newid= idn;
idn->flag |= LIB_NEW;
-
+ if (id->properties) idn->properties = IDP_CopyProperty(id->properties);
+
return idn;
}
Modified: trunk/blender/source/blender/makesdna/DNA_ID.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_ID.h 2007-07-09 17:33:38 UTC (rev 11199)
+++ trunk/blender/source/blender/makesdna/DNA_ID.h 2007-07-09 20:42:14 UTC (rev 11200)
@@ -65,7 +65,7 @@
/*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 @@
#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. */
More information about the Bf-blender-cvs
mailing list