Changeset View
Standalone View
source/blender/makesrna/intern/rna_context.c
| Show First 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static PointerRNA rna_Context_main_get(PointerRNA *ptr) | static PointerRNA rna_Context_main_get(PointerRNA *ptr) | ||||
| { | { | ||||
| bContext *C = (bContext *)ptr->data; | bContext *C = (bContext *)ptr->data; | ||||
| return rna_pointer_inherit_refine(ptr, &RNA_BlendData, CTX_data_main(C)); | return rna_pointer_inherit_refine(ptr, &RNA_BlendData, CTX_data_main(C)); | ||||
| } | } | ||||
| static PointerRNA rna_Context_depsgraph_get(PointerRNA *ptr) | |||||
| { | |||||
| bContext *C = (bContext *)ptr->data; | |||||
| return rna_pointer_inherit_refine(ptr, &RNA_Depsgraph, CTX_data_depsgraph(C)); | |||||
| } | |||||
| static PointerRNA rna_Context_scene_get(PointerRNA *ptr) | static PointerRNA rna_Context_scene_get(PointerRNA *ptr) | ||||
| { | { | ||||
| bContext *C = (bContext *)ptr->data; | bContext *C = (bContext *)ptr->data; | ||||
| return rna_pointer_inherit_refine(ptr, &RNA_Scene, CTX_data_scene(C)); | return rna_pointer_inherit_refine(ptr, &RNA_Scene, CTX_data_scene(C)); | ||||
| } | } | ||||
| static PointerRNA rna_Context_view_layer_get(PointerRNA *ptr) | static PointerRNA rna_Context_view_layer_get(PointerRNA *ptr) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static int rna_Context_mode_get(PointerRNA *ptr) | static int rna_Context_mode_get(PointerRNA *ptr) | ||||
| { | { | ||||
| bContext *C = (bContext *)ptr->data; | bContext *C = (bContext *)ptr->data; | ||||
| return CTX_data_mode_enum(C); | return CTX_data_mode_enum(C); | ||||
| } | } | ||||
| static struct Depsgraph *rna_Context_evaluated_depsgraph_get(bContext *C) | |||||
| { | |||||
| return CTX_data_evaluated_depsgraph(C); | |||||
| } | |||||
| #else | #else | ||||
| void RNA_def_context(BlenderRNA *brna) | void RNA_def_context(BlenderRNA *brna) | ||||
| { | { | ||||
| StructRNA *srna; | StructRNA *srna; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| FunctionRNA *func; | |||||
| PropertyRNA *parm; | |||||
| srna = RNA_def_struct(brna, "Context", NULL); | srna = RNA_def_struct(brna, "Context", NULL); | ||||
| RNA_def_struct_ui_text(srna, "Context", "Current windowmanager and data context"); | RNA_def_struct_ui_text(srna, "Context", "Current windowmanager and data context"); | ||||
| RNA_def_struct_sdna(srna, "bContext"); | RNA_def_struct_sdna(srna, "bContext"); | ||||
| /* WM */ | /* WM */ | ||||
| prop = RNA_def_property(srna, "window_manager", PROP_POINTER, PROP_NONE); | prop = RNA_def_property(srna, "window_manager", PROP_POINTER, PROP_NONE); | ||||
| RNA_def_property_clear_flag(prop, PROP_EDITABLE); | RNA_def_property_clear_flag(prop, PROP_EDITABLE); | ||||
| RNA_def_property_struct_type(prop, "WindowManager"); | RNA_def_property_struct_type(prop, "WindowManager"); | ||||
| Show All 40 Lines | void RNA_def_context(BlenderRNA *brna) | ||||
| RNA_def_property_pointer_funcs(prop, "rna_Context_gizmo_group_get", NULL, NULL, NULL); | RNA_def_property_pointer_funcs(prop, "rna_Context_gizmo_group_get", NULL, NULL, NULL); | ||||
| /* Data */ | /* Data */ | ||||
| prop = RNA_def_property(srna, "blend_data", PROP_POINTER, PROP_NONE); | prop = RNA_def_property(srna, "blend_data", PROP_POINTER, PROP_NONE); | ||||
| RNA_def_property_clear_flag(prop, PROP_EDITABLE); | RNA_def_property_clear_flag(prop, PROP_EDITABLE); | ||||
| RNA_def_property_struct_type(prop, "BlendData"); | RNA_def_property_struct_type(prop, "BlendData"); | ||||
| RNA_def_property_pointer_funcs(prop, "rna_Context_main_get", NULL, NULL, NULL); | RNA_def_property_pointer_funcs(prop, "rna_Context_main_get", NULL, NULL, NULL); | ||||
| prop = RNA_def_property(srna, "depsgraph", PROP_POINTER, PROP_NONE); | |||||
| RNA_def_property_clear_flag(prop, PROP_EDITABLE); | |||||
| RNA_def_property_struct_type(prop, "Depsgraph"); | |||||
| RNA_def_property_pointer_funcs(prop, "rna_Context_depsgraph_get", NULL, NULL, NULL); | |||||
| prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE); | prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE); | ||||
| RNA_def_property_clear_flag(prop, PROP_EDITABLE); | RNA_def_property_clear_flag(prop, PROP_EDITABLE); | ||||
| RNA_def_property_struct_type(prop, "Scene"); | RNA_def_property_struct_type(prop, "Scene"); | ||||
| RNA_def_property_pointer_funcs(prop, "rna_Context_scene_get", NULL, NULL, NULL); | RNA_def_property_pointer_funcs(prop, "rna_Context_scene_get", NULL, NULL, NULL); | ||||
| prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE); | prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE); | ||||
| RNA_def_property_clear_flag(prop, PROP_EDITABLE); | RNA_def_property_clear_flag(prop, PROP_EDITABLE); | ||||
| RNA_def_property_struct_type(prop, "ViewLayer"); | RNA_def_property_struct_type(prop, "ViewLayer"); | ||||
| Show All 22 Lines | void RNA_def_context(BlenderRNA *brna) | ||||
| RNA_def_property_clear_flag(prop, PROP_EDITABLE); | RNA_def_property_clear_flag(prop, PROP_EDITABLE); | ||||
| RNA_def_property_struct_type(prop, "Preferences"); | RNA_def_property_struct_type(prop, "Preferences"); | ||||
| RNA_def_property_pointer_funcs(prop, "rna_Context_preferences_get", NULL, NULL, NULL); | RNA_def_property_pointer_funcs(prop, "rna_Context_preferences_get", NULL, NULL, NULL); | ||||
| prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); | prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); | ||||
| RNA_def_property_enum_items(prop, rna_enum_context_mode_items); | RNA_def_property_enum_items(prop, rna_enum_context_mode_items); | ||||
| RNA_def_property_clear_flag(prop, PROP_EDITABLE); | RNA_def_property_clear_flag(prop, PROP_EDITABLE); | ||||
| RNA_def_property_enum_funcs(prop, "rna_Context_mode_get", NULL, NULL); | RNA_def_property_enum_funcs(prop, "rna_Context_mode_get", NULL, NULL); | ||||
| func = RNA_def_function(srna, "evaluated_depsgraph_get", "rna_Context_evaluated_depsgraph_get"); | |||||
brecht: I think the convention is for API functions to start with the verb? So this would be… | |||||
Done Inline ActionsEugh. In C i think we've got verb as a suffix. A bit confusing, but fine changing it in Python API. evaluate_depsgraph() indeed sounds in a way that implies there is work to be done. But it doesn't imply that it gives you dependency graph. Is it more like evaluate_and_get_depsgraph()? Kinda too verbose. sergey: Eugh. In C i think we've got verb as a suffix. A bit confusing, but fine changing it in Python… | |||||
Not Done Inline ActionsI don’t think so? That would be opposite of our C 'API' conventions. And in rna_object_api.c e.g. all accessor functions end with _get()/_set()… Think the one starting with a verb are older ones? mont29: I don’t think so? That would be opposite of our C 'API' conventions. And in `rna_object_api.c`… | |||||
Not Done Inline ActionsOk, it seems we are already inconsistent in this case, it's a mix. I'm fine with having evaluated_depsgraph_get() then. brecht: Ok, it seems we are already inconsistent in this case, it's a mix. I'm fine with having… | |||||
| RNA_def_function_ui_description( | |||||
| func, | |||||
| "Get the dependency graph for the current scene and view layer, to access to data-blocks " | |||||
Not Done Inline ActionsNo final point in RNA descriptions. ;) mont29: No final point in RNA descriptions. ;) | |||||
Not Done Inline ActionsThis description should make it clear that it's an expensive operation, and could give some guidance on what to use it for. Suggested description: Get the dependency graph for the current scene and view layer, to access to data-blocks with animation and modifiers applied. If any data-blocks have been edited, the dependency graph will be updated. This invalidates all references to evaluated data-blocks from the dependency graph. brecht: This description should make it clear that it's an expensive operation, and could give some… | |||||
Done Inline Actions
Not really correct. References to sub-data is invalidated. References to the datablock itself are not. While this seems like implementation details, there are a lot of places which are dependent on this, and being aware of this fact will speed up things like baking type of operations: one can look up evaluated datablock once, then keep updating dependency graph without looking up datablock again. sergey: > This invalidates all references to evaluated data-blocks from the dependency graph.
Not… | |||||
Not Done Inline ActionsIf an object becomes invisible, is the reference still valid? I was thinking it's safer to just consider everything invalidated since the distinction is difficult to explain. But maybe we need to try anyway. brecht: If an object becomes invisible, is the reference still valid?
I was thinking it's safer to… | |||||
Done Inline ActionsThat is a good point. So maybe all the details belongs to a wiki page like "How to get maximum performance from scripts when you know what you are doing"? Just feel like we should share such knowledge. sergey: That is a good point.
So maybe all the details belongs to a wiki page like "How to get maximum… | |||||
Not Done Inline ActionsYes, keeping the details to the Python API docs seems fine. brecht: Yes, keeping the details to the Python API docs seems fine. | |||||
| "with animation and modifiers applied. If any data-blocks have been edited, the dependency " | |||||
| "graph will be updated. This invalidates all references to evaluated data-blocks from the " | |||||
Not Done Inline ActionsIn theory, aren’t we supposed to put RNA functions into rna_xxx_api.c files? Not sure how strict we are on that policy currently (suspect it's quiet weak, given the amount of places not respecting it), just noting. mont29: In theory, aren’t we supposed to put RNA functions into `rna_xxx_api.c` files? Not sure how… | |||||
Done Inline ActionsBut there is no such a file yet, and i don't see this to be used a lot. More like if there is a huge amount of function calls then _api file is created. sergey: But there is no such a file yet, and i don't see this to be used a lot. More like if there is a… | |||||
| "dependency graph."); | |||||
| parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "Evaluated dependency graph"); | |||||
| RNA_def_function_return(func, parm); | |||||
| } | } | ||||
| #endif | #endif | ||||
I think the convention is for API functions to start with the verb? So this would be get_evaluated_depsgraph().
I could even be called evaluate_depsgraph() to make it clear that this does some work, but I'm not sure.