示例#1
0
// does copy_fcurve...
void BKE_action_make_local(bAction *act)
{
	tMakeLocalActionContext mlac = {act, NULL, false, false};
	Main *bmain = G.main;
	
	if (act->id.lib == NULL)
		return;
	
	/* XXX: double-check this; it used to be just single-user check, but that was when fake-users were still default */
	if ((act->id.flag & LIB_FAKEUSER) && (act->id.us <= 1)) {
		id_clear_lib_data(bmain, &act->id);
		return;
	}
	
	BKE_animdata_main_cb(bmain, make_localact_init_cb, &mlac);
	
	if (mlac.is_local && mlac.is_lib == false) {
		id_clear_lib_data(bmain, &act->id);
	}
	else if (mlac.is_local && mlac.is_lib) {
		mlac.act_new = BKE_action_copy(act);
		mlac.act_new->id.us = 0;

		BKE_id_lib_local_paths(bmain, act->id.lib, &mlac.act_new->id);

		BKE_animdata_main_cb(bmain, make_localact_apply_cb, &mlac);
	}
}
示例#2
0
void BKE_brush_make_local(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 (BKE_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 = BKE_brush_copy(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 (BKE_paint_brush(&scene->toolsettings->imapaint.paint) == brush) {
				if (scene->id.lib == NULL) {
					BKE_paint_brush_set(&scene->toolsettings->imapaint.paint, brush_new);
				}
			}
		}
	}
}
示例#3
0
void BKE_lamp_make_local(Lamp *la)
{
	Main *bmain = G.main;
	Object *ob;
	int is_local = FALSE, is_lib = FALSE;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */
	
	if (la->id.lib == NULL) return;
	if (la->id.us == 1) {
		id_clear_lib_data(bmain, &la->id);
		return;
	}
	
	ob = bmain->object.first;
	while (ob) {
		if (ob->data == la) {
			if (ob->id.lib) is_lib = TRUE;
			else is_local = TRUE;
		}
		ob = ob->id.next;
	}
	
	if (is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &la->id);
	}
	else if (is_local && is_lib) {
		Lamp *la_new = BKE_lamp_copy(la);
		la_new->id.us = 0;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, la->id.lib, &la_new->id);

		ob = bmain->object.first;
		while (ob) {
			if (ob->data == la) {
				
				if (ob->id.lib == NULL) {
					ob->data = la_new;
					la_new->id.us++;
					la->id.us--;
				}
			}
			ob = ob->id.next;
		}
	}
}
示例#4
0
void BKE_speaker_make_local(Speaker *spk)
{
	Main *bmain = G.main;
	Object *ob;
	bool is_local = false, is_lib = false;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */

	if (spk->id.lib == NULL) return;
	if (spk->id.us == 1) {
		id_clear_lib_data(bmain, &spk->id);
		return;
	}

	ob = bmain->object.first;
	while (ob) {
		if (ob->data == spk) {
			if (ob->id.lib) is_lib = true;
			else is_local = true;
		}
		ob = ob->id.next;
	}

	if (is_local && is_lib == false) {
		id_clear_lib_data(bmain, &spk->id);
	}
	else if (is_local && is_lib) {
		Speaker *spk_new = BKE_speaker_copy(spk);
		spk_new->id.us = 0;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, spk->id.lib, &spk_new->id);

		ob = bmain->object.first;
		while (ob) {
			if (ob->data == spk) {

				if (ob->id.lib == NULL) {
					ob->data = spk_new;
					spk_new->id.us++;
					spk->id.us--;
				}
			}
			ob = ob->id.next;
		}
	}
}
示例#5
0
文件: mball.c 项目: mcgrathd/blender
void BKE_mball_make_local(MetaBall *mb)
{
    Main *bmain = G.main;
    Object *ob;
    bool is_local = false, is_lib = false;

    /* - only lib users: do nothing
     * - only local users: set flag
     * - mixed: make copy
     */

    if (mb->id.lib == NULL) return;
    if (mb->id.us == 1) {
        id_clear_lib_data(bmain, &mb->id);
        extern_local_mball(mb);

        return;
    }

    for (ob = G.main->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) {
        if (ob->data == mb) {
            if (ob->id.lib) is_lib = true;
            else is_local = true;
        }
    }

    if (is_local && is_lib == false) {
        id_clear_lib_data(bmain, &mb->id);
        extern_local_mball(mb);
    }
    else if (is_local && is_lib) {
        MetaBall *mb_new = BKE_mball_copy(mb);
        mb_new->id.us = 0;

        /* Remap paths of new ID using old library as base. */
        BKE_id_lib_local_paths(bmain, mb->id.lib, &mb_new->id);

        for (ob = G.main->object.first; ob; ob = ob->id.next) {
            if (ob->data == mb) {
                if (ob->id.lib == NULL) {
                    ob->data = mb_new;
                    mb_new->id.us++;
                    mb->id.us--;
                }
            }
        }
    }
}
示例#6
0
void BKE_mesh_make_local(Mesh *me)
{
	Main *bmain = G.main;
	Object *ob;
	int is_local = FALSE, is_lib = FALSE;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */

	if (me->id.lib == NULL) return;
	if (me->id.us == 1) {
		id_clear_lib_data(bmain, &me->id);
		expand_local_mesh(me);
		return;
	}

	for (ob = bmain->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) {
		if (me == ob->data) {
			if (ob->id.lib) is_lib = TRUE;
			else is_local = TRUE;
		}
	}

	if (is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &me->id);
		expand_local_mesh(me);
	}
	else if (is_local && is_lib) {
		Mesh *me_new = BKE_mesh_copy(me);
		me_new->id.us = 0;


		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, me->id.lib, &me_new->id);

		for (ob = bmain->object.first; ob; ob = ob->id.next) {
			if (me == ob->data) {
				if (ob->id.lib == NULL) {
					BKE_mesh_assign_object(ob, me_new);
				}
			}
		}
	}
}
示例#7
0
void make_local_camera(Camera *cam)
{
	Main *bmain= G.main;
	Object *ob;
	int is_local= FALSE, is_lib= FALSE;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */
	
	if (cam->id.lib==NULL) return;
	if (cam->id.us==1) {
		id_clear_lib_data(bmain, &cam->id);
		return;
	}
	
	for (ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) {
		if (ob->data==cam) {
			if (ob->id.lib) is_lib= TRUE;
			else is_local= TRUE;
		}
	}
	
	if (is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &cam->id);
	}
	else if (is_local && is_lib) {
		Camera *cam_new= copy_camera(cam);

		cam_new->id.us= 0;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, cam->id.lib, &cam_new->id);

		for (ob= bmain->object.first; ob; ob= ob->id.next) {
			if (ob->data == cam) {
				if (ob->id.lib==NULL) {
					ob->data= cam_new;
					cam_new->id.us++;
					cam->id.us--;
				}
			}
		}
	}
}
示例#8
0
void BKE_lattice_make_local(Lattice *lt)
{
	Main *bmain = G.main;
	Object *ob;
	int is_local = FALSE, is_lib = FALSE;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */
	
	if (lt->id.lib == NULL) return;
	if (lt->id.us == 1) {
		id_clear_lib_data(bmain, &lt->id);
		return;
	}
	
	for (ob = bmain->object.first; ob && ELEM(FALSE, is_lib, is_local); ob = ob->id.next) {
		if (ob->data == lt) {
			if (ob->id.lib) is_lib = TRUE;
			else is_local = TRUE;
		}
	}
	
	if (is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &lt->id);
	}
	else if (is_local && is_lib) {
		Lattice *lt_new = BKE_lattice_copy(lt);
		lt_new->id.us = 0;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, lt->id.lib, &lt_new->id);

		for (ob = bmain->object.first; ob; ob = ob->id.next) {
			if (ob->data == lt) {
				if (ob->id.lib == NULL) {
					ob->data = lt_new;
					lt_new->id.us++;
					lt->id.us--;
				}
			}
		}
	}
}
示例#9
0
文件: world.c 项目: 244xiao/blender
void BKE_world_make_local(World *wrld)
{
	Main *bmain = G.main;
	Scene *sce;
	int is_local = FALSE, is_lib = FALSE;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */
	
	if (wrld->id.lib == NULL) return;
	if (wrld->id.us == 1) {
		id_clear_lib_data(bmain, &wrld->id);
		return;
	}
	
	for (sce = bmain->scene.first; sce && ELEM(FALSE, is_lib, is_local); sce = sce->id.next) {
		if (sce->world == wrld) {
			if (sce->id.lib) is_lib = TRUE;
			else is_local = TRUE;
		}
	}

	if (is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &wrld->id);
	}
	else if (is_local && is_lib) {
		World *wrld_new = BKE_world_copy(wrld);
		wrld_new->id.us = 0;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, wrld->id.lib, &wrld_new->id);

		for (sce = bmain->scene.first; sce; sce = sce->id.next) {
			if (sce->world == wrld) {
				if (sce->id.lib == NULL) {
					sce->world = wrld_new;
					wrld_new->id.us++;
					wrld->id.us--;
				}
			}
		}
	}
}
示例#10
0
static void id_local_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
{
	if (tselem->id->lib && (tselem->id->flag & LIB_EXTERN)) {
		/* if the ID type has no special local function,
		 * just clear the lib */
		if (id_make_local(tselem->id, FALSE) == FALSE) {
			Main *bmain= CTX_data_main(C);
			id_clear_lib_data(bmain, tselem->id);
		}
	}
}
示例#11
0
/* if lib!=NULL, only all from lib local
 * bmain is almost certainly G.main */
