[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21520] branches/blender2.5/blender: 2. 5 - Restored Set/Clear Inverse Buttons for ChildOf Constraint

Joshua Leung aligorith at gmail.com
Sat Jul 11 13:52:20 CEST 2009


Revision: 21520
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21520
Author:   aligorith
Date:     2009-07-11 13:52:20 +0200 (Sat, 11 Jul 2009)

Log Message:
-----------
2.5 - Restored Set/Clear Inverse Buttons for ChildOf Constraint

I've tagged these operators with CONSTRAINT_OT_* not OBJECT_OT_constraint_* since constraints can operate on Bones too (and do so more often)

Modified Paths:
--------------
    branches/blender2.5/blender/release/ui/buttons_object_constraint.py
    branches/blender2.5/blender/source/blender/editors/include/ED_object.h
    branches/blender2.5/blender/source/blender/editors/object/editconstraint.c
    branches/blender2.5/blender/source/blender/editors/object/object_intern.h
    branches/blender2.5/blender/source/blender/editors/object/object_ops.c

Modified: branches/blender2.5/blender/release/ui/buttons_object_constraint.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_object_constraint.py	2009-07-11 11:31:49 UTC (rev 21519)
+++ branches/blender2.5/blender/release/ui/buttons_object_constraint.py	2009-07-11 11:52:20 UTC (rev 21520)
@@ -111,8 +111,8 @@
 		
 		# Missing
 		row = layout.row()
-		row.itemL(text="SET OFFSET")
-		row.itemL(text="CLEAR OFFSET")
+		row.itemO("CONSTRAINT_OT_childof_set_inverse")
+		row.itemO("CONSTRAINT_OT_childof_clear_inverse")
 		
 	def track_to(self, layout, con):
 		self.target_template(layout, con)

Modified: branches/blender2.5/blender/source/blender/editors/include/ED_object.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/ED_object.h	2009-07-11 11:31:49 UTC (rev 21519)
+++ branches/blender2.5/blender/source/blender/editors/include/ED_object.h	2009-07-11 11:52:20 UTC (rev 21520)
@@ -35,7 +35,6 @@
 struct Base;
 struct View3D;
 struct bConstraint;
-struct bConstraintChannel;
 struct KeyBlock;
 struct Lattice;
 struct Mesh;
@@ -78,7 +77,6 @@
 
 struct ListBase *get_active_constraints(struct Object *ob);
 struct bConstraint *get_active_constraint(struct Object *ob);
-struct bConstraintChannel *get_active_constraint_channel(struct Scene *scene, struct Object *ob);
 
 void object_test_constraints(struct Object *ob);
 

Modified: branches/blender2.5/blender/source/blender/editors/object/editconstraint.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/object/editconstraint.c	2009-07-11 11:31:49 UTC (rev 21519)
+++ branches/blender2.5/blender/source/blender/editors/object/editconstraint.c	2009-07-11 11:52:20 UTC (rev 21520)
@@ -117,63 +117,6 @@
 	
 	return NULL;
 }
-
-/* single channel, for ipo */
-bConstraintChannel *get_active_constraint_channel (Scene *scene, Object *ob)
-{
-	bConstraint *con;
-	
-	if (ob->flag & OB_POSEMODE) {
-		//if (ob->action) { // XXX old animation system
-			bPoseChannel *pchan;
-			
-			pchan = get_active_posechannel(ob);
-			if (pchan) {
-				for (con= pchan->constraints.first; con; con= con->next) {
-					if (con->flag & CONSTRAINT_ACTIVE)
-						break;
-				}
-				
-				if (con) {
-#if 0 // XXX old animation system
-					bActionChannel *achan = get_action_channel(ob->action, pchan->name);
-					if (achan) {
-						for (chan= achan->constraintChannels.first; chan; chan= chan->next) {
-							if (!strcmp(chan->name, con->name))
-								break;
-						}
-						return chan;
-					}
-#endif // XXX old animation system
-				}
-			}
-		//} // xxx old animation system
-	}
-	else {
-		for (con= ob->constraints.first; con; con= con->next) {
-			if (con->flag & CONSTRAINT_ACTIVE)
-				break;
-		}
-		
-		if (con) {
-#if 0 // XXX old animation system
-			ListBase *lb= get_active_constraint_channels(scene, ob, 0);
-			
-			if (lb) {
-				for (chan= lb->first; chan; chan= chan->next) {
-					if (!strcmp(chan->name, con->name))
-						break;
-				}
-				
-				return chan;
-			}
-#endif // XXX old animation system
-		}
-	}
-	
-	return NULL;
-}
-
 /* -------------- Constraint Management (Add New, Remove, Rename) -------------------- */
 /* ------------- PyConstraints ------------------ */
 
