[Bf-blender-cvs] [4a328a7] master: EditCurve: move selection into own file

Campbell Barton noreply at git.blender.org
Wed Jul 8 16:27:13 CEST 2015


Commit: 4a328a76895c4f03b528b3c7e251475e76c68351
Author: Campbell Barton
Date:   Wed Jul 8 23:24:16 2015 +1000
Branches: master
https://developer.blender.org/rB4a328a76895c4f03b528b3c7e251475e76c68351

EditCurve: move selection into own file

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

M	source/blender/editors/curve/CMakeLists.txt
M	source/blender/editors/curve/curve_intern.h
M	source/blender/editors/curve/editcurve.c
A	source/blender/editors/curve/editcurve_select.c
M	source/blender/editors/include/ED_curve.h

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

diff --git a/source/blender/editors/curve/CMakeLists.txt b/source/blender/editors/curve/CMakeLists.txt
index 1b877c0..66c281d 100644
--- a/source/blender/editors/curve/CMakeLists.txt
+++ b/source/blender/editors/curve/CMakeLists.txt
@@ -37,6 +37,7 @@ set(SRC
 	curve_ops.c
 	editcurve.c
 	editcurve_add.c
+	editcurve_select.c
 	editfont.c
 
 	curve_intern.h
diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h
index 579f149..bb0abf4 100644
--- a/source/blender/editors/curve/curve_intern.h
+++ b/source/blender/editors/curve/curve_intern.h
@@ -37,6 +37,7 @@ struct ListBase;
 struct EditNurb;
 struct Object;
 struct wmOperatorType;
+struct ViewContext;
 
 /* editfont.c */
 enum { DEL_ALL, DEL_NEXT_CHAR, DEL_PREV_CHAR, DEL_SELECTION, DEL_NEXT_SEL, DEL_PREV_SEL };
@@ -44,6 +45,25 @@ enum { CASE_LOWER, CASE_UPPER };
 enum { LINE_BEGIN, LINE_END, PREV_CHAR, NEXT_CHAR, PREV_WORD, NEXT_WORD,
        PREV_LINE, NEXT_LINE, PREV_PAGE, NEXT_PAGE };
 
+typedef enum eVisible_Types {
+	HIDDEN = true,
+	VISIBLE = false,
+} eVisible_Types;
+
+typedef enum eEndPoint_Types {
+	FIRST = true,
+	LAST = false,
+} eEndPoint_Types;
+
+typedef enum eCurveElem_Types {
+	CURVE_VERTEX = 0,
+	CURVE_SEGMENT,
+} eCurveElem_Types;
+
+/* internal select utils */
+bool select_beztriple(BezTriple *bezt, bool selstatus, short flag, eVisible_Types hidden);
+bool select_bpoint(BPoint *bp, bool selstatus, short flag, bool hidden);
+
 void FONT_OT_text_insert(struct wmOperatorType *ot);
 void FONT_OT_line_break(struct wmOperatorType *ot);
 void FONT_OT_insert_lorem(struct wmOperatorType *ot);
@@ -98,19 +118,6 @@ void CURVE_OT_smooth_weight(struct wmOperatorType *ot);
 void CURVE_OT_smooth_radius(struct wmOperatorType *ot);
 void CURVE_OT_smooth_tilt(struct wmOperatorType *ot);
 
-void CURVE_OT_de_select_first(struct wmOperatorType *ot);
-void CURVE_OT_de_select_last(struct wmOperatorType *ot);
-void CURVE_OT_select_all(struct wmOperatorType *ot);
-void CURVE_OT_select_linked(struct wmOperatorType *ot);
-void CURVE_OT_select_linked_pick(struct wmOperatorType *ot);
-void CURVE_OT_select_row(struct wmOperatorType *ot);
-void CURVE_OT_select_next(struct wmOperatorType *ot);
-void CURVE_OT_select_previous(struct wmOperatorType *ot);
-void CURVE_OT_select_more(struct wmOperatorType *ot);
-void CURVE_OT_select_less(struct wmOperatorType *ot);
-void CURVE_OT_select_random(struct wmOperatorType *ot);
-void CURVE_OT_select_nth(struct wmOperatorType *ot);
-
 void CURVE_OT_switch_direction(struct wmOperatorType *ot);
 void CURVE_OT_subdivide(struct wmOperatorType *ot);
 void CURVE_OT_make_segment(struct wmOperatorType *ot);
@@ -121,11 +128,28 @@ void CURVE_OT_cyclic_toggle(struct wmOperatorType *ot);
 
 void CURVE_OT_match_texture_space(struct wmOperatorType *ot);
 
+bool ED_curve_pick_vert(
+        struct ViewContext *vc, short sel, const int mval[2],
+        struct Nurb **r_nurb, struct BezTriple **r_bezt, struct BPoint **r_bp, short *r_handle);
+
 /* helper functions */
 void ed_editnurb_translate_flag(struct ListBase *editnurb, short flag, const float vec[3]);
 bool ed_editnurb_extrude_flag(struct EditNurb *editnurb, short flag);
 bool ed_editnurb_spin(float viewmat[4][4], struct Object *obedit, const float axis[3], const float cent[3]);
 
+/* editcurve_select.c */
+void CURVE_OT_de_select_first(struct wmOperatorType *ot);
+void CURVE_OT_de_select_last(struct wmOperatorType *ot);
+void CURVE_OT_select_all(struct wmOperatorType *ot);
+void CURVE_OT_select_linked(struct wmOperatorType *ot);
+void CURVE_OT_select_linked_pick(struct wmOperatorType *ot);
+void CURVE_OT_select_row(struct wmOperatorType *ot);
+void CURVE_OT_select_next(struct wmOperatorType *ot);
+void CURVE_OT_select_previous(struct wmOperatorType *ot);
+void CURVE_OT_select_more(struct wmOperatorType *ot);
+void CURVE_OT_select_less(struct wmOperatorType *ot);
+void CURVE_OT_select_random(struct wmOperatorType *ot);
+void CURVE_OT_select_nth(struct wmOperatorType *ot);
 
 /* editcurve_add.c */
 void CURVE_OT_primitive_bezier_curve_add(struct wmOperatorType *ot);
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index 1a10814..d17c05a 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -37,9 +37,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
-#include "BLI_bitmap.h"
 #include "BLI_math.h"
-#include "BLI_rand.h"
 #include "BLI_ghash.h"
 
 #include "BLF_translation.h"
@@ -96,23 +94,7 @@ typedef struct {
 	Nurb *orig_nu;
 } CVKeyIndex;
 
-typedef enum eVisible_Types {
-	HIDDEN = true,
-	VISIBLE = false,
-} eVisible_Types;
-
-typedef enum eEndPoint_Types {
-	FIRST = true,
-	LAST = false,
-} eEndPoint_Types;
-
-typedef enum eCurveElem_Types {
-	CURVE_VERTEX = 0,
-	CURVE_SEGMENT,
-} eCurveElem_Types;
-
 void selectend_nurb(Object *obedit, enum eEndPoint_Types selfirst, bool doswap, bool selstatus);
-static void select_adjacent_cp(ListBase *editnurb, short next, const bool cont, const bool selstatus);
 static void adduplicateflagNurb(Object *obedit, ListBase *newnurb, const short flag, const bool split);
 static int curve_delete_segments(Object *obedit, const bool split);
 
@@ -127,61 +109,6 @@ ListBase *object_editcurve_get(Object *ob)
 
 /* ******************* SELECTION FUNCTIONS ********************* */
 
-
-/* returns 1 in case (de)selection was successful */
-static bool select_beztriple(BezTriple *bezt, bool selstatus, short flag, eVisible_Types hidden)
-{	
-	if ((bezt->hide == 0) || (hidden == HIDDEN)) {
-		if (selstatus == SELECT) { /* selects */
-			bezt->f1 |= flag;
-			bezt->f2 |= flag;
-			bezt->f3 |= flag;
-			return true;
-		}
-		else { /* deselects */
-			bezt->f1 &= ~flag;
-			bezt->f2 &= ~flag;
-			bezt->f3 &= ~flag;
-			return true;
-		}
-	}
-	
-	return false;
-}
-
-/* returns 1 in case (de)selection was successful */
-static bool select_bpoint(BPoint *bp, bool selstatus, short flag, bool hidden)
-{	
-	if ((bp->hide == 0) || (hidden == 1)) {
-		if (selstatus == SELECT) {
-			bp->f1 |= flag;
-			return true;
-		}
-		else {
-			bp->f1 &= ~flag;
-			return true;
-		}
-	}
-
-	return false;
-}
-
-static bool swap_selection_beztriple(BezTriple *bezt)
-{
-	if (bezt->f2 & SELECT)
-		return select_beztriple(bezt, DESELECT, SELECT, VISIBLE);
-	else
-		return select_beztriple(bezt, SELECT, SELECT, VISIBLE);
-}
-
-static bool swap_selection_bpoint(BPoint *bp)
-{
-	if (bp->f1 & SELECT)
-		return select_bpoint(bp, DESELECT, SELECT, VISIBLE);
-	else
-		return select_bpoint(bp, SELECT, SELECT, VISIBLE);
-}
-
 int isNurbsel(Nurb *nu)
 {
 	BezTriple *bezt;
@@ -1407,64 +1334,6 @@ void ED_curve_deselect_all(EditNurb *editnurb)
 	}
 }
 