void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only)
{
    ListBase *lbarray[MAX_LIBARRAY], tempbase = {NULL, NULL};
    ID *id, *idn;
    int a;

    a = set_listbasepointers(bmain, lbarray);
    while (a--) {
        id = lbarray[a]->first;

        while (id) {
            id->newid = NULL;
            idn = id->next;      /* id is possibly being inserted again */

            /* The check on the second line (LIB_PRE_EXISTING) is done so its
             * possible to tag data you don't want to be made local, used for
             * 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) &&
                    (untagged_only == 0 || !(id->flag & LIB_PRE_EXISTING)))
            {
                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
                         * id_clear_lib_data() ? - campbell */
                        id_sort_by_name(lbarray[a], id);
                    }
                    else {
                        id->flag &= ~(LIB_EXTERN | LIB_INDIRECT | LIB_NEW);
                    }
                }
            }
            id = idn;
        }

        /* patch2: make it aphabetically */
        while ( (id = tempbase.first) ) {
            BLI_remlink(&tempbase, id);
            BLI_addtail(lbarray[a], id);
            new_id(lbarray[a], id, NULL);
        }
    }

    /* 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)
            lib_indirect_test_id(id, lib);
    }
}
示例#12
0
/* if lib!=NULL, only all from lib local
 * bmain is almost certainly G.main */
