|
Blender
V2.59
|
00001 /* 00002 * $Id: context.c 36442 2011-05-02 13:35:04Z campbellbarton $ 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 00033 #include <string.h> 00034 #include <stddef.h> 00035 00036 #include "MEM_guardedalloc.h" 00037 00038 #include "DNA_scene_types.h" 00039 #include "DNA_screen_types.h" 00040 #include "DNA_space_types.h" 00041 #include "DNA_view3d_types.h" 00042 #include "DNA_windowmanager_types.h" 00043 #include "DNA_object_types.h" 00044 00045 #include "RNA_access.h" 00046 00047 #include "BLI_listbase.h" 00048 #include "BLI_string.h" 00049 00050 #include "BKE_context.h" 00051 #include "BKE_main.h" 00052 #include "BKE_screen.h" 00053 00054 #ifdef WITH_PYTHON 00055 #include "BPY_extern.h" 00056 #endif 00057 00058 /* struct */ 00059 00060 struct bContext { 00061 int thread; 00062 00063 /* windowmanager context */ 00064 struct { 00065 struct wmWindowManager *manager; 00066 struct wmWindow *window; 00067 struct bScreen *screen; 00068 struct ScrArea *area; 00069 struct ARegion *region; 00070 struct ARegion *menu; 00071 struct bContextStore *store; 00072 const char *operator_poll_msg; /* reason for poll failing */ 00073 } wm; 00074 00075 /* data context */ 00076 struct { 00077 struct Main *main; 00078 struct Scene *scene; 00079 00080 int recursion; 00081 int py_init; /* true if python is initialized */ 00082 void *py_context; 00083 } data; 00084 00085 /* data evaluation */ 00086 struct { 00087 int render; 00088 } eval; 00089 }; 00090 00091 /* context */ 00092 00093 bContext *CTX_create(void) 00094 { 00095 bContext *C; 00096 00097 C= MEM_callocN(sizeof(bContext), "bContext"); 00098 00099 return C; 00100 } 00101 00102 bContext *CTX_copy(const bContext *C) 00103 { 00104 bContext *newC= MEM_dupallocN((void*)C); 00105 00106 return newC; 00107 } 00108 00109 void CTX_free(bContext *C) 00110 { 00111 MEM_freeN(C); 00112 } 00113 00114 /* store */ 00115 00116 bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *ptr) 00117 { 00118 bContextStoreEntry *entry; 00119 bContextStore *ctx, *lastctx; 00120 00121 /* ensure we have a context to put the entry in, if it was already used 00122 * we have to copy the context to ensure */ 00123 ctx= contexts->last; 00124 00125 if(!ctx || ctx->used) { 00126 if(ctx) { 00127 lastctx= ctx; 00128 ctx= MEM_dupallocN(lastctx); 00129 BLI_duplicatelist(&ctx->entries, &lastctx->entries); 00130 } 00131 else 00132 ctx= MEM_callocN(sizeof(bContextStore), "bContextStore"); 00133 00134 BLI_addtail(contexts, ctx); 00135 } 00136 00137 entry= MEM_callocN(sizeof(bContextStoreEntry), "bContextStoreEntry"); 00138 BLI_strncpy(entry->name, name, sizeof(entry->name)); 00139 entry->ptr= *ptr; 00140 00141 BLI_addtail(&ctx->entries, entry); 00142 00143 return ctx; 00144 } 00145 00146 void CTX_store_set(bContext *C, bContextStore *store) 00147 { 00148 C->wm.store= store; 00149 } 00150 00151 bContextStore *CTX_store_copy(bContextStore *store) 00152 { 00153 bContextStore *ctx; 00154 00155 ctx= MEM_dupallocN(store); 00156 BLI_duplicatelist(&ctx->entries, &store->entries); 00157 00158 return ctx; 00159 } 00160 00161 void CTX_store_free(bContextStore *store) 00162 { 00163 BLI_freelistN(&store->entries); 00164 MEM_freeN(store); 00165 } 00166 00167 void CTX_store_free_list(ListBase *contexts) 00168 { 00169 bContextStore *ctx; 00170 00171 while((ctx= contexts->first)) { 00172 BLI_remlink(contexts, ctx); 00173 CTX_store_free(ctx); 00174 } 00175 } 00176 00177 /* is python initialied? */ 00178 int CTX_py_init_get(bContext *C) 00179 { 00180 return C->data.py_init; 00181 } 00182 void CTX_py_init_set(bContext *C, int value) 00183 { 00184 C->data.py_init= value; 00185 } 00186 00187 void *CTX_py_dict_get(const bContext *C) 00188 { 00189 return C->data.py_context; 00190 } 00191 void CTX_py_dict_set(bContext *C, void *value) 00192 { 00193 C->data.py_context= value; 00194 } 00195 00196 /* window manager context */ 00197 00198 wmWindowManager *CTX_wm_manager(const bContext *C) 00199 { 00200 return C->wm.manager; 00201 } 00202 00203 wmWindow *CTX_wm_window(const bContext *C) 00204 { 00205 return C->wm.window; 00206 } 00207 00208 bScreen *CTX_wm_screen(const bContext *C) 00209 { 00210 return C->wm.screen; 00211 } 00212 00213 ScrArea *CTX_wm_area(const bContext *C) 00214 { 00215 return C->wm.area; 00216 } 00217 00218 SpaceLink *CTX_wm_space_data(const bContext *C) 00219 { 00220 return (C->wm.area)? C->wm.area->spacedata.first: NULL; 00221 } 00222 00223 ARegion *CTX_wm_region(const bContext *C) 00224 { 00225 return C->wm.region; 00226 } 00227 00228 void *CTX_wm_region_data(const bContext *C) 00229 { 00230 return (C->wm.region)? C->wm.region->regiondata: NULL; 00231 } 00232 00233 struct ARegion *CTX_wm_menu(const bContext *C) 00234 { 00235 return C->wm.menu; 00236 } 00237 00238 struct ReportList *CTX_wm_reports(const bContext *C) 00239 { 00240 if (C->wm.manager) 00241 return &(C->wm.manager->reports); 00242 00243 return NULL; 00244 } 00245 00246 View3D *CTX_wm_view3d(const bContext *C) 00247 { 00248 if(C->wm.area && C->wm.area->spacetype==SPACE_VIEW3D) 00249 return C->wm.area->spacedata.first; 00250 return NULL; 00251 } 00252 00253 RegionView3D *CTX_wm_region_view3d(const bContext *C) 00254 { 00255 if(C->wm.area && C->wm.area->spacetype==SPACE_VIEW3D) 00256 if(C->wm.region) 00257 return C->wm.region->regiondata; 00258 return NULL; 00259 } 00260 00261 struct SpaceText *CTX_wm_space_text(const bContext *C) 00262 { 00263 if(C->wm.area && C->wm.area->spacetype==SPACE_TEXT) 00264 return C->wm.area->spacedata.first; 00265 return NULL; 00266 } 00267 00268 struct SpaceConsole *CTX_wm_space_console(const bContext *C) 00269 { 00270 if(C->wm.area && C->wm.area->spacetype==SPACE_CONSOLE) 00271 return C->wm.area->spacedata.first; 00272 return NULL; 00273 } 00274 00275 struct SpaceImage *CTX_wm_space_image(const bContext *C) 00276 { 00277 if(C->wm.area && C->wm.area->spacetype==SPACE_IMAGE) 00278 return C->wm.area->spacedata.first; 00279 return NULL; 00280 } 00281 00282 struct SpaceButs *CTX_wm_space_buts(const bContext *C) 00283 { 00284 if(C->wm.area && C->wm.area->spacetype==SPACE_BUTS) 00285 return C->wm.area->spacedata.first; 00286 return NULL; 00287 } 00288 00289 struct SpaceFile *CTX_wm_space_file(const bContext *C) 00290 { 00291 if(C->wm.area && C->wm.area->spacetype==SPACE_FILE) 00292 return C->wm.area->spacedata.first; 00293 return NULL; 00294 } 00295 00296 struct SpaceSeq *CTX_wm_space_seq(const bContext *C) 00297 { 00298 if(C->wm.area && C->wm.area->spacetype==SPACE_SEQ) 00299 return C->wm.area->spacedata.first; 00300 return NULL; 00301 } 00302 00303 struct SpaceOops *CTX_wm_space_outliner(const bContext *C) 00304 { 00305 if(C->wm.area && C->wm.area->spacetype==SPACE_OUTLINER) 00306 return C->wm.area->spacedata.first; 00307 return NULL; 00308 } 00309 00310 struct SpaceNla *CTX_wm_space_nla(const bContext *C) 00311 { 00312 if(C->wm.area && C->wm.area->spacetype==SPACE_NLA) 00313 return C->wm.area->spacedata.first; 00314 return NULL; 00315 } 00316 00317 struct SpaceTime *CTX_wm_space_time(const bContext *C) 00318 { 00319 if(C->wm.area && C->wm.area->spacetype==SPACE_TIME) 00320 return C->wm.area->spacedata.first; 00321 return NULL; 00322 } 00323 00324 struct SpaceNode *CTX_wm_space_node(const bContext *C) 00325 { 00326 if(C->wm.area && C->wm.area->spacetype==SPACE_NODE) 00327 return C->wm.area->spacedata.first; 00328 return NULL; 00329 } 00330 00331 struct SpaceLogic *CTX_wm_space_logic(const bContext *C) 00332 { 00333 if(C->wm.area && C->wm.area->spacetype==SPACE_LOGIC) 00334 return C->wm.area->spacedata.first; 00335 return NULL; 00336 } 00337 00338 struct SpaceIpo *CTX_wm_space_graph(const bContext *C) 00339 { 00340 if(C->wm.area && C->wm.area->spacetype==SPACE_IPO) 00341 return C->wm.area->spacedata.first; 00342 return NULL; 00343 } 00344 00345 struct SpaceAction *CTX_wm_space_action(const bContext *C) 00346 { 00347 if(C->wm.area && C->wm.area->spacetype==SPACE_ACTION) 00348 return C->wm.area->spacedata.first; 00349 return NULL; 00350 } 00351 00352 struct SpaceInfo *CTX_wm_space_info(const bContext *C) 00353 { 00354 if(C->wm.area && C->wm.area->spacetype==SPACE_INFO) 00355 return C->wm.area->spacedata.first; 00356 return NULL; 00357 } 00358 00359 struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C) 00360 { 00361 if(C->wm.area && C->wm.area->spacetype==SPACE_USERPREF) 00362 return C->wm.area->spacedata.first; 00363 return NULL; 00364 } 00365 00366 void CTX_wm_manager_set(bContext *C, wmWindowManager *wm) 00367 { 00368 C->wm.manager= wm; 00369 C->wm.window= NULL; 00370 C->wm.screen= NULL; 00371 C->wm.area= NULL; 00372 C->wm.region= NULL; 00373 } 00374 00375 void CTX_wm_window_set(bContext *C, wmWindow *win) 00376 { 00377 C->wm.window= win; 00378 C->wm.screen= (win)? win->screen: NULL; 00379 C->data.scene= (C->wm.screen)? C->wm.screen->scene: NULL; 00380 C->wm.area= NULL; 00381 C->wm.region= NULL; 00382 } 00383 00384 void CTX_wm_screen_set(bContext *C, bScreen *screen) 00385 { 00386 C->wm.screen= screen; 00387 C->data.scene= (C->wm.screen)? C->wm.screen->scene: NULL; 00388 C->wm.area= NULL; 00389 C->wm.region= NULL; 00390 } 00391 00392 void CTX_wm_area_set(bContext *C, ScrArea *area) 00393 { 00394 C->wm.area= area; 00395 C->wm.region= NULL; 00396 } 00397 00398 void CTX_wm_region_set(bContext *C, ARegion *region) 00399 { 00400 C->wm.region= region; 00401 } 00402 00403 void CTX_wm_menu_set(bContext *C, ARegion *menu) 00404 { 00405 C->wm.menu= menu; 00406 } 00407 00408 void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg) 00409 { 00410 C->wm.operator_poll_msg= msg; 00411 } 00412 00413 const char *CTX_wm_operator_poll_msg_get(bContext *C) 00414 { 00415 return C->wm.operator_poll_msg; 00416 } 00417 00418 /* data context utility functions */ 00419 00420 struct bContextDataResult { 00421 PointerRNA ptr; 00422 ListBase list; 00423 const char **dir; 00424 short type; /* 0: normal, 1: seq */ 00425 }; 00426 00427 static int ctx_data_get(bContext *C, const char *member, bContextDataResult *result) 00428 { 00429 int done= 0, recursion= C->data.recursion; 00430 int ret= 0; 00431 00432 memset(result, 0, sizeof(bContextDataResult)); 00433 #ifdef WITH_PYTHON 00434 if(CTX_py_dict_get(C)) { 00435 return BPY_context_member_get(C, member, result); 00436 // if (BPY_context_member_get(C, member, result)) 00437 // return 1; 00438 } 00439 #endif 00440 /* we check recursion to ensure that we do not get infinite 00441 * loops requesting data from ourselfs in a context callback */ 00442 00443 /* Ok, this looks evil... 00444 * if(ret) done= -(-ret | -done); 00445 * 00446 * Values in order of importance 00447 * (0, -1, 1) - Where 1 is highest priority 00448 * */ 00449 if(done!=1 && recursion < 1 && C->wm.store) { 00450 bContextStoreEntry *entry; 00451 00452 C->data.recursion= 1; 00453 00454 entry= BLI_rfindstring(&C->wm.store->entries, member, offsetof(bContextStoreEntry, name)); 00455 if(entry) { 00456 result->ptr= entry->ptr; 00457 done= 1; 00458 } 00459 } 00460 if(done!=1 && recursion < 2 && C->wm.region) { 00461 C->data.recursion= 2; 00462 if(C->wm.region->type && C->wm.region->type->context) { 00463 ret = C->wm.region->type->context(C, member, result); 00464 if(ret) done= -(-ret | -done); 00465 00466 } 00467 } 00468 if(done!=1 && recursion < 3 && C->wm.area) { 00469 C->data.recursion= 3; 00470 if(C->wm.area->type && C->wm.area->type->context) { 00471 ret = C->wm.area->type->context(C, member, result); 00472 if(ret) done= -(-ret | -done); 00473 } 00474 } 00475 if(done!=1 && recursion < 4 && C->wm.screen) { 00476 bContextDataCallback cb= C->wm.screen->context; 00477 C->data.recursion= 4; 00478 if(cb) { 00479 ret = cb(C, member, result); 00480 if(ret) done= -(-ret | -done); 00481 } 00482 } 00483 00484 C->data.recursion= recursion; 00485 00486 return done; 00487 } 00488 00489 static void *ctx_data_pointer_get(const bContext *C, const char *member) 00490 { 00491 bContextDataResult result; 00492 00493 if(C && ctx_data_get((bContext*)C, member, &result)==1) 00494 return result.ptr.data; 00495 00496 return NULL; 00497 } 00498 00499 static int ctx_data_pointer_verify(const bContext *C, const char *member, void **pointer) 00500 { 00501 bContextDataResult result; 00502 00503 /* if context is NULL, pointer must be NULL too and that is a valid return */ 00504 if (C == NULL) { 00505 *pointer= NULL; 00506 return 1; 00507 } 00508 else if(ctx_data_get((bContext*)C, member, &result)==1) { 00509 *pointer= result.ptr.data; 00510 return 1; 00511 } 00512 else { 00513 *pointer= NULL; 00514 return 0; 00515 } 00516 } 00517 00518 static int ctx_data_collection_get(const bContext *C, const char *member, ListBase *list) 00519 { 00520 bContextDataResult result; 00521 00522 if(ctx_data_get((bContext*)C, member, &result)==1) { 00523 *list= result.list; 00524 return 1; 00525 } 00526 00527 list->first= NULL; 00528 list->last= NULL; 00529 00530 return 0; 00531 } 00532 00533 PointerRNA CTX_data_pointer_get(const bContext *C, const char *member) 00534 { 00535 bContextDataResult result; 00536 00537 if(ctx_data_get((bContext*)C, member, &result)==1) 00538 return result.ptr; 00539 else 00540 return PointerRNA_NULL; 00541 } 00542 00543 PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type) 00544 { 00545 PointerRNA ptr = CTX_data_pointer_get(C, member); 00546 00547 if(ptr.data && RNA_struct_is_a(ptr.type, type)) 00548 return ptr; 00549 00550 return PointerRNA_NULL; 00551 } 00552 00553 ListBase CTX_data_collection_get(const bContext *C, const char *member) 00554 { 00555 bContextDataResult result; 00556 00557 if(ctx_data_get((bContext*)C, member, &result)==1) { 00558 return result.list; 00559 } 00560 else { 00561 ListBase list= {NULL, NULL}; 00562 return list; 00563 } 00564 } 00565 00566 /* 1:found, -1:found but not set, 0:not found */ 00567 int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb, short *r_type) 00568 { 00569 bContextDataResult result; 00570 int ret= ctx_data_get((bContext*)C, member, &result); 00571 00572 if(ret==1) { 00573 *r_ptr= result.ptr; 00574 *r_lb= result.list; 00575 *r_type= result.type; 00576 } 00577 else { 00578 memset(r_ptr, 0, sizeof(*r_ptr)); 00579 memset(r_lb, 0, sizeof(*r_lb)); 00580 *r_type= 0; 00581 } 00582 00583 return ret; 00584 } 00585 00586 static void data_dir_add(ListBase *lb, const char *member) 00587 { 00588 LinkData *link; 00589 00590 if(strcmp(member, "scene") == 0) /* exception */ 00591 return; 00592 00593 if(BLI_findstring(lb, member, offsetof(LinkData, data))) 00594 return; 00595 00596 link= MEM_callocN(sizeof(LinkData), "LinkData"); 00597 link->data= (void*)member; 00598 BLI_addtail(lb, link); 00599 } 00600 00601 ListBase CTX_data_dir_get(const bContext *C) 00602 { 00603 bContextDataResult result; 00604 ListBase lb; 00605 int a; 00606 00607 memset(&lb, 0, sizeof(lb)); 00608 00609 if(C->wm.store) { 00610 bContextStoreEntry *entry; 00611 00612 for(entry=C->wm.store->entries.first; entry; entry=entry->next) 00613 data_dir_add(&lb, entry->name); 00614 } 00615 if(C->wm.region && C->wm.region->type && C->wm.region->type->context) { 00616 memset(&result, 0, sizeof(result)); 00617 C->wm.region->type->context(C, "", &result); 00618 00619 if(result.dir) 00620 for(a=0; result.dir[a]; a++) 00621 data_dir_add(&lb, result.dir[a]); 00622 } 00623 if(C->wm.area && C->wm.area->type && C->wm.area->type->context) { 00624 memset(&result, 0, sizeof(result)); 00625 C->wm.area->type->context(C, "", &result); 00626 00627 if(result.dir) 00628 for(a=0; result.dir[a]; a++) 00629 data_dir_add(&lb, result.dir[a]); 00630 } 00631 if(C->wm.screen && C->wm.screen->context) { 00632 bContextDataCallback cb= C->wm.screen->context; 00633 memset(&result, 0, sizeof(result)); 00634 cb(C, "", &result); 00635 00636 if(result.dir) 00637 for(a=0; result.dir[a]; a++) 00638 data_dir_add(&lb, result.dir[a]); 00639 } 00640 00641 return lb; 00642 } 00643 00644 int CTX_data_equals(const char *member, const char *str) 00645 { 00646 return (strcmp(member, str) == 0); 00647 } 00648 00649 int CTX_data_dir(const char *member) 00650 { 00651 return member[0] == '\0'; 00652 } 00653 00654 void CTX_data_id_pointer_set(bContextDataResult *result, ID *id) 00655 { 00656 RNA_id_pointer_create(id, &result->ptr); 00657 } 00658 00659 void CTX_data_pointer_set(bContextDataResult *result, ID *id, StructRNA *type, void *data) 00660 { 00661 RNA_pointer_create(id, type, data, &result->ptr); 00662 } 00663 00664 void CTX_data_id_list_add(bContextDataResult *result, ID *id) 00665 { 00666 CollectionPointerLink *link; 00667 00668 link= MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_id_list_add"); 00669 RNA_id_pointer_create(id, &link->ptr); 00670 00671 BLI_addtail(&result->list, link); 00672 } 00673 00674 void CTX_data_list_add(bContextDataResult *result, ID *id, StructRNA *type, void *data) 00675 { 00676 CollectionPointerLink *link; 00677 00678 link= MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_list_add"); 00679 RNA_pointer_create(id, type, data, &link->ptr); 00680 00681 BLI_addtail(&result->list, link); 00682 } 00683 00684 int ctx_data_list_count(const bContext *C, int (*func)(const bContext*, ListBase*)) 00685 { 00686 ListBase list; 00687 00688 if(func(C, &list)) { 00689 int tot= BLI_countlist(&list); 00690 BLI_freelistN(&list); 00691 return tot; 00692 } 00693 else 00694 return 0; 00695 } 00696 00697 void CTX_data_dir_set(bContextDataResult *result, const char **dir) 00698 { 00699 result->dir= dir; 00700 } 00701 00702 void CTX_data_type_set(bContextDataResult *result, short type) 00703 { 00704 result->type= type; 00705 } 00706 00707 short CTX_data_type_get(bContextDataResult *result) 00708 { 00709 return result->type; 00710 } 00711 00712 /* data context */ 00713 00714 Main *CTX_data_main(const bContext *C) 00715 { 00716 Main *bmain; 00717 00718 if(ctx_data_pointer_verify(C, "blend_data", (void*)&bmain)) 00719 return bmain; 00720 else 00721 return C->data.main; 00722 } 00723 00724 void CTX_data_main_set(bContext *C, Main *bmain) 00725 { 00726 C->data.main= bmain; 00727 } 00728 00729 Scene *CTX_data_scene(const bContext *C) 00730 { 00731 Scene *scene; 00732 00733 if(ctx_data_pointer_verify(C, "scene", (void*)&scene)) 00734 return scene; 00735 else 00736 return C->data.scene; 00737 } 00738 00739 int CTX_data_mode_enum(const bContext *C) 00740 { 00741 Object *obedit= CTX_data_edit_object(C); 00742 00743 if(obedit) { 00744 switch(obedit->type) { 00745 case OB_MESH: 00746 return CTX_MODE_EDIT_MESH; 00747 case OB_CURVE: 00748 return CTX_MODE_EDIT_CURVE; 00749 case OB_SURF: 00750 return CTX_MODE_EDIT_SURFACE; 00751 case OB_FONT: 00752 return CTX_MODE_EDIT_TEXT; 00753 case OB_ARMATURE: 00754 return CTX_MODE_EDIT_ARMATURE; 00755 case OB_MBALL: 00756 return CTX_MODE_EDIT_METABALL; 00757 case OB_LATTICE: 00758 return CTX_MODE_EDIT_LATTICE; 00759 } 00760 } 00761 else { 00762 Object *ob = CTX_data_active_object(C); 00763 00764 if(ob) { 00765 if(ob->mode & OB_MODE_POSE) return CTX_MODE_POSE; 00766 else if(ob->mode & OB_MODE_SCULPT) return CTX_MODE_SCULPT; 00767 else if(ob->mode & OB_MODE_WEIGHT_PAINT) return CTX_MODE_PAINT_WEIGHT; 00768 else if(ob->mode & OB_MODE_VERTEX_PAINT) return CTX_MODE_PAINT_VERTEX; 00769 else if(ob->mode & OB_MODE_TEXTURE_PAINT) return CTX_MODE_PAINT_TEXTURE; 00770 else if(ob->mode & OB_MODE_PARTICLE_EDIT) return CTX_MODE_PARTICLE; 00771 } 00772 } 00773 00774 return CTX_MODE_OBJECT; 00775 } 00776 00777 00778 /* would prefer if we can use the enum version below over this one - Campbell */ 00779 /* must be aligned with above enum */ 00780 static const char *data_mode_strings[] = { 00781 "mesh_edit", 00782 "curve_edit", 00783 "surface_edit", 00784 "text_edit", 00785 "armature_edit", 00786 "mball_edit", 00787 "lattice_edit", 00788 "posemode", 00789 "sculpt_mode", 00790 "weightpaint", 00791 "vertexpaint", 00792 "imagepaint", 00793 "particlemode", 00794 "objectmode", 00795 NULL 00796 }; 00797 const char *CTX_data_mode_string(const bContext *C) 00798 { 00799 return data_mode_strings[CTX_data_mode_enum(C)]; 00800 } 00801 00802 void CTX_data_scene_set(bContext *C, Scene *scene) 00803 { 00804 C->data.scene= scene; 00805 } 00806 00807 ToolSettings *CTX_data_tool_settings(const bContext *C) 00808 { 00809 Scene *scene = CTX_data_scene(C); 00810 00811 if(scene) 00812 return scene->toolsettings; 00813 else 00814 return NULL; 00815 } 00816 00817 int CTX_data_selected_nodes(const bContext *C, ListBase *list) 00818 { 00819 return ctx_data_collection_get(C, "selected_nodes", list); 00820 } 00821 00822 int CTX_data_selected_editable_objects(const bContext *C, ListBase *list) 00823 { 00824 return ctx_data_collection_get(C, "selected_editable_objects", list); 00825 } 00826 00827 int CTX_data_selected_editable_bases(const bContext *C, ListBase *list) 00828 { 00829 return ctx_data_collection_get(C, "selected_editable_bases", list); 00830 } 00831 00832 int CTX_data_selected_objects(const bContext *C, ListBase *list) 00833 { 00834 return ctx_data_collection_get(C, "selected_objects", list); 00835 } 00836 00837 int CTX_data_selected_bases(const bContext *C, ListBase *list) 00838 { 00839 return ctx_data_collection_get(C, "selected_bases", list); 00840 } 00841 00842 int CTX_data_visible_objects(const bContext *C, ListBase *list) 00843 { 00844 return ctx_data_collection_get(C, "visible_objects", list); 00845 } 00846 00847 int CTX_data_visible_bases(const bContext *C, ListBase *list) 00848 { 00849 return ctx_data_collection_get(C, "visible_bases", list); 00850 } 00851 00852 int CTX_data_selectable_objects(const bContext *C, ListBase *list) 00853 { 00854 return ctx_data_collection_get(C, "selectable_objects", list); 00855 } 00856 00857 int CTX_data_selectable_bases(const bContext *C, ListBase *list) 00858 { 00859 return ctx_data_collection_get(C, "selectable_bases", list); 00860 } 00861 00862 struct Object *CTX_data_active_object(const bContext *C) 00863 { 00864 return ctx_data_pointer_get(C, "active_object"); 00865 } 00866 00867 struct Base *CTX_data_active_base(const bContext *C) 00868 { 00869 return ctx_data_pointer_get(C, "active_base"); 00870 } 00871 00872 struct Object *CTX_data_edit_object(const bContext *C) 00873 { 00874 return ctx_data_pointer_get(C, "edit_object"); 00875 } 00876 00877 struct Image *CTX_data_edit_image(const bContext *C) 00878 { 00879 return ctx_data_pointer_get(C, "edit_image"); 00880 } 00881 00882 struct Text *CTX_data_edit_text(const bContext *C) 00883 { 00884 return ctx_data_pointer_get(C, "edit_text"); 00885 } 00886 00887 struct EditBone *CTX_data_active_bone(const bContext *C) 00888 { 00889 return ctx_data_pointer_get(C, "active_bone"); 00890 } 00891 00892 int CTX_data_selected_bones(const bContext *C, ListBase *list) 00893 { 00894 return ctx_data_collection_get(C, "selected_bones", list); 00895 } 00896 00897 int CTX_data_selected_editable_bones(const bContext *C, ListBase *list) 00898 { 00899 return ctx_data_collection_get(C, "selected_editable_bones", list); 00900 } 00901 00902 int CTX_data_visible_bones(const bContext *C, ListBase *list) 00903 { 00904 return ctx_data_collection_get(C, "visible_bones", list); 00905 } 00906 00907 int CTX_data_editable_bones(const bContext *C, ListBase *list) 00908 { 00909 return ctx_data_collection_get(C, "editable_bones", list); 00910 } 00911 00912 struct bPoseChannel *CTX_data_active_pose_bone(const bContext *C) 00913 { 00914 return ctx_data_pointer_get(C, "active_pose_bone"); 00915 } 00916 00917 int CTX_data_selected_pose_bones(const bContext *C, ListBase *list) 00918 { 00919 return ctx_data_collection_get(C, "selected_pose_bones", list); 00920 } 00921 00922 int CTX_data_visible_pose_bones(const bContext *C, ListBase *list) 00923 { 00924 return ctx_data_collection_get(C, "visible_pose_bones", list); 00925 } 00926