[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51208] trunk/blender/source/blender/ editors/space_view3d/view3d_buttons.c: Another refactor for 3D view' s edit Transform panel.

Bastien Montagne montagne29 at wanadoo.fr
Tue Oct 9 11:14:37 CEST 2012


Revision: 51208
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51208
Author:   mont29
Date:     2012-10-09 09:14:37 +0000 (Tue, 09 Oct 2012)
Log Message:
-----------
Another refactor for 3D view's edit Transform panel. Main changes:
*Get rid of the magic numbers for median arrays, use defines instead, should make things a bit more clear and easy to edit (though there are still a bit of "array magic" on median here and there).
*Restore and extend use of RNA prop when a single (control)point of curve or lattice is selected, to allow keyframing (was added by sergey for curve radius in r41494, see [#29122], and reverted by myself in previous refactor r44599).

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41494
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44599

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

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_buttons.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_buttons.c	2012-10-09 08:40:20 UTC (rev 51207)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_buttons.c	2012-10-09 09:14:37 UTC (rev 51208)
@@ -86,13 +86,15 @@
 #define B_REDR              2
 #define B_OBJECTPANELMEDIAN 1008
 
+#define NBR_TRANSFORM_PROPERTIES 7
+
 /* temporary struct for storing transform properties */
 typedef struct {
 	float ob_eul[4];   /* used for quat too... */
 	float ob_scale[3]; /* need temp space due to linked values */
 	float ob_dims[3];
 	short link_scale;
-	float ve_median[9];
+	float ve_median[NBR_TRANSFORM_PROPERTIES];
 	int curdef;
 	float *defweightp;
 } TransformProperties;
@@ -131,17 +133,38 @@
 /* is used for both read and write... */
 static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float lim)
 {
+/* Get rid of those ugly magic numbers, even in a single func they become confusing! */
+/* Location, common to all. */
+/* XXX Those two *must* remain contiguous (used as array)! */
+#define LOC_X     0
+#define LOC_Y     1
+#define LOC_Z     2
+/* Meshes... */
+#define M_CREASE  3
+#define M_WEIGHT  4
+/* XXX Those two *must* remain contiguous (used as array)! */
+#define M_SKIN_X  5
+#define M_SKIN_Y  6
+/* Curves... */
+#define C_BWEIGHT 3
+#define C_WEIGHT  4
+#define C_RADIUS  5
+#define C_TILT    6
+/*Lattice... */
+#define L_WEIGHT  4
+
 	uiBlock *block = (layout) ? uiLayoutAbsoluteBlock(layout) : NULL;
 	MDeformVert *dvert = NULL;
 	TransformProperties *tfp;
-	float median[9], ve_median[9];
-	int tot, totw, totweight, totedge, totradius, totskinradius;
+	float median[NBR_TRANSFORM_PROPERTIES], ve_median[NBR_TRANSFORM_PROPERTIES];
+	int tot, totedgedata, totcurvedata, totlattdata, totskinradius, totcurvebweight;
+	int meshdata = FALSE, i;
 	char defstr[320];
-	PointerRNA radius_ptr;
+	PointerRNA data_ptr;
 
-	median[0] = median[1] = median[2] = median[3] = median[4] = median[5] = median[6] = median[7] = median[8] = 0.0;
-	tot = totw = totweight = totedge = totradius = totskinradius = 0;
-	defstr[0] = 0;
+	fill_vn_fl(median, NBR_TRANSFORM_PROPERTIES, 0.0f);
+	tot = totedgedata = totcurvedata = totlattdata = totskinradius = totcurvebweight = 0;
+	defstr[0] = '\0';
 
 	/* make sure we got storage */
 	if (v3d->properties_storage == NULL)
@@ -162,11 +185,11 @@
 
 				evedef = eve;
 				tot++;
-				add_v3_v3(median, eve->co);
+				add_v3_v3(&median[LOC_X], eve->co);
 
 				vs = (MVertSkin *)CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MVERT_SKIN);
 				if (vs) {
-					add_v2_v2(median + 7, vs->radius); /* Third val not used currently. */
+					add_v2_v2(&median[M_SKIN_X], vs->radius); /* Third val not used currently. */
 					totskinradius++;
 				}
 			}
@@ -176,12 +199,12 @@
 			if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
 				float *f;
 
-				totedge++;
+				totedgedata++;
 				f = (float *)CustomData_bmesh_get(&bm->edata, eed->head.data, CD_CREASE);
-				median[3] += f ? *f : 0.0f;
+				median[M_CREASE] += f ? *f : 0.0f;
 
 				f = (float *)CustomData_bmesh_get(&bm->edata, eed->head.data, CD_BWEIGHT);
-				median[6] += f ? *f : 0.0f;
+				median[M_WEIGHT] += f ? *f : 0.0f;
 			}
 		}
 
@@ -211,6 +234,8 @@
 				tfp->defweightp = &dvert->dw[0].weight;
 			}
 		}
