[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21522] branches/blender2.5/blender: 2. 5 - Made more operators for constraint buttons

Joshua Leung aligorith at gmail.com
Sat Jul 11 14:54:17 CEST 2009


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

Log Message:
-----------
2.5 - Made more operators for constraint buttons 

* Move Up/Down and Delete are now operators 
* Made TrackTo constraint use expanded enum toggles for up axis too. 
--> BUG ALERT: specifying name and expand in the arguments to itemR doesn't work (name gets skipped)

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/interface/interface_templates.c
    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:58:50 UTC (rev 21521)
+++ branches/blender2.5/blender/release/ui/buttons_object_constraint.py	2009-07-11 12:54:17 UTC (rev 21522)
@@ -109,7 +109,6 @@
 		sub.itemR(con, "sizey", text="Y")
 		sub.itemR(con, "sizez", text="Z")
 		
-		# Missing
 		row = layout.row()
 		row.itemO("CONSTRAINT_OT_childof_set_inverse")
 		row.itemO("CONSTRAINT_OT_childof_clear_inverse")
@@ -122,6 +121,7 @@
 		row.itemR(con, "track", expand=True)
 		
 		row = layout.row()
+		#row.itemR(con, "up", text="Up", expand=True) # XXX: up and expand don't play nice together
 		row.itemR(con, "up", text="Up")
 		row.itemR(con, "target_z")
 		

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:58:50 UTC (rev 21521)
+++ branches/blender2.5/blender/source/blender/editors/include/ED_object.h	2009-07-11 12:54:17 UTC (rev 21522)
@@ -82,9 +82,6 @@
 
 void ED_object_constraint_rename(struct Object *ob, struct bConstraint *con, char *oldname);
 void ED_object_constraint_set_active(struct Object *ob, struct bConstraint *con);
-int ED_object_constraint_delete(struct ReportList *reports, struct Object *ob, struct bConstraint *con);
-int ED_object_constraint_move_down(struct ReportList *reports, struct Object *ob, struct bConstraint *con);
-int ED_object_constraint_move_up(struct ReportList *reports, struct Object *ob, struct bConstraint *con);
 
 /* editlattice.c */
 void mouse_lattice(struct bContext *C, short mval[2], int extend);

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_templates.c	2009-07-11 11:58:50 UTC (rev 21521)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_templates.c	2009-07-11 12:54:17 UTC (rev 21522)
@@ -616,12 +616,6 @@
 	ED_object_constraint_set_active(ob_v, con_v);
 }
 
-static void del_constraint_func (bContext *C, void *ob_v, void *con_v)
-{
-	if(ED_object_constraint_delete(NULL, ob_v, con_v))
-		ED_undo_push(C, "Delete Constraint");
-}
-
 static void verify_constraint_name_func (bContext *C, void *con_v, void *name_v)
 {
 	Object *ob= CTX_data_active_object(C);
@@ -639,18 +633,6 @@
 	// XXX allqueue(REDRAWACTION, 0); 
 }
 
-static void constraint_moveUp(bContext *C, void *ob_v, void *con_v)
-{
-	if(ED_object_constraint_move_up(NULL, ob_v, con_v))
-		ED_undo_push(C, "Move Constraint");
-}
-
-static void constraint_moveDown(bContext *C, void *ob_v, void *con_v)
-{
-	if(ED_object_constraint_move_down(NULL, ob_v, con_v))
-		ED_undo_push(C, "Move Constraint");
-}
-
 /* some commonly used macros in the constraints drawing code */
 #define is_armature_target(target) (target && target->type==OB_ARMATURE)
 #define is_armature_owner(ob) ((ob->type == OB_ARMATURE) && (ob->flag & OB_POSEMODE))
@@ -828,25 +810,18 @@
 			uiBlockBeginAlign(block);
 				uiBlockSetEmboss(block, UI_EMBOSS);
 				
