Bugfix - Hook Operators:
authorJoshua Leung <aligorith@gmail.com>
Mon, 23 Nov 2009 02:27:52 +0000 (02:27 +0000)
committerJoshua Leung <aligorith@gmail.com>
Mon, 23 Nov 2009 02:27:52 +0000 (02:27 +0000)
These now work for curves, nurbs, and lattices in addition to meshes again.

source/blender/editors/object/object_hook.c
source/blender/editors/object/object_ops.c

index d97806cd806defd1ce7bcc1c06567b171750541a..a2feee54c8c4a9912a6726b7b58311d5c287d083 100644 (file)
@@ -55,6 +55,7 @@
 #include "BKE_object.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
+#include "BKE_utildefines.h"
 
 #include "RNA_define.h"
 #include "RNA_access.h"
@@ -385,6 +386,22 @@ static void object_hook_select(Object *ob, HookModifierData *hmd)
        else if(ob->type==OB_SURF) select_editcurve_hook(ob, hmd);
 }
 
+/* special poll operators for hook operators */
+// TODO: check for properties window modifier context too as alternative?
+static int hook_op_edit_poll(bContext *C)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       
+       if (obedit) {
+               if (ED_operator_editmesh(C)) return 1;
+               if (ED_operator_editsurfcurve(C)) return 1;
+               if (ED_operator_editlattice(C)) return 1;
+               //if (ED_operator_editmball(C)) return 1;
+       }
+       
+       return 0;
+}
+
 static Object *add_hook_object_new(Scene *scene, Object *obedit)
 {
        Base *base, *basedit;
@@ -403,7 +420,6 @@ static Object *add_hook_object_new(Scene *scene, Object *obedit)
        return ob;
 }
 
-
 static void add_hook_object(Scene *scene, Object *obedit, Object *ob, int mode)
 {
        ModifierData *md=NULL;
@@ -488,7 +504,7 @@ void OBJECT_OT_hook_add_selobj(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= object_add_hook_selob_exec;
-       ot->poll= ED_operator_editmesh;
+       ot->poll= hook_op_edit_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -514,7 +530,7 @@ void OBJECT_OT_hook_add_newobj(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= object_add_hook_newob_exec;
-       ot->poll= ED_operator_editmesh;
+       ot->poll= hook_op_edit_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -585,9 +601,9 @@ void OBJECT_OT_hook_remove(wmOperatorType *ot)
        ot->description= "Remove a hook from the active object.";
        
        /* api callbacks */
-       ot->poll= ED_operator_editmesh;
        ot->exec= object_hook_remove_exec;
        ot->invoke= WM_menu_invoke;
+       ot->poll= hook_op_edit_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -607,7 +623,8 @@ static int object_hook_reset_exec(bContext *C, wmOperator *op)
        if (ptr.data) {         /* if modifier context is available, use that */
                ob = ptr.id.data;
                hmd= ptr.data;
-       } else {                        /* use the provided property */
+       } 
+       else {                  /* use the provided property */
                ob = CTX_data_edit_object(C);
                hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num);
        }
@@ -617,7 +634,6 @@ static int object_hook_reset_exec(bContext *C, wmOperator *op)
        }
        
        /* reset functionality */
-       
        if(hmd->object) {
                bPoseChannel *pchan= get_pose_channel(hmd->object->pose, hmd->subtarget);
                
@@ -646,12 +662,14 @@ void OBJECT_OT_hook_reset(wmOperatorType *ot)
 {
        PropertyRNA *prop;
        
+       /* identifiers */
        ot->name= "Reset Hook";
        ot->description= "Recalculate and and clear offset transformation.";
        ot->idname= "OBJECT_OT_hook_reset";
        
-       ot->poll= ED_operator_editmesh;
+       /* callbacks */
        ot->exec= object_hook_reset_exec;
+       ot->poll= hook_op_edit_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -673,7 +691,8 @@ static int object_hook_recenter_exec(bContext *C, wmOperator *op)
        if (ptr.data) {         /* if modifier context is available, use that */
                ob = ptr.id.data;
                hmd= ptr.data;
-       } else {                        /* use the provided property */
+       } 
+       else {                  /* use the provided property */
                ob = CTX_data_edit_object(C);
                hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num);
        }
@@ -683,7 +702,6 @@ static int object_hook_recenter_exec(bContext *C, wmOperator *op)
        }
        
        /* recenter functionality */
-       
        copy_m3_m4(bmat, ob->obmat);
        invert_m3_m3(imat, bmat);
        
@@ -700,12 +718,14 @@ void OBJECT_OT_hook_recenter(wmOperatorType *ot)
 {
        PropertyRNA *prop;
        
+       /* identifiers */
        ot->name= "Recenter Hook";
        ot->description= "Set hook center to cursor position.";
        ot->idname= "OBJECT_OT_hook_recenter";
        
-       ot->poll= ED_operator_editmesh;
+       /* callbacks */
        ot->exec= object_hook_recenter_exec;
+       ot->poll= hook_op_edit_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -728,7 +748,8 @@ static int object_hook_assign_exec(bContext *C, wmOperator *op)
        if (ptr.data) {         /* if modifier context is available, use that */
                ob = ptr.id.data;
                hmd= ptr.data;
-       } else {                        /* use the provided property */
+       } 
+       else {                  /* use the provided property */
                ob = CTX_data_edit_object(C);
                hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num);
        }
@@ -760,12 +781,14 @@ void OBJECT_OT_hook_assign(wmOperatorType *ot)
 {
        PropertyRNA *prop;
        
+       /* identifiers */
        ot->name= "Assign to Hook";
        ot->description= "Assign the selected vertices to a hook.";
        ot->idname= "OBJECT_OT_hook_assign";
        
-       ot->poll= ED_operator_editmesh;
+       /* callbacks */
        ot->exec= object_hook_assign_exec;
+       ot->poll= hook_op_edit_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -785,7 +808,8 @@ static int object_hook_select_exec(bContext *C, wmOperator *op)
        if (ptr.data) {         /* if modifier context is available, use that */
                ob = ptr.id.data;
                hmd= ptr.data;
-       } else {                        /* use the provided property */
+       } 
+       else {                  /* use the provided property */
                ob = CTX_data_edit_object(C);
                hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num);
        }
@@ -795,7 +819,6 @@ static int object_hook_select_exec(bContext *C, wmOperator *op)
        }
        
        /* select functionality */
