2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-18 02:56:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-18 02:56:48 +00:00
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation (2008).
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:40:57 +00:00
|
|
|
/** \file blender/blenkernel/intern/context.c
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
2010-08-22 14:15:28 +00:00
|
|
|
#include <string.h>
|
2012-12-28 10:08:17 +00:00
|
|
|
#include <stdlib.h>
|
2010-08-22 14:15:28 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
#include "DNA_space_types.h"
|
2009-01-17 18:35:33 +00:00
|
|
|
#include "DNA_view3d_types.h"
|
2008-12-18 02:56:48 +00:00
|
|
|
#include "DNA_windowmanager_types.h"
|
2009-08-15 19:40:09 +00:00
|
|
|
#include "DNA_object_types.h"
|
2008-12-18 02:56:48 +00:00
|
|
|
|
2008-12-23 02:07:13 +00:00
|
|
|
#include "BLI_listbase.h"
|
2009-05-28 23:13:42 +00:00
|
|
|
#include "BLI_string.h"
|
2012-11-16 15:15:40 +00:00
|
|
|
#include "BLI_threads.h"
|
2012-05-19 13:28:19 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2008-12-23 02:07:13 +00:00
|
|
|
|
2013-02-19 15:45:56 +00:00
|
|
|
#include "BLF_translation.h"
|
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_screen.h"
|
|
|
|
|
2013-03-07 02:44:55 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2013-03-07 02:44:55 +00:00
|
|
|
# include "BPY_extern.h"
|
2010-01-23 20:43:55 +00:00
|
|
|
#endif
|
2009-11-10 16:18:54 +00:00
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
/* struct */
|
|
|
|
|
|
|
|
struct bContext {
|
|
|
|
int thread;
|
|
|
|
|
|
|
|
/* windowmanager context */
|
|
|
|
struct {
|
|
|
|
struct wmWindowManager *manager;
|
|
|
|
struct wmWindow *window;
|
|
|
|
struct bScreen *screen;
|
|
|
|
struct ScrArea *area;
|
|
|
|
struct ARegion *region;
|
2009-03-25 20:49:15 +00:00
|
|
|
struct ARegion *menu;
|
2009-05-28 23:13:42 +00:00
|
|
|
struct bContextStore *store;
|
2010-09-27 12:21:23 +00:00
|
|
|
const char *operator_poll_msg; /* reason for poll failing */
|
2008-12-18 02:56:48 +00:00
|
|
|
} wm;
|
|
|
|
|
|
|
|
/* data context */
|
|
|
|
struct {
|
|
|
|
struct Main *main;
|
|
|
|
struct Scene *scene;
|
2008-12-23 02:07:13 +00:00
|
|
|
|
|
|
|
int recursion;
|
2009-07-18 19:40:26 +00:00
|
|
|
int py_init; /* true if python is initialized */
|
2009-10-29 09:25:11 +00:00
|
|
|
void *py_context;
|
2008-12-18 02:56:48 +00:00
|
|
|
} data;
|
|
|
|
|
|
|
|
/* data evaluation */
|
2013-04-13 14:57:08 +00:00
|
|
|
#if 0
|
2008-12-18 02:56:48 +00:00
|
|
|
struct {
|
|
|
|
int render;
|
|
|
|
} eval;
|
2013-04-13 14:57:08 +00:00
|
|
|
#endif
|
2008-12-18 02:56:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* context */
|
|
|
|
|
2011-02-13 10:52:18 +00:00
|
|
|
bContext *CTX_create(void)
|
2008-12-18 02:56:48 +00:00
|
|
|
{
|
|
|
|
bContext *C;
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
C = MEM_callocN(sizeof(bContext), "bContext");
|
2008-12-18 02:56:48 +00:00
|
|
|
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2009-03-25 20:49:15 +00:00
|
|
|
bContext *CTX_copy(const bContext *C)
|
2008-12-18 02:56:48 +00:00
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
bContext *newC = MEM_dupallocN((void *)C);
|
2008-12-18 02:56:48 +00:00
|
|
|
|
|
|
|
return newC;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_free(bContext *C)
|
|
|
|
{
|
|
|
|
MEM_freeN(C);
|
|
|
|
}
|
|
|
|
|
2009-05-28 23:13:42 +00:00
|
|
|
/* store */
|
|
|
|
|
2010-11-17 09:45:45 +00:00
|
|
|
bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *ptr)
|
2009-05-28 23:13:42 +00:00
|
|
|
{
|
|
|
|
bContextStoreEntry *entry;
|
|
|
|
bContextStore *ctx, *lastctx;
|
|
|
|
|
|
|
|
/* ensure we have a context to put the entry in, if it was already used
|
|
|
|
* we have to copy the context to ensure */
|
2012-05-06 17:22:54 +00:00
|
|
|
ctx = contexts->last;
|
2009-05-28 23:13:42 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!ctx || ctx->used) {
|
|
|
|
if (ctx) {
|
2012-05-06 17:22:54 +00:00
|
|
|
lastctx = ctx;
|
|
|
|
ctx = MEM_dupallocN(lastctx);
|
2009-05-28 23:13:42 +00:00
|
|
|
BLI_duplicatelist(&ctx->entries, &lastctx->entries);
|
|
|
|
}
|
|
|
|
else
|
2012-05-06 17:22:54 +00:00
|
|
|
ctx = MEM_callocN(sizeof(bContextStore), "bContextStore");
|
2009-05-28 23:13:42 +00:00
|
|
|
|
|
|
|
BLI_addtail(contexts, ctx);
|
|
|
|
}
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
entry = MEM_callocN(sizeof(bContextStoreEntry), "bContextStoreEntry");
|
2009-05-28 23:13:42 +00:00
|
|
|
BLI_strncpy(entry->name, name, sizeof(entry->name));
|
2012-05-06 17:22:54 +00:00
|
|
|
entry->ptr = *ptr;
|
2009-05-28 23:13:42 +00:00
|
|
|
|
|
|
|
BLI_addtail(&ctx->entries, entry);
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2012-04-03 15:18:59 +00:00
|
|
|
bContextStore *CTX_store_add_all(ListBase *contexts, bContextStore *context)
|
|
|
|
{
|
|
|
|
bContextStoreEntry *entry, *tentry;
|
|
|
|
bContextStore *ctx, *lastctx;
|
|
|
|
|
|
|
|
/* ensure we have a context to put the entries in, if it was already used
|
|
|
|
* we have to copy the context to ensure */
|
2012-05-06 17:22:54 +00:00
|
|
|
ctx = contexts->last;
|
2012-04-03 15:18:59 +00:00
|
|
|
|
|
|
|
if (!ctx || ctx->used) {
|
|
|
|
if (ctx) {
|
2012-05-06 17:22:54 +00:00
|
|
|
lastctx = ctx;
|
|
|
|
ctx = MEM_dupallocN(lastctx);
|
2012-04-03 15:18:59 +00:00
|
|
|
BLI_duplicatelist(&ctx->entries, &lastctx->entries);
|
|
|
|
}
|
|
|
|
else
|
2012-05-06 17:22:54 +00:00
|
|
|
ctx = MEM_callocN(sizeof(bContextStore), "bContextStore");
|
2012-04-03 15:18:59 +00:00
|
|
|
|
|
|
|
BLI_addtail(contexts, ctx);
|
|
|
|
}
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
for (tentry = context->entries.first; tentry; tentry = tentry->next) {
|
|
|
|
entry = MEM_dupallocN(tentry);
|
2012-04-03 15:18:59 +00:00
|
|
|
BLI_addtail(&ctx->entries, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2009-05-28 23:13:42 +00:00
|
|
|
void CTX_store_set(bContext *C, bContextStore *store)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
C->wm.store = store;
|
2009-05-28 23:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bContextStore *CTX_store_copy(bContextStore *store)
|
|
|
|
{
|
|
|
|
bContextStore *ctx;
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
ctx = MEM_dupallocN(store);
|
2009-05-28 23:13:42 +00:00
|
|
|
BLI_duplicatelist(&ctx->entries, &store->entries);
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_store_free(bContextStore *store)
|
|
|
|
{
|
|
|
|
BLI_freelistN(&store->entries);
|
|
|
|
MEM_freeN(store);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_store_free_list(ListBase *contexts)
|
|
|
|
{
|
|
|
|
bContextStore *ctx;
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
while ((ctx = contexts->first)) {
|
2009-05-28 23:13:42 +00:00
|
|
|
BLI_remlink(contexts, ctx);
|
|
|
|
CTX_store_free(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-18 19:40:26 +00:00
|
|
|
/* is python initialied? */
|
2012-05-02 12:14:27 +00:00
|
|
|
|
2009-07-18 19:40:26 +00:00
|
|
|
int CTX_py_init_get(bContext *C)
|
|
|
|
{
|
|
|
|
return C->data.py_init;
|
|
|
|
}
|
2009-07-18 19:42:13 +00:00
|
|
|
void CTX_py_init_set(bContext *C, int value)
|
2009-07-18 19:40:26 +00:00
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
C->data.py_init = value;
|
2009-07-18 19:40:26 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 04:12:15 +00:00
|
|
|
void *CTX_py_dict_get(const bContext *C)
|
2009-10-29 09:25:11 +00:00
|
|
|
{
|
|
|
|
return C->data.py_context;
|
|
|
|
}
|
|
|
|
void CTX_py_dict_set(bContext *C, void *value)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
C->data.py_context = value;
|
2009-10-29 09:25:11 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
/* data context utility functions */
|
|
|
|
|
2008-12-23 02:07:13 +00:00
|
|
|
struct bContextDataResult {
|
2009-03-19 19:03:38 +00:00
|
|
|
PointerRNA ptr;
|
2008-12-23 02:07:13 +00:00
|
|
|
ListBase list;
|
2009-06-20 14:55:28 +00:00
|
|
|
const char **dir;
|
2010-04-24 19:26:05 +00:00
|
|
|
short type; /* 0: normal, 1: seq */
|
2008-12-23 02:07:13 +00:00
|
|
|
};
|
2008-12-18 02:56:48 +00:00
|
|
|
|
2012-05-02 12:14:27 +00:00
|
|
|
static void *ctx_wm_python_context_get(const bContext *C, const char *member, void *fall_through)
|
|
|
|
{
|
|
|
|
#ifdef WITH_PYTHON
|
2012-10-25 03:10:35 +00:00
|
|
|
if (UNLIKELY(C && CTX_py_dict_get(C))) {
|
|
|
|
bContextDataResult result;
|
2012-05-02 12:14:27 +00:00
|
|
|
memset(&result, 0, sizeof(bContextDataResult));
|
2012-05-06 17:22:54 +00:00
|
|
|
BPY_context_member_get((bContext *)C, member, &result);
|
|
|
|
if (result.ptr.data)
|
2012-05-02 12:14:27 +00:00
|
|
|
return result.ptr.data;
|
|
|
|
}
|
2012-07-29 17:49:14 +00:00
|
|
|
#else
|
|
|
|
(void)C, (void)member;
|
2012-05-02 12:14:27 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-16 15:15:40 +00:00
|
|
|
/* don't allow UI context access from non-main threads */
|
|
|
|
if (!BLI_thread_is_main())
|
|
|
|
return NULL;
|
|
|
|
|
2012-05-02 12:14:27 +00:00
|
|
|
return fall_through;
|
|
|
|
}
|
|
|
|
|
2009-03-19 19:03:38 +00:00
|
|
|
static int ctx_data_get(bContext *C, const char *member, bContextDataResult *result)
|
2008-12-23 02:07:13 +00:00
|
|
|
{
|
2012-05-02 13:48:14 +00:00
|
|
|
bScreen *sc;
|
|
|
|
ScrArea *sa;
|
|
|
|
ARegion *ar;
|
2012-05-19 13:28:19 +00:00
|
|
|
int done = FALSE, recursion = C->data.recursion;
|
2012-05-06 17:22:54 +00:00
|
|
|
int ret = 0;
|
2008-12-18 02:56:48 +00:00
|
|
|
|
2008-12-23 02:07:13 +00:00
|
|
|
memset(result, 0, sizeof(bContextDataResult));
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2012-03-24 06:18:31 +00:00
|
|
|
if (CTX_py_dict_get(C)) {
|
2013-06-10 12:17:36 +00:00
|
|
|
if (BPY_context_member_get(C, member, result)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2009-10-29 09:25:11 +00:00
|
|
|
}
|
2010-01-23 20:43:55 +00:00
|
|
|
#endif
|
2012-11-16 15:15:40 +00:00
|
|
|
|
|
|
|
/* don't allow UI context access from non-main threads */
|
|
|
|
if (!BLI_thread_is_main())
|
|
|
|
return done;
|
|
|
|
|
2008-12-23 02:07:13 +00:00
|
|
|
/* we check recursion to ensure that we do not get infinite
|
|
|
|
* loops requesting data from ourselfs in a context callback */
|
2009-11-10 15:09:53 +00:00
|
|
|
|
|
|
|
/* Ok, this looks evil...
|
2012-05-27 19:40:36 +00:00
|
|
|
* if (ret) done = -(-ret | -done);
|
2009-11-10 15:09:53 +00:00
|
|
|
*
|
|
|
|
* Values in order of importance
|
|
|
|
* (0, -1, 1) - Where 1 is highest priority
|
|
|
|
* */
|
2012-05-06 17:22:54 +00:00
|
|
|
if (done != 1 && recursion < 1 && C->wm.store) {
|
2009-05-28 23:13:42 +00:00
|
|
|
bContextStoreEntry *entry;
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
C->data.recursion = 1;
|
2009-05-28 23:13:42 +00:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
entry = BLI_rfindstring(&C->wm.store->entries, member, offsetof(bContextStoreEntry, name));
|
2012-03-24 06:18:31 +00:00
|
|
|
if (entry) {
|
2012-05-06 17:22:54 +00:00
|
|
|
result->ptr = entry->ptr;
|
2012-05-19 13:28:19 +00:00
|
|
|
done = TRUE;
|
2009-05-28 23:13:42 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-06 17:22:54 +00:00
|
|
|
if (done != 1 && recursion < 2 && (ar = CTX_wm_region(C))) {
|
|
|
|
C->data.recursion = 2;
|
2012-05-02 13:48:14 +00:00
|
|
|
if (ar->type && ar->type->context) {
|
|
|
|
ret = ar->type->context(C, member, result);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (ret) done = -(-ret | -done);
|
2009-11-10 15:09:53 +00:00
|
|
|
|
|
|
|
}
|
2008-12-23 02:07:13 +00:00
|
|
|
}
|
2012-05-06 17:22:54 +00:00
|
|
|
if (done != 1 && recursion < 3 && (sa = CTX_wm_area(C))) {
|
|
|
|
C->data.recursion = 3;
|
2012-05-02 13:48:14 +00:00
|
|
|
if (sa->type && sa->type->context) {
|
|
|
|
ret = sa->type->context(C, member, result);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (ret) done = -(-ret | -done);
|
2009-11-10 15:09:53 +00:00
|
|
|
}
|
2008-12-23 02:07:13 +00:00
|
|
|
}
|
2012-05-06 17:22:54 +00:00
|
|
|
if (done != 1 && recursion < 4 && (sc = CTX_wm_screen(C))) {
|
|
|
|
bContextDataCallback cb = sc->context;
|
|
|
|
C->data.recursion = 4;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cb) {
|
2009-11-10 15:09:53 +00:00
|
|
|
ret = cb(C, member, result);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (ret) done = -(-ret | -done);
|
2009-11-10 15:09:53 +00:00
|
|
|
}
|
2008-12-23 02:07:13 +00:00
|
|
|
}
|
2008-12-18 02:56:48 +00:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
C->data.recursion = recursion;
|
2008-12-23 02:07:13 +00:00
|
|
|
|
|
|
|
return done;
|
2008-12-18 02:56:48 +00:00
|
|
|
}
|
|
|
|
|
2009-03-19 19:03:38 +00:00
|
|
|
static void *ctx_data_pointer_get(const bContext *C, const char *member)
|
2008-12-18 02:56:48 +00:00
|
|
|
{
|
|
|
|
bContextDataResult result;
|
|
|
|
|
2012-12-28 10:08:17 +00:00
|
|
|
if (C && ctx_data_get((bContext *)C, member, &result) == 1) {
|
|
|
|
BLI_assert(result.type == CTX_DATA_TYPE_POINTER);
|
2009-03-19 19:03:38 +00:00
|
|
|
return result.ptr.data;
|
2012-12-28 10:08:17 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-12-18 02:56:48 +00:00
|
|
|
}
|
|
|
|
|
2009-03-19 19:03:38 +00:00
|
|
|
static int ctx_data_pointer_verify(const bContext *C, const char *member, void **pointer)
|
2008-12-18 02:56:48 +00:00
|
|
|
{
|
|
|
|
bContextDataResult result;
|
|
|
|
|
2010-01-27 20:12:54 +00:00
|
|
|
/* if context is NULL, pointer must be NULL too and that is a valid return */
|
|
|
|
if (C == NULL) {
|
2012-05-06 17:22:54 +00:00
|
|
|
*pointer = NULL;
|
2010-01-27 20:12:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2012-05-06 17:22:54 +00:00
|
|
|
else if (ctx_data_get((bContext *)C, member, &result) == 1) {
|
2012-12-28 10:08:17 +00:00
|
|
|
BLI_assert(result.type == CTX_DATA_TYPE_POINTER);
|
2012-05-06 17:22:54 +00:00
|
|
|
*pointer = result.ptr.data;
|
2008-12-18 02:56:48 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
2012-05-06 17:22:54 +00:00
|
|
|
*pointer = NULL;
|
2008-12-18 02:56:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-19 19:03:38 +00:00
|
|
|
static int ctx_data_collection_get(const bContext *C, const char *member, ListBase *list)
|
2008-12-18 02:56:48 +00:00
|
|
|
{
|
|
|
|
bContextDataResult result;
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
if (ctx_data_get((bContext *)C, member, &result) == 1) {
|
2012-12-28 10:08:17 +00:00
|
|
|
BLI_assert(result.type == CTX_DATA_TYPE_COLLECTION);
|
2012-05-06 17:22:54 +00:00
|
|
|
*list = result.list;
|
2008-12-18 02:56:48 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
list->first = NULL;
|
|
|
|
list->last = NULL;
|
2009-06-28 11:37:45 +00:00
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-20 14:55:28 +00:00
|
|
|
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
|
2008-12-23 02:07:13 +00:00
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
bContextDataResult result;
|
|
|
|
|
2012-12-28 09:48:35 +00:00
|
|
|
if (ctx_data_get((bContext *)C, member, &result) == 1) {
|
2012-12-28 10:08:17 +00:00
|
|
|
BLI_assert(result.type == CTX_DATA_TYPE_POINTER);
|
2009-03-19 19:03:38 +00:00
|
|
|
return result.ptr;
|
2012-12-28 09:48:35 +00:00
|
|
|
}
|
2012-12-28 10:08:17 +00:00
|
|
|
else {
|
2009-06-24 14:03:55 +00:00
|
|
|
return PointerRNA_NULL;
|
2012-12-28 10:08:17 +00:00
|
|
|
}
|
2009-06-24 14:03:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
|
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get(C, member);
|
2009-03-19 19:03:38 +00:00
|
|
|
|
2012-07-24 10:28:29 +00:00
|
|
|
if (ptr.data) {
|
|
|
|
if (RNA_struct_is_a(ptr.type, type)) {
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("%s: warning, member '%s' is '%s', not '%s'\n",
|
|
|
|
__func__, member, RNA_struct_identifier(ptr.type), RNA_struct_identifier(type));
|
|
|
|
}
|
|
|
|
}
|
2009-06-24 14:03:55 +00:00
|
|
|
|
|
|
|
return PointerRNA_NULL;
|
2008-12-23 02:07:13 +00:00
|
|
|
}
|
|
|
|
|
2009-06-20 14:55:28 +00:00
|
|
|
ListBase CTX_data_collection_get(const bContext *C, const char *member)
|
2008-12-23 02:07:13 +00:00
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
bContextDataResult result;
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
if (ctx_data_get((bContext *)C, member, &result) == 1) {
|
2012-12-28 10:08:17 +00:00
|
|
|
BLI_assert(result.type == CTX_DATA_TYPE_COLLECTION);
|
2009-03-19 19:03:38 +00:00
|
|
|
return result.list;
|
|
|
|
}
|
|
|
|
else {
|
2012-05-06 17:22:54 +00:00
|
|
|
ListBase list = {NULL, NULL};
|
2009-03-19 19:03:38 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-10 15:09:53 +00:00
|
|
|
/* 1:found, -1:found but not set, 0:not found */
|
2010-04-24 19:26:05 +00:00
|
|
|
int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb, short *r_type)
|
2009-03-19 19:03:38 +00:00
|
|
|
{
|
|
|
|
bContextDataResult result;
|
2012-05-06 17:22:54 +00:00
|
|
|
int ret = ctx_data_get((bContext *)C, member, &result);
|
2009-03-19 19:03:38 +00:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
if (ret == 1) {
|
|
|
|
*r_ptr = result.ptr;
|
|
|
|
*r_lb = result.list;
|
|
|
|
*r_type = result.type;
|
2009-03-19 19:03:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
memset(r_ptr, 0, sizeof(*r_ptr));
|
|
|
|
memset(r_lb, 0, sizeof(*r_lb));
|
2012-05-06 17:22:54 +00:00
|
|
|
*r_type = 0;
|
2009-03-19 19:03:38 +00:00
|
|
|
}
|
2009-11-10 15:09:53 +00:00
|
|
|
|
|
|
|
return ret;
|
2009-03-19 19:03:38 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 02:08:58 +00:00
|
|
|
static void data_dir_add(ListBase *lb, const char *member, const short use_all)
|
2009-06-20 14:55:28 +00:00
|
|
|
{
|
|
|
|
LinkData *link;
|
2010-08-22 14:15:28 +00:00
|
|
|
|
2012-12-19 02:08:58 +00:00
|
|
|
if ((use_all == FALSE) && strcmp(member, "scene") == 0) /* exception */
|
2009-06-20 14:55:28 +00:00
|
|
|
return;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (BLI_findstring(lb, member, offsetof(LinkData, data)))
|
2010-08-22 14:15:28 +00:00
|
|
|
return;
|
2009-06-20 14:55:28 +00:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
link = MEM_callocN(sizeof(LinkData), "LinkData");
|
|
|
|
link->data = (void *)member;
|
2009-06-20 14:55:28 +00:00
|
|
|
BLI_addtail(lb, link);
|
|
|
|
}
|
|
|
|
|
2012-12-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* \param C Context
|
|
|
|
* \param use_store Use 'C->wm.store'
|
|
|
|
* \param use_rna Use Include the properties from 'RNA_Context'
|
|
|
|
* \param use_all Don't skip values (currently only "scene")
|
|
|
|
*/
|
|
|
|
ListBase CTX_data_dir_get_ex(const bContext *C, const short use_store, const short use_rna, const short use_all)
|
2009-06-20 14:55:28 +00:00
|
|
|
{
|
|
|
|
bContextDataResult result;
|
|
|
|
ListBase lb;
|
2012-05-02 14:22:22 +00:00
|
|
|
bScreen *sc;
|
|
|
|
ScrArea *sa;
|
|
|
|
ARegion *ar;
|
2009-06-20 14:55:28 +00:00
|
|
|
int a;
|
|
|
|
|
|
|
|
memset(&lb, 0, sizeof(lb));
|
|
|
|
|
2012-12-19 02:08:58 +00:00
|
|
|
if (use_rna) {
|
|
|
|
char name[256], *nameptr;
|
|
|
|
int namelen;
|
|
|
|
|
|
|
|
PropertyRNA *iterprop;
|
|
|
|
PointerRNA ctx_ptr;
|
|
|
|
RNA_pointer_create(NULL, &RNA_Context, (void *)C, &ctx_ptr);
|
|
|
|
|
|
|
|
iterprop = RNA_struct_iterator_property(ctx_ptr.type);
|
|
|
|
|
|
|
|
RNA_PROP_BEGIN (&ctx_ptr, itemptr, iterprop)
|
|
|
|
{
|
|
|
|
nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen);
|
|
|
|
data_dir_add(&lb, name, use_all);
|
|
|
|
if (nameptr) {
|
|
|
|
if (name != nameptr) {
|
|
|
|
MEM_freeN(nameptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RNA_PROP_END;
|
|
|
|
}
|
|
|
|
if (use_store && C->wm.store) {
|
2009-06-20 14:55:28 +00:00
|
|
|
bContextStoreEntry *entry;
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
for (entry = C->wm.store->entries.first; entry; entry = entry->next)
|
2012-12-19 02:08:58 +00:00
|
|
|
data_dir_add(&lb, entry->name, use_all);
|
2009-06-20 14:55:28 +00:00
|
|
|
}
|
2012-05-06 17:22:54 +00:00
|
|
|
if ((ar = CTX_wm_region(C)) && ar->type && ar->type->context) {
|
2009-06-20 14:55:28 +00:00
|
|
|
memset(&result, 0, sizeof(result));
|
2012-05-02 14:22:22 +00:00
|
|
|
ar->type->context(C, "", &result);
|
2009-06-20 14:55:28 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (result.dir)
|
2012-05-06 17:22:54 +00:00
|
|
|
for (a = 0; result.dir[a]; a++)
|
2012-12-19 02:08:58 +00:00
|
|
|
data_dir_add(&lb, result.dir[a], use_all);
|
2009-06-20 14:55:28 +00:00
|
|
|
}
|
2012-05-06 17:22:54 +00:00
|
|
|
if ((sa = CTX_wm_area(C)) && sa->type && sa->type->context) {
|
2009-06-20 14:55:28 +00:00
|
|
|
memset(&result, 0, sizeof(result));
|
2012-05-02 14:22:22 +00:00
|
|
|
sa->type->context(C, "", &result);
|
2009-06-20 14:55:28 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (result.dir)
|
2012-05-06 17:22:54 +00:00
|
|
|
for (a = 0; result.dir[a]; a++)
|
2012-12-19 02:08:58 +00:00
|
|
|
data_dir_add(&lb, result.dir[a], use_all);
|
2009-06-20 14:55:28 +00:00
|
|
|
}
|
2012-05-06 17:22:54 +00:00
|
|
|
if ((sc = CTX_wm_screen(C)) && sc->context) {
|
|
|
|
bContextDataCallback cb = sc->context;
|
2009-06-20 14:55:28 +00:00
|
|
|
memset(&result, 0, sizeof(result));
|
|
|
|
cb(C, "", &result);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (result.dir)
|
2012-05-06 17:22:54 +00:00
|
|
|
for (a = 0; result.dir[a]; a++)
|
2012-12-19 02:08:58 +00:00
|
|
|
data_dir_add(&lb, result.dir[a], use_all);
|
2009-06-20 14:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return lb;
|
|
|
|
}
|
|
|
|
|
2012-12-19 02:08:58 +00:00
|
|
|
ListBase CTX_data_dir_get(const bContext *C)
|
|
|
|
{
|
|
|
|
return CTX_data_dir_get_ex(C, TRUE, FALSE, FALSE);
|
|
|
|
}
|
|
|
|
|
2013-07-27 10:32:27 +00:00
|
|
|
bool CTX_data_equals(const char *member, const char *str)
|
2009-03-19 19:03:38 +00:00
|
|
|
{
|
|
|
|
return (strcmp(member, str) == 0);
|
|
|
|
}
|
|
|
|
|
2013-07-27 10:32:27 +00:00
|
|
|
bool CTX_data_dir(const char *member)
|
2009-06-20 14:55:28 +00:00
|
|
|
{
|
2011-05-01 06:34:40 +00:00
|
|
|
return member[0] == '\0';
|
2009-06-20 14:55:28 +00:00
|
|
|
}
|
|
|
|
|
2009-03-19 19:03:38 +00:00
|
|
|
void CTX_data_id_pointer_set(bContextDataResult *result, ID *id)
|
|
|
|
{
|
|
|
|
RNA_id_pointer_create(id, &result->ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_data_pointer_set(bContextDataResult *result, ID *id, StructRNA *type, void *data)
|
|
|
|
{
|
|
|
|
RNA_pointer_create(id, type, data, &result->ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_data_id_list_add(bContextDataResult *result, ID *id)
|
|
|
|
{
|
|
|
|
CollectionPointerLink *link;
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
link = MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_id_list_add");
|
2009-03-19 19:03:38 +00:00
|
|
|
RNA_id_pointer_create(id, &link->ptr);
|
|
|
|
|
|
|
|
BLI_addtail(&result->list, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_data_list_add(bContextDataResult *result, ID *id, StructRNA *type, void *data)
|
|
|
|
{
|
|
|
|
CollectionPointerLink *link;
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
link = MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_list_add");
|
2009-03-19 19:03:38 +00:00
|
|
|
RNA_pointer_create(id, type, data, &link->ptr);
|
2008-12-23 02:07:13 +00:00
|
|
|
|
|
|
|
BLI_addtail(&result->list, link);
|
|
|
|
}
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
int ctx_data_list_count(const bContext *C, int (*func)(const bContext *, ListBase *))
|
2009-01-17 00:51:42 +00:00
|
|
|
{
|
|
|
|
ListBase list;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (func(C, &list)) {
|
2012-05-06 17:22:54 +00:00
|
|
|
int tot = BLI_countlist(&list);
|
2009-02-07 13:39:54 +00:00
|
|
|
BLI_freelistN(&list);
|
|
|
|
return tot;
|
|
|
|
}
|
2009-01-17 00:51:42 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-20 14:55:28 +00:00
|
|
|
void CTX_data_dir_set(bContextDataResult *result, const char **dir)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
result->dir = dir;
|
2009-06-20 14:55:28 +00:00
|
|
|
}
|
|
|
|
|
2010-04-24 19:26:05 +00:00
|
|
|
void CTX_data_type_set(bContextDataResult *result, short type)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
result->type = type;
|
2010-04-24 19:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
short CTX_data_type_get(bContextDataResult *result)
|
|
|
|
{
|
|
|
|
return result->type;
|
|
|
|
}
|
|
|
|
|
2012-05-02 12:14:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* window manager context */
|
|
|
|
|
|
|
|
wmWindowManager *CTX_wm_manager(const bContext *C)
|
|
|
|
{
|
|
|
|
return C->wm.manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
wmWindow *CTX_wm_window(const bContext *C)
|
|
|
|
{
|
|
|
|
return ctx_wm_python_context_get(C, "window", C->wm.window);
|
|
|
|
}
|
|
|
|
|
|
|
|
bScreen *CTX_wm_screen(const bContext *C)
|
|
|
|
{
|
|
|
|
return ctx_wm_python_context_get(C, "screen", C->wm.screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
ScrArea *CTX_wm_area(const bContext *C)
|
|
|
|
{
|
|
|
|
return ctx_wm_python_context_get(C, "area", C->wm.area);
|
|
|
|
}
|
|
|
|
|
|
|
|
SpaceLink *CTX_wm_space_data(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
return (sa) ? sa->spacedata.first : NULL;
|
2012-05-02 12:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ARegion *CTX_wm_region(const bContext *C)
|
|
|
|
{
|
|
|
|
return ctx_wm_python_context_get(C, "region", C->wm.region);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *CTX_wm_region_data(const bContext *C)
|
|
|
|
{
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
return (ar) ? ar->regiondata : NULL;
|
2012-05-02 12:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ARegion *CTX_wm_menu(const bContext *C)
|
|
|
|
{
|
|
|
|
return C->wm.menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ReportList *CTX_wm_reports(const bContext *C)
|
|
|
|
{
|
|
|
|
if (C->wm.manager)
|
|
|
|
return &(C->wm.manager->reports);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
View3D *CTX_wm_view3d(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_VIEW3D)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegionView3D *CTX_wm_region_view3d(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-02 14:22:22 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_VIEW3D)
|
2012-05-02 14:22:22 +00:00
|
|
|
if (ar)
|
|
|
|
return ar->regiondata;
|
2012-05-02 12:14:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceText *CTX_wm_space_text(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_TEXT)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceConsole *CTX_wm_space_console(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_CONSOLE)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceImage *CTX_wm_space_image(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_IMAGE)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceButs *CTX_wm_space_buts(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_BUTS)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceFile *CTX_wm_space_file(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_FILE)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceSeq *CTX_wm_space_seq(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_SEQ)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceOops *CTX_wm_space_outliner(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_OUTLINER)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceNla *CTX_wm_space_nla(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_NLA)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceTime *CTX_wm_space_time(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_TIME)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceNode *CTX_wm_space_node(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_NODE)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceLogic *CTX_wm_space_logic(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_LOGIC)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceIpo *CTX_wm_space_graph(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_IPO)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceAction *CTX_wm_space_action(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_ACTION)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceInfo *CTX_wm_space_info(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_INFO)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_USERPREF)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpaceClip *CTX_wm_space_clip(const bContext *C)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-05-06 17:22:54 +00:00
|
|
|
if (sa && sa->spacetype == SPACE_CLIP)
|
2012-05-02 12:14:27 +00:00
|
|
|
return sa->spacedata.first;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
C->wm.manager = wm;
|
|
|
|
C->wm.window = NULL;
|
|
|
|
C->wm.screen = NULL;
|
|
|
|
C->wm.area = NULL;
|
|
|
|
C->wm.region = NULL;
|
2012-05-02 12:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_wm_window_set(bContext *C, wmWindow *win)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
C->wm.window = win;
|
|
|
|
C->wm.screen = (win) ? win->screen : NULL;
|
2012-05-02 12:14:27 +00:00
|
|
|
if (C->wm.screen)
|
2012-05-06 17:22:54 +00:00
|
|
|
C->data.scene = C->wm.screen->scene;
|
|
|
|
C->wm.area = NULL;
|
|
|
|
C->wm.region = NULL;
|
2012-05-02 12:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_wm_screen_set(bContext *C, bScreen *screen)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
C->wm.screen = screen;
|
2012-05-02 12:14:27 +00:00
|
|
|
if (C->wm.screen)
|
2012-05-06 17:22:54 +00:00
|
|
|
C->data.scene = C->wm.screen->scene;
|
|
|
|
C->wm.area = NULL;
|
|
|
|
C->wm.region = NULL;
|
2012-05-02 12:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_wm_area_set(bContext *C, ScrArea *area)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
C->wm.area = area;
|
|
|
|
C->wm.region = NULL;
|
2012-05-02 12:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_wm_region_set(bContext *C, ARegion *region)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
C->wm.region = region;
|
2012-05-02 12:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_wm_menu_set(bContext *C, ARegion *menu)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
C->wm.menu = menu;
|
2012-05-02 12:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
C->wm.operator_poll_msg = msg;
|
2012-05-02 12:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *CTX_wm_operator_poll_msg_get(bContext *C)
|
|
|
|
{
|
2013-02-19 15:45:56 +00:00
|
|
|
return IFACE_(C->wm.operator_poll_msg);
|
2012-05-02 12:14:27 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
/* data context */
|
|
|
|
|
|
|
|
Main *CTX_data_main(const bContext *C)
|
|
|
|
{
|
|
|
|
Main *bmain;
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
if (ctx_data_pointer_verify(C, "blend_data", (void *)&bmain))
|
2008-12-18 02:56:48 +00:00
|
|
|
return bmain;
|
|
|
|
else
|
|
|
|
return C->data.main;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTX_data_main_set(bContext *C, Main *bmain)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
C->data.main = bmain;
|
2008-12-18 02:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Scene *CTX_data_scene(const bContext *C)
|
|
|
|
{
|
|
|
|
Scene *scene;
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
if (ctx_data_pointer_verify(C, "scene", (void *)&scene))
|
2008-12-18 02:56:48 +00:00
|
|
|
return scene;
|
|
|
|
else
|
|
|
|
return C->data.scene;
|
|
|
|
}
|
|
|
|
|
2009-08-16 03:40:00 +00:00
|
|
|
int CTX_data_mode_enum(const bContext *C)
|
2009-08-15 19:40:09 +00:00
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
Object *obedit = CTX_data_edit_object(C);
|
2009-08-15 19:40:09 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (obedit) {
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (obedit->type) {
|
2009-08-15 19:40:09 +00:00
|
|
|
case OB_MESH:
|
2009-08-16 03:40:00 +00:00
|
|
|
return CTX_MODE_EDIT_MESH;
|
2009-08-15 19:40:09 +00:00
|
|
|
case OB_CURVE:
|
2009-08-16 03:40:00 +00:00
|
|
|
return CTX_MODE_EDIT_CURVE;
|
2009-08-15 19:40:09 +00:00
|
|
|
case OB_SURF:
|
2009-08-16 03:40:00 +00:00
|
|
|
return CTX_MODE_EDIT_SURFACE;
|
2009-08-15 19:40:09 +00:00
|
|
|
case OB_FONT:
|
2009-08-16 03:40:00 +00:00
|
|
|
return CTX_MODE_EDIT_TEXT;
|
2009-08-15 19:40:09 +00:00
|
|
|
case OB_ARMATURE:
|
2009-08-16 03:40:00 +00:00
|
|
|
return CTX_MODE_EDIT_ARMATURE;
|
2009-08-15 19:40:09 +00:00
|
|
|
case OB_MBALL:
|
2009-08-16 03:40:00 +00:00
|
|
|
return CTX_MODE_EDIT_METABALL;
|
2009-08-15 19:40:09 +00:00
|
|
|
case OB_LATTICE:
|
2009-08-16 03:40:00 +00:00
|
|
|
return CTX_MODE_EDIT_LATTICE;
|
2009-08-15 19:40:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
2009-08-16 03:40:00 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ob) {
|
|
|
|
if (ob->mode & OB_MODE_POSE) return CTX_MODE_POSE;
|
2012-05-06 17:22:54 +00:00
|
|
|
else if (ob->mode & OB_MODE_SCULPT) return CTX_MODE_SCULPT;
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (ob->mode & OB_MODE_WEIGHT_PAINT) return CTX_MODE_PAINT_WEIGHT;
|
|
|
|
else if (ob->mode & OB_MODE_VERTEX_PAINT) return CTX_MODE_PAINT_VERTEX;
|
|
|
|
else if (ob->mode & OB_MODE_TEXTURE_PAINT) return CTX_MODE_PAINT_TEXTURE;
|
|
|
|
else if (ob->mode & OB_MODE_PARTICLE_EDIT) return CTX_MODE_PARTICLE;
|
2009-08-16 01:25:53 +00:00
|
|
|
}
|
2009-08-15 19:40:09 +00:00
|
|
|
}
|
2009-08-16 03:40:00 +00:00
|
|
|
|
|
|
|
return CTX_MODE_OBJECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* would prefer if we can use the enum version below over this one - Campbell */
|
|
|
|
/* must be aligned with above enum */
|
2010-12-03 17:05:21 +00:00
|
|
|
static const char *data_mode_strings[] = {
|
2009-08-16 03:40:00 +00:00
|
|
|
"mesh_edit",
|
|
|
|
"curve_edit",
|
|
|
|
"surface_edit",
|
|
|
|
"text_edit",
|
|
|
|
"armature_edit",
|
|
|
|
"mball_edit",
|
|
|
|
"lattice_edit",
|
|
|
|
"posemode",
|
|
|
|
"sculpt_mode",
|
|
|
|
"weightpaint",
|
|
|
|
"vertexpaint",
|
2011-04-01 04:22:30 +00:00
|
|
|
"imagepaint",
|
2009-08-16 03:40:00 +00:00
|
|
|
"particlemode",
|
|
|
|
"objectmode",
|
2011-02-13 10:52:18 +00:00
|
|
|
NULL
|
2009-08-16 03:40:00 +00:00
|
|
|
};
|
2010-12-03 17:05:21 +00:00
|
|
|
const char *CTX_data_mode_string(const bContext *C)
|
2009-08-16 03:40:00 +00:00
|
|
|
{
|
|
|
|
return data_mode_strings[CTX_data_mode_enum(C)];
|
2009-08-15 19:40:09 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
void CTX_data_scene_set(bContext *C, Scene *scene)
|
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
C->data.scene = scene;
|
2008-12-18 02:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ToolSettings *CTX_data_tool_settings(const bContext *C)
|
|
|
|
{
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (scene)
|
2008-12-18 02:56:48 +00:00
|
|
|
return scene->toolsettings;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-02 23:58:03 +00:00
|
|
|
int CTX_data_selected_nodes(const bContext *C, ListBase *list)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_collection_get(C, "selected_nodes", list);
|
2009-01-02 23:58:03 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 18:35:33 +00:00
|
|
|
int CTX_data_selected_editable_objects(const bContext *C, ListBase *list)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_collection_get(C, "selected_editable_objects", list);
|
2009-01-17 18:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CTX_data_selected_editable_bases(const bContext *C, ListBase *list)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_collection_get(C, "selected_editable_bases", list);
|
2009-01-17 18:35:33 +00:00
|
|
|
}
|
|
|
|
|
2008-12-23 02:07:13 +00:00
|
|
|
int CTX_data_selected_objects(const bContext *C, ListBase *list)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_collection_get(C, "selected_objects", list);
|
2008-12-23 02:07:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CTX_data_selected_bases(const bContext *C, ListBase *list)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_collection_get(C, "selected_bases", list);
|
2008-12-23 02:07:13 +00:00
|
|
|
}
|
|
|
|
|
2008-12-28 18:10:24 +00:00
|
|
|
int CTX_data_visible_objects(const bContext *C, ListBase *list)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_collection_get(C, "visible_objects", list);
|
2008-12-28 18:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CTX_data_visible_bases(const bContext *C, ListBase *list)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_collection_get(C, "visible_bases", list);
|
2008-12-28 18:10:24 +00:00
|
|
|
}
|
|
|
|
|
2009-07-11 11:31:49 +00:00
|
|
|
int CTX_data_selectable_objects(const bContext *C, ListBase *list)
|
|
|
|
{
|
|
|
|
return ctx_data_collection_get(C, "selectable_objects", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CTX_data_selectable_bases(const bContext *C, ListBase *list)
|
|
|
|
{
|
|
|
|
return ctx_data_collection_get(C, "selectable_bases", list);
|
|
|
|
}
|
|
|
|
|
2008-12-23 02:07:13 +00:00
|
|
|
struct Object *CTX_data_active_object(const bContext *C)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_pointer_get(C, "active_object");
|
2008-12-23 02:07:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Base *CTX_data_active_base(const bContext *C)
|
2008-12-18 02:56:48 +00:00
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_pointer_get(C, "active_base");
|
2008-12-18 02:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Object *CTX_data_edit_object(const bContext *C)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_pointer_get(C, "edit_object");
|
2008-12-18 02:56:48 +00:00
|
|
|
}
|
|
|
|
|
2.5: Space Image ported back
Organized as follows:
uvedit/
uv editing related code
uvedit_draw.c: drawing code
uvedit_ops.c: operators, just a few done
uvedit_unwrap_ops.c: will be operators for unwrapping
uvedit_paramatrizer.c: lscm/abf/stretch/pack
space_image/
space_image.c: registration and common getter/setters
image_draw.c: drawing code, mostly functional
image_panels.c: panels, all commented out
image_render.c: render callbacks, non functional
image_ops.c: operators, only view navigation done
image_header.c: header, menus mostly done but missing buttons
Notes:
* Header menus consist only of Operator and RNA buttons, if they
are not implemented they're displayed grayed out. Ideally the full
header could work like this, but std_libbuttons looks problematic.
* Started using view2d code more than the old code, but for now it
still does own view2d management due to some very specific
requirements that the image window has. The drawing code however
is more clear hopefully, it only uses view2d, and there is no
switching between 'p' and 'f' view2d's anymore, it is always 'f'.
* In order to make uvedit operators more independent I move some
image space settings to scene toolsettings, and the current image
and its buffer is in the context. Especially sync selection and
select mode belonged there anyway as this cannot work correct with
different spaces having different settings anyway.
* Image paint is not back yet, did not want to put that together with
uvedit because there's really no code sharing.. perhaps vertex paint,
image paint and sculpt would be good to have in one module to share
brush code, partial redraw, etc better.
2009-01-15 04:38:18 +00:00
|
|
|
struct Image *CTX_data_edit_image(const bContext *C)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_pointer_get(C, "edit_image");
|
2.5: Space Image ported back
Organized as follows:
uvedit/
uv editing related code
uvedit_draw.c: drawing code
uvedit_ops.c: operators, just a few done
uvedit_unwrap_ops.c: will be operators for unwrapping
uvedit_paramatrizer.c: lscm/abf/stretch/pack
space_image/
space_image.c: registration and common getter/setters
image_draw.c: drawing code, mostly functional
image_panels.c: panels, all commented out
image_render.c: render callbacks, non functional
image_ops.c: operators, only view navigation done
image_header.c: header, menus mostly done but missing buttons
Notes:
* Header menus consist only of Operator and RNA buttons, if they
are not implemented they're displayed grayed out. Ideally the full
header could work like this, but std_libbuttons looks problematic.
* Started using view2d code more than the old code, but for now it
still does own view2d management due to some very specific
requirements that the image window has. The drawing code however
is more clear hopefully, it only uses view2d, and there is no
switching between 'p' and 'f' view2d's anymore, it is always 'f'.
* In order to make uvedit operators more independent I move some
image space settings to scene toolsettings, and the current image
and its buffer is in the context. Especially sync selection and
select mode belonged there anyway as this cannot work correct with
different spaces having different settings anyway.
* Image paint is not back yet, did not want to put that together with
uvedit because there's really no code sharing.. perhaps vertex paint,
image paint and sculpt would be good to have in one module to share
brush code, partial redraw, etc better.
2009-01-15 04:38:18 +00:00
|
|
|
}
|
|
|
|
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
struct Text *CTX_data_edit_text(const bContext *C)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_pointer_get(C, "edit_text");
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
}
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
struct MovieClip *CTX_data_edit_movieclip(const bContext *C)
|
|
|
|
{
|
|
|
|
return ctx_data_pointer_get(C, "edit_movieclip");
|
|
|
|
}
|
|
|
|
|
2012-06-04 16:42:58 +00:00
|
|
|
struct Mask *CTX_data_edit_mask(const bContext *C)
|
|
|
|
{
|
|
|
|
return ctx_data_pointer_get(C, "edit_mask");
|
|
|
|
}
|
|
|
|
|
2009-02-05 03:28:07 +00:00
|
|
|
struct EditBone *CTX_data_active_bone(const bContext *C)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_pointer_get(C, "active_bone");
|
2009-02-05 03:28:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CTX_data_selected_bones(const bContext *C, ListBase *list)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_collection_get(C, "selected_bones", list);
|
2009-02-05 03:28:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CTX_data_selected_editable_bones(const bContext *C, ListBase *list)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_collection_get(C, "selected_editable_bones", list);
|
2009-02-05 03:28:07 +00:00
|
|
|
}
|
|
|
|
|
2009-02-14 07:27:12 +00:00
|
|
|
int CTX_data_visible_bones(const bContext *C, ListBase *list)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_collection_get(C, "visible_bones", list);
|
2009-02-14 07:27:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CTX_data_editable_bones(const bContext *C, ListBase *list)
|
|
|
|
{
|
2009-03-19 19:03:38 +00:00
|
|
|
return ctx_data_collection_get(C, "editable_bones", list);
|
2009-02-14 07:27:12 +00:00
|
|
|
}
|
|
|
|
|
2009-11-24 17:12:32 +00:00
|
|
|
struct bPoseChannel *CTX_data_active_pose_bone(const bContext *C)
|
2009-02-05 03:28:07 +00:00
|
|
|
{
|
2009-11-24 17:12:32 +00:00
|
|
|
return ctx_data_pointer_get(C, "active_pose_bone");
|
2009-02-05 03:28:07 +00:00
|
|
|
}
|
|
|
|
|
2009-11-25 15:00:29 +00:00
|
|
|
int CTX_data_selected_pose_bones(const bContext *C, ListBase *list)
|
2009-02-05 03:28:07 +00:00
|
|
|
{
|
2009-11-25 15:00:29 +00:00
|
|
|
return ctx_data_collection_get(C, "selected_pose_bones", list);
|
2009-02-05 03:28:07 +00:00
|
|
|
}
|
|
|
|
|
2009-11-25 15:00:29 +00:00
|
|
|
int CTX_data_visible_pose_bones(const bContext *C, ListBase *list)
|
2009-02-14 07:27:12 +00:00
|
|
|
{
|
2009-11-25 15:00:29 +00:00
|
|
|
return ctx_data_collection_get(C, "visible_pose_bones", list);
|
2009-02-14 07:27:12 +00:00
|
|
|
}
|
|
|
|
|