fix [#27778] Set Bone Flags - No Scale - Toggle seems not to work.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 27 Jun 2011 07:51:52 +0000 (07:51 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 27 Jun 2011 07:51:52 +0000 (07:51 +0000)
Toggling options on the selection is better done as a generic operator.
Replace ARMATURE_OT_flags_set and POSE_OT_flags_set with WM_OT_context_collection_boolean_set and use menus to access it with specific settings.

This way its easy make a key shortcut which toggles any boolean on any collection - sequences, metaballs, objects, bones etc.

release/scripts/startup/bl_operators/wm.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/editors/armature/armature_intern.h
source/blender/editors/armature/armature_ops.c
source/blender/editors/armature/editarmature.c

index 629a48d5750f2929543e4f188597baa09f9aa211..af33e45668c19933b84a5e1f0a50cc2172f44314 100644 (file)
@@ -19,7 +19,9 @@
 # <pep8 compliant>
 
 import bpy
-from bpy.props import StringProperty, BoolProperty, IntProperty, FloatProperty
+from bpy.props import StringProperty, BoolProperty, IntProperty, \
+                      FloatProperty, EnumProperty
+
 from rna_prop_ui import rna_idprop_ui_prop_get, rna_idprop_ui_prop_clear
 
 
@@ -457,6 +459,66 @@ doc_id = StringProperty(name="Doc ID",
 doc_new = StringProperty(name="Edit Description",
         description="", maxlen=1024, default="")
 
+data_path_iter = StringProperty(
+        description="The data path relative to the context, must point to an iterable.")
+
+data_path_item = StringProperty(
+        description="The data path from each iterable to the value (int or float)")
+
+
+class WM_OT_context_collection_boolean_set(bpy.types.Operator):
+    '''Set boolean values for a collection of items'''
+    bl_idname = "wm.context_collection_boolean_set"
+    bl_label = "Context Collection Boolean Set"
+    bl_options = {'UNDO', 'REGISTER', 'INTERNAL'}
+
+    data_path_iter = data_path_iter
+    data_path_item = data_path_item
+
+    type = EnumProperty(items=(
+            ('TOGGLE', "Toggle", ""),
+            ('ENABLE', "Enable", ""),
+            ('DISABLE', "Disable", ""),
+            ),
+        name="Type")
+
+    def execute(self, context):
+        data_path_iter = self.data_path_iter
+        data_path_item = self.data_path_item
+
+        items = list(getattr(context, data_path_iter))
+        items_ok = []
+        is_set = False
+        for item in items:
+            try:
+                value_orig = eval("item." + data_path_item)
+            except:
+                continue
+
+            if value_orig == True:
+                is_set = True
+            elif value_orig == False:
+                pass
+            else:
+                self.report({'WARNING'}, "Non boolean value found: %s[ ].%s" %
+                            (data_path_iter, data_path_item))
+                return {'CANCELLED'}
+
+            items_ok.append(item)
+
+        if self.type == 'ENABLE':
+            is_set = True
+        elif self.type == 'DISABLE':
+            is_set = False
+        else:
+            is_set = not is_set
+
+        exec_str = "item.%s = %s" % (data_path_item, is_set)
+        for item in items_ok:
+            exec(exec_str)
+
+        return {'FINISHED'}
+
 
 class WM_OT_context_modal_mouse(bpy.types.Operator):
     '''Adjust arbitrary values with mouse input'''
@@ -464,8 +526,9 @@ class WM_OT_context_modal_mouse(bpy.types.Operator):
     bl_label = "Context Modal Mouse"
     bl_options = {'GRAB_POINTER', 'BLOCKING', 'INTERNAL'}
 
-    data_path_iter = StringProperty(description="The data path relative to the context, must point to an iterable.")
-    data_path_item = StringProperty(description="The data path from each iterable to the value (int or float)")
+    data_path_iter = data_path_iter
+    data_path_item = data_path_item
+
     input_scale = FloatProperty(default=0.01, description="Scale the mouse movement by this value before applying the delta")
     invert = BoolProperty(default=False, description="Invert the mouse input")
     initial_x = IntProperty(options={'HIDDEN'})
index b989085939f29c68c641ad2b4dddbe8a84d07aec..188b011c1ab6e91abb1a98e3b3c80cba7b2898ce 100644 (file)
@@ -1252,7 +1252,7 @@ class VIEW3D_MT_pose(bpy.types.Menu):
         layout.separator()
 
         layout.menu("VIEW3D_MT_pose_showhide")
-        layout.operator_menu_enum("pose.flags_set", 'mode', text="Bone Settings")
+        layout.menu("VIEW3D_MT_bone_options_toggle", text="Bone Settings")
 
 
 class VIEW3D_MT_pose_transform(bpy.types.Menu):
@@ -1373,6 +1373,50 @@ class VIEW3D_MT_pose_apply(bpy.types.Menu):
         layout.operator("pose.visual_transform_apply")
 
 
+class BoneOptions:
+    def draw(self, context):
+        layout = self.layout
+        bone_props = bpy.types.Bone.bl_rna.properties
+
+        options = [
+            "show_wire",
+            "use_deform",
+            "use_envelope_multiply",
+            "use_inherit_rotation",
+            "use_inherit_scale",
+        ]
+
+        if context.mode == 'POSE':
+            data_path_iter = "selected_pose_bones"
+            opt_suffix = "bone."
+        else:
+            data_path_iter = "selected_bones"
+            opt_suffix = ""
+
+            if context.mode == 'EDIT_ARMATURE':
+                options.append("lock")
+
+        for opt in options:
+            props = layout.operator("wm.context_collection_boolean_set", text=bone_props[opt].name)
+            props.data_path_iter = data_path_iter
+            props.data_path_item = opt_suffix + opt
+            props.type = self.type
+
+
+class VIEW3D_MT_bone_options_toggle(bpy.types.Menu, BoneOptions):
+    bl_label = "Toggle Options"
+    type = 'TOGGLE'
+
+
+class VIEW3D_MT_bone_options_enable(bpy.types.Menu, BoneOptions):
+    bl_label = "Enable Options"
+    type = 'ENABLE'
+
+
+class VIEW3D_MT_bone_options_disable(bpy.types.Menu, BoneOptions):
+    bl_label = "Disable Options"
+    type = 'DISABLE'
+
 # ********** Edit Menus, suffix from ob.type **********
 
 
@@ -1966,7 +2010,7 @@ class VIEW3D_MT_edit_armature(bpy.types.Menu):
 
         layout.separator()
 
-        layout.operator_menu_enum("armature.flags_set", "mode", text="Bone Settings")
+        layout.menu("VIEW3D_MT_bone_options_toggle", text="Bone Settings")
 
 
 class VIEW3D_MT_armature_specials(bpy.types.Menu):
index 82decf8d1cffc05e934e8d7b27f8b0467aa5257b..85da7a212c929bf7213d46f23acaef85ffca5f95 100644 (file)
@@ -79,8 +79,6 @@ void ARMATURE_OT_separate(struct wmOperatorType *ot);
 void ARMATURE_OT_autoside_names(struct wmOperatorType *ot);
 void ARMATURE_OT_flip_names(struct wmOperatorType *ot);
 
-void ARMATURE_OT_flags_set(struct wmOperatorType *ot);
-
 void ARMATURE_OT_layers_show_all(struct wmOperatorType *ot);
 void ARMATURE_OT_armature_layers(struct wmOperatorType *ot);
 void ARMATURE_OT_bone_layers(struct wmOperatorType *ot);
@@ -125,8 +123,6 @@ void POSE_OT_flip_names(struct wmOperatorType *ot);
 
 void POSE_OT_quaternions_flip(struct wmOperatorType *ot);
 
-void POSE_OT_flags_set(struct wmOperatorType *ot);
-
 void POSE_OT_armature_layers(struct wmOperatorType *ot);
 void POSE_OT_bone_layers(struct wmOperatorType *ot);
 
index 545cff824833123b7d539cbdc8439afbc8fa76d5..7bc9bb48a4c63f8a516eb6f4aa61be6cb019c9c0 100644 (file)
@@ -85,8 +85,6 @@ void ED_operatortypes_armature(void)
        WM_operatortype_append(ARMATURE_OT_autoside_names);
        WM_operatortype_append(ARMATURE_OT_flip_names);
        
-       WM_operatortype_append(ARMATURE_OT_flags_set);
-       
        WM_operatortype_append(ARMATURE_OT_layers_show_all);
        WM_operatortype_append(ARMATURE_OT_armature_layers);
        WM_operatortype_append(ARMATURE_OT_bone_layers);
@@ -141,8 +139,6 @@ void ED_operatortypes_armature(void)
 
        WM_operatortype_append(POSE_OT_quaternions_flip);
        
-       WM_operatortype_append(POSE_OT_flags_set);
-       
        WM_operatortype_append(POSE_OT_armature_layers);
        WM_operatortype_append(POSE_OT_bone_layers);
        
@@ -268,12 +264,9 @@ void ED_keymap_armature(wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "ARMATURE_OT_separate", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
        
                /* set flags */
-       kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_flags_set", WKEY, KM_PRESS, KM_SHIFT, 0);
-               RNA_enum_set(kmi->ptr, "mode", 2); // toggle
-       kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_flags_set", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
-               RNA_enum_set(kmi->ptr, "mode", 1); // enable
-       kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_flags_set", WKEY, KM_PRESS, KM_ALT, 0);
-               RNA_enum_set(kmi->ptr, "mode", 0); // clear
+       WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_toggle", WKEY, KM_PRESS, KM_SHIFT, 0);
+       WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_enable", WKEY, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_disable", WKEY, KM_PRESS, KM_ALT, 0);
                
                /* armature/bone layers */
        WM_keymap_add_item(keymap, "ARMATURE_OT_layers_show_all", ACCENTGRAVEKEY, KM_PRESS, KM_CTRL, 0);
@@ -349,13 +342,10 @@ void ED_keymap_armature(wmKeyConfig *keyconf)
        WM_keymap_add_menu(keymap, "VIEW3D_MT_pose_group", GKEY, KM_PRESS, KM_CTRL, 0);
        
                /* set flags */
-       kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_SHIFT, 0);
-               RNA_enum_set(kmi->ptr, "mode", 2); // toggle
-       kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
-               RNA_enum_set(kmi->ptr, "mode", 1); // enable
-       kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_ALT, 0);
-               RNA_enum_set(kmi->ptr, "mode", 0); // clear
-               
+       WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_toggle", WKEY, KM_PRESS, KM_SHIFT, 0);
+       WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_enable", WKEY, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_disable", WKEY, KM_PRESS, KM_ALT, 0);
+
                /* armature/bone layers */
        WM_keymap_add_item(keymap, "ARMATURE_OT_layers_show_all", ACCENTGRAVEKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "POSE_OT_armature_layers", MKEY, KM_PRESS, KM_SHIFT, 0);
