Blender V5.3
info_report.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <climits>
10#include <cstdlib>
11#include <cstring>
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_dynstr.hh"
16#include "BLI_listbase.hh"
17#include "BLI_utildefines.hh"
18
19#include "BKE_context.hh"
20
21#include "WM_api.hh"
22#include "WM_types.hh"
23
24#include "ED_screen.hh"
25#include "ED_select_utils.hh"
26
27#include "RNA_access.hh"
28#include "RNA_define.hh"
29
30#include "info_intern.hh"
31
32namespace blender {
33
34static void reports_select_all(ReportList *reports, int report_mask, int action)
35{
36 if (action == SEL_TOGGLE) {
37 action = SEL_SELECT;
38 for (const Report &report : reports->list.items_reversed()) {
39 if ((report.type & report_mask) && (report.flag & SELECT)) {
40 action = SEL_DESELECT;
41 break;
42 }
43 }
44 }
45
46 for (Report &report : reports->list.items_reversed()) {
47 if (report.type & report_mask) {
48 switch (action) {
49 case SEL_SELECT:
50 report.flag = SELECT;
51 break;
52 case SEL_DESELECT:
53 report.flag = ~SELECT;
54 break;
55 case SEL_INVERT:
56 report.flag ^= SELECT;
57 break;
58 default:
59 BLI_assert(0);
60 }
61 }
62 }
63}
64
65int info_report_mask(const SpaceInfo * /*sinfo*/)
66{
67#if 0
68 int report_mask = 0;
69
70 if (sinfo->rpt_mask & INFO_RPT_DEBUG) {
71 report_mask |= RPT_DEBUG_ALL;
72 }
73 if (sinfo->rpt_mask & INFO_RPT_INFO) {
74 report_mask |= RPT_INFO_ALL;
75 }
76 if (sinfo->rpt_mask & INFO_RPT_OP) {
77 report_mask |= RPT_OPERATOR_ALL;
78 }
79 if (sinfo->rpt_mask & INFO_RPT_WARN) {
80 report_mask |= RPT_WARNING_ALL;
81 }
82 if (sinfo->rpt_mask & INFO_RPT_ERR) {
83 report_mask |= RPT_ERROR_ALL;
84 }
85
86 return report_mask;
87#endif
88
91}
92
94{
95 /* TODO: get this working again! */
96#if 0
98 ReportList *reports = CTX_wm_reports(C);
99 int report_mask = info_report_mask(sc);
100 Report *report;
101
102 sc->type = CONSOLE_TYPE_PYTHON;
103
104 for (report = reports->list.last; report; report = report->prev) {
105 if ((report->type & report_mask) && (report->type & RPT_OPERATOR_ALL | RPT_PROPERTY_ALL) &&
106 (report->flag & SELECT))
107 {
108 console_history_add_str(sc, report->message, 0);
109 WM_operator_name_call(C, "CONSOLE_OT_execute", wm::OpCallContext::ExecDefault, nullptr, nullptr);
110
112 }
113 }
114
115 sc->type = CONSOLE_TYPE_REPORT;
116#endif
118
119 return OPERATOR_FINISHED;
120}
121
123{
124 /* identifiers */
125 ot->name = "Replay Operators";
126 ot->description = "Replay selected reports";
127 ot->idname = "INFO_OT_report_replay";
128
129 /* API callbacks. */
132
133 /* flags */
134 // ot->flag = OPTYPE_REGISTER;
135
136 /* properties */
137}
138
140{
141 int report_index = RNA_int_get(op->ptr, "report_index");
142 bool extend = RNA_boolean_get(op->ptr, "extend");
143
144 Report *report = static_cast<Report *>(BLI_findlink(&CTX_wm_reports(C)->list, report_index));
145
146 SpaceInfo *sinfo = CTX_wm_space_info(C);
147 ReportList *reports = CTX_wm_reports(C);
148 const int report_mask = info_report_mask(sinfo);
149 if (!report) {
150 return OPERATOR_CANCELLED;
151 }
152
153 if (!extend) {
154 reports_select_all(reports, report_mask, SEL_DESELECT);
155 }
156 report->flag ^= SELECT; /* toggle */
157
159
160 return OPERATOR_FINISHED;
161}
162
164 wmOperator *op,
165 const wmEvent *event)
166{
167 SpaceInfo *sinfo = CTX_wm_space_info(C);
168 ARegion *region = CTX_wm_region(C);
169 ReportList *reports = CTX_wm_reports(C);
170 Report *report;
171
172 report = static_cast<Report *>(info_text_pick(sinfo, region, reports, event->mval[1]));
173
174 RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));
175
176 return select_report_pick_exec(C, op);
177}
178
180{
181 /* identifiers */
182 ot->name = "Select Report";
183 ot->description = "Select reports by index";
184 ot->idname = "INFO_OT_select_pick";
185
186 /* API callbacks. */
190
191 /* flags */
192 // ot->flag = OPTYPE_REGISTER;
193
194 /* properties */
195 PropertyRNA *prop;
197 ot->srna, "report_index", 0, 0, INT_MAX, "Report", "Index of the report", 0, INT_MAX);
198 prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend report selection");
200}
201
203{
204 SpaceInfo *sinfo = CTX_wm_space_info(C);
205 ReportList *reports = CTX_wm_reports(C);
206 const int report_mask = info_report_mask(sinfo);
207
208 int action = RNA_enum_get(op->ptr, "action");
209 reports_select_all(reports, report_mask, action);
210
212
213 return OPERATOR_FINISHED;
214}
215
217{
218 /* identifiers */
219 ot->name = "(De)select All";
220 ot->description = "Change selection of all visible reports";
221 ot->idname = "INFO_OT_select_all";
222
223 /* API callbacks. */
226
227 /* properties */
229}
230
231/* box_select operator */
233{
234 SpaceInfo *sinfo = CTX_wm_space_info(C);
235 ARegion *region = CTX_wm_region(C);
236 ReportList *reports = CTX_wm_reports(C);
237 int report_mask = info_report_mask(sinfo);
238 Report *report_min, *report_max;
239 rcti rect;
240
242
243 const eSelectOp sel_op = eSelectOp(RNA_enum_get(op->ptr, "mode"));
244 const int select = (sel_op != SEL_OP_SUB);
245 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
246 for (Report &report : reports->list) {
247 if ((report.type & report_mask) == 0) {
248 continue;
249 }
250 report.flag &= ~SELECT;
251 }
252 }
253
254 report_min = static_cast<Report *>(info_text_pick(sinfo, region, reports, rect.ymax));
255 report_max = static_cast<Report *>(info_text_pick(sinfo, region, reports, rect.ymin));
256
257 /* get the first report if none found */
258 if (report_min == nullptr) {
259 // printf("find_min\n");
260 for (Report &report : reports->list) {
261 if (report.type & report_mask) {
262 report_min = &report;
263 break;
264 }
265 }
266 }
267
268 if (report_max == nullptr) {
269 // printf("find_max\n");
270 for (Report &report : reports->list.items_reversed()) {
271 if (report.type & report_mask) {
272 report_max = &report;
273 break;
274 }
275 }
276 }
277
278 if (report_min == nullptr || report_max == nullptr) {
279 return OPERATOR_CANCELLED;
280 }
281
282 for (Report *report = report_min; (report != report_max->next); report = report->next) {
283 if ((report->type & report_mask) == 0) {
284 continue;
285 }
286 SET_FLAG_FROM_TEST(report->flag, select, SELECT);
287 }
288
290
291 return OPERATOR_FINISHED;
292}
293
294/* ****** Box Select ****** */
295
297{
298 /* identifiers */
299 ot->name = "Box Select";
300 ot->description = "Toggle box selection";
301 ot->idname = "INFO_OT_select_box";
302
303 /* API callbacks. */
305 ot->exec = box_select_exec;
308
310
311 /* flags */
312 // ot->flag = OPTYPE_REGISTER;
313
314 /* properties */
317}
318
320{
321 SpaceInfo *sinfo = CTX_wm_space_info(C);
322 ReportList *reports = CTX_wm_reports(C);
323 int report_mask = info_report_mask(sinfo);
324
325 Report *report, *report_next;
326
327 for (report = reports->list.first(); report;) {
328 report_next = report->next;
329
330 if ((report->type & report_mask) && (report->flag & SELECT)) {
331 BLI_remlink(&reports->list, report);
332 MEM_delete(report->message);
333 MEM_delete(report);
334 }
335
336 report = report_next;
337 }
338
340
341 return OPERATOR_FINISHED;
342}
343
345{
346 /* identifiers */
347 ot->name = "Delete Reports";
348 ot->description = "Delete selected reports";
349 ot->idname = "INFO_OT_report_delete";
350
351 /* API callbacks. */
354
355 /* flags */
356 // ot->flag = OPTYPE_REGISTER;
357
358 /* properties */
359}
360
362{
363 SpaceInfo *sinfo = CTX_wm_space_info(C);
364 ReportList *reports = CTX_wm_reports(C);
365 int report_mask = info_report_mask(sinfo);
366
367 DynStr *buf_dyn = BLI_dynstr_new();
368 char *buf_str;
369
370 for (Report &report : reports->list) {
371 if ((report.type & report_mask) && (report.flag & SELECT)) {
372 BLI_dynstr_append(buf_dyn, report.message);
373 BLI_dynstr_append(buf_dyn, "\n");
374 }
375 }
376
377 buf_str = BLI_dynstr_get_cstring(buf_dyn);
378 BLI_dynstr_free(buf_dyn);
379
380 WM_clipboard_text_set(buf_str, false);
381
382 MEM_delete(buf_str);
383 return OPERATOR_FINISHED;
384}
385
387{
388 /* identifiers */
389 ot->name = "Copy Reports to Clipboard";
390 ot->description = "Copy selected reports to clipboard";
391 ot->idname = "INFO_OT_report_copy";
392
393 /* API callbacks. */
396
397 /* flags */
398 // ot->flag = OPTYPE_REGISTER;
399
400 /* properties */
401}
402
403} // namespace blender
#define SELECT
Definition BKE_mask.hh:19
#define RPT_PROPERTY_ALL
Definition BKE_report.hh:51
#define RPT_ERROR_ALL
Definition BKE_report.hh:53
#define RPT_INFO_ALL
Definition BKE_report.hh:49
#define RPT_OPERATOR_ALL
Definition BKE_report.hh:50
#define RPT_WARNING_ALL
Definition BKE_report.hh:52
#define RPT_DEBUG_ALL
Definition BKE_report.hh:48
A dynamically sized string ADT.
#define SEL_OP_USE_PRE_DESELECT(sel_op)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define SET_FLAG_FROM_TEST(value, test, flag)
#define INT_MAX
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ScrArea * CTX_wm_area(const bContext *C)
static wmOperatorStatus report_copy_exec(bContext *C, wmOperator *)
int RNA_enum_get(PointerRNA *ptr, const char *name)
wmOperatorStatus WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus select_report_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
static void reports_select_all(ReportList *reports, int report_mask, int action)
int RNA_int_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus select_report_pick_exec(bContext *C, wmOperator *op)
static wmOperatorStatus report_replay_exec(bContext *C, wmOperator *)
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition BLI_dynstr.cc:58
void WM_operator_properties_select_action(wmOperatorType *ot, int default_action, bool hide_gui)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
SpaceInfo * CTX_wm_space_info(const bContext *C)
int info_report_mask(const SpaceInfo *sinfo)
void INFO_OT_select_pick(wmOperatorType *ot)
void WM_operator_properties_border_to_rcti(wmOperator *op, rcti *r_rect)
void * info_text_pick(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports, int mouse_y)
Definition info_draw.cc:203
bool ED_operator_region_info_active(bContext *C)
static wmOperatorStatus report_select_all_exec(bContext *C, wmOperator *op)
static wmOperatorStatus report_delete_exec(bContext *C, wmOperator *)
void WM_operator_properties_gesture_box(wmOperatorType *ot)
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void INFO_OT_select_box(wmOperatorType *ot)
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void INFO_OT_report_delete(wmOperatorType *ot)
void WM_clipboard_text_set(const char *buf, bool selection)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
bool ED_operator_info_active(bContext *C)
void WM_operator_properties_select_operation_simple(wmOperatorType *ot)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
ReportList * CTX_wm_reports(const bContext *C)
DynStr * BLI_dynstr_new() ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_dynstr.cc:39
ConsoleLine * console_history_add_str(SpaceConsole *sc, char *str, bool own)
ARegion * CTX_wm_region(const bContext *C)
void INFO_OT_report_replay(wmOperatorType *ot)
void INFO_OT_select_all(wmOperatorType *ot)
void INFO_OT_report_copy(wmOperatorType *ot)
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
static wmOperatorStatus box_select_exec(bContext *C, wmOperator *op)
ListBaseT< Report > list
Definition BKE_report.hh:79
const char * message
Definition BKE_report.hh:73
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157