[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49268] branches/soc-2012-bratwurst: Add the ability to query the last redoable operator from in python.

Jorge Rodriguez bs.vino at gmail.com
Fri Jul 27 00:26:52 CEST 2012


Revision: 49268
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49268
Author:   vino
Date:     2012-07-26 22:26:50 +0000 (Thu, 26 Jul 2012)
Log Message:
-----------
Add the ability to query the last redoable operator from in python. Add the ability to mark certain operator properties as "Primary" meaning that they're the most important ones, and the ones that should be shown if the operator's representation must be shortened. Built an example/prototype floating control which shows the last operator and, if clicked, opens the f6 window for that operator. It has a few problems though, such as that it can't seem to access all operator properties and I can't figure out how to get it to render white.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py
    branches/soc-2012-bratwurst/source/blender/editors/mesh/editmesh_tools.c
    branches/soc-2012-bratwurst/source/blender/editors/transform/transform_ops.c
    branches/soc-2012-bratwurst/source/blender/makesrna/RNA_types.h
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_rna.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_wm_api.c
    branches/soc-2012-bratwurst/source/blender/python/intern/bpy_props.c
    branches/soc-2012-bratwurst/source/blender/python/intern/bpy_rna.c
    branches/soc-2012-bratwurst/source/blender/windowmanager/WM_api.h
    branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_operators.c

Modified: branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py
===================================================================
--- branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py	2012-07-26 22:15:24 UTC (rev 49267)
+++ branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py	2012-07-26 22:26:50 UTC (rev 49268)
@@ -2700,16 +2700,52 @@
     bl_label = "Floating Controls"
     bl_options = {'HIDE_HEADER'}
 
+    def make_lastop(self, context, layout):
+        wm = context.window_manager
+
+        last_operator = wm.last_redo()
+        if last_operator != None:
+            lastop = layout.row()
+            lastop.alignment = 'RIGHT'
+                
+            lastop_name = last_operator.name
+            for id, p in last_operator.properties.items():
+                if last_operator.properties.is_property_primary(id):
+                    if str(p.__class__) == "<class 'IDPropertyArray'>":
+                        lastop_name = lastop_name + " ("
+                        for v in p:
+                            if type(v) is float:
+                                string_formatted = "%(pretty_number).3f" % { "pretty_number": v }
+                            else:
+                                string_formatted = str(v)
+                            lastop_name = lastop_name + string_formatted + " "
+                        lastop_name = lastop_name[:-1] # cut off the last space
+                        lastop_name = lastop_name + ")"
+                    else:
+                        lastop_name = lastop_name + " (" + str(p) + ")"
+
+            lastop.operator("screen.redo_last", text=lastop_name, emboss=False)
+
     def draw(self, context):
         view = context.space_data
         tools = context.tool_settings
+        wm = context.window_manager
 
         if bpy.context.user_preferences.view.floating_controls == 'BOTTOM' or bpy.context.user_preferences.view.floating_controls == 'TOP':
             layout = self.layout
+
+            row = None
+
             if bpy.context.user_preferences.view.floating_controls == 'BOTTOM':
-	            layout.alignment = 'BOTTOM'
+                layout.alignment = 'BOTTOM'
+                row = layout.row()  # Create this first so it floats on the bottom
 
-            row = layout.row(align=True)
+            self.make_lastop(context, layout)
+
+            if bpy.context.user_preferences.view.floating_controls == 'TOP':
+                row = layout.row()
+
+            row = row.row(align=True)
             row.alignment = 'CENTER'
             row.scale_x = 1.5
             row.scale_y = 1.5
@@ -2743,6 +2779,8 @@
         elif bpy.context.user_preferences.view.floating_controls == 'LEFT' or bpy.context.user_preferences.view.floating_controls == 'RIGHT':
             layout = self.layout
 
+            self.make_lastop(context, layout)
+
             row = layout.row()
             if bpy.context.user_preferences.view.floating_controls == 'RIGHT':
 	            row.alignment = 'RIGHT'

Modified: branches/soc-2012-bratwurst/source/blender/editors/mesh/editmesh_tools.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/mesh/editmesh_tools.c	2012-07-26 22:15:24 UTC (rev 49267)
+++ branches/soc-2012-bratwurst/source/blender/editors/mesh/editmesh_tools.c	2012-07-26 22:26:50 UTC (rev 49268)
@@ -138,7 +138,7 @@
 	/* properties */
 	prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, INT_MAX, "Number of Cuts", "", 1, 10);
 	/* avoid re-using last var because it can cause _very_ high poly meshes and annoy users (or worse crash) */
-	RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+	RNA_def_property_flag(prop, PROP_SKIP_SAVE|PROP_PRIMARY);
 
 	RNA_def_float(ot->srna, "smoothness", 0.0f, 0.0f, FLT_MAX, "Smoothness", "Smoothness factor", 0.0f, 1.0f);
 