-				if (show_upbut) {
-					but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_UP, xco+width-50, yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint up in constraint stack");
-					uiButSetFunc(but, constraint_moveUp, ob, con);
-				}
+				if (show_upbut)
+					uiDefIconButO(block, BUT, "CONSTRAINT_OT_move_up", WM_OP_INVOKE_DEFAULT, VICON_MOVE_UP, xco+width-50, yco, 16, 18, "Move constraint up in constraint stack");
 				
-				if (show_downbut) {
-					but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_DOWN, xco+width-50+18, yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint down in constraint stack");
-					uiButSetFunc(but, constraint_moveDown, ob, con);
-				}
+				if (show_downbut)
+					uiDefIconButO(block, BUT, "CONSTRAINT_OT_move_down", WM_OP_INVOKE_DEFAULT, VICON_MOVE_DOWN, xco+width-50+18, yco, 16, 18, "Move constraint down in constraint stack");
 			uiBlockEndAlign(block);
 		}
 		
 		
 		/* Close 'button' - emboss calls here disable drawing of 'button' behind X */
 		uiBlockSetEmboss(block, UI_EMBOSSN);
-		
-		but = uiDefIconBut(block, BUT, B_CONSTRAINT_CHANGETARGET, ICON_X, xco+262, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Delete constraint");
-		uiButSetFunc(but, del_constraint_func, ob, con);
-		
+			uiDefIconButO(block, BUT, "CONSTRAINT_OT_delete", WM_OP_INVOKE_DEFAULT, ICON_X, xco+262, yco, 19, 19, "Delete constraint");
 		uiBlockSetEmboss(block, UI_EMBOSS);
 	}
 	
@@ -944,19 +919,6 @@
 			}
 			break;
 #endif /* DISABLE_PYTHON */
-		/*case CONSTRAINT_TYPE_CHILDOF:
-			{
-				// Inverse options 
-				uiBlockBeginAlign(block);
-					but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Set Offset", xco, yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Calculate current Parent-Inverse Matrix (i.e. restore offset from parent)");
-					// XXX uiButSetFunc(but, childof_const_setinv, con, NULL);
-					
-					but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Clear Offset", xco+((width/2)+10), yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Clear Parent-Inverse Matrix (i.e. clear offset from parent)");
-					// XXX uiButSetFunc(but, childof_const_clearinv, con, NULL);
-				uiBlockEndAlign(block);
-			}
-			break; 
-		*/
 		
 		/*case CONSTRAINT_TYPE_RIGIDBODYJOINT:
 			{

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:58:50 UTC (rev 21521)
+++ branches/blender2.5/blender/source/blender/editors/object/editconstraint.c	2009-07-11 12:54:17 UTC (rev 21522)
@@ -81,7 +81,6 @@
 
 /* -------------- Get Active Constraint Data ---------------------- */
 
-
 /* if object in posemode, active bone constraints, else object constraints */
 ListBase *get_active_constraints (Object *ob)
 {
@@ -841,7 +840,6 @@
 	bConstraint *tcon;
 	ListBase *conlist= NULL;
 	int from_object= 0;
-	char *channame="";
 	
 	/* get context by searching for con (primitive...) */
 	for (tcon= ob->constraints.first; tcon; tcon= tcon->next) {
@@ -851,7 +849,6 @@
 	
 	if (tcon) {
 		conlist= &ob->constraints;
-		channame= "Object";
 		from_object= 1;
 	}
 	else if (ob->pose) {
@@ -868,7 +865,6 @@
 		
 		if (tcon) {
 			conlist= &pchan->constraints;
-			channame= pchan->name;
 		}
 	}
 	
@@ -878,7 +874,7 @@
 	}
 	
 	/* first make sure it's a unique name within context */
-	unique_constraint_name (con, conlist);
+	unique_constraint_name(con, conlist);
 }
 
 
@@ -901,77 +897,111 @@
 		if(con==origcon) con->flag |= CONSTRAINT_ACTIVE;
 		else con->flag &= ~CONSTRAINT_ACTIVE;
 	}
