[Bf-blender-cvs] [fbc7ab3] master: Curves: save active point to file

Kevin Mackay noreply at git.blender.org
Mon Jan 27 05:22:53 CET 2014


Commit: fbc7ab30ff025ad3db59a73e2901883986e2e81e
Author: Kevin Mackay
Date:   Mon Jan 27 15:18:40 2014 +1100
https://developer.blender.org/rBfbc7ab30ff025ad3db59a73e2901883986e2e81e

Curves: save active point to file

Changed curve active point from pointer to index. Allows curve active point to be saved to file and retained between modes for free. Also some small optimisations by removing pointer look up code.

- Made active point access functions into BKE API calls.
- Fixes operators where curve de-selection resulted in unsel-active point.
- Split curve delete into 2 functions

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

M	source/blender/blenkernel/BKE_curve.h
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/curve/editcurve.c
M	source/blender/editors/curve/editcurve_add.c
M	source/blender/editors/include/ED_curve.h
M	source/blender/editors/include/UI_resources.h
M	source/blender/editors/interface/resources.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/editors/transform/transform_generics.c
M	source/blender/editors/transform/transform_manipulator.c
M	source/blender/editors/transform/transform_orientations.c
M	source/blender/makesdna/DNA_curve_types.h

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

diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index 589ca68..afa0530 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -86,7 +86,14 @@ void BKE_curve_translate(struct Curve *cu, float offset[3], int do_keys);
 void BKE_curve_material_index_remove(struct Curve *cu, int index);
 void BKE_curve_material_index_clear(struct Curve *cu);
 
-ListBase *BKE_curve_nurbs_get(struct Curve *cu);
+ListBase    *BKE_curve_nurbs_get(struct Curve *cu);
+
+void         BKE_curve_nurb_active_set(struct Curve *cu, struct Nurb *nu);
+struct Nurb *BKE_curve_nurb_active_get(struct Curve *cu);
+void        *BKE_curve_vert_active_get(struct Curve *cu);
+void         BKE_curve_nurb_vert_active_set(struct Curve *cu, struct Nurb *nu,    void *vert);
+bool         BKE_curve_nurb_vert_active_get(struct Curve *cu, struct Nurb **r_nu, void **r_vert);
+void         BKE_curve_nurb_vert_active_validate(struct Curve *cu);
 
 float (*BKE_curve_nurbs_vertexCos_get(struct ListBase *lb, int *numVerts_r))[3];
 void BK_curve_nurbs_vertexCos_apply(struct ListBase *lb, float (*vertexCos)[3]);
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index dfcd8f6..cba4b7e 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -224,7 +224,6 @@ Curve *BKE_curve_copy(Curve *cu)
 
 	cun->editnurb = NULL;
 	cun->editfont = NULL;
-	cun->lastsel = NULL;
 
 #if 0   // XXX old animation system
 	/* single user ipo too */
@@ -3931,6 +3930,105 @@ ListBase *BKE_curve_nurbs_get(Curve *cu)
 	return &cu->nurb;
 }
 
+void BKE_curve_nurb_active_set(Curve *cu, Nurb *nu)
+{
+	if (nu == NULL) {
+		cu->actnu = -1;
+	}
+	else {
+		ListBase *nurbs = BKE_curve_editNurbs_get(cu);
+		cu->actnu = BLI_findindex(nurbs, nu);
+	}
+}
+
+Nurb *BKE_curve_nurb_active_get(Curve *cu)
+{
+	ListBase *nurbs = BKE_curve_editNurbs_get(cu);
+	return BLI_findlink(nurbs, cu->actnu);
+}
+
+/* Get active vert for curve */
+void *BKE_curve_vert_active_get(Curve *cu)
+{
+	Nurb *nu = NULL;
+	void *vert = NULL;
+
+	BKE_curve_nurb_vert_active_get(cu, &nu, &vert);
+	return vert;
+}
+
+/* Set active nurb and active vert for curve */
+void BKE_curve_nurb_vert_active_set(Curve *cu, Nurb *nu, void *vert)
+{
+	if (nu) {
+		BKE_curve_nurb_active_set(cu, nu);
+
+		if (nu->type == CU_BEZIER) {
+			BLI_assert(ARRAY_HAS_ITEM((BezTriple *)vert, nu->bezt, nu->pntsu));
+			cu->actvert = (BezTriple *)vert - nu->bezt;
+		}
+		else {
+			BLI_assert(ARRAY_HAS_ITEM((BPoint *)vert, nu->bp, nu->pntsu * nu->pntsv));
+			cu->actvert = (BPoint *)vert - nu->bp;
+		}
+	}
+	else {
+		cu->actnu = cu->actvert = CU_ACT_NONE;
+	}
+}
+
+/* Get points to active active nurb and active vert for curve */
+bool BKE_curve_nurb_vert_active_get(Curve *cu, Nurb **r_nu, void **r_vert)
+{
+	Nurb *nu = NULL;
+	void *vert = NULL;
+
+	if (cu->actvert != CU_ACT_NONE) {
+		ListBase *nurbs = BKE_curve_editNurbs_get(cu);
+		nu = BLI_findlink(nurbs, cu->actnu);
+
+		if (nu) {
+			if (nu->type == CU_BEZIER) {
+				BLI_assert(nu->pntsu > cu->actvert);
+				vert = &nu->bezt[cu->actvert];
+			}
+			else {
+				BLI_assert((nu->pntsu * nu->pntsv) > cu->actvert);
+				vert = &nu->bp[cu->actvert];
+			}
+		}
+		/* get functions should never set! */
+#if 0
+		else {
+			cu->actnu = cu->actvert = CU_ACT_NONE;
+		}
+#endif
+	}
+
+	*r_nu = nu;
+	*r_vert = vert;
+
+	return (*r_vert != NULL);
+}
+
+void BKE_curve_nurb_vert_active_validate(Curve *cu)
+{
+	Nurb *nu;
+	void *vert;
+
+	if (BKE_curve_nurb_vert_active_get(cu, &nu, &vert)) {
+		if (nu->type == CU_BEZIER) {
+			if ((((BezTriple *)vert)->f1 & SELECT) == 0) {
+				cu->actvert = CU_ACT_NONE;
+			}
+		}
+		else {
+			if ((((BPoint *)vert)->f1 & SELECT) == 0) {
+				cu->actvert = CU_ACT_NONE;
+			}
+		}
+	}
+}
 
 /* basic vertex data functions */
 bool BKE_curve_minmax(Curve *cu, bool use_radius, float min[3], float max[3])
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 88e7f85..913bdfd 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3388,7 +3388,6 @@ static void direct_link_curve(FileData *fd, Curve *cu)
 	}
 
 	cu->editnurb = NULL;
