Blender V5.3
rna_curveprofile.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "DNA_curve_types.h"
13
14#include "RNA_define.hh"
15#include "rna_internal.hh"
16
17#include "BLT_translation.hh"
18
19#include "WM_api.hh"
20#include "WM_types.hh"
21
22#ifdef RNA_RUNTIME
23
24# include "RNA_access.hh"
25
26# include "BKE_curveprofile.h"
27
28namespace blender {
29
34static void rna_CurveProfilePoint_handle_type_set(PointerRNA *ptr, int value)
35{
36 CurveProfilePoint *point = static_cast<CurveProfilePoint *>(ptr->data);
37 CurveProfile *profile = point->profile;
38
39 if (profile) {
40 BKE_curveprofile_selected_handle_set(profile, value, value);
43 }
44}
45
46static void rna_CurveProfile_clip_set(PointerRNA *ptr, bool value)
47{
48 CurveProfile *profile = static_cast<CurveProfile *>(ptr->data);
49
50 if (value) {
51 profile->flag |= PROF_USE_CLIP;
52 }
53 else {
54 profile->flag &= ~PROF_USE_CLIP;
55 }
56
58}
59
60static void rna_CurveProfile_sample_straight_set(PointerRNA *ptr, bool value)
61{
62 CurveProfile *profile = static_cast<CurveProfile *>(ptr->data);
63
64 if (value) {
65 profile->flag |= PROF_SAMPLE_STRAIGHT_EDGES;
66 }
67 else {
68 profile->flag &= ~PROF_SAMPLE_STRAIGHT_EDGES;
69 }
70
72}
73
74static void rna_CurveProfile_sample_even_set(PointerRNA *ptr, bool value)
75{
76 CurveProfile *profile = static_cast<CurveProfile *>(ptr->data);
77
78 if (value) {
79 profile->flag |= PROF_SAMPLE_EVEN_LENGTHS;
80 }
81 else {
82 profile->flag &= ~PROF_SAMPLE_EVEN_LENGTHS;
83 }
84
86}
87
88static void rna_CurveProfile_remove_point(CurveProfile *profile,
89 ReportList *reports,
90 PointerRNA *point_ptr)
91{
92 CurveProfilePoint *point = static_cast<CurveProfilePoint *>(point_ptr->data);
93 if (BKE_curveprofile_remove_point(profile, point) == false) {
94 BKE_report(reports, RPT_ERROR, "Unable to remove path point");
95 return;
96 }
97
98 point_ptr->invalidate();
99}
100
101static void rna_CurveProfile_evaluate(CurveProfile *profile,
102 ReportList *reports,
103 float length_portion,
104 float location[2])
105{
106 if (!profile->table) {
107 BKE_report(reports, RPT_ERROR, "CurveProfile table not initialized, call initialize()");
108 }
109 BKE_curveprofile_evaluate_length_portion(profile, length_portion, &location[0], &location[1]);
110}
111
112static void rna_CurveProfile_initialize(CurveProfile *profile, int segments_len)
113{
114 BKE_curveprofile_init(profile, short(segments_len));
115}
116
117static void rna_CurveProfile_update(CurveProfile *profile)
118{
120}
121
122} // namespace blender
123
124#else
125
126namespace blender {
127
129 {HD_AUTO, "AUTO", ICON_HANDLE_AUTO, "Auto Handle", ""},
130 {HD_VECT, "VECTOR", ICON_HANDLE_VECTOR, "Vector Handle", ""},
131 {HD_FREE, "FREE", ICON_HANDLE_FREE, "Free Handle", ""},
132 {HD_ALIGN, "ALIGN", ICON_HANDLE_ALIGNED, "Aligned Free Handles", ""},
133 {0, nullptr, 0, nullptr, nullptr},
134};
135
137{
138 StructRNA *srna;
139 PropertyRNA *prop;
140
141 srna = RNA_def_struct(brna, "CurveProfilePoint", nullptr);
142 RNA_def_struct_ui_text(srna, "CurveProfilePoint", "Point of a path used to define a profile");
143
144 prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
145 RNA_def_property_float_sdna(prop, nullptr, "x");
146 RNA_def_property_array(prop, 2);
147 RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the path point");
148
149 prop = RNA_def_property(srna, "handle_type_1", PROP_ENUM, PROP_NONE);
150 RNA_def_property_enum_sdna(prop, nullptr, "h1");
152 RNA_def_property_enum_funcs(prop, nullptr, "rna_CurveProfilePoint_handle_type_set", nullptr);
153 RNA_def_property_ui_text(prop, "First Handle Type", "Path interpolation at this point");
154
155 prop = RNA_def_property(srna, "handle_type_2", PROP_ENUM, PROP_NONE);
156 RNA_def_property_enum_sdna(prop, nullptr, "h2");
158 RNA_def_property_enum_funcs(prop, nullptr, "rna_CurveProfilePoint_handle_type_set", nullptr);
159 RNA_def_property_ui_text(prop, "Second Handle Type", "Path interpolation at this point");
160
161 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
162 RNA_def_property_boolean_sdna(prop, nullptr, "flag", PROF_SELECT);
163 RNA_def_property_ui_text(prop, "Select", "Selection state of the path point");
164}
165
167{
168 StructRNA *srna;
169 PropertyRNA *parm;
170 FunctionRNA *func;
171
172 RNA_def_property_srna(cprop, "CurveProfilePoints");
173 srna = RNA_def_struct(brna, "CurveProfilePoints", nullptr);
174 RNA_def_struct_sdna(srna, "CurveProfile");
175 RNA_def_struct_ui_text(srna, "Profile Point", "Collection of Profile Points");
176
177 func = RNA_def_function(srna, "add", "BKE_curveprofile_insert");
178 RNA_def_function_ui_description(func, "Add point to the profile");
179 parm = RNA_def_float(func,
180 "x",
181 0.0f,
182 -FLT_MAX,
183 FLT_MAX,
184 "X Position",
185 "X Position for new point",
186 -FLT_MAX,
187 FLT_MAX);
189 parm = RNA_def_float(func,
190 "y",
191 0.0f,
192 -FLT_MAX,
193 FLT_MAX,
194 "Y Position",
195 "Y Position for new point",
196 -FLT_MAX,
197 FLT_MAX);
199 parm = RNA_def_pointer(func, "point", "CurveProfilePoint", "", "New point");
200 RNA_def_function_return(func, parm);
201
202 func = RNA_def_function(srna, "remove", "rna_CurveProfile_remove_point");
204 RNA_def_function_ui_description(func, "Delete point from the profile");
205 parm = RNA_def_pointer(func, "point", "CurveProfilePoint", "", "Point to remove");
208}
209
211{
212 StructRNA *srna;
213 PropertyRNA *prop;
214 PropertyRNA *parm;
215 FunctionRNA *func;
216
217 static const EnumPropertyItem rna_enum_curveprofile_preset_items[] = {
218 {PROF_PRESET_LINE, "LINE", 0, "Line", "Default"},
219 {PROF_PRESET_SUPPORTS, "SUPPORTS", 0, "Support Loops", "Loops on each side of the profile"},
220 {PROF_PRESET_CORNICE, "CORNICE", 0, "Cornice Molding", ""},
221 {PROF_PRESET_CROWN, "CROWN", 0, "Crown Molding", ""},
222 {PROF_PRESET_STEPS, "STEPS", 0, "Steps", "A number of steps defined by the segments"},
223 {0, nullptr, 0, nullptr, nullptr},
224 };
225
226 srna = RNA_def_struct(brna, "CurveProfile", nullptr);
227 RNA_def_struct_ui_text(srna, "CurveProfile", "Profile Path editor used to build a profile path");
228
229 prop = RNA_def_property(srna, "preset", PROP_ENUM, PROP_NONE);
230 RNA_def_property_enum_sdna(prop, nullptr, "preset");
231 RNA_def_property_enum_items(prop, rna_enum_curveprofile_preset_items);
233 RNA_def_property_ui_text(prop, "Preset", "");
234
235 prop = RNA_def_property(srna, "use_clip", PROP_BOOLEAN, PROP_NONE);
236 RNA_def_property_boolean_sdna(prop, nullptr, "flag", PROF_USE_CLIP);
237 RNA_def_property_ui_text(prop, "Clip", "Force the path view to fit a defined boundary");
238 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CurveProfile_clip_set");
239
240 prop = RNA_def_property(srna, "use_sample_straight_edges", PROP_BOOLEAN, PROP_NONE);
242 RNA_def_property_ui_text(prop, "Sample Straight Edges", "Sample edges with vector handles");
243 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CurveProfile_sample_straight_set");
244
245 prop = RNA_def_property(srna, "use_sample_even_lengths", PROP_BOOLEAN, PROP_NONE);
247 RNA_def_property_ui_text(prop, "Sample Even Lengths", "Sample edges with even lengths");
248 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CurveProfile_sample_even_set");
249
250 func = RNA_def_function(srna, "update", "rna_CurveProfile_update");
251 RNA_def_function_ui_description(func, "Refresh internal data, remove doubles and clip points");
252
253 func = RNA_def_function(srna, "reset_view", "BKE_curveprofile_reset_view");
254 RNA_def_function_ui_description(func, "Reset the curve profile grid to its clipping size");
255
256 func = RNA_def_function(srna, "initialize", "rna_CurveProfile_initialize");
257 parm = RNA_def_int(func,
258 "totsegments",
259 1,
260 1,
261 1000,
262 "",
263 "The number of segment values to"
264 " initialize the segments table with",
265 1,
266 100);
268 RNA_def_function_ui_description(func, "Set the number of display segments and fill tables");
269
270 prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
271 RNA_def_property_collection_sdna(prop, nullptr, "path", "path_len");
272 RNA_def_property_struct_type(prop, "CurveProfilePoint");
273 RNA_def_property_ui_text(prop, "Points", "Profile control points");
275
276 prop = RNA_def_property(srna, "segments", PROP_COLLECTION, PROP_NONE);
277 RNA_def_property_collection_sdna(prop, nullptr, "segments", "segments_len");
278 RNA_def_property_struct_type(prop, "CurveProfilePoint");
279 RNA_def_property_ui_text(prop, "Segments", "Segments sampled from control points");
280
281 func = RNA_def_function(srna, "evaluate", "rna_CurveProfile_evaluate");
283 RNA_def_function_ui_description(func, "Evaluate the at the given portion of the path length");
284 parm = RNA_def_float(func,
285 "length_portion",
286 0.0f,
287 0.0f,
288 1.0f,
289 "Length Portion",
290 "Portion of the path length to travel before evaluation",
291 0.0f,
292 1.0f);
294 parm = RNA_def_float_vector(func,
295 "location",
296 2,
297 nullptr,
298 -100.0f,
299 100.0f,
300 "Location",
301 "The location at the given portion of the profile",
302 -100.0f,
303 100.0f);
304 RNA_def_function_output(func, parm);
305}
306
312
313} // namespace blender
314
315#endif
#define BLT_I18NCONTEXT_ID_MESH
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DATA
Definition WM_types.hh:552
#define FLT_MAX
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void BKE_curveprofile_init(struct CurveProfile *profile, short segments_len)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_function_output(FunctionRNA *, PropertyRNA *ret)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void BKE_curveprofile_evaluate_length_portion(const struct CurveProfile *profile, float length_portion, float *x_out, float *y_out)
@ FUNC_USE_REPORTS
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_profile(BlenderRNA *brna)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_COLLECTION
Definition RNA_types.hh:216
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
@ PROF_UPDATE_REMOVE_DOUBLES
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
static void rna_def_curveprofilepoint(BlenderRNA *brna)
static void rna_def_curveprofile(BlenderRNA *brna)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
void BKE_curveprofile_selected_handle_set(struct CurveProfile *profile, int type_1, int type_2)
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_RNAPTR
Definition RNA_types.hh:633
void BKE_curveprofile_update(struct CurveProfile *profile, int update_flags)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_def_property_array(PropertyRNA *prop, int length)
bool BKE_curveprofile_remove_point(struct CurveProfile *profile, struct CurveProfilePoint *point)
static const EnumPropertyItem prop_handle_type_items[]
static void rna_def_curveprofile_points_api(BlenderRNA *brna, PropertyRNA *cprop)