[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21692] branches/blender2.5/blender/source /blender/editors: 2.5 - Clear Constraints Operators
Joshua Leung
aligorith at gmail.com
Sun Jul 19 09:20:22 CEST 2009
Revision: 21692
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21692
Author: aligorith
Date: 2009-07-19 09:20:21 +0200 (Sun, 19 Jul 2009)
Log Message:
-----------
2.5 - Clear Constraints Operators
Added some operators to clear all constraints on the active object or the selected bones.
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/editors/armature/poseobject.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
branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_header.c
Modified: branches/blender2.5/blender/source/blender/editors/armature/poseobject.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/armature/poseobject.c 2009-07-19 05:20:30 UTC (rev 21691)
+++ branches/blender2.5/blender/source/blender/editors/armature/poseobject.c 2009-07-19 07:20:21 UTC (rev 21692)
@@ -640,39 +640,7 @@
BIF_undo_push("Remove IK constraint(s)");
}
-void pose_clear_constraints(Scene *scene)
-{
- Object *obedit= scene->obedit; // XXX context
- Object *ob= OBACT;
- bArmature *arm= ob->data;
- bPoseChannel *pchan;
-
- /* paranoia checks */
- if(!ob && !ob->pose) return;
- if(ob==obedit || (ob->flag & OB_POSEMODE)==0) return;
-
- if(pose_has_protected_selected(ob, 0, 1))
- return;
-
- if(okee("Remove Constraints")==0) return;
-
- /* find active */
- for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
- if(arm->layer & pchan->bone->layer) {
- if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) {
- free_constraints(&pchan->constraints);
- pchan->constflag= 0;
- }
- }
- }
-
- DAG_object_flush_update(scene, ob, OB_RECALC_DATA); // and all its relations
-
- BIF_undo_push("Remove Constraint(s)");
-
-}
-
void pose_copy_menu(Scene *scene)
{
Object *obedit= scene->obedit; // XXX context
Modified: branches/blender2.5/blender/source/blender/editors/object/editconstraint.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/object/editconstraint.c 2009-07-19 05:20:30 UTC (rev 21691)
+++ branches/blender2.5/blender/source/blender/editors/object/editconstraint.c 2009-07-19 07:20:21 UTC (rev 21692)
@@ -519,28 +519,6 @@
}
-/* Remove all constraints from the active object */
-void ob_clear_constraints (Scene *scene)
-{
- Object *ob= OBACT;
-
- /* paranoia checks */
- if ((ob==NULL) || (ob==scene->obedit) || (ob->flag & OB_POSEMODE))
- return;
-
- /* get user permission */
- if (okee("Clear Constraints")==0)
- return;
-
- /* do freeing */
- free_constraints(&ob->constraints);
-
- /* do updates */
- DAG_object_flush_update(scene, ob, OB_RECALC_OB);
-
- BIF_undo_push("Clear Constraint(s)");
-}
-
/* ------------- Constraint Sanity Testing ------------------- */
/* checks validity of object pointers, and NULLs,
@@ -1006,8 +984,72 @@
/***************************** OPERATORS ****************************/
-/************************ add constraint operator *********************/
+/************************ remove constraint operators *********************/
+static int pose_constraints_clear_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene= CTX_data_scene(C);
+ Object *ob= CTX_data_active_object(C);
+
+ /* free constraints for all selected bones */
+ CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans)
+ {
+ free_constraints(&pchan->constraints);
+ }
+ CTX_DATA_END;
+
+ /* do updates */
+ DAG_object_flush_update(scene, ob, OB_RECALC_OB);
+ WM_event_add_notifier(C, NC_OBJECT|ND_POSE|ND_CONSTRAINT|NA_REMOVED, ob);
+
+ return OPERATOR_FINISHED;
+}
+
+void POSE_OT_constraints_clear(wmOperatorType *ot)
+{
+ /* identifiers */
+ //ot->name = "Clear Constraints";
+ ot->idname= "POSE_OT_constraints_clear";
+ ot->description= "Clear all the constraints for the selected bones.";
+
+ /* callbacks */
+ //ot->invoke= WM_menu_confirm; // XXX do we want confirmations on these things anymore?
+ ot->exec= pose_constraints_clear_exec;
+ ot->poll= ED_operator_posemode; // XXX - do we want to ensure there are selected bones too?
+}
+
+
+static int object_constraints_clear_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene= CTX_data_scene(C);
+ Object *ob= CTX_data_active_object(C);
+
+ /* do freeing */
+ // TODO: we should free constraints for all selected objects instead (to be more consistent with bones)
+ free_constraints(&ob->constraints);
+
+ /* do updates */
+ DAG_object_flush_update(scene, ob, OB_RECALC_OB);
+ WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_REMOVED, ob);
+
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_constraints_clear(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Clear Constraints";
+ ot->idname= "OBJECT_OT_constraints_clear";
+ ot->description= "Clear all the constraints for the active Object only.";
+
+ /* callbacks */
+ //ot->invoke= WM_menu_confirm; // XXX do we want confirmations on these things anymore?
+ ot->exec= object_constraints_clear_exec;
+ ot->poll= ED_operator_object_active;
+}
+
+/************************ add constraint operators *********************/
+
static int constraint_add_exec(bContext *C, wmOperator *op, ListBase *list)
{
Scene *scene= CTX_data_scene(C);
@@ -1071,7 +1113,7 @@
else
DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
+ WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_ADDED, ob);
return OPERATOR_FINISHED;
}
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-19 05:20:30 UTC (rev 21691)
+++ branches/blender2.5/blender/source/blender/editors/object/object_intern.h 2009-07-19 07:20:21 UTC (rev 21692)
@@ -103,6 +103,10 @@
/* editconstraint.c */
void OBJECT_OT_constraint_add(struct wmOperatorType *ot);
void POSE_OT_constraint_add(struct wmOperatorType *ot);
+
+void OBJECT_OT_constraints_clear(struct wmOperatorType *ot);
+void POSE_OT_constraints_clear(struct wmOperatorType *ot);
+
void CONSTRAINT_OT_delete(struct wmOperatorType *ot);
void CONSTRAINT_OT_move_up(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-19 05:20:30 UTC (rev 21691)
+++ branches/blender2.5/blender/source/blender/editors/object/object_ops.c 2009-07-19 07:20:21 UTC (rev 21692)
@@ -113,6 +113,8 @@
WM_operatortype_append(OBJECT_OT_constraint_add);
WM_operatortype_append(POSE_OT_constraint_add);
+ WM_operatortype_append(OBJECT_OT_constraints_clear);
+ WM_operatortype_append(POSE_OT_constraints_clear);
WM_operatortype_append(CONSTRAINT_OT_delete);
WM_operatortype_append(CONSTRAINT_OT_move_up);
WM_operatortype_append(CONSTRAINT_OT_move_down);
Modified: branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_header.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_header.c 2009-07-19 05:20:30 UTC (rev 21691)
+++ branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_header.c 2009-07-19 07:20:21 UTC (rev 21692)
@@ -1978,12 +1978,8 @@
static void view3d_edit_object_constraintsmenu(bContext *C, uiLayout *layout, void *arg_unused)
{
-#if 0
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Constraint...|Ctrl Alt C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
- add_constraint(0);
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Clear Constraints", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
- ob_clear_constraints();
-#endif
+ uiItemO(layout, NULL, 0, "OBJECT_OT_constraint_add"); // XXX it'd be better to have the version which sets links...
+ uiItemO(layout, NULL, 0, "OBJECT_OT_constraints_clear");
}
static void view3d_edit_object_showhidemenu(bContext *C, uiLayout *layout, void *arg_unused)
More information about the Bf-blender-cvs
mailing list