Blender  V2.93
screen_context.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  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 
28 #include "MEM_guardedalloc.h"
29 
30 #include "DNA_anim_types.h"
31 #include "DNA_armature_types.h"
32 #include "DNA_gpencil_types.h"
33 #include "DNA_object_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
36 #include "DNA_sequence_types.h"
37 #include "DNA_space_types.h"
39 
40 #include "BLI_ghash.h"
41 #include "BLI_listbase.h"
42 #include "BLI_utildefines.h"
43 
44 #include "BKE_action.h"
45 #include "BKE_armature.h"
46 #include "BKE_blender.h"
47 #include "BKE_context.h"
48 #include "BKE_gpencil.h"
49 #include "BKE_layer.h"
50 #include "BKE_object.h"
51 
52 #include "RNA_access.h"
53 
54 #include "ED_anim_api.h"
55 #include "ED_armature.h"
56 #include "ED_gpencil.h"
57 
58 #include "SEQ_sequencer.h"
59 
60 #include "UI_interface.h"
61 #include "WM_api.h"
62 
63 #include "screen_intern.h"
64 
65 const char *screen_context_dir[] = {
66  "scene",
67  "view_layer",
68  "visible_objects",
69  "selectable_objects",
70  "selected_objects",
71  "editable_objects",
72  "selected_editable_objects",
73  "objects_in_mode",
74  "objects_in_mode_unique_data",
75  "visible_bones",
76  "editable_bones",
77  "selected_bones",
78  "selected_editable_bones",
79  "visible_pose_bones",
80  "selected_pose_bones",
81  "selected_pose_bones_from_active_object",
82  "active_bone",
83  "active_pose_bone",
84  "active_object",
85  "object",
86  "edit_object",
87  "sculpt_object",
88  "vertex_paint_object",
89  "weight_paint_object",
90  "image_paint_object",
91  "particle_edit_object",
92  "pose_object",
93  "sequences",
94  "selected_sequences",
95  "selected_editable_sequences", /* sequencer */
96  "selected_nla_strips", /* nla editor */
97  "gpencil_data",
98  "gpencil_data_owner", /* grease pencil data */
99  "annotation_data",
100  "annotation_data_owner",
101  "visible_gpencil_layers",
102  "editable_gpencil_layers",
103  "editable_gpencil_strokes",
104  "active_gpencil_layer",
105  "active_gpencil_frame",
106  "active_annotation_layer",
107  "active_operator",
108  "visible_fcurves",
109  "editable_fcurves",
110  "selected_visible_fcurves",
111  "selected_editable_fcurves",
112  "active_editable_fcurve",
113  "selected_editable_keyframes",
114  NULL,
115 };
116 
117 /* Each function `screen_ctx_XXX()` will be called when the screen context "XXX" is requested.
118  * ensure_ed_screen_context_functions() is responsible for creating the hash map from context
119  * member name to function. */
120 
122 {
123  wmWindow *win = CTX_wm_window(C);
126  return CTX_RESULT_OK;
127 }
129 {
130  wmWindow *win = CTX_wm_window(C);
131  View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */
132  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
133 
134  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
135  if (BASE_VISIBLE(v3d, base)) {
136  CTX_data_id_list_add(result, &base->object->id);
137  }
138  }
140  return CTX_RESULT_OK;
141 }
143 {
144  wmWindow *win = CTX_wm_window(C);
145  View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */
146  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
147 
148  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
149  if (BASE_SELECTABLE(v3d, base)) {
150  CTX_data_id_list_add(result, &base->object->id);
151  }
152  }
154  return CTX_RESULT_OK;
155 }
157 {
158  wmWindow *win = CTX_wm_window(C);
159  View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */
160  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
161 
162  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
163  if (BASE_SELECTED(v3d, base)) {
164  CTX_data_id_list_add(result, &base->object->id);
165  }
166  }
168  return CTX_RESULT_OK;
169 }
172 {
173  wmWindow *win = CTX_wm_window(C);
174  View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */
175  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
176 
177  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
178  if (BASE_SELECTED_EDITABLE(v3d, base)) {
179  CTX_data_id_list_add(result, &base->object->id);
180  }
181  }
183  return CTX_RESULT_OK;
184 }
186 {
187  wmWindow *win = CTX_wm_window(C);
188  View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */
189  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
190 
191  /* Visible + Editable, but not necessarily selected */
192  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
193  if (BASE_EDITABLE(v3d, base)) {
194  CTX_data_id_list_add(result, &base->object->id);
195  }
196  }
198  return CTX_RESULT_OK;
199 }
201 {
202  wmWindow *win = CTX_wm_window(C);
203  View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */
204  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
205  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
206 
207  if (obact && (obact->mode != OB_MODE_OBJECT)) {
208  FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) {
209  CTX_data_id_list_add(result, &ob_iter->id);
210  }
212  }
214  return CTX_RESULT_OK;
215 }
218 {
219  wmWindow *win = CTX_wm_window(C);
220  View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */
221  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
222  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
223 
224  if (obact && (obact->mode != OB_MODE_OBJECT)) {
225  FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) {
226  ob_iter->id.tag |= LIB_TAG_DOIT;
227  }
229  FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) {
230  if (ob_iter->id.tag & LIB_TAG_DOIT) {
231  ob_iter->id.tag &= ~LIB_TAG_DOIT;
232  CTX_data_id_list_add(result, &ob_iter->id);
233  }
234  }
236  }
238  return CTX_RESULT_OK;
239 }
242  const bool editable_bones)
243 {
244  wmWindow *win = CTX_wm_window(C);
245  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
246  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
247 
248  bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL;
249  EditBone *flipbone = NULL;
250 
251  if (arm && arm->edbo) {
252  uint objects_len;
254  view_layer, CTX_wm_view3d(C), &objects_len);
255  for (uint i = 0; i < objects_len; i++) {
256  Object *ob = objects[i];
257  arm = ob->data;
258 
259  /* Attention: X-Axis Mirroring is also handled here... */
260  LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) {
261  /* first and foremost, bone must be visible and selected */
262  if (EBONE_VISIBLE(arm, ebone)) {
263  /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
264  * so that most users of this data don't need to explicitly check for it themselves.
265  *
266  * We need to make sure that these mirrored copies are not selected, otherwise some
267  * bones will be operated on twice.
268  */
269  if (arm->flag & ARM_MIRROR_EDIT) {
270  flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone);
271  }
272 
273  /* if we're filtering for editable too, use the check for that instead,
274  * as it has selection check too */
275  if (editable_bones) {
276  /* only selected + editable */
277  if (EBONE_EDITABLE(ebone)) {
278  CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
279 
280  if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) {
281  CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
282  }
283  }
284  }
285  else {
286  /* only include bones if visible */
287  CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
288 
289  if ((flipbone) && EBONE_VISIBLE(arm, flipbone) == 0) {
290  CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
291  }
292  }
293  }
294  }
295  }
296  MEM_freeN(objects);
297 
299  return CTX_RESULT_OK;
300  }
301  return CTX_RESULT_NO_DATA;
302 }
304 {
306 }
308 {
310 }
313  const bool selected_editable_bones)
314 {
315  wmWindow *win = CTX_wm_window(C);
316  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
317  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
318  bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL;
319  EditBone *flipbone = NULL;
320 
321  if (arm && arm->edbo) {
322  uint objects_len;
324  view_layer, CTX_wm_view3d(C), &objects_len);
325  for (uint i = 0; i < objects_len; i++) {
326  Object *ob = objects[i];
327  arm = ob->data;
328 
329  /* Attention: X-Axis Mirroring is also handled here... */
330  LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) {
331  /* first and foremost, bone must be visible and selected */
332  if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_SELECTED)) {
333  /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
334  * so that most users of this data don't need to explicitly check for it themselves.
335  *
336  * We need to make sure that these mirrored copies are not selected, otherwise some
337  * bones will be operated on twice.
338  */
339  if (arm->flag & ARM_MIRROR_EDIT) {
340  flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone);
341  }
342 
343  /* if we're filtering for editable too, use the check for that instead,
344  * as it has selection check too */
345  if (selected_editable_bones) {
346  /* only selected + editable */
347  if (EBONE_EDITABLE(ebone)) {
348  CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
349 
350  if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) {
351  CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
352  }
353  }
354  }
355  else {
356  /* only include bones if selected */
357  CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
358 
359  if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) {
360  CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
361  }
362  }
363  }
364  }
365  }
366  MEM_freeN(objects);
367 
369  return CTX_RESULT_OK;
370  }
371  return CTX_RESULT_NO_DATA;
372 }
374 {
375  return screen_ctx_selected_bones_(C, result, false);
376 }
379 {
380  return screen_ctx_selected_bones_(C, result, true);
381 }
383 {
384  wmWindow *win = CTX_wm_window(C);
385  View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */
386  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
387  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
388  Object *obpose = BKE_object_pose_armature_get(obact);
389  if (obpose && obpose->pose && obpose->data) {
390  if (obpose != obact) {
391  FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (obpose, pchan) {
392  CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
393  }
395  }
396  else if (obact->mode & OB_MODE_POSE) {
397  FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob_iter) {
398  FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (ob_iter, pchan) {
399  CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan);
400  }
402  }
404  }
406  return CTX_RESULT_OK;
407  }
408  return CTX_RESULT_NO_DATA;
409 }
411 {
412  wmWindow *win = CTX_wm_window(C);
413  View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */
414  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
415  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
416  Object *obpose = BKE_object_pose_armature_get(obact);
417  if (obpose && obpose->pose && obpose->data) {
418  if (obpose != obact) {
420  CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
421  }
423  }
424  else if (obact->mode & OB_MODE_POSE) {
425  FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob_iter) {
426  FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob_iter, pchan) {
427  CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan);
428  }
430  }
432  }
434  return CTX_RESULT_OK;
435  }
436  return CTX_RESULT_NO_DATA;
437 }
440 {
441  wmWindow *win = CTX_wm_window(C);
442  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
443  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
444  Object *obpose = BKE_object_pose_armature_get(obact);
445  if (obpose && obpose->pose && obpose->data) {
446  if (obpose != obact) {
448  CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
449  }
451  }
452  else if (obact->mode & OB_MODE_POSE) {
454  CTX_data_list_add(result, &obact->id, &RNA_PoseBone, pchan);
455  }
457  }
459  return CTX_RESULT_OK;
460  }
461  return CTX_RESULT_NO_DATA;
462 }
464 {
465  wmWindow *win = CTX_wm_window(C);
466  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
467  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
468  if (obact && obact->type == OB_ARMATURE) {
469  bArmature *arm = obact->data;
470  if (arm->edbo) {
471  if (arm->act_edbone) {
473  return CTX_RESULT_OK;
474  }
475  }
476  else {
477  if (arm->act_bone) {
479  return CTX_RESULT_OK;
480  }
481  }
482  }
483  return CTX_RESULT_NO_DATA;
484 }
486 {
487  wmWindow *win = CTX_wm_window(C);
488  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
489  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
490  Object *obpose = BKE_object_pose_armature_get(obact);
491 
492  bPoseChannel *pchan = BKE_pose_channel_active(obpose);
493  if (pchan) {
494  CTX_data_pointer_set(result, &obpose->id, &RNA_PoseBone, pchan);
495  return CTX_RESULT_OK;
496  }
497  return CTX_RESULT_NO_DATA;
498 }
500 {
501  wmWindow *win = CTX_wm_window(C);
502  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
503  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
504 
505  if (obact) {
507  }
508 
509  return CTX_RESULT_OK;
510 }
512 {
513  wmWindow *win = CTX_wm_window(C);
514  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
515  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
516 
517  if (obact) {
519  }
520 
521  return CTX_RESULT_OK;
522 }
524 {
525  wmWindow *win = CTX_wm_window(C);
526  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
527  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
528  /* convenience for now, 1 object per scene in editmode */
529  if (obedit) {
530  CTX_data_id_pointer_set(result, &obedit->id);
531  }
532 
533  return CTX_RESULT_OK;
534 }
536 {
537  wmWindow *win = CTX_wm_window(C);
538  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
539  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
540 
541  if (obact && (obact->mode & OB_MODE_SCULPT)) {
543  }
544 
545  return CTX_RESULT_OK;
546 }
548 {
549  wmWindow *win = CTX_wm_window(C);
550  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
551  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
552  if (obact && (obact->mode & OB_MODE_VERTEX_PAINT)) {
554  }
555 
556  return CTX_RESULT_OK;
557 }
559 {
560  wmWindow *win = CTX_wm_window(C);
561  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
562  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
563  if (obact && (obact->mode & OB_MODE_ALL_WEIGHT_PAINT)) {
565  }
566 
567  return CTX_RESULT_OK;
568 }
570 {
571  wmWindow *win = CTX_wm_window(C);
572  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
573  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
574  if (obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) {
576  }
577 
578  return CTX_RESULT_OK;
579 }
582 {
583  wmWindow *win = CTX_wm_window(C);
584  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
585  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
586  if (obact && (obact->mode & OB_MODE_PARTICLE_EDIT)) {
588  }
589 
590  return CTX_RESULT_OK;
591 }
593 {
594  wmWindow *win = CTX_wm_window(C);
595  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
596  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
597  Object *obpose = BKE_object_pose_armature_get(obact);
598  if (obpose) {
599  CTX_data_id_pointer_set(result, &obpose->id);
600  }
601  return CTX_RESULT_OK;
602 }
604 {
605  wmWindow *win = CTX_wm_window(C);
607  Editing *ed = SEQ_editing_get(scene, false);
608  if (ed) {
609  LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) {
611  }
613  return CTX_RESULT_OK;
614  }
615  return CTX_RESULT_NO_DATA;
616 }
618 {
619  wmWindow *win = CTX_wm_window(C);
621  Editing *ed = SEQ_editing_get(scene, false);
622  if (ed) {
623  LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) {
624  if (seq->flag & SELECT) {
626  }
627  }
629  return CTX_RESULT_OK;
630  }
631  return CTX_RESULT_NO_DATA;
632 }
635 {
636  wmWindow *win = CTX_wm_window(C);
638  Editing *ed = SEQ_editing_get(scene, false);
639  if (ed) {
640  LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) {
641  if (seq->flag & SELECT && !(seq->flag & SEQ_LOCK)) {
643  }
644  }
646  return CTX_RESULT_OK;
647  }
648  return CTX_RESULT_NO_DATA;
649 }
651 {
652  bAnimContext ac;
653  if (ANIM_animdata_get_context(C, &ac) != 0) {
654  ListBase anim_data = {NULL, NULL};
655 
656  ANIM_animdata_filter(&ac, &anim_data, ANIMFILTER_DATA_VISIBLE, ac.data, ac.datatype);
657  LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
658  if (ale->datatype != ALE_NLASTRIP) {
659  continue;
660  }
661  NlaTrack *nlt = (NlaTrack *)ale->data;
662  LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) {
663  if (strip->flag & NLASTRIP_FLAG_SELECT) {
664  CTX_data_list_add(result, ale->id, &RNA_NlaStrip, strip);
665  }
666  }
667  }
668  ANIM_animdata_freelist(&anim_data);
669 
671  return CTX_RESULT_OK;
672  }
673  return CTX_RESULT_NO_DATA;
674 }
676 {
677  wmWindow *win = CTX_wm_window(C);
679  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
680  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
681  /* FIXME: for some reason, CTX_data_active_object(C) returns NULL when called from these
682  * situations (as outlined above - see Campbell's #ifdefs).
683  * That causes the get_active function to fail when called from context.
684  * For that reason, we end up using an alternative where we pass everything in!
685  */
687 
688  if (gpd) {
690  return CTX_RESULT_OK;
691  }
692  return CTX_RESULT_NO_DATA;
693 }
695 {
696  wmWindow *win = CTX_wm_window(C);
698  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
699  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
700 
701  /* Pointer to which data/datablock owns the reference to the Grease Pencil data being used
702  * (as gpencil_data). */
703  PointerRNA ptr;
704  bGPdata **gpd_ptr = ED_gpencil_data_get_pointers_direct(area, obact, &ptr);
705 
706  if (gpd_ptr) {
708  return CTX_RESULT_OK;
709  }
710  return CTX_RESULT_NO_DATA;
711 }
713 {
714  wmWindow *win = CTX_wm_window(C);
715  bScreen *screen = CTX_wm_screen(C);
719 
720  if (gpd) {
722  return CTX_RESULT_OK;
723  }
724  return CTX_RESULT_NO_DATA;
725 }
728 {
729  wmWindow *win = CTX_wm_window(C);
730  bScreen *screen = CTX_wm_screen(C);
733 
734  /* Pointer to which data/datablock owns the reference to the Grease Pencil data being used. */
735  PointerRNA ptr;
736  bGPdata **gpd_ptr = ED_annotation_data_get_pointers_direct((ID *)screen, area, scene, &ptr);
737 
738  if (gpd_ptr) {
740  return CTX_RESULT_OK;
741  }
742  return CTX_RESULT_NO_DATA;
743 }
746 {
747  wmWindow *win = CTX_wm_window(C);
749  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
750  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
752 
753  if (gpd) {
755 
756  if (gpl) {
758  return CTX_RESULT_OK;
759  }
760  }
761  return CTX_RESULT_NO_DATA;
762 }
765 {
766  wmWindow *win = CTX_wm_window(C);
767  bScreen *screen = CTX_wm_screen(C);
771 
772  if (gpd) {
774 
775  if (gpl) {
777  return CTX_RESULT_OK;
778  }
779  }
780  return CTX_RESULT_NO_DATA;
781 }
784 {
785  wmWindow *win = CTX_wm_window(C);
787  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
788  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
790 
791  if (gpd) {
793 
794  if (gpl) {
796  return CTX_RESULT_OK;
797  }
798  }
799  return CTX_RESULT_NO_DATA;
800 }
803 {
804  wmWindow *win = CTX_wm_window(C);
806  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
807  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
809 
810  if (gpd) {
811  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
812  if ((gpl->flag & GP_LAYER_HIDE) == 0) {
814  }
815  }
817  return CTX_RESULT_OK;
818  }
819  return CTX_RESULT_NO_DATA;
820 }
823 {
824  wmWindow *win = CTX_wm_window(C);
826  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
827  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
829 
830  if (gpd) {
831  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
834  }
835  }
837  return CTX_RESULT_OK;
838  }
839  return CTX_RESULT_NO_DATA;
840 }
843 {
844  wmWindow *win = CTX_wm_window(C);
846  ViewLayer *view_layer = WM_window_get_active_view_layer(win);
847  Object *obact = view_layer->basact ? view_layer->basact->object : NULL;
848 
850  const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
851 
852  if (gpd == NULL) {
853  return CTX_RESULT_NO_DATA;
854  }
855 
856  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
857  if (BKE_gpencil_layer_is_editable(gpl) && (gpl->actframe)) {
858  bGPDframe *gpf;
859  bGPDframe *init_gpf = gpl->actframe;
860  if (is_multiedit) {
861  init_gpf = gpl->frames.first;
862  }
863 
864  for (gpf = init_gpf; gpf; gpf = gpf->next) {
865  if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
866  LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
868  /* check if the color is editable */
869  if (ED_gpencil_stroke_material_editable(obact, gpl, gps) == false) {
870  continue;
871  }
872 
874  }
875  }
876  }
877  /* if not multiedit out of loop */
878  if (!is_multiedit) {
879  break;
880  }
881  }
882  }
883  }
885  return CTX_RESULT_OK;
886 }
888 {
889  wmOperator *op = NULL;
890 
891  SpaceFile *sfile = CTX_wm_space_file(C);
892  if (sfile) {
893  op = sfile->op;
894  }
895  else if ((op = UI_context_active_operator_get(C))) {
896  /* do nothing */
897  }
898  else {
899  /* note, this checks poll, could be a problem, but this also
900  * happens for the toolbar */
901  op = WM_operator_last_redo(C);
902  }
903  /* TODO, get the operator from popup's */
904 
905  if (op && op->ptr) {
907  return CTX_RESULT_OK;
908  }
909  return CTX_RESULT_NO_DATA;
910 }
913  const int extra_filter)
914 {
915  bAnimContext ac;
917  ListBase anim_data = {NULL, NULL};
918 
922  extra_filter;
923 
924  ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
925 
926  LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
927  if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) {
928  CTX_data_list_add(result, ale->fcurve_owner_id, &RNA_FCurve, ale->data);
929  }
930  }
931 
932  ANIM_animdata_freelist(&anim_data);
933 
935  return CTX_RESULT_OK;
936  }
937  return CTX_RESULT_NO_DATA;
938 }
940 {
942 }
944 {
946 }
949 {
951 }
954 {
956 }
959 {
960  bAnimContext ac;
962  ListBase anim_data = {NULL, NULL};
963 
966 
967  ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
968 
969  LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
970  if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) {
971  CTX_data_pointer_set(result, ale->fcurve_owner_id, &RNA_FCurve, ale->data);
972  break;
973  }
974  }
975 
976  ANIM_animdata_freelist(&anim_data);
977  return CTX_RESULT_OK;
978  }
979  return CTX_RESULT_NO_DATA;
980 }
983 {
984  bAnimContext ac;
986  ListBase anim_data = {NULL, NULL};
987 
988  /* Use keyframes from editable selected FCurves. */
990  ANIMFILTER_SEL) |
993 
994  ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
995 
996  int i;
997  FCurve *fcurve;
998  BezTriple *bezt;
999  LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
1000  if (!ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) {
1001  continue;
1002  }
1003 
1004  fcurve = (FCurve *)ale->data;
1005  if (fcurve->bezt == NULL) {
1006  /* Skip baked FCurves. */
1007  continue;
1008  }
1009 
1010  for (i = 0, bezt = fcurve->bezt; i < fcurve->totvert; i++, bezt++) {
1011  if ((bezt->f2 & SELECT) == 0) {
1012  continue;
1013  }
1014 
1015  CTX_data_list_add(result, ale->fcurve_owner_id, &RNA_Keyframe, bezt);
1016  }
1017  }
1018 
1019  ANIM_animdata_freelist(&anim_data);
1020 
1022  return CTX_RESULT_OK;
1023  }
1024  return CTX_RESULT_NO_DATA;
1025 }
1026 
1027 /* Registry of context callback functions. */
1028 
1031 
1033 {
1035 }
1036 static inline void register_context_function(const char *member, context_callback function)
1037 {
1038  BLI_ghash_insert(ed_screen_context_functions, (void *)member, function);
1039 }
1040 
1042 {
1044  return;
1045  }
1046 
1047  /* Murmur hash is faster for smaller strings (according to BLI_hash_mm2). */
1050 
1052 
1060  register_context_function("objects_in_mode_unique_data", screen_ctx_objects_in_mode_unique_data);
1067  register_context_function("selected_pose_bones_from_active_object",
1082  register_context_function("selected_editable_sequences", screen_ctx_selected_editable_sequences);
1100  register_context_function("selected_editable_keyframes", screen_ctx_selected_editable_keyframes);
1101 }
1102 
1103 /* Entry point for the screen context. */
1104 int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result)
1105 {
1106  if (CTX_data_dir(member)) {
1108  return CTX_RESULT_OK;
1109  }
1110 
1113  if (callback == NULL) {
1115  }
1116 
1117  return callback(C, result);
1118 }
Blender kernel action and pose functionality.
struct bPoseChannel * BKE_pose_channel_active(struct Object *ob)
Definition: action.c:708
#define FOREACH_PCHAN_SELECTED_IN_OBJECT_END
Definition: BKE_armature.h:353
#define FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN(_ob, _pchan)
Definition: BKE_armature.h:358
#define FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN(_ob, _pchan)
Definition: BKE_armature.h:349
#define FOREACH_PCHAN_VISIBLE_IN_OBJECT_END
Definition: BKE_armature.h:361
Blender util stuff.
void BKE_blender_atexit_register(void(*func)(void *user_data), void *user_data)
Definition: blender.c:400
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
void CTX_data_dir_set(bContextDataResult *result, const char **dir)
Definition: context.c:672
void CTX_data_pointer_set(bContextDataResult *result, struct ID *id, StructRNA *type, void *data)
Definition: context.c:638
void CTX_data_id_pointer_set(bContextDataResult *result, struct ID *id)
Definition: context.c:633
bool CTX_data_dir(const char *member)
Definition: context.c:628
void CTX_data_id_list_add(bContextDataResult *result, struct ID *id)
Definition: context.c:643
@ CTX_DATA_TYPE_COLLECTION
Definition: BKE_context.h:221
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:760
eContextResult
Definition: BKE_context.h:81
@ CTX_RESULT_MEMBER_NOT_FOUND
Definition: BKE_context.h:86
@ CTX_RESULT_OK
Definition: BKE_context.h:83
@ CTX_RESULT_NO_DATA
Definition: BKE_context.h:90
void CTX_data_list_add(bContextDataResult *result, struct ID *id, StructRNA *type, void *data)
Definition: context.c:651
struct bScreen * CTX_wm_screen(const bContext *C)
Definition: context.c:709
void CTX_data_type_set(struct bContextDataResult *result, short type)
Definition: context.c:677
struct SpaceFile * CTX_wm_space_file(const bContext *C)
Definition: context.c:818
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:699
struct bGPDlayer * BKE_gpencil_layer_active_get(struct bGPdata *gpd)
Definition: gpencil.c:1650
bool BKE_gpencil_layer_is_editable(const struct bGPDlayer *gpl)
#define BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, v3d, r_len)
Definition: BKE_layer.h:426
#define FOREACH_OBJECT_IN_MODE_END
Definition: BKE_layer.h:284
#define FOREACH_OBJECT_IN_MODE_BEGIN(_view_layer, _v3d, _object_type, _object_mode, _instance)
Definition: BKE_layer.h:280
General operations, lookup, etc. for blender objects.
struct Object * BKE_object_pose_armature_get(struct Object *ob)
Definition: object.c:2487
bool BLI_ghashutil_strcmp(const void *a, const void *b)
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:718
unsigned int BLI_ghashutil_strhash_p_murmur(const void *ptr)
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:756
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:1008
void * BLI_ghash_lookup(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:803
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
unsigned int uint
Definition: BLI_sys_types.h:83
#define UNUSED(x)
#define ELEM(...)
@ LIB_TAG_DOIT
Definition: DNA_ID.h:554
@ NLASTRIP_FLAG_SELECT
@ BONE_SELECTED
@ ARM_MIRROR_EDIT
#define GPENCIL_MULTIEDIT_SESSIONS_ON(gpd)
@ GP_LAYER_HIDE
@ GP_FRAME_SELECT
@ BASE_SELECTABLE
@ BASE_SELECTED
#define OB_MODE_ALL_WEIGHT_PAINT
@ OB_MODE_PARTICLE_EDIT
@ OB_MODE_SCULPT
@ OB_MODE_POSE
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_OBJECT
@ OB_MODE_VERTEX_PAINT
Object is a sort of wrapper for general info.
@ OB_ARMATURE
#define OBEDIT_FROM_VIEW_LAYER(view_layer)
#define BASE_SELECTED_EDITABLE(v3d, base)
#define BASE_EDITABLE(v3d, base)
#define BASE_VISIBLE(v3d, base)
@ SEQ_LOCK
@ SPACE_ACTION
@ SPACE_GRAPH
@ ANIMTYPE_NLACURVE
Definition: ED_anim_api.h:210
@ ANIMTYPE_FCURVE
Definition: ED_anim_api.h:207
@ ALE_NLASTRIP
Definition: ED_anim_api.h:261
@ ANIMFILTER_ACTIVE
Definition: ED_anim_api.h:306
@ ANIMFILTER_FOREDIT
Definition: ED_anim_api.h:315
@ ANIMFILTER_DATA_VISIBLE
Definition: ED_anim_api.h:295
@ ANIMFILTER_CURVE_VISIBLE
Definition: ED_anim_api.h:300
@ ANIMFILTER_LIST_VISIBLE
Definition: ED_anim_api.h:298
@ ANIMFILTER_NODUPLIS
Definition: ED_anim_api.h:328
@ ANIMFILTER_SEL
Definition: ED_anim_api.h:311
#define EBONE_VISIBLE(arm, ebone)
Definition: ED_armature.h:56
#define EBONE_EDITABLE(ebone)
Definition: ED_armature.h:64
Read Guarded memory(de)allocation.
StructRNA RNA_Bone
StructRNA RNA_GPencilStroke
StructRNA RNA_EditBone
StructRNA RNA_FCurve
StructRNA RNA_Keyframe
StructRNA RNA_PoseBone
StructRNA RNA_GPencilLayer
StructRNA RNA_Sequence
StructRNA RNA_Operator
StructRNA RNA_NlaStrip
#define C
Definition: RandGen.cpp:39
struct wmOperator * UI_context_active_operator_get(const struct bContext *C)
void ANIM_animdata_freelist(ListBase *anim_data)
Definition: anim_deps.c:425
bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
Definition: anim_filter.c:405
size_t ANIM_animdata_filter(bAnimContext *ac, ListBase *anim_data, eAnimFilter_Flags filter_mode, void *data, eAnimCont_Types datatype)
Definition: anim_filter.c:3442
EditBone * ED_armature_ebone_get_mirrored(const ListBase *edbo, EditBone *ebo)
#define SELECT
Scene scene
void * user_data
DEGForeachIDComponentCallback callback
bool ED_gpencil_stroke_material_editable(Object *ob, const bGPDlayer *gpl, const bGPDstroke *gps)
bool ED_gpencil_stroke_can_use_direct(const ScrArea *area, const bGPDstroke *gps)
bGPdata * ED_gpencil_data_get_active_direct(ScrArea *area, Object *ob)
bGPdata ** ED_annotation_data_get_pointers_direct(ID *screen_id, ScrArea *area, Scene *scene, PointerRNA *r_ptr)
bGPdata ** ED_gpencil_data_get_pointers_direct(ScrArea *area, Object *ob, PointerRNA *r_ptr)
bGPdata * ED_annotation_data_get_active_direct(ID *screen_id, ScrArea *area, Scene *scene)
DO_INLINE void filter(lfVector *V, fmatrix3x3 *S)
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
static void area(int d1, int d2, int e1, int e2, float weights[2])
static eContextResult screen_ctx_selected_pose_bones(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_objects_in_mode_unique_data(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_selected_editable_objects(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_active_operator(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_sel_edit_fcurves_(const bContext *C, bContextDataResult *result, const int extra_filter)
const char * screen_context_dir[]
static eContextResult screen_ctx_selected_objects(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_selected_bones(const bContext *C, bContextDataResult *result)
eContextResult(* context_callback)(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_selected_editable_sequences(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_selected_nla_strips(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_editable_objects(const bContext *C, bContextDataResult *result)
static GHash * ed_screen_context_functions
static eContextResult screen_ctx_selected_sequences(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_visible_gpencil_layers(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_active_annotation_layer(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_visible_pose_bones(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_pose_object(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_active_gpencil_layer(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_selected_visible_fcurves(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_gpencil_data_owner(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_annotation_data(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_edit_object(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_active_bone(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_objects_in_mode(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_selectable_objects(const bContext *C, bContextDataResult *result)
static void register_context_function(const char *member, context_callback function)
static eContextResult screen_ctx_editable_gpencil_layers(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_annotation_data_owner(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_editable_gpencil_strokes(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_visible_fcurves(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_editable_fcurves(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_active_object(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_particle_edit_object(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_selected_editable_bones(const bContext *C, bContextDataResult *result)
int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result)
static eContextResult screen_ctx_visible_objects(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_editable_bones(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_selected_editable_keyframes(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_selected_editable_fcurves(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_object(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_active_editable_fcurve(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_selected_bones_(const bContext *C, bContextDataResult *result, const bool selected_editable_bones)
static eContextResult screen_ctx_gpencil_data(const bContext *C, bContextDataResult *result)
static void free_context_function_ghash(void *UNUSED(user_data))
static eContextResult screen_ctx_selected_pose_bones_from_active_object(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_visible_bones(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_sequences(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_vertex_paint_object(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_active_pose_bone(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_sculpt_object(const bContext *C, bContextDataResult *result)
static void ensure_ed_screen_context_functions(void)
static eContextResult screen_ctx_visible_or_editable_bones_(const bContext *C, bContextDataResult *result, const bool editable_bones)
static eContextResult screen_ctx_active_gpencil_frame(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_image_paint_object(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_scene(const bContext *C, bContextDataResult *result)
static eContextResult screen_ctx_weight_paint_object(const bContext *C, bContextDataResult *result)
Editing * SEQ_editing_get(Scene *scene, bool alloc)
Definition: sequencer.c:232
struct Object * object
ListBase * seqbasep
BezTriple * bezt
Definition: DNA_ID.h:273
ListBase strips
struct bPose * pose
void * data
struct StructRNA * type
Definition: RNA_types.h:51
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
struct wmOperator * op
struct Base * basact
ListBase object_bases
short spacetype
Definition: ED_anim_api.h:80
short datatype
Definition: ED_anim_api.h:75
void * data
Definition: ED_anim_api.h:73
struct EditBone * act_edbone
ListBase * edbo
struct bGPDframe * next
ListBase strokes
bGPDframe * actframe
ListBase layers
struct PointerRNA * ptr
PointerRNA * ptr
Definition: wm_files.c:3157
wmOperator * WM_operator_last_redo(const bContext *C)
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
Definition: wm_window.c:2286
Scene * WM_window_get_active_scene(const wmWindow *win)
Definition: wm_window.c:2249