Context operators for adjusting context values directly to avoid adding operators...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 13 Oct 2009 15:30:19 +0000 (15:30 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 13 Oct 2009 15:30:19 +0000 (15:30 +0000)
wm.context_set(path="scene.tool_settings.someattr", somevalue)
wm.context_toggle(path="scene.tool_settings.somebool")
wm.context_toggle_values(path="scene.tool_settings.some_enum", value_1="somevalue", value_2="othervalue") # switch between 2 values
wm.context_cycle_enum(path="scene.tool_settings.some_enum", reverse=False)

the path value is taken from the context so the full path is
context.scene.tool_settings...

This means in keymaps you can cycle draw modes, change PET- anything with rna access.
If its not so nice to map keys to operators like wm.context_set we could use macro's to wrap it and have its own name

Use this for PET and setting pivot options

- Made userpref key shortcut Ctrl+Alt+U since its not used in 2.4x
- added pivot_point_align (Alt+Comma)
- added PET wasnt rna wrapped correctly.

13 files changed:
release/scripts/modules/bpy_ops.py
source/blender/editors/curve/curve_ops.c
source/blender/editors/include/ED_object.h
source/blender/editors/mesh/mesh_ops.c
source/blender/editors/object/object_ops.c
source/blender/editors/physics/particle_edit.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_view3d/view3d_ops.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/uvedit/uvedit_ops.c
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_space.c

index 834a33d305d14c80cae395b6763c8b1bc1796fa3..b1d782917b643454c3f4c7b074881a665e93e3ce 100644 (file)
@@ -145,7 +145,7 @@ bpy.ops = bpy_ops()
 class MESH_OT_delete_edgeloop(bpy.types.Operator):
        '''Export a single object as a stanford PLY with normals, colours and texture coordinates.'''
        __idname__ = "mesh.delete_edgeloop"
-       __label__ = "Export PLY"
+       __label__ = "Delete Edge Loop"
        
        def execute(self, context):
                bpy.ops.tfm.edge_slide(value=1.0)
@@ -153,6 +153,100 @@ class MESH_OT_delete_edgeloop(bpy.types.Operator):
                bpy.ops.mesh.remove_doubles()
                return ('FINISHED',)
 
+class WM_OT_context_set(bpy.types.Operator):
+       '''Set a context value.'''
+       __idname__ = "wm.context_set"
+       __label__ = "Context Set"
+       __register__ = True
+       __undo__ = True
+       
+       __props__ = [
+               bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= ""),
+               bpy.props.StringProperty(attr="value", name="Value", description="Assignment value (as a string)", maxlen= 1024, default= "")
+       ]
+       
+       def execute(self, context):
+               exec("context.%s=%s" % (self.path, self.value)) # security nuts will complain.
+               return ('FINISHED',)
+
+class WM_OT_context_toggle(bpy.types.Operator):
+       '''Toggle a context value.'''
+       __idname__ = "wm.context_toggle"
+       __label__ = "Context Toggle"
+       __register__ = True
+       __undo__ = True
+       
+       __props__ = [
+               bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= ""),
+       ]
+       
+       def execute(self, context):
+               exec("context.%s=not (context.%s)" % (self.path, self.path)) # security nuts will complain.
+               return ('FINISHED',)
+
+class WM_OT_context_toggle_values(bpy.types.Operator):
+       '''Toggle a context value.'''
+       __idname__ = "wm.context_toggle_values"
+       __label__ = "Context Toggle Values"
+       __register__ = True
+       __undo__ = True
+       
+       __props__ = [
+               bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= ""),
+               bpy.props.StringProperty(attr="value_1", name="Value", description="Toggle value (as a string)", maxlen= 1024, default= ""),
+               bpy.props.StringProperty(attr="value_2", name="Value", description="Toggle value (as a string)", maxlen= 1024, default= "")
+       ]
+       
+       def execute(self, context):
+               exec("context.%s = [%s, %s][context.%s!=%s]" % (self.path, self.value_1, self.value_2, self.path, self.value_2)) # security nuts will complain.
+               return ('FINISHED',)
+
+class WM_OT_context_cycle_enum(bpy.types.Operator):
+       '''Toggle a context value.'''
+       __idname__ = "wm.context_cycle_enum"
+       __label__ = "Context Toggle Values"
+       __register__ = True
+       __undo__ = True
+       
+       __props__ = [
+               bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= ""),
+               bpy.props.BoolProperty(attr="reverse", name="Reverse", description="Cycle backwards", default= False)
+       ]
+       
+       def execute(self, context):
+               orig_value = eval("context.%s" % self.path) # security nuts will complain.
+               
+               # Have to get rna enum values
+               rna_struct_str, rna_prop_str =  self.path.rsplit('.', 1)
+               i = rna_prop_str.find('[')
+               if i != -1: rna_prop_str = rna_prop_str[0:i] # just incse we get "context.foo.bar[0]"
+               
+               rna_struct = eval("context.%s.rna_type" % rna_struct_str)
+               
+               rna_prop = rna_struct.properties[rna_prop_str]
+               
+               if type(rna_prop) != bpy.types.EnumProperty:
+                       raise Exception("expected an enum property")
+               
+               enums = rna_struct.properties[rna_prop_str].items.keys()
+               orig_index = enums.index(orig_value)
+               
+               # Have the info we need, advance to the next item
+               if self.reverse:
+                       if orig_index==0:                       advance_enum = enums[-1]
+                       else:                                   advance_enum = enums[orig_index-1]
+               else:
+                       if orig_index==len(enums)-1:    advance_enum = enums[0]
+                       else:                                   advance_enum = enums[orig_index+1]
+               
+               # set the new value
+               exec("context.%s=advance_enum" % self.path)
+               return ('FINISHED',)
 
 bpy.ops.add(MESH_OT_delete_edgeloop)
 