index abf0839354403c2fad229e291beb635e8de5c5a2..2035220612197b9fd1e09819046788775d785fa1 100644 (file)
@@ -1352,30 +1352,6 @@ static void *get_nearest_bone (bContext *C, short findunsel, int x, int y)
        return NULL;
 }
 
-/* helper for setflag_sel_bone() */
-static void bone_setflag (int *bone, int flag, short mode)
-{
-       if (bone && flag) {
-               /* exception for inverse flags */
-               if (flag == BONE_NO_DEFORM) {
-                       if (mode == 2)
-                               *bone |= flag;
-                       else if (mode == 1)
-                               *bone &= ~flag;
-                       else
-                               *bone ^= flag;
-               }
-               else {
-                       if (mode == 2)
-                               *bone &= ~flag;
-                       else if (mode == 1)
-                               *bone |= flag;
-                       else
-                               *bone ^= flag;
-               }
-       }
-}
-
 /* Get the first available child of an editbone */
 static EditBone *editbone_get_child(bArmature *arm, EditBone *pabone, short use_visibility)
 {
@@ -1396,105 +1372,6 @@ static EditBone *editbone_get_child(bArmature *arm, EditBone *pabone, short use_
        return chbone;
 }
 
-/* callback for posemode setflag */
-static int pose_setflag_exec (bContext *C, wmOperator *op)
-{
-       int flag= RNA_enum_get(op->ptr, "type");
-       int mode= RNA_enum_get(op->ptr, "mode");
-       
-       /* loop over all selected pchans */
-       CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pose_bones) 
-       {
-               bone_setflag(&pchan->bone->flag, flag, mode);
-       }
-       CTX_DATA_END;
-       
-       /* note, notifier might evolve */
-       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ED_object_pose_armature(CTX_data_active_object(C)));
-       
-       return OPERATOR_FINISHED;
-}
-
-/* callback for editbones setflag */
-static int armature_bones_setflag_exec (bContext *C, wmOperator *op)
-{
-       int flag= RNA_enum_get(op->ptr, "type");
-       int mode= RNA_enum_get(op->ptr, "mode");
-       
-       /* loop over all selected pchans */
-       CTX_DATA_BEGIN(C, EditBone *, ebone, selected_bones) 
-       {
-               bone_setflag(&ebone->flag, flag, mode);
-       }
-       CTX_DATA_END;
-       
-       /* note, notifier might evolve */
-       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, CTX_data_edit_object(C));
-       
-       return OPERATOR_FINISHED;
-}
-
-/* settings that can be changed */
-static EnumPropertyItem prop_bone_setting_types[] = {
-       {BONE_DRAWWIRE, "DRAWWIRE", 0, "Draw Wire", ""},
-       {BONE_NO_DEFORM, "DEFORM", 0, "Deform", ""},
-       {BONE_MULT_VG_ENV, "MULT_VG", 0, "Multiply Vertex Groups", ""},
-       {BONE_HINGE, "HINGE", 0, "Hinge", ""},
-       {BONE_NO_SCALE, "NO_SCALE", 0, "No Scale", ""},
-       {BONE_EDITMODE_LOCKED, "LOCKED", 0, "Locked", "(For EditMode only)"},
-       {0, NULL, 0, NULL, NULL}
-};
-
-/* ways that settings can be changed */
-static EnumPropertyItem prop_bone_setting_modes[] = {
-       {0, "CLEAR", 0, "Clear", ""},
-       {1, "ENABLE", 0, "Enable", ""},
-       {2, "TOGGLE", 0, "Toggle", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-
-void ARMATURE_OT_flags_set (wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Set Bone Flags";
-       ot->idname= "ARMATURE_OT_flags_set";
-       ot->description= "Set flags for armature bones";
-       
-       /* callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= armature_bones_setflag_exec;
-       ot->poll= ED_operator_editarmature;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       /* properties */
-       ot->prop= RNA_def_enum(ot->srna, "type", prop_bone_setting_types, 0, "Type", "");
-       RNA_def_enum(ot->srna, "mode", prop_bone_setting_modes, 0, "Mode", "");
-}
-
-void POSE_OT_flags_set (wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Set Bone Flags";
-       ot->idname= "POSE_OT_flags_set";
-       ot->description= "Set flags for armature bones";
-       
-       /* callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= pose_setflag_exec;
-       ot->poll= ED_operator_posemode;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       /* properties */
-       ot->prop= RNA_def_enum(ot->srna, "type", prop_bone_setting_types, 0, "Type", "");
-       RNA_def_enum(ot->srna, "mode", prop_bone_setting_modes, 0, "Mode", "");
-}
-
-
 /* **************** END PoseMode & EditMode *************************** */
 /* **************** Posemode stuff ********************** */