Blender  V2.93
info_report.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include <limits.h>
22 #include <stdlib.h>
23 #include <string.h>
24 
25 #include "MEM_guardedalloc.h"
26 
27 #include "BLI_blenlib.h"
28 #include "BLI_dynstr.h"
29 #include "BLI_utildefines.h"
30 
31 #include "BKE_context.h"
32 
33 #include "WM_api.h"
34 #include "WM_types.h"
35 
36 #include "ED_screen.h"
37 #include "ED_select_utils.h"
38 
39 #include "RNA_access.h"
40 #include "RNA_define.h"
41 
42 #include "info_intern.h"
43 
44 static void reports_select_all(ReportList *reports, int report_mask, int action)
45 {
46  if (action == SEL_TOGGLE) {
47  action = SEL_SELECT;
48  for (Report *report = reports->list.last; report; report = report->prev) {
49  if ((report->type & report_mask) && (report->flag & SELECT)) {
50  action = SEL_DESELECT;
51  break;
52  }
53  }
54  }
55 
56  for (Report *report = reports->list.last; report; report = report->prev) {
57  if (report->type & report_mask) {
58  switch (action) {
59  case SEL_SELECT:
60  report->flag = SELECT;
61  break;
62  case SEL_DESELECT:
63  report->flag = ~SELECT;
64  break;
65  case SEL_INVERT:
66  report->flag ^= SELECT;
67  break;
68  default:
69  BLI_assert(0);
70  }
71  }
72  }
73 }
74 
75 int info_report_mask(const SpaceInfo *UNUSED(sinfo))
76 {
77 #if 0
78  int report_mask = 0;
79 
80  if (sinfo->rpt_mask & INFO_RPT_DEBUG) {
81  report_mask |= RPT_DEBUG_ALL;
82  }
83  if (sinfo->rpt_mask & INFO_RPT_INFO) {
84  report_mask |= RPT_INFO_ALL;
85  }
86  if (sinfo->rpt_mask & INFO_RPT_OP) {
87  report_mask |= RPT_OPERATOR_ALL;
88  }
89  if (sinfo->rpt_mask & INFO_RPT_WARN) {
90  report_mask |= RPT_WARNING_ALL;
91  }
92  if (sinfo->rpt_mask & INFO_RPT_ERR) {
93  report_mask |= RPT_ERROR_ALL;
94  }
95 
96  return report_mask;
97 #endif
98 
101 }
102 
104 {
105  /* TODO, get this working again! */
106 #if 0
108  ReportList *reports = CTX_wm_reports(C);
109  int report_mask = info_report_mask(sc);
110  Report *report;
111 
112  sc->type = CONSOLE_TYPE_PYTHON;
113 
114  for (report = reports->list.last; report; report = report->prev) {
115  if ((report->type & report_mask) && (report->type & RPT_OPERATOR_ALL | RPT_PROPERTY_ALL) &&
116  (report->flag & SELECT)) {
117  console_history_add_str(sc, report->message, 0);
118  WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL);
119 
121  }
122  }
123 
124  sc->type = CONSOLE_TYPE_REPORT;
125 #endif
127 
128  return OPERATOR_FINISHED;
129 }
130 
132 {
133  /* identifiers */
134  ot->name = "Replay Operators";
135  ot->description = "Replay selected reports";
136  ot->idname = "INFO_OT_report_replay";
137 
138  /* api callbacks */
141 
142  /* flags */
143  /* ot->flag = OPTYPE_REGISTER; */
144 
145  /* properties */
146 }
147 
149 {
150  int report_index = RNA_int_get(op->ptr, "report_index");
151  bool extend = RNA_boolean_get(op->ptr, "extend");
152 
153  Report *report = BLI_findlink(&CTX_wm_reports(C)->list, report_index);
154 
155  SpaceInfo *sinfo = CTX_wm_space_info(C);
156  ReportList *reports = CTX_wm_reports(C);
157  const int report_mask = info_report_mask(sinfo);
158  if (!report) {
159  return OPERATOR_CANCELLED;
160  }
161 
162  if (!extend) {
163  reports_select_all(reports, report_mask, SEL_DESELECT);
164  }
165  report->flag ^= SELECT; /* toggle */
166 
168 
169  return OPERATOR_FINISHED;
170 }
171 
172 static int select_report_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
173 {
174  SpaceInfo *sinfo = CTX_wm_space_info(C);
175  ARegion *region = CTX_wm_region(C);
176  ReportList *reports = CTX_wm_reports(C);
177  Report *report;
178 
179  report = info_text_pick(sinfo, region, reports, event->mval[1]);
180 
181  RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));
182 
183  return select_report_pick_exec(C, op);
184 }
185 
187 {
188  /* identifiers */
189  ot->name = "Select Report";
190  ot->description = "Select reports by index";
191  ot->idname = "INFO_OT_select_pick";
192 
193  /* api callbacks */
197 
198  /* flags */
199  /* ot->flag = OPTYPE_REGISTER; */
200 
201  /* properties */
202  PropertyRNA *prop;
203  RNA_def_int(
204  ot->srna, "report_index", 0, 0, INT_MAX, "Report", "Index of the report", 0, INT_MAX);
205  prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend report selection");
207 }
208 
210 {
211  SpaceInfo *sinfo = CTX_wm_space_info(C);
212  ReportList *reports = CTX_wm_reports(C);
213  const int report_mask = info_report_mask(sinfo);
214 
215  int action = RNA_enum_get(op->ptr, "action");
216  reports_select_all(reports, report_mask, action);
217 
219 
220  return OPERATOR_FINISHED;
221 }
222 
224 {
225  /* identifiers */
226  ot->name = "(De)select All";
227  ot->description = "Change selection of all visible reports";
228  ot->idname = "INFO_OT_select_all";
229 
230  /* api callbacks */
233 
234  /* properties */
236 }
237 
238 /* box_select operator */
240 {
241  SpaceInfo *sinfo = CTX_wm_space_info(C);
242  ARegion *region = CTX_wm_region(C);
243  ReportList *reports = CTX_wm_reports(C);
244  int report_mask = info_report_mask(sinfo);
245  Report *report_min, *report_max;
246  rcti rect;
247 
249 
250  const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
251  const int select = (sel_op != SEL_OP_SUB);
252  if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
253  LISTBASE_FOREACH (Report *, report, &reports->list) {
254  if ((report->type & report_mask) == 0) {
255  continue;
256  }
257  report->flag &= ~SELECT;
258  }
259  }
260 
261  report_min = info_text_pick(sinfo, region, reports, rect.ymax);
262  report_max = info_text_pick(sinfo, region, reports, rect.ymin);
263 
264  /* get the first report if none found */
265  if (report_min == NULL) {
266  // printf("find_min\n");
267  LISTBASE_FOREACH (Report *, report, &reports->list) {
268  if (report->type & report_mask) {
269  report_min = report;
270  break;
271  }
272  }
273  }
274 
275  if (report_max == NULL) {
276  // printf("find_max\n");
277  for (Report *report = reports->list.last; report; report = report->prev) {
278  if (report->type & report_mask) {
279  report_max = report;
280  break;
281  }
282  }
283  }
284 
285  if (report_min == NULL || report_max == NULL) {
286  return OPERATOR_CANCELLED;
287  }
288 
289  for (Report *report = report_min; (report != report_max->next); report = report->next) {
290  if ((report->type & report_mask) == 0) {
291  continue;
292  }
293  SET_FLAG_FROM_TEST(report->flag, select, SELECT);
294  }
295 
297 
298  return OPERATOR_FINISHED;
299 }
300 
301 /* ****** Box Select ****** */
303 {
304  /* identifiers */
305  ot->name = "Box Select";
306  ot->description = "Toggle box selection";
307  ot->idname = "INFO_OT_select_box";
308 
309  /* api callbacks */
314 
316 
317  /* flags */
318  /* ot->flag = OPTYPE_REGISTER; */
319 
320  /* properties */
323 }
324 
326 {
327  SpaceInfo *sinfo = CTX_wm_space_info(C);
328  ReportList *reports = CTX_wm_reports(C);
329  int report_mask = info_report_mask(sinfo);
330 
331  Report *report, *report_next;
332 
333  for (report = reports->list.first; report;) {
334 
335  report_next = report->next;
336 
337  if ((report->type & report_mask) && (report->flag & SELECT)) {
338  BLI_remlink(&reports->list, report);
339  MEM_freeN((void *)report->message);
340  MEM_freeN(report);
341  }
342 
343  report = report_next;
344  }
345 
347 
348  return OPERATOR_FINISHED;
349 }
350 
352 {
353  /* identifiers */
354  ot->name = "Delete Reports";
355  ot->description = "Delete selected reports";
356  ot->idname = "INFO_OT_report_delete";
357 
358  /* api callbacks */
361 
362  /* flags */
363  /*ot->flag = OPTYPE_REGISTER;*/
364 
365  /* properties */
366 }
367 
369 {
370  SpaceInfo *sinfo = CTX_wm_space_info(C);
371  ReportList *reports = CTX_wm_reports(C);
372  int report_mask = info_report_mask(sinfo);
373 
374  Report *report;
375 
376  DynStr *buf_dyn = BLI_dynstr_new();
377  char *buf_str;
378 
379  for (report = reports->list.first; report; report = report->next) {
380  if ((report->type & report_mask) && (report->flag & SELECT)) {
381  BLI_dynstr_append(buf_dyn, report->message);
382  BLI_dynstr_append(buf_dyn, "\n");
383  }
384  }
385 
386  buf_str = BLI_dynstr_get_cstring(buf_dyn);
387  BLI_dynstr_free(buf_dyn);
388 
389  WM_clipboard_text_set(buf_str, 0);
390 
391  MEM_freeN(buf_str);
392  return OPERATOR_FINISHED;
393 }
394 
396 {
397  /* identifiers */
398  ot->name = "Copy Reports to Clipboard";
399  ot->description = "Copy selected reports to clipboard";
400  ot->idname = "INFO_OT_report_copy";
401 
402  /* api callbacks */
405 
406  /* flags */
407  /*ot->flag = OPTYPE_REGISTER;*/
408 
409  /* properties */
410 }
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct SpaceInfo * CTX_wm_space_info(const bContext *C)
Definition: context.c:881
struct ReportList * CTX_wm_reports(const bContext *C)
Definition: context.c:751
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:725
#define BLI_assert(a)
Definition: BLI_assert.h:58
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:71
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:358
char * BLI_dynstr_get_cstring(DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:323
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:107
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:133
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
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
#define RPT_PROPERTY_ALL
#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:745
bool ED_operator_info_active(struct bContext *C)
Definition: screen_ops.c:339
#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:204
#define C
Definition: RandGen.cpp:39
@ WM_OP_EXEC_DEFAULT
Definition: WM_types.h:204
ConsoleLine * console_history_add_str(struct SpaceConsole *sc, char *str, bool own)
Definition: console_ops.c:204
#define SELECT
void * info_text_pick(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports, int mouse_y)
Definition: info_draw.c:223
void INFO_OT_select_all(wmOperatorType *ot)
Definition: info_report.c:223
void INFO_OT_report_copy(wmOperatorType *ot)
Definition: info_report.c:395
void INFO_OT_select_pick(wmOperatorType *ot)
Definition: info_report.c:186
static int box_select_exec(bContext *C, wmOperator *op)
Definition: info_report.c:239
void INFO_OT_report_replay(wmOperatorType *ot)
Definition: info_report.c:131
void INFO_OT_report_delete(wmOperatorType *ot)
Definition: info_report.c:351
static int report_select_all_exec(bContext *C, wmOperator *op)
Definition: info_report.c:209
static int report_replay_exec(bContext *C, wmOperator *UNUSED(op))
Definition: info_report.c:103
int info_report_mask(const SpaceInfo *UNUSED(sinfo))
Definition: info_report.c:75
static void reports_select_all(ReportList *reports, int report_mask, int action)
Definition: info_report.c:44
static int report_copy_exec(bContext *C, wmOperator *UNUSED(op))
Definition: info_report.c:368
static int select_report_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: info_report.c:172
void INFO_OT_select_box(wmOperatorType *ot)
Definition: info_report.c:302
static int select_report_pick_exec(bContext *C, wmOperator *op)
Definition: info_report.c:148
static int report_delete_exec(bContext *C, wmOperator *UNUSED(op))
Definition: info_report.c:325
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6319
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6308
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
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:3585
void * last
Definition: DNA_listBase.h:47
void * first
Definition: DNA_listBase.h:47
struct Report * next
struct Report * prev
const char * message
int ymin
Definition: DNA_vec_types.h:80
int ymax
Definition: DNA_vec_types.h:80
int mval[2]
Definition: WM_types.h:583
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
int(* modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:768
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
void(* cancel)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:760
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct PointerRNA * ptr
__forceinline const avxb select(const avxb &m, const avxb &t, const avxb &f)
Definition: util_avxb.h:167
int WM_operator_name_call(bContext *C, const char *opstring, short context, PointerRNA *properties)
wmOperatorType * ot
Definition: wm_files.c:3156
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:1778