Exemplo n.º 1
0
/**
 * Special hack for MESH_OT_loopcut_slide so we get back to the selection mode
 */
static void transformops_loopsel_hack(bContext *C, wmOperator *op)
{
	if (op->type->idname == OP_EDGE_SLIDE) {
		if (op->opm && op->opm->opm && op->opm->opm->prev) {
			wmOperator *op_prev = op->opm->opm->prev;
			Scene *scene = CTX_data_scene(C);
			int mesh_select_mode[3];
			PropertyRNA *prop = RNA_struct_find_property(op_prev->ptr, "mesh_select_mode_init");

			if (prop && RNA_property_is_set(op_prev->ptr, prop)) {
				ToolSettings *ts = scene->toolsettings;
				short selectmode_orig;

				RNA_property_boolean_get_array(op_prev->ptr, prop, mesh_select_mode);
				selectmode_orig = ((mesh_select_mode[0] ? SCE_SELECT_VERTEX : 0) |
				                   (mesh_select_mode[1] ? SCE_SELECT_EDGE   : 0) |
				                   (mesh_select_mode[2] ? SCE_SELECT_FACE   : 0));

				/* still switch if we were originally in face select mode */
				if ((ts->selectmode != selectmode_orig) && (selectmode_orig != SCE_SELECT_FACE)) {
					BMEditMesh *em = BKE_editmesh_from_object(scene->obedit);
					em->selectmode = ts->selectmode = selectmode_orig;
					EDBM_selectmode_set(em);
				}
			}
		}
	}
}
Exemplo n.º 2
0
static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event)
{
	wmWindow *win = CTX_wm_window(C);
	ToolSettings *ts = CTX_data_tool_settings(C);
	ScrArea *sa = CTX_wm_area(C);
	View3D *v3d = sa->spacedata.first;
	Object *obedit = CTX_data_edit_object(C);
	BMEditMesh *em = NULL;
	int ctrl = win->eventstate->ctrl, shift = win->eventstate->shift;
	PointerRNA props_ptr;
	
	if (obedit && obedit->type == OB_MESH) {
		em = BMEdit_FromObject(obedit);
	}
	/* watch it: if sa->win does not exist, check that when calling direct drawing routines */

	switch (event) {
		case B_REDR:
			ED_area_tag_redraw(sa);
			break;

		case B_MODESELECT:
			WM_operator_properties_create(&props_ptr, "OBJECT_OT_mode_set");
			RNA_enum_set(&props_ptr, "mode", v3d->modeselect);
			WM_operator_name_call(C, "OBJECT_OT_mode_set", WM_OP_EXEC_REGION_WIN, &props_ptr);
			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;
		case B_MAN_MODE:
			ED_area_tag_redraw(sa);
			break;
		default:
			break;
	}
}