[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55695] trunk/blender/source/blender/ editors: code cleanup: split editmesh_tools.c, into inset, bevel ( both modal operators) and moved extrude operators into their own file.

Campbell Barton ideasman42 at gmail.com
Mon Apr 1 12:18:01 CEST 2013


Revision: 55695
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55695
Author:   campbellbarton
Date:     2013-04-01 10:18:01 +0000 (Mon, 01 Apr 2013)
Log Message:
-----------
code cleanup: split editmesh_tools.c, into inset, bevel (both modal operators) and moved extrude operators into their own file.
also move some selection operators from editmesh_tools.c into editmesh_select.c

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_mesh.h
    trunk/blender/source/blender/editors/mesh/CMakeLists.txt
    trunk/blender/source/blender/editors/mesh/editmesh_add.c
    trunk/blender/source/blender/editors/mesh/editmesh_bvh.c
    trunk/blender/source/blender/editors/mesh/editmesh_knife.c
    trunk/blender/source/blender/editors/mesh/editmesh_knife_project.c
    trunk/blender/source/blender/editors/mesh/editmesh_loopcut.c
    trunk/blender/source/blender/editors/mesh/editmesh_rip.c
    trunk/blender/source/blender/editors/mesh/editmesh_select.c
    trunk/blender/source/blender/editors/mesh/editmesh_tools.c
    trunk/blender/source/blender/editors/mesh/editmesh_utils.c
    trunk/blender/source/blender/editors/mesh/mesh_data.c
    trunk/blender/source/blender/editors/mesh/mesh_intern.h
    trunk/blender/source/blender/editors/mesh/mesh_navmesh.c
    trunk/blender/source/blender/editors/mesh/mesh_ops.c
    trunk/blender/source/blender/editors/mesh/meshtools.c

Added Paths:
-----------
    trunk/blender/source/blender/editors/mesh/editmesh_bevel.c
    trunk/blender/source/blender/editors/mesh/editmesh_extrude.c
    trunk/blender/source/blender/editors/mesh/editmesh_inset.c

Modified: trunk/blender/source/blender/editors/include/ED_mesh.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_mesh.h	2013-04-01 09:55:37 UTC (rev 55694)
+++ trunk/blender/source/blender/editors/include/ED_mesh.h	2013-04-01 10:18:01 UTC (rev 55695)
@@ -278,7 +278,7 @@
 void EDBM_redo_state_free(struct BMBackup *, struct BMEditMesh *em, int recalctess);
 
 
-/* meshtools.c */
+/* *** meshtools.c *** */
 int         join_mesh_exec(struct bContext *C, struct wmOperator *op);
 int         join_mesh_shapes_exec(struct bContext *C, struct wmOperator *op);
 

