void make_local_brush(Brush *brush) { /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ Main *bmain= G.main; Scene *scene; int is_local= FALSE, is_lib= FALSE; if(brush->id.lib==NULL) return; if(brush->clone.image) { /* special case: ima always local immediately. Clone image should only have one user anyway. */ id_clear_lib_data(bmain, &brush->clone.image->id); extern_local_brush(brush); } for(scene= bmain->scene.first; scene && ELEM(0, is_lib, is_local); scene=scene->id.next) { if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) { if(scene->id.lib) is_lib= TRUE; else is_local= TRUE; } } if(is_local && is_lib == FALSE) { id_clear_lib_data(bmain, &brush->id); extern_local_brush(brush); /* enable fake user by default */ if (!(brush->id.flag & LIB_FAKEUSER)) { brush->id.flag |= LIB_FAKEUSER; brush->id.us++; } } else if(is_local && is_lib) { Brush *brush_new= copy_brush(brush); brush_new->id.us= 1; /* only keep fake user */ brush_new->id.flag |= LIB_FAKEUSER; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id); for(scene= bmain->scene.first; scene; scene=scene->id.next) { if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) { if(scene->id.lib==NULL) { paint_brush_set(&scene->toolsettings->imapaint.paint, brush_new); } } } } }
void make_local_brush(Brush *brush) { /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ Main *bmain= G.main; Scene *scene; int local= 0, lib= 0; if(brush->id.lib==NULL) return; if(brush->clone.image) { /* special case: ima always local immediately */ brush->clone.image->id.lib= NULL; brush->clone.image->id.flag= LIB_LOCAL; new_id(&bmain->brush, (ID *)brush->clone.image, NULL); extern_local_brush(brush); } for(scene= bmain->scene.first; scene && ELEM(0, lib, local); scene=scene->id.next) { if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) { if(scene->id.lib) lib= 1; else local= 1; } } if(local && lib==0) { brush->id.lib= NULL; brush->id.flag= LIB_LOCAL; new_id(&bmain->brush, (ID *)brush, NULL); extern_local_brush(brush); /* enable fake user by default */ if (!(brush->id.flag & LIB_FAKEUSER)) { brush->id.flag |= LIB_FAKEUSER; brush->id.us++; } } else if(local && lib) { Brush *brushn= copy_brush(brush); brushn->id.us= 1; /* only keep fake user */ brushn->id.flag |= LIB_FAKEUSER; for(scene= bmain->scene.first; scene; scene=scene->id.next) { if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) { if(scene->id.lib==NULL) { paint_brush_set(&scene->toolsettings->imapaint.paint, brushn); } } } } }
/* Brush operators */ static int brush_add_exec(bContext *C, wmOperator *UNUSED(op)) { /*int type = RNA_enum_get(op->ptr, "type");*/ Paint *paint = paint_get_active(CTX_data_scene(C)); struct Brush *br = paint_brush(paint); if (br) br = copy_brush(br); else br = add_brush("Brush"); paint_brush_set(paint_get_active(CTX_data_scene(C)), br); return OPERATOR_FINISHED; }
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: if(!test) *newid= (ID*)copy_image((Image*)id); return 1; 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_SPK: if(!test) *newid= (ID*)copy_speaker((Speaker*)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); 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; }