@@ -790,15 +733,17 @@
 /* ------------- Child-Of Constraint ------------------ */
 
 /* ChildOf Constraint - set inverse callback */
-void childof_const_setinv (void *conv, void *scenev)
+static int childof_set_inverse_exec (bContext *C, wmOperator *op)
 {
-	bConstraint *con= (bConstraint *)conv;
-	Scene *scene= (Scene *)scenev;
+	PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_ChildOfConstraint);
+	Scene *scene= CTX_data_scene(C);
+	Object *ob= ptr.id.data;
+	bConstraint *con= ptr.data;
 	bChildOfConstraint *data= (bChildOfConstraint *)con->data;
-	Object *ob= OBACT;
 	bPoseChannel *pchan= NULL;
 
 	/* try to find a pose channel */
+	// TODO: get from context instead?
 	if (ob && ob->pose)
 		pchan= get_active_posechannel(ob);
 	
@@ -839,18 +784,55 @@
 	}
 	else
 		Mat4One(data->invmat);
+		
+	WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
+		
+	return OPERATOR_FINISHED;
 }
 
+void CONSTRAINT_OT_childof_set_inverse (wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Set Inverse";
+	ot->idname= "CONSTRAINT_OT_childof_set_inverse";
+	ot->description= "Set inverse correction for ChildOf constraint.";
+	
+	ot->exec= childof_set_inverse_exec;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+
 /* ChildOf Constraint - clear inverse callback */
-void childof_const_clearinv (void *conv, void *unused)
+static int childof_clear_inverse_exec (bContext *C, wmOperator *op)
 {
-	bConstraint *con= (bConstraint *)conv;
+	PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_ChildOfConstraint);
+	Object *ob= ptr.id.data;
+	bConstraint *con= ptr.data;
 	bChildOfConstraint *data= (bChildOfConstraint *)con->data;
 	
 	/* simply clear the matrix */
 	Mat4One(data->invmat);
+	
+	WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
+	
+	return OPERATOR_FINISHED;
 }
 
+void CONSTRAINT_OT_childof_clear_inverse (wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Clear Inverse";
+	ot->idname= "CONSTRAINT_OT_childof_clear_inverse";
+	ot->description= "Clear inverse correction for ChildOf constraint.";
+	
+	ot->exec= childof_clear_inverse_exec;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
 /***************************** BUTTONS ****************************/
 
 /* Rename the given constraint, con already has the new name */

Modified: branches/blender2.5/blender/source/blender/editors/object/object_intern.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/object/object_intern.h	2009-07-11 11:31:49 UTC (rev 21519)
+++ branches/blender2.5/blender/source/blender/editors/object/object_intern.h	2009-07-11 11:52:20 UTC (rev 21520)
@@ -102,6 +102,9 @@
 /* editconstraint.c */
 void OBJECT_OT_constraint_add(struct wmOperatorType *ot);
 
+void CONSTRAINT_OT_childof_set_inverse(struct wmOperatorType *ot);
+void CONSTRAINT_OT_childof_clear_inverse(struct wmOperatorType *ot);
+
 /* object_vgroup.c */
 void OBJECT_OT_vertex_group_add(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_remove(struct wmOperatorType *ot);

Modified: branches/blender2.5/blender/source/blender/editors/object/object_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/object/object_ops.c	2009-07-11 11:31:49 UTC (rev 21519)
+++ branches/blender2.5/blender/source/blender/editors/object/object_ops.c	2009-07-11 11:52:20 UTC (rev 21520)
@@ -111,6 +111,8 @@
 	WM_operatortype_append(OBJECT_OT_modifier_mdef_bind);
 
 	WM_operatortype_append(OBJECT_OT_constraint_add);
+	WM_operatortype_append(CONSTRAINT_OT_childof_set_inverse);
+	WM_operatortype_append(CONSTRAINT_OT_childof_clear_inverse);
 
 	WM_operatortype_append(OBJECT_OT_vertex_group_add);
 	WM_operatortype_append(OBJECT_OT_vertex_group_remove);





More information about the Bf-blender-cvs mailing list