WM: rename WM_report* to WM_global_report*, note it's often bad practice

WM_report was originally added for special cases however new code
has been using this in operators for example, where reports should be
sent to the operator via BKE_report, so the caller can handle,
and so Python can catch the errors.

Rename the functions to make them less easily confused with BKE_report
and add a code-comment on why their use should be avoided.
This commit is contained in:
Campbell Barton
2025-03-11 12:36:17 +11:00
parent a064c23de5
commit bd06baf6e6
32 changed files with 153 additions and 121 deletions

View File

@@ -4994,7 +4994,7 @@ static int graphkeys_view_selected_channels_exec(bContext *C, wmOperator *op)
&ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
if (anim_data_length == 0) {
WM_report(RPT_WARNING, "No channels to operate on");
WM_global_report(RPT_WARNING, "No channels to operate on");
return OPERATOR_CANCELLED;
}
@@ -5023,7 +5023,7 @@ static int graphkeys_view_selected_channels_exec(bContext *C, wmOperator *op)
if (!valid_bounds) {
ANIM_animdata_freelist(&anim_data);
WM_report(RPT_WARNING, "No keyframes to focus on");
WM_global_report(RPT_WARNING, "No keyframes to focus on");
return OPERATOR_CANCELLED;
}
@@ -5112,7 +5112,7 @@ static int graphkeys_channel_view_pick_invoke(bContext *C, wmOperator *op, const
if (!found_bounds) {
ANIM_animdata_freelist(&anim_data);
WM_report(RPT_WARNING, "No keyframes to focus on");
WM_global_report(RPT_WARNING, "No keyframes to focus on");
return OPERATOR_CANCELLED;
}
@@ -5181,7 +5181,7 @@ static int channels_bake_exec(bContext *C, wmOperator *op)
&ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
if (anim_data_length == 0) {
WM_report(RPT_WARNING, "No channels to operate on");
WM_global_report(RPT_WARNING, "No channels to operate on");
return OPERATOR_CANCELLED;
}
@@ -5340,7 +5340,7 @@ static int slot_channels_move_to_new_action_exec(bContext *C, wmOperator * /* op
size_t anim_data_length = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
if (anim_data_length == 0) {
WM_report(RPT_WARNING, "No channels to operate on");
WM_global_report(RPT_WARNING, "No channels to operate on");
return OPERATOR_CANCELLED;
}
@@ -5356,7 +5356,7 @@ static int slot_channels_move_to_new_action_exec(bContext *C, wmOperator * /* op
ANIM_animdata_freelist(&anim_data);
if (slots.size() == 0) {
WM_report(RPT_WARNING, "None of the selected channels is an Action Slot");
WM_global_report(RPT_WARNING, "None of the selected channels is an Action Slot");
return OPERATOR_CANCELLED;
}
@@ -5708,7 +5708,7 @@ static int view_curve_in_graph_editor_exec(bContext *C, wmOperator *op)
if (!context_find_graph_editor(
C, &wm_context_temp.win, &wm_context_temp.area, &wm_context_temp.region))
{
WM_report(RPT_WARNING, "No open Graph Editor window found");
WM_global_report(RPT_WARNING, "No open Graph Editor window found");
retval = OPERATOR_CANCELLED;
}
else {
@@ -5723,7 +5723,7 @@ static int view_curve_in_graph_editor_exec(bContext *C, wmOperator *op)
bAnimContext ac;
if (!ANIM_animdata_get_context(C, &ac)) {
/* This might never be called since we are manually setting the Graph Editor just before. */
WM_report(RPT_ERROR, "Cannot create the Animation Context");
WM_global_report(RPT_ERROR, "Cannot create the Animation Context");
retval = OPERATOR_CANCELLED;
}
else {
@@ -5763,11 +5763,12 @@ static int view_curve_in_graph_editor_exec(bContext *C, wmOperator *op)
}
if (filtered_fcurve_count > 0) {
WM_report(RPT_WARNING, "One or more F-Curves are not visible due to filter settings");
WM_global_report(RPT_WARNING,
"One or more F-Curves are not visible due to filter settings");
}
if (!BLI_rctf_is_valid(&bounds)) {
WM_report(RPT_ERROR, "F-Curves have no valid size");
WM_global_report(RPT_ERROR, "F-Curves have no valid size");
retval = OPERATOR_CANCELLED;
}
else {

View File

@@ -106,7 +106,7 @@ static void fmodifier_reorder(bContext *C, Panel *panel, int new_index)
/* Cycles modifier has to be the first, so make sure it's kept that way. */
if (fmi->requires_flag & FMI_REQUIRES_ORIGINAL_DATA) {
WM_report(RPT_ERROR, "Modifier requires original data");
WM_global_report(RPT_ERROR, "Modifier requires original data");
return;
}
@@ -116,7 +116,7 @@ static void fmodifier_reorder(bContext *C, Panel *panel, int new_index)
FModifier *fcm_first = static_cast<FModifier *>(modifiers->first);
const FModifierTypeInfo *fmi_first = get_fmodifier_typeinfo(fcm_first->type);
if (fmi_first->requires_flag & FMI_REQUIRES_ORIGINAL_DATA && new_index == 0) {
WM_report(RPT_ERROR, "Modifier requires original data");
WM_global_report(RPT_ERROR, "Modifier requires original data");
return;
}

View File

@@ -1797,7 +1797,8 @@ static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op)
BLI_assert_msg(bcoll_ref,
"Bone that is not visible due to its bone collections MUST be assigned to at "
"least one of them.");
WM_reportf(RPT_WARNING, "Bone was added to a hidden collection '%s'", bcoll_ref->bcoll->name);
WM_global_reportf(
RPT_WARNING, "Bone was added to a hidden collection '%s'", bcoll_ref->bcoll->name);
}
copy_v3_v3(bone->head, curs);

