[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49047] branches/soc-2012-bratwurst: Introduce an operator which switches to edit mode and activates a specific edit selection mode at the same time .

Jorge Rodriguez bs.vino at gmail.com
Thu Jul 19 00:29:32 CEST 2012


Revision: 49047
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49047
Author:   vino
Date:     2012-07-18 22:29:31 +0000 (Wed, 18 Jul 2012)
Log Message:
-----------
Introduce an operator which switches to edit mode and activates a specific edit selection mode at the same time. This lets a designer create buttons that go to a specific edit selection mode when the user is in object mode. Use this operator to implement more functionality for the floating controls.

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/mesh/mesh_intern.h
    branches/soc-2012-bratwurst/source/blender/editors/mesh/mesh_ops.c
    branches/soc-2012-bratwurst/source/blender/editors/space_view3d/view3d_header.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-18 21:43:37 UTC (rev 49046)
+++ branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py	2012-07-18 22:29:31 UTC (rev 49047)
@@ -2717,13 +2717,26 @@
             row.prop(view, "use_manipulator_rotate", text="", icon='MAN_ROT', clearfield=True)
             row.prop(view, "use_manipulator_scale", text="", icon='MAN_SCALE', clearfield=True)
 
+            row.separator()
+
+            # When the user is in edit mode, these buttons are property controls so that they can remember state,
+            # toggle on and off, make use of shift, etc. However, when the user is in object mode they're drawn
+            # as operator controls so that they render off (popped, not toggled) and when the user clicks they
+            # invoke edit mode.
+
             if bpy.context.object.mode == 'EDIT':
-                row.separator()
-            
                 row.prop(tools, "use_select_vertex", text="", clearfield=True)
                 row.prop(tools, "use_select_edge", text="", clearfield=True)
                 row.prop(tools, "use_select_face", text="", clearfield=True)
 
+            else:
+                props = row.operator("mesh.selection_mode_set", text="", icon='VERTEXSEL')
+                props.mode='VERTEX'
+                props = row.operator("mesh.selection_mode_set", text="", icon='EDGESEL')
+                props.mode='EDGE'
+                props = row.operator("mesh.selection_mode_set", text="", icon='FACESEL')
+                props.mode='FACE'
+
         elif bpy.context.user_preferences.edit.floating_controls == 'LEFT' or bpy.context.user_preferences.edit.floating_controls == 'RIGHT':
             layout = self.layout
 
@@ -2739,13 +2752,20 @@
             column.prop(view, "use_manipulator_rotate", text="", icon='MAN_ROT', clearfield=True)
             column.prop(view, "use_manipulator_scale", text="", icon='MAN_SCALE', clearfield=True)
 
+            column.separator()
+
             if bpy.context.object.mode == 'EDIT':
-                column.separator()
-            
                 column.prop(tools, "use_select_vertex", text="", clearfield=True)
                 column.prop(tools, "use_select_edge", text="", clearfield=True)
                 column.prop(tools, "use_select_face", text="", clearfield=True)
 
+            else:
+                props = column.operator("mesh.selection_mode_set", text="", icon='VERTEXSEL')
+                props.mode='VERTEX'
+                props = column.operator("mesh.selection_mode_set", text="", icon='EDGESEL')
+                props.mode='EDGE'
+                props = column.operator("mesh.selection_mode_set", text="", icon='FACESEL')
+                props.mode='FACE'
 
 
 

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-18 21:43:37 UTC (rev 49046)
+++ branches/soc-2012-bratwurst/source/blender/editors/mesh/editmesh_tools.c	2012-07-18 22:29:31 UTC (rev 49047)
@@ -5189,3 +5189,72 @@
 
 	join_triangle_props(ot);
 }
