Blender V4.5
transform_mode_shrink_fatten.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#include <fmt/format.h>
11
12#include "BLI_math_vector.h"
13#include "BLI_task.hh"
14
15#include "BKE_report.hh"
16#include "BKE_unit.hh"
17
18#include "ED_screen.hh"
19
20#include "WM_api.hh"
21#include "WM_types.hh"
22
23#include "BLT_translation.hh"
24
25#include "transform.hh"
26#include "transform_convert.hh"
27#include "transform_snap.hh"
28
29#include "transform_mode.hh"
30
31namespace blender::ed::transform {
32
33/* -------------------------------------------------------------------- */
36
38 const TransDataContainer * /*tc*/,
39 TransData *td,
40 const float distance)
41{
42 /* Get the final offset. */
43 float tdistance = distance * td->factor;
44 if (td->ext && (t->flag & T_ALT_TRANSFORM) != 0) {
45 tdistance *= td->ext->iscale[0]; /* Shell factor. */
46 }
47
48 madd_v3_v3v3fl(td->loc, td->iloc, td->axismtx[2], tdistance);
49}
50
52{
53 if (t->redraw) {
54 /* Event already handled. */
55 return TREDRAW_NOTHING;
56 }
57
59 const wmKeyMapItem *kmi = static_cast<const wmKeyMapItem *>(t->custom.mode.data);
60 if (kmi && event->type == kmi->type && event->val == kmi->val) {
61 /* Allows the "Even Thickness" effect to be enabled as a toggle. */
63 return TREDRAW_HARD;
64 }
65 return TREDRAW_NOTHING;
66}
67
69{
70 float distance;
71 fmt::memory_buffer str;
72 const UnitSettings &unit = t->scene->unit;
73
74 distance = t->values[0] + t->values_modal_offset[0];
75
77
79
80 t->values_final[0] = distance;
81
82 /* Header print for NumInput. */
83 fmt::format_to(fmt::appender(str), "{}", IFACE_("Shrink/Fatten: "));
84 if (hasNumInput(&t->num)) {
85 char c[NUM_STR_REP_LEN];
86 outputNumInput(&(t->num), c, unit);
87 fmt::format_to(fmt::appender(str), "{}", c);
88 }
89 else {
90 /* Default header print. */
91 if (unit.system != USER_UNIT_NONE) {
92 char unit_str[64];
94 unit_str, sizeof(unit_str), distance, 4, B_UNIT_LENGTH, unit, true);
95 fmt::format_to(fmt::appender(str), "{}", unit_str);
96 }
97 else {
98 fmt::format_to(fmt::appender(str), "{:.4f}", distance);
99 }
100 }
101
102 if (t->proptext[0]) {
103 fmt::format_to(fmt::appender(str), " {}", t->proptext);
104 }
105 fmt::format_to(fmt::appender(str), ", (");
106
107 const wmKeyMapItem *kmi = static_cast<const wmKeyMapItem *>(t->custom.mode.data);
108 if (kmi) {
109 str.append(WM_keymap_item_to_string(kmi, false).value_or(""));
110 }
111
112 fmt::format_to(fmt::appender(str),
113 fmt::runtime(IFACE_(" or Alt) Even Thickness {}")),
115 /* Done with header string. */
116
118 threading::parallel_for(IndexRange(tc->data_len), 1024, [&](const IndexRange range) {
119 for (const int i : range) {
120 TransData *td = &tc->data[i];
121 if (td->flag & TD_SKIP) {
122 continue;
123 }
124 transdata_elem_shrink_fatten(t, tc, td, distance);
125 }
126 });
127 }
128
129 recalc_data(t);
130
131 ED_area_status_text(t->area, fmt::to_string(str).c_str());
132}
133
134static void initShrinkFatten(TransInfo *t, wmOperator * /*op*/)
135{
136 if ((t->flag & T_EDIT) == 0 || (t->obedit_type != OB_MESH)) {
137 BKE_report(t->reports, RPT_ERROR, "'Shrink/Fatten' meshes is only supported in edit mode");
138 t->state = TRANS_CANCEL;
139 }
140
142
144
145 t->idx_max = 0;
146 t->num.idx_max = 0;
147 t->snap[0] = 1.0f;
148 t->snap[1] = t->snap[0] * 0.1f;
149
150 copy_v3_fl(t->num.val_inc, t->snap[0]);
151 t->num.unit_sys = t->scene->unit.system;
153
154 if (t->keymap) {
155 /* Workaround to use the same key as the modal keymap. */
157 }
158}
159
161
163 /*flags*/ T_NO_CONSTRAINT,
164 /*init_fn*/ initShrinkFatten,
165 /*transform_fn*/ applyShrinkFatten,
166 /*transform_matrix_fn*/ nullptr,
167 /*handle_event_fn*/ shrinkfatten_handleEvent,
168 /*snap_distance_fn*/ nullptr,
169 /*snap_apply_fn*/ nullptr,
170 /*draw_fn*/ nullptr,
171};
172
173} // namespace blender::ed::transform
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:126
size_t BKE_unit_value_as_string_scaled(char *str, int str_maxncpy, double value, int prec, int type, const UnitSettings &settings, bool pad)
Definition unit.cc:1889
@ B_UNIT_LENGTH
Definition BKE_unit.hh:124
#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)
#define IFACE_(msgid)
@ OB_MESH
@ USER_UNIT_NONE
#define NUM_STR_REP_LEN
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:189
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:87
bool hasNumInput(const NumInput *n)
Definition numinput.cc:170
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:872
#define str(s)
float distance(VecOp< float, D >, VecOp< float, D >) RET
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 initShrinkFatten(TransInfo *t, wmOperator *)
static void applyShrinkFatten(TransInfo *t)
static eRedrawFlag shrinkfatten_handleEvent(TransInfo *t, const wmEvent *event)
static void transdata_elem_shrink_fatten(const TransInfo *t, const TransDataContainer *, TransData *td, const float distance)
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
TransCustomDataContainer custom
Definition transform.hh:968
wmEventType type
Definition WM_types.hh:754
short val
Definition WM_types.hh:756
#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.
const wmKeyMapItem * WM_modalkeymap_find_propvalue(const wmKeyMap *km, const int propvalue)
std::optional< std::string > WM_keymap_item_to_string(const wmKeyMapItem *kmi, const bool compact)
const char * WM_bool_as_string(bool test)