View File

@@ -256,7 +256,7 @@ void ED_armature_bone_rename(Main *bmain,
if (BKE_modifiers_uses_armature(ob, arm) && BKE_object_supports_vertex_groups(ob)) {
if (BKE_object_defgroup_find_name(ob, newname)) {
WM_reportf(
WM_global_reportf(
eReportType::RPT_WARNING,
"%s (%s::%s)",
RPT_("New bone name collides with an existing vertex group name, vertex group "

View File

@@ -227,7 +227,7 @@ static BoneCollection *get_bonecoll_named_or_active(bContext * /*C*/, wmOperator
BoneCollection *bcoll = ANIM_armature_bonecoll_get_by_name(armature, bcoll_name);
if (!bcoll) {
WM_reportf(RPT_ERROR, "No bone collection named '%s'", bcoll_name);
WM_global_reportf(RPT_ERROR, "No bone collection named '%s'", bcoll_name);
return nullptr;
}
@@ -415,7 +415,7 @@ static int bone_collection_assign_exec(bContext *C, wmOperator *op)
bArmature *armature = static_cast<bArmature *>(ob->data);
if (!ANIM_armature_bonecoll_is_editable(armature, bcoll)) {
WM_reportf(RPT_ERROR, "Cannot assign to linked bone collection %s", bcoll->name);
WM_global_reportf(RPT_ERROR, "Cannot assign to linked bone collection %s", bcoll->name);
return OPERATOR_CANCELLED;
}
@@ -431,15 +431,15 @@ static int bone_collection_assign_exec(bContext *C, wmOperator *op)
&had_bones_to_assign);
if (!mode_is_supported) {
WM_report(RPT_ERROR, "This operator only works in pose mode and armature edit mode");
WM_global_report(RPT_ERROR, "This operator only works in pose mode and armature edit mode");
return OPERATOR_CANCELLED;
}
if (!had_bones_to_assign) {
WM_report(RPT_WARNING, "No bones selected, nothing to assign to bone collection");
WM_global_report(RPT_WARNING, "No bones selected, nothing to assign to bone collection");
return OPERATOR_CANCELLED;
}
if (!made_any_changes) {
WM_report(RPT_WARNING, "All selected bones were already part of this collection");
WM_global_report(RPT_WARNING, "All selected bones were already part of this collection");
return OPERATOR_CANCELLED;
}
@@ -528,12 +528,12 @@ static int bone_collection_create_and_assign_exec(bContext *C, wmOperator *op)
&had_bones_to_assign);
if (!mode_is_supported) {
WM_report(RPT_ERROR, "This operator only works in pose mode and armature edit mode");
WM_global_report(RPT_ERROR, "This operator only works in pose mode and armature edit mode");
ANIM_armature_bonecoll_remove(armature, bcoll);
return OPERATOR_CANCELLED;
}
if (!had_bones_to_assign) {
WM_report(RPT_WARNING, "No bones selected, nothing to assign to bone collection");
WM_global_report(RPT_WARNING, "No bones selected, nothing to assign to bone collection");
return OPERATOR_FINISHED;
}
/* Not checking for `made_any_changes`, as if there were any bones to assign, they never could
@@ -591,15 +591,15 @@ static int bone_collection_unassign_exec(bContext *C, wmOperator *op)
&had_bones_to_unassign);
if (!mode_is_supported) {
WM_report(RPT_ERROR, "This operator only works in pose mode and armature edit mode");
WM_global_report(RPT_ERROR, "This operator only works in pose mode and armature edit mode");
return OPERATOR_CANCELLED;
}
if (!had_bones_to_unassign) {
WM_report(RPT_WARNING, "No bones selected, nothing to unassign from bone collection");
WM_global_report(RPT_WARNING, "No bones selected, nothing to unassign from bone collection");
return OPERATOR_CANCELLED;
}
if (!made_any_changes) {
WM_report(RPT_WARNING, "None of the selected bones were assigned to this collection");
WM_global_report(RPT_WARNING, "None of the selected bones were assigned to this collection");
return OPERATOR_CANCELLED;
}
return OPERATOR_FINISHED;
@@ -643,7 +643,7 @@ static int bone_collection_unassign_named_exec(bContext *C, wmOperator *op)
char bone_name[MAX_NAME];
RNA_string_get(op->ptr, "bone_name", bone_name);
if (!bone_name[0]) {
WM_report(RPT_ERROR, "Missing bone name");
WM_global_report(RPT_ERROR, "Missing bone name");
return OPERATOR_CANCELLED;
}
@@ -660,15 +660,15 @@ static int bone_collection_unassign_named_exec(bContext *C, wmOperator *op)
&had_bones_to_unassign);
if (!mode_is_supported) {
WM_report(RPT_ERROR, "This operator only works in pose mode and armature edit mode");
WM_global_report(RPT_ERROR, "This operator only works in pose mode and armature edit mode");
return OPERATOR_CANCELLED;
}
if (!had_bones_to_unassign) {
WM_reportf(RPT_WARNING, "Could not find bone '%s'", bone_name);
WM_global_reportf(RPT_WARNING, "Could not find bone '%s'", bone_name);
return OPERATOR_CANCELLED;
}
if (!made_any_changes) {
WM_reportf(
WM_global_reportf(
RPT_WARNING, "Bone '%s' was not assigned to collection '%s'", bone_name, bcoll->name);
return OPERATOR_CANCELLED;
}
@@ -926,15 +926,15 @@ static int add_or_move_to_collection_exec(bContext *C,
&had_bones_to_assign);
if (!mode_is_supported) {
WM_report(RPT_ERROR, "This operator only works in pose mode and armature edit mode");
WM_global_report(RPT_ERROR, "This operator only works in pose mode and armature edit mode");
return OPERATOR_CANCELLED;
}
if (!had_bones_to_assign) {
WM_report(RPT_WARNING, "No bones selected, nothing to assign to bone collection");
WM_global_report(RPT_WARNING, "No bones selected, nothing to assign to bone collection");
return OPERATOR_CANCELLED;
}
if (!made_any_changes) {
WM_report(RPT_WARNING, "All selected bones were already part of this collection");
WM_global_report(RPT_WARNING, "All selected bones were already part of this collection");
return OPERATOR_CANCELLED;
}

View File

@@ -355,7 +355,8 @@ static int lineart_bake_common(bContext *C,
if (!bake_all_targets) {
Object *ob = CTX_data_active_object(C);
if (!ob || ob->type != OB_GREASE_PENCIL) {
WM_report(RPT_ERROR, "No active object, or active object isn't a Grease Pencil object");
WM_global_report(RPT_ERROR,
"No active object, or active object isn't a Grease Pencil object");
return OPERATOR_CANCELLED;
}
bj->objects.append(ob);

View File

@@ -50,10 +50,10 @@ bool ED_id_rename(Main &bmain, ID &id, blender::StringRefNull name)
"collision with another ID",
id.name + 2,
name.c_str());
WM_reportf(RPT_INFO,
"Data-block renamed to '%s', try again to force renaming it to '%s'",
id.name + 2,
name.c_str());
WM_global_reportf(RPT_INFO,
"Data-block renamed to '%s', try again to force renaming it to '%s'",
id.name + 2,
name.c_str());
WM_main_add_notifier(NC_ID | NA_RENAME, &id);
return true;
case IDNewNameResult::Action::RENAMED_COLLISION_FORCED:
@@ -62,9 +62,9 @@ bool ED_id_rename(Main &bmain, ID &id, blender::StringRefNull name)
4,
"ID '%s' forcefully renamed, another ID had to also be renamed to avoid name collision",
id.name + 2);
WM_reportf(RPT_INFO,
"Name in use. The other data-block was renamed to %s",
result.other_id->name + 2);
WM_global_reportf(RPT_INFO,
"Name in use. The other data-block was renamed to %s",
result.other_id->name + 2);
WM_main_add_notifier(NC_ID | NA_RENAME, &id);
WM_main_add_notifier(NC_ID | NA_RENAME, result.other_id);
return true;

View File

@@ -2612,7 +2612,7 @@ static void ui_but_paste_numeric_array(bContext *C,
ui_but_set_float_array(C, but, data, values.data(), values_len);
}
else {
WM_report(RPT_ERROR, "Expected an array of numbers: [n, n, ...]");
WM_global_report(RPT_ERROR, "Expected an array of numbers: [n, n, ...]");
}
}
@@ -2637,7 +2637,7 @@ static void ui_but_paste_numeric_value(bContext *C,
button_activate_state(C, but, BUTTON_STATE_EXIT);
}
else {
WM_report(RPT_ERROR, "Expected a number");
WM_global_report(RPT_ERROR, "Expected a number");
}
}
@@ -2655,7 +2655,7 @@ static void ui_but_paste_normalized_vector(bContext *C,
ui_but_set_float_array(C, but, data, xyz, 3);
}
else {
WM_report(RPT_ERROR, "Paste expected 3 numbers, formatted: '[n, n, n]'");
WM_global_report(RPT_ERROR, "Paste expected 3 numbers, formatted: '[n, n, n]'");
}
}
@@ -2696,7 +2696,7 @@ static void ui_but_paste_color(bContext *C, uiBut *but, char *buf_paste)
}
}
else {
WM_report(RPT_ERROR, "Paste expected 4 numbers, formatted: '[n, n, n, n]'");
WM_global_report(RPT_ERROR, "Paste expected 4 numbers, formatted: '[n, n, n, n]'");
}
}
@@ -3667,7 +3667,7 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
/* ensure menu (popup) too is closed! */
data->escapecancel = true;
WM_reportf(RPT_ERROR, "Failed to find '%s'", but->editstr);
WM_global_reportf(RPT_ERROR, "Failed to find '%s'", but->editstr);
WM_report_banner_show(CTX_wm_manager(C), win);
}
}
@@ -4752,11 +4752,11 @@ static int ui_do_but_HOTKEYEVT(bContext *C,
return WM_UI_HANDLER_CONTINUE;
}
if (event->type == EVT_UNKNOWNKEY) {
WM_report(RPT_WARNING, "Unsupported key: Unknown");
WM_global_report(RPT_WARNING, "Unsupported key: Unknown");
return WM_UI_HANDLER_CONTINUE;
}
if (event->type == EVT_CAPSLOCKKEY) {
WM_report(RPT_WARNING, "Unsupported key: CapsLock");
WM_global_report(RPT_WARNING, "Unsupported key: CapsLock");
return WM_UI_HANDLER_CONTINUE;
}
@@ -8678,8 +8678,8 @@ static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState s
* No warnings should show for editing driver expressions though!
*/
if (state != BUTTON_STATE_TEXT_EDITING) {
WM_report(RPT_INFO,
"Can't edit driven number value, see driver editor for the driver setup");
WM_global_report(RPT_INFO,
"Can't edit driven number value, see driver editor for the driver setup");
}
}

View File

@@ -385,7 +385,7 @@ ID *ui_template_id_liboverride_hierarchy_make(
* NOTE: do not attempt to perform such hierarchy override at all cost, if there is not enough
* context, better to abort than create random overrides all over the place. */
if (!ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(id)) {
WM_reportf(RPT_ERROR, "The data-block %s is not overridable", id->name);
WM_global_reportf(RPT_ERROR, "The data-block %s is not overridable", id->name);
return nullptr;
}
@@ -574,16 +574,16 @@ ID *ui_template_id_liboverride_hierarchy_make(
case ID_MA:
case ID_TE:
case ID_IM:
WM_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name);
WM_global_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name);
break;
case ID_WO:
WM_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name);
WM_global_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name);
break;
case ID_PA:
WM_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name);
WM_global_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name);
break;
default:
WM_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name);
WM_global_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name);
break;
}
@@ -657,7 +657,7 @@ static void template_id_liboverride_hierarchy_make(bContext *C,
}
}
else {
WM_reportf(RPT_ERROR, "The data-block %s could not be overridden", id->name);
WM_global_reportf(RPT_ERROR, "The data-block %s could not be overridden", id->name);
}
}

