Convert direct usages of base defines

This replaces all direct usage of:
- FIRSTBASE
- LASTBASE
- BASACT
- OBACT

Some usages still remain in legacy utility functions which are called
all over the place.
This commit is contained in:
Luca Rood 2017-04-19 11:31:33 +02:00
parent 2f2420709c
commit 4bee5b80d4
7 changed files with 51 additions and 49 deletions

View File

@ -33,6 +33,7 @@
#include "BKE_context.h"
#include "BKE_sketch.h"
#include "BKE_layer.h"
#include "RNA_define.h"
#include "RNA_access.h"
@ -144,9 +145,8 @@ static RigGraph *TEMPLATE_RIGG = NULL;
void BIF_makeListTemplates(const bContext *C)
{
Object *obedit = CTX_data_edit_object(C);
Scene *scene = CTX_data_scene(C);
SceneLayer *sl = CTX_data_scene_layer(C);
ToolSettings *ts = CTX_data_tool_settings(C);
BaseLegacy *base;
int index = 0;
if (TEMPLATES_HASH != NULL) {
@ -156,9 +156,8 @@ void BIF_makeListTemplates(const bContext *C)
TEMPLATES_HASH = BLI_ghash_int_new("makeListTemplates gh");
TEMPLATES_CURRENT = 0;
for (base = FIRSTBASE; base; base = base->next) {
Object *ob = base->object;
FOREACH_OBJECT(sl, ob)
{
if (ob != obedit && ob->type == OB_ARMATURE) {
index++;
BLI_ghash_insert(TEMPLATES_HASH, SET_INT_IN_POINTER(index), ob);
@ -168,6 +167,7 @@ void BIF_makeListTemplates(const bContext *C)
}
}
}
FOREACH_OBJECT_END
}
#if 0 /* UNUSED */

View File

@ -56,12 +56,14 @@
#include "DNA_view3d_types.h"
#include "DNA_gpencil_types.h"
#include "BKE_collection.h"
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_gpencil.h"
#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_object.h"
#include "BKE_report.h"
@ -1121,14 +1123,15 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG
const bool norm_weights, const float rad_fac, const bool link_strokes, tGpTimingData *gtd)
{
struct Main *bmain = CTX_data_main(C);
View3D *v3d = CTX_wm_view3d(C); /* may be NULL */
Scene *scene = CTX_data_scene(C);
SceneLayer *sl = CTX_data_scene_layer(C);
SceneCollection *sc = CTX_data_scene_collection(C);
bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, 0);
bGPDstroke *gps, *prev_gps = NULL;
Object *ob;
Curve *cu;
Nurb *nu = NULL;
BaseLegacy *base_orig = BASACT, *base_new = NULL;
Base *base_new = NULL;
float minmax_weights[2] = {1.0f, 0.0f};
/* camera framing */
@ -1152,7 +1155,8 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG
*/
ob = BKE_object_add_only_object(bmain, OB_CURVE, gpl->info);
cu = ob->data = BKE_curve_add(bmain, gpl->info, OB_CURVE);
base_new = BKE_scene_base_add(scene, ob);
BKE_collection_object_add(scene, sc, ob);
base_new = BKE_scene_layer_base_find(sl, ob);
cu->flag |= CU_3D;
@ -1216,9 +1220,8 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG
}
/* set the layer and select */
base_new->lay = ob->lay = base_orig ? base_orig->lay : BKE_screen_view3d_layer_active(v3d, scene);
base_new->flag_legacy |= SELECT;
BKE_scene_base_flag_sync_from_base(base_new);
base_new->flag |= SELECT;
BKE_scene_object_base_flag_sync_from_base(base_new);
}
/* --- */

View File

