ID: Document the steps to properly add a new ID data-block type #15

Open
Sybren A. Stüvel wants to merge 1 commits from pr/new-id-datablock into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Showing only changes of commit 561b54d06e - Show all commits

View File

@ -183,5 +183,48 @@ To add a new `IDTypeInfo` you need to:
for object).
2. Add the `extern` declaration of the new `IDType` in
`BKE_idtype.h`.
3. Register the new `IDTypeInfo` in `id_type_init()` of
`idtype.cc`.
3. `idtype.cc`:
- Register the new `IDTypeInfo` in `id_type_init()`.
- Add a new `case` to `BKE_idtype_idcode_to_idfilter()`
- Add a new `case` to `BKE_idtype_idcode_to_index()`
- Add a new `case` to `BKE_idtype_idcode_from_index()`
Additionally, there are some other areas in the source code where a reference to
the new type might be added:
dr.sybren marked this conversation as resolved
Review

might be added -> might be needed ?

`might be added` -> `might be needed` ?
4. `lib_query.cc`: in `BKE_library_id_can_use_filter_id()`.
5. `blenkernel/intern/main.cc`:
- `which_libbase()`
- `set_listbasepointers()`
6. `readfile.c`: in `dataname()`
dr.sybren marked this conversation as resolved
Review

This is readfile.cc now.

This is `readfile.cc` now.
7. `BLT_translation.h`: add a `#define BLT_I18NCONTEXT_ID...` line
dr.sybren marked this conversation as resolved
Review
  1. BLT_translation.h: add #define BLT_I18NCONTEXT_ID... and BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_..., "id_..."), \ lines
7. `BLT_translation.h`: add `#define BLT_I18NCONTEXT_ID...` and `BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_..., "id_..."), \` lines
8. Dependency graph handling: `deg_builder_nodes.h`, `deg_builder_nodes.cc`,
`deg_builder_relations.h`, and `deg_builder_relations.cc`,
9. `editors/interface/interface_icons.cc` in `UI_icon_from_idcode()`
10. `editors/interface/interface_templates.cc` in `template_id_browse_tip()`
11. `editors/render/render_opengl.cc` in `gather_frames_to_render_for_id()`
12. Outliner support in `editors/space_outliner`:
- `outliner_intern.hh`: `TREESTORE_ID_TYPE`
- `outliner_draw.cc`: `tree_element_get_icon_from_id()`
- `outliner_tools.cc`: `get_element_operation_type()`
- `tree_element_id.cc`: `TreeElementID::create_from_id()`
13. Filtering:
- `DNA_ID.h`: add a `#define FILTER_ID_...` line and add it to `FILTER_ID_ALL`.
- `DNA_ID.h`: add an entry to `eID_Index`
- `rna_space.cc`: add to `rna_enum_space_file_id_filter_categories`
14. `DNA_ID_enums.h`: add to `enum ID_Type`
15. If your DNA definition has default values in `DNA_..._defaults.h`, add this to`dna_defaults.c`:
- add a `SDNA_DEFAULT_DECL_STRUCT(...)` line for each struct that has defaults.
- add a `SDNA_DEFAULT_DECL(...)` line to `DNA_default_table()` for each such struct.
16. If you want to have RNA support:
- `makesrna.cc`: add an entry to `PROCESS_ITEMS` for your RNA definition file.
- `rna_ID.cc`: add to `rna_enum_id_type_items`, `rna_enum_id_type_filter_items`, `RNA_type_to_ID_code()`, `rna_ID_update_tag()`
- `rna_internal.hh`:
- add declaration of your RNA definition entry function (`void RNA_def_yourtype(BlenderRNA *brna);`)
- add declaration for the `bpy.data.yourdata` collection (`void RNA_def_main_yourdata(BlenderRNA *brna, PropertyRNA *cprop);`)
- `rna_main.cc`:
- add a `RNA_MAIN_LISTBASE_FUNCS_DEF(yourdata)` line.
- add your type to the `RNA_def_main()` function.
- `rna_main_api.cc`: add these functions:
- `static YourType *rna_Main_yourdata_new(Main *bmain, const char *name)`
- `void RNA_def_main_yourdata(BlenderRNA *brna, PropertyRNA *cprop)`