View File

@@ -199,7 +199,7 @@ static int cachefile_layer_add_exec(bContext *C, wmOperator *op)
CacheFileLayer *layer = BKE_cachefile_add_layer(cache_file, filepath);
if (layer == nullptr) {
WM_report(RPT_ERROR, "Could not add a layer to the cache file");
WM_global_report(RPT_ERROR, "Could not add a layer to the cache file");
return OPERATOR_CANCELLED;
}

View File

@@ -924,18 +924,19 @@ static void quadriflow_end_job(void *customdata)
switch (qj->success) {
case 1:
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
WM_reportf(RPT_INFO, "QuadriFlow: Remeshing completed");
WM_global_reportf(RPT_INFO, "QuadriFlow: Remeshing completed");
break;
case 0:
WM_reportf(RPT_ERROR, "QuadriFlow: Remeshing failed");
WM_global_reportf(RPT_ERROR, "QuadriFlow: Remeshing failed");
break;
case -1:
WM_report(RPT_WARNING, "QuadriFlow: Remeshing canceled");
WM_global_report(RPT_WARNING, "QuadriFlow: Remeshing canceled");
break;
case -2:
WM_report(RPT_WARNING,
"QuadriFlow: The mesh needs to be manifold and have face normals that point in a "
"consistent direction");
WM_global_report(
RPT_WARNING,
"QuadriFlow: The mesh needs to be manifold and have face normals that point in a "
"consistent direction");
break;
}
}