-
-	/* make sure ipowin and buttons shows it */
-	if(ob->ipowin==ID_CO) {
-		// XXX allqueue(REDRAWIPO, ID_CO);
-		// XXX allspace(REMAKEIPO, 0);
-		// XXX allqueue(REDRAWNLA, 0);
-	}
-	// XXX allqueue(REDRAWBUTSOBJECT, 0);
 }
 
-int ED_object_constraint_delete(ReportList *reports, Object *ob, bConstraint *con)
+static int constraint_delete_exec (bContext *C, wmOperator *op)
 {
-	bConstraintChannel *chan;
+	PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
+	Object *ob= ptr.id.data;
+	bConstraint *con= ptr.data;
 	ListBase *lb;
 	
-	/* remove ipo channel */
-	lb= NULL; // XXX get_active_constraint_channels(ob, 0);
-	if(lb) {
-		chan = NULL; // XXX get_constraint_channel(lb, con->name);
-		if(chan) {
-			if(chan->ipo) chan->ipo->id.us--;
-			BLI_freelinkN(lb, chan);
-		}
-	}
-
 	/* remove constraint itself */
 	lb= get_active_constraints(ob);
 	free_constraint_data(con);
 	BLI_freelinkN(lb, con);
 	
 	ED_object_constraint_set_active(ob, NULL);
+	WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
 
-	return 1;
+	return OPERATOR_FINISHED;
 }
 
-int ED_object_constraint_move_down(ReportList *reports, Object *ob, bConstraint *constr)
+void CONSTRAINT_OT_delete (wmOperatorType *ot)
 {
-	bConstraint *con;
-	ListBase *conlist;
+	/* identifiers */
+	ot->name= "Delete Constraint";
+	ot->idname= "CONSTRAINT_OT_delete";
+	ot->description= "Remove constraitn from constraint stack.";
 	
-	if(constr->next) {
-		conlist = get_active_constraints(ob);
-		for(con= conlist->first; con; con= con->next) {
-			if(con==constr) {
-				BLI_remlink(conlist, con);
-				BLI_insertlink(conlist, con->next, con);
-				return 1;
-			}
-		}
+	/* callbacks */
+	ot->exec= constraint_delete_exec;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 
+}
+
+static int constraint_move_down_exec (bContext *C, wmOperator *op)
+{
+	PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
+	Object *ob= ptr.id.data;
+	bConstraint *con= ptr.data;
+	
+	if (con->next) {
+		ListBase *conlist= get_active_constraints(ob);
+		bConstraint *nextCon= con->next;
+		
+		/* insert the nominated constraint after the one that used to be after it */
+		BLI_remlink(conlist, con);
+		BLI_insertlinkafter(conlist, nextCon, con);
+		
+		WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
+		
+		return OPERATOR_FINISHED;
 	}
+	
+	return OPERATOR_CANCELLED;
+}
 
-	return 0;
+void CONSTRAINT_OT_move_down (wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Move Constraint Down";
+	ot->idname= "CONSTRAINT_OT_move_down";
+	ot->description= "Move constraint down constraint stack.";
+	
+	/* callbacks */
+	ot->exec= constraint_move_down_exec;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 
 }
 
-int ED_object_constraint_move_up(ReportList *reports, Object *ob, bConstraint *constr)
+
+static int constraint_move_up_exec (bContext *C, wmOperator *op)
 {
-	bConstraint *con;
-	ListBase *conlist;
+	PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
+	Object *ob= ptr.id.data;
+	bConstraint *con= ptr.data;
 	
-	if(constr->prev) {
-		conlist = get_active_constraints(ob);
-		for(con= conlist->first; con; con= con->next) {
-			if(con==constr) {
-				BLI_remlink(conlist, con);
-				BLI_insertlink(conlist, con->prev->prev, con);
-				return 1;
-			}
-		}
+	if (con->prev) {
+		ListBase *conlist= get_active_constraints(ob);
+		bConstraint *prevCon= con->prev;
+		
+		/* insert the nominated constraint before the one that used to be before it */
+		BLI_remlink(conlist, con);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list