2.5/Sculpt:
[blender.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 #include "BKE_global.h"
37
38 #include "RNA_access.h"
39
40 #include "ED_object.h"
41
42 int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result)
43 {
44         bScreen *sc= CTX_wm_screen(C);
45         Scene *scene= sc->scene;
46         Base *base;
47
48         if(CTX_data_dir(member)) {
49                 static const char *dir[] = {
50                         "scene", "selected_objects", "selected_bases",
51                         "selected_editable_objects", "selected_editable_bases"
52                         "active_base", "active_object", "edit_object",
53                         "sculpt_object", "vertex_paint_object", "weight_paint_object",
54                         "texture_paint_object", "brush", "particle_edit_object", NULL};
55
56                 CTX_data_dir_set(result, dir);
57                 return 1;
58         }
59         else if(CTX_data_equals(member, "scene")) {
60                 CTX_data_id_pointer_set(result, &scene->id);
61                 return 1;
62         }
63         else if(CTX_data_equals(member, "selected_objects") || CTX_data_equals(member, "selected_bases")) {
64                 int selected_objects= CTX_data_equals(member, "selected_objects");
65
66                 for(base=scene->base.first; base; base=base->next) {
67                         if((base->flag & SELECT) && (base->lay & scene->lay)) {
68                                 if(selected_objects)
69                                         CTX_data_id_list_add(result, &base->object->id);
70                                 else
71                                         CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base);
72                         }
73                 }
74
75                 return 1;
76         }
77         else if(CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) {
78                 int selected_editable_objects= CTX_data_equals(member, "selected_editable_objects");
79
80                 for(base=scene->base.first; base; base=base->next) {
81                         if((base->flag & SELECT) && (base->lay & scene->lay)) {
82                                 if((base->object->restrictflag & OB_RESTRICT_VIEW)==0) {
83                                         if(0==object_is_libdata(base->object)) {
84                                                 if(selected_editable_objects)
85                                                         CTX_data_id_list_add(result, &base->object->id);
86                                                 else
87                                                         CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base);
88                                         }
89                                 }
90                         }
91                 }
92
93                 return 1;
94         }
95         else if(CTX_data_equals(member, "active_base")) {
96                 if(scene->basact)
97                         CTX_data_pointer_set(result, &scene->id, &RNA_UnknownType, scene->basact);
98
99                 return 1;
100         }
101         else if(CTX_data_equals(member, "active_object")) {
102                 if(scene->basact)
103                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
104
105                 return 1;
106         }
107         else if(CTX_data_equals(member, "edit_object")) {
108                 /* convenience for now, 1 object per scene in editmode */
109                 if(scene->obedit)
110                         CTX_data_id_pointer_set(result, &scene->obedit->id);
111                 
112                 return 1;
113         }
114         else if(CTX_data_equals(member, "sculpt_object")) {
115                 if(scene->basact && (scene->basact->object->mode & OB_MODE_SCULPT))
116                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
117
118                 return 1;
119         }
120         else if(CTX_data_equals(member, "vertex_paint_object")) {
121                 if(G.f & G_VERTEXPAINT && scene->basact)
122                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
123
124                 return 1;
125         }
126         else if(CTX_data_equals(member, "weight_paint_object")) {
127                 if(G.f & G_WEIGHTPAINT && scene->basact)
128                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
129
130                 return 1;
131         }
132         else if(CTX_data_equals(member, "texture_paint_object")) {
133                 if(G.f & G_TEXTUREPAINT && scene->basact)
134                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
135
136                 return 1;
137         }
138         else if(CTX_data_equals(member, "particle_edit_object")) {
139                 if(G.f & G_PARTICLEEDIT && scene->basact)
140                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
141
142                 return 1;
143         }
144
145         return 0;
146 }
147