Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * Contributor(s): Blender Foundation (2008). 00022 * 00023 * ***** END GPL LICENSE BLOCK ***** 00024 */ 00025 00026 #ifndef BKE_CONTEXT_H 00027 #define BKE_CONTEXT_H 00028 00033 #include "DNA_listBase.h" 00034 #include "RNA_types.h" 00035 00036 #ifdef __cplusplus 00037 extern "C" { 00038 #endif 00039 00040 struct ARegion; 00041 struct bScreen; 00042 struct EditMesh; 00043 struct ListBase; 00044 struct Main; 00045 struct Object; 00046 struct PointerRNA; 00047 struct ReportList; 00048 struct Scene; 00049 struct ScrArea; 00050 struct SpaceLink; 00051 struct View3D; 00052 struct RegionView3D; 00053 struct StructRNA; 00054 struct ToolSettings; 00055 struct Image; 00056 struct Text; 00057 struct ImBuf; 00058 struct EditBone; 00059 struct bPoseChannel; 00060 struct wmWindow; 00061 struct wmWindowManager; 00062 struct SpaceText; 00063 struct SpaceImage; 00064 struct SpaceClip; 00065 struct ID; 00066 00067 /* Structs */ 00068 00069 struct bContext; 00070 typedef struct bContext bContext; 00071 00072 struct bContextDataResult; 00073 typedef struct bContextDataResult bContextDataResult; 00074 00075 typedef int (*bContextDataCallback)(const bContext *C, 00076 const char *member, bContextDataResult *result); 00077 00078 typedef struct bContextStoreEntry { 00079 struct bContextStoreEntry *next, *prev; 00080 00081 char name[128]; 00082 PointerRNA ptr; 00083 } bContextStoreEntry; 00084 00085 typedef struct bContextStore { 00086 struct bContextStore *next, *prev; 00087 00088 ListBase entries; 00089 int used; 00090 } bContextStore; 00091 00092 /* for the conrtext's rna mode enum 00093 * keep aligned with data_mode_strings in context.c */ 00094 enum { 00095 CTX_MODE_EDIT_MESH = 0, 00096 CTX_MODE_EDIT_CURVE, 00097 CTX_MODE_EDIT_SURFACE, 00098 CTX_MODE_EDIT_TEXT, 00099 CTX_MODE_EDIT_ARMATURE, 00100 CTX_MODE_EDIT_METABALL, 00101 CTX_MODE_EDIT_LATTICE, 00102 CTX_MODE_POSE, 00103 CTX_MODE_SCULPT, 00104 CTX_MODE_PAINT_WEIGHT, 00105 CTX_MODE_PAINT_VERTEX, 00106 CTX_MODE_PAINT_TEXTURE, 00107 CTX_MODE_PARTICLE, 00108 CTX_MODE_OBJECT 00109 }; 00110 00111 /* Context */ 00112 00113 bContext *CTX_create(void); 00114 void CTX_free(bContext *C); 00115 00116 bContext *CTX_copy(const bContext *C); 00117 00118 /* Stored Context */ 00119 00120 bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *ptr); 00121 void CTX_store_set(bContext *C, bContextStore *store); 00122 bContextStore *CTX_store_copy(bContextStore *store); 00123 void CTX_store_free(bContextStore *store); 00124 void CTX_store_free_list(ListBase *contexts); 00125 00126 /* need to store if python is initialized or not */ 00127 int CTX_py_init_get(bContext *C); 00128 void CTX_py_init_set(bContext *C, int value); 00129 00130 void *CTX_py_dict_get(const bContext *C); 00131 void CTX_py_dict_set(bContext *C, void *value); 00132 00133 /* Window Manager Context */ 00134 00135 struct wmWindowManager *CTX_wm_manager(const bContext *C); 00136 struct wmWindow *CTX_wm_window(const bContext *C); 00137 struct bScreen *CTX_wm_screen(const bContext *C); 00138 struct ScrArea *CTX_wm_area(const bContext *C); 00139 struct SpaceLink *CTX_wm_space_data(const bContext *C); 00140 struct ARegion *CTX_wm_region(const bContext *C); 00141 void *CTX_wm_region_data(const bContext *C); 00142 struct ARegion *CTX_wm_menu(const bContext *C); 00143 struct ReportList *CTX_wm_reports(const bContext *C); 00144 00145 struct View3D *CTX_wm_view3d(const bContext *C); 00146 struct RegionView3D *CTX_wm_region_view3d(const bContext *C); 00147 struct SpaceText *CTX_wm_space_text(const bContext *C); 00148 struct SpaceImage *CTX_wm_space_image(const bContext *C); 00149 struct SpaceConsole *CTX_wm_space_console(const bContext *C); 00150 struct SpaceButs *CTX_wm_space_buts(const bContext *C); 00151 struct SpaceFile *CTX_wm_space_file(const bContext *C); 00152 struct SpaceSeq *CTX_wm_space_seq(const bContext *C); 00153 struct SpaceOops *CTX_wm_space_outliner(const bContext *C); 00154 struct SpaceNla *CTX_wm_space_nla(const bContext *C); 00155 struct SpaceTime *CTX_wm_space_time(const bContext *C); 00156 struct SpaceNode *CTX_wm_space_node(const bContext *C); 00157 struct SpaceLogic *CTX_wm_space_logic(const bContext *C); 00158 struct SpaceIpo *CTX_wm_space_graph(const bContext *C); 00159 struct SpaceAction *CTX_wm_space_action(const bContext *C); 00160 struct SpaceInfo *CTX_wm_space_info(const bContext *C); 00161 struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C); 00162 struct SpaceClip *CTX_wm_space_clip(const bContext *C); 00163 00164 void CTX_wm_manager_set(bContext *C, struct wmWindowManager *wm); 00165 void CTX_wm_window_set(bContext *C, struct wmWindow *win); 00166 void CTX_wm_screen_set(bContext *C, struct bScreen *screen); /* to be removed */ 00167 void CTX_wm_area_set(bContext *C, struct ScrArea *sa); 00168 void CTX_wm_region_set(bContext *C, struct ARegion *region); 00169 void CTX_wm_menu_set(bContext *C, struct ARegion *menu); 00170 const char *CTX_wm_operator_poll_msg_get(struct bContext *C); 00171 void CTX_wm_operator_poll_msg_set(struct bContext *C, const char *msg); 00172 00173 /* Data Context 00174 00175 - listbases consist of CollectionPointerLink items and must be 00176 freed with BLI_freelistN! 00177 - the dir listbase consits of LinkData items */ 00178 00179 /* data type, needed so we can tell between a NULL pointer and an empty list */ 00180 enum { 00181 CTX_DATA_TYPE_POINTER = 0, 00182 CTX_DATA_TYPE_COLLECTION 00183 }; 00184 00185 PointerRNA CTX_data_pointer_get(const bContext *C, const char *member); 00186 PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type); 00187 ListBase CTX_data_collection_get(const bContext *C, const char *member); 00188 ListBase CTX_data_dir_get(const bContext *C); 00189 int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb, short *r_type); 00190 00191 void CTX_data_id_pointer_set(bContextDataResult *result, struct ID *id); 00192 void CTX_data_pointer_set(bContextDataResult *result, struct ID *id, StructRNA *type, void *data); 00193 00194 void CTX_data_id_list_add(bContextDataResult *result, struct ID *id); 00195 void CTX_data_list_add(bContextDataResult *result, struct ID *id, StructRNA *type, void *data); 00196 00197 void CTX_data_dir_set(bContextDataResult *result, const char **member); 00198 00199 void CTX_data_type_set(struct bContextDataResult *result, short type); 00200 short CTX_data_type_get(struct bContextDataResult *result); 00201 00202 int CTX_data_equals(const char *member, const char *str); 00203 int CTX_data_dir(const char *member); 00204 00205 /*void CTX_data_pointer_set(bContextDataResult *result, void *data); 00206 void CTX_data_list_add(bContextDataResult *result, void *data);*/ 00207 00208 #define CTX_DATA_BEGIN(C, Type, instance, member) \ 00209 { \ 00210 ListBase ctx_data_list; \ 00211 CollectionPointerLink *ctx_link; \ 00212 CTX_data_##member(C, &ctx_data_list); \ 00213 for(ctx_link=ctx_data_list.first; ctx_link; ctx_link=ctx_link->next) {\ 00214 Type instance= ctx_link->ptr.data; 00215 00216 #define CTX_DATA_END \ 00217 } \ 00218 BLI_freelistN(&ctx_data_list); \ 00219 } 00220 00221 int ctx_data_list_count(const bContext *C, int (*func)(const bContext*, ListBase*)); 00222 00223 #define CTX_DATA_COUNT(C, member) \ 00224 ctx_data_list_count(C, CTX_data_##member) 00225 00226 /* Data Context Members */ 00227 00228 struct Main *CTX_data_main(const bContext *C); 00229 struct Scene *CTX_data_scene(const bContext *C); 00230 struct ToolSettings *CTX_data_tool_settings(const bContext *C); 00231 00232 const char *CTX_data_mode_string(const bContext *C); 00233 int CTX_data_mode_enum(const bContext *C); 00234 00235 void CTX_data_main_set(bContext *C, struct Main *bmain); 00236 void CTX_data_scene_set(bContext *C, struct Scene *bmain); 00237 00238 int CTX_data_selected_editable_objects(const bContext *C, ListBase *list); 00239 int CTX_data_selected_editable_bases(const bContext *C, ListBase *list); 00240 00241 int CTX_data_selected_objects(const bContext *C, ListBase *list); 00242 int CTX_data_selected_bases(const bContext *C, ListBase *list); 00243 00244 int CTX_data_visible_objects(const bContext *C, ListBase *list); 00245 int CTX_data_visible_bases(const bContext *C, ListBase *list); 00246 00247 int CTX_data_selectable_objects(const bContext *C, ListBase *list); 00248 int CTX_data_selectable_bases(const bContext *C, ListBase *list); 00249 00250 struct Object *CTX_data_active_object(const bContext *C); 00251 struct Base *CTX_data_active_base(const bContext *C); 00252 struct Object *CTX_data_edit_object(const bContext *C); 00253 00254 struct Image *CTX_data_edit_image(const bContext *C); 00255 00256 struct Text *CTX_data_edit_text(const bContext *C); 00257 struct MovieClip *CTX_data_edit_movieclip(const bContext *C); 00258 00259 int CTX_data_selected_nodes(const bContext *C, ListBase *list); 00260 00261 struct EditBone *CTX_data_active_bone(const bContext *C); 00262 int CTX_data_selected_bones(const bContext *C, ListBase *list); 00263 int CTX_data_selected_editable_bones(const bContext *C, ListBase *list); 00264 int CTX_data_visible_bones(const bContext *C, ListBase *list); 00265 int CTX_data_editable_bones(const bContext *C, ListBase *list); 00266 00267 struct bPoseChannel *CTX_data_active_pose_bone(const bContext *C); 00268 int CTX_data_selected_pose_bones(const bContext *C, ListBase *list); 00269 int CTX_data_visible_pose_bones(const bContext *C, ListBase *list); 00270 00271 #ifdef __cplusplus 00272 } 00273 #endif 00274 00275 #endif 00276