+
+
+/* *************** Operator: set selection mode *************/
+
+static EnumPropertyItem prop_selection_mode[] = {
+	{SCE_SELECT_VERTEX, "VERTEX", 0, "Vertex", ""},
+	{SCE_SELECT_EDGE, "EDGE", 0, "Edge", ""},
+	{SCE_SELECT_FACE, "FACE", 0, "Face", ""},
+	{0, NULL, 0, NULL, NULL}
+};
+
+static int selection_mode_set_exec(bContext *C, wmOperator *op)
+{
+	Object *ob = CTX_data_active_object(C);
+	ObjectMode mode = OB_MODE_EDIT;
+	BMEditMesh *em = BMEdit_FromObject(ob);
+	ToolSettings *ts = CTX_data_tool_settings(C);
+	int type;
+
+	if (!ob || ob->type != OB_MESH)
+		return OPERATOR_PASS_THROUGH;
+
+	// Make sure we are in edit mode.
+	if (ob->mode != mode) {
+		PointerRNA ptr;
+
+		WM_operator_properties_create(&ptr, "OBJECT_OT_mode_set");
+		RNA_enum_set(&ptr, "mode", OB_MODE_EDIT);
+		RNA_boolean_set(&ptr, "toggle", 0);
+		WM_operator_name_call(C, "OBJECT_OT_mode_set", WM_OP_EXEC_REGION_WIN, &ptr);
+		WM_operator_properties_free(&ptr);
+	}
+
+	type = RNA_enum_get(op->ptr, "mode");
+
+	if (type != SCE_SELECT_FACE && type != SCE_SELECT_EDGE && type != SCE_SELECT_VERTEX)
+		return OPERATOR_PASS_THROUGH;
+
+	ts->selectmode = type;
+
+	if (!em)
+		return OPERATOR_PASS_THROUGH;
+
+	em->selectmode = ts->selectmode;
+	EDBM_selectmode_set(em);
+
+	EDBM_flag_enable_all(em, BM_ELEM_SELECT);
+
+	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob);
+	WM_main_add_notifier(NC_SCENE|ND_TOOLSETTINGS, NULL);
+
+	return OPERATOR_FINISHED;
+}
+
+void MESH_OT_selection_mode_set(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Set Selection Mode";
+	ot->description = "Specify to work with either vertex, edge, or face selection";
+	ot->idname = "MESH_OT_selection_mode_set";
+
+	/* api callbacks */
+	ot->exec = selection_mode_set_exec;
+
+	/* flags */
+	ot->flag = 0;
+
+	ot->prop = RNA_def_enum(ot->srna, "mode", prop_selection_mode, 0, "Mode", "");
+}
\ No newline at end of file

Modified: branches/soc-2012-bratwurst/source/blender/editors/mesh/mesh_intern.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/mesh/mesh_intern.h	2012-07-18 21:43:37 UTC (rev 49046)
+++ branches/soc-2012-bratwurst/source/blender/editors/mesh/mesh_intern.h	2012-07-18 22:29:31 UTC (rev 49047)
@@ -89,6 +89,8 @@
 
 void MESH_OT_separate(struct wmOperatorType *ot);
 
+void MESH_OT_selection_mode_set(struct wmOperatorType *ot);
+
 /* ******************* editmesh_add.c */
 void MESH_OT_primitive_plane_add(struct wmOperatorType *ot);
 void MESH_OT_primitive_cube_add(struct wmOperatorType *ot);