void BKE_library_make_local(Main *bmain, Library *lib, bool untagged_only)
{
	ListBase *lbarray[MAX_LIBARRAY];
	ID *id, *idn;
	int a;

	a = set_listbasepointers(bmain, lbarray);
	while (a--) {
		id = lbarray[a]->first;
		
		while (id) {
			id->newid = NULL;
			idn = id->next;      /* id is possibly being inserted again */
			
			/* The check on the second line (LIB_PRE_EXISTING) is done so its
			 * possible to tag data you don't want to be made local, used for
			 * 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) &&
			    ((untagged_only == false) || !(id->flag & LIB_PRE_EXISTING)))
			{
				if (lib == NULL || id->lib == lib) {
					if (id->lib) {
						/* for Make Local > All we should be calling id_make_local,
						 * but doing that breaks append (see #36003 and #36006), we
						 * we should make it work with all datablocks and id.us==0 */
						id_clear_lib_data(bmain, id); /* sets 'id->flag' */

						/* why sort alphabetically here but not in
						 * id_clear_lib_data() ? - campbell */
						id_sort_by_name(lbarray[a], id);
					}
					else {
						id->flag &= ~(LIB_EXTERN | LIB_INDIRECT | LIB_NEW);
					}
				}
			}
			id = idn;
		}
	}

	a = set_listbasepointers(bmain, lbarray);
	while (a--) {
		for (id = lbarray[a]->first; id; id = id->next)
			lib_indirect_test_id(id, lib);
	}
}
示例#13
0
文件: brush.c 项目: UPBGE/blender
void BKE_brush_make_local(Main *bmain, Brush *brush, const bool lib_local)
{
	bool is_local = false, is_lib = false;

	/* - only lib users: do nothing (unless force_local is set)
	 * - only local users: set flag
	 * - mixed: make copy
	 */

	if (!ID_IS_LINKED_DATABLOCK(brush)) {
		return;
	}

	if (brush->clone.image) {
		/* Special case: ima always local immediately. Clone image should only have one user anyway. */
		id_make_local(bmain, &brush->clone.image->id, false, false);
	}

	BKE_library_ID_test_usages(bmain, brush, &is_local, &is_lib);

	if (lib_local || is_local) {
		if (!is_lib) {
			id_clear_lib_data(bmain, &brush->id);
			BKE_id_expand_local(&brush->id);

			/* enable fake user by default */
			id_fake_user_set(&brush->id);
		}
		else {
			Brush *brush_new = BKE_brush_copy(bmain, brush);  /* Ensures FAKE_USER is set */

			brush_new->id.us = 0;

			/* setting newid is mandatory for complex make_lib_local logic... */
			ID_NEW_SET(brush, brush_new);

			if (!lib_local) {
				BKE_libblock_remap(bmain, brush, brush_new, ID_REMAP_SKIP_INDIRECT_USAGE);
			}
		}
	}
}
示例#14
0
void BKE_texture_make_local(Tex *tex)
{
	Main *bmain = G.main;
	Material *ma;
	World *wrld;
	Lamp *la;
	Brush *br;
	ParticleSettings *pa;
	int a, is_local = FALSE, is_lib = FALSE;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */
	
	if (tex->id.lib == NULL) return;

	if (tex->id.us == 1) {
		id_clear_lib_data(bmain, &tex->id);
		extern_local_texture(tex);
		return;
	}
	
	ma = bmain->mat.first;
	while (ma) {
		for (a = 0; a < MAX_MTEX; a++) {
			if (ma->mtex[a] && ma->mtex[a]->tex == tex) {
				if (ma->id.lib) is_lib = TRUE;
				else is_local = TRUE;
			}
		}
		ma = ma->id.next;
	}
	la = bmain->lamp.first;
	while (la) {
		for (a = 0; a < MAX_MTEX; a++) {
			if (la->mtex[a] && la->mtex[a]->tex == tex) {
				if (la->id.lib) is_lib = TRUE;
				else is_local = TRUE;
			}
		}
		la = la->id.next;
	}
	wrld = bmain->world.first;
	while (wrld) {
		for (a = 0; a < MAX_MTEX; a++) {
			if (wrld->mtex[a] && wrld->mtex[a]->tex == tex) {
				if (wrld->id.lib) is_lib = TRUE;
				else is_local = TRUE;
			}
		}
		wrld = wrld->id.next;
	}
	br = bmain->brush.first;
	while (br) {
		if (br->mtex.tex == tex) {
			if (br->id.lib) is_lib = TRUE;
			else is_local = TRUE;
		}
		if (br->mask_mtex.tex == tex) {
			if (br->id.lib) is_lib = TRUE;
			else is_local = TRUE;
		}
		br = br->id.next;
	}
	pa = bmain->particle.first;
	while (pa) {
		for (a = 0; a < MAX_MTEX; a++) {
			if (pa->mtex[a] && pa->mtex[a]->tex == tex) {
				if (pa->id.lib) is_lib = TRUE;
				else is_local = TRUE;
			}
		}
		pa = pa->id.next;
	}
	
	if (is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &tex->id);
		extern_local_texture(tex);
	}
	else if (is_local && is_lib) {
		Tex *tex_new = BKE_texture_copy(tex);

		tex_new->id.us = 0;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, tex->id.lib, &tex_new->id);
		
		ma = bmain->mat.first;
		while (ma) {
			for (a = 0; a < MAX_MTEX; a++) {
				if (ma->mtex[a] && ma->mtex[a]->tex == tex) {
					if (ma->id.lib == NULL) {
						ma->mtex[a]->tex = tex_new;
						tex_new->id.us++;
						tex->id.us--;
					}
				}
			}
			ma = ma->id.next;
		}
		la = bmain->lamp.first;
		while (la) {
			for (a = 0; a < MAX_MTEX; a++) {
				if (la->mtex[a] && la->mtex[a]->tex == tex) {
					if (la->id.lib == NULL) {
						la->mtex[a]->tex = tex_new;
						tex_new->id.us++;
						tex->id.us--;
					}
				}
			}
			la = la->id.next;
		}
		wrld = bmain->world.first;
		while (wrld) {
			for (a = 0; a < MAX_MTEX; a++) {
				if (wrld->mtex[a] && wrld->mtex[a]->tex == tex) {
					if (wrld->id.lib == NULL) {
						wrld->mtex[a]->tex = tex_new;
						tex_new->id.us++;
						tex->id.us--;
					}
				}
			}
			wrld = wrld->id.next;
		}
		br = bmain->brush.first;
		while (br) {
			if (br->mtex.tex == tex) {
				if (br->id.lib == NULL) {
					br->mtex.tex = tex_new;
					tex_new->id.us++;
					tex->id.us--;
				}
			}
			if (br->mask_mtex.tex == tex) {
				if (br->id.lib == NULL) {
					br->mask_mtex.tex = tex_new;
					tex_new->id.us++;
					tex->id.us--;
				}
			}
			br = br->id.next;
		}
		pa = bmain->particle.first;
		while (pa) {
			for (a = 0; a < MAX_MTEX; a++) {
				if (pa->mtex[a] && pa->mtex[a]->tex == tex) {
					if (pa->id.lib == NULL) {
						pa->mtex[a]->tex = tex_new;
						tex_new->id.us++;
						tex->id.us--;
					}
				}
			}
			pa = pa->id.next;
		}
	}
}