Cleanup: Move outliner types to namespace, avoid C-style type definition

With C++ we should transition towards namespaces to avoid naming
collisions. Having the namespace in place is the first step for that
transition.

Plus, the `typedef` isn't necessary for struct/class/enum definitions
in C++, so avoid the verbosity it adds.
This commit is contained in:
Julian Eisel 2022-08-24 19:45:48 +02:00
parent ce1f401b42
commit b19c51c7f4
22 changed files with 123 additions and 72 deletions

View File

@ -38,6 +38,8 @@
#include "outliner_intern.hh" /* own include */
namespace blender::ed::outliner {
/* -------------------------------------------------------------------- */
/** \name Utility API
* \{ */
@ -122,8 +124,12 @@ TreeTraversalAction outliner_find_selected_objects(TreeElement *te, void *custom
return TRAVERSE_CONTINUE;
}
} // namespace blender::ed::outliner
void ED_outliner_selected_objects_get(const bContext *C, ListBase *objects)
{
using namespace blender::ed::outliner;
SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
struct IDsSelectedData data = {{nullptr}};
outliner_tree_traverse(space_outliner,
@ -140,12 +146,16 @@ void ED_outliner_selected_objects_get(const bContext *C, ListBase *objects)
BLI_freelistN(&data.selected_array);
}
namespace blender::ed::outliner {
/** \} */
/* -------------------------------------------------------------------- */
/** \name Poll Functions
* \{ */
} // namespace blender::ed::outliner
bool ED_outliner_collections_editor_poll(bContext *C)
{
SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
@ -153,6 +163,8 @@ bool ED_outliner_collections_editor_poll(bContext *C)
ELEM(space_outliner->outlinevis, SO_VIEW_LAYER, SO_SCENES, SO_LIBRARIES);
}
namespace blender::ed::outliner {
static bool outliner_view_layer_collections_editor_poll(bContext *C)
{
SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
@ -1636,3 +1648,5 @@ void OUTLINER_OT_collection_color_tag_set(wmOperatorType *ot)
}
/** \} */
} // namespace blender::ed::outliner

View File

@ -14,7 +14,7 @@
#include "outliner_intern.hh"
#include "tree/tree_iterator.hh"
using namespace blender::ed::outliner;
namespace blender::ed::outliner {
static void outliner_context_selected_ids_recursive(const SpaceOutliner &space_outliner,
bContextDataResult *result)
@ -55,3 +55,5 @@ int /*eContextResult*/ outliner_context(const bContext *C,
return CTX_RESULT_MEMBER_NOT_FOUND;
}
} // namespace blender::ed::outliner

View File

@ -45,6 +45,8 @@
#include "outliner_intern.hh"
namespace blender::ed::outliner {
static Collection *collection_parent_from_ID(ID *id);
/* -------------------------------------------------------------------- */
@ -1592,3 +1594,5 @@ void outliner_dropboxes(void)
}
/** \} */
} // namespace blender::ed::outliner

View File

@ -74,8 +74,7 @@
#include "tree/tree_element_rna.hh"
#include "tree/tree_iterator.hh"
using namespace blender;
using namespace blender::ed::outliner;
namespace blender::ed::outliner {
/* -------------------------------------------------------------------- */
/** \name Tree Size Functions
@ -3994,3 +3993,5 @@ void draw_outliner(const bContext *C)
}
/** \} */
} // namespace blender::ed::outliner

View File

@ -65,6 +65,8 @@
using namespace blender::ed::outliner;
namespace blender::ed::outliner {
static void outliner_show_active(SpaceOutliner *space_outliner,
ARegion *region,
TreeElement *te,
@ -2230,3 +2232,5 @@ void OUTLINER_OT_orphans_purge(wmOperatorType *ot)
}
/** \} */
} // namespace blender::ed::outliner

View File

