[Bf-blender-cvs] [76fd84f2094] master: Cleanup: Use LISTBASE_FOREACH in curve code

Hans Goudey noreply at git.blender.org
Sun Oct 25 05:32:31 CET 2020


Commit: 76fd84f20949ec3d09afc30001e8d9d6a43601ea
Author: Hans Goudey
Date:   Sat Oct 24 23:32:11 2020 -0500
Branches: master
https://developer.blender.org/rB76fd84f20949ec3d09afc30001e8d9d6a43601ea

Cleanup: Use LISTBASE_FOREACH in curve code

This is a followup to rBa308607a533, using the macro in a few places
that were missed.

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

M	source/blender/blenkernel/intern/curve.c
M	source/blender/editors/curve/editcurve_query.c
M	source/blender/editors/curve/editcurve_select.c
M	source/blender/editors/object/object_hook.c
M	source/blender/editors/space_view3d/view3d_buttons.c
M	source/blender/makesrna/intern/rna_curve.c

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

diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 82548112096..fa45a4ba836 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -438,7 +438,6 @@ ListBase *BKE_curve_editNurbs_get(Curve *cu)
 
 short BKE_curve_type_get(const Curve *cu)
 {
-  Nurb *nu;
   int type = cu->type;
 
   if (cu->vfont) {
@@ -448,7 +447,7 @@ short BKE_curve_type_get(const Curve *cu)
   if (!cu->type) {
     type = OB_CURVE;
 
-    for (nu = cu->nurb.first; nu; nu = nu->next) {
+    LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
       if (nu->pntsv > 1) {
         type = OB_SURF;
       }
@@ -5276,8 +5275,7 @@ void BKE_curve_transform_ex(Curve *cu,
   }
 
   if (do_keys && cu->key) {
-    KeyBlock *kb;
-    for (kb = cu->key->block.first; kb; kb = kb->next) {
+    LISTBASE_FOREACH (KeyBlock *, kb, &cu->key->block) {
       float *fp = kb->data;
       int n = kb->totelem;
 
@@ -5437,9 +5435,8 @@ bool BKE_curve_material_index_validate(Curve *cu)
     }
   }
   else {
-    Nurb *nu;
     const int max_idx = max_ii(0, cu->totcol - 1);
-    for (nu = cu->nurb.first; nu; nu = nu->next) {
+    LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
       if (nu->mat_nr > max_idx) {
         nu->mat_nr = 0;
         is_valid = false;
@@ -5505,12 +5502,12 @@ void BKE_curve_material_remap(Curve *cu, const unsigned int *remap, unsigned int
 void BKE_curve_smooth_flag_set(Curve *cu, const bool use_smooth)
 {
   if (use_smooth) {
-    for (Nurb *nu = cu->nurb.first; nu; nu = nu->next) {
+    LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
       nu->flag |= CU_SMOOTH;
     }
   }
   else {
-    for (Nurb *nu = cu->nurb.first; nu; nu = nu->next) {
+    LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
       nu->flag &= ~CU_SMOOTH;
     }
   }
diff --git a/source/blender/editors/curve/editcurve_query.c b/source/blender/editors/curve/editcurve_query.c
index 48571ab2a9b..369137cbe25 100644
--- a/source/blender/editors/curve/editcurve_query.c
+++ b/source/blender/editors/curve/editcurve_query.c
@@ -26,6 +26,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_listbase.h"
 #include "BLI_math.h"
 
 #include "BKE_curve.h"
@@ -170,7 +171,6 @@ void ED_curve_nurb_vert_selected_find(
   /* in nu and (bezt or bp) selected are written if there's 1 sel.  */
   /* if more points selected in 1 spline: return only nu, bezt and bp are 0 */
   ListBase *editnurb = &cu->editnurb->nurbs;
-  Nurb *nu1;
   BezTriple *bezt1;
   BPoint *bp1;
   int a;
@@ -179,7 +179,7 @@ void ED_curve_nurb_vert_selected_find(
   *r_bezt = NULL;
   *r_bp = NULL;
 
-  for (nu1 = editnurb->first; nu1; nu1 = nu1->next) {
+  LISTBASE_FOREACH (Nurb *, nu1, editnurb) {
     if (nu1->type == CU_BEZIER) {
       bezt1 = nu1->bezt;
       a = nu1->pntsu;
diff --git a/source/blender/editors/curve/editcurve_select.c b/source/blender/editors/curve/editcurve_select.c
index aa4ba332b66..cb0a66bf5a8 100644
--- a/source/blender/editors/curve/editcurve_select.c
+++ b/source/blender/editors/curve/editcurve_select.c
@@ -237,9 +237,7 @@ int ED_curve_select_count(View3D *v3d, struct EditNurb *editnurb)
 
 bool ED_curve_select_check(View3D *v3d, struct EditNurb *editnurb)
 {
-  Nurb *nu;
-
-  for (nu = editnurb->nurbs.first; nu; nu = nu->next) {
+  LISTBASE_FOREACH (Nurb *, nu, &editnurb->nurbs) {
     if (ED_curve_nurb_select_check(v3d, nu)) {
       return true;
     }
@@ -284,13 +282,12 @@ bool ED_curve_deselect_all_multi(struct bContext *C)
 
 bool ED_curve_select_swap(EditNurb *editnurb, bool hide_handles)
 {
-  Nurb *nu;
   BPoint *bp;
   BezTriple *bezt;
   int a;
   bool changed = false;
 
-  for (nu = editnurb->nurbs.first; nu; nu = nu->next) {
+  LISTBASE_FOREACH (Nurb *, nu, &editnurb->nurbs) {
     if (nu->type == CU_BEZIER) {
       bezt = nu->bezt;
       a = nu->pntsu;
@@ -331,7 +328,6 @@ static void select_adjacent_cp(ListBase *editnurb,
                                const bool cont,
                                const bool selstatus)
 {
-  Nurb *nu;
   BezTriple *bezt;
   BPoint *bp;
   int a;
@@ -341,7 +337,7 @@ static void select_adjacent_cp(ListBase *editnurb,
     return;
   }
 
-  for (nu = editnurb->first; nu; nu = nu->next) {
+  LISTBASE_FOREACH (Nurb *, nu, editnurb) {
     lastsel = false;
     if (nu->type == CU_BEZIER) {
       a = nu->pntsu;
@@ -412,7 +408,6 @@ static void select_adjacent_cp(ListBase *editnurb,
 static void selectend_nurb(Object *obedit, eEndPoint_Types selfirst, bool doswap, bool selstatus)
 {
   ListBase *editnurb = object_editcurve_get(obedit);
-  Nurb *nu;
   BPoint *bp;
   BezTriple *bezt;
   Curve *cu;
@@ -425,7 +420,7 @@ static void selectend_nurb(Object *obedit, eEndPoint_Types selfirst, bool doswap
   cu = (Curve *)obedit->data;
   cu->actvert = CU_ACT_NONE;
 
-  for (nu = editnurb->first; nu; nu = nu->next) {
+  LISTBASE_FOREACH (Nurb *, nu, editnurb) {
     if (nu->type == CU_BEZIER) {
       a = nu->pntsu;
 
@@ -632,10 +627,9 @@ static int select_linked_exec(bContext *C, wmOperator *UNUSED(op))
     Curve *cu = obedit->data;
     EditNurb *editnurb = cu->editnurb;
     ListBase *nurbs = &editnurb->nurbs;
-    Nurb *nu;
     bool changed = false;
 
-    for (nu = nurbs->first; nu; nu = nu->next) {
+    LISTBASE_FOREACH (Nurb *, nu, nurbs) {
       if (ED_curve_nurb_select_check(v3d, nu)) {
         changed |= ED_curve_nurb_select_all(nu);
       }
@@ -887,7 +881,6 @@ void CURVE_OT_select_previous(wmOperatorType *ot)
 static void curve_select_more(Object *obedit)
 {
   ListBase *editnurb = object_editcurve_get(obedit);
-  Nurb *nu;
   BPoint *bp, *tempbp;
   int a;
   short sel = 0;
@@ -897,7 +890,7 @@ static void curve_select_more(Object *obedit)
   /* The algorithm is designed to work in planar cases so it    */
   /* may not be optimal always (example: end of NURBS sphere)   */
   if (obedit->type == OB_SURF) {
-    for (nu = editnurb->first; nu; nu = nu->next) {
+    LISTBASE_FOREACH (Nurb *, nu, editnurb) {
       BLI_bitmap *selbpoints;
       a = nu->pntsu * nu->pntsv;
       bp = nu->bp;
@@ -997,7 +990,6 @@ void CURVE_OT_select_more(wmOperatorType *ot)
 static void curve_select_less(Object *obedit)
 {
   ListBase *editnurb = object_editcurve_get(obedit);
-  Nurb *nu;
   BPoint *bp;
   BezTriple *bezt;
   int a;
@@ -1005,7 +997,7 @@ static void curve_select_less(Object *obedit)
   bool lastsel = false;
 
   if (obedit->type == OB_SURF) {
-    for (nu = editnurb->first; nu; nu = nu->next) {
+    LISTBASE_FOREACH (Nurb *, nu, editnurb) {
       BLI_bitmap *selbpoints;
       a = nu->pntsu * nu->pntsv;
       bp = nu->bp;
@@ -1077,7 +1069,7 @@ static void curve_select_less(Object *obedit)
     }
   }
   else {
-    for (nu = editnurb->first; nu; nu = nu->next) {
+    LISTBASE_FOREACH (Nurb *, nu, editnurb) {
       lastsel = false;
       /* check what type of curve/nurb it is */
       if (nu->type == CU_BEZIER) {
@@ -1210,14 +1202,13 @@ void CURVE_OT_select_less(wmOperatorType *ot)
 
 static void curve_select_random(ListBase *editnurb, float randfac, int seed, bool select)
 {
-  Nurb *nu;
   BezTriple *bezt;
   BPoint *bp;
   int a;
 
   RNG *rng = BLI_rng_new_srandom(seed);
 
-  for (nu = editnurb->first; nu; nu = nu->next) {
+  LISTBASE_FOREACH (Nurb *, nu, editnurb) {
     if (nu->type == CU_BEZIER) {
       bezt = nu->bezt;
       a = nu->pntsu;
@@ -1702,8 +1693,7 @@ static int curve_select_similar_exec(bContext *C, wmOperator *op)
     Curve *cu = obedit->data;
     EditNurb *editnurb = cu->editnurb;
 
-    Nurb *nu;
-    for (nu = editnurb->nurbs.first; nu; nu = nu->next) {
+    LISTBASE_FOREACH (Nurb *, nu, &editnurb->nurbs) {
       if (!ED_curve_nurb_select_check(v3d, nu)) {
         continue;
       }
@@ -1736,9 +1726,8 @@ static int curve_select_similar_exec(bContext *C, wmOperator *op)
     Curve *cu = obedit->data;
     EditNurb *editnurb = cu->editnurb;
     bool changed = false;
-    Nurb *nu;
 
-    for (nu = editnurb->nurbs.first; nu; nu = nu->next) {
+    LISTBASE_FOREACH (Nurb *, nu, &editnurb->nurbs) {
       switch (optype) {
         case SIMCURHAND_TYPE: {
           if (nu->type & type_ref) {
diff --git a/source/blender/editors/object/object_hook.c b/source/blender/editors/object/object_hook.c
index 5cfe02dbc59..91c9916d227 100644
--- a/source/blender/editors/object/object_hook.c
+++ b/source/blender/editors/object/object_hook.c
@@ -238,12 +238,11 @@ static void select_editlattice_hook(Object *obedit, HookModifierData *hmd)
 static int return_editcurve_indexar(Object *obedit, int *r_tot, int **r_indexar, float r_cent[3])
 {
   ListBase *editnurb = object_editcurve_get(obedit);
-  Nurb *nu;
   BPoint *bp;
   BezTriple *bezt;
   int *index, a, nr, totvert = 0;
 
-  for (nu = editnurb->first; nu; nu = nu->next) {
+  LISTBASE_FOREACH (Nurb *, nu, editnurb) {
     if (nu->type == CU_BEZIER) {
       bezt = nu->bezt;
       a = nu->pntsu;
@@ -280,7 +279,7 @@ static int return_editcurve_indexar(Object *obedit, int *r_tot, int **r_indexar,
   nr = 0;
   zero_v3(r_cent);
 
-  for (nu = editnurb->first; nu; nu = nu->next) {
+  LISTBASE_FOREACH (Nurb *, nu, editnurb) {
     if (nu->type == CU_BEZIER) {
       bezt = nu->bezt;
       a = nu->pntsu;
@@ -377,12 +376,11 @@ static bool object_hook_index_array(Main *bmain,
 static void select_editcurve_hook(Object *obedit, HookModifierData *hmd)
 {
   ListBase *editnurb = object_editcurve_get(obedit);
-  Nurb *nu;
   BPoint *bp;
   BezTriple *bezt;
   int index = 0, a, nr = 0;
 
-  for (nu = editnurb->first; nu; nu = nu->next) {
+  LISTBASE_FOREACH (Nurb *, nu, editnurb) {
     if (nu->type == CU_BEZIER) {
       bezt = nu->bezt;
       a = nu->pntsu;
diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c
index 8e03ed6e11d..f67eb73bbd1 100644
--- a/source/blender/editors/space_view3d/view3d_buttons.c
+++ b/source/blender/editors/space_view3d/view3d_buttons.c
@@ -283,7 +283,6 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
   else if (ob->type == OB_CURVE || ob->type == OB_SURF) {
     TransformMedian_Curve *median = &median_basis.curve;
     Curve *cu = ob->data;
-    Nurb *nu;
     BPoint *bp;
     BezTriple *bezt;
     int a;
@@ -291,8 +290,7 @@ 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list