[Bf-blender-cvs] [e41abf9e261] master: Cleanup: Remove runtime node flag, various node transform cleanups

Hans Goudey noreply at git.blender.org
Tue Dec 13 00:10:04 CET 2022


Commit: e41abf9e26178ee4844004566be43acb7c7e39fb
Author: Hans Goudey
Date:   Mon Dec 12 16:16:59 2022 -0600
Branches: master
https://developer.blender.org/rBe41abf9e26178ee4844004566be43acb7c7e39fb

Cleanup: Remove runtime node flag, various node transform cleanups

Remove another runtime node flag that's simpler as a local variable.
Use references, C++ types, simpler for loops, etc.

===================================================================

M	source/blender/editors/include/ED_node.hh
M	source/blender/editors/space_node/node_group.cc
M	source/blender/editors/space_node/node_intern.hh
M	source/blender/editors/transform/transform_convert_node.cc
M	source/blender/makesdna/DNA_node_types.h

===================================================================

diff --git a/source/blender/editors/include/ED_node.hh b/source/blender/editors/include/ED_node.hh
index 3929f5952e4..7b35bbf0b6e 100644
--- a/source/blender/editors/include/ED_node.hh
+++ b/source/blender/editors/include/ED_node.hh
@@ -2,6 +2,7 @@
 
 #pragma once
 
+#include "BLI_vector_set.hh"
 #include "ED_node.h"
 
 struct SpaceNode;