+bpy.ops.add(WM_OT_context_set)
+bpy.ops.add(WM_OT_context_toggle)
+bpy.ops.add(WM_OT_context_toggle_values)
+bpy.ops.add(WM_OT_context_cycle_enum)
+
index a71ff8347e815bfe1788dc35d1f672ead7d46539..929e35149903bbe87957b2af88e87c1ca0c43da0 100644 (file)
@@ -248,5 +248,7 @@ void ED_keymap_curve(wmKeyConfig *keyconf)
        RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "unselected", 1);
 
        WM_keymap_add_item(keymap, "CURVE_OT_specials_menu", WKEY, KM_PRESS, 0, 0);
+
+       ED_object_generic_keymap(keyconf, keymap, TRUE);
 }
 
index e19fc806404fb7dfbdda5c5addef97c9acde0e30..3d0d776f5497a920d03c75277ea420002f1f6dae 100644 (file)
@@ -47,6 +47,9 @@ void ED_operatortypes_object(void);
 void ED_operatormacros_object(void);
 void ED_keymap_object(struct wmKeyConfig *keyconf);
 
+/* generic editmode keys like pet */
+void ED_object_generic_keymap(struct wmKeyConfig *keyconf, struct wmKeyMap *keymap, int do_pet);
+
        /* send your own notifier for select! */
 void ED_base_object_select(struct Base *base, short mode);
        /* includes notifier */
index 8c24dda4da7faa7c782ccd13ec34e40b867e3b01..3a3e4f5491533bd365f490979042b7cf4642b187 100644 (file)
@@ -291,5 +291,7 @@ void ED_keymap_mesh(wmKeyConfig *keyconf)
 
        /* UV's */
        WM_keymap_add_item(keymap, "UV_OT_mapping_menu", UKEY, KM_PRESS, 0, 0);
+
+       ED_object_generic_keymap(keyconf, keymap, TRUE);
 }
 
index 9869d15a69c56502847aa43cd612ff006b457779..4f9a3d22f3b1a13042fd8954c9ac503e9f2077b9 100644 (file)
@@ -273,3 +273,26 @@ void ED_keymap_object(wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "LATTICE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
 }
 
