[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51082] trunk/blender: Clean up in " add object" code:

Bastien Montagne montagne29 at wanadoo.fr
Fri Oct 5 14:59:09 CEST 2012


Revision: 51082
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51082
Author:   mont29
Date:     2012-10-05 12:59:09 +0000 (Fri, 05 Oct 2012)
Log Message:
-----------
Clean up in "add object" code:
* Get rid of ED_object_add_generic_invoke() and all invoke callbacks using it, it was doing nothing exec() callbacks would not do. In fact, its only action (setting part of common add ops properties, like loc, layers, etc.) was needed too by direct exec call, so it was done twice in case of using invoke()!
* Replace custom invoke code for metaballs by WM_menu_invoke helper (as already used by lamps).
* Add a new OBJECT_OT_empty_add op, to allow direct addition of empties of a given drawtype.
* And some general code cleanup (like trailing spaces, empty lines, ...).

Did quite a bunch of tests/verifications, but obviously could not tackle all possible scenarios... Anyway, if any, bugs should arize quite quickly (but I don?\226?\128?\153t expect any! :p ).

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_info.py
    trunk/blender/source/blender/editors/curve/editcurve.c
    trunk/blender/source/blender/editors/include/ED_object.h
    trunk/blender/source/blender/editors/mesh/editmesh_add.c
    trunk/blender/source/blender/editors/object/object_add.c
    trunk/blender/source/blender/editors/object/object_intern.h
    trunk/blender/source/blender/editors/object/object_ops.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_info.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_info.py	2012-10-05 12:18:09 UTC (rev 51081)
+++ trunk/blender/release/scripts/startup/bl_ui/space_info.py	2012-10-05 12:59:09 UTC (rev 51082)
@@ -192,7 +192,7 @@
     def draw(self, context):
         layout = self.layout
 
-        layout.operator_context = 'INVOKE_REGION_WIN'
+        layout.operator_context = 'EXEC_REGION_WIN'
         layout.operator("mesh.primitive_plane_add", icon='MESH_PLANE', text="Plane")
         layout.operator("mesh.primitive_cube_add", icon='MESH_CUBE', text="Cube")
         layout.operator("mesh.primitive_circle_add", icon='MESH_CIRCLE', text="Circle")
@@ -203,7 +203,7 @@
         layout.separator()
         layout.operator("mesh.primitive_grid_add", icon='MESH_GRID', text="Grid")
         layout.operator("mesh.primitive_monkey_add", icon='MESH_MONKEY', text="Monkey")
-        layout.operator("mesh.primitive_torus_add", text="Torus", icon='MESH_TORUS')
+        layout.operator("mesh.primitive_torus_add", icon='MESH_TORUS', text="Torus")
 
 
 class INFO_MT_curve_add(Menu):
@@ -213,7 +213,7 @@
     def draw(self, context):
         layout = self.layout
 
-        layout.operator_context = 'INVOKE_REGION_WIN'
+        layout.operator_context = 'EXEC_REGION_WIN'
         layout.operator("curve.primitive_bezier_curve_add", icon='CURVE_BEZCURVE', text="Bezier")
         layout.operator("curve.primitive_bezier_circle_add", icon='CURVE_BEZCIRCLE', text="Circle")
         layout.operator("curve.primitive_nurbs_curve_add", icon='CURVE_NCURVE', text="Nurbs Curve")
@@ -221,22 +221,6 @@
         layout.operator("curve.primitive_nurbs_path_add", icon='CURVE_PATH', text="Path")
 
 
-class INFO_MT_edit_curve_add(Menu):
-    bl_idname = "INFO_MT_edit_curve_add"
-    bl_label = "Add"
-
-    def draw(self, context):
-        is_surf = context.active_object.type == 'SURFACE'
-
-        layout = self.layout
-        layout.operator_context = 'INVOKE_REGION_WIN'
-
-        if is_surf:
-            INFO_MT_surface_add.draw(self, context)
-        else:
-            INFO_MT_curve_add.draw(self, context)
-
-
 class INFO_MT_surface_add(Menu):
     bl_idname = "INFO_MT_surface_add"
     bl_label = "Surface"
@@ -244,7 +228,7 @@
     def draw(self, context):
         layout = self.layout
 
-        layout.operator_context = 'INVOKE_REGION_WIN'
+        layout.operator_context = 'EXEC_REGION_WIN'
         layout.operator("surface.primitive_nurbs_surface_curve_add", icon='SURFACE_NCURVE', text="NURBS Curve")
         layout.operator("surface.primitive_nurbs_surface_circle_add", icon='SURFACE_NCIRCLE', text="NURBS Circle")
         layout.operator("surface.primitive_nurbs_surface_surface_add", icon='SURFACE_NSURFACE', text="NURBS Surface")