@ -124,6 +124,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
SceneLayer *sl = CTX_data_scene_layer(C);
Object *obedit = CTX_data_edit_object(C);
BMVert *eve;
BMIter iter;
@ -240,7 +241,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
else {
Object workob;
ob->parent = BASACT->object;
ob->parent = BASACT_NEW->object;
if (v3) {
ob->partype = PARVERT3;
ob->par1 = v1 - 1;
@ -347,7 +348,7 @@ static int make_proxy_exec(bContext *C, wmOperator *op)
if (ob) {
Object *newob;
BaseLegacy *newbase, *oldbase = BASACT;
BaseLegacy *newbase, *oldbase = BASACT_NEW;
char name[MAX_ID_NAME + 4];
BLI_snprintf(name, sizeof(name), "%s_proxy", ((ID *)(gob ? gob : ob))->name + 2);
@ -356,7 +357,7 @@ static int make_proxy_exec(bContext *C, wmOperator *op)
newob = BKE_object_add(bmain, scene, sl, OB_EMPTY, name);
/* set layers OK */
newbase = BASACT; /* BKE_object_add sets active... */
newbase = BASACT_NEW; /* BKE_object_add sets active... */
newbase->lay = oldbase->lay;
newob->lay = newbase->lay;
@ -1763,7 +1764,7 @@ static void new_id_matar(Main *bmain, Material **matar, const int totcol)
}
}
static void single_obdata_users(Main *bmain, Scene *scene, const int flag)
static void single_obdata_users(Main *bmain, Scene *scene, SceneLayer *sl, const int flag)
{
Lamp *la;
Curve *cu;
@ -1773,11 +1774,9 @@ static void single_obdata_users(Main *bmain, Scene *scene, const int flag)
ID *id;
int a;
TODO_LAYER; /* need to use scene->collection base instead of scene->bases */
for (base = FIRSTBASE; base; base = base->next) {
ob = base->object;
if (!ID_IS_LINKED_DATABLOCK(ob) && (base->flag_legacy & flag) == flag) {
FOREACH_OBJECT_FLAG(scene, sl, flag, ob)
{
if (!ID_IS_LINKED_DATABLOCK(ob)) {
id = ob->data;
if (id && id->us > 1 && !ID_IS_LINKED_DATABLOCK(id)) {
@ -1843,6 +1842,7 @@ static void single_obdata_users(Main *bmain, Scene *scene, const int flag)
}
}
}
FOREACH_OBJECT_FLAG_END
me = bmain->mesh.first;
while (me) {
@ -2000,7 +2000,7 @@ void ED_object_single_users(Main *bmain, Scene *scene, const bool full, const bo
single_object_users(bmain, scene, NULL, 0, copy_groups);
if (full) {
single_obdata_users(bmain, scene, 0);
single_obdata_users(bmain, scene, NULL, 0);
single_object_action_users(scene, NULL, 0);
single_mat_users_expand(bmain);
single_tex_users_expand(bmain);
@ -2319,7 +2319,7 @@ static int make_single_user_exec(bContext *C, wmOperator *op)
}
if (RNA_boolean_get(op->ptr, "obdata")) {
single_obdata_users(bmain, scene, flag);
single_obdata_users(bmain, scene, sl, flag);
}
if (RNA_boolean_get(op->ptr, "material")) {

View File

@ -446,6 +446,7 @@ static void image_refresh(const bContext *C, ScrArea *sa)
static void image_listener(bScreen *sc, ScrArea *sa, wmNotifier *wmn)
{
Scene *scene = sc->scene;
SceneLayer *sl = BKE_scene_layer_context_active(scene);
SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
/* context changes */
@ -538,8 +539,7 @@ static void image_listener(bScreen *sc, ScrArea *sa, wmNotifier *wmn)
case ND_TRANSFORM:
case ND_MODIFIER:
{
TODO_LAYER_CONTEXT; /* need to use OBACT_NEW */
Object *ob = OBACT;
Object *ob = OBACT_NEW;
if (ob && (ob == wmn->reference) && (ob->mode & OB_MODE_EDIT)) {
if (sima->lock && (sima->flag & SI_DRAWSHADOW)) {
ED_area_tag_refresh(sa);

View File

@ -460,14 +460,14 @@ static void set_sca_ob(Object *ob)
static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisflag)
{
BaseLegacy *base;
Main *bmain= CTX_data_main(C);
Scene *scene= CTX_data_scene(C);
Object *ob, *obt, *obact= CTX_data_active_object(C);
Base *base;
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
SceneLayer *sl = CTX_data_scene_layer(C);
Object *ob, *obt, *obact = CTX_data_active_object(C);
ID **idar;
bSensor *sens;
bController *cont;
unsigned int lay;
int a, nr, do_it;
/* we need a sorted object list */
@ -485,19 +485,12 @@ static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisf
ob= ob->id.next;
}
/* XXX here it checked 3d lay */
lay= scene->lay;
base= FIRSTBASE;
while (base) {
if (base->lay & lay) {
if (base->flag_legacy & SELECT) {
if (scavisflag & BUTS_SENS_SEL) base->object->scavisflag |= OB_VIS_SENS;
if (scavisflag & BUTS_CONT_SEL) base->object->scavisflag |= OB_VIS_CONT;
if (scavisflag & BUTS_ACT_SEL) base->object->scavisflag |= OB_VIS_ACT;
}
for (base = FIRSTBASE_NEW; base; base = base->next) {
if ((base->flag & BASE_VISIBLED) && (base->flag & SELECT)) {
if (scavisflag & BUTS_SENS_SEL) base->object->scavisflag |= OB_VIS_SENS;
if (scavisflag & BUTS_CONT_SEL) base->object->scavisflag |= OB_VIS_CONT;
if (scavisflag & BUTS_ACT_SEL) base->object->scavisflag |= OB_VIS_ACT;
}
base= base->next;
}
if (obact) {

View File

@ -98,14 +98,14 @@ static eOLDrawState tree_element_active_renderlayer(
* CTRL+LMB: Select/Deselect object and all cildren
* CTRL+SHIFT+LMB: Add/Remove object and all children
*/
static void do_outliner_object_select_recursive(Scene *scene, Object *ob_parent, bool select)
static void do_outliner_object_select_recursive(SceneLayer *sl, Object *ob_parent, bool select)
{
BaseLegacy *base;
Base *base;
for (base = FIRSTBASE; base; base = base->next) {
for (base = FIRSTBASE_NEW; base; base = base->next) {
Object *ob = base->object;
if ((((ob->restrictflag & OB_RESTRICT_VIEW) == 0) && BKE_object_is_child_recursive(ob_parent, ob))) {
ED_base_object_select(base, select ? BA_SELECT : BA_DESELECT);
if ((((base->flag & BASE_VISIBLED) == 0) && BKE_object_is_child_recursive(ob_parent, ob))) {
ED_object_base_select(base, select ? BA_SELECT : BA_DESELECT);
}
}
}
@ -183,7 +183,7 @@ static eOLDrawState tree_element_set_active_object(
if (recursive) {
/* Recursive select/deselect for Object hierarchies */
do_outliner_object_select_recursive(scene, ob, (ob->flag & SELECT) != 0);
do_outliner_object_select_recursive(sl, ob, (ob->flag & SELECT) != 0);
}
if (set != OL_SETSEL_NONE) {

View File

@ -2056,9 +2056,11 @@ static char *rna_MeshStatVis_path(PointerRNA *UNUSED(ptr))
* is not for general use and only for the few cases where changing scene
* settings and NOT for general purpose updates, possibly this should be
* given its own notifier. */
static void rna_Scene_update_active_object_data(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
static void rna_Scene_update_active_object_data(bContext *C, PointerRNA *UNUSED(ptr))
{
Object *ob = OBACT;
SceneLayer *sl = CTX_data_scene_layer(C);
Object *ob = OBACT_NEW;
if (ob) {
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, &ob->id);
@ -3303,6 +3305,7 @@ static void rna_def_tool_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Sculpt", "");
prop = RNA_def_property(srna, "use_auto_normalize", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_boolean_sdna(prop, NULL, "auto_normalize", 1);
RNA_def_property_ui_text(prop, "WPaint Auto-Normalize",
"Ensure all bone-deforming vertex groups add up "
@ -3310,6 +3313,7 @@ static void rna_def_tool_settings(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_Scene_update_active_object_data");
prop = RNA_def_property(srna, "use_multipaint", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_boolean_sdna(prop, NULL, "multipaint", 1);
RNA_def_property_ui_text(prop, "WPaint Multi-Paint",
"Paint across the weights of all selected bones, "
@ -3317,12 +3321,14 @@ static void rna_def_tool_settings(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_Scene_update_active_object_data");
prop = RNA_def_property(srna, "vertex_group_user", PROP_ENUM, PROP_NONE);
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_enum_sdna(prop, NULL, "weightuser");
RNA_def_property_enum_items(prop, draw_groupuser_items);
RNA_def_property_ui_text(prop, "Mask Non-Group Vertices", "Display unweighted vertices");
RNA_def_property_update(prop, 0, "rna_Scene_update_active_object_data");
prop = RNA_def_property(srna, "vertex_group_subset", PROP_ENUM, PROP_NONE);
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_enum_sdna(prop, NULL, "vgroupsubset");
RNA_def_property_enum_items(prop, vertex_group_select_items);
RNA_def_property_ui_text(prop, "Subset", "Filter Vertex groups for Display");