From 0ce5163cc0aa32df5450752da9056059a88f1fd5 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Sat, 15 Aug 2009 19:40:09 +0000 Subject: 2.5 3D_View: Patch [#19031] (2.5) python menus for the view3d header by Lorenzo Pierfederici (lento). Thanks! * Added CTX_data_mode_string() to find out in which mode we're in. * Added some "select" menus as a test. This patch makes it basically possible to wrap the 3D View menus to python. --- source/blender/blenkernel/BKE_context.h | 2 ++ source/blender/blenkernel/intern/context.c | 38 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h index e47ad969b91..81dea204dd0 100644 --- a/source/blender/blenkernel/BKE_context.h +++ b/source/blender/blenkernel/BKE_context.h @@ -191,6 +191,8 @@ struct Main *CTX_data_main(const bContext *C); struct Scene *CTX_data_scene(const bContext *C); struct ToolSettings *CTX_data_tool_settings(const bContext *C); +char *CTX_data_mode_string(const bContext *C); + void CTX_data_main_set(bContext *C, struct Main *bmain); void CTX_data_scene_set(bContext *C, struct Scene *bmain); diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index d1e228f83b6..df5b0d766b5 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -34,6 +34,7 @@ #include "DNA_space_types.h" #include "DNA_view3d_types.h" #include "DNA_windowmanager_types.h" +#include "DNA_object_types.h" #include "RNA_access.h" @@ -43,6 +44,7 @@ #include "BKE_context.h" #include "BKE_main.h" #include "BKE_screen.h" +#include "BKE_global.h" #include @@ -659,6 +661,42 @@ Scene *CTX_data_scene(const bContext *C) return C->data.scene; } +char *CTX_data_mode_string(const bContext *C) +{ + Object *obedit= CTX_data_edit_object(C); + + if(obedit) { + switch(obedit->type) { + case OB_MESH: + return "meshedit"; + case OB_CURVE: + return "curveedit"; + case OB_SURF: + return "surfaceedit"; + case OB_FONT: + return "textedit"; + case OB_ARMATURE: + return "armatureedit"; + case OB_MBALL: + return "mballedit"; + case OB_LATTICE: + return "latticeedit"; + } + } + else { + Object *ob = CTX_data_active_object(C); + + if(ob && (ob->flag & OB_POSEMODE)) return "posemode"; + else if (ob && ob->mode & OB_MODE_SCULPT) return "sculpt_mode"; + else if (G.f & G_WEIGHTPAINT) return "weightpaint"; + else if (G.f & G_VERTEXPAINT) return "vertexpaint"; + else if (G.f & G_TEXTUREPAINT) return "texturepaint"; + else if(G.f & G_PARTICLEEDIT) return "particlemode"; + } + + return "objectmode"; +} + void CTX_data_scene_set(bContext *C, Scene *scene) { C->data.scene= scene; -- cgit v1.2.3