+
+		meshdata = totedgedata || totskinradius;
 	}
 	else if (ob->type == OB_CURVE || ob->type == OB_SURF) {
 		Curve *cu = ob->data;
@@ -229,22 +254,24 @@
 				a = nu->pntsu;
 				while (a--) {
 					if (bezt->f2 & SELECT) {
-						add_v3_v3(median, bezt->vec[1]);
+						add_v3_v3(&median[LOC_X], bezt->vec[1]);
 						tot++;
-						median[4] += bezt->weight;
-						totweight++;
-						median[5] += bezt->radius;
-						totradius++;
-						selp = bezt;
-						seltype = &RNA_BezierSplinePoint;
+						median[C_WEIGHT] += bezt->weight;
+						median[C_RADIUS] += bezt->radius;
+						median[C_TILT] += bezt->alfa;
+						if (!totcurvedata) { /* I.e. first time... */
+							selp = bezt;
+							seltype = &RNA_BezierSplinePoint;
+						}
+						totcurvedata++;
 					}
 					else {
 						if (bezt->f1 & SELECT) {
-							add_v3_v3(median, bezt->vec[0]);
+							add_v3_v3(&median[LOC_X], bezt->vec[0]);
 							tot++;
 						}
 						if (bezt->f3 & SELECT) {
-							add_v3_v3(median, bezt->vec[2]);
+							add_v3_v3(&median[LOC_X], bezt->vec[2]);
 							tot++;
 						}
 					}
@@ -256,16 +283,18 @@
 				a = nu->pntsu * nu->pntsv;
 				while (a--) {
 					if (bp->f1 & SELECT) {
-						add_v3_v3(median, bp->vec);
-						median[3] += bp->vec[3];
-						totw++;
+						add_v3_v3(&median[LOC_X], bp->vec);
+						median[C_BWEIGHT] += bp->vec[3];
+						totcurvebweight++;
 						tot++;
-						median[4] += bp->weight;
-						totweight++;
-						median[5] += bp->radius;
-						totradius++;
-						selp = bp;
-						seltype = &RNA_SplinePoint;
+						median[C_WEIGHT] += bp->weight;
+						median[C_RADIUS] += bp->radius;
+						median[C_TILT] += bp->alfa;
+						if (!totcurvedata) { /* I.e. first time... */
+							selp = bp;
+							seltype = &RNA_SplinePoint;
+						}
+						totcurvedata++;
 					}
 					bp++;
 				}
@@ -273,84 +302,102 @@
 			nu = nu->next;
 		}
 
-		if (totradius == 1)
-			RNA_pointer_create(&cu->id, seltype, selp, &radius_ptr);
+		if (totcurvedata == 1)
+			RNA_pointer_create(&cu->id, seltype, selp, &data_ptr);
 	}
 	else if (ob->type == OB_LATTICE) {
 		Lattice *lt = ob->data;
 		BPoint *bp;
 		int a;
+		StructRNA *seltype = NULL;
+		void *selp = NULL;
 
 		a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw;
 		bp = lt->editlatt->latt->def;
 		while (a--) {
 			if (bp->f1 & SELECT) {
-				add_v3_v3(median, bp->vec);
+				add_v3_v3(&median[LOC_X], bp->vec);
 				tot++;
-				median[4] += bp->weight;
-				totweight++;
+				median[L_WEIGHT] += bp->weight;
+				if (!totlattdata) { /* I.e. first time... */
+					selp = bp;
+					seltype = &RNA_LatticePoint;
+				}
+				totlattdata++;
 			}
 			bp++;
 		}
+
+		if (totlattdata == 1)
+			RNA_pointer_create(&lt->id, seltype, selp, &data_ptr);
 	}
 
 	if (tot == 0) {
 		uiDefBut(block, LABEL, 0, IFACE_("Nothing selected"), 0, 130, 200, 20, NULL, 0, 0, 0, 0, "");
 		return;
 	}