@@ -3373,6 +3373,8 @@
 
 void MESH_OT_spin(wmOperatorType *ot)
 {
+	PropertyRNA* prop;
+
 	/* identifiers */
 	ot->name = "Spin";
 	ot->description = "Extrude selected vertices in a circle around the cursor in indicated viewport";
@@ -3387,10 +3389,14 @@
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
 	/* props */
-	RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, INT_MAX);
+	prop = RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, INT_MAX);
+	RNA_def_property_flag(prop, PROP_PRIMARY);
+
 	RNA_def_boolean(ot->srna, "dupli", 0, "Dupli", "Make Duplicates");
-	RNA_def_float(ot->srna, "degrees", 90.0f, -FLT_MAX, FLT_MAX, "Degrees", "Degrees", -360.0f, 360.0f);
 
+	prop = RNA_def_float(ot->srna, "degrees", 90.0f, -FLT_MAX, FLT_MAX, "Degrees", "Degrees", -360.0f, 360.0f);
+	RNA_def_property_flag(prop, PROP_PRIMARY);
+
 	RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX);
 	RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX);
 
@@ -3497,6 +3503,8 @@
 
 void MESH_OT_screw(wmOperatorType *ot)
 {
+	PropertyRNA* prop;
+
 	/* identifiers */
 	ot->name = "Screw";
 	ot->description = "Extrude selected vertices in screw-shaped rotation around the cursor in indicated viewport";
@@ -3511,9 +3519,12 @@
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
 	/* props */
-	RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, 256);
-	RNA_def_int(ot->srna, "turns", 1, 0, INT_MAX, "Turns", "Turns", 0, 256);
+	prop = RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, 256);
+	RNA_def_property_flag(prop, PROP_PRIMARY);
 
+	prop = RNA_def_int(ot->srna, "turns", 1, 0, INT_MAX, "Turns", "Turns", 0, 256);
+	RNA_def_property_flag(prop, PROP_PRIMARY);
+
 	RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX,
 	                     "Center", "Center in global view space", -FLT_MAX, FLT_MAX);
 	RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f,

Modified: branches/soc-2012-bratwurst/source/blender/editors/transform/transform_ops.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform_ops.c	2012-07-26 22:15:24 UTC (rev 49267)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform_ops.c	2012-07-26 22:26:50 UTC (rev 49268)
@@ -513,6 +513,8 @@
 
 static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
 {
+	PropertyRNA *prop;
+
 	/* identifiers */
 	ot->name   = "Translate";
 	ot->description = "Translate (move) selected items";
@@ -526,13 +528,16 @@
 	ot->cancel = transform_cancel;
 	ot->poll   = ED_operator_screenactive;
 
-	RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
+	prop = RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
+	RNA_def_property_flag(prop, PROP_PRIMARY);
 
 	Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS);
 }
 
 static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
 {
+	PropertyRNA *prop;
+
 	/* identifiers */
 	ot->name   = "Resize";
 	ot->description = "Scale (resize) selected items"; 
@@ -546,7 +551,8 @@
 	ot->cancel = transform_cancel;
 	ot->poll   = ED_operator_screenactive;
 
-	RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
+	prop = RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
+	RNA_def_property_flag(prop, PROP_PRIMARY);
 
 	Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS);
 }
@@ -603,6 +609,8 @@
 
 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
 {
+	PropertyRNA *prop;
+
 	/* identifiers */
 	ot->name   = "Rotate";
 	ot->description = "Rotate selected items";
@@ -616,7 +624,8 @@
 	ot->cancel = transform_cancel;
 	ot->poll   = ED_operator_screenactive;
 
-	RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
+	prop = RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
+	RNA_def_property_flag(prop, PROP_PRIMARY);
 
 	Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP);
 }
@@ -688,6 +697,8 @@
 
 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
 {
+	PropertyRNA *prop;
+
 	/* identifiers */
 	ot->name   = "Push/Pull";
 	ot->description = "Push/Pull selected items";
@@ -701,13 +712,16 @@
 	ot->cancel = transform_cancel;
 	ot->poll   = ED_operator_screenactive;
 
-	RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
+	prop = RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
+	RNA_def_property_flag(prop, PROP_PRIMARY);
 
 	Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
 }
 
 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
 {
+	PropertyRNA *prop;
+
 	/* identifiers */
 	ot->name   = "Shrink/Fatten";
 	ot->description = "Shrink/fatten selected vertices along normals";
@@ -721,7 +735,8 @@
 	ot->cancel = transform_cancel;
 	ot->poll   = ED_operator_editmesh;
 
-	RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
+	prop = RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
+	RNA_def_property_flag(prop, PROP_PRIMARY);
 
 	Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
 }
@@ -767,6 +782,8 @@
 
 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
 {
+	PropertyRNA *prop;
+
 	/* identifiers */
 	ot->name   = "Edge Slide";
 	ot->description = "Slide an edge loop along a mesh"; 
@@ -780,7 +797,8 @@
 	ot->cancel = transform_cancel;
 	ot->poll   = ED_operator_editmesh;
 
-	RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
+	prop = RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
+	RNA_def_property_flag(prop, PROP_PRIMARY);
 
 	Transform_Properties(ot, P_MIRROR | P_SNAP);
 }

Modified: branches/soc-2012-bratwurst/source/blender/makesrna/RNA_types.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/makesrna/RNA_types.h	2012-07-26 22:15:24 UTC (rev 49267)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list