diff options
Diffstat (limited to 'source/blender/blenkernel/intern/library.c')
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 240 |
1 files changed, 121 insertions, 119 deletions
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 3bfccea4780..eb28e9f641a 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -143,8 +143,8 @@ void BKE_id_lib_local_paths(Main *bmain, Library *lib, ID *id) void id_lib_extern(ID *id) { - if(id) { - if(id->flag & LIB_INDIRECT) { + if (id) { + if (id->flag & LIB_INDIRECT) { id->flag -= LIB_INDIRECT; id->flag |= LIB_EXTERN; } @@ -153,9 +153,9 @@ void id_lib_extern(ID *id) void id_us_plus(ID *id) { - if(id) { + if (id) { id->us++; - if(id->flag & LIB_INDIRECT) { + if (id->flag & LIB_INDIRECT) { id->flag -= LIB_INDIRECT; id->flag |= LIB_EXTERN; } @@ -164,10 +164,10 @@ void id_us_plus(ID *id) void id_us_min(ID *id) { - if(id) { - if(id->us<2 && (id->flag & LIB_FAKEUSER)) + if (id) { + if (id->us<2 && (id->flag & LIB_FAKEUSER)) id->us= 1; - else if(id->us<=0) + else if (id->us<=0) printf("ID user decrement error: %s \n", id->name); else id->us--; @@ -176,7 +176,7 @@ void id_us_min(ID *id) int id_make_local(ID *id, int test) { - if(id->flag & LIB_INDIRECT) + if (id->flag & LIB_INDIRECT) return 0; switch(GS(id->name)) { @@ -185,54 +185,54 @@ int id_make_local(ID *id, int test) case ID_LI: return 0; /* can't be linked */ case ID_OB: - if(!test) make_local_object((Object*)id); + if (!test) make_local_object((Object*)id); return 1; case ID_ME: - if(!test) { + if (!test) { make_local_mesh((Mesh*)id); make_local_key(((Mesh*)id)->key); } return 1; case ID_CU: - if(!test) { + 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); + if (!test) make_local_mball((MetaBall*)id); return 1; case ID_MA: - if(!test) make_local_material((Material*)id); + if (!test) make_local_material((Material*)id); return 1; case ID_TE: - if(!test) make_local_texture((Tex*)id); + if (!test) make_local_texture((Tex*)id); return 1; case ID_IM: - if(!test) make_local_image((Image*)id); + if (!test) make_local_image((Image*)id); return 1; case ID_LT: - if(!test) { + if (!test) { make_local_lattice((Lattice*)id); make_local_key(((Lattice*)id)->key); } return 1; case ID_LA: - if(!test) make_local_lamp((Lamp*)id); + if (!test) make_local_lamp((Lamp*)id); return 1; case ID_CA: - if(!test) make_local_camera((Camera*)id); + if (!test) make_local_camera((Camera*)id); return 1; case ID_SPK: - if(!test) make_local_speaker((Speaker*)id); + if (!test) make_local_speaker((Speaker*)id); return 1; case ID_IP: return 0; /* deprecated */ case ID_KE: - if(!test) make_local_key((Key*)id); + if (!test) make_local_key((Key*)id); return 1; case ID_WO: - if(!test) make_local_world((World*)id); + if (!test) make_local_world((World*)id); return 1; case ID_SCR: return 0; /* can't be linked */ @@ -247,18 +247,18 @@ int id_make_local(ID *id, int test) case ID_GR: return 0; /* not implemented */ case ID_AR: - if(!test) make_local_armature((bArmature*)id); + if (!test) make_local_armature((bArmature*)id); return 1; case ID_AC: - if(!test) make_local_action((bAction*)id); + 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); + if (!test) make_local_brush((Brush*)id); return 1; case ID_PA: - if(!test) make_local_particlesettings((ParticleSettings*)id); + if (!test) make_local_particlesettings((ParticleSettings*)id); return 1; case ID_WM: return 0; /* can't be linked */ @@ -271,7 +271,7 @@ int id_make_local(ID *id, int test) int id_copy(ID *id, ID **newid, int test) { - if(!test) *newid= NULL; + if (!test) *newid= NULL; /* conventions: * - make shallow copy, only this ID block @@ -282,74 +282,74 @@ int id_copy(ID *id, ID **newid, int test) case ID_LI: return 0; /* can't be copied from here */ case ID_OB: - if(!test) *newid= (ID*)copy_object((Object*)id); + if (!test) *newid= (ID*)copy_object((Object*)id); return 1; case ID_ME: - if(!test) *newid= (ID*)copy_mesh((Mesh*)id); + if (!test) *newid= (ID*)copy_mesh((Mesh*)id); return 1; case ID_CU: - if(!test) *newid= (ID*)copy_curve((Curve*)id); + if (!test) *newid= (ID*)copy_curve((Curve*)id); return 1; case ID_MB: - if(!test) *newid= (ID*)copy_mball((MetaBall*)id); + if (!test) *newid= (ID*)copy_mball((MetaBall*)id); return 1; case ID_MA: - if(!test) *newid= (ID*)copy_material((Material*)id); + if (!test) *newid= (ID*)copy_material((Material*)id); return 1; case ID_TE: - if(!test) *newid= (ID*)copy_texture((Tex*)id); + if (!test) *newid= (ID*)copy_texture((Tex*)id); return 1; case ID_IM: - if(!test) *newid= (ID*)copy_image((Image*)id); + if (!test) *newid= (ID*)copy_image((Image*)id); return 1; case ID_LT: - if(!test) *newid= (ID*)copy_lattice((Lattice*)id); + if (!test) *newid= (ID*)copy_lattice((Lattice*)id); return 1; case ID_LA: - if(!test) *newid= (ID*)copy_lamp((Lamp*)id); + if (!test) *newid= (ID*)copy_lamp((Lamp*)id); return 1; case ID_SPK: - if(!test) *newid= (ID*)copy_speaker((Speaker*)id); + if (!test) *newid= (ID*)copy_speaker((Speaker*)id); return 1; case ID_CA: - if(!test) *newid= (ID*)copy_camera((Camera*)id); + 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); + if (!test) *newid= (ID*)copy_key((Key*)id); return 1; case ID_WO: - if(!test) *newid= (ID*)copy_world((World*)id); + 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); + 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); + if (!test) *newid= (ID*)copy_group((Group*)id); return 1; case ID_AR: - if(!test) *newid= (ID*)copy_armature((bArmature*)id); + if (!test) *newid= (ID*)copy_armature((bArmature*)id); return 1; case ID_AC: - if(!test) *newid= (ID*)copy_action((bAction*)id); + if (!test) *newid= (ID*)copy_action((bAction*)id); return 1; case ID_NT: - if(!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id); + if (!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id); return 1; case ID_BR: - if(!test) *newid= (ID*)copy_brush((Brush*)id); + if (!test) *newid= (ID*)copy_brush((Brush*)id); return 1; case ID_PA: - if(!test) *newid= (ID*)psys_copy_settings((ParticleSettings*)id); + if (!test) *newid= (ID*)psys_copy_settings((ParticleSettings*)id); return 1; case ID_WM: return 0; /* can't be copied from here */ @@ -367,21 +367,21 @@ int id_unlink(ID *id, int test) switch(GS(id->name)) { case ID_TXT: - if(test) return 1; + if (test) return 1; unlink_text(mainlib, (Text*)id); break; case ID_GR: - if(test) return 1; + if (test) return 1; unlink_group((Group*)id); break; case ID_OB: - if(test) return 1; + if (test) return 1; unlink_object((Object*)id); break; } - if(id->us == 0) { - if(test) return 1; + if (id->us == 0) { + if (test) return 1; lb= which_libbase(mainlib, GS(id->name)); free_libblock(lb, id); @@ -492,10 +492,11 @@ void flag_listbase_ids(ListBase *lb, short flag, short value) { ID *id; if (value) { - for(id= lb->first; id; id= id->next) id->flag |= flag; - } else { + for (id= lb->first; id; id= id->next) id->flag |= flag; + } + else { flag = ~flag; - for(id= lb->first; id; id= id->next) id->flag &= flag; + for (id= lb->first; id; id= id->next) id->flag &= flag; } } @@ -505,7 +506,7 @@ void flag_all_listbases_ids(short flag, short value) ListBase *lbarray[MAX_LIBARRAY]; int a; a= set_listbasepointers(G.main, lbarray); - while(a--) flag_listbase_ids(lbarray[a], flag, value); + while (a--) flag_listbase_ids(lbarray[a], flag, value); } void recalc_all_library_objects(Main *main) @@ -513,8 +514,8 @@ void recalc_all_library_objects(Main *main) Object *ob; /* flag for full recalc */ - for(ob=main->object.first; ob; ob=ob->id.next) - if(ob->id.lib) + for (ob=main->object.first; ob; ob=ob->id.next) + if (ob->id.lib) ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; } @@ -686,7 +687,7 @@ void *alloc_libblock(ListBase *lb, short type, const char *name) ID *id= NULL; id= alloc_libblock_notest(type); - if(id) { + if (id) { BLI_addtail(lb, id); id->us= 1; id->icon_id = 0; @@ -732,7 +733,7 @@ void *copy_libblock(ID *id) assert(idn != NULL); idn_len= MEM_allocN_len(idn); - if((int)idn_len - (int)sizeof(ID) > 0) { /* signed to allow neg result */ + if ((int)idn_len - (int)sizeof(ID) > 0) { /* signed to allow neg result */ const char *cp= (const char *)id; char *cpn= (char *)idn; @@ -875,7 +876,7 @@ void free_libblock(ListBase *lb, void *idv) psys_free_settings((ParticleSettings *)id); break; case ID_WM: - if(free_windowmanager_cb) + if (free_windowmanager_cb) free_windowmanager_cb(NULL, (wmWindowManager *)id); break; case ID_GD: @@ -905,12 +906,12 @@ void free_libblock_us(ListBase *lb, void *idv) /* test users */ id->us--; - if(id->us<0) { - if(id->lib) printf("ERROR block %s %s users %d\n", id->lib->name, id->name, id->us); + if (id->us<0) { + if (id->lib) printf("ERROR block %s %s users %d\n", id->lib->name, id->name, id->us); else printf("ERROR block %s users %d\n", id->name, id->us); } - if(id->us==0) { - if( GS(id->name)==ID_OB ) unlink_object((Object *)id); + if (id->us==0) { + if ( GS(id->name)==ID_OB ) unlink_object((Object *)id); free_libblock(lb, id); } @@ -924,7 +925,7 @@ void free_main(Main *mainvar) int a; a= set_listbasepointers(mainvar, lbarray); - while(a--) { + while (a--) { ListBase *lb= lbarray[a]; ID *id; @@ -956,16 +957,16 @@ static void get_flags_for_id(ID *id, char *buf) * to have that explicit, oh well - zr */ - if(GS(id->name)==ID_MA) + if (GS(id->name)==ID_MA) isnode= ((Material *)id)->use_nodes; - if(GS(id->name)==ID_TE) + if (GS(id->name)==ID_TE) isnode= ((Tex *)id)->use_nodes; if (id->us<0) strcpy(buf, "-1W "); else if (!id->lib && !isfake && id->us && !isnode) strcpy(buf, " "); - else if(isnode) + else if (isnode) sprintf(buf, "%c%cN%c ", id->lib?'L':' ', isfake?'F':' ', (id->us==0)?'O':' '); else sprintf(buf, "%c%c%c ", id->lib?'L':' ', isfake?'F':' ', (id->us==0)?'O':' '); @@ -982,7 +983,8 @@ static void IDnames_to_dyn_pupstring(DynStr *pupds, ListBase *lb, ID *link, shor if (nr && nids>MAX_IDPUP) { BLI_dynstr_append(pupds, "DataBrowse %x-2"); *nr= -2; - } else { + } + else { ID *id; for (i=0, id= lb->first; id; id= id->next, i++) { @@ -1019,7 +1021,7 @@ static void IDnames_to_dyn_pupstring(DynStr *pupds, ListBase *lb, ID *link, shor break; } - if(id->next) + if (id->next) BLI_dynstr_append(pupds, "|"); } } @@ -1076,19 +1078,19 @@ static void sort_alpha_id(ListBase *lb, ID *id) ID *idtest; /* insert alphabetically */ - if(lb->first!=lb->last) { + if (lb->first!=lb->last) { BLI_remlink(lb, id); idtest= lb->first; - while(idtest) { - if(BLI_strcasecmp(idtest->name, id->name)>0 || idtest->lib) { + while (idtest) { + if (BLI_strcasecmp(idtest->name, id->name)>0 || idtest->lib) { BLI_insertlinkbefore(lb, idtest, id); break; } idtest= idtest->next; } /* as last */ - if(idtest==NULL) { + if (idtest==NULL) { BLI_addtail(lb, id); } } @@ -1103,13 +1105,13 @@ static ID *is_dupid(ListBase *lb, ID *id, const char *name) { ID *idtest=NULL; - for( idtest = lb->first; idtest; idtest = idtest->next ) { + for ( idtest = lb->first; idtest; idtest = idtest->next ) { /* if idtest is not a lib */ - if( id != idtest && idtest->lib == NULL ) { + if ( id != idtest && idtest->lib == NULL ) { /* do not test alphabetic! */ /* optimized */ - if( idtest->name[2] == name[0] ) { - if(strcmp(name, idtest->name+2)==0) break; + if ( idtest->name[2] == name[0] ) { + if (strcmp(name, idtest->name+2)==0) break; } } } @@ -1145,7 +1147,7 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) idtest = is_dupid(lb, id, name); /* if there is no double, done */ - if( idtest == NULL ) return 0; + if ( idtest == NULL ) return 0; /* we have a dup; need to make a new name */ /* quick check so we can reuse one of first 64 ids if vacant */ @@ -1155,33 +1157,33 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) left_len= BLI_split_name_num(left, &nr, name, '.'); /* if new name will be too long, truncate it */ - if(nr > 999 && left_len > (MAX_ID_NAME - 8)) { + if (nr > 999 && left_len > (MAX_ID_NAME - 8)) { left[MAX_ID_NAME - 8]= 0; left_len= MAX_ID_NAME - 8; } - else if(left_len > (MAX_ID_NAME - 7)) { + else if (left_len > (MAX_ID_NAME - 7)) { left[MAX_ID_NAME - 7]= 0; left_len= MAX_ID_NAME - 7; } - for(idtest= lb->first; idtest; idtest= idtest->next) { - if( (id != idtest) && + for (idtest= lb->first; idtest; idtest= idtest->next) { + if ( (id != idtest) && (idtest->lib == NULL) && (*name == *(idtest->name+2)) && (strncmp(name, idtest->name+2, left_len)==0) && (BLI_split_name_num(leftest, &nrtest, idtest->name+2, '.') == left_len) ) { - if(nrtest < sizeof(in_use)) + if (nrtest < sizeof(in_use)) in_use[nrtest]= 1; /* mark as used */ - if(nr <= nrtest) + if (nr <= nrtest) nr= nrtest+1; /* track largest unused */ } } /* decide which value of nr to use */ - for(a=0; a < sizeof(in_use); a++) { - if(a>=nr) break; /* stop when we've check up to biggest */ - if( in_use[a]==0 ) { /* found an unused value */ + for (a=0; a < sizeof(in_use); a++) { + if (a>=nr) break; /* stop when we've check up to biggest */ + if ( in_use[a]==0 ) { /* found an unused value */ nr = a; break; } @@ -1203,7 +1205,7 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) /* otherwise just continue and use a number suffix */ } - if(nr > 999 && left_len > (MAX_ID_NAME - 8)) { + if (nr > 999 && left_len > (MAX_ID_NAME - 8)) { /* this would overflow name buffer */ left[MAX_ID_NAME - 8] = 0; /* left_len = MAX_ID_NAME - 8; */ /* for now this isn't used again */ @@ -1230,14 +1232,14 @@ int new_id(ListBase *lb, ID *id, const char *tname) char name[MAX_ID_NAME-2]; /* if library, don't rename */ - if(id->lib) return 0; + if (id->lib) return 0; /* if no libdata given, look up based on ID */ - if(lb==NULL) lb= which_libbase(G.main, GS(id->name)); + if (lb==NULL) lb= which_libbase(G.main, GS(id->name)); /* if no name given, use name of current ID * else make a copy (tname args can be const) */ - if(tname==NULL) + if (tname==NULL) tname= id->name+2; strncpy(name, tname, sizeof(name)-1); @@ -1246,7 +1248,7 @@ int new_id(ListBase *lb, ID *id, const char *tname) * easier to assign each time then to check if its needed */ name[sizeof(name)-1]= 0; - if(name[0] == '\0') { + if (name[0] == '\0') { /* disallow empty names */ strcpy(name, ID_FALLBACK_NAME); } @@ -1264,7 +1266,7 @@ int new_id(ListBase *lb, ID *id, const char *tname) * sorting should not hurt, but noting just incause it alters the way other * functions work, so sort every time */ #if 0 - if( result ) + if ( result ) sort_alpha_id(lb, id); #endif @@ -1292,9 +1294,9 @@ void clear_id_newpoins(void) int a; a= set_listbasepointers(G.main, lbarray); - while(a--) { + while (a--) { id= lbarray[a]->first; - while(id) { + while (id) { id->newid= NULL; id->flag &= ~LIB_NEW; id= id->next; @@ -1302,21 +1304,21 @@ void clear_id_newpoins(void) } } -#define LIBTAG(a) if(a && a->id.lib) {a->id.flag &=~LIB_INDIRECT; a->id.flag |= LIB_EXTERN;} +#define LIBTAG(a) if (a && a->id.lib) {a->id.flag &=~LIB_INDIRECT; a->id.flag |= LIB_EXTERN;} static void lib_indirect_test_id(ID *id, Library *lib) { - if(id->lib) { + if (id->lib) { /* datablocks that were indirectly related are now direct links * without this, appending data that has a link to other data will fail to write */ - if(lib && id->lib->parent == lib) { + if (lib && id->lib->parent == lib) { id_lib_extern(id); } return; } - if(GS(id->name)==ID_OB) { + if (GS(id->name)==ID_OB) { Object *ob= (Object *)id; Mesh *me; @@ -1335,7 +1337,7 @@ static void lib_indirect_test_id(ID *id, Library *lib) // XXX: new animation system needs something like this? #endif - for(a=0; a<ob->totcol; a++) { + for (a=0; a<ob->totcol; a++) { LIBTAG(ob->mat[a]); } @@ -1350,13 +1352,13 @@ static void lib_indirect_test_id(ID *id, Library *lib) void tag_main_lb(ListBase *lb, const short tag) { ID *id; - if(tag) { - for(id= lb->first; id; id= id->next) { + if (tag) { + for (id= lb->first; id; id= id->next) { id->flag |= LIB_DOIT; } } else { - for(id= lb->first; id; id= id->next) { + for (id= lb->first; id; id= id->next) { id->flag &= ~LIB_DOIT; } } @@ -1375,7 +1377,7 @@ void tag_main(struct Main *mainvar, const short tag) int a; a= set_listbasepointers(mainvar, lbarray); - while(a--) { + while (a--) { tag_main_lb(lbarray[a], tag); } } @@ -1389,10 +1391,10 @@ void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only) int a; a= set_listbasepointers(bmain, lbarray); - while(a--) { + while (a--) { id= lbarray[a]->first; - while(id) { + while (id) { id->newid= NULL; idn= id->next; /* id is possibly being inserted again */ @@ -1401,11 +1403,11 @@ void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only) * appending data, so any libdata already linked wont become local * (very nasty to discover all your links are lost after appending) * */ - if(id->flag & (LIB_EXTERN|LIB_INDIRECT|LIB_NEW) && + if (id->flag & (LIB_EXTERN|LIB_INDIRECT|LIB_NEW) && (untagged_only==0 || !(id->flag & LIB_PRE_EXISTING))) { - if(lib==NULL || id->lib==lib) { - if(id->lib) { + if (lib==NULL || id->lib==lib) { + if (id->lib) { id_clear_lib_data(bmain, id); /* sets 'id->flag' */ /* why sort alphabetically here but not in @@ -1421,7 +1423,7 @@ void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only) } /* patch2: make it aphabetically */ - while( (id=tempbase.first) ) { + while ( (id=tempbase.first) ) { BLI_remlink(&tempbase, id); BLI_addtail(lbarray[a], id); new_id(lbarray[a], id, NULL); @@ -1430,8 +1432,8 @@ void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only) /* patch 3: make sure library data isn't indirect falsely... */ a= set_listbasepointers(bmain, lbarray); - while(a--) { - for(id= lbarray[a]->first; id; id=id->next) + while (a--) { + for (id= lbarray[a]->first; id; id=id->next) lib_indirect_test_id(id, lib); } } @@ -1445,22 +1447,22 @@ void test_idbutton(char *name) lb= which_libbase(G.main, GS(name-2) ); - if(lb==NULL) return; + if (lb==NULL) return; /* search for id */ idtest= BLI_findstring(lb, name, offsetof(ID, name) + 2); - if(idtest) if( new_id(lb, idtest, name)==0 ) sort_alpha_id(lb, idtest); + if (idtest) if( new_id(lb, idtest, name)==0 ) sort_alpha_id(lb, idtest); } void text_idbutton(struct ID *id, char *text) { - if(id) { - if(GS(id->name)==ID_SCE) + if (id) { + if (GS(id->name)==ID_SCE) strcpy(text, "SCE: "); - else if(GS(id->name)==ID_SCR) + else if (GS(id->name)==ID_SCR) strcpy(text, "SCR: "); - else if(GS(id->name)==ID_MA && ((Material*)id)->use_nodes) + else if (GS(id->name)==ID_MA && ((Material*)id)->use_nodes) strcpy(text, "NT: "); else { text[0]= id->name[0]; |