Modified: branches/soc-2012-bratwurst/source/blender/editors/mesh/mesh_ops.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/mesh/mesh_ops.c	2012-07-18 21:43:37 UTC (rev 49046)
+++ branches/soc-2012-bratwurst/source/blender/editors/mesh/mesh_ops.c	2012-07-18 22:29:31 UTC (rev 49047)
@@ -58,6 +58,7 @@
 
 void ED_operatortypes_mesh(void)
 {
+	WM_operatortype_append(MESH_OT_selection_mode_set);
 	WM_operatortype_append(MESH_OT_select_all);
 	WM_operatortype_append(MESH_OT_select_interior_faces);
 	WM_operatortype_append(MESH_OT_select_more);

Modified: branches/soc-2012-bratwurst/source/blender/editors/space_view3d/view3d_header.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/space_view3d/view3d_header.c	2012-07-18 21:43:37 UTC (rev 49046)
+++ branches/soc-2012-bratwurst/source/blender/editors/space_view3d/view3d_header.c	2012-07-18 22:29:31 UTC (rev 49047)
@@ -357,63 +357,6 @@
 			WM_operator_properties_free(&props_ptr);
 			break;
 
-		case B_SEL_VERT:
-			if (em) {
-				if (shift == 0 || em->selectmode == 0)
-					em->selectmode = SCE_SELECT_VERTEX;
-				ts->selectmode = em->selectmode;
-				EDBM_selectmode_set(em);
-				WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
-				ED_undo_push(C, "Selectmode Set: Vertex");
-			}
-			break;
-		case B_SEL_EDGE:
-			if (em) {
-				if (shift == 0 || em->selectmode == 0) {
-					if ( (em->selectmode ^ SCE_SELECT_EDGE) == SCE_SELECT_VERTEX) {
-						if (ctrl) EDBM_selectmode_convert(em, SCE_SELECT_VERTEX, SCE_SELECT_EDGE);
-					}
-					em->selectmode = SCE_SELECT_EDGE;
-				}
-				ts->selectmode = em->selectmode;
-				EDBM_selectmode_set(em);
-				WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
-				ED_undo_push(C, "Selectmode Set: Edge");
-			}
-			break;
-		case B_SEL_FACE:
-			if (em) {
-				if (shift == 0 || em->selectmode == 0) {
-					if ( ((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_VERTEX) || ((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_EDGE)) {
-						if (ctrl) EDBM_selectmode_convert(em, (ts->selectmode ^ SCE_SELECT_FACE), SCE_SELECT_FACE);
-					}
-					em->selectmode = SCE_SELECT_FACE;
-				}
-				ts->selectmode = em->selectmode;
-				EDBM_selectmode_set(em);
-				WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
-				ED_undo_push(C, "Selectmode Set: Face");
-			}
-			break;
-
-		case B_MAN_TRANS:
-			if (shift == 0 || v3d->twtype == 0) {
-				v3d->twtype = V3D_MANIP_TRANSLATE;
-			}
-			ED_area_tag_redraw(sa);
-			break;
-		case B_MAN_ROT:
-			if (shift == 0 || v3d->twtype == 0) {
-				v3d->twtype = V3D_MANIP_ROTATE;
-			}
-			ED_area_tag_redraw(sa);
-			break;
-		case B_MAN_SCALE:
-			if (shift == 0 || v3d->twtype == 0) {
-				v3d->twtype = V3D_MANIP_SCALE;
-			}
-			ED_area_tag_redraw(sa);
-			break;
 		case B_NDOF:
 			ED_area_tag_redraw(sa);
 			break;
@@ -535,15 +478,6 @@
 		uiItemR(row, &v3dptr, "show_manipulator", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
 		block = uiLayoutGetBlock(row);
 		
-		if (v3d->twflag & V3D_USE_MANIPULATOR) {
-			but = uiDefIconButBitC(block, TOG, V3D_MANIP_TRANSLATE, B_MAN_TRANS, ICON_MAN_TRANS, 0, 0, UI_UNIT_X, UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0, TIP_("Translate manipulator - Shift-Click for multiple modes"));
-			uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
-			but = uiDefIconButBitC(block, TOG, V3D_MANIP_ROTATE, B_MAN_ROT, ICON_MAN_ROT, 0, 0, UI_UNIT_X, UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0, TIP_("Rotate manipulator - Shift-Click for multiple modes"));
-			uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
-			but = uiDefIconButBitC(block, TOG, V3D_MANIP_SCALE, B_MAN_SCALE, ICON_MAN_SCALE, 0, 0, UI_UNIT_X, UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0, TIP_("Scale manipulator - Shift-Click for multiple modes"));
-			uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
-		}
-			
 		if (v3d->twmode > (BIF_countTransformOrientation(C) - 1) + V3D_MANIP_CUSTOM) {
 			v3d->twmode = 0;
 		}
@@ -563,6 +497,4 @@
 		/* Scene lock */
 		uiItemR(layout, &v3dptr, "lock_camera_and_layers", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
 	}
-	
-	uiTemplateEditModeSelection(layout, C);
 }




More information about the Bf-blender-cvs mailing list