|
Blender
V2.59
|
00001 /* 00002 * $Id: BKE_context.h 34962 2011-02-18 13:05:18Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * Contributor(s): Blender Foundation (2008). 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00028 #ifndef BKE_CONTEXT_H 00029 #define BKE_CONTEXT_H 00030 00035 #include "DNA_listBase.h" 00036 #include "RNA_types.h" 00037 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif 00041 00042 struct ARegion; 00043 struct bScreen; 00044 struct EditMesh; 00045 struct ListBase; 00046 struct Main; 00047 struct Object; 00048 struct PointerRNA; 00049 struct ReportList; 00050 struct Scene; 00051 struct ScrArea; 00052 struct SpaceLink; 00053 struct View3D; 00054 struct RegionView3D; 00055 struct StructRNA; 00056 struct ToolSettings; 00057 struct Image; 00058 struct Text; 00059 struct ImBuf; 00060 struct EditBone; 00061 struct bPoseChannel; 00062 struct wmWindow; 00063 struct wmWindowManager; 00064 struct SpaceText; 00065 struct SpaceImage; 00066 struct ID; 00067 00068 /* Structs */ 00069 00070 struct bContext; 00071 typedef struct bContext bContext; 00072 00073 struct bContextDataResult; 00074 typedef struct bContextDataResult bContextDataResult; 00075 00076 typedef int (*bContextDataCallback)(const bContext *C, 00077 const char *member, bContextDataResult *result); 00078 00079 typedef struct bContextStoreEntry { 00080 struct bContextStoreEntry *next, *prev; 00081 00082 char name[128]; 00083 PointerRNA ptr; 00084 } bContextStoreEntry; 00085 00086 typedef struct bContextStore { 00087 struct bContextStore *next, *prev; 00088 00089 ListBase entries; 00090 int used; 00091 } bContextStore; 00092 00093 /* for the conrtext's rna mode enum 00094 * keep aligned with data_mode_strings in context.c */ 00095 enum { 00096 CTX_MODE_EDIT_MESH = 0, 00097 CTX_MODE_EDIT_CURVE, 00098 CTX_MODE_EDIT_SURFACE, 00099 CTX_MODE_EDIT_TEXT, 00100 CTX_MODE_EDIT_ARMATURE, 00101 CTX_MODE_EDIT_METABALL, 00102 CTX_MODE_EDIT_LATTICE, 00103 CTX_MODE_POSE, 00104 CTX_MODE_SCULPT, 00105 CTX_MODE_PAINT_WEIGHT, 00106 CTX_MODE_PAINT_VERTEX, 00107 CTX_MODE_PAINT_TEXTURE, 00108 CTX_MODE_PARTICLE, 00109 CTX_MODE_OBJECT 00110 }; 00111 00112 /* Context */ 00113 00114 bContext *CTX_create(void); 00115 void CTX_free(bContext *C); 00116 00117 bContext *CTX_copy(const bContext *C); 00118 00119 /* Stored Context */ 00120 00121 bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *ptr); 00122 void CTX_store_set(bContext *C, bContextStore *store); 00123 bContextStore *CTX_store_copy(bContextStore *store); 00124 void CTX_store_free(bContextStore *store); 00125 void CTX_store_free_list(ListBase *contexts); 00126 00127 /* need to store if python is initialized or not */ 00128 int CTX_py_init_get(bContext *C); 00129 void CTX_py_init_set(bContext *C, int value); 00130 00131 void *CTX_py_dict_get(const bContext *C); 00132 void CTX_py_dict_set(bContext *C, void *value); 00133 00134 /* Window Manager Context */ 00135 00136 struct wmWindowManager *CTX_wm_manager(const bContext *C); 00137 struct wmWindow *CTX_wm_window(const bContext *C); 00138 struct bScreen *CTX_wm_screen(const bContext *C); 00139 struct ScrArea *CTX_wm_area(const bContext *C); 00140 struct SpaceLink *CTX_wm_space_data(const bContext *C); 00141 struct ARegion *CTX_wm_region(const bContext *C); 00142 void *CTX_wm_region_data(const bContext *C); 00143 struct ARegion *CTX_wm_menu(const bContext *C); 00144 struct ReportList *CTX_wm_reports(const bContext *C); 00145 00146 struct View3D *CTX_wm_view3d(const bContext *C); 00147 struct RegionView3D *CTX_wm_region_view3d(const bContext *C); 00148 struct SpaceText *CTX_wm_space_text(const bContext *C); 00149 struct SpaceImage *CTX_wm_space_image(const bContext *C); 00150 struct SpaceConsole *CTX_wm_space_console(const bContext *C); 00151 struct SpaceButs *CTX_wm_space_buts(const bContext *C); 00152 struct SpaceFile *CTX_wm_space_file(const bContext *C); 00153 struct SpaceSeq *CTX_wm_space_seq(const bContext *C); 00154 struct SpaceOops *CTX_wm_space_outliner(const bContext *C); 00155 struct SpaceNla *CTX_wm_space_nla(const bContext *C); 00156 struct SpaceTime *CTX_wm_space_time(const bContext *C); 00157 struct SpaceNode *CTX_wm_space_node(const bContext *C); 00158 struct SpaceLogic *CTX_wm_space_logic(const bContext *C); 00159 struct SpaceIpo *CTX_wm_space_graph(const bContext *C); 00160 struct SpaceAction *CTX_wm_space_action(const bContext *C); 00161 struct SpaceInfo *CTX_wm_space_info(const bContext *C); 00162 struct SpaceUserPref *CTX_wm_space_userpref(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 00258 int CTX_data_selected_nodes(const bContext *C, ListBase *list); 00259 00260 struct EditBone *CTX_data_active_bone(const bContext *C); 00261 int CTX_data_selected_bones(const bContext *C, ListBase *list); 00262 int CTX_data_selected_editable_bones(const bContext *C, ListBase *list); 00263 int CTX_data_visible_bones(const bContext *C, ListBase *list); 00264 int CTX_data_editable_bones(const bContext *C, ListBase *list); 00265 00266 struct bPoseChannel *CTX_data_active_pose_bone(const bContext *C); 00267 int CTX_data_selected_pose_bones(const bContext *C, ListBase *list); 00268 int CTX_data_visible_pose_bones(const bContext *C, ListBase *list); 00269 00270 #ifdef __cplusplus 00271 } 00272 #endif 00273 00274 #endif 00275