Modified: trunk/blender/source/blender/editors/mesh/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/editors/mesh/CMakeLists.txt	2013-04-01 09:55:37 UTC (rev 55694)
+++ trunk/blender/source/blender/editors/mesh/CMakeLists.txt	2013-04-01 10:18:01 UTC (rev 55695)
@@ -42,7 +42,10 @@
 set(SRC
 	editface.c
 	editmesh_add.c
+	editmesh_bevel.c
 	editmesh_bvh.c
+	editmesh_extrude.c
+	editmesh_inset.c
 	editmesh_knife.c
 	editmesh_knife_project.c
 	editmesh_loopcut.c

Modified: trunk/blender/source/blender/editors/mesh/editmesh_add.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_add.c	2013-04-01 09:55:37 UTC (rev 55694)
+++ trunk/blender/source/blender/editors/mesh/editmesh_add.c	2013-04-01 10:18:01 UTC (rev 55695)
@@ -30,7 +30,6 @@
  */
 
 #include "DNA_object_types.h"
-#include "DNA_scene_types.h"
 
 #include "BLI_math.h"
 
@@ -50,7 +49,7 @@
 #include "ED_screen.h"
 #include "ED_object.h"
 
-#include "mesh_intern.h"
+#include "mesh_intern.h"  /* own include */
 
 /* ********* add primitive operators ************* */
 

Added: trunk/blender/source/blender/editors/mesh/editmesh_bevel.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_bevel.c	                        (rev 0)
+++ trunk/blender/source/blender/editors/mesh/editmesh_bevel.c	2013-04-01 10:18:01 UTC (rev 55695)
@@ -0,0 +1,368 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Joseph Eagar, Howard Trickey, Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/mesh/editmesh_bevel.c
+ *  \ingroup edmesh
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_object_types.h"
+
+#include "BLI_string.h"
+#include "BLI_math.h"
+
+#include "BLF_translation.h"
+
+#include "BKE_context.h"
+#include "BKE_tessmesh.h"
+
+#include "RNA_define.h"
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_mesh.h"
+#include "ED_numinput.h"
+#include "ED_screen.h"
+#include "ED_transform.h"
+#include "ED_view3d.h"
+
+#include "mesh_intern.h"  /* own include */
+
+
+#define MVAL_PIXEL_MARGIN  5.0f
+
+typedef struct {
+	BMEditMesh *em;
+	BMBackup mesh_backup;
+	int mcenter[2];
+	float initial_length;
+	float pixel_size;  /* use when mouse input is interpreted as spatial distance */
+	int is_modal;
+	NumInput num_input;
+	float shift_factor; /* The current factor when shift is pressed. Negative when shift not active. */
+} BevelData;
+
+#define HEADER_LENGTH 180
+
+static void edbm_bevel_update_header(wmOperator *op, bContext *C)
+{
+	const char *str = IFACE_("Confirm: Enter/LClick, Cancel: (Esc/RMB), Offset: %s, Segments: %d");
+
+	char msg[HEADER_LENGTH];
+	ScrArea *sa = CTX_wm_area(C);
+
+	if (sa) {
+		char offset_str[NUM_STR_REP_LEN];
+		BLI_snprintf(offset_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "offset"));
+		BLI_snprintf(msg, HEADER_LENGTH, str,
+		             offset_str,
+		             RNA_int_get(op->ptr, "segments")
+		            );
+
+		ED_area_headerprint(sa, msg);
+	}
+}
+
+static int edbm_bevel_init(bContext *C, wmOperator *op, int is_modal)
+{
+	Object *obedit = CTX_data_edit_object(C);
+	BMEditMesh *em = BMEdit_FromObject(obedit);
+	BevelData *opdata;
+
+	if (em == NULL) {
+		return 0;
+	}
+
+	op->customdata = opdata = MEM_mallocN(sizeof(BevelData), "beveldata_mesh_operator");
+
+	opdata->em = em;
+	opdata->is_modal = is_modal;
+	opdata->shift_factor = -1.0f;
+
+	initNumInput(&opdata->num_input);
+	opdata->num_input.flag = NUM_NO_NEGATIVE;
+
+	/* avoid the cost of allocating a bm copy */
+	if (is_modal)
+		opdata->mesh_backup = EDBM_redo_state_store(em);
+
+	return 1;
+}
+
+static int edbm_bevel_calc(wmOperator *op)
+{
+	BevelData *opdata = op->customdata;
+	BMEditMesh *em = opdata->em;
+	BMOperator bmop;
+	const float offset = RNA_float_get(op->ptr, "offset");
+	const int segments = RNA_int_get(op->ptr, "segments");
+	const bool vertex_only = RNA_boolean_get(op->ptr, "vertex_only");
+
+	/* revert to original mesh */
+	if (opdata->is_modal) {
+		EDBM_redo_state_restore(opdata->mesh_backup, em, false);
+	}
+
+	if (!EDBM_op_init(em, &bmop, op,
+		              "bevel geom=%hev offset=%f segments=%i vertex_only=%b",
+		              BM_ELEM_SELECT, offset, segments, vertex_only))
+	{
+		return 0;
+	}
+
+	BMO_op_exec(em->bm, &bmop);
+
+	if (offset != 0.0f) {
+		/* not essential, but we may have some loose geometry that
+		 * won't get bevel'd and better not leave it selected */
+		EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+		BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true);
+	}
+
+	/* no need to de-select existing geometry */
+	if (!EDBM_op_finish(em, &bmop, op, true))
+		return 0;
+
+	EDBM_mesh_normals_update(opdata->em);
+
+	EDBM_update_generic(opdata->em, true, true);
+
+	return 1;
+}
+
+static void edbm_bevel_exit(bContext *C, wmOperator *op)
+{
+	BevelData *opdata = op->customdata;
+
+	ScrArea *sa = CTX_wm_area(C);
+
+	if (sa) {
+		ED_area_headerprint(sa, NULL);
+	}
+
+	if (opdata->is_modal) {
+		EDBM_redo_state_free(&opdata->mesh_backup, NULL, false);
+	}
+	MEM_freeN(opdata);
+	op->customdata = NULL;
+}
+
+static int edbm_bevel_cancel(bContext *C, wmOperator *op)
+{
+	BevelData *opdata = op->customdata;
+	if (opdata->is_modal) {
+		EDBM_redo_state_free(&opdata->mesh_backup, opdata->em, true);
+		EDBM_update_generic(opdata->em, false, true);
+	}
+
+	edbm_bevel_exit(C, op);
+
+	/* need to force redisplay or we may still view the modified result */
+	ED_region_tag_redraw(CTX_wm_region(C));
+	return OPERATOR_CANCELLED;
+}
+
+/* bevel! yay!!*/
+static int edbm_bevel_exec(bContext *C, wmOperator *op)
+{
+	if (!edbm_bevel_init(C, op, false)) {
+		edbm_bevel_exit(C, op);
+		return OPERATOR_CANCELLED;
+	}
+
+	if (!edbm_bevel_calc(op)) {
+		edbm_bevel_cancel(C, op);
+		return OPERATOR_CANCELLED;
+	}
+
+	edbm_bevel_exit(C, op);
+
+	return OPERATOR_FINISHED;
+}
+
+static int edbm_bevel_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+	/* TODO make modal keymap (see fly mode) */
+	RegionView3D *rv3d = CTX_wm_region_view3d(C);
+	BevelData *opdata;
+	float mlen[2];
+	float center_3d[3];
+
+	if (!edbm_bevel_init(C, op, true)) {
+		return OPERATOR_CANCELLED;
+	}
+
+	opdata = op->customdata;
+
+	/* initialize mouse values */
+	if (!calculateTransformCenter(C, V3D_CENTROID, center_3d, opdata->mcenter)) {
+		/* in this case the tool will likely do nothing,
+		 * ideally this will never happen and should be checked for above */
+		opdata->mcenter[0] = opdata->mcenter[1] = 0;
+	}
+	mlen[0] = opdata->mcenter[0] - event->mval[0];
+	mlen[1] = opdata->mcenter[1] - event->mval[1];
+	opdata->initial_length = len_v2(mlen);
+	opdata->pixel_size = rv3d ? ED_view3d_pixel_size(rv3d, center_3d) : 1.0f;
+
+	edbm_bevel_update_header(op, C);
+
+	if (!edbm_bevel_calc(op)) {
+		edbm_bevel_cancel(C, op);
+		return OPERATOR_CANCELLED;
+	}
+
+	WM_event_add_modal_handler(C, op);
+
+	return OPERATOR_RUNNING_MODAL;
+}
+
+static float edbm_bevel_mval_factor(wmOperator *op, const wmEvent *event)
+{
+	BevelData *opdata = op->customdata;
+	int use_dist = true;
+	float mdiff[2];
+	float factor;
+
+	mdiff[0] = opdata->mcenter[0] - event->mval[0];
+	mdiff[1] = opdata->mcenter[1] - event->mval[1];
+
+	if (use_dist) {
+		factor = ((len_v2(mdiff) - MVAL_PIXEL_MARGIN) - opdata->initial_length) * opdata->pixel_size;
+	}
+	else {
+		factor = (len_v2(mdiff) - MVAL_PIXEL_MARGIN) / opdata->initial_length;
+		factor = factor - 1.0f;  /* a different kind of buffer where nothing happens */
+	}
+
+	/* Fake shift-transform... */
+	if (event->shift) {
+		if (opdata->shift_factor < 0.0f) {
+			opdata->shift_factor = RNA_float_get(op->ptr, "offset");
+		}
+		factor = (factor - opdata->shift_factor) * 0.1f + opdata->shift_factor;
+	}
+	else if (opdata->shift_factor >= 0.0f)
+		opdata->shift_factor = -1.0f;
+
+	/* clamp differently based on distance/factor */
+	if (use_dist) {
+		if (factor < 0.0f) factor = 0.0f;
+	}
+	else {
+		CLAMP(factor, 0.0f, 1.0f);
+	}
+
+	return factor;
+}
+
+static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event)
+{
+	BevelData *opdata = op->customdata;
+	int segments = RNA_int_get(op->ptr, "segments");
+
+	if (event->val == KM_PRESS) {
+		/* Try to handle numeric inputs... */
+
+		if (handleNumInput(&opdata->num_input, event)) {
+			float value = RNA_float_get(op->ptr, "offset");
+			applyNumInput(&opdata->num_input, &value);
+			RNA_float_set(op->ptr, "offset", value);
+			edbm_bevel_calc(op);
+			edbm_bevel_update_header(op, C);
+			return OPERATOR_RUNNING_MODAL;
+		}
+	}
+
+	switch (event->type) {
+		case ESCKEY:
+		case RIGHTMOUSE:
+			edbm_bevel_cancel(C, op);
+			return OPERATOR_CANCELLED;
+
+		case MOUSEMOVE:
+			if (!hasNumInput(&opdata->num_input)) {
+				const float factor = edbm_bevel_mval_factor(op, event);
+				RNA_float_set(op->ptr, "offset", factor);
+
+				edbm_bevel_calc(op);
+				edbm_bevel_update_header(op, C);
+			}
+			break;
+
+		case LEFTMOUSE:
+		case PADENTER:
+		case RETKEY:
+			edbm_bevel_calc(op);
+			edbm_bevel_exit(C, op);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list