Blender  V3.3
transform_mode_shrink_fatten.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include <stdlib.h>
9 
10 #include "BLI_math.h"
11 #include "BLI_string.h"
12 #include "BLI_task.h"
13 
14 #include "BKE_context.h"
15 #include "BKE_unit.h"
16 
17 #include "ED_screen.h"
18 
19 #include "WM_api.h"
20 #include "WM_types.h"
21 
22 #include "UI_interface.h"
23 
24 #include "BLT_translation.h"
25 
26 #include "transform.h"
27 #include "transform_convert.h"
28 #include "transform_snap.h"
29 
30 #include "transform_mode.h"
31 
32 /* -------------------------------------------------------------------- */
40  const TransInfo *t;
42  float distance;
43 };
44 
46  const TransDataContainer *UNUSED(tc),
47  TransData *td,
48  const float distance)
49 {
50  /* Get the final offset. */
51  float tdistance = distance * td->factor;
52  if (td->ext && (t->flag & T_ALT_TRANSFORM) != 0) {
53  tdistance *= td->ext->isize[0]; /* shell factor */
54  }
55 
56  madd_v3_v3v3fl(td->loc, td->iloc, td->axismtx[2], tdistance);
57 }
58 
59 static void transdata_elem_shrink_fatten_fn(void *__restrict iter_data_v,
60  const int iter,
61  const TaskParallelTLS *__restrict UNUSED(tls))
62 {
63  struct TransDataArgs_ShrinkFatten *data = iter_data_v;
64  TransData *td = &data->tc->data[iter];
65  if (td->flag & TD_SKIP) {
66  return;
67  }
68  transdata_elem_shrink_fatten(data->t, data->tc, td, data->distance);
69 }
70 
73 /* -------------------------------------------------------------------- */
78 {
79  BLI_assert(t->mode == TFM_SHRINKFATTEN);
80  const wmKeyMapItem *kmi = t->custom.mode.data;
81  if (kmi && event->type == kmi->type && event->val == kmi->val) {
82  /* Allows the "Even Thickness" effect to be enabled as a toggle. */
83  t->flag ^= T_ALT_TRANSFORM;
84  return TREDRAW_HARD;
85  }
86  return TREDRAW_NOTHING;
87 }
88 
89 static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
90 {
91  float distance;
92  int i;
93  char str[UI_MAX_DRAW_STR];
94  size_t ofs = 0;
95  UnitSettings *unit = &t->scene->unit;
96 
97  distance = t->values[0] + t->values_modal_offset[0];
98 
100 
101  applyNumInput(&t->num, &distance);
102 
103  t->values_final[0] = distance;
104 
105  /* header print for NumInput */
106  ofs += BLI_strncpy_rlen(str + ofs, TIP_("Shrink/Fatten: "), sizeof(str) - ofs);
107  if (hasNumInput(&t->num)) {
108  char c[NUM_STR_REP_LEN];
109  outputNumInput(&(t->num), c, unit);
110  ofs += BLI_snprintf_rlen(str + ofs, sizeof(str) - ofs, "%s", c);
111  }
112  else {
113  /* default header print */
114  if (unit != NULL) {
115  ofs += BKE_unit_value_as_string(str + ofs,
116  sizeof(str) - ofs,
117  distance * unit->scale_length,
118  4,
120  unit,
121  true);
122  }
123  else {
124  ofs += BLI_snprintf_rlen(str + ofs, sizeof(str) - ofs, "%.4f", distance);
125  }
126  }
127 
128  if (t->proptext[0]) {
129  ofs += BLI_snprintf_rlen(str + ofs, sizeof(str) - ofs, " %s", t->proptext);
130  }
131  ofs += BLI_strncpy_rlen(str + ofs, ", (", sizeof(str) - ofs);
132 
133  const wmKeyMapItem *kmi = t->custom.mode.data;
134  if (kmi) {
135  ofs += WM_keymap_item_to_string(kmi, false, str + ofs, sizeof(str) - ofs);
136  }
137 
138  BLI_snprintf(str + ofs,
139  sizeof(str) - ofs,
140  TIP_(" or Alt) Even Thickness %s"),
141  WM_bool_as_string((t->flag & T_ALT_TRANSFORM) != 0));
142  /* done with header string */
143 
146  TransData *td = tc->data;
147  for (i = 0; i < tc->data_len; i++, td++) {
148  if (td->flag & TD_SKIP) {
149  continue;
150  }
152  }
153  }
154  else {
156  .t = t,
157  .tc = tc,
158  .distance = distance,
159  };
160  TaskParallelSettings settings;
163  }
164  }
165 
166  recalcData(t);
167 
168  ED_area_status_text(t->area, str);
169 }
170 
172 {
173  /* If not in mesh edit mode, fallback to Resize. */
174  if ((t->flag & T_EDIT) == 0 || (t->obedit_type != OB_MESH)) {
175  float no_mouse_dir_constraint[3];
176  zero_v3(no_mouse_dir_constraint);
177  initResize(t, no_mouse_dir_constraint);
178  }
179  else {
180  t->mode = TFM_SHRINKFATTEN;
181  t->transform = applyShrinkFatten;
182  t->handleEvent = shrinkfatten_handleEvent;
183 
185 
186  t->idx_max = 0;
187  t->num.idx_max = 0;
188  t->snap[0] = 1.0f;
189  t->snap[1] = t->snap[0] * 0.1f;
190 
191  copy_v3_fl(t->num.val_inc, t->snap[0]);
192  t->num.unit_sys = t->scene->unit.system;
193  t->num.unit_type[0] = B_UNIT_LENGTH;
194 
195  t->flag |= T_NO_CONSTRAINT;
196 
197  if (t->keymap) {
198  /* Workaround to use the same key as the modal keymap. */
199  t->custom.mode.data = (void *)WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_RESIZE);
200  }
201  }
202 }
203 
@ B_UNIT_LENGTH
Definition: BKE_unit.h:101
size_t BKE_unit_value_as_string(char *str, int len_max, double value, int prec, int type, const struct UnitSettings *settings, bool pad)
#define BLI_assert(a)
Definition: BLI_assert.h:46
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE void zero_v3(float r[3])
size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: string.c:120
size_t BLI_snprintf_rlen(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
void BLI_task_parallel_range(int start, int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
Definition: task_range.cc:94
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
Definition: BLI_task.h:293
#define UNUSED(x)
#define TIP_(msgid)
@ OB_MESH
void outputNumInput(NumInput *n, char *str, struct UnitSettings *unit_settings)
Definition: numinput.c:87
#define NUM_STR_REP_LEN
Definition: ED_numinput.h:13
bool applyNumInput(NumInput *n, float *vec)
Definition: numinput.c:189
bool hasNumInput(const NumInput *n)
Definition: numinput.c:170
void ED_area_status_text(ScrArea *area, const char *str)
Definition: area.c:792
@ TFM_SHRINKFATTEN
Definition: ED_transform.h:37
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
#define UI_MAX_DRAW_STR
Definition: UI_interface.h:91
#define str(s)
static unsigned c
Definition: RandGen.cpp:83
T distance(const T &a, const T &b)
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
float axismtx[3][3]
TransDataExtension * ext
short val
Definition: WM_types.h:680
short type
Definition: WM_types.h:678
void recalcData(TransInfo *t)
conversion and adaptation of different datablocks to a common struct.
@ TD_SKIP
#define TRANSDATA_THREAD_LIMIT
transform modes used by different operators.
void initResize(TransInfo *t, float mouse_dir_constraint[3])
static eRedrawFlag shrinkfatten_handleEvent(struct TransInfo *t, const wmEvent *event)
static void transdata_elem_shrink_fatten_fn(void *__restrict iter_data_v, const int iter, const TaskParallelTLS *__restrict UNUSED(tls))
static void transdata_elem_shrink_fatten(const TransInfo *t, const TransDataContainer *UNUSED(tc), TransData *td, const float distance)
static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
void initShrinkFatten(TransInfo *t)
bool transform_snap_increment(const TransInfo *t, float *r_val)
const char * WM_bool_as_string(bool test)
Definition: wm_keymap.c:2052
int WM_keymap_item_to_string(const wmKeyMapItem *kmi, const bool compact, char *result, const int result_len)
Definition: wm_keymap.c:1213
const wmKeyMapItem * WM_modalkeymap_find_propvalue(const wmKeyMap *km, const int propvalue)
Definition: wm_keymap.c:980