[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19749] branches/blender2.5/blender/source /blender: PoseLib: Fixed up RNA-properties for this operator so that it can be repeated using the exec () callback added in previous commit.

Joshua Leung aligorith at gmail.com
Thu Apr 16 02:53:22 CEST 2009


Revision: 19749
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19749
Author:   aligorith
Date:     2009-04-16 02:53:22 +0200 (Thu, 16 Apr 2009)

Log Message:
-----------
PoseLib: Fixed up RNA-properties for this operator so that it can be repeated using the exec() callback added in previous commit.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c
    branches/blender2.5/blender/source/blender/editors/armature/poselib.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c	2009-04-16 00:33:40 UTC (rev 19748)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c	2009-04-16 00:53:22 UTC (rev 19749)
@@ -1889,7 +1889,6 @@
 			printf("do Action Constraint %s - Ob %s Pchan %s \n", con->name, cob->ob->id.name+2, (cob->pchan)?cob->pchan->name:NULL);
 		
 		/* Get the appropriate information from the action */
-		// XXX probably we might need some special filtering methods to make this more efficient
 		if (cob->type == CONSTRAINT_OBTYPE_BONE) {
 			Object workob;
 			bPose *pose;

Modified: branches/blender2.5/blender/source/blender/editors/armature/poselib.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/armature/poselib.c	2009-04-16 00:33:40 UTC (rev 19748)
+++ branches/blender2.5/blender/source/blender/editors/armature/poselib.c	2009-04-16 00:53:22 UTC (rev 19749)
@@ -824,8 +824,12 @@
 			pld->flag &= ~PL_PREVIEW_FIRSTTIME;
 			
 		/* pose should be the right one to draw (unless we're temporarily not showing it) */
-		if ((pld->flag & PL_PREVIEW_SHOWORIGINAL)==0)
+		if ((pld->flag & PL_PREVIEW_SHOWORIGINAL)==0) {
+			RNA_int_set(op->ptr, "pose_index", BLI_findindex(&pld->act->markers, pld->marker));
 			poselib_apply_pose(pld);
+		}
+		else
+			RNA_int_set(op->ptr, "pose_index", -2); /* -2 means don't apply any pose */
 		
 		/* old optimize trick... this enforces to bypass the depgraph 
 		 *	- note: code copied from transform_generics.c -> recalcData()
@@ -1241,7 +1245,7 @@
 {
 	tPoseLib_PreviewData *pld;
 	Object *ob= CTX_data_active_object(C);
-	short apply_active= RNA_boolean_get(op->ptr, "apply_active");
+	int pose_index = RNA_int_get(op->ptr, "pose_index");
 	
 	/* set up preview state info */
 	op->customdata= pld= MEM_callocN(sizeof(tPoseLib_PreviewData), "PoseLib Preview Data");
@@ -1251,11 +1255,18 @@
 	pld->arm= (ob) ? (ob->data) : NULL;
 	pld->pose= (ob) ? (ob->pose) : NULL;
 	pld->act= (ob) ? (ob->poselib) : NULL;
-	pld->marker= poselib_get_active_pose(pld->act);
 	
 	pld->scene= CTX_data_scene(C);
 	pld->sa= CTX_wm_area(C);
 	
+	/* get starting pose based on RNA-props for this operator */
+	if (pose_index == -1)
+		pld->marker= poselib_get_active_pose(pld->act);
+	else if (pose_index == -2)
+		pld->flag |= PL_PREVIEW_SHOWORIGINAL;
+	else
+		pld->marker= (pld->act) ? BLI_findlink(&pld->act->markers, pose_index) : NULL;
+	
 	/* check if valid poselib */
 	if (ELEM3(NULL, pld->ob, pld->pose, pld->arm)) {
 		BKE_report(op->reports, RPT_ERROR, "PoseLib is only for Armatures in PoseMode");
@@ -1268,10 +1279,10 @@
 		return;
 	}
 	if (pld->marker == NULL) {
-		if ((apply_active==0) && (pld->act->markers.first)) {
+		if (pld->act->markers.first) {
 			/* just use first one then... */
 			pld->marker= pld->act->markers.first;
-			printf("PoseLib had no active pose\n");
+			if (pose_index > -2) printf("PoseLib had no active pose\n");
 		}
 		else {
 			BKE_report(op->reports, RPT_ERROR, "PoseLib has no poses to preview/apply");
@@ -1287,9 +1298,9 @@
 	poselib_backup_posecopy(pld);
 	
 	/* set flags for running */
-	pld->state= (apply_active) ? PL_PREVIEW_RUNONCE : PL_PREVIEW_RUNNING;
+	pld->state= PL_PREVIEW_RUNNING;
 	pld->redraw= PL_PREVIEW_REDRAWALL;
-	pld->flag= PL_PREVIEW_FIRSTTIME;
+	pld->flag |= PL_PREVIEW_FIRSTTIME;
 	
 	/* set depsgraph flags */
 		/* make sure the lock is set OK, unlock can be accidentally saved? */
@@ -1392,17 +1403,9 @@
 	int ret;
 	
 	/* 1) check state to see if we're still running */
-	if (ELEM(pld->state, PL_PREVIEW_RUNONCE, PL_PREVIEW_RUNNING) == 0)
+	if (pld->state != PL_PREVIEW_RUNNING)
 		return poselib_preview_exit(C, op);
 	
-	/* check if time to exit */
-	if (pld->state == PL_PREVIEW_RUNONCE) {
-		/* set status to cleanup time */
-		pld->state = PL_PREVIEW_CONFIRM;
-		
-		return poselib_preview_exit(C, op);
-	}
-	
 	/* 2) handle events */
 	ret= poselib_preview_handle_event(C, op, event);
 	
@@ -1410,7 +1413,7 @@
 	if (pld->redraw)
 		poselib_preview_apply(C, op);
 	
-	return ret; //OPERATOR_RUNNING_MODAL;
+	return ret;
 }
 
 /* Modal Operator init */
@@ -1452,9 +1455,17 @@
 		return OPERATOR_CANCELLED;
 	}
 	
+	/* the exec() callback is effectively a 'run-once' scenario, so set the state to that
+	 * so that everything draws correctly
+	 */
+	pld->state = PL_PREVIEW_RUNONCE;
+	
 	/* apply the active pose */
 	poselib_preview_apply(C, op);
 	
+	/* now, set the status to exit */
+	pld->state = PL_PREVIEW_CONFIRM;
+	
 	/* cleanup */
 	return poselib_preview_exit(C, op);
 }
@@ -1477,6 +1488,5 @@
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 	
 	/* properties */	
-		// FIXME: the following should be removed...
-	RNA_def_boolean(ot->srna, "apply_active", 0, "Apply Active Pose", "Simply apply the active pose and exit");
+	RNA_def_int(ot->srna, "pose_index", -1, -2, INT_MAX, "Pose", "Index of the pose to apply (-2 for no change to pose, -1 for poselib active pose)", 0, INT_MAX);
 }





More information about the Bf-blender-cvs mailing list