View File

@@ -324,15 +324,15 @@ static void dpaint_bake_endjob(void *customdata)
* Report for ended bake and how long it took */
if (job->success) {
/* Show bake info */
WM_reportf(
WM_global_reportf(
RPT_INFO, "DynamicPaint: Bake complete! (%.2f)", BLI_time_now_seconds() - job->start);
}
else {
if (strlen(canvas->error)) { /* If an error occurred */
WM_reportf(RPT_ERROR, "DynamicPaint: Bake failed: %s", canvas->error);
WM_global_reportf(RPT_ERROR, "DynamicPaint: Bake failed: %s", canvas->error);
}
else { /* User canceled the bake */
WM_report(RPT_WARNING, "Baking canceled!");
WM_global_report(RPT_WARNING, "Baking canceled!");
}
}
}

View File

@@ -336,15 +336,15 @@ static void fluid_bake_endjob(void *customdata)
* Report for ended bake and how long it took. */
if (job->success) {
/* Show bake info. */
WM_reportf(
WM_global_reportf(
RPT_INFO, "Fluid: %s complete (%.2f)", job->name, BLI_time_now_seconds() - job->start);
}
else {
if (fds->error[0] != '\0') {
WM_reportf(RPT_ERROR, "Fluid: %s failed: %s", job->name, fds->error);
WM_global_reportf(RPT_ERROR, "Fluid: %s failed: %s", job->name, fds->error);
}
else { /* User canceled the bake. */
WM_reportf(RPT_WARNING, "Fluid: %s canceled!", job->name);
WM_global_reportf(RPT_WARNING, "Fluid: %s canceled!", job->name);
}
}
}
@@ -444,15 +444,15 @@ static void fluid_free_endjob(void *customdata)
* Report for ended free job and how long it took */
if (job->success) {
/* Show free job info */
WM_reportf(
WM_global_reportf(
RPT_INFO, "Fluid: %s complete (%.2f)", job->name, BLI_time_now_seconds() - job->start);
}
else {
if (fds->error[0] != '\0') {
WM_reportf(RPT_ERROR, "Fluid: %s failed: %s", job->name, fds->error);
WM_global_reportf(RPT_ERROR, "Fluid: %s failed: %s", job->name, fds->error);
}
else { /* User canceled the free job */
WM_reportf(RPT_WARNING, "Fluid: %s canceled!", job->name);
WM_global_reportf(RPT_WARNING, "Fluid: %s canceled!", job->name);
}
}
}

