Blender  V2.59
rna_context.c
Go to the documentation of this file.
00001 /*
00002  * $Id: rna_context.c 35238 2011-02-27 20:20:01Z 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  * Contributor(s): Blender Foundation (2009).
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #include <stdlib.h>
00031 
00032 #include "DNA_ID.h"
00033 #include "DNA_userdef_types.h"
00034 
00035 #include "RNA_access.h"
00036 #include "RNA_define.h"
00037 
00038 #include "BKE_context.h"
00039 
00040 #ifdef RNA_RUNTIME
00041 
00042 static PointerRNA rna_Context_manager_get(PointerRNA *ptr)
00043 {
00044         bContext *C= (bContext*)ptr->data;
00045         return rna_pointer_inherit_refine(ptr, &RNA_WindowManager, CTX_wm_manager(C));
00046 }
00047 
00048 static PointerRNA rna_Context_window_get(PointerRNA *ptr)
00049 {
00050         bContext *C= (bContext*)ptr->data;
00051         return rna_pointer_inherit_refine(ptr, &RNA_Window, CTX_wm_window(C));
00052 }
00053 
00054 static PointerRNA rna_Context_screen_get(PointerRNA *ptr)
00055 {
00056         bContext *C= (bContext*)ptr->data;
00057         return rna_pointer_inherit_refine(ptr, &RNA_Screen, CTX_wm_screen(C));
00058 }
00059 
00060 static PointerRNA rna_Context_area_get(PointerRNA *ptr)
00061 {
00062         bContext *C= (bContext*)ptr->data;
00063         PointerRNA newptr;
00064         RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_Area, CTX_wm_area(C), &newptr);
00065         return newptr;
00066 }
00067 
00068 static PointerRNA rna_Context_space_data_get(PointerRNA *ptr)
00069 {
00070         bContext *C= (bContext*)ptr->data;
00071         PointerRNA newptr;
00072         RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_Space, CTX_wm_space_data(C), &newptr);
00073         return newptr;
00074 }
00075 
00076 static PointerRNA rna_Context_region_get(PointerRNA *ptr)
00077 {
00078         bContext *C= (bContext*)ptr->data;
00079         PointerRNA newptr;
00080         RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_Region, CTX_wm_region(C), &newptr);
00081         return newptr;
00082 }
00083 
00084 static PointerRNA rna_Context_region_data_get(PointerRNA *ptr)
00085 {
00086         bContext *C= (bContext*)ptr->data;
00087 
00088         /* only exists for one space still, no generic system yet */
00089         if(CTX_wm_view3d(C)) {
00090                 PointerRNA newptr;
00091                 RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_RegionView3D, CTX_wm_region_data(C), &newptr);
00092                 return newptr;
00093         }
00094 
00095         return PointerRNA_NULL;
00096 }
00097 
00098 static PointerRNA rna_Context_main_get(PointerRNA *ptr)
00099 {
00100         bContext *C= (bContext*)ptr->data;
00101         return rna_pointer_inherit_refine(ptr, &RNA_BlendData, CTX_data_main(C));
00102 }
00103 
00104 static PointerRNA rna_Context_scene_get(PointerRNA *ptr)
00105 {
00106         bContext *C= (bContext*)ptr->data;
00107         return rna_pointer_inherit_refine(ptr, &RNA_Scene, CTX_data_scene(C));
00108 }
00109 
00110 static PointerRNA rna_Context_tool_settings_get(PointerRNA *ptr)
00111 {
00112         bContext *C= (bContext*)ptr->data;
00113         ptr->id.data= CTX_data_scene(C);
00114         return rna_pointer_inherit_refine(ptr, &RNA_ToolSettings, CTX_data_tool_settings(C));
00115 }
00116 
00117 static PointerRNA rna_Context_user_preferences_get(PointerRNA *ptr)
00118 {
00119         PointerRNA newptr;
00120         RNA_pointer_create(NULL, &RNA_UserPreferences, &U, &newptr);
00121         return newptr;
00122 }
00123 
00124 static int rna_Context_mode_get(PointerRNA *ptr)
00125 {
00126         bContext *C= (bContext*)ptr->data;
00127         return CTX_data_mode_enum(C);
00128 }
00129 
00130 #else
00131 
00132 void RNA_def_context(BlenderRNA *brna)
00133 {
00134         StructRNA *srna;
00135         PropertyRNA *prop;
00136 
00137         static EnumPropertyItem mode_items[] = {
00138                 {CTX_MODE_EDIT_MESH, "EDIT_MESH", 0, "Mesh Edit", ""},
00139                 {CTX_MODE_EDIT_CURVE, "EDIT_CURVE", 0, "Curve Edit", ""},
00140                 {CTX_MODE_EDIT_SURFACE, "EDIT_SURFACE", 0, "Surface Edit", ""},
00141                 {CTX_MODE_EDIT_TEXT, "EDIT_TEXT", 0, "Edit Edit", ""},
00142                 {CTX_MODE_EDIT_ARMATURE, "EDIT_ARMATURE", 0, "Armature Edit", ""}, // PARSKEL reuse will give issues
00143                 {CTX_MODE_EDIT_METABALL, "EDIT_METABALL", 0, "Metaball Edit", ""},
00144                 {CTX_MODE_EDIT_LATTICE, "EDIT_LATTICE", 0, "Lattice Edit", ""},
00145                 {CTX_MODE_POSE, "POSE", 0, "Pose ", ""},
00146                 {CTX_MODE_SCULPT, "SCULPT", 0, "Sculpt", ""},
00147                 {CTX_MODE_PAINT_WEIGHT, "PAINT_WEIGHT", 0, "Weight Paint", ""},
00148                 {CTX_MODE_PAINT_VERTEX, "PAINT_VERTEX", 0, "Vertex Paint", ""},
00149                 {CTX_MODE_PAINT_TEXTURE, "PAINT_TEXTURE", 0, "Texture Paint", ""},
00150                 {CTX_MODE_PARTICLE, "PARTICLE", 0, "Particle", ""},
00151                 {CTX_MODE_OBJECT, "OBJECT", 0, "Object", ""},
00152                 {0, NULL, 0, NULL, NULL}};
00153 
00154         srna= RNA_def_struct(brna, "Context", NULL);
00155         RNA_def_struct_ui_text(srna, "Context", "Current windowmanager and data context");
00156         RNA_def_struct_sdna(srna, "bContext");
00157 
00158         /* WM */
00159         prop= RNA_def_property(srna, "window_manager", PROP_POINTER, PROP_NONE);
00160         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00161         RNA_def_property_struct_type(prop, "WindowManager");
00162         RNA_def_property_pointer_funcs(prop, "rna_Context_manager_get", NULL, NULL, NULL);
00163 
00164         prop= RNA_def_property(srna, "window", PROP_POINTER, PROP_NONE);
00165         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00166         RNA_def_property_struct_type(prop, "Window");
00167         RNA_def_property_pointer_funcs(prop, "rna_Context_window_get", NULL, NULL, NULL);
00168 
00169         prop= RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE);
00170         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00171         RNA_def_property_struct_type(prop, "Screen");
00172         RNA_def_property_pointer_funcs(prop, "rna_Context_screen_get", NULL, NULL, NULL);
00173 
00174         prop= RNA_def_property(srna, "area", PROP_POINTER, PROP_NONE);
00175         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00176         RNA_def_property_struct_type(prop, "Area");
00177         RNA_def_property_pointer_funcs(prop, "rna_Context_area_get", NULL, NULL, NULL);
00178 
00179         prop= RNA_def_property(srna, "space_data", PROP_POINTER, PROP_NONE);
00180         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00181         RNA_def_property_struct_type(prop, "Space");
00182         RNA_def_property_pointer_funcs(prop, "rna_Context_space_data_get", NULL, NULL, NULL);
00183 
00184         prop= RNA_def_property(srna, "region", PROP_POINTER, PROP_NONE);
00185         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00186         RNA_def_property_struct_type(prop, "Region");
00187         RNA_def_property_pointer_funcs(prop, "rna_Context_region_get", NULL, NULL, NULL);
00188 
00189         prop= RNA_def_property(srna, "region_data", PROP_POINTER, PROP_NONE);
00190         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00191         RNA_def_property_struct_type(prop, "RegionView3D");
00192         RNA_def_property_pointer_funcs(prop, "rna_Context_region_data_get", NULL, NULL, NULL);
00193 
00194         /* Data */
00195         prop= RNA_def_property(srna, "blend_data", PROP_POINTER, PROP_NONE);
00196         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00197         RNA_def_property_struct_type(prop, "BlendData");
00198         RNA_def_property_pointer_funcs(prop, "rna_Context_main_get", NULL, NULL, NULL);
00199 
00200         prop= RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
00201         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00202         RNA_def_property_struct_type(prop, "Scene");
00203         RNA_def_property_pointer_funcs(prop, "rna_Context_scene_get", NULL, NULL, NULL);
00204 
00205         prop= RNA_def_property(srna, "tool_settings", PROP_POINTER, PROP_NONE);
00206         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00207         RNA_def_property_struct_type(prop, "ToolSettings");
00208         RNA_def_property_pointer_funcs(prop, "rna_Context_tool_settings_get", NULL, NULL, NULL);
00209 
00210         prop= RNA_def_property(srna, "user_preferences", PROP_POINTER, PROP_NONE);
00211         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00212         RNA_def_property_struct_type(prop, "UserPreferences");
00213         RNA_def_property_pointer_funcs(prop, "rna_Context_user_preferences_get", NULL, NULL, NULL);
00214 
00215         prop= RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
00216         RNA_def_property_enum_items(prop, mode_items);
00217         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00218         RNA_def_property_enum_funcs(prop, "rna_Context_mode_get", NULL, NULL);
00219 }
00220 
00221 #endif
00222