Blender  V3.3
info_report.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <limits.h>
8 #include <stdlib.h>
9 #include <string.h>
10 
11 #include "MEM_guardedalloc.h"
12 
13 #include "BLI_blenlib.h"
14 #include "BLI_dynstr.h"
15 #include "BLI_utildefines.h"
16 
17 #include "BKE_context.h"
18 
19 #include "WM_api.h"
20 #include "WM_types.h"
21 
22 #include "ED_screen.h"
23 #include "ED_select_utils.h"
24 
25 #include "RNA_access.h"
26 #include "RNA_define.h"
27 
28 #include "info_intern.h"
29 
30 static void reports_select_all(ReportList *reports, int report_mask, int action)
31 {
32  if (action == SEL_TOGGLE) {
33  action = SEL_SELECT;
34  for (Report *report = reports->list.last; report; report = report->prev) {
35  if ((report->type & report_mask) && (report->flag & SELECT)) {
36  action = SEL_DESELECT;
37  break;
38  }
39  }
40  }
41 
42  for (Report *report = reports->list.last; report; report = report->prev) {
43  if (report->type & report_mask) {
44  switch (action) {
45  case SEL_SELECT:
46  report->flag = SELECT;
47  break;
48  case SEL_DESELECT:
49  report->flag = ~SELECT;
50  break;
51  case SEL_INVERT:
52  report->flag ^= SELECT;
53  break;
54  default:
55  BLI_assert(0);
56  }
57  }
58  }
59 }
60 
61 int info_report_mask(const SpaceInfo *UNUSED(sinfo))
62 {
63 #if 0
64  int report_mask = 0;
65 
66  if (sinfo->rpt_mask & INFO_RPT_DEBUG) {
67  report_mask |= RPT_DEBUG_ALL;
68  }
69  if (sinfo->rpt_mask & INFO_RPT_INFO) {
70  report_mask |= RPT_INFO_ALL;
71  }
72  if (sinfo->rpt_mask & INFO_RPT_OP) {
73  report_mask |= RPT_OPERATOR_ALL;
74  }
75  if (sinfo->rpt_mask & INFO_RPT_WARN) {
76  report_mask |= RPT_WARNING_ALL;
77  }
78  if (sinfo->rpt_mask & INFO_RPT_ERR) {
79  report_mask |= RPT_ERROR_ALL;
80  }
81 
82  return report_mask;
83 #endif
84 
87 }
88 
90 {
91  /* TODO: get this working again! */
92 #if 0
94  ReportList *reports = CTX_wm_reports(C);
95  int report_mask = info_report_mask(sc);
96  Report *report;
97 
98  sc->type = CONSOLE_TYPE_PYTHON;
99 
100  for (report = reports->list.last; report; report = report->prev) {
101  if ((report->type & report_mask) && (report->type & RPT_OPERATOR_ALL | RPT_PROPERTY_ALL) &&
102  (report->flag & SELECT)) {
103  console_history_add_str(sc, report->message, 0);
104  WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL, NULL);
105 
107  }
108  }
109 
110  sc->type = CONSOLE_TYPE_REPORT;
111 #endif
113 
114  return OPERATOR_FINISHED;
115 }
116 
118 {
119  /* identifiers */
120  ot->name = "Replay Operators";
121  ot->description = "Replay selected reports";
122  ot->idname = "INFO_OT_report_replay";
123 
124  /* api callbacks */
127 
128  /* flags */
129  /* ot->flag = OPTYPE_REGISTER; */
130 
131  /* properties */
132 }
133 
135 {
136  int report_index = RNA_int_get(op->ptr, "report_index");
137  bool extend = RNA_boolean_get(op->ptr, "extend");
138 
139  Report *report = BLI_findlink(&CTX_wm_reports(C)->list, report_index);
140 
141  SpaceInfo *sinfo = CTX_wm_space_info(C);
142  ReportList *reports = CTX_wm_reports(C);
143  const int report_mask = info_report_mask(sinfo);
144  if (!report) {
145  return OPERATOR_CANCELLED;
146  }
147 
148  if (!extend) {
149  reports_select_all(reports, report_mask, SEL_DESELECT);
150  }
151  report->flag ^= SELECT; /* toggle */
152 
154 
155  return OPERATOR_FINISHED;
156 }
157 
158 static int select_report_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
159 {
160  SpaceInfo *sinfo = CTX_wm_space_info(C);
161  ARegion *region = CTX_wm_region(C);
162  ReportList *reports = CTX_wm_reports(C);
163  Report *report;
164 
165  report = info_text_pick(sinfo, region, reports, event->mval[1]);
166 
167  RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));
168 
169  return select_report_pick_exec(C, op);
170 }
171 
173 {
174  /* identifiers */
175  ot->name = "Select Report";
176  ot->description = "Select reports by index";
177  ot->idname = "INFO_OT_select_pick";
178 
179  /* api callbacks */
183 
184  /* flags */
185  /* ot->flag = OPTYPE_REGISTER; */
186 
187  /* properties */
188  PropertyRNA *prop;
189  RNA_def_int(
190  ot->srna, "report_index", 0, 0, INT_MAX, "Report", "Index of the report", 0, INT_MAX);
191  prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend report selection");
193 }
194 
196 {
197  SpaceInfo *sinfo = CTX_wm_space_info(C);
198  ReportList *reports = CTX_wm_reports(C);
199  const int report_mask = info_report_mask(sinfo);
200 
201  int action = RNA_enum_get(op->ptr, "action");
202  reports_select_all(reports, report_mask, action);
203 
205 
206  return OPERATOR_FINISHED;
207 }
208 
210 {
211  /* identifiers */
212  ot->name = "(De)select All";
213  ot->description = "Change selection of all visible reports";
214  ot->idname = "INFO_OT_select_all";
215 
216  /* api callbacks */
219 
220  /* properties */
222 }
223 
224 /* box_select operator */
226 {
227  SpaceInfo *sinfo = CTX_wm_space_info(C);
228  ARegion *region = CTX_wm_region(C);
229  ReportList *reports = CTX_wm_reports(C);
230  int report_mask = info_report_mask(sinfo);
231  Report *report_min, *report_max;
232  rcti rect;
233 
235 
236  const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
237  const int select = (sel_op != SEL_OP_SUB);
238  if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
239  LISTBASE_FOREACH (Report *, report, &reports->list) {
240  if ((report->type & report_mask) == 0) {
241  continue;
242  }
243  report->flag &= ~SELECT;
244  }
245  }
246 
247  report_min = info_text_pick(sinfo, region, reports, rect.ymax);
248  report_max = info_text_pick(sinfo, region, reports, rect.ymin);
249 
250  /* get the first report if none found */
251  if (report_min == NULL) {
252  // printf("find_min\n");
253  LISTBASE_FOREACH (Report *, report, &reports->list) {
254  if (report->type & report_mask) {
255  report_min = report;
256  break;
257  }
258  }
259  }
260 
261  if (report_max == NULL) {
262  // printf("find_max\n");
263  for (Report *report = reports->list.last; report; report = report->prev) {
264  if (report->type & report_mask) {
265  report_max = report;
266  break;
267  }
268  }
269  }
270 
271  if (report_min == NULL || report_max == NULL) {
272  return OPERATOR_CANCELLED;
273  }
274 
275  for (Report *report = report_min; (report != report_max->next); report = report->next) {
276  if ((report->type & report_mask) == 0) {
277  continue;
278  }
279  SET_FLAG_FROM_TEST(report->flag, select, SELECT);
280  }
281 
283 
284  return OPERATOR_FINISHED;
285 }
286 
287 /* ****** Box Select ****** */
288 
290 {
291  /* identifiers */
292  ot->name = "Box Select";
293  ot->description = "Toggle box selection";
294  ot->idname = "INFO_OT_select_box";
295 
296  /* api callbacks */
301 
303 
304  /* flags */
305  /* ot->flag = OPTYPE_REGISTER; */
306 
307  /* properties */
310 }
311 
313 {
314  SpaceInfo *sinfo = CTX_wm_space_info(C);
315  ReportList *reports = CTX_wm_reports(C);
316  int report_mask = info_report_mask(sinfo);
317 
318  Report *report, *report_next;
319 
320  for (report = reports->list.first; report;) {
321 
322  report_next = report->next;
323 
324  if ((report->type & report_mask) && (report->flag & SELECT)) {
325  BLI_remlink(&reports->list, report);
326  MEM_freeN((void *)report->message);
327  MEM_freeN(report);
328  }
329 
330  report = report_next;
331  }
332 
334 
335  return OPERATOR_FINISHED;
336 }
337 
339 {
340  /* identifiers */
341  ot->name = "Delete Reports";
342  ot->description = "Delete selected reports";
343  ot->idname = "INFO_OT_report_delete";
344 
345  /* api callbacks */
348 
349  /* flags */
350  // ot->flag = OPTYPE_REGISTER;
351 
352  /* properties */
353 }
354 
356 {
357  SpaceInfo *sinfo = CTX_wm_space_info(C);
358  ReportList *reports = CTX_wm_reports(C);
359  int report_mask = info_report_mask(sinfo);
360 
361  Report *report;
362 
363  DynStr *buf_dyn = BLI_dynstr_new();
364  char *buf_str;
365 
366  for (report = reports->list.first; report; report = report->next) {
367  if ((report->type & report_mask) && (report->flag & SELECT)) {
368  BLI_dynstr_append(buf_dyn, report->message);
369  BLI_dynstr_append(buf_dyn, "\n");
370  }
371  }
372 
373  buf_str = BLI_dynstr_get_cstring(buf_dyn);
374  BLI_dynstr_free(buf_dyn);
375 
376  WM_clipboard_text_set(buf_str, 0);
377 
378  MEM_freeN(buf_str);
379  return OPERATOR_FINISHED;
380 }
381 
383 {
384  /* identifiers */
385  ot->name = "Copy Reports to Clipboard";
386  ot->description = "Copy selected reports to clipboard";
387  ot->idname = "INFO_OT_report_copy";
388 
389  /* api callbacks */
392 
393  /* flags */
394  // ot->flag = OPTYPE_REGISTER;
395 
396  /* properties */
397 }
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:738
struct SpaceInfo * CTX_wm_space_info(const bContext *C)
Definition: context.c:905
struct ReportList * CTX_wm_reports(const bContext *C)
Definition: context.c:775
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:749
#define BLI_assert(a)
Definition: BLI_assert.h:46
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:50
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:256
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:281
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:75
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:100
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define UNUSED(x)
#define SET_FLAG_FROM_TEST(value, test, flag)
@ INFO_RPT_INFO
@ INFO_RPT_WARN
@ INFO_RPT_ERR
@ INFO_RPT_OP
@ INFO_RPT_DEBUG
#define RPT_PROPERTY_ALL
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
#define RPT_ERROR_ALL
#define RPT_INFO_ALL
#define RPT_OPERATOR_ALL
#define RPT_WARNING_ALL
#define RPT_DEBUG_ALL
void ED_area_tag_redraw(ScrArea *area)
Definition: area.c:729
bool ED_operator_info_active(struct bContext *C)
Definition: screen_ops.c:354
#define SEL_OP_USE_PRE_DESELECT(sel_op)
@ SEL_SELECT
@ SEL_INVERT
@ SEL_DESELECT
@ SEL_TOGGLE
eSelectOp
@ SEL_OP_SUB
Read Guarded memory(de)allocation.
@ PROP_SKIP_SAVE
Definition: RNA_types.h:218
#define C
Definition: RandGen.cpp:25
@ WM_OP_EXEC_DEFAULT
Definition: WM_types.h:208
__forceinline const avxb select(const avxb &m, const avxb &t, const avxb &f)
Definition: avxb.h:154
ConsoleLine * console_history_add_str(struct SpaceConsole *sc, char *str, bool own)
Definition: console_ops.c:190
#define SELECT
void * info_text_pick(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports, int mouse_y)
Definition: info_draw.c:205
void INFO_OT_select_all(wmOperatorType *ot)
Definition: info_report.c:209
void INFO_OT_report_copy(wmOperatorType *ot)
Definition: info_report.c:382
void INFO_OT_select_pick(wmOperatorType *ot)
Definition: info_report.c:172
static int box_select_exec(bContext *C, wmOperator *op)
Definition: info_report.c:225
void INFO_OT_report_replay(wmOperatorType *ot)
Definition: info_report.c:117
void INFO_OT_report_delete(wmOperatorType *ot)
Definition: info_report.c:338
static int report_select_all_exec(bContext *C, wmOperator *op)
Definition: info_report.c:195
static int report_replay_exec(bContext *C, wmOperator *UNUSED(op))
Definition: info_report.c:89
int info_report_mask(const SpaceInfo *UNUSED(sinfo))
Definition: info_report.c:61
static void reports_select_all(ReportList *reports, int report_mask, int action)
Definition: info_report.c:30
static int report_copy_exec(bContext *C, wmOperator *UNUSED(op))
Definition: info_report.c:355
static int select_report_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: info_report.c:158
void INFO_OT_select_box(wmOperatorType *ot)
Definition: info_report.c:289
static int select_report_pick_exec(bContext *C, wmOperator *op)
Definition: info_report.c:134
static int report_delete_exec(bContext *C, wmOperator *UNUSED(op))
Definition: info_report.c:312
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:4921
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4910
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3597
void * last
Definition: DNA_listBase.h:31
void * first
Definition: DNA_listBase.h:31
struct Report * next
struct Report * prev
const char * message
int ymin
Definition: DNA_vec_types.h:64
int ymax
Definition: DNA_vec_types.h:64
int mval[2]
Definition: WM_types.h:684
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
int(* modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:935
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
void(* cancel)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:927
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
struct PointerRNA * ptr
int WM_operator_name_call(bContext *C, const char *opstring, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
wmOperatorType * ot
Definition: wm_files.c:3479
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
int WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
int WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
void WM_operator_properties_border_to_rcti(struct wmOperator *op, rcti *rect)
void WM_operator_properties_gesture_box(wmOperatorType *ot)
void WM_operator_properties_select_operation_simple(wmOperatorType *ot)
void WM_operator_properties_select_action(wmOperatorType *ot, int default_action, bool hide_gui)
void WM_clipboard_text_set(const char *buf, bool selection)
Definition: wm_window.c:1780