@@ -253,6 +237,22 @@
         layout.operator("surface.primitive_nurbs_surface_torus_add", icon='SURFACE_NTORUS', text="NURBS Torus")
 
 
+class INFO_MT_edit_curve_add(Menu):
+    bl_idname = "INFO_MT_edit_curve_add"
+    bl_label = "Add"
+
+    def draw(self, context):
+        is_surf = context.active_object.type == 'SURFACE'
+
+        layout = self.layout
+        layout.operator_context = 'EXEC_REGION_WIN'
+
+        if is_surf:
+            INFO_MT_surface_add.draw(self, context)
+        else:
+            INFO_MT_curve_add.draw(self, context)
+
+
 class INFO_MT_armature_add(Menu):
     bl_idname = "INFO_MT_armature_add"
     bl_label = "Armature"
@@ -260,7 +260,7 @@
     def draw(self, context):
         layout = self.layout
 
-        layout.operator_context = 'INVOKE_REGION_WIN'
+        layout.operator_context = 'EXEC_REGION_WIN'
         layout.operator("object.armature_add", text="Single Bone", icon='BONE_DATA')
 
 
@@ -284,23 +284,18 @@
         #layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE')
         layout.menu("INFO_MT_surface_add", icon='OUTLINER_OB_SURFACE')
         layout.operator_menu_enum("object.metaball_add", "type", text="Metaball", icon='OUTLINER_OB_META')
-#        layout.operator_context = 'INVOKE_REGION_WIN'
         layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT')
         layout.separator()
 
         layout.menu("INFO_MT_armature_add", icon='OUTLINER_OB_ARMATURE')
-        # XXX Quick fix for [#32764].
-        layout.operator_context = 'INVOKE_REGION_WIN'
         layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE'
-        layout.operator("object.add", text="Empty", icon='OUTLINER_OB_EMPTY').type = 'EMPTY'
-        layout.operator_context = 'EXEC_REGION_WIN'
+        layout.operator_menu_enum("object.empty_add", "type", text="Empty", icon='OUTLINER_OB_EMPTY')
         layout.separator()
 
         layout.operator("object.speaker_add", text="Speaker", icon='OUTLINER_OB_SPEAKER')
         layout.separator()
 
         layout.operator("object.camera_add", text="Camera", icon='OUTLINER_OB_CAMERA')
-#        layout.operator_context = 'EXEC_AREA'
         layout.operator_menu_enum("object.lamp_add", "type", text="Lamp", icon='OUTLINER_OB_LAMP')
         layout.separator()
 
@@ -308,7 +303,7 @@
         layout.separator()
 
         if(len(bpy.data.groups) > 10):
-            layout.operator_context = 'INVOKE_DEFAULT'
+            layout.operator_context = 'INVOKE_REGION_WIN'
             layout.operator("object.group_instance_add", text="Group Instance...", icon='OUTLINER_OB_EMPTY')
         else:
             layout.operator_menu_enum("object.group_instance_add", "group", text="Group Instance", icon='OUTLINER_OB_EMPTY')

Modified: trunk/blender/source/blender/editors/curve/editcurve.c
===================================================================
--- trunk/blender/source/blender/editors/curve/editcurve.c	2012-10-05 12:18:09 UTC (rev 51081)
+++ trunk/blender/source/blender/editors/curve/editcurve.c	2012-10-05 12:59:09 UTC (rev 51082)
@@ -6567,18 +6567,18 @@
 	if (!isSurf) { /* adding curve */
 		if (obedit == NULL || obedit->type != OB_CURVE) {
 			Curve *cu;
-			
+
 			obedit = ED_object_add_type(C, OB_CURVE, loc, rot, TRUE, layer);
 			newob = 1;
 
 			cu = (Curve *)obedit->data;
 			cu->flag |= CU_DEFORM_FILL;
-			
+
 			if (type & CU_PRIM_PATH)
 				cu->flag |= CU_PATH | CU_3D;
-		} 
+		}
 		else DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