@@ -11,6 +12,8 @@ struct bNodeTree;
 
 namespace blender::ed::space_node {
 
+VectorSet<bNode *> get_selected_nodes(bNodeTree &node_tree);
+
 void node_insert_on_link_flags_set(SpaceNode &snode, const ARegion &region);
 
 /**
diff --git a/source/blender/editors/space_node/node_group.cc b/source/blender/editors/space_node/node_group.cc
index 93d2774c4b8..be9a6c69601 100644
--- a/source/blender/editors/space_node/node_group.cc
+++ b/source/blender/editors/space_node/node_group.cc
@@ -33,6 +33,7 @@
 #include "DEG_depsgraph_build.h"
 
 #include "ED_node.h" /* own include */
+#include "ED_node.hh"
 #include "ED_render.h"
 #include "ED_screen.h"
 
diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh
index ff1a0e55fd5..1a6859a3078 100644
--- a/source/blender/editors/space_node/node_intern.hh
+++ b/source/blender/editors/space_node/node_intern.hh
@@ -183,7 +183,6 @@ void node_keymap(wmKeyConfig *keyconf);
 rctf node_frame_rect_inside(const bNode &node);
 bool node_or_socket_isect_event(const bContext &C, const wmEvent &event);
 
-VectorSet<bNode *> get_selected_nodes(bNodeTree &node_tree);
 void node_deselect_all(SpaceNode &snode);
 void node_socket_select(bNode *node, bNodeSocket &sock);
 void node_socket_deselect(bNode *node, bNodeSocket &sock, bool deselect_node);
diff --git a/source/blender/editors/transform/transform_convert_node.cc b/source/blender/editors/transform/transform_convert_node.cc
index 7f54fa723f0..8b15302853b 100644
--- a/source/blender/editors/transform/transform_convert_node.cc
+++ b/source/blender/editors/transform/transform_convert_node.cc
@@ -9,8 +9,8 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "BLI_listbase.h"
-#include "BLI_math.h"
+#include "BLI_math_vector.h"
+#include "BLI_math_vector.hh"
 #include "BLI_rect.h"
 
 #include "BKE_context.h"
@@ -39,58 +39,60 @@ struct TransCustomDataNode {
 /** \name Node Transform Creation
  * \{ */
 
-/* transcribe given node into TransData2D for Transforming */
-static void NodeToTransData(TransData *td, TransData2D *td2d, bNode *node, const float dpi_fac)
+static void create_transform_data_for_node(TransData &td,
+                                           TransData2D &td2d,
+                                           bNode &node,
+                                           const float dpi_fac)
 {
   float locx, locy;
 
   /* account for parents (nested nodes) */
-  if (node->parent) {
-    nodeToView(node->parent, node->locx, node->locy, &locx, &locy);
+  if (node.parent) {
+    nodeToView(node.parent, node.locx, node.locy, &locx, &locy);
   }
   else {
-    locx = node->locx;
-    locy = node->locy;
+    locx = node.locx;
+    locy = node.locy;
   }
 
   /* use top-left corner as the transform origin for nodes */
   /* Weirdo - but the node system is a mix of free 2d elements and DPI sensitive UI. */
 #ifdef USE_NODE_CENTER
-  td2d->loc[0] = (locx * dpi_fac) + (BLI_rctf_size_x(&node->runtime->totr) * +0.5f);
-  td2d->loc[1] = (locy * dpi_fac) + (BLI_rctf_size_y(&node->runtime->totr) * -0.5f);
+  td2d.loc[0] = (locx * dpi_fac) + (BLI_rctf_size_x(&node.runtime->totr) * +0.5f);
+  td2d.loc[1] = (locy * dpi_fac) + (BLI_rctf_size_y(&node.runtime->totr) * -0.5f);
 #else
-  td2d->loc[0] = locx * dpi_fac;
-  td2d->loc[1] = locy * dpi_fac;
+  td2d.loc[0] = locx * dpi_fac;
+  td2d.loc[1] = locy * dpi_fac;
 #endif
-  td2d->loc[2] = 0.0f;
-  td2d->loc2d = td2d->loc; /* current location */
+  td2d.loc[2] = 0.0f;
+  td2d.loc2d = td2d.loc; /* current location */
 
-  td->loc = td2d->loc;
-  copy_v3_v3(td->iloc, td->loc);
+  td.loc = td2d.loc;
+  copy_v3_v3(td.iloc, td.loc);
   /* use node center instead of origin (top-left corner) */
-  td->center[0] = td2d->loc[0];
-  td->center[1] = td2d->loc[1];
-  td->center[2] = 0.0f;
+  td.center[0] = td2d.loc[0];
+  td.center[1] = td2d.loc[1];
+  td.center[2] = 0.0f;
 
-  memset(td->axismtx, 0, sizeof(td->axismtx));
-  td->axismtx[2][2] = 1.0f;
+  memset(td.axismtx, 0, sizeof(td.axismtx));
+  td.axismtx[2][2] = 1.0f;
 
-  td->ext = nullptr;
-  td->val = nullptr;
+  td.ext = nullptr;
+  td.val = nullptr;
 
-  td->flag = TD_SELECTED;
-  td->dist = 0.0f;
+  td.flag = TD_SELECTED;
+  td.dist = 0.0f;
 
-  unit_m3(td->mtx);
-  unit_m3(td->smtx);
+  unit_m3(td.mtx);
+  unit_m3(td.smtx);
 
-  td->extra = node;
+  td.extra = &node;
 }
 
-static bool is_node_parent_select(bNode *node)
+static bool is_node_parent_select(const bNode *node)
 {
   while ((node = node->parent)) {
-    if (node->flag & NODE_TRANSFORM) {
+    if (node->flag & NODE_SELECT) {
       return true;
     }
   }
@@ -99,8 +101,13 @@ static bool is_node_parent_select(bNode *node)
 
 static void createTransNodeData(bContext * /*C*/, TransInfo *t)
 {
-  const float dpi_fac = UI_DPI_FAC;
+  using namespace blender;
+  using namespace blender::ed;
   SpaceNode *snode = static_cast<SpaceNode *>(t->area->spacedata.first);
+  bNodeTree *node_tree = snode->edittree;
+  if (!node_tree) {
+    return;
+  }
 
   /* Custom data to enable edge panning during the node transform */
   TransCustomDataNode *customdata = MEM_cnew<TransCustomDataNode>(__func__);
@@ -119,37 +126,21 @@ static void createTransNodeData(bContext * /*C*/, TransInfo *t)
 
   TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
 
-  tc->data_len = 0;
-
-  if (!snode->edittree) {
-    return;
-  }
-
   /* Nodes don't support proportional editing and probably never will. */
   t->flag = t->flag & ~T_PROP_EDIT_ALL;
 
-  /* set transform flags on nodes */
-  for (bNode *node : snode->edittree->all_nodes()) {
-    if (node->flag & NODE_SELECT && !is_node_parent_select(node)) {
-      node->flag |= NODE_TRANSFORM;
-      tc->data_len++;
-    }
-    else {
-      node->flag &= ~NODE_TRANSFORM;
-    }
-  }
-
-  if (tc->data_len == 0) {
+  VectorSet<bNode *> nodes = space_node::get_selected_nodes(*node_tree);
+  nodes.remove_if([&](bNode *node) { return is_node_parent_select(node); });
+  if (nodes.is_empty()) {
     return;
   }
 
-  TransData *td = tc->data = MEM_cnew_array<TransData>(tc->data_len, __func__);
-  TransData2D *td2d = tc->data_2d = MEM_cnew_array<TransData2D>(tc->data_len, __func__);
+  tc->data_len = nodes.size();
+  tc->data = MEM_cnew_array<TransData>(tc->data_len, __func__);
+  tc->data_2d = MEM_cnew_array<TransData2D>(tc->data_len, __func__);
 
-  for (bNode *node : snode->edittree->all_nodes()) {
-    if (node->flag & NODE_TRANSFORM) {
-      NodeToTransData(td++, td2d++, node, dpi_fac);
-    }
+  for (const int i : nodes.index_range()) {
+    create_transform_data_for_node(tc->data[i], tc->data_2d[i], *nodes[i], UI_DPI_FAC);
   }
 }
 
@@ -161,43 +152,41 @@ static void createTransNodeData(bContext * /*C*/, TransInfo *t)
 
 static void node_snap_grid_apply(TransInfo *t)
 {
-  int i;
+  using namespace blender;
 
   if (!(activeSnap(t) && (t->tsnap.mode & (SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)))) {
     return;
   }
 
-  float grid_size[2];
-  copy_v2_v2(grid_size, t->snap_spatial);
+  float2 grid_size = t->snap_spatial;
   if (t->modifiers & MOD_PRECISION) {
-    mul_v2_fl(grid_size, t->snap_spatial_precision);
+    grid_size *= t->snap_spatial_precision;
   }
 
   /* Early exit on unusable grid size. */
-  if (is_zero_v2(grid_size)) {
+  if (math::is_zero(grid_size)) {
     return;
   }
 
   FOREACH_TRANS_DATA_CONTAINER (t, tc) {
-    TransData *td;
-
-    for (i = 0, td = tc->data; i < tc->data_len; i++, td++) {
+    for (const int i : IndexRange(tc->data_len)) {
+      TransData &td = tc->data[i];
       float iloc[2], loc[2], tvec[2];
-      if (td->flag & TD_SKIP) {
+      if (td.flag & TD_SKIP) {
         continue;
       }
 
-      if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) {
+      if ((t->flag & T_PROP_EDIT) && (td.factor == 0.0f)) {
         continue;
       }
 
-      copy_v2_v2(iloc, td->loc);
+      copy_v2_v2(iloc, td.loc);
 
       loc[0] = roundf(iloc[0] / grid_size[0]) * grid_size[0];
       loc[1] = roundf(iloc[1] / grid_size[1]) * grid_size[1];
 
       sub_v2_v2v2(tvec, loc, iloc);
-      add_v2_v2(td->loc, tvec);
+      add_v2_v2(td.loc, tvec);
     }
   }
 }
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 4025726733f..424a4c17e82 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -417,7 +417,7 @@ typedef struct bNode {
 /* node is always behind others */
 #define NODE_BACKGROUND (1 << 12)
 /* automatic flag for nodes included in transforms */
-#define NODE_TRANSFORM (1 << 13)
+// #define NODE_TRANSFORM (1 << 13) /* deprecated */
 /* node is active texture */
 
 /* NOTE: take care with this flag since its possible it gets



More information about the Bf-blender-cvs mailing list