[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32114] trunk/blender/source/blender/ editors/space_view3d/view3d_snap.c: - Ignore selected handles if control point is selected when

Sergey Sharybin g.ulairi at gmail.com
Sat Sep 25 08:45:30 CEST 2010


Revision: 32114
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32114
Author:   nazgul
Date:     2010-09-25 08:45:28 +0200 (Sat, 25 Sep 2010)

Log Message:
-----------
- Ignore selected handles if control point is selected when
  snapping cursor to selection (fixes #23966: Cursor to selected: incorrect behaviour in curves)
- Keep handles' of selected vectors if control point is selected when
  snapping selection to grid/cursor
- Added definitions to hard-coded numeric flags for make_trans_verts
  and removed unused proportional flag

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_view3d/view3d_snap.c

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_snap.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_snap.c	2010-09-25 06:36:01 UTC (rev 32113)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_snap.c	2010-09-25 06:45:28 UTC (rev 32114)
@@ -99,6 +99,37 @@
 			Nurb *nu= nurbs->first;
 
 			while(nu) {
+				/* keep handles' vectors unchanged */
+				if(nu->bezt) {
+					int a= nu->pntsu;
+					TransVert *tv= transvmain;
+					BezTriple *bezt= nu->bezt;
+
+					while(a--) {
+						if(bezt->f1 & SELECT) tv++;
+
+						if(bezt->f2 & SELECT) {
+							float v[3];
+
+							if(bezt->f1 & SELECT) {
+								sub_v3_v3v3(v, (tv-1)->oldloc, tv->oldloc);
+								add_v3_v3v3(bezt->vec[0], bezt->vec[1], v);
+							}
+
+							if(bezt->f3 & SELECT) {
+								sub_v3_v3v3(v, (tv+1)->oldloc, tv->oldloc);
+								add_v3_v3v3(bezt->vec[2], bezt->vec[1], v);
+							}
+
+							tv++;
+						}
+
+						if(bezt->f3 & SELECT) tv++;
+
+						bezt++;
+					}
+				}
+
 				test2DNurb(nu);
 				testhandlesNurb(nu); /* test for bezier too */
 				nu= nu->next;
@@ -152,7 +183,9 @@
 }
 
 /* copied from editobject.c, needs to be replaced with new transform code still */
-/* mode: 1 = proportional, 2 = all joints (for bones only) */
+/* mode flags: */
+#define TM_ALL_JOINTS		1 /* all joints (for bones only) */
+#define TM_SKIP_HANDLES		2 /* skip handles when control point is selected (for curves only) */
 static void make_trans_verts(Object *obedit, float *min, float *max, int mode)	
 {
 	Nurb *nu;
@@ -173,7 +206,6 @@
 	if(obedit->type==OB_MESH) {
 		Mesh *me= obedit->data;
 		EditMesh *em= me->edit_mesh;
-		int proptrans= 0;
 		
 		// transform now requires awareness for select mode, so we tag the f1 flags in verts
 		tottrans= 0;
@@ -206,17 +238,6 @@
 			for(eve= em->verts.first; eve; eve= eve->next) if(eve->f1) tottrans++;
 		}
 		
-		/* proportional edit exception... */
-		if((mode & 1) && tottrans) {
-			for(eve= em->verts.first; eve; eve= eve->next) {
-				if(eve->h==0) {
-					eve->f1 |= 2;
-					proptrans++;
-				}
-			}
-			if(proptrans>tottrans) tottrans= proptrans;
-		}
-		
 		/* and now make transverts */
 		if(tottrans) {
 			tv=transvmain= MEM_callocN(tottrans*sizeof(TransVert), "maketransverts");
@@ -248,7 +269,7 @@
 				short rootok= (!(ebo->parent && (ebo->flag & BONE_CONNECTED) && ebo->parent->flag & BONE_TIPSEL));
 				
 				if ((tipsel && rootsel) || (rootsel)) {
-					/* Don't add the tip (unless mode & 2, for getting all joints), 
+					/* Don't add the tip (unless mode & TM_ALL_JOINTS, for getting all joints),
 					 * otherwise we get zero-length bones as tips will snap to the same
 					 * location as heads. 
 					 */
@@ -261,7 +282,7 @@
 						tottrans++;
 					}	
 					
-					if ((mode & 2) && (tipsel)) {
+					if ((mode & TM_ALL_JOINTS) && (tipsel)) {
 						VECCOPY (tv->oldloc, ebo->tail);
 						tv->loc= ebo->tail;
 						tv->nor= NULL;
@@ -301,14 +322,18 @@
 				bezt= nu->bezt;
 				while(a--) {
 					if(bezt->hide==0) {
-						if((mode & 1) || (bezt->f1 & SELECT)) {
+						int skip_handle= 0;
+						if(bezt->f2 & SELECT)
+							skip_handle= mode & TM_SKIP_HANDLES;
+
+						if((bezt->f1 & SELECT) && !skip_handle) {
 							VECCOPY(tv->oldloc, bezt->vec[0]);
 							tv->loc= bezt->vec[0];
 							tv->flag= bezt->f1 & SELECT;
 							tv++;
 							tottrans++;
 						}
-						if((mode & 1) || (bezt->f2 & SELECT)) {
+						if(bezt->f2 & SELECT) {
 							VECCOPY(tv->oldloc, bezt->vec[1]);
 							tv->loc= bezt->vec[1];
 							tv->val= &(bezt->alfa);
@@ -317,7 +342,7 @@
 							tv++;
 							tottrans++;
 						}
-						if((mode & 1) || (bezt->f3 & SELECT)) {
+						if((bezt->f3 & SELECT) && !skip_handle) {
 							VECCOPY(tv->oldloc, bezt->vec[2]);
 							tv->loc= bezt->vec[2];
 							tv->flag= bezt->f3 & SELECT;
@@ -333,7 +358,7 @@
 				bp= nu->bp;
 				while(a--) {
 					if(bp->hide==0) {
-						if((mode & 1) || (bp->f1 & SELECT)) {
+						if(bp->f1 & SELECT) {
 							VECCOPY(tv->oldloc, bp->vec);
 							tv->loc= bp->vec;
 							tv->val= &(bp->alfa);
@@ -376,10 +401,10 @@
 		
 		a= lt->editlatt->latt->pntsu*lt->editlatt->latt->pntsv*lt->editlatt->latt->pntsw;
 		
-		tv=transvmain= MEM_callocN(a*sizeof(TransVert), "maketransverts curve");
+		tv=transvmain= MEM_callocN(a*sizeof(TransVert), "maketransverts latt");
 		
 		while(a--) {
-			if((mode & 1) || (bp->f1 & SELECT)) {
+			if(bp->f1 & SELECT) {
 				if(bp->hide==0) {
 					copy_v3_v3(tv->oldloc, bp->vec);
 					tv->loc= bp->vec;
@@ -392,6 +417,13 @@
 		}
 	}
 	
+	if(!tottrans && transvmain) {
+		/* prevent memory leak. happens for curves/latticies due to */
+		/* difficult condition of adding points to trans data */
+		MEM_freeN(transvmain);
+		transvmain= NULL;
+	}
+
 	/* cent etc */
 	tv= transvmain;
 	total= 0.0;
@@ -727,7 +759,7 @@
 		tottrans=0;
 		
 		if ELEM6(obedit->type, OB_ARMATURE, OB_LATTICE, OB_MESH, OB_SURF, OB_CURVE, OB_MBALL) 
-			make_trans_verts(obedit, bmat[0], bmat[1], 2);
+			make_trans_verts(obedit, bmat[0], bmat[1], TM_ALL_JOINTS|TM_SKIP_HANDLES);
 		if(tottrans==0) return OPERATOR_CANCELLED;
 		
 		copy_m3_m4(bmat, obedit->obmat);
@@ -909,7 +941,7 @@
 
 	tottrans=0;
 	if ELEM5(obedit->type, OB_ARMATURE, OB_LATTICE, OB_MESH, OB_SURF, OB_CURVE) 
-		make_trans_verts(obedit, bmat[0], bmat[1], 2);
+		make_trans_verts(obedit, bmat[0], bmat[1], TM_ALL_JOINTS);
 	
 	if(tottrans==0) return 0;
 





More information about the Bf-blender-cvs mailing list