-       
        object_hook_select(ob, hmd);
        
        WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data);
@@ -807,12 +830,14 @@ void OBJECT_OT_hook_select(wmOperatorType *ot)
 {
        PropertyRNA *prop;
        
+       /* identifiers */
        ot->name= "Select Hook";
        ot->description= "Selects effected vertices on mesh.";
        ot->idname= "OBJECT_OT_hook_select";
        
-       ot->poll= ED_operator_editmesh;
+       /* callbacks */
        ot->exec= object_hook_select_exec;
+       ot->poll= hook_op_edit_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
index 44dc5b06ea8e6f64d8dd4c700d926907c8f51bbf..fd66b564d537832d7881759b6d160f0e47d980ae 100644 (file)
@@ -227,6 +227,7 @@ void ED_keymap_object(wmKeyConfig *keyconf)
        wmKeyMap *keymap;
        wmKeyMapItem *kmi;
        
+       /* Objects, Regardless of Mode -------------------------------------------------- */
        keymap= WM_keymap_find(keyconf, "Object Non-modal", 0, 0);
        
        /* Note: this keymap works disregarding mode */
@@ -251,6 +252,7 @@ void ED_keymap_object(wmKeyConfig *keyconf)
        
        WM_keymap_add_item(keymap, "OBJECT_OT_center_set", CKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_CTRL, 0);
 
+       /* Object Mode ---------------------------------------------------------------- */
        /* Note: this keymap gets disabled in non-objectmode,  */
        keymap= WM_keymap_find(keyconf, "Object Mode", 0, 0);
        keymap->poll= object_mode_poll;
@@ -311,11 +313,14 @@ void ED_keymap_object(wmKeyConfig *keyconf)
        WM_keymap_verify_item(keymap, "GROUP_OT_objects_add_active", GKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
        WM_keymap_verify_item(keymap, "GROUP_OT_objects_remove_active", GKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
 
-       /* Lattice */
+       /* Lattice -------------------------------------------------------------------- */
        keymap= WM_keymap_find(keyconf, "Lattice", 0, 0);
        keymap->poll= ED_operator_editlattice;
 
        WM_keymap_add_item(keymap, "LATTICE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
+       
+               /* menus */
+       WM_keymap_add_menu(keymap, "VIEW3D_MT_hook", HKEY, KM_PRESS, KM_CTRL, 0);
 
        ED_object_generic_keymap(keyconf, keymap, TRUE);
 }