Cleanup: Move some node editors functions to C++ namespace

Pull Request: https://projects.blender.org/blender/blender/pulls/132873
This commit is contained in:
Hans Goudey
2025-01-09 12:17:45 -05:00
committed by Gitea
parent b44a86e281
commit 7c775c6f57
8 changed files with 51 additions and 71 deletions

View File

@@ -25,6 +25,11 @@ struct uiLayout;
namespace blender::ed::space_node {
void tree_update(const bContext *C);
void tag_update_id(ID *id);
float grid_size_get();
/** Update the active node tree based on the context. */
void snode_set_context(const bContext &C);

View File

@@ -65,13 +65,6 @@ void ED_init_node_socket_type_virtual(blender::bke::bNodeSocketType *stype);
void ED_node_sample_set(const float col[4]);
void ED_node_type_draw_color(const char *idname, float *r_color);
/* `node_draw.cc` */
void ED_node_tree_update(const bContext *C);
void ED_node_tag_update_id(ID *id);
float ED_node_grid_size();
/* `node_edit.cc` */
void ED_node_set_tree_type(SpaceNode *snode, blender::bke::bNodeTreeType *typeinfo);

View File

@@ -268,7 +268,7 @@ static void texture_changed(Main *bmain, Tex *tex)
if (scene->use_nodes && scene->nodetree) {
LISTBASE_FOREACH (bNode *, node, &scene->nodetree->nodes) {
if (node->id == &tex->id) {
ED_node_tag_update_id(&scene->id);
blender::ed::space_node::tag_update_id(&scene->id);
}
}
}

View File

@@ -1090,7 +1090,7 @@ static int new_node_tree_exec(bContext *C, wmOperator *op)
else if (snode) {
snode->nodetree = ntree;
ED_node_tree_update(C);
tree_update(C);
}
WM_event_add_notifier(C, NC_NODE | NA_ADDED, nullptr);

View File

@@ -104,6 +104,8 @@ using blender::bke::bNodeTreeZones;
using blender::ed::space_node::NestedTreePreviews;
using blender::nodes::NodeExtraInfoRow;
namespace blender::ed::space_node {
/**
* This is passed to many functions which draw the node editor.
*/
@@ -126,7 +128,7 @@ struct TreeDrawContext {
* Geometry nodes logs various data during execution. The logged data that corresponds to the
* currently drawn node tree can be retrieved from the log below.
*/
blender::Map<const bNodeTreeZone *, geo_log::GeoTreeLog *> geo_log_by_zone;
Map<const bNodeTreeZone *, geo_log::GeoTreeLog *> geo_log_by_zone;
NestedTreePreviews *nested_group_infos = nullptr;
/**
@@ -134,24 +136,21 @@ struct TreeDrawContext {
*/
bool used_by_compositor = false;
blender::Map<bNodeInstanceKey, blender::timeit::Nanoseconds>
*compositor_per_node_execution_time = nullptr;
Map<bNodeInstanceKey, timeit::Nanoseconds> *compositor_per_node_execution_time = nullptr;
/**
* Label for reroute nodes that is derived from upstream reroute nodes.
*/
blender::Map<const bNode *, blender::StringRef> reroute_auto_labels;
Map<const bNode *, StringRef> reroute_auto_labels;
};
float ED_node_grid_size()
float grid_size_get()
{
return NODE_GRID_STEP_SIZE;
}
void ED_node_tree_update(const bContext *C)
void tree_update(const bContext *C)
{
using namespace blender::ed::space_node;
SpaceNode *snode = CTX_wm_space_node(C);
if (snode) {
snode_set_context(*C);
@@ -169,13 +168,13 @@ static bNodeTree *node_tree_from_ID(ID *id)
if (GS(id->name) == ID_NT) {
return (bNodeTree *)id;
}
return blender::bke::node_tree_from_id(id);
return bke::node_tree_from_id(id);
}
return nullptr;
}
void ED_node_tag_update_id(ID *id)
void tag_update_id(ID *id)
{
bNodeTree *ntree = node_tree_from_ID(id);
if (id == nullptr || ntree == nullptr) {
@@ -215,8 +214,6 @@ void ED_node_tag_update_id(ID *id)
}
}
namespace blender::ed::space_node {
static std::string node_socket_get_tooltip(const SpaceNode *snode,
const bNodeTree &ntree,
const bNodeSocket &socket);
@@ -1833,8 +1830,6 @@ static std::optional<std::string> create_description_inspection_string(const bNo
static std::optional<std::string> create_log_inspection_string(geo_log::GeoTreeLog *geo_tree_log,
const bNodeSocket &socket)
{
using namespace blender::nodes::geo_eval_log;
if (geo_tree_log == nullptr) {
return std::nullopt;
}
@@ -1843,7 +1838,7 @@ static std::optional<std::string> create_log_inspection_string(geo_log::GeoTreeL
}
geo_tree_log->ensure_socket_values();
ValueLog *value_log = geo_tree_log->find_socket_value_log(socket);
geo_log::ValueLog *value_log = geo_tree_log->find_socket_value_log(socket);
fmt::memory_buffer buf;
if (const geo_log::GenericValueLog *generic_value_log =
dynamic_cast<const geo_log::GenericValueLog *>(value_log))

View File

@@ -963,7 +963,7 @@ static void node_resize_exit(bContext *C, wmOperator *op, bool cancel)
/* Compute the nearest 1D coordinate corresponding to the nearest grid in node. */
static float nearest_node_grid_coord(float co)
{
float grid_size = ED_node_grid_size();
float grid_size = grid_size_get();
float rest = fmod(co, grid_size);
float offset = rest - grid_size / 2 >= 0 ? grid_size : 0;

View File

@@ -853,7 +853,7 @@ void transform_snap_grid_init(const TransInfo *t, float r_snap[3], float *r_snap
*r_snap_precision = 0.5f;
}
else if (t->spacetype == SPACE_NODE) {
r_snap[0] = r_snap[1] = ED_node_grid_size();
r_snap[0] = r_snap[1] = blender::ed::space_node::grid_size_get();
}
}

View File

@@ -217,37 +217,35 @@ const EnumPropertyItem rna_enum_space_file_browse_mode_items[] = {
};
#define SACT_ITEM_DOPESHEET \
{ \
SACTCONT_DOPESHEET, "DOPESHEET", ICON_ACTION, "Dope Sheet", "Edit all keyframes in scene" \
}
{SACTCONT_DOPESHEET, "DOPESHEET", ICON_ACTION, "Dope Sheet", "Edit all keyframes in scene"}
#define SACT_ITEM_TIMELINE \
{ \
SACTCONT_TIMELINE, "TIMELINE", ICON_TIME, "Timeline", "Timeline and playback controls" \
}
{SACTCONT_TIMELINE, "TIMELINE", ICON_TIME, "Timeline", "Timeline and playback controls"}
#define SACT_ITEM_ACTION \
{ \
SACTCONT_ACTION, "ACTION", ICON_OBJECT_DATA, "Action Editor", \
"Edit keyframes in active object's Object-level action" \
}
{SACTCONT_ACTION, \
"ACTION", \
ICON_OBJECT_DATA, \
"Action Editor", \
"Edit keyframes in active object's Object-level action"}
#define SACT_ITEM_SHAPEKEY \
{ \
SACTCONT_SHAPEKEY, "SHAPEKEY", ICON_SHAPEKEY_DATA, "Shape Key Editor", \
"Edit keyframes in active object's Shape Keys action" \
}
{SACTCONT_SHAPEKEY, \
"SHAPEKEY", \
ICON_SHAPEKEY_DATA, \
"Shape Key Editor", \
"Edit keyframes in active object's Shape Keys action"}
#define SACT_ITEM_GPENCIL \
{ \
SACTCONT_GPENCIL, "GPENCIL", ICON_OUTLINER_OB_GREASEPENCIL, "Grease Pencil", \
"Edit timings for all Grease Pencil sketches in file" \
}
{SACTCONT_GPENCIL, \
"GPENCIL", \
ICON_OUTLINER_OB_GREASEPENCIL, \
"Grease Pencil", \
"Edit timings for all Grease Pencil sketches in file"}
#define SACT_ITEM_MASK \
{ \
SACTCONT_MASK, "MASK", ICON_MOD_MASK, "Mask", "Edit timings for Mask Editor splines" \
}
{SACTCONT_MASK, "MASK", ICON_MOD_MASK, "Mask", "Edit timings for Mask Editor splines"}
#define SACT_ITEM_CACHEFILE \
{ \
SACTCONT_CACHEFILE, "CACHEFILE", ICON_FILE, "Cache File", \
"Edit timings for Cache File data-blocks" \
}
{SACTCONT_CACHEFILE, \
"CACHEFILE", \
ICON_FILE, \
"Cache File", \
"Edit timings for Cache File data-blocks"}
#ifndef RNA_RUNTIME
/* XXX: action-editor is currently for object-level only actions,
@@ -291,21 +289,10 @@ const EnumPropertyItem rna_enum_space_action_mode_items[] = {
#undef SACT_ITEM_CACHEFILE
#define SI_ITEM_VIEW(identifier, name, icon) \
{ \
SI_MODE_VIEW, identifier, icon, name, "View the image" \
}
#define SI_ITEM_UV \
{ \
SI_MODE_UV, "UV", ICON_UV, "UV Editor", "UV edit in mesh editmode" \
}
#define SI_ITEM_PAINT \
{ \
SI_MODE_PAINT, "PAINT", ICON_TPAINT_HLT, "Paint", "2D image painting mode" \
}
#define SI_ITEM_MASK \
{ \
SI_MODE_MASK, "MASK", ICON_MOD_MASK, "Mask", "Mask editing" \
}
{SI_MODE_VIEW, identifier, icon, name, "View the image"}
#define SI_ITEM_UV {SI_MODE_UV, "UV", ICON_UV, "UV Editor", "UV edit in mesh editmode"}
#define SI_ITEM_PAINT {SI_MODE_PAINT, "PAINT", ICON_TPAINT_HLT, "Paint", "2D image painting mode"}
#define SI_ITEM_MASK {SI_MODE_MASK, "MASK", ICON_MOD_MASK, "Mask", "Mask editing"}
const EnumPropertyItem rna_enum_space_image_mode_all_items[] = {
SI_ITEM_VIEW("VIEW", "View", ICON_FILE_IMAGE),
@@ -2669,7 +2656,7 @@ static bool rna_SpaceNodeEditor_node_tree_poll(PointerRNA *ptr, const PointerRNA
static void rna_SpaceNodeEditor_node_tree_update(const bContext *C, PointerRNA * /*ptr*/)
{
ED_node_tree_update(C);
blender::ed::space_node::tree_update(C);
}
static void rna_SpaceNodeEditor_geometry_nodes_type_update(Main * /*main*/,
@@ -2745,13 +2732,13 @@ static int rna_SpaceNodeEditor_path_length(PointerRNA *ptr)
static void rna_SpaceNodeEditor_path_clear(SpaceNode *snode, bContext *C)
{
ED_node_tree_start(snode, nullptr, nullptr, nullptr);
ED_node_tree_update(C);
blender::ed::space_node::tree_update(C);
}
static void rna_SpaceNodeEditor_path_start(SpaceNode *snode, bContext *C, PointerRNA *node_tree)
{
ED_node_tree_start(snode, (bNodeTree *)node_tree->data, nullptr, nullptr);
ED_node_tree_update(C);
blender::ed::space_node::tree_update(C);
}
static void rna_SpaceNodeEditor_path_append(SpaceNode *snode,
@@ -2761,13 +2748,13 @@ static void rna_SpaceNodeEditor_path_append(SpaceNode *snode,
{
ED_node_tree_push(
snode, static_cast<bNodeTree *>(node_tree->data), static_cast<bNode *>(node->data));
ED_node_tree_update(C);
blender::ed::space_node::tree_update(C);
}
static void rna_SpaceNodeEditor_path_pop(SpaceNode *snode, bContext *C)
{
ED_node_tree_pop(snode);
ED_node_tree_update(C);
blender::ed::space_node::tree_update(C);
}
static void rna_SpaceNodeEditor_show_backdrop_update(Main * /*bmain*/,