operator macro playback (run operator reports in the console)
[blender-staging.git] / source / blender / editors / screen / screen_context.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include "DNA_object_types.h"
31 #include "DNA_scene_types.h"
32 #include "DNA_screen_types.h"
33
34 #include "BKE_context.h"
35 #include "BKE_utildefines.h"
36
37 #include "RNA_access.h"
38
39 int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result)
40 {
41         bScreen *sc= CTX_wm_screen(C);
42         Scene *scene= sc->scene;
43         Base *base;
44
45         if(CTX_data_dir(member)) {
46                 static const char *dir[] = {
47                         "scene", "selected_objects", "selected_bases",
48                         "selected_editable_objects", "selected_editable_bases"
49                         "active_base",
50                         "active_object", "edit_object", NULL};
51
52                 CTX_data_dir_set(result, dir);
53                 return 1;
54         }
55         else if(CTX_data_equals(member, "scene")) {
56                 CTX_data_id_pointer_set(result, &scene->id);
57                 return 1;
58         }
59         else if(CTX_data_equals(member, "selected_objects") || CTX_data_equals(member, "selected_bases")) {
60                 int selected_objects= CTX_data_equals(member, "selected_objects");
61
62                 for(base=scene->base.first; base; base=base->next) {
63                         if((base->flag & SELECT) && (base->lay & scene->lay)) {
64                                 if(selected_objects)
65                                         CTX_data_id_list_add(result, &base->object->id);
66                                 else
67                                         CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base);
68                         }
69                 }
70
71                 return 1;
72         }
73         else if(CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) {
74                 int selected_editable_objects= CTX_data_equals(member, "selected_editable_objects");
75
76                 for(base=scene->base.first; base; base=base->next) {
77                         if((base->flag & SELECT) && (base->lay & scene->lay)) {
78                                 if((base->object->restrictflag & OB_RESTRICT_VIEW)==0) {
79                                         if(0==object_is_libdata(base->object)) {
80                                                 if(selected_editable_objects)
81                                                         CTX_data_id_list_add(result, &base->object->id);
82                                                 else
83                                                         CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base);
84                                         }
85                                 }
86                         }
87                 }
88
89                 return 1;
90         }
91         else if(CTX_data_equals(member, "active_base")) {
92                 if(scene->basact)
93                         CTX_data_pointer_set(result, &scene->id, &RNA_UnknownType, &scene->basact);
94
95                 return 1;
96         }
97         else if(CTX_data_equals(member, "active_object")) {
98                 if(scene->basact)
99                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
100
101                 return 1;
102         }
103         else if(CTX_data_equals(member, "edit_object")) {
104                 /* convenience for now, 1 object per scene in editmode */
105                 if(scene->obedit)
106                         CTX_data_id_pointer_set(result, &scene->obedit->id);
107                 
108                 return 1;
109         }
110         
111         return 0;
112 }
113