From 249e4df110e0a5ca7ebb24a7503f922b28d10405 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 6 Nov 2020 20:54:20 +0100 Subject: UI Code Quality: Start refactoring Outliner tree building (using C++) This introduces a new C++ abstraction "tree-display" (in this commit named tree-view, renamed in a followup) to help constructing and managing the tree for the different display types (View Layer, Scene, Blender file, etc.). See https://developer.blender.org/D9499 for more context. Other developers approved this rather significantly different design approach there. ---- Motivation General problems with current design: * The Outliner tree building code is messy and hard to follow. * Hard-coded display mode checks are scattered over many places. * Data is passed around in rather unsafe ways (e.g. lots of `void *`). * There are no individually testable units. * Data-structure use is inefficient. The current Outliner code needs quite some untangling, the tree building seems like a good place to start. This and the followup commits tackle that. ---- Design Idea Idea is to have an abstract base class (`AbstractTreeDisplay`), and then sub-classes with the implementation for each display type (e.g. `TreeDisplayViewLayer`, `TreeDisplayDataAPI`, etc). The tree-display is kept alive until tree-rebuild as runtime data of the space, so that further queries based on the display type can be executed (e.g. "does the display support selection syncing?", "does it support restriction toggle columns?", etc.). New files are in a new `space_outliner/tree` sub-directory. With the new design, display modes become proper units, making them more maintainable, safer and testable. It should also be easier now to add new display modes. --- source/blender/editors/space_outliner/space_outliner.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/space_outliner/space_outliner.c') diff --git a/source/blender/editors/space_outliner/space_outliner.c b/source/blender/editors/space_outliner/space_outliner.c index 8be7f4d1bad..ce772043e3b 100644 --- a/source/blender/editors/space_outliner/space_outliner.c +++ b/source/blender/editors/space_outliner/space_outliner.c @@ -351,11 +351,21 @@ static void outliner_free(SpaceLink *sl) if (space_outliner->treehash) { BKE_outliner_treehash_free(space_outliner->treehash); } + + if (space_outliner->runtime) { + MEM_freeN(space_outliner->runtime); + } } /* spacetype; init callback */ -static void outliner_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area)) +static void outliner_init(wmWindowManager *UNUSED(wm), ScrArea *area) { + SpaceOutliner *space_outliner = area->spacedata.first; + + if (space_outliner->runtime == NULL) { + space_outliner->runtime = MEM_callocN(sizeof(*space_outliner->runtime), + "SpaceOutliner_Runtime"); + } } static SpaceLink *outliner_duplicate(SpaceLink *sl) @@ -369,6 +379,10 @@ static SpaceLink *outliner_duplicate(SpaceLink *sl) space_outliner_new->sync_select_dirty = WM_OUTLINER_SYNC_SELECT_FROM_ALL; + if (space_outliner->runtime) { + space_outliner_new->runtime = MEM_dupallocN(space_outliner->runtime); + } + return (SpaceLink *)space_outliner_new; } -- cgit v1.2.3