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
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2006-11-17 09:14:15 +0300
committerJoseph Eagar <joeedh@gmail.com>2006-11-17 09:14:15 +0300
commit4c5fcf136b510ddb2aeb9c1c9afbc155e95ce12c (patch)
tree1cf7b5790e151d5f9b2cb39e6ccd2f320bd64b2b
parentc8ca36a9c8b9f8fabf1b8f09507f35349017cfbf (diff)
=ID Properties Update=
This commit adds file reading/writing of ID properties to all ID types, and also adds python access for NMesh, Mesh, Scene and Image. Note that the file reading code might need some more work for certain future/planned features to save right. Also I updated a few comments in idprop.c.
-rw-r--r--source/blender/blenkernel/intern/idprop.c11
-rw-r--r--source/blender/blenloader/intern/readfile.c30
-rw-r--r--source/blender/blenloader/intern/writefile.c26
-rw-r--r--source/blender/python/api2_2x/Image.c3
-rw-r--r--source/blender/python/api2_2x/Mesh.c10
-rw-r--r--source/blender/python/api2_2x/NMesh.c4
-rw-r--r--source/blender/python/api2_2x/Scene.c5
7 files changed, 63 insertions, 26 deletions
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c
index ade4176eeac..66feaffadb7 100644
--- a/source/blender/blenkernel/intern/idprop.c
+++ b/source/blender/blenkernel/intern/idprop.c
@@ -64,13 +64,6 @@ void IDP_ResizeArray(IDProperty *prop, int newlen)
prop->totallen = newsize;
}
-/*does NOT unlink anything!*/
-/*Ok, the way things work, Groups and List Arrays free the ID Property structs of their children.
-
- This is because all ID Property freeing functions free only direct data (not the ID Property
- struct itself), but for Groups and List Arrays their child properties *are* considered
- direct data.
-*/
void IDP_FreeArray(IDProperty *prop)
{
if (prop->data.pointer)
@@ -194,9 +187,9 @@ void IDP_FreeIterBeforeEnd(void *vself)
MEM_freeN(vself);
}
-/*Ok, the way things work, Groups and List Arrays free the ID Property structs of their children.
+/*Ok, the way things work, Groups free the ID Property structs of their children.
This is because all ID Property freeing functions free only direct data (not the ID Property
- struct itself), but for Groups and List Arrays their child properties *are* considered
+ struct itself), but for Groups the child properties *are* considered
direct data.*/
void IDP_FreeGroup(IDProperty *prop)
{
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 8df1040d530..b34b8f554c8 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2104,6 +2104,7 @@ static void lib_link_image(FileData *fd, Main *main)
ima= main->image.first;
while (ima) {
if(ima->id.flag & LIB_NEEDLINK) {
+ if (ima->id.properties) IDP_LibLinkProperty(ima->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
ima->id.flag -= LIB_NEEDLINK;
}
@@ -2279,8 +2280,6 @@ static void lib_link_material(FileData *fd, Main *main)
if(ma->id.flag & LIB_NEEDLINK) {
/*Link ID Properties -- and copy this comment EXACTLY for easy finding
of library blocks that implement this.*/
- /*set head id properties type to IDP_GROUP; calloc kindly initilizes
- all other needed values :) */
if (ma->id.properties) IDP_LibLinkProperty(ma->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
ma->ipo= newlibadr_us(fd, ma->id.lib, ma->ipo);
@@ -2312,11 +2311,6 @@ static void direct_link_material(FileData *fd, Material *ma)
ma->mtex[a]= newdataadr(fd, ma->mtex[a]);
}
- if (ma->id.properties) {
- ma->id.properties = newdataadr(fd, ma->id.properties);
- IDP_DirectLinkProperty(ma->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
- }
-
ma->ramp_col= newdataadr(fd, ma->ramp_col);
ma->ramp_spec= newdataadr(fd, ma->ramp_spec);
@@ -2338,6 +2332,10 @@ static void lib_link_mesh(FileData *fd, Main *main)
if(me->id.flag & LIB_NEEDLINK) {
int i;
+ /*Link ID Properties -- and copy this comment EXACTLY for easy finding
+ of library blocks that implement this.*/
+ if (me->id.properties) IDP_LibLinkProperty(me->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+
/* this check added for python created meshes */
if(me->mat) {
for(i=0; i<me->totcol; i++) {
@@ -2725,11 +2723,6 @@ static void direct_link_object(FileData *fd, Object *ob)
ob->pose= newdataadr(fd, ob->pose);
direct_link_pose(fd, ob->pose);
- if (ob->id.properties) {
- ob->id.properties = newdataadr(fd, ob->id.properties);
- IDP_DirectLinkProperty(ob->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
- }
-
link_list(fd, &ob->defbase);
direct_link_nlastrips(fd, &ob->nlastrips);
link_list(fd, &ob->constraintChannels);
@@ -2904,7 +2897,10 @@ static void lib_link_scene(FileData *fd, Main *main)
sce= main->scene.first;
while(sce) {
if(sce->id.flag & LIB_NEEDLINK) {
-
+ /*Link ID Properties -- and copy this comment EXACTLY for easy finding
+ of library blocks that implement this.*/
+ if (sce->id.properties) IDP_LibLinkProperty(sce->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+
sce->camera= newlibadr(fd, sce->id.lib, sce->camera);
sce->world= newlibadr_us(fd, sce->id.lib, sce->world);
sce->set= newlibadr(fd, sce->id.lib, sce->set);
@@ -2992,7 +2988,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
sce->dagisvalid = 0;
/* set users to one by default, not in lib-link, this will increase it for compo nodes */
sce->id.us= 1;
-
+
link_list(fd, &(sce->base));
sce->basact= newdataadr(fd, sce->basact);
@@ -3905,6 +3901,12 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
direct_link_brush(fd, (Brush*)id);
break;
}
+
+ /*link direct data of ID properties*/
+ if (id->properties) {
+ id->properties = newdataadr(fd, id->properties);
+ IDP_DirectLinkProperty(id->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+ }
oldnewmap_free_unused(fd->datamap);
oldnewmap_clear(fd->datamap);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 40facd30b2f..4fcf982970f 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -824,8 +824,6 @@ static void write_objects(WriteData *wd, ListBase *idbase)
/*Write ID Properties -- and copy this comment EXACTLY for easy finding
of library blocks that implement this.*/
- /*manually set head group property to IDP_GROUP, just in case it hadn't been
- set yet :) */
if (ob->id.properties) IDP_WriteProperty(ob->id.properties, wd);
/* direct data */
@@ -875,6 +873,7 @@ static void write_vfonts(WriteData *wd, ListBase *idbase)
if(vf->id.us>0 || wd->current) {
/* write LibData */
writestruct(wd, ID_VF, "VFont", 1, vf);
+ if (vf->id.properties) IDP_WriteProperty(vf->id.properties, wd);
/* direct data */
@@ -899,6 +898,7 @@ static void write_ipos(WriteData *wd, ListBase *idbase)
if(ipo->id.us>0 || wd->current) {
/* write LibData */
writestruct(wd, ID_IP, "Ipo", 1, ipo);
+ if (ipo->id.properties) IDP_WriteProperty(ipo->id.properties, wd);
/* direct data */
icu= ipo->curve.first;
@@ -933,6 +933,7 @@ static void write_keys(WriteData *wd, ListBase *idbase)
if(key->id.us>0 || wd->current) {
/* write LibData */
writestruct(wd, ID_KE, "Key", 1, key);
+ if (key->id.properties) IDP_WriteProperty(key->id.properties, wd);
/* direct data */
kb= key->block.first;
@@ -958,6 +959,7 @@ static void write_cameras(WriteData *wd, ListBase *idbase)
if(cam->id.us>0 || wd->current) {
/* write LibData */
writestruct(wd, ID_CA, "Camera", 1, cam);
+ if (cam->id.properties) IDP_WriteProperty(cam->id.properties, wd);
/* direct data */
write_scriptlink(wd, &cam->scriptlink);
@@ -977,6 +979,7 @@ static void write_mballs(WriteData *wd, ListBase *idbase)
if(mb->id.us>0 || wd->current) {
/* write LibData */
writestruct(wd, ID_MB, "MetaBall", 1, mb);
+ if (mb->id.properties) IDP_WriteProperty(mb->id.properties, wd);
/* direct data */
writedata(wd, DATA, sizeof(void *)*mb->totcol, mb->mat);
@@ -1011,6 +1014,7 @@ static void write_curves(WriteData *wd, ListBase *idbase)
/* direct data */
writedata(wd, DATA, sizeof(void *)*cu->totcol, cu->mat);
+ if (cu->id.properties) IDP_WriteProperty(cu->id.properties, wd);
if(cu->vfont) {
writedata(wd, DATA, amount_of_chars(cu->str)+1, cu->str);
@@ -1084,6 +1088,8 @@ static void write_meshs(WriteData *wd, ListBase *idbase)
#endif
/* direct data */
+ if (mesh->id.properties) IDP_WriteProperty(mesh->id.properties, wd);
+
writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat);
writestruct(wd, DATA, "MVert", mesh->pv?mesh->pv->totvert:mesh->totvert, mesh->mvert);
@@ -1129,7 +1135,8 @@ static void write_lattices(WriteData *wd, ListBase *idbase)
if(lt->id.us>0 || wd->current) {
/* write LibData */
writestruct(wd, ID_LT, "Lattice", 1, lt);
-
+ if (lt->id.properties) IDP_WriteProperty(lt->id.properties, wd);
+
/* direct data */
writestruct(wd, DATA, "BPoint", lt->pntsu*lt->pntsv*lt->pntsw, lt->def);
@@ -1151,6 +1158,7 @@ static void write_images(WriteData *wd, ListBase *idbase)
if(ima->id.us>0 || wd->current) {
/* write LibData */
writestruct(wd, ID_IM, "Image", 1, ima);
+ if (ima->id.properties) IDP_WriteProperty(ima->id.properties, wd);
if (ima->packedfile) {
pf = ima->packedfile;
@@ -1179,6 +1187,7 @@ static void write_textures(WriteData *wd, ListBase *idbase)
if(tex->id.us>0 || wd->current) {
/* write LibData */
writestruct(wd, ID_TE, "Tex", 1, tex);
+ if (tex->id.properties) IDP_WriteProperty(tex->id.properties, wd);
/* direct data */
if(tex->plugin) writestruct(wd, DATA, "PluginTex", 1, tex->plugin);
@@ -1238,6 +1247,7 @@ static void write_worlds(WriteData *wd, ListBase *idbase)
if(wrld->id.us>0 || wd->current) {
/* write LibData */
writestruct(wd, ID_WO, "World", 1, wrld);
+ if (wrld->id.properties) IDP_WriteProperty(wrld->id.properties, wd);
for(a=0; a<MAX_MTEX; a++) {
if(wrld->mtex[a]) writestruct(wd, DATA, "MTex", 1, wrld->mtex[a]);
@@ -1259,6 +1269,7 @@ static void write_lamps(WriteData *wd, ListBase *idbase)
if(la->id.us>0 || wd->current) {
/* write LibData */
writestruct(wd, ID_LA, "Lamp", 1, la);
+ if (la->id.properties) IDP_WriteProperty(la->id.properties, wd);
/* direct data */
for(a=0; a<MAX_MTEX; a++) {
@@ -1288,6 +1299,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
while(sce) {
/* write LibData */
writestruct(wd, ID_SCE, "Scene", 1, sce);
+ if (sce->id.properties) IDP_WriteProperty(sce->id.properties, wd);
/* direct data */
base= sce->base.first;
@@ -1399,6 +1411,7 @@ static void write_screens(WriteData *wd, ListBase *scrbase)
while(sc) {
/* write LibData */
writestruct(wd, ID_SCR, "Screen", 1, sc);
+ if (sc->id.properties) IDP_WriteProperty(sc->id.properties, wd);
/* direct data */
sv= sc->vertbase.first;
@@ -1593,6 +1606,7 @@ static void write_armatures(WriteData *wd, ListBase *idbase)
while (arm) {
if (arm->id.us>0 || wd->current) {
writestruct(wd, ID_AR, "bArmature", 1, arm);
+ if (arm->id.properties) IDP_WriteProperty(arm->id.properties, wd);
/* Direct data */
bone= arm->bonebase.first;
@@ -1617,6 +1631,7 @@ static void write_actions(WriteData *wd, ListBase *idbase)
for(act=idbase->first; act; act= act->id.next) {
if (act->id.us>0 || wd->current) {
writestruct(wd, ID_AC, "bAction", 1, act);
+ if (act->id.properties) IDP_WriteProperty(act->id.properties, wd);
for (chan=act->chanbase.first; chan; chan=chan->next) {
writestruct(wd, DATA, "bActionChannel", 1, chan);
@@ -1642,6 +1657,7 @@ static void write_texts(WriteData *wd, ListBase *idbase)
/* write LibData */
writestruct(wd, ID_TXT, "Text", 1, text);
if(text->name) writedata(wd, DATA, strlen(text->name)+1, text->name);
+ if (text->id.properties) IDP_WriteProperty(text->id.properties, wd);
if(!(text->flags & TXT_ISEXT)) {
/* now write the text data, in two steps for optimization in the readfunction */
@@ -1695,6 +1711,7 @@ static void write_sounds(WriteData *wd, ListBase *idbase)
/* write LibData */
writestruct(wd, ID_SO, "bSound", 1, sound);
+ if (sound->id.properties) IDP_WriteProperty(sound->id.properties, wd);
if (sound->newpackedfile) {
pf = sound->newpackedfile;
@@ -1722,6 +1739,7 @@ static void write_groups(WriteData *wd, ListBase *idbase)
if(group->id.us>0 || wd->current) {
/* write LibData */
writestruct(wd, ID_GR, "Group", 1, group);
+ if (group->id.properties) IDP_WriteProperty(group->id.properties, wd);
go= group->gobject.first;
while(go) {
@@ -1740,6 +1758,7 @@ static void write_nodetrees(WriteData *wd, ListBase *idbase)
if (ntree->id.us>0 || wd->current) {
writestruct(wd, ID_NT, "bNodeTree", 1, ntree);
write_nodetree(wd, ntree);
+ if (ntree->id.properties) IDP_WriteProperty(ntree->id.properties, wd);
}
}
}
@@ -1752,6 +1771,7 @@ static void write_brushes(WriteData *wd, ListBase *idbase)
for(brush=idbase->first; brush; brush= brush->id.next) {
if(brush->id.us>0 || wd->current) {
writestruct(wd, ID_BR, "Brush", 1, brush);
+ if (brush->id.properties) IDP_WriteProperty(brush->id.properties, wd);
for(a=0; a<MAX_MTEX; a++)
if(brush->mtex[a])
writestruct(wd, DATA, "MTex", 1, brush->mtex[a]);
diff --git a/source/blender/python/api2_2x/Image.c b/source/blender/python/api2_2x/Image.c
index 16e537e37d4..d6458c12435 100644
--- a/source/blender/python/api2_2x/Image.c
+++ b/source/blender/python/api2_2x/Image.c
@@ -47,6 +47,7 @@
#include "DNA_packedFile_types.h"
#include "BKE_icons.h"
#include "IMB_imbuf.h"
+#include "IDProp.h"
/* used so we can get G.scene->r.cfra for getting the
current image frame, some images change frame if they are a sequence */
@@ -1150,6 +1151,8 @@ static PyObject *Image_getAttr( BPy_Image * self, char *name )
if( strcmp( name, "name" ) == 0 )
attr = PyString_FromString( self->image->id.name + 2 );
+ else if ( strcmp( name, "properties" ) == 0 )
+ return BPy_Wrap_IDProperty( (ID*)self->image, IDP_GetProperties((ID*)self->image, 1) );
else if( strcmp( name, "filename" ) == 0 )
attr = PyString_FromString( self->image->name );
else if( strcmp( name, "size" ) == 0 )
diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c
index c8b444a830e..3f88a06da93 100644
--- a/source/blender/python/api2_2x/Mesh.c
+++ b/source/blender/python/api2_2x/Mesh.c
@@ -81,6 +81,7 @@
#include "Image.h"
#include "Material.h"
#include "Mathutils.h"
+#include "IDProp.h"
#include "meshPrimitive.h"
#include "constant.h"
#include "gen_utils.h"
@@ -7384,10 +7385,19 @@ static PyObject *Mesh_repr( BPy_Mesh * self )
self->mesh->id.name + 2 );
}
+static PyObject *Mesh_getProperties( BPy_Mesh * self )
+{
+ /*sanity check, we set parent property type to Group here*/
+ return BPy_Wrap_IDProperty( (ID*)self->mesh, IDP_GetProperties((ID*)self->mesh, 1) );
+}
+
/*****************************************************************************/
/* Python Mesh_Type attributes get/set structure: */
/*****************************************************************************/
static PyGetSetDef BPy_Mesh_getseters[] = {
+ {"properties",
+ (getter)Mesh_getProperties, NULL,
+ "get the ID properties associated with this mesh"},
{"verts",
(getter)Mesh_getVerts, (setter)Mesh_setVerts,
"The mesh's vertices (MVert)",
diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c
index fe97a7c916a..164011fee6e 100644
--- a/source/blender/python/api2_2x/NMesh.c
+++ b/source/blender/python/api2_2x/NMesh.c
@@ -73,6 +73,7 @@
#include "Object.h"
#include "Key.h"
#include "Mathutils.h"
+#include "IDProp.h"
#include "constant.h"
#include "gen_utils.h"
@@ -1718,6 +1719,9 @@ static PyObject *NMesh_getattr( PyObject * self, char *name )
if( strcmp( name, "name" ) == 0 )
return EXPP_incr_ret( me->name );
+ else if ( strcmp( name, "properties" ) == 0 )
+ return BPy_Wrap_IDProperty( (ID*)me->mesh, IDP_GetProperties((ID*)me->mesh, 1) );
+
else if( strcmp( name, "mode" ) == 0 )
return PyInt_FromLong( me->mode );
diff --git a/source/blender/python/api2_2x/Scene.c b/source/blender/python/api2_2x/Scene.c
index 8b096f81840..150aa0b9fd3 100644
--- a/source/blender/python/api2_2x/Scene.c
+++ b/source/blender/python/api2_2x/Scene.c
@@ -67,6 +67,7 @@ struct View3D;
#include "Mesh.h"
#include "Lattice.h"
#include "Metaball.h"
+#include "IDProp.h"
#include "Text3d.h"
#include "gen_utils.h"
@@ -279,6 +280,10 @@ static PyObject *Scene_getAttr( BPy_Scene * self, char *name )
if( strcmp( name, "name" ) == 0 )
attr = PyString_FromString( self->scene->id.name + 2 );
+
+ else if ( strcmp( name, "properties" ) == 0 )
+ return BPy_Wrap_IDProperty( (ID*)self->scene, IDP_GetProperties((ID*)self->scene, 1) );
+
/* accept both Layer (for compatibility with ob.Layer) and Layers */
else if( strncmp( name, "Layer", 5 ) == 0 )
attr = PyInt_FromLong( self->scene->lay & (1<<20)-1 );