Blender  V3.3
transform_mode_push_pull.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 "UI_interface.h"
20 
21 #include "BLT_translation.h"
22 
23 #include "transform.h"
24 #include "transform_constraints.h"
25 #include "transform_convert.h"
26 #include "transform_snap.h"
27 
28 #include "transform_mode.h"
29 
30 /* -------------------------------------------------------------------- */
38  const TransInfo *t;
40 
41  float distance;
42  const float axis_global[3];
45 };
46 
48  const TransDataContainer *tc,
49  TransData *td,
50  const float distance,
51  const float axis_global[3],
52  const bool is_lock_constraint,
53  const bool is_data_space)
54 {
55  float vec[3];
56  sub_v3_v3v3(vec, tc->center_local, td->center);
57  if (t->con.applyRot && t->con.mode & CON_APPLY) {
58  float axis[3];
59  copy_v3_v3(axis, axis_global);
60  t->con.applyRot(t, tc, td, axis, NULL);
61 
62  mul_m3_v3(td->smtx, axis);
63  if (is_lock_constraint) {
64  float dvec[3];
65  project_v3_v3v3(dvec, vec, axis);
66  sub_v3_v3(vec, dvec);
67  }
68  else {
69  project_v3_v3v3(vec, vec, axis);
70  }
71  }
73  if (is_data_space) {
74  mul_m3_v3(td->smtx, vec);
75  }
76 
77  add_v3_v3v3(td->loc, td->iloc, vec);
78 }
79 
80 static void transdata_elem_push_pull_fn(void *__restrict iter_data_v,
81  const int iter,
82  const TaskParallelTLS *__restrict UNUSED(tls))
83 {
84  struct TransDataArgs_PushPull *data = iter_data_v;
85  TransData *td = &data->tc->data[iter];
86  if (td->flag & TD_SKIP) {
87  return;
88  }
90  data->tc,
91  td,
92  data->distance,
93  data->axis_global,
94  data->is_lock_constraint,
95  data->is_data_space);
96 }
97 
100 /* -------------------------------------------------------------------- */
104 static void applyPushPull(TransInfo *t, const int UNUSED(mval[2]))
105 {
106  float axis_global[3];
107  float distance;
108  int i;
109  char str[UI_MAX_DRAW_STR];
110 
111  distance = t->values[0] + t->values_modal_offset[0];
112 
114 
115  applyNumInput(&t->num, &distance);
116 
117  t->values_final[0] = distance;
118 
119  /* header print for NumInput */
120  if (hasNumInput(&t->num)) {
121  char c[NUM_STR_REP_LEN];
122 
123  outputNumInput(&(t->num), c, &t->scene->unit);
124 
125  BLI_snprintf(str, sizeof(str), TIP_("Push/Pull: %s%s %s"), c, t->con.text, t->proptext);
126  }
127  else {
128  /* default header print */
129  BLI_snprintf(
130  str, sizeof(str), TIP_("Push/Pull: %.4f%s %s"), distance, t->con.text, t->proptext);
131  }
132 
133  if (t->con.applyRot && t->con.mode & CON_APPLY) {
134  t->con.applyRot(t, NULL, NULL, axis_global, NULL);
135  }
136 
137  const bool is_lock_constraint = isLockConstraint(t);
138  const bool is_data_space = (t->options & CTX_POSE_BONE) != 0;
139 
142  TransData *td = tc->data;
143  for (i = 0; i < tc->data_len; i++, td++) {
144  if (td->flag & TD_SKIP) {
145  continue;
146  }
149  }
150  }
151  else {
152  struct TransDataArgs_PushPull data = {
153  .t = t,
154  .tc = tc,
155 
156  .distance = distance,
157  .axis_global = {UNPACK3(axis_global)},
158  .is_lock_constraint = is_lock_constraint,
159  .is_data_space = is_data_space,
160  };
161  TaskParallelSettings settings;
164  }
165  }
166 
167  recalcData(t);
168 
169  ED_area_status_text(t->area, str);
170 }
171 
173 {
174  t->mode = TFM_PUSHPULL;
175  t->transform = applyPushPull;
176 
178 
179  t->idx_max = 0;
180  t->num.idx_max = 0;
181  t->snap[0] = 1.0f;
182  t->snap[1] = t->snap[0] * 0.1f;
183 
184  copy_v3_fl(t->num.val_inc, t->snap[0]);
185  t->num.unit_sys = t->scene->unit.system;
186  t->num.unit_type[0] = B_UNIT_LENGTH;
187 }
188 
@ B_UNIT_LENGTH
Definition: BKE_unit.h:101
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:926
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
void project_v3_v3v3(float out[3], const float p[3], const float v_proj[3])
Definition: math_vector.c:600
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE float normalize_v3_length(float r[3], float unit_scale)
MINLINE void copy_v3_fl(float r[3], float f)
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 UNPACK3(a)
#define TIP_(msgid)
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_PUSHPULL
Definition: ED_transform.h:40
_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)
const TransDataContainer * tc
float smtx[3][3]
bool isLockConstraint(const TransInfo *t)
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 initPushPull(TransInfo *t)
static void transdata_elem_push_pull(const TransInfo *t, const TransDataContainer *tc, TransData *td, const float distance, const float axis_global[3], const bool is_lock_constraint, const bool is_data_space)
static void applyPushPull(TransInfo *t, const int UNUSED(mval[2]))
static void transdata_elem_push_pull_fn(void *__restrict iter_data_v, const int iter, const TaskParallelTLS *__restrict UNUSED(tls))
bool transform_snap_increment(const TransInfo *t, float *r_val)