-	cu->lastsel = NULL;
 	cu->editfont = NULL;
 	
 	for (nu = cu->nurb.first; nu; nu = nu->next) {
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index 6144c84..f07d575 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -80,7 +80,7 @@
 /* Undo stuff */
 typedef struct {
 	ListBase nubase;
-	void *lastsel;
+	int actvert;
 	GHash *undoIndex;
 	ListBase fcurves, drivers;
 	int actnu;
@@ -123,27 +123,6 @@ ListBase *object_editcurve_get(Object *ob)
 	return NULL;
 }
 
-/* this replaces the active flag used in uv/face mode */
-static void set_actNurb(Object *obedit, Nurb *nu)
-{
-	Curve *cu = obedit->data;
-	
-	if (nu == NULL)
-		cu->actnu = -1;
-	else {
-		ListBase *nurbs = BKE_curve_editNurbs_get(cu);
-		cu->actnu = BLI_findindex(nurbs, nu);
-	}
-}
-
-static Nurb *get_actNurb(Object *obedit)
-{
-	Curve *cu = obedit->data;
-	ListBase *nurbs = BKE_curve_editNurbs_get(cu);
-
-	return BLI_findlink(nurbs, cu->actnu);
-}
-
 /* ******************* SELECTION FUNCTIONS ********************* */
 
 
@@ -1217,11 +1196,9 @@ void make_editNurb(Object *obedit)
 {
 	Curve *cu = (Curve *)obedit->data;
 	EditNurb *editnurb = cu->editnurb;
-	Nurb *nu, *newnu, *nu_act = NULL;
+	Nurb *nu, *newnu;
 	KeyBlock *actkey;
 
-	set_actNurb(obedit, NULL);
-
 	if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
 		actkey = BKE_keyblock_from_object(obedit);
 
@@ -1242,18 +1219,10 @@ void make_editNurb(Object *obedit)
 		}
 
 		nu = cu->nurb.first;
-		cu->lastsel = NULL;   /* for select row */
-
 		while (nu) {
 			newnu = BKE_nurb_duplicate(nu);
 			BKE_nurb_test2D(newnu); // after join, or any other creation of curve
 			BLI_addtail(&editnurb->nurbs, newnu);
-
-			if (nu_act == NULL && isNurbsel(nu)) {
-				nu_act = newnu;
-				set_actNurb(obedit, newnu);
-			}
-
 			nu = nu->next;
 		}
 
@@ -1273,98 +1242,82 @@ void free_editNurb(Object *obedit)
 	BKE_curve_editNurb_free(cu);
 }
 
