BKE_context.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  19. * All rights reserved.
  20. *
  21. * Contributor(s): Blender Foundation (2008).
  22. *
  23. * ***** END GPL LICENSE BLOCK *****
  24. */
  25. #ifndef __BKE_CONTEXT_H__
  26. #define __BKE_CONTEXT_H__
  27. /** \file BKE_context.h
  28. * \ingroup bke
  29. */
  30. #include "DNA_listBase.h"
  31. #include "RNA_types.h"
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. struct ARegion;
  36. struct bScreen;
  37. struct CacheFile;
  38. struct ListBase;
  39. struct Main;
  40. struct Object;
  41. struct PointerRNA;
  42. struct ReportList;
  43. struct Scene;
  44. struct ScrArea;
  45. struct SpaceLink;
  46. struct View3D;
  47. struct RegionView3D;
  48. struct StructRNA;
  49. struct ToolSettings;
  50. struct Image;
  51. struct Text;
  52. struct EditBone;
  53. struct bPoseChannel;
  54. struct bGPdata;
  55. struct bGPDlayer;
  56. struct bGPDframe;
  57. struct bGPDpalette;
  58. struct bGPDpalettecolor;
  59. struct bGPDbrush;
  60. struct wmWindow;
  61. struct wmWindowManager;
  62. struct SpaceText;
  63. struct SpaceImage;
  64. struct SpaceClip;
  65. struct ID;
  66. /* Structs */
  67. struct bContext;
  68. typedef struct bContext bContext;
  69. struct bContextDataResult;
  70. typedef struct bContextDataResult bContextDataResult;
  71. typedef int (*bContextDataCallback)(const bContext *C,
  72. const char *member, bContextDataResult *result);
  73. typedef struct bContextStoreEntry {
  74. struct bContextStoreEntry *next, *prev;
  75. char name[128];
  76. PointerRNA ptr;
  77. } bContextStoreEntry;
  78. typedef struct bContextStore {
  79. struct bContextStore *next, *prev;
  80. ListBase entries;
  81. bool used;
  82. } bContextStore;
  83. /* for the context's rna mode enum
  84. * keep aligned with data_mode_strings in context.c */
  85. enum {
  86. CTX_MODE_EDIT_MESH = 0,
  87. CTX_MODE_EDIT_CURVE,
  88. CTX_MODE_EDIT_SURFACE,
  89. CTX_MODE_EDIT_TEXT,
  90. CTX_MODE_EDIT_ARMATURE,
  91. CTX_MODE_EDIT_METABALL,
  92. CTX_MODE_EDIT_LATTICE,
  93. CTX_MODE_POSE,
  94. CTX_MODE_SCULPT,
  95. CTX_MODE_PAINT_WEIGHT,
  96. CTX_MODE_PAINT_VERTEX,
  97. CTX_MODE_PAINT_TEXTURE,
  98. CTX_MODE_PARTICLE,
  99. CTX_MODE_OBJECT
  100. };
  101. /* Context */
  102. bContext *CTX_create(void);
  103. void CTX_free(bContext *C);
  104. bContext *CTX_copy(const bContext *C);
  105. /* Stored Context */
  106. bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *ptr);
  107. bContextStore *CTX_store_add_all(ListBase *contexts, bContextStore *context);
  108. void CTX_store_set(bContext *C, bContextStore *store);
  109. bContextStore *CTX_store_copy(bContextStore *store);
  110. void CTX_store_free(bContextStore *store);
  111. void CTX_store_free_list(ListBase *contexts);
  112. /* need to store if python is initialized or not */
  113. int CTX_py_init_get(bContext *C);
  114. void CTX_py_init_set(bContext *C, int value);
  115. void *CTX_py_dict_get(const bContext *C);
  116. void CTX_py_dict_set(bContext *C, void *value);
  117. /* Window Manager Context */
  118. struct wmWindowManager *CTX_wm_manager(const bContext *C);
  119. struct wmWindow *CTX_wm_window(const bContext *C);
  120. struct bScreen *CTX_wm_screen(const bContext *C);
  121. struct ScrArea *CTX_wm_area(const bContext *C);
  122. struct SpaceLink *CTX_wm_space_data(const bContext *C);
  123. struct ARegion *CTX_wm_region(const bContext *C);
  124. void *CTX_wm_region_data(const bContext *C);
  125. struct ARegion *CTX_wm_menu(const bContext *C);
  126. struct ReportList *CTX_wm_reports(const bContext *C);
  127. struct View3D *CTX_wm_view3d(const bContext *C);
  128. struct RegionView3D *CTX_wm_region_view3d(const bContext *C);
  129. struct SpaceText *CTX_wm_space_text(const bContext *C);
  130. struct SpaceImage *CTX_wm_space_image(const bContext *C);
  131. struct SpaceConsole *CTX_wm_space_console(const bContext *C);
  132. struct SpaceButs *CTX_wm_space_buts(const bContext *C);
  133. struct SpaceFile *CTX_wm_space_file(const bContext *C);
  134. struct SpaceSeq *CTX_wm_space_seq(const bContext *C);
  135. struct SpaceOops *CTX_wm_space_outliner(const bContext *C);
  136. struct SpaceNla *CTX_wm_space_nla(const bContext *C);
  137. struct SpaceTime *CTX_wm_space_time(const bContext *C);
  138. struct SpaceNode *CTX_wm_space_node(const bContext *C);
  139. struct SpaceLogic *CTX_wm_space_logic(const bContext *C);
  140. struct SpaceIpo *CTX_wm_space_graph(const bContext *C);
  141. struct SpaceAction *CTX_wm_space_action(const bContext *C);
  142. struct SpaceInfo *CTX_wm_space_info(const bContext *C);
  143. struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C);
  144. struct SpaceClip *CTX_wm_space_clip(const bContext *C);
  145. void CTX_wm_manager_set(bContext *C, struct wmWindowManager *wm);
  146. void CTX_wm_window_set(bContext *C, struct wmWindow *win);
  147. void CTX_wm_screen_set(bContext *C, struct bScreen *screen); /* to be removed */
  148. void CTX_wm_area_set(bContext *C, struct ScrArea *sa);
  149. void CTX_wm_region_set(bContext *C, struct ARegion *region);
  150. void CTX_wm_menu_set(bContext *C, struct ARegion *menu);
  151. const char *CTX_wm_operator_poll_msg_get(struct bContext *C);
  152. void CTX_wm_operator_poll_msg_set(struct bContext *C, const char *msg);
  153. /* Data Context
  154. *
  155. * - listbases consist of CollectionPointerLink items and must be
  156. * freed with BLI_freelistN!
  157. * - the dir listbase consists of LinkData items */
  158. /* data type, needed so we can tell between a NULL pointer and an empty list */
  159. enum {
  160. CTX_DATA_TYPE_POINTER = 0,
  161. CTX_DATA_TYPE_COLLECTION
  162. };
  163. PointerRNA CTX_data_pointer_get(const bContext *C, const char *member);
  164. PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type);
  165. ListBase CTX_data_collection_get(const bContext *C, const char *member);
  166. ListBase CTX_data_dir_get_ex(const bContext *C, const bool use_store, const bool use_rna, const bool use_all);
  167. ListBase CTX_data_dir_get(const bContext *C);
  168. int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb, short *r_type);
  169. void CTX_data_id_pointer_set(bContextDataResult *result, struct ID *id);
  170. void CTX_data_pointer_set(bContextDataResult *result, struct ID *id, StructRNA *type, void *data);
  171. void CTX_data_id_list_add(bContextDataResult *result, struct ID *id);
  172. void CTX_data_list_add(bContextDataResult *result, struct ID *id, StructRNA *type, void *data);
  173. void CTX_data_dir_set(bContextDataResult *result, const char **member);
  174. void CTX_data_type_set(struct bContextDataResult *result, short type);
  175. short CTX_data_type_get(struct bContextDataResult *result);
  176. bool CTX_data_equals(const char *member, const char *str);
  177. bool CTX_data_dir(const char *member);
  178. #if 0
  179. void CTX_data_pointer_set(bContextDataResult *result, void *data);
  180. void CTX_data_list_add(bContextDataResult *result, void *data);
  181. #endif
  182. #define CTX_DATA_BEGIN(C, Type, instance, member) \
  183. { \
  184. ListBase ctx_data_list; \
  185. CollectionPointerLink *ctx_link; \
  186. CTX_data_##member(C, &ctx_data_list); \
  187. for (ctx_link = ctx_data_list.first; \
  188. ctx_link; \
  189. ctx_link = ctx_link->next) \
  190. { \
  191. Type instance = ctx_link->ptr.data;
  192. #define CTX_DATA_END \
  193. } \
  194. BLI_freelistN(&ctx_data_list); \
  195. } (void)0
  196. int ctx_data_list_count(const bContext *C, int (*func)(const bContext *, ListBase *));
  197. #define CTX_DATA_COUNT(C, member) \
  198. ctx_data_list_count(C, CTX_data_##member)
  199. /* Data Context Members */
  200. struct Main *CTX_data_main(const bContext *C);
  201. struct Scene *CTX_data_scene(const bContext *C);
  202. struct ToolSettings *CTX_data_tool_settings(const bContext *C);
  203. const char *CTX_data_mode_string(const bContext *C);
  204. int CTX_data_mode_enum(const bContext *C);
  205. void CTX_data_main_set(bContext *C, struct Main *bmain);
  206. void CTX_data_scene_set(bContext *C, struct Scene *bmain);
  207. int CTX_data_selected_editable_objects(const bContext *C, ListBase *list);
  208. int CTX_data_selected_editable_bases(const bContext *C, ListBase *list);
  209. int CTX_data_editable_objects(const bContext *C, ListBase *list);
  210. int CTX_data_editable_bases(const bContext *C, ListBase *list);
  211. int CTX_data_selected_objects(const bContext *C, ListBase *list);
  212. int CTX_data_selected_bases(const bContext *C, ListBase *list);
  213. int CTX_data_visible_objects(const bContext *C, ListBase *list);
  214. int CTX_data_visible_bases(const bContext *C, ListBase *list);
  215. int CTX_data_selectable_objects(const bContext *C, ListBase *list);
  216. int CTX_data_selectable_bases(const bContext *C, ListBase *list);
  217. struct Object *CTX_data_active_object(const bContext *C);
  218. struct Base *CTX_data_active_base(const bContext *C);
  219. struct Object *CTX_data_edit_object(const bContext *C);
  220. struct Image *CTX_data_edit_image(const bContext *C);
  221. struct Text *CTX_data_edit_text(const bContext *C);
  222. struct MovieClip *CTX_data_edit_movieclip(const bContext *C);
  223. struct Mask *CTX_data_edit_mask(const bContext *C);
  224. struct CacheFile *CTX_data_edit_cachefile(const bContext *C);
  225. int CTX_data_selected_nodes(const bContext *C, ListBase *list);
  226. struct EditBone *CTX_data_active_bone(const bContext *C);
  227. int CTX_data_selected_bones(const bContext *C, ListBase *list);
  228. int CTX_data_selected_editable_bones(const bContext *C, ListBase *list);
  229. int CTX_data_visible_bones(const bContext *C, ListBase *list);
  230. int CTX_data_editable_bones(const bContext *C, ListBase *list);
  231. struct bPoseChannel *CTX_data_active_pose_bone(const bContext *C);
  232. int CTX_data_selected_pose_bones(const bContext *C, ListBase *list);
  233. int CTX_data_visible_pose_bones(const bContext *C, ListBase *list);
  234. struct bGPdata *CTX_data_gpencil_data(const bContext *C);
  235. struct bGPDlayer *CTX_data_active_gpencil_layer(const bContext *C);
  236. struct bGPDframe *CTX_data_active_gpencil_frame(const bContext *C);
  237. struct bGPDpalette *CTX_data_active_gpencil_palette(const bContext *C);
  238. struct bGPDpalettecolor *CTX_data_active_gpencil_palettecolor(const bContext *C);
  239. struct bGPDbrush *CTX_data_active_gpencil_brush(const bContext *C);
  240. int CTX_data_visible_gpencil_layers(const bContext *C, ListBase *list);
  241. int CTX_data_editable_gpencil_layers(const bContext *C, ListBase *list);
  242. int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list);
  243. #ifdef __cplusplus
  244. }
  245. #endif
  246. #endif