View File

@@ -965,13 +965,13 @@ static PoseBackup *action_preview_render_prepare(IconPreview *preview)
{
Object *object = preview->active_object;
if (object == nullptr) {
WM_report(RPT_WARNING, "No active object, unable to apply the Action before rendering");
WM_global_report(RPT_WARNING, "No active object, unable to apply the Action before rendering");
return nullptr;
}
if (object->pose == nullptr) {
WM_reportf(RPT_WARNING,
"Object %s has no pose, unable to apply the Action before rendering",
object->id.name + 2);
WM_global_reportf(RPT_WARNING,
"Object %s has no pose, unable to apply the Action before rendering",
object->id.name + 2);
return nullptr;
}
@@ -979,7 +979,7 @@ static PoseBackup *action_preview_render_prepare(IconPreview *preview)
blender::animrig::Action &pose_action = reinterpret_cast<bAction *>(preview->id)->wrap();
if (pose_action.slot_array_num == 0) {
WM_report(RPT_WARNING, "Action has no data, cannot render preview");
WM_global_report(RPT_WARNING, "Action has no data, cannot render preview");
return nullptr;
}

View File

@@ -395,7 +395,7 @@ static bool screen_areas_can_align(bScreen *screen, ScrArea *sa1, ScrArea *sa2,
if (area->v3->vec.x - area->v1->vec.x < tolerance &&
(area->v1->vec.x == xmin || area->v3->vec.x == xmax))
{
WM_report(RPT_ERROR, "A narrow vertical area interferes with this operation");
WM_global_report(RPT_ERROR, "A narrow vertical area interferes with this operation");
return false;
}
}
@@ -410,7 +410,7 @@ static bool screen_areas_can_align(bScreen *screen, ScrArea *sa1, ScrArea *sa2,
if (area->v3->vec.y - area->v1->vec.y < tolerance &&
(area->v1->vec.y == ymin || area->v3->vec.y == ymax))
{
WM_report(RPT_ERROR, "A narrow horizontal area interferes with this operation");
WM_global_report(RPT_ERROR, "A narrow horizontal area interferes with this operation");
return false;
}
}

View File

@@ -1053,7 +1053,7 @@ static int min_distance_edit_invoke(bContext *C, wmOperator *op, const wmEvent *
surface_bvh_eval.raycast_callback,
&surface_bvh_eval);
if (ray_hit.index == -1) {
WM_report(RPT_ERROR, "Cursor must be over the surface mesh");
WM_global_report(RPT_ERROR, "Cursor must be over the surface mesh");
return OPERATOR_CANCELLED;
}

View File

@@ -874,7 +874,8 @@ static void renamebutton_cb(bContext *C, void * /*arg1*/, char *oldname)
if (!STREQ(orgname, newname)) {
errno = 0;
if ((BLI_rename(orgname, newname) != 0) || !BLI_exists(newname)) {
WM_reportf(RPT_ERROR, "Could not rename: %s", errno ? strerror(errno) : "unknown error");
WM_global_reportf(
RPT_ERROR, "Could not rename: %s", errno ? strerror(errno) : "unknown error");
WM_report_banner_show(wm, win);
/* Renaming failed, reset the name for further renaming handling. */
STRNCPY(params->renamefile, oldname);

View File

@@ -3332,10 +3332,10 @@ static int graph_driver_delete_invalid_exec(bContext *C, wmOperator * /*op*/)
/* Notify the world of any changes. */
DEG_relations_tag_update(CTX_data_main(C));
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, nullptr);
WM_reportf(RPT_INFO, "Deleted %u drivers", deleted);
WM_global_reportf(RPT_INFO, "Deleted %u drivers", deleted);
}
else {
WM_report(RPT_INFO, "No drivers deleted");
WM_global_report(RPT_INFO, "No drivers deleted");
}
/* Successful or not? */

View File

@@ -411,7 +411,7 @@ static int graph_slider_invoke(bContext *C, wmOperator *op, const wmEvent *event
ED_slider_init(gso->slider, event);
if (gso->bezt_arr_list.first == nullptr) {
WM_report(RPT_ERROR, "Cannot find keys to operate on");
WM_global_report(RPT_ERROR, "Cannot find keys to operate on");
graph_slider_exit(C, op);
return OPERATOR_CANCELLED;
}
@@ -443,7 +443,7 @@ static void decimate_graph_keys(bAnimContext *ac, float factor, float error_sq_m
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
if (!decimate_fcurve(ale, factor, error_sq_max)) {
/* The selection contains unsupported keyframe types! */
WM_report(RPT_WARNING, "Decimate: Skipping non linear/Bézier keyframes!");
WM_global_report(RPT_WARNING, "Decimate: Skipping non linear/Bézier keyframes!");
}
ale->update |= ANIM_UPDATE_DEFAULT;
@@ -1319,10 +1319,10 @@ static void match_slope_graph_keys(bAnimContext *ac, const float factor)
if (!all_segments_valid) {
if (factor >= 0) {
WM_report(RPT_WARNING, "You need at least 2 keys to the right side of the selection");
WM_global_report(RPT_WARNING, "You need at least 2 keys to the right side of the selection");
}
else {
WM_report(RPT_WARNING, "You need at least 2 keys to the left side of the selection");
WM_global_report(RPT_WARNING, "You need at least 2 keys to the left side of the selection");
}
}

View File

@@ -381,7 +381,7 @@ static bool is_compositing_possible(const bContext *C)
* texture, which we want to avoid due its cost. So we employ a heuristic that so far has worked
* with all known GPU drivers. */
if (size_t(width) * height > (size_t(max_texture_size) * max_texture_size) / 4) {
WM_report(RPT_ERROR, "Render size too large for GPU, use CPU compositor instead");
WM_global_report(RPT_ERROR, "Render size too large for GPU, use CPU compositor instead");
return false;
}

View File

@@ -56,7 +56,7 @@ static bool build_depsgraph(ExportJobData *job)
Collection *collection = reinterpret_cast<Collection *>(
BKE_libblock_find_name(job->bmain, ID_GR, job->params.collection));
if (!collection) {
WM_reportf(
WM_global_reportf(
RPT_ERROR, "Alembic Export: Unable to find collection '%s'", job->params.collection);
return false;
}
@@ -121,7 +121,7 @@ static void export_startjob(void *customdata, wmJobWorkerStatus *worker_status)
/* The exception message can be very cryptic (just "iostream error" on Linux, for example),
* so better not to include it in the report. */
CLOG_ERROR(&LOG, "%s: %s", error_message.c_str(), ex.what());
WM_report(RPT_ERROR, error_message.c_str());
WM_global_report(RPT_ERROR, error_message.c_str());
data->export_ok = false;
return;
}
@@ -129,7 +129,7 @@ static void export_startjob(void *customdata, wmJobWorkerStatus *worker_status)
/* Unknown exception class, so we cannot include its message. */
std::stringstream error_message_stream;
error_message_stream << "Unknown error writing to " << data->filepath;
WM_report(RPT_ERROR, error_message_stream.str().c_str());
WM_global_report(RPT_ERROR, error_message_stream.str().c_str());
data->export_ok = false;
return;
}

View File

@@ -700,7 +700,8 @@ static void import_endjob(void *user_data)
data->import_ok = !data->was_cancelled;
break;
case ABC_ARCHIVE_FAIL:
WM_report(RPT_ERROR, "Could not open Alembic archive for reading, see console for detail");
WM_global_report(RPT_ERROR,
"Could not open Alembic archive for reading, see console for detail");
break;
}

View File

@@ -354,7 +354,7 @@ std::string get_export_textures_dir(const pxr::UsdStageRefPtr stage)
pxr::SdfLayerHandle layer = stage->GetRootLayer();
if (layer->IsAnonymous()) {
WM_reportf(
WM_global_reportf(
RPT_WARNING, "%s: Can't generate a textures directory path for anonymous stage", __func__);
return "";
}
@@ -362,7 +362,7 @@ std::string get_export_textures_dir(const pxr::UsdStageRefPtr stage)
const pxr::ArResolvedPath &stage_path = layer->GetResolvedPath();
if (stage_path.empty()) {
WM_reportf(RPT_WARNING, "%s: Can't get resolved path for stage", __func__);
WM_global_reportf(RPT_WARNING, "%s: Can't get resolved path for stage", __func__);
return "";
}
@@ -642,10 +642,10 @@ void USD_path_abs(char *path, const char *basepath, bool for_import)
BLI_strncpy(path, path_str.c_str(), FILE_MAX);
return;
}
WM_reportf(RPT_ERROR,
"In %s: resolved path %s exceeds path buffer length.",
__func__,
path_str.c_str());
WM_global_reportf(RPT_ERROR,
"In %s: resolved path %s exceeds path buffer length.",
__func__,
path_str.c_str());
}
}