@ -14,10 +14,6 @@
/* Needed for `tree_element_cast()`. */
#include "tree/tree_element.hh"
#ifdef __cplusplus
extern "C" {
#endif
/* internal exports only */
struct ARegion;
@ -27,7 +23,6 @@ struct ListBase;
struct Main;
struct Object;
struct Scene;
struct TreeElement;
struct TreeStoreElem;
struct ViewLayer;
struct bContext;
@ -37,22 +32,23 @@ struct View2D;
struct wmKeyConfig;
struct wmOperatorType;
namespace blender::ed::outliner {
class AbstractTreeDisplay;
class AbstractTreeElement;
} // namespace blender::ed::outliner
namespace blender::bke::outliner::treehash {
class TreeHash;
}
namespace outliner = blender::ed::outliner;
namespace blender::ed::outliner {
class AbstractTreeDisplay;
class AbstractTreeElement;
namespace treehash = blender::bke::outliner::treehash;
struct TreeElement;
struct SpaceOutliner_Runtime {
/** Object to create and manage the tree for a specific display type (View Layers, Scenes,
* Blender File, etc.). */
std::unique_ptr<outliner::AbstractTreeDisplay> tree_display;
std::unique_ptr<AbstractTreeDisplay> tree_display;
/* Hash table for tree-store elements, using `(id, type, index)` as key. */
std::unique_ptr<treehash::TreeHash> tree_hash;
@ -63,25 +59,25 @@ struct SpaceOutliner_Runtime {
~SpaceOutliner_Runtime() = default;
};
typedef enum TreeElementInsertType {
enum TreeElementInsertType {
TE_INSERT_BEFORE,
TE_INSERT_AFTER,
TE_INSERT_INTO,
} TreeElementInsertType;
};
typedef enum TreeTraversalAction {
enum TreeTraversalAction {
/** Continue traversal regularly, don't skip children. */
TRAVERSE_CONTINUE = 0,
/** Stop traversal. */
TRAVERSE_BREAK,
/** Continue traversal, but skip children of traversed element. */
TRAVERSE_SKIP_CHILDS,
} TreeTraversalAction;
};
typedef TreeTraversalAction (*TreeTraversalFunc)(struct TreeElement *te, void *customdata);
typedef TreeTraversalAction (*TreeTraversalFunc)(TreeElement *te, void *customdata);
typedef struct TreeElement {
struct TreeElement *next, *prev, *parent;
struct TreeElement {
TreeElement *next, *prev, *parent;
/**
* The new inheritance based representation of the element (a derived type of base
@ -89,7 +85,7 @@ typedef struct TreeElement {
* be moved to it and operations based on the type should become virtual methods of the class
* hierarchy.
*/
std::unique_ptr<outliner::AbstractTreeElement> abstract_element;
std::unique_ptr<AbstractTreeElement> abstract_element;
ListBase subtree;
int xs, ys; /* Do selection. */
@ -100,12 +96,12 @@ typedef struct TreeElement {
short xend; /* Width of item display, for select. */
const char *name;
void *directdata; /* Armature Bones, Base, ... */
} TreeElement;
};
typedef struct TreeElementIcon {
struct TreeElementIcon {
struct ID *drag_id, *drag_parent;
int icon;
} TreeElementIcon;
};
#define TREESTORE_ID_TYPE(_id) \
(ELEM(GS((_id)->name), \
@ -172,17 +168,17 @@ enum {
/* button events */
#define OL_NAMEBUTTON 1
typedef enum {
enum eOLDrawState {
OL_DRAWSEL_NONE = 0, /* inactive (regular black text) */
OL_DRAWSEL_NORMAL = 1, /* active object (draws white text) */
OL_DRAWSEL_ACTIVE = 2, /* active obdata (draws a circle around the icon) */
} eOLDrawState;
};
typedef enum {
enum eOLSetState {
OL_SETSEL_NONE = 0, /* don't change the selection state */
OL_SETSEL_NORMAL = 1, /* select the item */
OL_SETSEL_EXTEND = 2, /* select the item and extend (also toggles selection) */
} eOLSetState;
};
/* get TreeStoreElem associated with a TreeElement
* < a: (TreeElement) tree element to find stored element for
@ -232,7 +228,7 @@ typedef enum {
* Container to avoid passing around these variables to many functions.
* Also so we can have one place to assign these variables.
*/
typedef struct TreeViewContext {
struct TreeViewContext {
/* Scene level. */
struct Scene *scene;
struct ViewLayer *view_layer;
@ -245,16 +241,16 @@ typedef struct TreeViewContext {
* The pose object may not be the active object (when in weight paint mode).
* Checking this in draw loops isn't efficient, so set only once. */
Object *ob_pose;
} TreeViewContext;
};
typedef enum TreeItemSelectAction {
enum TreeItemSelectAction {
OL_ITEM_DESELECT = 0, /* Deselect the item */
OL_ITEM_SELECT = (1 << 0), /* Select the item */
OL_ITEM_SELECT_DATA = (1 << 1), /* Select object data */
OL_ITEM_ACTIVATE = (1 << 2), /* Activate the item */
OL_ITEM_EXTEND = (1 << 3), /* Extend the current selection */
OL_ITEM_RECURSIVE = (1 << 4), /* Select recursively */
} TreeItemSelectAction;
};
/* outliner_tree.c ----------------------------------------------- */
@ -277,9 +273,9 @@ void outliner_build_tree(struct Main *mainvar,
struct SpaceOutliner *space_outliner,
struct ARegion *region);
struct TreeElement *outliner_add_collection_recursive(SpaceOutliner *space_outliner,
struct Collection *collection,
TreeElement *ten);
TreeElement *outliner_add_collection_recursive(SpaceOutliner *space_outliner,
struct Collection *collection,
TreeElement *ten);
bool outliner_requires_rebuild_on_select_or_active_change(
const struct SpaceOutliner *space_outliner);
@ -288,8 +284,8 @@ typedef struct IDsSelectedData {
struct ListBase selected_array;
} IDsSelectedData;
TreeTraversalAction outliner_find_selected_collections(struct TreeElement *te, void *customdata);
TreeTraversalAction outliner_find_selected_objects(struct TreeElement *te, void *customdata);
TreeTraversalAction outliner_find_selected_collections(TreeElement *te, void *customdata);
TreeTraversalAction outliner_find_selected_objects(TreeElement *te, void *customdata);
/* outliner_draw.c ---------------------------------------------- */
@ -351,7 +347,7 @@ struct bPoseChannel *outliner_find_parent_bone(TreeElement *te, TreeElement **r_
*/
void outliner_item_select(struct bContext *C,
struct SpaceOutliner *space_outliner,
struct TreeElement *te,
TreeElement *te,
short select_flag);
/**
@ -381,7 +377,7 @@ void outliner_item_mode_toggle(struct bContext *C,
typedef void (*outliner_operation_fn)(struct bContext *C,
struct ReportList *,
struct Scene *scene,
struct TreeElement *,
TreeElement *,
struct TreeStoreElem *,
TreeStoreElem *,
void *);
@ -410,12 +406,10 @@ int outliner_flag_is_any_test(ListBase *lb, short flag, int curlevel);
* Set or unset \a flag for all outliner elements in \a lb and sub-trees.
* \return if any flag was modified.
*/
extern "C++" {
bool outliner_flag_set(const SpaceOutliner &space_outliner, short flag, short set);
bool outliner_flag_set(const ListBase &lb, short flag, short set);
bool outliner_flag_flip(const SpaceOutliner &space_outliner, short flag);
bool outliner_flag_flip(const ListBase &lb, short flag);
}
void item_rename_fn(struct bContext *C,
struct ReportList *reports,
@ -427,14 +421,14 @@ void item_rename_fn(struct bContext *C,
void lib_relocate_fn(struct bContext *C,
struct ReportList *reports,
struct Scene *scene,
struct TreeElement *te,
TreeElement *te,
struct TreeStoreElem *tsep,
struct TreeStoreElem *tselem,
void *user_data);
void lib_reload_fn(struct bContext *C,
struct ReportList *reports,
struct Scene *scene,
struct TreeElement *te,
TreeElement *te,
struct TreeStoreElem *tsep,
struct TreeStoreElem *tselem,
void *user_data);
@ -442,14 +436,14 @@ void lib_reload_fn(struct bContext *C,
void id_delete_tag_fn(struct bContext *C,
struct ReportList *reports,
struct Scene *scene,
struct TreeElement *te,
TreeElement *te,
struct TreeStoreElem *tsep,
struct TreeStoreElem *tselem,
void *user_data);
void id_remap_fn(struct bContext *C,
struct ReportList *reports,
struct Scene *scene,
struct TreeElement *te,
TreeElement *te,
struct TreeStoreElem *tsep,
struct TreeStoreElem *tselem,
void *user_data);
@ -686,12 +680,6 @@ int outliner_context(const struct bContext *C,
const char *member,
struct bContextDataResult *result);
#ifdef __cplusplus
}
#endif
namespace blender::ed::outliner {
/**
* Helper to safely "cast" a #TreeElement to its new C++ #AbstractTreeElement, if possible.
* \return nullptr if the tree-element doesn't match the requested type \a TreeElementT or the

View File

@ -11,6 +11,7 @@
#include "outliner_intern.hh"
namespace blender::ed::outliner {
/* -------------------------------------------------------------------- */
/** \name Registration
* \{ */
@ -103,3 +104,5 @@ void outliner_keymap(wmKeyConfig *keyconf)
}
/** \} */
} // namespace blender::ed::outliner

View File

@ -13,7 +13,7 @@
#include "outliner_intern.hh"
#include "tree/tree_display.hh"
using namespace blender::ed::outliner;
namespace blender::ed::outliner {
bool outliner_shows_mode_column(const SpaceOutliner &space_outliner)
{
@ -46,3 +46,5 @@ bool outliner_has_element_warnings(const SpaceOutliner &space_outliner)
return recursive_fn(space_outliner.tree);
}
} // namespace blender::ed::outliner

View File

@ -70,7 +70,7 @@
#include "tree/tree_element_seq.hh"
#include "tree/tree_iterator.hh"
using namespace blender::ed::outliner;
namespace blender::ed::outliner {
/* -------------------------------------------------------------------- */
/** \name Internal Utilities
@ -2040,3 +2040,5 @@ void OUTLINER_OT_select_walk(wmOperatorType *ot)
}
/** \} */
} // namespace blender::ed::outliner

View File

@ -94,6 +94,8 @@ void ED_outliner_select_sync_flag_outliners(const bContext *C)
wm->outliner_sync_select_dirty = 0;
}
namespace blender::ed::outliner {
/**
* Outliner sync select dirty flags are not enough to determine which types to sync,
* outliner display mode also needs to be considered. This stores the types of data
@ -335,8 +337,12 @@ static void outliner_sync_selection_from_outliner(Scene *scene,
}
}
} // namespace blender::ed::outliner
void ED_outliner_select_sync_from_outliner(bContext *C, SpaceOutliner *space_outliner)
{
using namespace blender::ed::outliner;
/* Don't sync if not checked or in certain outliner display modes */
if (!(space_outliner->flag & SO_SYNC_SELECT) || ELEM(space_outliner->outlinevis,
SO_LIBRARIES,
@ -380,6 +386,8 @@ void ED_outliner_select_sync_from_outliner(bContext *C, SpaceOutliner *space_out
}
}
namespace blender::ed::outliner {
static void outliner_select_sync_from_object(ViewLayer *view_layer,
Object *obact,
TreeElement *te,
@ -561,3 +569,5 @@ void outliner_sync_selection(const bContext *C, SpaceOutliner *space_outliner)
}
}
}
} // namespace blender::ed::outliner

View File

@ -89,6 +89,8 @@
#include "tree/tree_element_seq.hh"
#include "tree/tree_iterator.hh"
namespace blender::ed::outliner {
static CLG_LogRef LOG = {"ed.outliner.tools"};
using namespace blender::ed::outliner;
@ -3459,3 +3461,5 @@ void OUTLINER_OT_operation(wmOperatorType *ot)
}
/** \} */
} // namespace blender::ed::outliner

View File

@ -70,7 +70,7 @@
# include "BLI_math_base.h" /* M_PI */
#endif
using namespace blender::ed::outliner;
namespace blender::ed::outliner {
/* prototypes */
static int outliner_exclude_filter_get(const SpaceOutliner *space_outliner);
@ -786,8 +786,6 @@ static void outliner_add_id_contents(SpaceOutliner *space_outliner,
}
}
namespace blender::ed::outliner {
TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
ListBase *lb,
void *idv,
@ -924,8 +922,6 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
return te;
}
} // namespace blender::ed::outliner
/* ======================================================= */
BLI_INLINE void outliner_add_collection_init(TreeElement *te, Collection *collection)
@ -1727,3 +1723,5 @@ void outliner_build_tree(Main *mainvar,
}
/** \} */
} // namespace blender::ed::outliner

View File

@ -30,7 +30,7 @@
#include "tree/tree_display.hh"
#include "tree/tree_iterator.hh"
using namespace blender::ed::outliner;
namespace blender::ed::outliner {
/* -------------------------------------------------------------------- */
/** \name Tree View Context
@ -445,6 +445,10 @@ void outliner_tag_redraw_avoid_rebuild_on_open_change(const SpaceOutliner *space
}
}
} // namespace blender::ed::outliner
using namespace blender::ed::outliner;
Base *ED_outliner_give_base_under_cursor(bContext *C, const int mval[2])
{
ARegion *region = CTX_wm_region(C);

View File

@ -37,6 +37,8 @@
#include "outliner_intern.hh"
#include "tree/tree_display.hh"
namespace blender::ed::outliner {
SpaceOutliner_Runtime::SpaceOutliner_Runtime(const SpaceOutliner_Runtime & /*other*/)
: tree_display(nullptr), tree_hash(nullptr)
{
@ -433,8 +435,12 @@ static void outliner_deactivate(struct ScrArea *area)
ED_region_tag_redraw_no_rebuild(BKE_area_find_region_type(area, RGN_TYPE_WINDOW));
}
} // namespace blender::ed::outliner
void ED_spacetype_outliner(void)
{
using namespace blender::ed::outliner;
SpaceType *st = MEM_cnew<SpaceType>("spacetype time");
ARegionType *art;

View File

@ -21,6 +21,8 @@
#include "common.hh"
#include "tree_display.hh"
namespace blender::ed::outliner {
/* -------------------------------------------------------------------- */
/** \name ID Helpers.
* \{ */
@ -63,3 +65,5 @@ bool outliner_animdata_test(const AnimData *adt)
}
return false;
}
} // namespace blender::ed::outliner

View File

@ -8,7 +8,11 @@
struct ListBase;
namespace blender::ed::outliner {
const char *outliner_idcode_to_plural(short idcode);
void outliner_make_object_parent_hierarchy(ListBase *lb);
bool outliner_animdata_test(const struct AnimData *adt);
} // namespace blender::ed::outliner

View File

@ -30,11 +30,11 @@ struct Main;
struct Scene;
struct Sequence;
struct SpaceOutliner;
struct TreeElement;
struct ViewLayer;
namespace blender::ed::outliner {
struct TreeElement;
class TreeElementID;
/**

View File

@ -14,10 +14,11 @@
struct ListBase;
struct SpaceOutliner;
struct TreeElement;
namespace blender::ed::outliner {
struct TreeElement;
/* -------------------------------------------------------------------- */
/* Tree-Display Interface */

View File

@ -8,8 +8,6 @@
#include "tree_element.hh"
struct TreeElement;
namespace blender::ed::outliner {
class TreeElementAnimData final : public AbstractTreeElement {

View File

@ -8,8 +8,6 @@
#include "tree_element.hh"
struct TreeElement;
namespace blender::ed::outliner {
class TreeElementDriverBase final : public AbstractTreeElement {

View File

@ -10,9 +10,11 @@
struct ListBase;
struct SpaceOutliner;
struct TreeElement;
namespace blender::ed::outliner {
struct TreeElement;
namespace tree_iterator {
using VisitorFn = FunctionRef<void(TreeElement *)>;

View File

@ -50,14 +50,19 @@ struct wmTimer;
/** Defined in `buttons_intern.h`. */
typedef struct SpaceProperties_Runtime SpaceProperties_Runtime;
/** Defined in `node_intern.hh`. */
#ifdef __cplusplus
namespace blender::ed::space_node {
struct SpaceNode_Runtime;
} // namespace blender::ed::space_node
using SpaceNode_Runtime = blender::ed::space_node::SpaceNode_Runtime;
namespace blender::ed::outliner {
struct SpaceOutliner_Runtime;
} // namespace blender::ed::outliner
using SpaceOutliner_Runtime = blender::ed::outliner::SpaceOutliner_Runtime;
#else
typedef struct SpaceNode_Runtime SpaceNode_Runtime;
typedef struct SpaceOutliner_Runtime SpaceOutliner_Runtime;
#endif
/** Defined in `file_intern.h`. */
@ -252,9 +257,6 @@ typedef enum eSpaceButtons_OutlinerSync {
/** \name Outliner
* \{ */
/** Defined in `outliner_intern.hh`. */
typedef struct SpaceOutliner_Runtime SpaceOutliner_Runtime;
/** Outliner */
typedef struct SpaceOutliner {
SpaceLink *next, *prev;