-	median[0] /= (float)tot;
-	median[1] /= (float)tot;
-	median[2] /= (float)tot;
-	if (totedge) {
-		median[3] /= (float)totedge;
-		median[6] /= (float)totedge;
+
+	/* Location, X/Y/Z */
+	mul_v3_fl(&median[LOC_X], 1.0f / (float)tot);
+	if (v3d->flag & V3D_GLOBAL_STATS)
+		mul_m4_v3(ob->obmat, &median[LOC_X]);
+
+	if (meshdata) {
+		if (totedgedata) {
+			median[M_CREASE] /= (float)totedgedata;
+			median[M_WEIGHT] /= (float)totedgedata;
+		}
+		if (totskinradius) {
+			median[M_SKIN_X] /= (float)totskinradius;
+			median[M_SKIN_Y] /= (float)totskinradius;
+		}
 	}
-	else if (totw)
-		median[3] /= (float)totw;
-	if (totweight)
-		median[4] /= (float)totweight;
-	if (totradius)
-		median[5] /= (float)totradius;
-	if (totskinradius) {
-		median[7] /= (float)totskinradius;
-		median[8] /= (float)totskinradius;
+	else if (totcurvedata) {
+		median[C_WEIGHT] /= (float)totcurvedata;
+		median[C_RADIUS] /= (float)totcurvedata;
+		median[C_TILT] /= (float)totcurvedata;
+		if (totcurvebweight)
+			median[C_BWEIGHT] /= (float)totcurvebweight;
 	}
+	else if (totlattdata)
+		median[L_WEIGHT] /= (float)totlattdata;
 
-	if (v3d->flag & V3D_GLOBAL_STATS)
-		mul_m4_v3(ob->obmat, median);
-
 	if (block) { /* buttons */
 		uiBut *but;
 		int yi = 200;
 		const int buth = 20 * UI_DPI_ICON_FAC;
 		const int but_margin = 2;
+		const char *c;
 
 		memcpy(tfp->ve_median, median, sizeof(tfp->ve_median));
 
 		uiBlockBeginAlign(block);
 		if (tot == 1) {
-			uiDefBut(block, LABEL, 0, IFACE_("Vertex:"), 0, yi -= buth, 200, buth, NULL, 0, 0, 0, 0, "");
+			if (totcurvedata) /* Curve */
+				c = IFACE_("Control Point:");
+			else /* Mesh or lattice */
+				c = IFACE_("Vertex:");
 		}
-		else {
-			uiDefBut(block, LABEL, 0, IFACE_("Median:"), 0, yi -= buth, 200, buth, NULL, 0, 0, 0, 0, "");
-		}
+		else
+			c = IFACE_("Median:");
+		uiDefBut(block, LABEL, 0, c, 0, yi -= buth, 200, buth, NULL, 0, 0, 0, 0, "");
 
 		uiBlockBeginAlign(block);
 
 		/* Should be no need to translate these. */
 		but = uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "X:", 0, yi -= buth, 200, buth,
-		                &(tfp->ve_median[0]), -lim, lim, 10, RNA_TRANSLATION_PREC_DEFAULT, "");
+		                &(tfp->ve_median[LOC_X]), -lim, lim, 10, RNA_TRANSLATION_PREC_DEFAULT, "");
 		uiButSetUnitType(but, PROP_UNIT_LENGTH);
 		but = uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Y:", 0, yi -= buth, 200, buth,
-		                &(tfp->ve_median[1]), -lim, lim, 10, RNA_TRANSLATION_PREC_DEFAULT, "");
+		                &(tfp->ve_median[LOC_Y]), -lim, lim, 10, RNA_TRANSLATION_PREC_DEFAULT, "");
 		uiButSetUnitType(but, PROP_UNIT_LENGTH);
 		but = uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Z:", 0, yi -= buth, 200, buth,
-		                &(tfp->ve_median[2]), -lim, lim, 10, RNA_TRANSLATION_PREC_DEFAULT, "");
+		                &(tfp->ve_median[LOC_Z]), -lim, lim, 10, RNA_TRANSLATION_PREC_DEFAULT, "");
 		uiButSetUnitType(but, PROP_UNIT_LENGTH);
 
-		if (totw == tot) {
+		if (totcurvebweight == tot) {
 			uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "W:", 0, yi -= buth, 200, buth,
-			          &(tfp->ve_median[3]), 0.01, 100.0, 1, 3, "");
+			          &(tfp->ve_median[C_BWEIGHT]), 0.01, 100.0, 1, 3, "");
 		}
 
 		uiBlockBeginAlign(block);
@@ -362,62 +409,62 @@
 		             &v3d->flag, 0, 0, 0, 0, "Displays local values");
 		uiBlockEndAlign(block);
 
-		if (totweight == 1) {
-			uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, IFACE_("Weight:"),
-			          0, yi -= buth + but_margin, 200, buth,
-			          &(tfp->ve_median[4]), 0.0, 1.0, 1, 3, TIP_("Weight used for SoftBody Goal"));
+		/* Meshes... */
+		if (meshdata) {
+			if (totedgedata) {
+				uiDefButF(block, NUM, B_OBJECTPANELMEDIAN,
+					      totedgedata == 1 ? IFACE_("Crease:") : IFACE_("Mean Crease:"),
+					      0, yi -= buth + but_margin, 200, buth,
+					      &(tfp->ve_median[M_CREASE]), 0.0, 1.0, 1, 3, TIP_("Weight used by SubSurf modifier"));
+				uiDefButF(block, NUM, B_OBJECTPANELMEDIAN,
+					      totedgedata == 1 ? IFACE_("Bevel Weight:") : IFACE_("Mean Bevel Weight:"),
+					      0, yi -= buth + but_margin, 200, buth,
+					      &(tfp->ve_median[M_WEIGHT]), 0.0, 1.0, 1, 3, TIP_("Weight used by Bevel modifier"));
+			}
+			if (totskinradius) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list