+void ED_object_generic_keymap(struct wmKeyConfig *keyconf, struct wmKeyMap *keymap, int do_pet)
+{
+       wmKeyMapItem *km;
+
+       /* used by mesh, curve & lattice only */
+       if(do_pet) {
+               /* context ops */
+               km = WM_keymap_add_item(keymap, "WM_OT_context_cycle_enum", OKEY, KM_PRESS, KM_SHIFT, 0);
+               RNA_string_set(km->ptr, "path", "scene.tool_settings.proportional_editing_falloff");
+
+               km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_values", OKEY, KM_PRESS, 0, 0);
+               RNA_string_set(km->ptr, "path", "scene.tool_settings.proportional_editing");
+               RNA_string_set(km->ptr, "value_1", "'DISABLED'");
+               RNA_string_set(km->ptr, "value_2", "'ENABLED'");
+
+               km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_values", OKEY, KM_PRESS, KM_ALT, 0);
+               RNA_string_set(km->ptr, "path", "scene.tool_settings.proportional_editing");
+               RNA_string_set(km->ptr, "value_1", "'DISABLED'");
+               RNA_string_set(km->ptr, "value_2", "'CONNECTED'");
+       }
+
+}
+
index e3f54158fbb6729745c9120d2485af93e6867050..d4a180e242734462b25619272355a6283774dfe7 100644 (file)
@@ -2908,7 +2908,7 @@ static void brush_add(PEData *data, short number)
        ParticleSimulationData sim = {scene, ob, psys, psmd};
        ParticleEditSettings *pset= PE_settings(scene);
        int i, k, n= 0, totpart= psys->totpart;
-       short mco[2];
+       float mco[2];
        short dmx= 0, dmy= 0;
        float co1[3], co2[3], min_d, imat[4][4];
        float framestep, timestep= psys_get_timestep(&sim);
index e160b85e2332098563de57c3689d5b98fa64c1c0..74303e8a6a323f91a8f75081668673b777ee6941 100644 (file)
@@ -3410,10 +3410,7 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "SCREEN_OT_render_view_show", F11KEY, KM_PRESS, 0, 0);
        
        /* user prefs */
-       #ifdef __APPLE__
-       WM_keymap_add_item(keymap, "SCREEN_OT_userpref_show", COMMAKEY, KM_PRESS, KM_OSKEY, 0);
-       #endif
-       WM_keymap_add_item(keymap, "SCREEN_OT_userpref_show", COMMAKEY, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "SCREEN_OT_userpref_show", UKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
        
        
        /* Anim Playback ------------------------------------------------ */
index 74074a041883c4a37efed4773861a8b9bb1e046b..758bf803fb87cae83ca50379b39e7fb663211162 100644 (file)
@@ -221,6 +221,31 @@ void view3d_keymap(wmKeyConfig *keyconf)
        
        WM_keymap_add_item(keymap, "VIEW3D_OT_snap_menu", SKEY, KM_PRESS, KM_SHIFT, 0);
 
+       /* context ops */
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set", COMMAKEY, KM_PRESS, 0, 0);
+       RNA_string_set(km->ptr, "path", "space_data.pivot_point");
+       RNA_string_set(km->ptr, "value", "'BOUNDING_BOX_CENTER'");
+
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set", COMMAKEY, KM_PRESS, KM_CTRL, 0); /* 2.4x allowed Comma+Shift too, rather not use both */
+       RNA_string_set(km->ptr, "path", "space_data.pivot_point");
+       RNA_string_set(km->ptr, "value", "'MEDIAN_POINT'");
+
+       km = WM_keymap_add_item(keymap, "WM_OT_context_toggle", COMMAKEY, KM_PRESS, KM_ALT, 0); /* new in 2.5 */
+       RNA_string_set(km->ptr, "path", "space_data.pivot_point_align");
+
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set", PERIODKEY, KM_PRESS, 0, 0);
+       RNA_string_set(km->ptr, "path", "space_data.pivot_point");
+       RNA_string_set(km->ptr, "value", "'CURSOR'");
+
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set", PERIODKEY, KM_PRESS, KM_CTRL, 0);
+       RNA_string_set(km->ptr, "path", "space_data.pivot_point");
+       RNA_string_set(km->ptr, "value", "'INDIVIDUAL_CENTERS'");
+
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set", PERIODKEY, KM_PRESS, KM_ALT, 0);
+       RNA_string_set(km->ptr, "path", "space_data.pivot_point");
+       RNA_string_set(km->ptr, "value", "'ACTIVE_ELEMENT'");
+
+
        transform_keymap_for_space(keyconf, keymap, SPACE_VIEW3D);
 
        fly_modal_keymap(keyconf);
index c8066f03abfca91584198b2b8cd171a84651c0b7..5fe9db3915f66f54c9b0aa7464fe4cb1f900a135 100644 (file)
@@ -995,10 +995,10 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
                }
                else
                {
-                       if ((t->options & CTX_NO_PET) == 0 && (ts->proportional)) {
+                       if ((t->options & CTX_NO_PET) == 0 && (ts->proportional != PROP_EDIT_OFF)) {
                                t->flag |= T_PROP_EDIT;
                                
-                               if(ts->proportional == 2)
+                               if(ts->proportional == PROP_EDIT_CONNECTED)
                                        t->flag |= T_PROP_CONNECTED;    // yes i know, has to become define
                        }
                }
index 0f79420d3a7d2d70691c83ae845ed3f42e29a593..9b3cb581c884de8038088b1959d3b013c8f9970b 100644 (file)
@@ -3129,6 +3129,8 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "UV_OT_cursor_set", ACTIONMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "UV_OT_tile_set", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
 
+       ED_object_generic_keymap(keyconf, keymap, TRUE);
+
        transform_keymap_for_space(keyconf, keymap, SPACE_IMAGE);
 }
 