View File

@@ -106,7 +106,7 @@ static bool prim_path_valid(const char *path)
/* Check path syntax. */
std::string errMsg;
if (!pxr::SdfPath::IsValidPathString(path, &errMsg)) {
WM_reportf(RPT_ERROR, "USD Export: invalid path string '%s': %s", path, errMsg.c_str());
WM_global_reportf(RPT_ERROR, "USD Export: invalid path string '%s': %s", path, errMsg.c_str());
return false;
}
@@ -115,12 +115,12 @@ static bool prim_path_valid(const char *path)
pxr::SdfPath sdf_path(path);
if (!sdf_path.IsAbsolutePath()) {
WM_reportf(RPT_ERROR, "USD Export: path '%s' is not an absolute path", path);
WM_global_reportf(RPT_ERROR, "USD Export: path '%s' is not an absolute path", path);
return false;
}
if (!sdf_path.IsPrimPath()) {
WM_reportf(RPT_ERROR, "USD Export: path string '%s' is not a prim path", path);
WM_global_reportf(RPT_ERROR, "USD Export: path string '%s' is not a prim path", path);
return false;
}

View File

@@ -333,7 +333,7 @@ static void rna_ActionSlot_name_display_set(PointerRNA *ptr, const char *name)
const StringRef name_ref(name);
if (name_ref.is_empty()) {
WM_report(RPT_ERROR, "Action slot display names cannot be empty");
WM_global_report(RPT_ERROR, "Action slot display names cannot be empty");
return;
}
@@ -347,7 +347,7 @@ static void rna_ActionSlot_identifier_set(PointerRNA *ptr, const char *identifie
const StringRef identifier_ref(identifier);
if (identifier_ref.size() < animrig::Slot::identifier_length_min) {
WM_report(RPT_ERROR, "Action slot identifiers should be at least three characters");
WM_global_report(RPT_ERROR, "Action slot identifiers should be at least three characters");
return;
}
@@ -358,12 +358,13 @@ static void rna_ActionSlot_identifier_set(PointerRNA *ptr, const char *identifie
identifier_ref.substr(2);
if (identifier_with_correct_prefix != identifier_ref) {
WM_reportf(RPT_WARNING,
"Attempted to set slot identifier to \"%s\", but the type prefix doesn't match the "
"slot's 'target_id_type' \"%s\". Setting to \"%s\" instead.\n",
identifier,
slot.idtype_string().c_str(),
identifier_with_correct_prefix.c_str());
WM_global_reportf(
RPT_WARNING,
"Attempted to set slot identifier to \"%s\", but the type prefix doesn't match the "
"slot's 'target_id_type' \"%s\". Setting to \"%s\" instead.\n",
identifier,
slot.idtype_string().c_str(),
identifier_with_correct_prefix.c_str());
}
action.slot_identifier_define(slot, identifier_with_correct_prefix);

View File

@@ -295,13 +295,13 @@ void rna_generic_action_slot_handle_set(blender::animrig::slot_handle_t slot_han
BLI_assert_unreachable();
break;
case ActionSlotAssignmentResult::SlotNotSuitable:
WM_reportf(RPT_ERROR,
"This slot is not suitable for this data-block type (%c%c)",
animated_id.name[0],
animated_id.name[1]);
WM_global_reportf(RPT_ERROR,
"This slot is not suitable for this data-block type (%c%c)",
animated_id.name[0],
animated_id.name[1]);
break;
case ActionSlotAssignmentResult::MissingAction:
WM_report(RPT_ERROR, "Cannot set slot without an assigned Action.");
WM_global_report(RPT_ERROR, "Cannot set slot without an assigned Action.");
break;
}
}

View File

@@ -95,7 +95,7 @@ static void rna_Volume_velocity_grid_set(PointerRNA *ptr, const char *value)
{
Volume *volume = (Volume *)ptr->data;
if (!BKE_volume_set_velocity_grid_by_name(volume, value)) {
WM_reportf(RPT_ERROR, "Could not find grid with name %s", value);
WM_global_reportf(RPT_ERROR, "Could not find grid with name %s", value);
}
WM_main_add_notifier(NC_GEOM | ND_DATA, volume);
}

View File

@@ -716,8 +716,30 @@ void WM_report_banners_cancel(Main *bmain);
* #G_MAIN will be used.
*/
void WM_reports_from_reports_move(wmWindowManager *wm, ReportList *reports);
void WM_report(eReportType type, const char *message);
void WM_reportf(eReportType type, const char *format, ...) ATTR_PRINTF_FORMAT(2, 3);
/**
* Report directly to the window manager without any context.
*
* \warning This function should almost always be avoided in favor of #BKE_report,
* if this isn't possible, a code-comment must be included explaining why.
*
* Global reports are bad practice because the caller can't handle or suppress them.
* This means for example, if an automated tasks/scripts can generate many reports
* that are shown to the user without any way to control error handling.
*
* When used in operators it prevents the Python script from raising an exception
* form the error as it should do, showing a popup instead.
*/
void WM_global_report(eReportType type, const char *message);
/**
* Report directly to the window manager without any context.
*
* \warning This function should almost always be avoided in favor of #BKE_reportf,
* if this isn't possible, a code-comment must be included explaining why.
*
* See #WM_global_report for details.
*/
void WM_global_reportf(eReportType type, const char *format, ...) ATTR_PRINTF_FORMAT(2, 3);
wmEvent *wm_event_add_ex(wmWindow *win,
const wmEvent *event_to_add,

View File

@@ -727,7 +727,7 @@ static void wm_draw_region_buffer_create(Scene *scene,
GPU_TEXTURE_USAGE_SHADER_READ,
nullptr);
if (!offscreen) {
WM_report(RPT_ERROR, "Region could not be drawn!");
WM_global_report(RPT_ERROR, "Region could not be drawn!");
return;
}

View File

@@ -1017,8 +1017,9 @@ void WM_reports_from_reports_move(wmWindowManager *wm, ReportList *reports)
WM_report_banner_show(wm, nullptr);
}
void WM_report(eReportType type, const char *message)
void WM_global_report(eReportType type, const char *message)
{
/* WARNING: in most cases #BKE_report should be used instead, see doc-string for details. */
ReportList reports;
BKE_reports_init(&reports, RPT_STORE | RPT_PRINT);
BKE_report_print_level_set(&reports, RPT_WARNING);
@@ -1029,8 +1030,10 @@ void WM_report(eReportType type, const char *message)
BKE_reports_free(&reports);
}
void WM_reportf(eReportType type, const char *format, ...)
void WM_global_reportf(eReportType type, const char *format, ...)
{
/* WARNING: in most cases #BKE_reportf should be used instead, see doc-string for details. */
va_list args;
format = RPT_(format);
@@ -1039,7 +1042,7 @@ void WM_reportf(eReportType type, const char *format, ...)
char *str = BLI_vsprintfN(format, args);
va_end(args);
WM_report(type, str);
WM_global_report(type, str);
MEM_freeN(str);
}

View File

@@ -45,7 +45,7 @@ static void wm_xr_error_handler(const GHOST_XrError *error)
wmWindow *root_win = wm->xr.runtime ? wm->xr.runtime->session_root_win : nullptr;
BKE_reports_clear(&wm->runtime->reports);
WM_report(RPT_ERROR, error->user_message);
WM_global_report(RPT_ERROR, error->user_message);
/* Rely on the fallback when `root_win` is nullptr. */
WM_report_banner_show(wm, root_win);

View File

@@ -217,7 +217,7 @@ void wm_xr_disable_passthrough(void *customdata)
XrSessionSettings *settings = &xr_data->session_settings;
settings->draw_flags &= ~V3D_OFSDRAW_XR_SHOW_PASSTHROUGH;
WM_report(RPT_INFO, "Passthrough not available");
WM_global_report(RPT_INFO, "Passthrough not available");
}
static blender::gpu::Batch *wm_xr_controller_model_batch_create(GHOST_XrContextHandle xr_context,