diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-09-05 01:02:43 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-09-05 01:02:43 +0400 |
commit | 5dd9f7635afeda66ca4475288b1eb7ad621486f4 (patch) | |
tree | 731ca793fb25b3ee986abaca0c08b4f90c74a06d /source/blender/blenkernel/intern | |
parent | 670296dabe9c4c5444c696af54e1b4ef07a8e60b (diff) |
2.5
Make local and make single user are back for ID template.
Internally these calls got unified, id_make_local and
id_copy are now used to do these operations for all types
that support it. Also reveals that for some ID types the
implementation is still missing.
Further, some small changes:
* unlink_text is now in blenkernel.
* copy_group was implemented.
* ID template now has an open operator again.
* fix preview to not change material reference count,
even if temporary it shows up with threaded preview.
* id_unlink unifies unlink for text, object and group.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/group.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 225 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/sca.c | 24 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 11 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 93 |
5 files changed, 318 insertions, 45 deletions
diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index 6fffbd794ef..6bb47bc0f0f 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -142,6 +142,16 @@ Group *add_group(char *name) return group; } +Group *copy_group(Group *group) +{ + Group *groupn; + + groupn= MEM_dupallocN(group); + BLI_duplicatelist(&groupn->gobject, &group->gobject); + + return groupn; +} + /* external */ void add_to_group(Group *group, Object *ob) { diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 3c8bf9200f8..f15552ab40c 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -119,6 +119,13 @@ #define MAX_IDPUP 60 /* was 24 */ +/* GS reads the memory pointed at in a specific ordering. + only use this definition, makes little and big endian systems + work fine, in conjunction with MAKE_ID */ + +/* from blendef: */ +#define GS(a) (*((short *)(a))) + /* ************* general ************************ */ void id_lib_extern(ID *id) @@ -148,6 +155,217 @@ void id_us_min(ID *id) id->us--; } +int id_make_local(ID *id, int test) +{ + if(id->flag & LIB_INDIRECT) + return 0; + + switch(GS(id->name)) { + case ID_SCE: + return 0; /* not implemented */ + case ID_LI: + return 0; /* can't be linked */ + case ID_OB: + if(!test) make_local_object((Object*)id); + return 1; + case ID_ME: + if(!test) { + make_local_mesh((Mesh*)id); + make_local_key(((Mesh*)id)->key); + } + return 1; + case ID_CU: + if(!test) { + make_local_curve((Curve*)id); + make_local_key(((Curve*)id)->key); + } + return 1; + case ID_MB: + if(!test) make_local_mball((MetaBall*)id); + return 1; + case ID_MA: + if(!test) make_local_material((Material*)id); + return 1; + case ID_TE: + if(!test) make_local_texture((Tex*)id); + return 1; + case ID_IM: + return 0; /* not implemented */ + case ID_WV: + return 0; /* deprecated */ + case ID_LT: + if(!test) make_local_lattice((Lattice*)id); + return 1; + case ID_LA: + if(!test) make_local_lamp((Lamp*)id); + return 1; + case ID_CA: + if(!test) make_local_camera((Camera*)id); + return 1; + case ID_IP: + return 0; /* deprecated */ + case ID_KE: + if(!test) make_local_key((Key*)id); + return 1; + case ID_WO: + if(!test) make_local_world((World*)id); + return 1; + case ID_SCR: + return 0; /* can't be linked */ + case ID_VF: + return 0; /* not implemented */ + case ID_TXT: + return 0; /* not implemented */ + case ID_SCRIPT: + return 0; /* deprecated */ + case ID_SO: + return 0; /* not implemented */ + case ID_GR: + return 0; /* not implemented */ + case ID_AR: + if(!test) make_local_armature((bArmature*)id); + return 1; + case ID_AC: + if(!test) make_local_action((bAction*)id); + return 1; + case ID_NT: + return 0; /* not implemented */ + case ID_BR: + if(!test) make_local_brush((Brush*)id); + return 1; + case ID_PA: + if(!test) make_local_particlesettings((ParticleSettings*)id); + return 1; + case ID_WM: + return 0; /* can't be linked */ + case ID_GD: + return 0; /* not implemented */ + } + + return 0; +} + +int id_copy(ID *id, ID **newid, int test) +{ + if(!test) *newid= NULL; + + /* conventions: + * - make shallow copy, only this ID block + * - id.us of the new ID is set to 1 */ + switch(GS(id->name)) { + case ID_SCE: + return 0; /* can't be copied from here */ + case ID_LI: + return 0; /* can't be copied from here */ + case ID_OB: + if(!test) *newid= (ID*)copy_object((Object*)id); + return 1; + case ID_ME: + if(!test) *newid= (ID*)copy_mesh((Mesh*)id); + return 1; + case ID_CU: + if(!test) *newid= (ID*)copy_curve((Curve*)id); + return 1; + case ID_MB: + if(!test) *newid= (ID*)copy_mball((MetaBall*)id); + return 1; + case ID_MA: + if(!test) *newid= (ID*)copy_material((Material*)id); + return 1; + case ID_TE: + if(!test) *newid= (ID*)copy_texture((Tex*)id); + return 1; + case ID_IM: + return 0; /* not implemented */ + case ID_WV: + return 0; /* deprecated */ + case ID_LT: + if(!test) *newid= (ID*)copy_lattice((Lattice*)id); + return 1; + case ID_LA: + if(!test) *newid= (ID*)copy_lamp((Lamp*)id); + return 1; + case ID_CA: + if(!test) *newid= (ID*)copy_camera((Camera*)id); + return 1; + case ID_IP: + return 0; /* deprecated */ + case ID_KE: + if(!test) *newid= (ID*)copy_key((Key*)id); + return 1; + case ID_WO: + if(!test) *newid= (ID*)copy_world((World*)id); + return 1; + case ID_SCR: + return 0; /* can't be copied from here */ + case ID_VF: + return 0; /* not implemented */ + case ID_TXT: + if(!test) *newid= (ID*)copy_text((Text*)id); + return 1; + case ID_SCRIPT: + return 0; /* deprecated */ + case ID_SO: + return 0; /* not implemented */ + case ID_GR: + if(!test) *newid= (ID*)copy_group((Group*)id); + return 1; + case ID_AR: + if(!test) *newid= (ID*)copy_armature((bArmature*)id); + return 1; + case ID_AC: + if(!test) *newid= (ID*)copy_action((bAction*)id); + return 1; + case ID_NT: + if(!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id, 0); + return 1; + case ID_BR: + if(!test) *newid= (ID*)copy_brush((Brush*)id); + return 1; + case ID_PA: + if(!test) *newid= (ID*)psys_copy_settings((ParticleSettings*)id); + return 1; + case ID_WM: + return 0; /* can't be copied from here */ + case ID_GD: + return 0; /* not implemented */ + } + + return 0; +} + +int id_unlink(ID *id, int test) +{ + Main *mainlib= G.main; + ListBase *lb; + + switch(GS(id->name)) { + case ID_TXT: + if(test) return 1; + unlink_text(mainlib, (Text*)id); + break; + case ID_GR: + if(test) return 1; + unlink_group((Group*)id); + break; + case ID_OB: + if(test) return 1; + unlink_object(NULL, (Object*)id); + break; + } + + if(id->us == 0) { + if(test) return 1; + + lb= wich_libbase(mainlib, GS(id->name)); + free_libblock(lb, id); + + return 1; + } + + return 0; +} + ListBase *wich_libbase(Main *mainlib, short type) { switch( type ) { @@ -409,13 +627,6 @@ void *alloc_libblock(ListBase *lb, short type, const char *name) return id; } -/* GS reads the memory pointed at in a specific ordering. - only use this definition, makes little and big endian systems - work fine, in conjunction with MAKE_ID */ - -/* from blendef: */ -#define GS(a) (*((short *)(a))) - /* by spec, animdata is first item after ID */ /* we still read ->adt itself, to ensure compiler warns when it doesnt exist */ static void id_copy_animdata(ID *id) diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index e4d73208c64..de2118af202 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -52,30 +52,6 @@ #include "BKE_blender.h" #include "BKE_sca.h" -//#include "wm_event_types.h" - -void free_text_controllers(Text *txt) -{ - Object *ob; - bController *cont; - - ob= G.main->object.first; - while(ob) { - cont= ob->controllers.first; - while(cont) { - if(cont->type==CONT_PYTHON) { - bPythonCont *pc; - - pc= cont->data; - if(pc->text==txt) pc->text= NULL; - } - cont= cont->next; - } - ob= ob->id.next; - } -} - - /* ******************* SENSORS ************************ */ void free_sensor(bSensor *sens) diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 10f6a8cf47c..6f9ed3e0978 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -860,14 +860,3 @@ float get_render_aosss_error(RenderData *r, float error) return error; } -void free_dome_warp_text(struct Text *txt) -{ - Scene *scene; - - scene = G.main->scene.first; - while(scene) { - if (scene->r.dometext == txt) - scene->r.dometext = NULL; - scene = scene->id.next; - } -} diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 8e3d59bbc58..dac426de4eb 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -37,14 +37,22 @@ #include "BLI_blenlib.h" +#include "DNA_action_types.h" +#include "DNA_armature_types.h" +#include "DNA_constraint_types.h" +#include "DNA_controller_types.h" #include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_space_types.h" #include "DNA_text_types.h" -#include "BKE_utildefines.h" -#include "BKE_text.h" -#include "BKE_library.h" +#include "BKE_depsgraph.h" #include "BKE_global.h" +#include "BKE_library.h" #include "BKE_main.h" +#include "BKE_node.h" +#include "BKE_text.h" +#include "BKE_utildefines.h" #ifndef DISABLE_PYTHON #include "BPY_extern.h" @@ -451,6 +459,85 @@ Text *copy_text(Text *ta) return tan; } +void unlink_text(Main *bmain, Text *text) +{ + bScreen *scr; + ScrArea *area; + SpaceLink *sl; + Scene *scene; + Object *ob; + bController *cont; + bConstraint *con; + short update; + + /* dome */ + for(scene=bmain->scene.first; scene; scene=scene->id.next) + if(scene->r.dometext == text) + scene->r.dometext = NULL; + + for(ob=bmain->object.first; ob; ob=ob->id.next) { + /* game controllers */ + for(cont=ob->controllers.first; cont; cont=cont->next) { + if(cont->type==CONT_PYTHON) { + bPythonCont *pc; + + pc= cont->data; + if(pc->text==text) pc->text= NULL; + } + } + + /* pyconstraints */ + update = 0; + + if(ob->type==OB_ARMATURE && ob->pose) { + bPoseChannel *pchan; + for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { + for(con = pchan->constraints.first; con; con=con->next) { + if(con->type==CONSTRAINT_TYPE_PYTHON) { + bPythonConstraint *data = con->data; + if (data->text==text) data->text = NULL; + update = 1; + + } + } + } + } + + for(con = ob->constraints.first; con; con=con->next) { + if(con->type==CONSTRAINT_TYPE_PYTHON) { + bPythonConstraint *data = con->data; + if (data->text==text) data->text = NULL; + update = 1; + } + } + + if(update) + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + } + + /* pynodes */ + // XXX nodeDynamicUnlinkText(&text->id); + + /* text space */ + for(scr= bmain->screen.first; scr; scr= scr->id.next) { + for(area= scr->areabase.first; area; area= area->next) { + for(sl= area->spacedata.first; sl; sl= sl->next) { + if(sl->spacetype==SPACE_TEXT) { + SpaceText *st= (SpaceText*) sl; + + if(st->text==text) { + st->text= NULL; + st->top= 0; + } + } + } + } + } + + text->id.us= 0; +} + + /*****************************/ /* Editing utility functions */ /*****************************/ |