This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/editors/mesh/editmesh_loopcut.c

872 lines
22 KiB
C
Raw Normal View History

/*
2009-09-16 22:27:22 +00:00
* ***** 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.
2009-09-16 22:27:22 +00:00
*
* 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,
2010-02-12 13:34:04 +00:00
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2009-09-16 22:27:22 +00:00
*
* The Original Code is Copyright (C) 2007 Blender Foundation.
* All rights reserved.
*
*
2009-09-16 22:27:22 +00:00
* Contributor(s): Joseph Eagar, Joshua Leung
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/mesh/editmesh_loopcut.c
2011-02-27 20:29:51 +00:00
* \ingroup edmesh
*/
#include "DNA_object_types.h"
2009-09-16 22:27:22 +00:00
#include "MEM_guardedalloc.h"
2015-06-21 09:46:12 +10:00
#include "BLI_stack.h"
#include "BLI_string.h"
2012-01-17 18:11:17 +00:00
#include "BLI_math.h"
2009-09-16 22:27:22 +00:00
#include "BLT_translation.h"
2009-09-16 22:27:22 +00:00
#include "BKE_context.h"
#include "BKE_modifier.h"
#include "BKE_report.h"
#include "BKE_editmesh.h"
#include "BKE_DerivedMesh.h"
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
#include "BKE_unit.h"
2009-09-16 22:27:22 +00:00
#include "BIF_gl.h"
#include "UI_interface.h"
2009-09-16 22:27:22 +00:00
#include "ED_screen.h"
#include "ED_space_api.h"
#include "ED_view3d.h"
#include "ED_mesh.h"
#include "ED_numinput.h"
2009-09-16 22:27:22 +00:00
#include "RNA_access.h"
#include "RNA_define.h"
2013-05-08 12:58:28 +00:00
#include "RNA_enum_types.h"
2009-09-16 22:27:22 +00:00
#include "WM_api.h"
#include "WM_types.h"
#include "mesh_intern.h" /* own include */
#define SUBD_SMOOTH_MAX 4.0f
#define SUBD_CUTS_MAX 500
2009-09-16 22:27:22 +00:00
/* ringsel operator */
/* struct for properties used while drawing */
typedef struct RingSelOpData {
ARegion *ar; /* region that ringsel was activated in */
void *draw_handle; /* for drawing preview loop */
2009-09-16 22:27:22 +00:00
float (*edges)[2][3];
int totedge;
float (*points)[3];
int totpoint;
2009-09-16 22:27:22 +00:00
ViewContext vc;
Object *ob;
BMEditMesh *em;
BMEdge *eed;
NumInput num;
2009-09-16 22:27:22 +00:00
bool extend;
bool do_cut;
float cuts; /* cuts as float so smooth mouse pan works in small increments */
float smoothness;
} RingSelOpData;
2009-09-16 22:27:22 +00:00
/* modal loop selection drawing callback */
static void ringsel_draw(const bContext *C, ARegion *UNUSED(ar), void *arg)
2009-09-16 22:27:22 +00:00
{
View3D *v3d = CTX_wm_view3d(C);
RingSelOpData *lcd = arg;
if ((lcd->totedge > 0) || (lcd->totpoint > 0)) {
if (v3d && v3d->zbuf)
glDisable(GL_DEPTH_TEST);
2009-09-16 22:27:22 +00:00
glPushMatrix();
glMultMatrixf(lcd->ob->obmat);
2009-09-16 22:27:22 +00:00
glColor3ub(255, 0, 255);
if (lcd->totedge > 0) {
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, lcd->edges);
glDrawArrays(GL_LINES, 0, lcd->totedge * 2);
glDisableClientState(GL_VERTEX_ARRAY);
}
if (lcd->totpoint > 0) {
glPointSize(3.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, lcd->points);
glDrawArrays(GL_POINTS, 0, lcd->totpoint);
glDisableClientState(GL_VERTEX_ARRAY);
}
2009-09-16 22:27:22 +00:00
glPopMatrix();
if (v3d && v3d->zbuf)
glEnable(GL_DEPTH_TEST);
}
2009-09-16 22:27:22 +00:00
}
/* given two opposite edges in a face, finds the ordering of their vertices so
* that cut preview lines won't cross each other */
static void edgering_find_order(BMEdge *lasteed, BMEdge *eed,
BMVert *lastv1, BMVert *v[2][2])
{
BMIter liter;
BMLoop *l, *l2;
int rev;
l = eed->l;
/* find correct order for v[1] */
if (!(BM_edge_in_face(eed, l->f) && BM_edge_in_face(lasteed, l->f))) {
BM_ITER_ELEM (l, &liter, l, BM_LOOPS_OF_LOOP) {
if (BM_edge_in_face(eed, l->f) && BM_edge_in_face(lasteed, l->f))
break;
}
}
/* this should never happen */
if (!l) {
v[0][0] = eed->v1;
v[0][1] = eed->v2;
v[1][0] = lasteed->v1;
v[1][1] = lasteed->v2;
return;
}
l2 = BM_loop_other_edge_loop(l, eed->v1);
2011-09-12 15:10:59 +00:00
rev = (l2 == l->prev);
while (l2->v != lasteed->v1 && l2->v != lasteed->v2) {
2011-09-12 15:10:59 +00:00
l2 = rev ? l2->prev : l2->next;
}
if (l2->v == lastv1) {
v[0][0] = eed->v1;
v[0][1] = eed->v2;
}
else {
v[0][0] = eed->v2;
v[0][1] = eed->v1;
}
}
static void edgering_vcos_get(DerivedMesh *dm, BMVert *v[2][2], float r_cos[2][2][3])
{
if (dm) {
int j, k;
for (j = 0; j < 2; j++) {
for (k = 0; k < 2; k++) {
dm->getVertCo(dm, BM_elem_index_get(v[j][k]), r_cos[j][k]);
}
}
}
else {
int j, k;
for (j = 0; j < 2; j++) {
for (k = 0; k < 2; k++) {
copy_v3_v3(r_cos[j][k], v[j][k]->co);
}
}
}
}
static void edgering_vcos_get_pair(DerivedMesh *dm, BMVert *v[2], float r_cos[2][3])
2009-09-16 22:27:22 +00:00
{
if (dm) {
int j;
for (j = 0; j < 2; j++) {
dm->getVertCo(dm, BM_elem_index_get(v[j]), r_cos[j]);
}
2009-09-16 22:27:22 +00:00
}
else {
int j;
for (j = 0; j < 2; j++) {
copy_v3_v3(r_cos[j], v[j]->co);
}
2009-09-16 22:27:22 +00:00
}
}
2009-09-16 22:27:22 +00:00
static void edgering_preview_free(RingSelOpData *lcd)
{
MEM_SAFE_FREE(lcd->edges);
lcd->totedge = 0;
2009-09-16 22:27:22 +00:00
MEM_SAFE_FREE(lcd->points);
lcd->totpoint = 0;
}
2009-09-16 22:27:22 +00:00
static void edgering_preview_calc_edges(RingSelOpData *lcd, DerivedMesh *dm, const int previewlines)
{
BMesh *bm = lcd->em->bm;
BMWalker walker;
BMEdge *eed_start = lcd->eed;
BMEdge *eed, *eed_last;
BMVert *v[2][2] = {{NULL}}, *v_last;
float (*edges)[2][3] = NULL;
2015-06-21 09:46:12 +10:00
BLI_Stack *edge_stack;
int i, tot = 0;
BMW_init(&walker, bm, BMW_EDGERING,
BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP,
BMW_FLAG_TEST_HIDDEN,
BMW_NIL_LAY);
2015-06-21 09:46:12 +10:00
edge_stack = BLI_stack_new(sizeof(BMEdge *), __func__);
eed_last = NULL;
for (eed = eed_last = BMW_begin(&walker, lcd->eed); eed; eed = BMW_step(&walker)) {
2015-06-21 09:46:12 +10:00
BLI_stack_push(edge_stack, &eed);
}
BMW_end(&walker);
eed_start = *(BMEdge **)BLI_stack_peek(edge_stack);
2015-06-21 09:46:12 +10:00
edges = MEM_mallocN(
(sizeof(*edges) * (BLI_stack_count(edge_stack) + (eed_last != eed_start))) * previewlines, __func__);
v_last = NULL;
eed_last = NULL;
2015-06-21 09:46:12 +10:00
while (!BLI_stack_is_empty(edge_stack)) {
BLI_stack_pop(edge_stack, &eed);
if (eed_last) {
if (v_last) {
v[1][0] = v[0][0];
v[1][1] = v[0][1];
}
else {
v[1][0] = eed_last->v1;
v[1][1] = eed_last->v2;
v_last = eed_last->v1;
2009-09-16 22:27:22 +00:00
}
edgering_find_order(eed_last, eed, v_last, v);
v_last = v[0][0];
for (i = 1; i <= previewlines; i++) {
2012-12-19 04:59:47 +00:00
const float fac = (i / ((float)previewlines + 1));
float v_cos[2][2][3];
edgering_vcos_get(dm, v, v_cos);
interp_v3_v3v3(edges[tot][0], v_cos[0][0], v_cos[0][1], fac);
interp_v3_v3v3(edges[tot][1], v_cos[1][0], v_cos[1][1], fac);
2009-09-16 22:27:22 +00:00
tot++;
}
}
eed_last = eed;
2009-09-16 22:27:22 +00:00
}
2013-07-19 16:44:17 +00:00
if ((eed_last != eed_start) &&
#ifdef BMW_EDGERING_NGON
2013-07-19 16:44:17 +00:00
BM_edge_share_face_check(eed_last, eed_start)
#else
2013-07-19 16:44:17 +00:00
BM_edge_share_quad_check(eed_last, eed_start)
#endif
2013-07-19 16:44:17 +00:00
)
{
v[1][0] = v[0][0];
v[1][1] = v[0][1];
edgering_find_order(eed_last, eed_start, v_last, v);
for (i = 1; i <= previewlines; i++) {
2012-12-19 04:59:47 +00:00
const float fac = (i / ((float)previewlines + 1));
float v_cos[2][2][3];
2012-12-19 04:59:47 +00:00
if (!v[0][0] || !v[0][1] || !v[1][0] || !v[1][1]) {
continue;
2012-12-19 04:59:47 +00:00
}
edgering_vcos_get(dm, v, v_cos);
interp_v3_v3v3(edges[tot][0], v_cos[0][0], v_cos[0][1], fac);
interp_v3_v3v3(edges[tot][1], v_cos[1][0], v_cos[1][1], fac);
2009-09-16 22:27:22 +00:00
tot++;
}
}
2015-06-21 09:46:12 +10:00
BLI_stack_free(edge_stack);
2009-09-16 22:27:22 +00:00
lcd->edges = edges;
lcd->totedge = tot;
}
static void edgering_preview_calc_points(RingSelOpData *lcd, DerivedMesh *dm, const int previewlines)
{
float v_cos[2][3];
float (*points)[3];
int i, tot = 0;
if (dm) {
BM_mesh_elem_table_ensure(lcd->em->bm, BM_VERT);
}
points = MEM_mallocN(sizeof(*lcd->points) * previewlines, __func__);
edgering_vcos_get_pair(dm, &lcd->eed->v1, v_cos);
for (i = 1; i <= previewlines; i++) {
const float fac = (i / ((float)previewlines + 1));
interp_v3_v3v3(points[tot], v_cos[0], v_cos[1], fac);
tot++;
}
lcd->points = points;
lcd->totpoint = previewlines;
}
static void edgering_preview_calc(RingSelOpData *lcd, const int previewlines)
{
DerivedMesh *dm;
BLI_assert(lcd->eed != NULL);
edgering_preview_free(lcd);
dm = EDBM_mesh_deform_dm_get(lcd->em);
if (dm) {
BM_mesh_elem_table_ensure(lcd->em->bm, BM_VERT);
}
if (BM_edge_is_wire(lcd->eed)) {
edgering_preview_calc_points(lcd, dm, previewlines);
}
else {
edgering_preview_calc_edges(lcd, dm, previewlines);
}
}
static void edgering_select(RingSelOpData *lcd)
{
BMEditMesh *em = lcd->em;
BMEdge *eed_start = lcd->eed;
BMWalker walker;
BMEdge *eed;
if (!eed_start)
return;
if (!lcd->extend) {
EDBM_flag_disable_all(lcd->em, BM_ELEM_SELECT);
}
BMW_init(&walker, em->bm, BMW_EDGERING,
2014-10-03 08:09:00 +02:00
BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP,
BMW_FLAG_TEST_HIDDEN,
BMW_NIL_LAY);
for (eed = BMW_begin(&walker, eed_start); eed; eed = BMW_step(&walker)) {
BM_edge_select_set(em->bm, eed, true);
}
BMW_end(&walker);
}
static void ringsel_find_edge(RingSelOpData *lcd, const int previewlines)
2009-09-16 22:27:22 +00:00
{
if (lcd->eed) {
edgering_preview_calc(lcd, previewlines);
}
else {
edgering_preview_free(lcd);
}
2009-09-16 22:27:22 +00:00
}
static void ringsel_finish(bContext *C, wmOperator *op)
{
RingSelOpData *lcd = op->customdata;
const int cuts = RNA_int_get(op->ptr, "number_cuts");
const float smoothness = RNA_float_get(op->ptr, "smoothness");
2013-05-08 12:58:28 +00:00
const int smooth_falloff = RNA_enum_get(op->ptr, "falloff");
#ifdef BMW_EDGERING_NGON
const bool use_only_quads = false;
#else
const bool use_only_quads = false;
#endif
2009-09-16 22:27:22 +00:00
if (lcd->eed) {
2011-02-27 06:19:40 +00:00
BMEditMesh *em = lcd->em;
BMVert *v_eed_orig[2] = {lcd->eed->v1, lcd->eed->v2};
2011-02-27 06:19:40 +00:00
edgering_select(lcd);
2009-09-16 22:27:22 +00:00
if (lcd->do_cut) {
const bool is_macro = (op->opm != NULL);
/* a single edge (rare, but better support) */
const bool is_single = (BM_edge_is_wire(lcd->eed));
const int seltype = is_single ? SUBDIV_SELECT_INNER : SUBDIV_SELECT_LOOPCUT;
/* Enable gridfill, so that intersecting loopcut works as one would expect.
* Note though that it will break edgeslide in this specific case.
* See [#31939]. */
BM_mesh_esubdivide(em->bm, BM_ELEM_SELECT,
smoothness, smooth_falloff, true,
0.0f, 0.0f,
cuts, seltype, SUBD_CORNER_PATH, 0, true,
use_only_quads, 0);
/* when used in a macro the tessfaces will be recalculated anyway,
* this is needed here because modifiers depend on updated tessellation, see T45920 */
EDBM_update_generic(em, true, true);
2012-12-12 15:01:27 +00:00
if (is_single) {
/* de-select endpoints */
BM_vert_select_set(em->bm, v_eed_orig[0], false);
BM_vert_select_set(em->bm, v_eed_orig[1], false);
EDBM_selectmode_flush_ex(lcd->em, SCE_SELECT_VERTEX);
}
/* we cant slide multiple edges in vertex select mode */
else if (is_macro && (cuts > 1) && (em->selectmode & SCE_SELECT_VERTEX)) {
EDBM_selectmode_disable(lcd->vc.scene, em, SCE_SELECT_VERTEX, SCE_SELECT_EDGE);
}
/* force edge slide to edge select mode in in face select mode */
else if (EDBM_selectmode_disable(lcd->vc.scene, em, SCE_SELECT_FACE, SCE_SELECT_EDGE)) {
/* pass, the change will flush selection */
}
2012-12-12 15:01:27 +00:00
else {
/* else flush explicitly */
EDBM_selectmode_flush(lcd->em);
2012-12-12 15:01:27 +00:00
}
}
else {
/* XXX Is this piece of code ever used now? Simple loop select is now
* in editmesh_select.c (around line 1000)... */
/* sets as active, useful for other tools */
if (em->selectmode & SCE_SELECT_VERTEX)
BM_select_history_store(em->bm, lcd->eed->v1); /* low priority TODO, get vertrex close to mouse */
if (em->selectmode & SCE_SELECT_EDGE)
BM_select_history_store(em->bm, lcd->eed);
EDBM_selectmode_flush(lcd->em);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, lcd->ob->data);
2009-09-16 22:27:22 +00:00
}
}
}
/* called when modal loop selection is done... */
static void ringsel_exit(bContext *UNUSED(C), wmOperator *op)
2009-09-16 22:27:22 +00:00
{
RingSelOpData *lcd = op->customdata;
2009-09-16 22:27:22 +00:00
/* deactivate the extra drawing stuff in 3D-View */
ED_region_draw_cb_exit(lcd->ar->type, lcd->draw_handle);
edgering_preview_free(lcd);
2009-09-16 22:27:22 +00:00
ED_region_tag_redraw(lcd->ar);
/* free the custom data */
MEM_freeN(lcd);
op->customdata = NULL;
2009-09-16 22:27:22 +00:00
}
2009-09-16 22:27:22 +00:00
/* called when modal loop selection gets set up... */
static int ringsel_init(bContext *C, wmOperator *op, bool do_cut)
2009-09-16 22:27:22 +00:00
{
RingSelOpData *lcd;
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
Scene *scene = CTX_data_scene(C);
2009-09-16 22:27:22 +00:00
/* alloc new customdata */
lcd = op->customdata = MEM_callocN(sizeof(RingSelOpData), "ringsel Modal Op Data");
2009-09-16 22:27:22 +00:00
/* assign the drawing handle for drawing preview line... */
lcd->ar = CTX_wm_region(C);
lcd->draw_handle = ED_region_draw_cb_activate(lcd->ar->type, ringsel_draw, lcd, REGION_DRAW_POST_VIEW);
2009-09-16 22:27:22 +00:00
lcd->ob = CTX_data_edit_object(C);
lcd->em = BKE_editmesh_from_object(lcd->ob);
lcd->extend = do_cut ? false : RNA_boolean_get(op->ptr, "extend");
2009-09-16 22:27:22 +00:00
lcd->do_cut = do_cut;
lcd->cuts = RNA_int_get(op->ptr, "number_cuts");
lcd->smoothness = RNA_float_get(op->ptr, "smoothness");
initNumInput(&lcd->num);
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
lcd->num.idx_max = 1;
lcd->num.val_flag[0] |= NUM_NO_NEGATIVE | NUM_NO_FRACTION;
/* No specific flags for smoothness. */
lcd->num.unit_sys = scene->unit.system;
lcd->num.unit_type[0] = B_UNIT_NONE;
lcd->num.unit_type[1] = B_UNIT_NONE;
2009-09-16 22:27:22 +00:00
em_setup_viewcontext(C, &lcd->vc);
ED_region_tag_redraw(lcd->ar);
return 1;
}
static void ringcut_cancel(bContext *C, wmOperator *op)
2009-09-16 22:27:22 +00:00
{
/* this is just a wrapper around exit() */
ringsel_exit(C, op);
}
static void loopcut_update_edge(RingSelOpData *lcd, BMEdge *e, const int previewlines)
{
if (e != lcd->eed) {
lcd->eed = e;
ringsel_find_edge(lcd, previewlines);
}
}
static void loopcut_mouse_move(RingSelOpData *lcd, const int previewlines)
{
float dist = ED_view3d_select_dist_px();
BMEdge *e = EDBM_edge_find_nearest(&lcd->vc, &dist);
loopcut_update_edge(lcd, e, previewlines);
}
/* called by both init() and exec() */
static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event)
2009-09-16 22:27:22 +00:00
{
const bool is_interactive = (event != NULL);
Object *obedit = CTX_data_edit_object(C);
RingSelOpData *lcd;
2009-09-16 22:27:22 +00:00
if (modifiers_isDeformedByLattice(obedit) || modifiers_isDeformedByArmature(obedit))
BKE_report(op->reports, RPT_WARNING, "Loop cut does not work well on deformed edit mesh display");
2009-09-16 22:27:22 +00:00
view3d_operator_needs_opengl(C);
/* for re-execution, check edge index is in range before we setup ringsel */
if (is_interactive == false) {
const int e_index = RNA_int_get(op->ptr, "edge_index");
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (UNLIKELY((e_index == -1) || (e_index >= em->bm->totedge))) {
return OPERATOR_CANCELLED;
}
}
if (!ringsel_init(C, op, true))
2009-09-16 22:27:22 +00:00
return OPERATOR_CANCELLED;
2009-09-16 22:27:22 +00:00
/* add a modal handler for this operator - handles loop selection */
if (is_interactive) {
op->flag |= OP_IS_MODAL_CURSOR_REGION;
WM_event_add_modal_handler(C, op);
}
2009-09-16 22:27:22 +00:00
lcd = op->customdata;
if (is_interactive) {
copy_v2_v2_int(lcd->vc.mval, event->mval);
loopcut_mouse_move(lcd, is_interactive ? 1 : 0);
}
else {
const int e_index = RNA_int_get(op->ptr, "edge_index");
BMEdge *e;
BM_mesh_elem_table_ensure(lcd->em->bm, BM_EDGE);
e = BM_edge_at_index(lcd->em->bm, e_index);
loopcut_update_edge(lcd, e, 0);
}
#ifdef USE_LOOPSLIDE_HACK
/* for use in macro so we can restore, HACK */
{
Scene *scene = CTX_data_scene(C);
ToolSettings *settings = scene->toolsettings;
const bool mesh_select_mode[3] = {
(settings->selectmode & SCE_SELECT_VERTEX) != 0,
(settings->selectmode & SCE_SELECT_EDGE) != 0,
(settings->selectmode & SCE_SELECT_FACE) != 0,
};
RNA_boolean_set_array(op->ptr, "mesh_select_mode_init", mesh_select_mode);
}
#endif
if (is_interactive) {
ScrArea *sa = CTX_wm_area(C);
ED_area_headerprint(sa, IFACE_("Select a ring to be cut, use mouse-wheel or page-up/down for number of cuts, "
"hold Alt for smooth"));
return OPERATOR_RUNNING_MODAL;
}
else {
ringsel_finish(C, op);
ringsel_exit(C, op);
return OPERATOR_FINISHED;
}
}
static int ringcut_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
return loopcut_init(C, op, event);
}
static int loopcut_exec(bContext *C, wmOperator *op)
{
return loopcut_init(C, op, NULL);
2009-09-16 22:27:22 +00:00
}
static int loopcut_finish(RingSelOpData *lcd, bContext *C, wmOperator *op)
{
/* finish */
ED_region_tag_redraw(lcd->ar);
ED_area_headerprint(CTX_wm_area(C), NULL);
if (lcd->eed) {
/* set for redo */
BM_mesh_elem_index_ensure(lcd->em->bm, BM_EDGE);
RNA_int_set(op->ptr, "edge_index", BM_elem_index_get(lcd->eed));
/* execute */
ringsel_finish(C, op);
ringsel_exit(C, op);
}
else {
ringcut_cancel(C, op);
return OPERATOR_CANCELLED;
}
return OPERATOR_FINISHED;
}
static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event)
2009-09-16 22:27:22 +00:00
{
RingSelOpData *lcd = op->customdata;
float cuts = lcd->cuts;
float smoothness = lcd->smoothness;
bool show_cuts = false;
const bool has_numinput = hasNumInput(&lcd->num);
2009-09-16 22:27:22 +00:00
em_setup_viewcontext(C, &lcd->vc);
lcd->ar = lcd->vc.ar;
2009-09-16 22:27:22 +00:00
view3d_operator_needs_opengl(C);
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
/* using the keyboard to input the number of cuts */
/* Modal numinput active, try to handle numeric inputs first... */
if (event->val == KM_PRESS && has_numinput && handleNumInput(C, &lcd->num, event)) {
float values[2] = {cuts, smoothness};
applyNumInput(&lcd->num, values);
cuts = values[0];
smoothness = values[1];
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
}
else {
bool handled = false;
switch (event->type) {
case RETKEY:
case PADENTER:
case LEFTMOUSE: /* confirm */ // XXX hardcoded
if (event->val == KM_PRESS)
return loopcut_finish(lcd, C, op);
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
ED_region_tag_redraw(lcd->ar);
handled = true;
break;
case RIGHTMOUSE: /* abort */ // XXX hardcoded
ED_region_tag_redraw(lcd->ar);
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
ringsel_exit(C, op);
ED_area_headerprint(CTX_wm_area(C), NULL);
return OPERATOR_CANCELLED;
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
case ESCKEY:
if (event->val == KM_RELEASE) {
/* cancel */
ED_region_tag_redraw(lcd->ar);
ED_area_headerprint(CTX_wm_area(C), NULL);
ringcut_cancel(C, op);
return OPERATOR_CANCELLED;
}
ED_region_tag_redraw(lcd->ar);
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
handled = true;
break;
case MOUSEPAN:
if (event->alt == 0) {
cuts += 0.02f * (event->y - event->prevy);
if (cuts < 1 && lcd->cuts >= 1)
cuts = 1;
}
else {
smoothness += 0.002f * (event->y - event->prevy);
}
handled = true;
break;
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
case PADPLUSKEY:
case PAGEUPKEY:
case WHEELUPMOUSE: /* change number of cuts */
if (event->val == KM_RELEASE)
break;
if (event->alt == 0) {
cuts += 1;
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
}
else {
smoothness += 0.05f;
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
}
handled = true;
break;
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
case PADMINUS:
case PAGEDOWNKEY:
case WHEELDOWNMOUSE: /* change number of cuts */
if (event->val == KM_RELEASE)
break;
if (event->alt == 0) {
cuts = max_ff(cuts - 1, 1);
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
}
else {
smoothness -= 0.05f;
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
}
handled = true;
break;
case MOUSEMOVE: /* mouse moved somewhere to select another loop */
/* This is normally disabled for all modal operators.
* This is an exception since mouse movement doesn't relate to numeric input.
*
* If numeric input changes we'll need to add this back see: D2973 */
#if 0
if (!has_numinput)
#endif
{
lcd->vc.mval[0] = event->mval[0];
lcd->vc.mval[1] = event->mval[1];
loopcut_mouse_move(lcd, (int)lcd->cuts);
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
ED_region_tag_redraw(lcd->ar);
handled = true;
}
break;
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
}
/* Modal numinput inactive, try to handle numeric inputs last... */
if (!handled && event->val == KM_PRESS && handleNumInput(C, &lcd->num, event)) {
float values[2] = {cuts, smoothness};
applyNumInput(&lcd->num, values);
cuts = values[0];
smoothness = values[1];
}
}
if (cuts != lcd->cuts) {
/* allow zero so you can backspace and type in a value
* otherwise 1 as minimum would make more sense */
lcd->cuts = clamp_i(cuts, 0, SUBD_CUTS_MAX);
RNA_int_set(op->ptr, "number_cuts", (int)lcd->cuts);
ringsel_find_edge(lcd, (int)lcd->cuts);
show_cuts = true;
ED_region_tag_redraw(lcd->ar);
}
if (smoothness != lcd->smoothness) {
lcd->smoothness = clamp_f(smoothness, -SUBD_SMOOTH_MAX, SUBD_SMOOTH_MAX);
RNA_float_set(op->ptr, "smoothness", lcd->smoothness);
show_cuts = true;
ED_region_tag_redraw(lcd->ar);
}
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
if (show_cuts) {
Scene *sce = CTX_data_scene(C);
char buf[UI_MAX_DRAW_STR];
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
char str_rep[NUM_STR_REP_LEN * 2];
if (hasNumInput(&lcd->num)) {
outputNumInput(&lcd->num, str_rep, &sce->unit);
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
}
else {
BLI_snprintf(str_rep, NUM_STR_REP_LEN, "%d", (int)lcd->cuts);
Support units in modal numinput Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
2013-12-21 17:11:43 +01:00
BLI_snprintf(str_rep + NUM_STR_REP_LEN, NUM_STR_REP_LEN, "%.2f", smoothness);
}
BLI_snprintf(buf, sizeof(buf), IFACE_("Number of Cuts: %s, Smooth: %s (Alt)"),
str_rep, str_rep + NUM_STR_REP_LEN);
ED_area_headerprint(CTX_wm_area(C), buf);
}
2009-09-16 22:27:22 +00:00
/* keep going until the user confirms */
return OPERATOR_RUNNING_MODAL;
}
/* for bmesh this tool is in bmesh_select.c */
#if 0
void MESH_OT_edgering_select(wmOperatorType *ot)
{
/* description */
ot->name = "Edge Ring Select";
ot->idname = "MESH_OT_edgering_select";
ot->description = "Select an edge ring";
/* callbacks */
ot->invoke = ringsel_invoke;
ot->poll = ED_operator_editmesh_region_view3d;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
}
#endif
void MESH_OT_loopcut(wmOperatorType *ot)
2009-09-16 22:27:22 +00:00
{
PropertyRNA *prop;
2009-09-16 22:27:22 +00:00
/* description */
ot->name = "Loop Cut";
ot->idname = "MESH_OT_loopcut";
ot->description = "Add a new loop between existing loops";
2009-09-16 22:27:22 +00:00
/* callbacks */
ot->invoke = ringcut_invoke;
ot->exec = loopcut_exec;
ot->modal = loopcut_modal;
ot->cancel = ringcut_cancel;
ot->poll = ED_operator_editmesh_region_view3d;
2009-09-16 22:27:22 +00:00
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
/* properties */
prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, 1000000, "Number of Cuts", "", 1, 100);
/* 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);
prop = RNA_def_float(ot->srna, "smoothness", 0.0f, -1e3f, 1e3f,
"Smoothness", "Smoothness factor", -SUBD_SMOOTH_MAX, SUBD_SMOOTH_MAX);
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
2013-05-08 12:58:28 +00:00
prop = RNA_def_property(ot->srna, "falloff", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, rna_enum_proportional_falloff_curve_only_items);
RNA_def_property_enum_default(prop, PROP_INVSQUARE);
2013-05-08 12:58:28 +00:00
RNA_def_property_ui_text(prop, "Falloff", "Falloff type the feather");
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */
2013-05-08 12:58:28 +00:00
prop = RNA_def_int(ot->srna, "edge_index", -1, -1, INT_MAX, "Edge Index", "", 0, INT_MAX);
RNA_def_property_flag(prop, PROP_HIDDEN);
#ifdef USE_LOOPSLIDE_HACK
prop = RNA_def_boolean_array(ot->srna, "mesh_select_mode_init", 3, NULL, "", "");
RNA_def_property_flag(prop, PROP_HIDDEN);
#endif
2009-09-16 22:27:22 +00:00
}