2013-04-01 10:18:01 +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.
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2013-04-01 10:18:01 +00:00
|
|
|
|
|
|
|
#include "BKE_context.h"
|
2013-04-02 10:48:11 +00:00
|
|
|
#include "BKE_global.h"
|
2013-04-13 20:31:52 +00:00
|
|
|
#include "BKE_editmesh.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"
|
2013-04-01 10:18:01 +00:00
|
|
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2016-05-14 10:00:52 +02:00
|
|
|
#include "UI_interface.h"
|
|
|
|
|
2013-04-01 10:18:01 +00:00
|
|
|
#include "ED_mesh.h"
|
|
|
|
#include "ED_numinput.h"
|
|
|
|
#include "ED_screen.h"
|
2013-04-02 10:48:11 +00:00
|
|
|
#include "ED_space_api.h"
|
2013-04-01 10:18:01 +00:00
|
|
|
#include "ED_transform.h"
|
|
|
|
#include "ED_view3d.h"
|
|
|
|
|
|
|
|
#include "mesh_intern.h" /* own include */
|
|
|
|
|
|
|
|
|
|
|
|
#define MVAL_PIXEL_MARGIN 5.0f
|
|
|
|
|
2016-06-06 13:15:13 -04:00
|
|
|
/* until implement profile = 0 case, need to clamp somewhat above zero */
|
|
|
|
#define PROFILE_HARD_MIN 0.15f
|
|
|
|
|
2016-06-13 09:14:13 -04:00
|
|
|
#define SEGMENTS_HARD_MAX 1000
|
|
|
|
|
|
|
|
/* which value is mouse movement and numeric input controlling? */
|
|
|
|
#define OFFSET_VALUE 0
|
|
|
|
#define OFFSET_VALUE_PERCENT 1
|
|
|
|
#define PROFILE_VALUE 2
|
|
|
|
#define SEGMENTS_VALUE 3
|
|
|
|
#define NUM_VALUE_KINDS 4
|
|
|
|
|
|
|
|
static const char *value_rna_name[NUM_VALUE_KINDS] = {"offset", "offset", "profile", "segments"};
|
|
|
|
static const float value_clamp_min[NUM_VALUE_KINDS] = {0.0f, 0.0f, PROFILE_HARD_MIN, 1.0f};
|
|
|
|
static const float value_clamp_max[NUM_VALUE_KINDS] = {1e6, 100.0f, 1.0f, SEGMENTS_HARD_MAX};
|
|
|
|
static const float value_start[NUM_VALUE_KINDS] = {0.0f, 0.0f, 0.5f, 1.0f};
|
|
|
|
static const float value_scale_per_inch[NUM_VALUE_KINDS] = { 0.0f, 100.0f, 1.0f, 4.0f};
|
|
|
|
|
2013-04-01 10:18:01 +00:00
|
|
|
typedef struct {
|
|
|
|
BMEditMesh *em;
|
2016-06-13 09:14:13 -04:00
|
|
|
float initial_length[NUM_VALUE_KINDS];
|
|
|
|
float scale[NUM_VALUE_KINDS];
|
|
|
|
NumInput num_input[NUM_VALUE_KINDS];
|
|
|
|
float shift_value[NUM_VALUE_KINDS]; /* The current value when shift is pressed. Negative when shift not active. */
|
2013-04-02 10:48:11 +00:00
|
|
|
bool is_modal;
|
|
|
|
|
|
|
|
/* modal only */
|
2013-10-12 03:42:06 +00:00
|
|
|
float mcenter[2];
|
2013-04-02 10:48:11 +00:00
|
|
|
BMBackup mesh_backup;
|
|
|
|
void *draw_handle_pixel;
|
|
|
|
short twtype;
|
2016-06-13 09:14:13 -04:00
|
|
|
short value_mode; /* Which value does mouse movement and numeric input affect? */
|
2016-05-08 18:14:44 +02:00
|
|
|
float segments; /* Segments as float so smooth mouse pan works in small increments */
|
2013-04-01 10:18:01 +00:00
|
|
|
} BevelData;
|
|
|
|
|
2014-08-25 20:18:43 +02:00
|
|
|
static void edbm_bevel_update_header(bContext *C, wmOperator *op)
|
2013-04-01 10:18:01 +00:00
|
|
|
{
|
2014-10-08 16:41:00 +02:00
|
|
|
const char *str = IFACE_("Confirm: (Enter/LMB), Cancel: (Esc/RMB), Mode: %s (M), Clamp Overlap: %s (C), "
|
2016-06-13 09:14:13 -04:00
|
|
|
"Vertex Only: %s (V), Profile Control: %s (P), Offset: %s, Segments: %d, Profile: %.3f");
|
2013-04-01 10:18:01 +00:00
|
|
|
|
2016-05-14 10:00:52 +02:00
|
|
|
char msg[UI_MAX_DRAW_STR];
|
2013-04-01 10:18:01 +00:00
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2014-06-30 10:57:39 +02:00
|
|
|
Scene *sce = CTX_data_scene(C);
|
2013-04-01 10:18:01 +00:00
|
|
|
|
|
|
|
if (sa) {
|
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
|
|
|
BevelData *opdata = op->customdata;
|
2013-04-01 10:18:01 +00:00
|
|
|
char offset_str[NUM_STR_REP_LEN];
|
2014-08-25 16:31:47 +02:00
|
|
|
const char *type_str;
|
|
|
|
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset_type");
|
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
|
|
|
|
2016-06-13 09:14:13 -04:00
|
|
|
if (hasNumInput(&opdata->num_input[OFFSET_VALUE])) {
|
|
|
|
outputNumInput(&opdata->num_input[OFFSET_VALUE], offset_str, &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(offset_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "offset"));
|
|
|
|
}
|
|
|
|
|
2014-08-25 16:31:47 +02:00
|
|
|
RNA_property_enum_name_gettexted(C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &type_str);
|
|
|
|
|
2016-05-14 10:00:52 +02:00
|
|
|
BLI_snprintf(msg, sizeof(msg), str, type_str,
|
2014-10-08 16:41:00 +02:00
|
|
|
WM_bool_as_string(RNA_boolean_get(op->ptr, "clamp_overlap")),
|
2015-12-23 22:37:24 +11:00
|
|
|
WM_bool_as_string(RNA_boolean_get(op->ptr, "vertex_only")),
|
2016-06-13 09:14:13 -04:00
|
|
|
WM_bool_as_string(opdata->value_mode == PROFILE_VALUE),
|
|
|
|
offset_str, RNA_int_get(op->ptr, "segments"), RNA_float_get(op->ptr, "profile"));
|
2013-04-01 10:18:01 +00:00
|
|
|
|
|
|
|
ED_area_headerprint(sa, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-08 10:03:51 +00:00
|
|
|
static bool edbm_bevel_init(bContext *C, wmOperator *op, const bool is_modal)
|
2013-04-01 10:18:01 +00:00
|
|
|
{
|
|
|
|
Object *obedit = CTX_data_edit_object(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
|
|
|
Scene *scene = CTX_data_scene(C);
|
2013-04-16 05:59:48 +00:00
|
|
|
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
2013-04-01 10:18:01 +00:00
|
|
|
BevelData *opdata;
|
2016-06-13 09:14:13 -04:00
|
|
|
float pixels_per_inch;
|
|
|
|
int i;
|
2013-04-01 10:18:01 +00:00
|
|
|
|
2013-04-08 02:14:58 +00:00
|
|
|
if (em->bm->totvertsel == 0) {
|
2013-04-08 10:03:51 +00:00
|
|
|
return false;
|
2013-04-01 10:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
op->customdata = opdata = MEM_mallocN(sizeof(BevelData), "beveldata_mesh_operator");
|
|
|
|
|
|
|
|
opdata->em = em;
|
|
|
|
opdata->is_modal = is_modal;
|
2016-06-13 09:14:13 -04:00
|
|
|
opdata->value_mode = OFFSET_VALUE;
|
|
|
|
pixels_per_inch = U.dpi * U.pixelsize;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_VALUE_KINDS; i++) {
|
|
|
|
opdata->shift_value[i] = -1.0f;
|
|
|
|
/* note: scale for OFFSET_VALUE will get overwritten in edbm_bevel_invoke */
|
|
|
|
opdata->scale[i] = value_scale_per_inch[i] / pixels_per_inch;
|
|
|
|
|
|
|
|
initNumInput(&opdata->num_input[i]);
|
|
|
|
opdata->num_input[i].idx_max = 0;
|
|
|
|
opdata->num_input[i].val_flag[0] |= NUM_NO_NEGATIVE;
|
|
|
|
if (i == SEGMENTS_VALUE) {
|
|
|
|
opdata->num_input[i].val_flag[0] |= NUM_NO_FRACTION | NUM_NO_ZERO;
|
|
|
|
}
|
|
|
|
if (i == OFFSET_VALUE) {
|
|
|
|
opdata->num_input[i].unit_sys = scene->unit.system;
|
|
|
|
}
|
|
|
|
opdata->num_input[i].unit_type[0] = B_UNIT_NONE; /* Not sure this is a factor or a unit? */
|
|
|
|
}
|
2013-04-01 10:18:01 +00:00
|
|
|
|
|
|
|
/* avoid the cost of allocating a bm copy */
|
2013-04-02 10:48:11 +00:00
|
|
|
if (is_modal) {
|
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
|
2013-04-01 10:18:01 +00:00
|
|
|
opdata->mesh_backup = EDBM_redo_state_store(em);
|
2016-06-13 09:14:13 -04:00
|
|
|
opdata->draw_handle_pixel = ED_region_draw_cb_activate(ar->type, ED_region_draw_mouse_line_cb,
|
|
|
|
opdata->mcenter, REGION_DRAW_POST_PIXEL);
|
2013-06-24 22:41:37 +00:00
|
|
|
G.moving = G_TRANSFORM_EDIT;
|
2016-04-29 00:00:43 +10:00
|
|
|
|
|
|
|
if (v3d) {
|
|
|
|
opdata->twtype = v3d->twtype;
|
|
|
|
v3d->twtype = 0;
|
|
|
|
}
|
2013-04-02 10:48:11 +00:00
|
|
|
}
|
2013-04-01 10:18:01 +00:00
|
|
|
|
2013-04-08 10:03:51 +00:00
|
|
|
return true;
|
2013-04-01 10:18:01 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 10:03:51 +00:00
|
|
|
static bool edbm_bevel_calc(wmOperator *op)
|
2013-04-01 10:18:01 +00:00
|
|
|
{
|
|
|
|
BevelData *opdata = op->customdata;
|
|
|
|
BMEditMesh *em = opdata->em;
|
|
|
|
BMOperator bmop;
|
|
|
|
const float offset = RNA_float_get(op->ptr, "offset");
|
2013-11-10 12:31:57 +00:00
|
|
|
const int offset_type = RNA_enum_get(op->ptr, "offset_type");
|
2013-04-01 10:18:01 +00:00
|
|
|
const int segments = RNA_int_get(op->ptr, "segments");
|
2014-01-08 07:40:01 -05:00
|
|
|
const float profile = RNA_float_get(op->ptr, "profile");
|
2013-04-01 10:18:01 +00:00
|
|
|
const bool vertex_only = RNA_boolean_get(op->ptr, "vertex_only");
|
2014-10-08 16:41:00 +02:00
|
|
|
const bool clamp_overlap = RNA_boolean_get(op->ptr, "clamp_overlap");
|
2014-07-17 09:20:22 -04:00
|
|
|
int material = RNA_int_get(op->ptr, "material");
|
2015-07-05 09:53:17 -04:00
|
|
|
const bool loop_slide = RNA_boolean_get(op->ptr, "loop_slide");
|
2013-04-01 10:18:01 +00:00
|
|
|
|
|
|
|
/* revert to original mesh */
|
|
|
|
if (opdata->is_modal) {
|
|
|
|
EDBM_redo_state_restore(opdata->mesh_backup, em, false);
|
|
|
|
}
|
|
|
|
|
2016-06-13 09:14:13 -04:00
|
|
|
if (em->ob) {
|
2014-07-17 09:20:22 -04:00
|
|
|
material = CLAMPIS(material, -1, em->ob->totcol - 1);
|
2016-06-13 09:14:13 -04:00
|
|
|
}
|
2014-07-17 09:20:22 -04:00
|
|
|
|
2013-04-08 10:03:51 +00:00
|
|
|
EDBM_op_init(em, &bmop, op,
|
2014-10-08 16:41:00 +02:00
|
|
|
"bevel geom=%hev offset=%f segments=%i vertex_only=%b offset_type=%i profile=%f clamp_overlap=%b "
|
2015-07-05 09:53:17 -04:00
|
|
|
"material=%i loop_slide=%b",
|
2016-06-13 09:14:13 -04:00
|
|
|
BM_ELEM_SELECT, offset, segments, vertex_only, offset_type, profile,
|
|
|
|
clamp_overlap, material, loop_slide);
|
2013-04-01 10:18:01 +00:00
|
|
|
|
|
|
|
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 */
|
2016-06-13 09:14:13 -04:00
|
|
|
if (!EDBM_op_finish(em, &bmop, op, true)) {
|
2013-04-08 10:03:51 +00:00
|
|
|
return false;
|
2016-06-13 09:14:13 -04:00
|
|
|
}
|
2013-04-01 10:18:01 +00:00
|
|
|
|
|
|
|
EDBM_mesh_normals_update(opdata->em);
|
|
|
|
|
|
|
|
EDBM_update_generic(opdata->em, true, true);
|
|
|
|
|
2013-04-08 10:03:51 +00:00
|
|
|
return true;
|
2013-04-01 10:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2013-04-02 10:48:11 +00:00
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2013-04-01 10:18:01 +00:00
|
|
|
EDBM_redo_state_free(&opdata->mesh_backup, NULL, false);
|
2013-04-02 10:48:11 +00:00
|
|
|
ED_region_draw_cb_exit(ar->type, opdata->draw_handle_pixel);
|
2016-04-29 00:00:43 +10:00
|
|
|
if (v3d) {
|
|
|
|
v3d->twtype = opdata->twtype;
|
|
|
|
}
|
2013-06-24 22:41:37 +00:00
|
|
|
G.moving = 0;
|
2013-04-01 10:18:01 +00:00
|
|
|
}
|
|
|
|
MEM_freeN(opdata);
|
|
|
|
op->customdata = NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-30 23:08:53 +00:00
|
|
|
static void edbm_bevel_cancel(bContext *C, wmOperator *op)
|
2013-04-01 10:18:01 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bevel! yay!!*/
|
|
|
|
static int edbm_bevel_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
if (!edbm_bevel_init(C, op, false)) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!edbm_bevel_calc(op)) {
|
|
|
|
edbm_bevel_cancel(C, op);
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
edbm_bevel_exit(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2016-06-13 09:14:13 -04:00
|
|
|
static void edbm_bevel_calc_initial_length(wmOperator *op, const wmEvent *event, bool mode_changed)
|
|
|
|
{
|
|
|
|
BevelData *opdata;
|
|
|
|
float mlen[2], len, value, sc, st;
|
|
|
|
int vmode;
|
|
|
|
|
|
|
|
opdata = op->customdata;
|
|
|
|
mlen[0] = opdata->mcenter[0] - event->mval[0];
|
|
|
|
mlen[1] = opdata->mcenter[1] - event->mval[1];
|
|
|
|
len = len_v2(mlen);
|
|
|
|
vmode = opdata->value_mode;
|
|
|
|
if (mode_changed) {
|
|
|
|
/* If current value is not default start value, adjust len so that
|
|
|
|
* the scaling and offset in edbm_bevel_mouse_set_value will
|
|
|
|
* start at current value */
|
|
|
|
value = (vmode == SEGMENTS_VALUE) ?
|
|
|
|
opdata->segments : RNA_float_get(op->ptr, value_rna_name[vmode]);
|
|
|
|
sc = opdata->scale[vmode];
|
|
|
|
st = value_start[vmode];
|
|
|
|
if (value != value_start[vmode]) {
|
|
|
|
len = (st + sc * (len - MVAL_PIXEL_MARGIN) - value) / sc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
opdata->initial_length[opdata->value_mode] = len;
|
|
|
|
}
|
|
|
|
|
2013-04-01 10:18:01 +00:00
|
|
|
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 center_3d[3];
|
|
|
|
|
|
|
|
if (!edbm_bevel_init(C, op, true)) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
opdata = op->customdata;
|
|
|
|
|
|
|
|
/* initialize mouse values */
|
2015-12-01 18:52:24 +11:00
|
|
|
if (!calculateTransformCenter(C, V3D_AROUND_CENTER_MEAN, center_3d, opdata->mcenter)) {
|
2013-04-01 10:18:01 +00:00
|
|
|
/* 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;
|
|
|
|
}
|
2016-06-13 09:14:13 -04:00
|
|
|
edbm_bevel_calc_initial_length(op, event, false);
|
|
|
|
|
|
|
|
/* for OFFSET_VALUE only, the scale is the size of a pixel under the mouse in 3d space */
|
|
|
|
opdata->scale[OFFSET_VALUE] = rv3d ? ED_view3d_pixel_size(rv3d, center_3d) : 1.0f;
|
2013-04-01 10:18:01 +00:00
|
|
|
|
2014-08-25 20:18:43 +02:00
|
|
|
edbm_bevel_update_header(C, op);
|
2013-04-01 10:18:01 +00:00
|
|
|
|
|
|
|
if (!edbm_bevel_calc(op)) {
|
|
|
|
edbm_bevel_cancel(C, op);
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
2016-06-13 09:14:13 -04:00
|
|
|
static void edbm_bevel_mouse_set_value(wmOperator *op, const wmEvent *event)
|
2013-04-01 10:18:01 +00:00
|
|
|
{
|
|
|
|
BevelData *opdata = op->customdata;
|
2016-06-13 09:14:13 -04:00
|
|
|
int vmode = opdata->value_mode;
|
2013-04-01 10:18:01 +00:00
|
|
|
float mdiff[2];
|
2016-06-13 09:14:13 -04:00
|
|
|
float value;
|
2013-04-01 10:18:01 +00:00
|
|
|
|
|
|
|
mdiff[0] = opdata->mcenter[0] - event->mval[0];
|
|
|
|
mdiff[1] = opdata->mcenter[1] - event->mval[1];
|
|
|
|
|
2016-06-13 09:14:13 -04:00
|
|
|
value = ((len_v2(mdiff) - MVAL_PIXEL_MARGIN) - opdata->initial_length[vmode]);
|
|
|
|
|
|
|
|
/* Scale according to value mode */
|
|
|
|
value = value_start[vmode] + value * opdata->scale[vmode];
|
2013-04-01 10:18:01 +00:00
|
|
|
|
|
|
|
/* Fake shift-transform... */
|
|
|
|
if (event->shift) {
|
2016-06-13 09:14:13 -04:00
|
|
|
if (opdata->shift_value[vmode] < 0.0f) {
|
|
|
|
opdata->shift_value[vmode] = (vmode == SEGMENTS_VALUE) ?
|
|
|
|
opdata->segments : RNA_float_get(op->ptr, value_rna_name[vmode]);
|
2013-04-01 10:18:01 +00:00
|
|
|
}
|
2016-06-13 09:14:13 -04:00
|
|
|
value = (value - opdata->shift_value[vmode]) * 0.1f + opdata->shift_value[vmode];
|
2013-04-01 10:18:01 +00:00
|
|
|
}
|
2016-06-13 09:14:13 -04:00
|
|
|
else if (opdata->shift_value[vmode] >= 0.0f) {
|
|
|
|
opdata->shift_value[vmode] = -1.0f;
|
2014-08-25 16:31:47 +02:00
|
|
|
}
|
2013-04-01 10:18:01 +00:00
|
|
|
|
2016-06-13 09:14:13 -04:00
|
|
|
/* clamp accordingto value mode, and store value back */
|
|
|
|
CLAMP(value, value_clamp_min[vmode], value_clamp_max[vmode]);
|
|
|
|
if (vmode == SEGMENTS_VALUE) {
|
|
|
|
opdata->segments = value;
|
|
|
|
RNA_int_set(op->ptr, "segments", (int)(value + 0.5f));
|
2013-04-01 10:18:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-06-13 09:14:13 -04:00
|
|
|
RNA_float_set(op->ptr, value_rna_name[vmode], value);
|
2013-04-01 10:18:01 +00:00
|
|
|
}
|
2016-06-13 09:14:13 -04:00
|
|
|
}
|
2013-04-01 10:18:01 +00:00
|
|
|
|
2016-06-13 09:14:13 -04:00
|
|
|
static void edbm_bevel_numinput_set_value(wmOperator *op)
|
|
|
|
{
|
|
|
|
BevelData *opdata = op->customdata;
|
|
|
|
float value;
|
|
|
|
int vmode;
|
|
|
|
|
|
|
|
vmode = opdata->value_mode;
|
|
|
|
value = (vmode == SEGMENTS_VALUE) ?
|
|
|
|
opdata->segments : RNA_float_get(op->ptr, value_rna_name[vmode]);
|
|
|
|
applyNumInput(&opdata->num_input[vmode], &value);
|
|
|
|
CLAMP(value, value_clamp_min[vmode], value_clamp_max[vmode]);
|
|
|
|
if (vmode == SEGMENTS_VALUE) {
|
|
|
|
opdata->segments = value;
|
|
|
|
RNA_int_set(op->ptr, "segments", (int)value);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
RNA_float_set(op->ptr, value_rna_name[vmode], value);
|
|
|
|
}
|
2013-04-01 10:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
{
|
|
|
|
BevelData *opdata = op->customdata;
|
2016-06-13 09:14:13 -04:00
|
|
|
const bool has_numinput = hasNumInput(&opdata->num_input[opdata->value_mode]);
|
2014-08-25 16:31:47 +02:00
|
|
|
|
|
|
|
/* Modal numinput active, try to handle numeric inputs first... */
|
2016-06-13 09:14:13 -04:00
|
|
|
if (event->val == KM_PRESS && has_numinput && handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) {
|
|
|
|
edbm_bevel_numinput_set_value(op);
|
2014-08-25 16:31:47 +02:00
|
|
|
edbm_bevel_calc(op);
|
2014-08-25 20:18:43 +02:00
|
|
|
edbm_bevel_update_header(C, op);
|
2014-08-25 16:31:47 +02:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2013-04-01 10:18:01 +00:00
|
|
|
}
|
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 ESCKEY:
|
|
|
|
case RIGHTMOUSE:
|
|
|
|
edbm_bevel_cancel(C, op);
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
case MOUSEMOVE:
|
2014-08-25 16:31:47 +02:00
|
|
|
if (!has_numinput) {
|
2016-06-13 09:14:13 -04:00
|
|
|
edbm_bevel_mouse_set_value(op, event);
|
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
|
|
|
edbm_bevel_calc(op);
|
2014-08-25 20:18:43 +02:00
|
|
|
edbm_bevel_update_header(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
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LEFTMOUSE:
|
|
|
|
case PADENTER:
|
|
|
|
case RETKEY:
|
2016-03-25 12:21:54 +01:00
|
|
|
if (event->val == KM_PRESS) {
|
|
|
|
edbm_bevel_calc(op);
|
|
|
|
edbm_bevel_exit(C, op);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
break;
|
2013-04-01 10:18:01 +00:00
|
|
|
|
2016-05-08 18:14:44 +02:00
|
|
|
case MOUSEPAN: {
|
|
|
|
float delta = 0.02f * (event->y - event->prevy);
|
|
|
|
if (opdata->segments >= 1 && opdata->segments + delta < 1)
|
|
|
|
opdata->segments = 1;
|
|
|
|
else
|
|
|
|
opdata->segments += delta;
|
|
|
|
RNA_int_set(op->ptr, "segments", (int)opdata->segments);
|
|
|
|
edbm_bevel_calc(op);
|
|
|
|
edbm_bevel_update_header(C, op);
|
|
|
|
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
|
|
|
/* Note this will prevent padplus and padminus to ever activate modal numinput.
|
|
|
|
* This is not really an issue though, as we only expect positive values here...
|
|
|
|
* Else we could force them to only modify segments number when shift is pressed, or so.
|
|
|
|
*/
|
2013-04-01 10:18:01 +00:00
|
|
|
|
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 WHEELUPMOUSE: /* change number of segments */
|
|
|
|
case PADPLUSKEY:
|
|
|
|
if (event->val == KM_RELEASE)
|
|
|
|
break;
|
2013-04-01 10:18:01 +00:00
|
|
|
|
2016-05-08 18:14:44 +02:00
|
|
|
opdata->segments = opdata->segments + 1;
|
|
|
|
RNA_int_set(op->ptr, "segments", (int)opdata->segments);
|
2013-04-01 10:18:01 +00:00
|
|
|
edbm_bevel_calc(op);
|
2014-08-25 20:18:43 +02:00
|
|
|
edbm_bevel_update_header(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
|
|
|
handled = true;
|
2013-04-01 10:18:01 +00:00
|
|
|
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 WHEELDOWNMOUSE: /* change number of segments */
|
|
|
|
case PADMINUS:
|
|
|
|
if (event->val == KM_RELEASE)
|
|
|
|
break;
|
2013-04-01 10:18:01 +00:00
|
|
|
|
2016-05-08 18:14:44 +02:00
|
|
|
opdata->segments = max_ff(opdata->segments - 1, 1);
|
|
|
|
RNA_int_set(op->ptr, "segments", (int)opdata->segments);
|
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
|
|
|
edbm_bevel_calc(op);
|
2014-08-25 20:18:43 +02:00
|
|
|
edbm_bevel_update_header(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
|
|
|
handled = true;
|
2013-04-01 10:18:01 +00:00
|
|
|
break;
|
|
|
|
|
2014-08-25 16:31:47 +02:00
|
|
|
case MKEY:
|
|
|
|
if (event->val == KM_RELEASE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
{
|
|
|
|
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset_type");
|
|
|
|
int type = RNA_property_enum_get(op->ptr, prop);
|
|
|
|
type++;
|
|
|
|
if (type > BEVEL_AMT_PERCENT) {
|
|
|
|
type = BEVEL_AMT_OFFSET;
|
|
|
|
}
|
2016-06-13 09:14:13 -04:00
|
|
|
if (opdata->value_mode == OFFSET_VALUE && type == BEVEL_AMT_PERCENT)
|
|
|
|
opdata->value_mode = OFFSET_VALUE_PERCENT;
|
|
|
|
else if (opdata->value_mode == OFFSET_VALUE_PERCENT && type != BEVEL_AMT_PERCENT)
|
|
|
|
opdata->value_mode = OFFSET_VALUE;
|
2014-08-25 16:31:47 +02:00
|
|
|
RNA_property_enum_set(op->ptr, prop, type);
|
|
|
|
}
|
2016-06-13 09:14:13 -04:00
|
|
|
/* Update offset accordingly to new offset_type. */
|
|
|
|
if (!has_numinput &&
|
|
|
|
(opdata->value_mode == OFFSET_VALUE || opdata->value_mode == OFFSET_VALUE_PERCENT))
|
|
|
|
{
|
|
|
|
edbm_bevel_mouse_set_value(op, event);
|
|
|
|
}
|
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
|
|
|
edbm_bevel_calc(op);
|
2014-08-25 20:18:43 +02:00
|
|
|
edbm_bevel_update_header(C, op);
|
2014-08-25 16:31:47 +02:00
|
|
|
handled = true;
|
|
|
|
break;
|
2014-10-08 16:41:00 +02:00
|
|
|
case CKEY:
|
|
|
|
if (event->val == KM_RELEASE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
{
|
|
|
|
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "clamp_overlap");
|
2015-12-23 22:37:24 +11:00
|
|
|
RNA_property_boolean_set(op->ptr, prop, !RNA_property_boolean_get(op->ptr, prop));
|
2014-10-08 16:41:00 +02:00
|
|
|
}
|
|
|
|
edbm_bevel_calc(op);
|
|
|
|
edbm_bevel_update_header(C, op);
|
|
|
|
handled = true;
|
|
|
|
break;
|
2016-06-06 13:15:13 -04:00
|
|
|
case PKEY:
|
|
|
|
if (event->val == KM_RELEASE)
|
|
|
|
break;
|
2016-06-13 09:14:13 -04:00
|
|
|
if (opdata->value_mode == PROFILE_VALUE) {
|
|
|
|
opdata->value_mode = OFFSET_VALUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
opdata->value_mode = PROFILE_VALUE;
|
|
|
|
}
|
|
|
|
edbm_bevel_calc_initial_length(op, event, true);
|
|
|
|
break;
|
|
|
|
case SKEY:
|
|
|
|
if (event->val == KM_RELEASE)
|
|
|
|
break;
|
|
|
|
if (opdata->value_mode == SEGMENTS_VALUE) {
|
|
|
|
opdata->value_mode = OFFSET_VALUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
opdata->value_mode = SEGMENTS_VALUE;
|
|
|
|
}
|
|
|
|
edbm_bevel_calc_initial_length(op, event, true);
|
2016-06-06 13:15:13 -04:00
|
|
|
break;
|
2015-07-04 10:14:47 -04:00
|
|
|
case VKEY:
|
|
|
|
if (event->val == KM_RELEASE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
{
|
|
|
|
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "vertex_only");
|
2015-12-23 22:37:24 +11:00
|
|
|
RNA_property_boolean_set(op->ptr, prop, !RNA_property_boolean_get(op->ptr, prop));
|
2015-07-04 10:14:47 -04:00
|
|
|
}
|
|
|
|
edbm_bevel_calc(op);
|
|
|
|
edbm_bevel_update_header(C, op);
|
|
|
|
handled = true;
|
|
|
|
break;
|
|
|
|
|
2014-08-25 16:31:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Modal numinput inactive, try to handle numeric inputs last... */
|
2016-06-13 09:14:13 -04:00
|
|
|
if (!handled && event->val == KM_PRESS && handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) {
|
|
|
|
edbm_bevel_numinput_set_value(op);
|
2014-08-25 16:31:47 +02:00
|
|
|
edbm_bevel_calc(op);
|
2014-08-25 20:18:43 +02:00
|
|
|
edbm_bevel_update_header(C, op);
|
2014-08-25 16:31:47 +02:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
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
|
|
|
}
|
2013-04-01 10:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
2014-06-16 09:03:26 +02:00
|
|
|
static void mesh_ot_bevel_offset_range_func(PointerRNA *ptr, PropertyRNA *UNUSED(prop),
|
|
|
|
float *min, float *max, float *softmin, float *softmax)
|
|
|
|
{
|
|
|
|
const int offset_type = RNA_enum_get(ptr, "offset_type");
|
|
|
|
|
|
|
|
*min = -FLT_MAX;
|
|
|
|
*max = FLT_MAX;
|
|
|
|
*softmin = 0.0f;
|
|
|
|
*softmax = (offset_type == BEVEL_AMT_PERCENT) ? 100.0f : 1.0f;
|
|
|
|
}
|
|
|
|
|
2013-04-01 10:18:01 +00:00
|
|
|
void MESH_OT_bevel(wmOperatorType *ot)
|
|
|
|
{
|
2014-06-16 09:03:26 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2013-11-10 12:31:57 +00:00
|
|
|
static EnumPropertyItem offset_type_items[] = {
|
|
|
|
{BEVEL_AMT_OFFSET, "OFFSET", 0, "Offset", "Amount is offset of new edges from original"},
|
|
|
|
{BEVEL_AMT_WIDTH, "WIDTH", 0, "Width", "Amount is width of new face"},
|
|
|
|
{BEVEL_AMT_DEPTH, "DEPTH", 0, "Depth", "Amount is perpendicular distance from original edge to bevel face"},
|
|
|
|
{BEVEL_AMT_PERCENT, "PERCENT", 0, "Percent", "Amount is percent of adjacent edge length"},
|
|
|
|
{0, NULL, 0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
2013-04-01 10:18:01 +00:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Bevel";
|
|
|
|
ot->description = "Edge Bevel";
|
|
|
|
ot->idname = "MESH_OT_bevel";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = edbm_bevel_exec;
|
|
|
|
ot->invoke = edbm_bevel_invoke;
|
|
|
|
ot->modal = edbm_bevel_modal;
|
|
|
|
ot->cancel = edbm_bevel_cancel;
|
|
|
|
ot->poll = ED_operator_editmesh;
|
|
|
|
|
|
|
|
/* flags */
|
2015-04-27 18:44:27 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_GRAB_CURSOR | OPTYPE_BLOCKING;
|
2013-04-01 10:18:01 +00:00
|
|
|
|
2013-11-10 12:31:57 +00:00
|
|
|
RNA_def_enum(ot->srna, "offset_type", offset_type_items, 0, "Amount Type", "What distance Amount measures");
|
2015-06-21 21:56:35 +02:00
|
|
|
prop = RNA_def_float(ot->srna, "offset", 0.0f, -1e6f, 1e6f, "Amount", "", 0.0f, 1.0f);
|
2014-06-16 09:03:26 +02:00
|
|
|
RNA_def_property_float_array_funcs_runtime(prop, NULL, NULL, mesh_ot_bevel_offset_range_func);
|
2016-06-13 09:14:13 -04:00
|
|
|
RNA_def_int(ot->srna, "segments", 1, 1, SEGMENTS_HARD_MAX, "Segments", "Segments for curved edge", 1, 8);
|
2016-06-06 13:15:13 -04:00
|
|
|
RNA_def_float(ot->srna, "profile", 0.5f, PROFILE_HARD_MIN, 1.0f, "Profile",
|
2016-06-13 09:14:13 -04:00
|
|
|
"Controls profile shape (0.5 = round)", PROFILE_HARD_MIN, 1.0f);
|
2014-10-08 16:41:00 +02:00
|
|
|
RNA_def_boolean(ot->srna, "vertex_only", false, "Vertex Only", "Bevel only vertices");
|
|
|
|
RNA_def_boolean(ot->srna, "clamp_overlap", false, "Clamp Overlap",
|
2016-06-13 09:14:13 -04:00
|
|
|
"Do not allow beveled edges/vertices to overlap each other");
|
2015-07-05 13:31:26 -04:00
|
|
|
RNA_def_boolean(ot->srna, "loop_slide", true, "Loop Slide", "Prefer slide along edge to even widths");
|
2016-06-13 09:14:13 -04:00
|
|
|
RNA_def_int(ot->srna, "material", -1, -1, INT_MAX, "Material",
|
|
|
|
"Material for bevel faces (-1 means use adjacent faces)", -1, 100);
|
2013-04-01 10:18:01 +00:00
|
|
|
}
|