Blender V5.0
transform_mode_customdata.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "BLI_math_vector.h"
12#include "BLI_string_utf8.h"
13#include "BLI_task.hh"
14
15#include "BKE_unit.hh"
16
17#include "ED_screen.hh"
18
19#include "BLT_translation.hh"
20
21#include "UI_interface_types.hh"
22
23#include "transform.hh"
24#include "transform_convert.hh"
25#include "transform_snap.hh"
26
27#include "transform_mode.hh"
28
29namespace blender::ed::transform {
30
31/* -------------------------------------------------------------------- */
34
35static void transdata_elem_value(const TransInfo * /*t*/,
36 const TransDataContainer * /*tc*/,
37 TransData *td,
38 const float value)
39{
40 if (td->val == nullptr) {
41 return;
42 }
43
44 *td->val = td->ival + value * td->factor;
45 CLAMP(*td->val, 0.0f, 1.0f);
46}
47
48static void apply_value_impl(TransInfo *t, const char *value_name)
49{
50 float value;
51 char str[UI_MAX_DRAW_STR];
52
53 value = t->values[0] + t->values_modal_offset[0];
54
55 CLAMP_MAX(value, 1.0f);
56
57 transform_snap_increment(t, &value);
58
59 applyNumInput(&t->num, &value);
60
61 t->values_final[0] = value;
62
63 /* Header print for NumInput. */
64 if (hasNumInput(&t->num)) {
65 char c[NUM_STR_REP_LEN];
66
67 outputNumInput(&(t->num), c, t->scene->unit);
68
69 if (value >= 0.0f) {
70 SNPRINTF_UTF8(str, "%s: +%s %s", value_name, c, t->proptext);
71 }
72 else {
73 SNPRINTF_UTF8(str, "%s: %s %s", value_name, c, t->proptext);
74 }
75 }
76 else {
77 /* Default header print. */
78 if (value >= 0.0f) {
79 SNPRINTF_UTF8(str, "%s: +%.3f %s", value_name, value, t->proptext);
80 }
81 else {
82 SNPRINTF_UTF8(str, "%s: %.3f %s", value_name, value, t->proptext);
83 }
84 }
85
87 threading::parallel_for(IndexRange(tc->data_len), 1024, [&](const IndexRange range) {
88 for (const int i : range) {
89 TransData *td = &tc->data[i];
90 if (td->flag & TD_SKIP) {
91 continue;
92 }
93 transdata_elem_value(t, tc, td, value);
94 }
95 });
96 }
97
98 recalc_data(t);
99
100 ED_area_status_text(t->area, str);
101}
102
103static void applyCrease(TransInfo *t)
104{
105 apply_value_impl(t, IFACE_("Crease"));
106}
107
109{
110 apply_value_impl(t, IFACE_("Bevel Weight"));
111}
112
114{
116
117 t->idx_max = 0;
118 t->num.idx_max = 0;
119 t->increment[0] = 0.1f;
120 t->increment_precision = 0.1f;
121
122 copy_v3_fl(t->num.val_inc, t->increment[0]);
123 t->num.unit_sys = t->scene->unit.system;
124 t->num.unit_type[0] = B_UNIT_NONE;
125}
126
127static void initEgdeCrease(TransInfo *t, wmOperator * /*op*/)
128{
131}
132
133static void initVertCrease(TransInfo *t, wmOperator * /*op*/)
134{
137}
138
139static void initBevelWeight(TransInfo *t, wmOperator * /*op*/)
140{
142 t->mode = TFM_BWEIGHT;
143}
144
146
148 /*flags*/ T_NO_CONSTRAINT | T_NO_PROJECT,
149 /*init_fn*/ initEgdeCrease,
150 /*transform_fn*/ applyCrease,
151 /*transform_matrix_fn*/ nullptr,
152 /*handle_event_fn*/ nullptr,
153 /*snap_distance_fn*/ nullptr,
154 /*snap_apply_fn*/ nullptr,
155 /*draw_fn*/ nullptr,
156};
157
159 /*flags*/ T_NO_CONSTRAINT | T_NO_PROJECT,
160 /*init_fn*/ initVertCrease,
161 /*transform_fn*/ applyCrease,
162 /*transform_matrix_fn*/ nullptr,
163 /*handle_event_fn*/ nullptr,
164 /*snap_distance_fn*/ nullptr,
165 /*snap_apply_fn*/ nullptr,
166 /*draw_fn*/ nullptr,
167};
168
170 /*flags*/ T_NO_CONSTRAINT | T_NO_PROJECT,
171 /*init_fn*/ initBevelWeight,
172 /*transform_fn*/ applyBevelWeight,
173 /*transform_matrix_fn*/ nullptr,
174 /*handle_event_fn*/ nullptr,
175 /*snap_distance_fn*/ nullptr,
176 /*snap_apply_fn*/ nullptr,
177 /*draw_fn*/ nullptr,
178};
179
180} // namespace blender::ed::transform
@ B_UNIT_NONE
Definition BKE_unit.hh:136
MINLINE void copy_v3_fl(float r[3], float f)
#define SNPRINTF_UTF8(dst, format,...)
#define CLAMP(a, b, c)
#define CLAMP_MAX(a, c)
#define IFACE_(msgid)
#define NUM_STR_REP_LEN
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:190
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:88
bool hasNumInput(const NumInput *n)
Definition numinput.cc:171
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:851
#define UI_MAX_DRAW_STR
#define str(s)
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
void recalc_data(TransInfo *t)
bool transform_snap_increment(const TransInfo *t, float *r_val)
static void transdata_elem_value(const TransInfo *, const TransDataContainer *, TransData *td, const float value)
static void apply_value_impl(TransInfo *t, const char *value_name)
static void initEgdeCrease(TransInfo *t, wmOperator *)
static void applyBevelWeight(TransInfo *t)
static void init_mode_impl(TransInfo *t)
static void initVertCrease(TransInfo *t, wmOperator *)
static void initBevelWeight(TransInfo *t, wmOperator *)
static void applyCrease(TransInfo *t)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:93
short idx_max
float val_inc[NUM_MAX_ELEMENTS]
int unit_type[NUM_MAX_ELEMENTS]
struct UnitSettings unit
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:42
conversion and adaptation of different datablocks to a common struct.
transform modes used by different operators.