-void ED_curve_select_all(EditNurb *editnurb)
-{
-	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;
-			}
-		}
-	}
-}
-
-void ED_curve_select_swap(EditNurb *editnurb, bool hide_handles)
-{
-	Nurb *nu;
-	BPoint *bp;
-	BezTriple *bezt;
-	int a;
-
-	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++;
-			}
-		}
-		else {
-			bp = nu->bp;
-			a = nu->pntsu * nu->pntsv;
-			while (a--) {
-				swap_selection_bpoint(bp);
-				bp++;
-			}
-		}
-	}
-}
-
 /******************** separate operator ***********************/
 
 static int separate_exec(bContext *C, wmOperator *op)
@@ -2925,274 +2794,6 @@ void CURVE_OT_smooth_tilt(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
-/***************** selection utility *************************/
-
-/* next == 1 -> select next         */
-/* next == -1 -> select previous    */
-/* cont == 1 -> select continuously */
-/* selstatus, inverts behavior		*/
-static void select_adjacent_cp(ListBase *editnurb, short next,
-                               const bool cont, const bool selstatus)
-{
-	Nurb *nu;
-	BezTriple *bezt;
-	BPoint *bp;
-	int a;
-	bool lastsel = false;
-	
-	if (next == 0) return;
-	
-	for (nu = editnurb->first; nu; nu = nu->next) {
-		lastsel = false;
-		if (nu->type == CU_BEZIER) {
-			a = nu->pntsu;
-			bezt = nu->bezt;
-			if (next < 0) bezt = &nu->bezt[a - 1];
-			while (a--) {
-				if (a - abs(next) < 0) break;
-				if ((lastsel == 0) && (bezt->hide == 0) && ((bezt->f2 & SELECT) || (selstatus == DESELECT))) {
-					bezt += next;
-					if (!(bezt->f2 & SELECT) || (selstatus == DESELECT)) {
-						short sel = select_beztriple(bezt, selstatus, SELECT, VISIBLE);
-						if ((sel == 1) && (cont == 0)) lastsel = true;
-					}
-				}
-				else {
-					bezt += next;
-					lastsel = false;
-				}
-				/* move around in zigzag way so that we go through each */
-				bezt -= (next - next / abs(next));
-			}
-		}
-		else {
-			a = nu->pntsu * nu->pntsv;
-			bp = nu->bp;
-			if (next < 0) bp = &nu->bp[a - 1];
-			while (a--) {
-				if (a - abs(next) < 0) break;
-				if ((lastsel == 0) && (bp->hide == 0) && ((bp->f1 & SELECT) || (selstatus == DESELECT))) {
-					bp += next;
-					if (!(bp->f1 & SELECT) || (selstatus == DESELECT)) {
-						short sel = select_bpoint(bp, selstatus, SELECT, VISIBLE);
-						if ((sel == 1) && (cont == 0)) lastsel = true;
-					}
-				}
-				else {
-					bp += next;
-					lastsel = false;
-				}
-				/* move around in zigzag way so that we go through each */
-				bp -= (next - next / abs(next));
-			}
-		}
-	}
-}
-
-/**************** select start/end operators **************/
-
-/* (de)selects first or last of visible part of each Nurb depending on selFirst
- * selFirst: defines the end of which to select
- * doswap: defines if selection state of each first/last control point is swapped
- 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list