-void CU_deselect_all(Object *obedit)
+void ED_curve_deselect_all(EditNurb *editnurb)
 {
-	ListBase *editnurb = object_editcurve_get(obedit);
-
-	if (editnurb) {
-		Nurb *nu;
-		int a;
-		((Curve *)obedit->data)->lastsel = NULL;
+	Nurb *nu;
+	int a;
 
-		for (nu = editnurb->first; nu; nu = nu->next) {
-			if (nu->bezt) {
-				BezTriple *bezt;
-				for (bezt = nu->bezt, a = 0; a < nu->pntsu; a++, bezt++) {
-					bezt->f1 &= ~SELECT;
-					bezt->f2 &= ~SELECT;
-					bezt->f3 &= ~SELECT;
-				}
+	for (nu = editnurb->nurbs.first; nu; nu = nu->next) {
+		if (nu->bezt) {
+			BezTriple *bezt;
+			for (bezt = nu->bezt, a = 0; a < nu->pntsu; a++, bezt++) {
+				bezt->f1 &= ~SELECT;
+				bezt->f2 &= ~SELECT;
+				bezt->f3 &= ~SELECT;
 			}
-			else if (nu->bp) {
-				BPoint *bp;
-				for (bp = nu->bp, a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) {
-					bp->f1 &= ~SELECT;
-				}
+		}
+		else if (nu->bp) {
+			BPoint *bp;
+			for (bp = nu->bp, a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) {
+				bp->f1 &= ~SELECT;
 			}
 		}
 	}
 }
 
-void CU_select_all(Object *obedit)
+void ED_curve_select_all(EditNurb *editnurb)
 {
-	ListBase *editnurb = object_editcurve_get(obedit);
-
-	if (editnurb) {
-		Nurb *nu;
-		int a;
-		for (nu = editnurb->first; nu; nu = nu->next) {
-			if (nu->bezt) {
-				BezTriple *bezt;
-				for (bezt = nu->bezt, a = 0; a < nu->pntsu; a++, bezt++) {
-					if (bezt->hide == 0) {
-						bezt->f1 |= SELECT;
-						bezt->f2 |= SELECT;
-						bezt->f3 |= SELECT;
-					}
+	Nurb *nu;
+	int a;
+	for (nu = editnurb->nurbs.first; nu; nu = nu->next) {
+		if (nu->bezt) {
+			BezTriple *bezt;
+			for (bezt = nu->bezt, a = 0; a < nu->pntsu; a++, bezt++) {
+				if (bezt->hide == 0) {
+					bezt->f1 |= SELECT;
+					bezt->f2 |= SELECT;
+					bezt->f3 |= SELECT;
 				}
 			}
-			else if (nu->bp) {
-				BPoint *bp;
-				for (bp = nu->bp, a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) {
-					if (bp->hide == 0)
-						bp->f1 |= SELECT;
-				}
+		}
+		else if (nu->bp) {
+			BPoint *bp;
+			for (bp = nu->bp, a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) {
+				if (bp->hide == 0)
+					bp->f1 |= SELECT;
 			}
 		}
 	}
 }
 
-void CU_select_swap(Object *obedit)
+void ED_curve_select_swap(EditNurb *editnurb, bool hide_handles)
 {
-	ListBase *editnurb = object_editcurve_get(obedit);
-
-	if (editnurb) {
-		Curve *cu = obedit->data;
-		Nurb *nu;
-		BPoint *bp;
-		BezTriple *bezt;
-		int a;
-
-		cu->lastsel = NULL;
+	Nurb *nu;
+	BPoint *bp;
+	BezTriple *bezt;
+	int a;
 
-		for (nu = editnurb->first; nu; nu = nu->next) {
-			if (nu->type == CU_BEZIER) {
-				bezt = nu->bezt;
-				a = nu->pntsu;
-				while (a--) {
-					if (bezt->hide == 0) {
-						bezt->f2 ^= SELECT; /* always do the center point */
-						if ((cu->drawflag & CU_HIDE_HANDLES) == 0) {
-							bezt->f1 ^= SELECT;
-							bezt->f3 ^= SELECT;
-						}
+	for (nu = editnurb->nurbs.first; nu; nu = nu->next) {
+		if (nu->type == CU_BEZIER) {
+			bezt = nu->bezt;
+			a = nu->pntsu;
+			while (a--) {
+				if (bezt->hide == 0) {
+					bezt->f2 ^= SELECT; /* always do the center point */
+					if (!hide_handles) {
+						bezt->f1 ^= SELECT;
+						bezt->f3 ^= SELECT;
 					}
-					bezt++;
 				}
+				bezt++;
 			}
-			else {
-				bp = nu->bp;
-				a = nu->pntsu * nu->pntsv;
-				while (a--) {
-					swap_selection_bpoint(bp);
-					bp++;
-				}
+		}
+		else {
+			bp = nu->bp;
+			a = nu->pntsu * nu->pntsv;
+			while (a--) {
+				swap_selection_bpoint(bp);
+				bp++;
 			}
 		}
 	}
@@ -1699,7 +1652,7 @@ static void weightflagNurb(ListBase *editnurb, short flag, float w)
 	}
 }
 
-static int deleteflagNurb(Object *obedit, short flag)
+static void ed_surf_delete_selected(Object *obedit)
 {
 	Curve *cu = obedit->data;
 	ListBase *editnurb = object_editcurve_get(obedit);
@@ -1707,11 +1660,7 @@ static int deleteflagNurb(Object *obedit, short flag)
 	BPoint *bp, *bpn, *newbp;
 	int a, b, newu, newv;
 
-	if (obedit->type != OB_SURF) {
-		return OPERATOR_CANCELLED;
-	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list