-	} 
+	}
 	else { /* adding surface */
 		if (obedit == NULL || obedit->type != OB_SURF) {
 			obedit = ED_object_add_type(C, OB_SURF, loc, rot, TRUE, layer);
@@ -6589,7 +6589,6 @@
 
 	/* rename here, the undo stack checks name for valid undo pushes */
 	if (newob) {
-
 		if (obedit->type == OB_CURVE) {
 			rename_id((ID *)obedit, get_curve_defname(type));
 			rename_id((ID *)obedit->data, get_curve_defname(type));
@@ -6599,11 +6598,11 @@
 			rename_id((ID *)obedit->data, get_surf_defname(type));
 		}
 	}
-	
+
 	/* ED_object_add_type doesnt do an undo, is needed for redo operator on primitive */
 	if (newob && enter_editmode)
 		ED_undo_push(C, "Enter Editmode");
-	
+
 	ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
 
 	nu = add_nurbs_primitive(C, obedit, mat, type, newob);
@@ -6643,12 +6642,11 @@
 	ot->name = "Add Bezier";
 	ot->description = "Construct a Bezier Curve";
 	ot->idname = "CURVE_OT_primitive_bezier_curve_add";
-	
+
 	/* api callbacks */
-	ot->invoke = ED_object_add_generic_invoke;
 	ot->exec = add_primitive_bezier_exec;
 	ot->poll = ED_operator_scene_editable;
-	
+
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -6666,12 +6664,11 @@
 	ot->name = "Add Bezier Circle";
 	ot->description = "Construct a Bezier Circle";
 	ot->idname = "CURVE_OT_primitive_bezier_circle_add";
-	
+
 	/* api callbacks */
-	ot->invoke = ED_object_add_generic_invoke;
 	ot->exec = add_primitive_bezier_circle_exec;
 	ot->poll = ED_operator_scene_editable;
-	
+
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -6689,12 +6686,11 @@
 	ot->name = "Add Nurbs Curve";
 	ot->description = "Construct a Nurbs Curve";
 	ot->idname = "CURVE_OT_primitive_nurbs_curve_add";
-	
+
 	/* api callbacks */
-	ot->invoke = ED_object_add_generic_invoke;
 	ot->exec = add_primitive_nurbs_curve_exec;
 	ot->poll = ED_operator_scene_editable;
-	
+
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -6712,12 +6708,11 @@
 	ot->name = "Add Nurbs Circle";
 	ot->description = "Construct a Nurbs Circle";
 	ot->idname = "CURVE_OT_primitive_nurbs_circle_add";
-	
+
 	/* api callbacks */
-	ot->invoke = ED_object_add_generic_invoke;
 	ot->exec = add_primitive_nurbs_circle_exec;
 	ot->poll = ED_operator_scene_editable;
-	
+
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -6735,12 +6730,11 @@
 	ot->name = "Add Path";
 	ot->description = "Construct a Path";
 	ot->idname = "CURVE_OT_primitive_nurbs_path_add";
-	
+
 	/* api callbacks */
-	ot->invoke = ED_object_add_generic_invoke;
 	ot->exec = add_primitive_curve_path_exec;
 	ot->poll = ED_operator_scene_editable;
-	
+
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -6759,12 +6753,11 @@
 	ot->name = "Add Surface Curve";
 	ot->description = "Construct a Nurbs surface Curve";
 	ot->idname = "SURFACE_OT_primitive_nurbs_surface_curve_add";
-	
+
 	/* api callbacks */
-	ot->invoke = ED_object_add_generic_invoke;
 	ot->exec = add_primitive_nurbs_surface_curve_exec;
 	ot->poll = ED_operator_scene_editable;
-	
+
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -6782,12 +6775,11 @@
 	ot->name = "Add Surface Circle";
 	ot->description = "Construct a Nurbs surface Circle";
 	ot->idname = "SURFACE_OT_primitive_nurbs_surface_circle_add";
-	
+
 	/* api callbacks */
-	ot->invoke = ED_object_add_generic_invoke;
 	ot->exec = add_primitive_nurbs_surface_circle_exec;
 	ot->poll = ED_operator_scene_editable;
-	
+
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -6805,12 +6797,11 @@
 	ot->name = "Add Surface Patch";
 	ot->description = "Construct a Nurbs surface Patch";
 	ot->idname = "SURFACE_OT_primitive_nurbs_surface_surface_add";
-	
+
 	/* api callbacks */
-	ot->invoke = ED_object_add_generic_invoke;
 	ot->exec = add_primitive_nurbs_surface_surface_exec;
 	ot->poll = ED_operator_scene_editable;
-	
+
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -6828,12 +6819,11 @@
 	ot->name = "Add Surface Cylinder";
 	ot->description = "Construct a Nurbs surface Cylinder";
 	ot->idname = "SURFACE_OT_primitive_nurbs_surface_cylinder_add";
-	
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list