Cleanup: moar removal of G.main in BKE area...

This commit is contained in:
Bastien Montagne 2018-06-12 15:16:45 +02:00
parent d617a6c85b
commit a6585fa4b1
12 changed files with 45 additions and 40 deletions

View File

@ -46,8 +46,9 @@ void BKE_group_copy_data(struct Main *bmain, struct Group *group_dst, c
struct Group *BKE_group_copy(struct Main *bmain, const struct Group *group);
void BKE_group_make_local(struct Main *bmain, struct Group *group, const bool lib_local);
bool BKE_group_object_add(struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base);
bool BKE_group_object_unlink(struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base);
struct Group *BKE_group_object_find(struct Group *group, struct Object *ob);
bool BKE_group_object_unlink(
struct Main *bmain, struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base);
struct Group *BKE_group_object_find(struct Main *bmain, struct Group *group, struct Object *ob);
bool BKE_group_object_exists(struct Group *group, struct Object *ob);
bool BKE_group_object_cyclic_check(struct Main *bmain, struct Object *object, struct Group *group);
bool BKE_group_is_animated(struct Group *group, struct Object *parent);

View File

@ -283,8 +283,9 @@ typedef enum eObjectSet {
struct LinkNode *BKE_object_relational_superset(
struct Scene *scene, eObjectSet objectSet, eObRelationTypes includeFilter);
struct LinkNode *BKE_object_groups(struct Object *ob);
void BKE_object_groups_clear(struct Scene *scene, struct Base *base, struct Object *object);
struct LinkNode *BKE_object_groups(struct Main *bmain, struct Object *ob);
void BKE_object_groups_clear(
struct Main *bmain, struct Scene *scene, struct Base *base, struct Object *object);
struct KDTree *BKE_object_as_kdtree(struct Object *ob, int *r_tot);

View File

@ -223,11 +223,11 @@ bool BKE_group_object_cyclic_check(Main *bmain, Object *object, Group *group)
return group_object_cyclic_check_internal(object, group);
}
bool BKE_group_object_unlink(Group *group, Object *object, Scene *scene, Base *base)
bool BKE_group_object_unlink(Main *bmain, Group *group, Object *object, Scene *scene, Base *base)
{
if (group_object_unlink_internal(group, object)) {
/* object can be NULL */
if (object && BKE_group_object_find(NULL, object) == NULL) {
if (object && BKE_group_object_find(bmain, NULL, object) == NULL) {
if (scene && base == NULL)
base = BKE_scene_base_find(scene, object);
@ -253,12 +253,12 @@ bool BKE_group_object_exists(Group *group, Object *ob)
}
}
Group *BKE_group_object_find(Group *group, Object *ob)
Group *BKE_group_object_find(Main *bmain, Group *group, Object *ob)
{
if (group)
group = group->id.next;
else
group = G.main->group.first;
group = bmain->group.first;
while (group) {
if (BKE_group_object_exists(group, ob))

View File

@ -335,12 +335,12 @@ static void libblock_remap_data_postprocess_object_update(Main *bmain, Object *o
* - unlinked old_ob (i.e. new_ob is NULL), in which case scenes' bases have been removed already.
* - remapped old_ob by new_ob, in which case scenes' bases are still valid as is.
* So in any case, no need to update them here. */
if (BKE_group_object_find(NULL, old_ob) == NULL) {
if (BKE_group_object_find(bmain, NULL, old_ob) == NULL) {
old_ob->flag &= ~OB_FROMGROUP;
}
if (new_ob == NULL) { /* We need to remove NULL-ified groupobjects... */
for (Group *group = bmain->group.first; group; group = group->id.next) {
BKE_group_object_unlink(group, NULL, NULL, NULL);
BKE_group_object_unlink(bmain, group, NULL, NULL, NULL);
}
}
else {
@ -356,7 +356,7 @@ static void libblock_remap_data_postprocess_object_update(Main *bmain, Object *o
}
}
static void libblock_remap_data_postprocess_group_scene_unlink(Main *UNUSED(bmain), Scene *sce, ID *old_id)
static void libblock_remap_data_postprocess_group_scene_unlink(Main *bmain, Scene *sce, ID *old_id)
{
/* Note that here we assume no object has no base (i.e. all objects are assumed instanced
* in one scene...). */
@ -365,11 +365,11 @@ static void libblock_remap_data_postprocess_group_scene_unlink(Main *UNUSED(bmai
Object *ob = base->object;
if (ob->flag & OB_FROMGROUP) {
Group *grp = BKE_group_object_find(NULL, ob);
Group *grp = BKE_group_object_find(bmain, NULL, ob);
/* Unlinked group (old_id) is still in bmain... */
if (grp && (&grp->id == old_id || grp->id.us == 0)) {
grp = BKE_group_object_find(grp, ob);
grp = BKE_group_object_find(bmain, grp, ob);
}
if (!grp) {
ob->flag &= ~OB_FROMGROUP;

View File

@ -3384,18 +3384,18 @@ LinkNode *BKE_object_relational_superset(struct Scene *scene, eObjectSet objectS
/**
* return all groups this object is apart of, caller must free.
*/
struct LinkNode *BKE_object_groups(Object *ob)
struct LinkNode *BKE_object_groups(Main *bmain, Object *ob)
{
LinkNode *group_linknode = NULL;
Group *group = NULL;
while ((group = BKE_group_object_find(group, ob))) {
while ((group = BKE_group_object_find(bmain, group, ob))) {
BLI_linklist_prepend(&group_linknode, group);
}
return group_linknode;
}
void BKE_object_groups_clear(Scene *scene, Base *base, Object *object)
void BKE_object_groups_clear(Main *bmain, Scene *scene, Base *base, Object *object)
{
Group *group = NULL;
@ -3405,8 +3405,8 @@ void BKE_object_groups_clear(Scene *scene, Base *base, Object *object)
base = BKE_scene_base_find(scene, object);
}
while ((group = BKE_group_object_find(group, base->object))) {
BKE_group_object_unlink(group, object, scene, base);
while ((group = BKE_group_object_find(bmain, group, base->object))) {
BKE_group_object_unlink(bmain, group, object, scene, base);
}
}

View File

@ -581,7 +581,7 @@ static const DupliGenerator gen_dupli_verts = {
};
/* OB_DUPLIVERTS - FONT */
static Object *find_family_object(const char *family, size_t family_len, unsigned int ch, GHash *family_gh)
static Object *find_family_object(Main *bmain, const char *family, size_t family_len, unsigned int ch, GHash *family_gh)
{
Object **ob_pt;
Object *ob;
@ -598,7 +598,7 @@ static Object *find_family_object(const char *family, size_t family_len, unsigne
ch_utf8[ch_utf8_len] = '\0';
ch_utf8_len += 1; /* compare with null terminator */
for (ob = G.main->object.first; ob; ob = ob->id.next) {
for (ob = bmain->object.first; ob; ob = ob->id.next) {
if (STREQLEN(ob->id.name + 2 + family_len, ch_utf8, ch_utf8_len)) {
if (STREQLEN(ob->id.name + 2, family, family_len)) {
break;
@ -655,7 +655,7 @@ static void make_duplis_font(const DupliContext *ctx)
/* advance matching BLI_strncpy_wchar_from_utf8 */
for (a = 0; a < text_len; a++, ct++) {
ob = find_family_object(cu->family, family_len, (unsigned int)text[a], family_gh);
ob = find_family_object(ctx->bmain, cu->family, family_len, (unsigned int)text[a], family_gh);
if (ob) {
vec[0] = fsize * (ct->xof - xof);
vec[1] = fsize * (ct->yof - yof);

View File

@ -7582,9 +7582,9 @@ static void direct_link_group(FileData *fd, Group *group)
group->preview = direct_link_preview_image(fd, group->preview);
}
static void lib_link_group(FileData *fd, Main *main)
static void lib_link_group(FileData *fd, Main *bmain)
{
for (Group *group = main->group.first; group; group = group->id.next) {
for (Group *group = bmain->group.first; group; group = group->id.next) {
if (group->id.tag & LIB_TAG_NEED_LINK) {
IDP_LibLinkProperty(group->id.properties, fd);
@ -7601,7 +7601,7 @@ static void lib_link_group(FileData *fd, Main *main)
if (add_us) {
id_us_ensure_real(&group->id);
}
BKE_group_object_unlink(group, NULL, NULL, NULL); /* removes NULL entries */
BKE_group_object_unlink(bmain, group, NULL, NULL, NULL); /* removes NULL entries */
group->id.tag &= ~LIB_TAG_NEED_LINK;
}

View File

@ -65,6 +65,7 @@
/* can be called with C == NULL */
static const EnumPropertyItem *group_object_active_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
{
Main *bmain = CTX_data_main(C);
Object *ob;
EnumPropertyItem *item = NULL, item_tmp = {0};
int totitem = 0;
@ -82,7 +83,7 @@ static const EnumPropertyItem *group_object_active_itemf(bContext *C, PointerRNA
/* if 2 or more groups, add option to add to all groups */
group = NULL;
while ((group = BKE_group_object_find(group, ob)))
while ((group = BKE_group_object_find(bmain, group, ob)))
count++;
if (count >= 2) {
@ -94,7 +95,7 @@ static const EnumPropertyItem *group_object_active_itemf(bContext *C, PointerRNA
/* add groups */
group = NULL;
while ((group = BKE_group_object_find(group, ob))) {
while ((group = BKE_group_object_find(bmain, group, ob))) {
item_tmp.identifier = item_tmp.name = group->id.name + 2;
/* item_tmp.icon = ICON_ARMATURE_DATA; */
item_tmp.value = i;
@ -110,11 +111,11 @@ static const EnumPropertyItem *group_object_active_itemf(bContext *C, PointerRNA
}
/* get the group back from the enum index, quite awkward and UI specific */
static Group *group_object_active_find_index(Object *ob, const int group_object_index)
static Group *group_object_active_find_index(Main *bmain, Object *ob, const int group_object_index)
{
Group *group = NULL;
int i = 0;
while ((group = BKE_group_object_find(group, ob))) {
while ((group = BKE_group_object_find(bmain, group, ob))) {
if (i == group_object_index) {
break;
}
@ -130,7 +131,7 @@ static int objects_add_active_exec(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
int single_group_index = RNA_enum_get(op->ptr, "group");
Group *single_group = group_object_active_find_index(ob, single_group_index);
Group *single_group = group_object_active_find_index(bmain, ob, single_group_index);
Group *group;
bool is_cycle = false;
bool updated = false;
@ -203,7 +204,7 @@ static int objects_remove_active_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
Object *ob = OBACT;
int single_group_index = RNA_enum_get(op->ptr, "group");
Group *single_group = group_object_active_find_index(ob, single_group_index);
Group *single_group = group_object_active_find_index(bmain, ob, single_group_index);
Group *group;
bool ok = false;
@ -221,7 +222,7 @@ static int objects_remove_active_exec(bContext *C, wmOperator *op)
/* Remove groups from selected objects */
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
{
BKE_group_object_unlink(group, base->object, scene, base);
BKE_group_object_unlink(bmain, group, base->object, scene, base);
ok = 1;
}
CTX_DATA_END;
@ -268,7 +269,7 @@ static int group_objects_remove_all_exec(bContext *C, wmOperator *UNUSED(op))
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
{
BKE_object_groups_clear(scene, base, base->object);
BKE_object_groups_clear(bmain, scene, base, base->object);
}
CTX_DATA_END;
@ -299,7 +300,7 @@ static int group_objects_remove_exec(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
int single_group_index = RNA_enum_get(op->ptr, "group");
Group *single_group = group_object_active_find_index(ob, single_group_index);
Group *single_group = group_object_active_find_index(bmain, ob, single_group_index);
Group *group;
bool updated = false;
@ -315,7 +316,7 @@ static int group_objects_remove_exec(bContext *C, wmOperator *op)
/* now remove all selected objects from the group */
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
{
BKE_group_object_unlink(group, base->object, scene, base);
BKE_group_object_unlink(bmain, group, base->object, scene, base);
updated = true;
}
CTX_DATA_END;
@ -490,6 +491,7 @@ void OBJECT_OT_group_link(wmOperatorType *ot)
static int group_remove_exec(bContext *C, wmOperator *UNUSED(op))
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
Object *ob = ED_object_context(C);
Group *group = CTX_data_pointer_get_type(C, "group", &RNA_Group).data;
@ -497,7 +499,7 @@ static int group_remove_exec(bContext *C, wmOperator *UNUSED(op))
if (!ob || !group)
return OPERATOR_CANCELLED;
BKE_group_object_unlink(group, ob, scene, NULL); /* base will be used if found */
BKE_group_object_unlink(bmain, group, ob, scene, NULL); /* base will be used if found */
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);

View File

@ -1550,7 +1550,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
/* avoid searching all groups in source object each time */
if (type == MAKE_LINKS_GROUP) {
ob_groups = BKE_object_groups(ob_src);
ob_groups = BKE_object_groups(bmain, ob_src);
}
CTX_DATA_BEGIN (C, Base *, base_dst, selected_editable_bases)
@ -1598,7 +1598,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
LinkNode *group_node;
/* first clear groups */
BKE_object_groups_clear(scene, base_dst, ob_dst);
BKE_object_groups_clear(bmain, scene, base_dst, ob_dst);
/* now add in the groups from the link nodes */
for (group_node = ob_groups; group_node; group_node = group_node->next) {

View File

@ -101,7 +101,7 @@ void ED_rigidbody_constraint_remove(Main *bmain, Scene *scene, Object *ob)
BKE_rigidbody_remove_constraint(scene, ob);
if (rbw)
BKE_group_object_unlink(rbw->constraints, ob, scene, NULL);
BKE_group_object_unlink(bmain, rbw->constraints, ob, scene, NULL);
DAG_relations_tag_update(bmain);
DAG_id_tag_update(&ob->id, OB_RECALC_OB);

View File

@ -132,7 +132,7 @@ void ED_rigidbody_object_remove(Main *bmain, Scene *scene, Object *ob)
BKE_rigidbody_remove_object(scene, ob);
if (rbw)
BKE_group_object_unlink(rbw->group, ob, scene, NULL);
BKE_group_object_unlink(bmain, rbw->group, ob, scene, NULL);
DAG_relations_tag_update(bmain);
DAG_id_tag_update(&ob->id, OB_RECALC_OB);

View File

@ -65,7 +65,8 @@ static void rna_Group_objects_link(Group *group, bContext *C, ReportList *report
static void rna_Group_objects_unlink(Group *group, bContext *C, ReportList *reports, Object *object)
{
if (!BKE_group_object_unlink(group, object, CTX_data_scene(C), NULL)) {
Main *bmain = CTX_data_main(C);
if (!BKE_group_object_unlink(bmain, group, object, CTX_data_scene(C), NULL)) {
BKE_reportf(reports, RPT_ERROR, "Object '%s' not in group '%s'", object->id.name + 2, group->id.name + 2);
return;
}