index e069136d46a81721fcaa708aafc89c32083f93bb..d2e88408f6b93a056111fce2c06449d069553c64 100644 (file)
@@ -1016,6 +1016,11 @@ typedef struct Scene {
 #define PROP_CONST             5
 #define PROP_RANDOM            6
 
+/* toolsettings->proportional */
+#define PROP_EDIT_OFF                  0
+#define PROP_EDIT_ON                   1
+#define PROP_EDIT_CONNECTED    2
+
 /* sce->flag */
 #define SCE_DS_SELECTED                        (1<<0)
 #define SCE_DS_COLLAPSED               (1<<1)
index 29fb9e4deb2cce15e25de495ee2812e0672236de..7831f6acd11f812324073b4e955986bfe0a2abcf 100644 (file)
@@ -502,6 +502,12 @@ static void rna_def_tool_settings(BlenderRNA  *brna)
                {AUTOKEY_MODE_EDITKEYS, "REPLACE_KEYS", 0, "Replace", ""},
                {0, NULL, 0, NULL, NULL}};
 
+       static EnumPropertyItem proportional_editing_items[] = {
+               {PROP_EDIT_OFF, "DISABLED", 0, "Disable", ""},
+               {PROP_EDIT_ON, "ENABLED", 0, "Enable", ""},
+               {PROP_EDIT_CONNECTED, "CONNECTED", 0, "Connected", ""},
+               {0, NULL, 0, NULL, NULL}};
+
        srna= RNA_def_struct(brna, "ToolSettings", NULL);
        RNA_def_struct_ui_text(srna, "Tool Settings", "");
        
@@ -526,14 +532,17 @@ static void rna_def_tool_settings(BlenderRNA  *brna)
        RNA_def_property_ui_text(prop, "Particle Edit", "");
 
        /* Transform */
-       prop= RNA_def_property(srna, "proportional_editing", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "proportional", 0);
+       prop= RNA_def_property(srna, "proportional_editing", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "proportional");
+       RNA_def_property_enum_items(prop, proportional_editing_items);
        RNA_def_property_ui_text(prop, "Proportional Editing", "Proportional editing mode.");
+       RNA_def_property_update(prop, NC_SCENE|ND_MODE, NULL); /* header redraw */
 
        prop= RNA_def_property(srna, "proportional_editing_falloff", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "prop_mode");
        RNA_def_property_enum_items(prop, prop_mode_items);
        RNA_def_property_ui_text(prop, "Proportional Editing Falloff", "Falloff type for proportional editing mode.");
+       RNA_def_property_update(prop, NC_SCENE|ND_MODE, NULL); /* header redraw */
 
        prop= RNA_def_property(srna, "normal_size", PROP_FLOAT, PROP_DISTANCE);
        RNA_def_property_float_sdna(prop, NULL, "normalsize");
index 99ee3e653f0475cd94dc1bfc4bfb6fade6fdba23..7d77660db6d323d2c1e5cffdae35732de256eae8 100644 (file)
@@ -766,6 +766,11 @@ static void rna_def_space_3dview(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Pivot Point", "Pivot center for rotation/scaling.");
        RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL);
        
+       prop= RNA_def_property(srna, "pivot_point_align", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_ALIGN);
+       RNA_def_property_ui_text(prop, "Align", "Manipulate object centers only.");
+       RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL);
+
        prop= RNA_def_property(srna, "manipulator", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "twflag", V3D_USE_MANIPULATOR);
        RNA_def_property_ui_text(prop, "Manipulator", "Use a 3D manipulator widget for controlling transforms.");