Cleanup: Use switch
and BLI_assert_unreachable()
more.
Replace some `if/else if` chains by proper `switch` statement. Replace some `BLI_assert(0)` calls by `BLI_assert_unreachable()` ones.
This commit is contained in:
parent
22bf263269
commit
6d42cd8ff9
@ -170,7 +170,8 @@ static TreeElement *outliner_drop_insert_find(bContext *C,
|
|||||||
*r_insert_type = TE_INSERT_BEFORE;
|
*r_insert_type = TE_INSERT_BEFORE;
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
BLI_assert(0);
|
|
||||||
|
BLI_assert_unreachable();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,43 +231,51 @@ static void unlink_material_fn(bContext *UNUSED(C),
|
|||||||
Material **matar = nullptr;
|
Material **matar = nullptr;
|
||||||
int a, totcol = 0;
|
int a, totcol = 0;
|
||||||
|
|
||||||
if (GS(tsep->id->name) == ID_OB) {
|
switch (GS(tsep->id->name)) {
|
||||||
Object *ob = (Object *)tsep->id;
|
case ID_OB: {
|
||||||
totcol = ob->totcol;
|
Object *ob = (Object *)tsep->id;
|
||||||
matar = ob->mat;
|
totcol = ob->totcol;
|
||||||
}
|
matar = ob->mat;
|
||||||
else if (GS(tsep->id->name) == ID_ME) {
|
break;
|
||||||
Mesh *me = (Mesh *)tsep->id;
|
}
|
||||||
totcol = me->totcol;
|
case ID_ME: {
|
||||||
matar = me->mat;
|
Mesh *me = (Mesh *)tsep->id;
|
||||||
}
|
totcol = me->totcol;
|
||||||
else if (GS(tsep->id->name) == ID_CU_LEGACY) {
|
matar = me->mat;
|
||||||
Curve *cu = (Curve *)tsep->id;
|
break;
|
||||||
totcol = cu->totcol;
|
}
|
||||||
matar = cu->mat;
|
case ID_CU_LEGACY: {
|
||||||
}
|
Curve *cu = (Curve *)tsep->id;
|
||||||
else if (GS(tsep->id->name) == ID_MB) {
|
totcol = cu->totcol;
|
||||||
MetaBall *mb = (MetaBall *)tsep->id;
|
matar = cu->mat;
|
||||||
totcol = mb->totcol;
|
break;
|
||||||
matar = mb->mat;
|
}
|
||||||
}
|
case ID_MB: {
|
||||||
else if (GS(tsep->id->name) == ID_CV) {
|
MetaBall *mb = (MetaBall *)tsep->id;
|
||||||
Curves *curves = (Curves *)tsep->id;
|
totcol = mb->totcol;
|
||||||
totcol = curves->totcol;
|
matar = mb->mat;
|
||||||
matar = curves->mat;
|
break;
|
||||||
}
|
}
|
||||||
else if (GS(tsep->id->name) == ID_PT) {
|
case ID_CV: {
|
||||||
PointCloud *pointcloud = (PointCloud *)tsep->id;
|
Curves *curves = (Curves *)tsep->id;
|
||||||
totcol = pointcloud->totcol;
|
totcol = curves->totcol;
|
||||||
matar = pointcloud->mat;
|
matar = curves->mat;
|
||||||
}
|
break;
|
||||||
else if (GS(tsep->id->name) == ID_VO) {
|
}
|
||||||
Volume *volume = (Volume *)tsep->id;
|
case ID_PT: {
|
||||||
totcol = volume->totcol;
|
PointCloud *pointcloud = (PointCloud *)tsep->id;
|
||||||
matar = volume->mat;
|
totcol = pointcloud->totcol;
|
||||||
}
|
matar = pointcloud->mat;
|
||||||
else {
|
break;
|
||||||
BLI_assert(0);
|
}
|
||||||
|
case ID_VO: {
|
||||||
|
Volume *volume = (Volume *)tsep->id;
|
||||||
|
totcol = volume->totcol;
|
||||||
|
matar = volume->mat;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
BLI_assert_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LIKELY(matar != nullptr)) {
|
if (LIKELY(matar != nullptr)) {
|
||||||
@ -492,7 +500,7 @@ static int outliner_scene_operation_exec(bContext *C, wmOperator *op)
|
|||||||
ED_undo_push(C, "Delete Scene(s)");
|
ED_undo_push(C, "Delete Scene(s)");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BLI_assert(0);
|
BLI_assert_unreachable();
|
||||||
return OPERATOR_CANCELLED;
|
return OPERATOR_CANCELLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1720,47 +1728,54 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op)
|
|||||||
|
|
||||||
event = RNA_enum_get(op->ptr, "type");
|
event = RNA_enum_get(op->ptr, "type");
|
||||||
|
|
||||||
if (event == OL_OP_SELECT) {
|
switch (event) {
|
||||||
Scene *sce = scene; /* To be able to delete, scenes are set... */
|
case OL_OP_SELECT: {
|
||||||
outliner_do_object_operation(
|
Scene *sce = scene; /* To be able to delete, scenes are set... */
|
||||||
C, op->reports, scene, space_outliner, &space_outliner->tree, object_select_fn);
|
outliner_do_object_operation(
|
||||||
if (scene != sce) {
|
C, op->reports, scene, space_outliner, &space_outliner->tree, object_select_fn);
|
||||||
WM_window_set_active_scene(bmain, C, win, sce);
|
/* FIXME: This is most certainly broken, maybe check should rather be
|
||||||
}
|
* `if (CTX_data_scene(C) != scene)` ? */
|
||||||
|
if (scene != sce) {
|
||||||
|
WM_window_set_active_scene(bmain, C, win, sce);
|
||||||
|
}
|
||||||
|
|
||||||
str = "Select Objects";
|
str = "Select Objects";
|
||||||
selection_changed = true;
|
selection_changed = true;
|
||||||
}
|
break;
|
||||||
else if (event == OL_OP_SELECT_HIERARCHY) {
|
|
||||||
Scene *sce = scene; /* To be able to delete, scenes are set... */
|
|
||||||
outliner_do_object_operation_ex(C,
|
|
||||||
op->reports,
|
|
||||||
scene,
|
|
||||||
space_outliner,
|
|
||||||
&space_outliner->tree,
|
|
||||||
object_select_hierarchy_fn,
|
|
||||||
nullptr,
|
|
||||||
false);
|
|
||||||
if (scene != sce) {
|
|
||||||
WM_window_set_active_scene(bmain, C, win, sce);
|
|
||||||
}
|
}
|
||||||
str = "Select Object Hierarchy";
|
case OL_OP_SELECT_HIERARCHY: {
|
||||||
selection_changed = true;
|
Scene *sce = scene; /* To be able to delete, scenes are set... */
|
||||||
}
|
outliner_do_object_operation_ex(C,
|
||||||
else if (event == OL_OP_DESELECT) {
|
op->reports,
|
||||||
outliner_do_object_operation(
|
scene,
|
||||||
C, op->reports, scene, space_outliner, &space_outliner->tree, object_deselect_fn);
|
space_outliner,
|
||||||
str = "Deselect Objects";
|
&space_outliner->tree,
|
||||||
selection_changed = true;
|
object_select_hierarchy_fn,
|
||||||
}
|
nullptr,
|
||||||
else if (event == OL_OP_RENAME) {
|
false);
|
||||||
outliner_do_object_operation(
|
/* FIXME: This is most certainly broken, maybe check should rather be
|
||||||
C, op->reports, scene, space_outliner, &space_outliner->tree, item_rename_fn);
|
* `if (CTX_data_scene(C) != scene)` ? */
|
||||||
str = "Rename Object";
|
if (scene != sce) {
|
||||||
}
|
WM_window_set_active_scene(bmain, C, win, sce);
|
||||||
else {
|
}
|
||||||
BLI_assert(0);
|
str = "Select Object Hierarchy";
|
||||||
return OPERATOR_CANCELLED;
|
selection_changed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OL_OP_DESELECT:
|
||||||
|
outliner_do_object_operation(
|
||||||
|
C, op->reports, scene, space_outliner, &space_outliner->tree, object_deselect_fn);
|
||||||
|
str = "Deselect Objects";
|
||||||
|
selection_changed = true;
|
||||||
|
break;
|
||||||
|
case OL_OP_RENAME:
|
||||||
|
outliner_do_object_operation(
|
||||||
|
C, op->reports, scene, space_outliner, &space_outliner->tree, item_rename_fn);
|
||||||
|
str = "Rename Object";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
BLI_assert_unreachable();
|
||||||
|
return OPERATOR_CANCELLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selection_changed) {
|
if (selection_changed) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user